Skip to content

Commit 097f4b4

Browse files
committed
feat: function to filter queue when a verifier gets disabled
1 parent 1a8c29c commit 097f4b4

File tree

2 files changed

+80
-10
lines changed

2 files changed

+80
-10
lines changed

batcher/aligned-batcher/src/lib.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,27 @@ impl Batcher {
10131013
/// Receives new block numbers, checks if conditions are met for submission and
10141014
/// finalizes the batch.
10151015
async fn handle_new_block(&self, block_number: u64) -> Result<(), BatcherError> {
1016-
let gas_price = match self.get_gas_price().await {
1017-
Some(price) => price,
1018-
None => {
1019-
error!("Failed to get gas price");
1020-
return Err(BatcherError::GasPriceError);
1021-
}
1022-
};
1016+
let gas_price_future = self.get_gas_price();
1017+
let disabled_verifiers_future = self.disabled_verifiers();
1018+
1019+
let (gas_price, disable_verifiers) =
1020+
tokio::join!(gas_price_future, disabled_verifiers_future);
1021+
let gas_price = gas_price.ok_or(BatcherError::GasPriceError)?;
1022+
let new_disable_verifiers =
1023+
disable_verifiers.map_err(|e| BatcherError::DisabledVerifiersError(e.to_string()))?;
1024+
1025+
let mut disabled_verifiers = self.disabled_verifiers.lock().await;
1026+
if new_disable_verifiers != *disabled_verifiers {
1027+
let mut batch_state = self.batch_state.lock().await;
1028+
*disabled_verifiers = new_disable_verifiers;
1029+
warn!("Disabled verifiers updated, filtering queue");
1030+
let filered_batch_queue = zk_utils::filter_disabled_verifiers(
1031+
batch_state.batch_queue.clone(),
1032+
disabled_verifiers,
1033+
)
1034+
.await;
1035+
batch_state.batch_queue = filered_batch_queue;
1036+
}
10231037

10241038
if let Some(finalized_batch) = self.is_batch_ready(block_number, gas_price).await {
10251039
let batch_finalization_result = self

batcher/aligned-batcher/src/zk_utils/mod.rs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
use crate::gnark::verify_gnark;
1+
use crate::connection::send_message;
22
use crate::risc_zero::verify_risc_zero_proof;
33
use crate::sp1::verify_sp1_proof;
4-
use aligned_sdk::core::types::{ProvingSystemId, VerificationData};
4+
use crate::types::batch_queue::BatchQueue;
5+
use crate::{gnark::verify_gnark, types::batch_queue::BatchQueueEntry};
6+
use aligned_sdk::core::types::{
7+
ProofInvalidReason, ProvingSystemId, ValidityResponseMessage, VerificationData,
8+
};
59
use ethers::types::U256;
6-
use log::{debug, warn};
10+
use log::{debug, info, warn};
11+
use tokio::sync::MutexGuard;
712

813
pub(crate) async fn verify(verification_data: &VerificationData) -> bool {
914
let verification_data = verification_data.clone();
@@ -70,6 +75,57 @@ pub(crate) fn is_verifier_disabled(
7075
disabled_verifiers & (U256::one() << verification_data.proving_system as u64) != U256::zero()
7176
}
7277

78+
pub(crate) async fn filter_disabled_verifiers(
79+
batch_queue: BatchQueue,
80+
disabled_verifiers: MutexGuard<'_, U256>,
81+
) -> BatchQueue {
82+
let mut removed_entries = Vec::new();
83+
let filtered_batch_queue = batch_queue
84+
.iter()
85+
.filter_map(|(entry, entry_priority)| {
86+
info!(
87+
"Verifying proof for proving system {}",
88+
entry
89+
.nonced_verification_data
90+
.verification_data
91+
.proving_system
92+
);
93+
let verification_data = &entry.nonced_verification_data.verification_data;
94+
if !is_verifier_disabled(*disabled_verifiers, verification_data)
95+
&& !removed_entries
96+
.iter()
97+
.any(|e: &BatchQueueEntry| e.sender == entry.sender)
98+
{
99+
Some((entry.clone(), entry_priority.clone()))
100+
} else {
101+
warn!(
102+
"Verifier for proving system {} is now disabled, removing proofs from batch",
103+
verification_data.proving_system
104+
);
105+
removed_entries.push(entry.clone());
106+
107+
None
108+
}
109+
})
110+
.collect();
111+
for entry in removed_entries {
112+
let ws_sink = entry.messaging_sink.as_ref();
113+
if let Some(ws_sink) = ws_sink {
114+
send_message(
115+
ws_sink.clone(),
116+
ValidityResponseMessage::InvalidProof(ProofInvalidReason::DisabledVerifier(
117+
entry
118+
.nonced_verification_data
119+
.verification_data
120+
.proving_system,
121+
)),
122+
)
123+
.await;
124+
}
125+
}
126+
filtered_batch_queue
127+
}
128+
73129
#[cfg(test)]
74130
mod test {
75131
use super::is_verifier_disabled;

0 commit comments

Comments
 (0)