From 92ac39c1ebbc090e88b8a52ab5e09f2e95041202 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 14:08:51 -0300 Subject: [PATCH 01/19] addd last_send_valid_nonce to InsufficientBalance Method --- batcher/aligned-batcher/src/lib.rs | 9 +++++---- batcher/aligned-sdk/src/communication/messaging.rs | 4 ++-- batcher/aligned-sdk/src/core/errors.rs | 8 ++++---- batcher/aligned-sdk/src/core/types.rs | 2 +- batcher/aligned/src/main.rs | 7 ++++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index e5588d4e3..c774da722 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -628,6 +628,7 @@ impl Batcher { return Ok(()); } + // If there is one invalid proof we send message with one out of batch and send rejected one. if !zk_utils::verify(verification_data).await { error!("Invalid proof detected. Verification failed"); send_message( @@ -657,7 +658,7 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(addr), + SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -749,7 +750,7 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(addr), + SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -1684,7 +1685,7 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr), + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), ) .await; return Ok(()); @@ -1694,7 +1695,7 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr), + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), ) .await; return Ok(()); diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 7f3ad921c..6c093700a 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -190,9 +190,9 @@ async fn handle_batcher_response(msg: Message) -> Result { + Ok(SubmitProofResponseMessage::InsufficientBalance(addr, last_sent_valid_nonce)) => { error!("Batcher responded with insufficient balance"); - Err(SubmitError::InsufficientBalance(addr)) + Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce)) } Ok(SubmitProofResponseMessage::InvalidChainId) => { error!("Batcher responded with invalid chain id"); diff --git a/batcher/aligned-sdk/src/core/errors.rs b/batcher/aligned-sdk/src/core/errors.rs index 8712009c6..3e47d6a16 100644 --- a/batcher/aligned-sdk/src/core/errors.rs +++ b/batcher/aligned-sdk/src/core/errors.rs @@ -2,7 +2,7 @@ use core::fmt; use ethers::providers::ProviderError; use ethers::signers::WalletError; use ethers::types::transaction::eip712::Eip712Error; -use ethers::types::{SignatureError, H160}; +use ethers::types::{SignatureError, H160, U256}; use serde::{Deserialize, Serialize}; use std::io; use std::path::PathBuf; @@ -90,7 +90,7 @@ pub enum SubmitError { InvalidProof(ProofInvalidReason), ProofTooLarge, InvalidReplacementMessage, - InsufficientBalance(H160), + InsufficientBalance(H160, U256), InvalidPaymentServiceAddress(H160, H160), BatchSubmissionFailed(String), AddToBatchError, @@ -195,8 +195,8 @@ impl fmt::Display for SubmitError { SubmitError::InvalidProof(reason) => write!(f, "Invalid proof {}", reason), SubmitError::ProofTooLarge => write!(f, "Proof too Large"), SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"), - SubmitError::InsufficientBalance(addr) => { - write!(f, "Insufficient balance, address: {}", addr) + SubmitError::InsufficientBalance(addr, last_sent_valid_nonce) => { + write!(f, "Insufficient balance, address: {} last_sent_valid_nonce: {}", addr, last_sent_valid_nonce) } SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => { write!( diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index ba59b5d6b..92e708e80 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -381,7 +381,7 @@ pub enum SubmitProofResponseMessage { InvalidSignature, ProofTooLarge, InvalidMaxFee, - InsufficientBalance(Address), + InsufficientBalance(Address, U256), InvalidChainId, InvalidReplacementMessage, AddToBatchError, diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 1153cacbd..7f272dafa 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -610,10 +610,11 @@ async fn handle_submit_err(err: SubmitError) { error!("Batch was reset. try resubmitting the proof"); } SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), - SubmitError::InsufficientBalance(sender_address) => { + SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { error!( - "Insufficient balance to pay for the transaction, address: {}", - sender_address + "Insufficient balance to pay for the transaction, address: {} nonce: {}", + sender_address, + last_sent_valid_nonce ) } _ => {} From de4d543267a04324595de84c9ca86159fe0c1af8 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 16:43:04 -0300 Subject: [PATCH 02/19] receive older msg's --- .../aligned-sdk/src/communication/messaging.rs | 18 ++++++++++++++---- batcher/aligned/src/main.rs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 6c093700a..08de99aa9 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -99,7 +99,7 @@ pub async fn receive( // Responses are filtered to only admit binary or close messages. let mut response_stream = response_stream.lock().await; let mut aligned_submitted_data: Vec> = Vec::new(); - let last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); + let mut last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); // read from WS while let Some(Ok(msg)) = response_stream.next().await { @@ -123,9 +123,18 @@ pub async fn receive( let batch_inclusion_data_message = match handle_batcher_response(msg).await { Ok(data) => data, Err(e) => { - warn!("Error while handling batcher response: {:?}", e); - aligned_submitted_data.push(Err(e)); - break; + // In the case of an insufficient balance we still want to read and return the proofs. + // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. + // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. + if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { + aligned_submitted_data.push(Err(e)); + last_proof_nonce = last_valid_nonce - 1; + continue; + } else { + warn!("Error while handling batcher response: {:?}", e); + aligned_submitted_data.push(Err(e)); + break; + } } }; @@ -191,6 +200,7 @@ async fn handle_batcher_response(msg: Message) -> Result { + // If we receive an invalid balance we should grab the last_sent_valid_nonce. error!("Batcher responded with insufficient balance"); Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce)) } diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 7f272dafa..6e47cab42 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -612,7 +612,7 @@ async fn handle_submit_err(err: SubmitError) { SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { error!( - "Insufficient balance to pay for the transaction, address: {} nonce: {}", + "Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}", sender_address, last_sent_valid_nonce ) From 820d4f3e8e4241865deb521e3bf679ee06b99f2e Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 20:30:38 -0300 Subject: [PATCH 03/19] works --- batcher/aligned-batcher/src/lib.rs | 10 +++++-- .../src/communication/messaging.rs | 29 ++++++++++++++----- batcher/aligned-sdk/src/sdk.rs | 2 +- batcher/aligned/src/main.rs | 12 ++++++-- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index c774da722..50a47ce41 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -658,6 +658,7 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), + // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), ) .await; @@ -750,7 +751,8 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce - 1), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -1685,7 +1687,8 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), ) .await; return Ok(()); @@ -1695,7 +1698,8 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), ) .await; return Ok(()); diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 08de99aa9..8afe7b1c4 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -95,11 +95,14 @@ pub async fn send_messages( pub async fn receive( response_stream: Arc>, mut sent_verification_data_rev: Vec>, + first_nonce: U256, ) -> Vec> { // Responses are filtered to only admit binary or close messages. let mut response_stream = response_stream.lock().await; let mut aligned_submitted_data: Vec> = Vec::new(); - let mut last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); + let last_sent_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); + let mut last_proof_nonce = last_sent_proof_nonce; + info!("last_sent_proof_nonce: {}", last_sent_proof_nonce); // read from WS while let Some(Ok(msg)) = response_stream.next().await { @@ -123,18 +126,25 @@ pub async fn receive( let batch_inclusion_data_message = match handle_batcher_response(msg).await { Ok(data) => data, Err(e) => { - // In the case of an insufficient balance we still want to read and return the proofs. + warn!("Error while handling batcher response: {:?}", e); + // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there + // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved. // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { aligned_submitted_data.push(Err(e)); - last_proof_nonce = last_valid_nonce - 1; + // last_valid_nonce = last_nonce - 1. In the case + info!("last_proof_nonce: {}", last_proof_nonce); + info!("last_valid_nonce: {}", last_valid_nonce); + // In the case all proofs are insufficient balance we go over them. + last_proof_nonce -= U256::from(1); + if last_proof_nonce <= first_nonce { + break; + } continue; - } else { - warn!("Error while handling batcher response: {:?}", e); - aligned_submitted_data.push(Err(e)); - break; } + aligned_submitted_data.push(Err(e)); + break; } }; @@ -168,6 +178,9 @@ pub async fn receive( aligned_submitted_data.push(Ok(aligned_verification_data)); debug!("Message response handled successfully"); + info!("last_proof_nonce: {}", last_proof_nonce); + info!("batch_inclusion_data_message.user_nonce: {}", batch_inclusion_data_message.user_nonce); + if batch_inclusion_data_message.user_nonce == last_proof_nonce { break; } @@ -314,4 +327,4 @@ fn get_biggest_nonce( } } biggest_nonce -} +} \ No newline at end of file diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 6045d8411..8db9cdaff 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -340,7 +340,7 @@ async fn _submit_multiple( nonce, ) .await; - receive(response_stream, sent_verification_data_rev).await + receive(response_stream, sent_verification_data_rev, nonce).await } .await; diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 6e47cab42..d6668ab78 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -392,8 +392,14 @@ async fn main() -> Result<(), AlignedError> { } Err(e) => { warn!("Error while submitting proof: {:?}", e); - handle_submit_err(e).await; - return Ok(()); + handle_submit_err(&e).await; + // In the case of an InsufficientBalance error we record and process the entire msg queue. + // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. + if let SubmitError::InsufficientBalance(_,_) = e { + continue; + } else { + return Ok(()); + } } }; } @@ -601,7 +607,7 @@ fn verification_data_from_args(args: &SubmitArgs) -> Result { error!("Invalid nonce. try again"); From 6e68bffcc960bed642da3807dd5dc61c31103014 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 21:43:11 -0300 Subject: [PATCH 04/19] edge case + msg --- batcher/aligned-sdk/src/communication/messaging.rs | 9 +++++++-- batcher/aligned/src/main.rs | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 8afe7b1c4..676c48b46 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -137,10 +137,15 @@ pub async fn receive( info!("last_proof_nonce: {}", last_proof_nonce); info!("last_valid_nonce: {}", last_valid_nonce); // In the case all proofs are insufficient balance we go over them. - last_proof_nonce -= U256::from(1); - if last_proof_nonce <= first_nonce { + //last_proof_nonce -= U256::from(1); + if last_valid_nonce < last_proof_nonce { + last_proof_nonce = last_valid_nonce; + } + + if last_proof_nonce < first_nonce { break; } + continue; } aligned_submitted_data.push(Err(e)); diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index d6668ab78..5eccbbedc 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -393,7 +393,7 @@ async fn main() -> Result<(), AlignedError> { Err(e) => { warn!("Error while submitting proof: {:?}", e); handle_submit_err(&e).await; - // In the case of an InsufficientBalance error we record and process the entire msg queue. + // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. if let SubmitError::InsufficientBalance(_,_) = e { continue; @@ -406,6 +406,8 @@ async fn main() -> Result<(), AlignedError> { match unique_batch_merkle_roots.len() { 1 => info!("Proofs submitted to aligned. See the batch in the explorer:"), + // If no verification data we do not log the msg. + 0 => (), _ => info!("Proofs submitted to aligned. See the batches in the explorer:"), } From 4d72694d0e00f0780c185b5d2f444d5581807f13 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 21:59:59 -0300 Subject: [PATCH 05/19] fmt + clippy --- batcher/aligned-batcher/src/lib.rs | 28 +++++++++++++------ .../src/communication/messaging.rs | 18 ++++++++---- batcher/aligned-sdk/src/core/errors.rs | 6 +++- batcher/aligned/src/main.rs | 5 ++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 50a47ce41..8a97ec1b3 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -658,8 +658,11 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + addr, + nonced_verification_data.nonce, + ), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -751,8 +754,11 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce - 1), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + addr, + nonced_verification_data.nonce - 1, + ), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -1687,8 +1693,11 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + replacement_addr, + client_msg.verification_data.nonce - 1, + ), ) .await; return Ok(()); @@ -1698,8 +1707,11 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + replacement_addr, + client_msg.verification_data.nonce - 1, + ), ) .await; return Ok(()); diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 676c48b46..4b678a4c4 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,13 +127,13 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there + // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved. - // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. + // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { aligned_submitted_data.push(Err(e)); - // last_valid_nonce = last_nonce - 1. In the case + // last_valid_nonce = last_nonce - 1. In the case info!("last_proof_nonce: {}", last_proof_nonce); info!("last_valid_nonce: {}", last_valid_nonce); // In the case all proofs are insufficient balance we go over them. @@ -184,7 +184,10 @@ pub async fn receive( debug!("Message response handled successfully"); info!("last_proof_nonce: {}", last_proof_nonce); - info!("batch_inclusion_data_message.user_nonce: {}", batch_inclusion_data_message.user_nonce); + info!( + "batch_inclusion_data_message.user_nonce: {}", + batch_inclusion_data_message.user_nonce + ); if batch_inclusion_data_message.user_nonce == last_proof_nonce { break; @@ -220,7 +223,10 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the last_sent_valid_nonce. error!("Batcher responded with insufficient balance"); - Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce)) + Err(SubmitError::InsufficientBalance( + addr, + last_sent_valid_nonce, + )) } Ok(SubmitProofResponseMessage::InvalidChainId) => { error!("Batcher responded with invalid chain id"); @@ -332,4 +338,4 @@ fn get_biggest_nonce( } } biggest_nonce -} \ No newline at end of file +} diff --git a/batcher/aligned-sdk/src/core/errors.rs b/batcher/aligned-sdk/src/core/errors.rs index 3e47d6a16..5ce83de6c 100644 --- a/batcher/aligned-sdk/src/core/errors.rs +++ b/batcher/aligned-sdk/src/core/errors.rs @@ -196,7 +196,11 @@ impl fmt::Display for SubmitError { SubmitError::ProofTooLarge => write!(f, "Proof too Large"), SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"), SubmitError::InsufficientBalance(addr, last_sent_valid_nonce) => { - write!(f, "Insufficient balance, address: {} last_sent_valid_nonce: {}", addr, last_sent_valid_nonce) + write!( + f, + "Insufficient balance, address: {} last_sent_valid_nonce: {}", + addr, last_sent_valid_nonce + ) } SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => { write!( diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 5eccbbedc..fe81f94d8 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -395,7 +395,7 @@ async fn main() -> Result<(), AlignedError> { handle_submit_err(&e).await; // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. - if let SubmitError::InsufficientBalance(_,_) = e { + if let SubmitError::InsufficientBalance(_, _) = e { continue; } else { return Ok(()); @@ -621,8 +621,7 @@ async fn handle_submit_err(err: &SubmitError) { SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { error!( "Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}", - sender_address, - last_sent_valid_nonce + sender_address, last_sent_valid_nonce ) } _ => {} From e550b811f7241bc74b10ec7ea2368b16a754d2e6 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 23 Dec 2024 13:06:55 -0300 Subject: [PATCH 06/19] julian's comments --- batcher/aligned-batcher/src/lib.rs | 3 +-- batcher/aligned-sdk/src/communication/messaging.rs | 9 --------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 8a97ec1b3..85e49db9d 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -628,7 +628,6 @@ impl Batcher { return Ok(()); } - // If there is one invalid proof we send message with one out of batch and send rejected one. if !zk_utils::verify(verification_data).await { error!("Invalid proof detected. Verification failed"); send_message( @@ -661,7 +660,7 @@ impl Batcher { // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( addr, - nonced_verification_data.nonce, + nonced_verification_data.nonce - 1, ), ) .await; diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 4b678a4c4..d4ae4f6cd 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,17 +127,8 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there - // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved. - // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. - // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { aligned_submitted_data.push(Err(e)); - // last_valid_nonce = last_nonce - 1. In the case - info!("last_proof_nonce: {}", last_proof_nonce); - info!("last_valid_nonce: {}", last_valid_nonce); - // In the case all proofs are insufficient balance we go over them. - //last_proof_nonce -= U256::from(1); if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From 7b86ef7c4c826e0049ab480f5157ffb8c82cf95f Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 23 Dec 2024 16:27:28 -0300 Subject: [PATCH 07/19] cmt + messaging fix --- batcher/aligned-batcher/src/lib.rs | 12 ++++-------- batcher/aligned-sdk/src/communication/messaging.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 85e49db9d..a652a92e3 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -657,10 +657,9 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( addr, - nonced_verification_data.nonce - 1, + nonced_verification_data.nonce, ), ) .await; @@ -753,10 +752,9 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( addr, - nonced_verification_data.nonce - 1, + nonced_verification_data.nonce, ), ) .await; @@ -1692,10 +1690,9 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( replacement_addr, - client_msg.verification_data.nonce - 1, + client_msg.verification_data.nonce, ), ) .await; @@ -1706,10 +1703,9 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( replacement_addr, - client_msg.verification_data.nonce - 1, + client_msg.verification_data.nonce, ), ) .await; diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index d4ae4f6cd..8980bdccb 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,8 +127,15 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { + // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the + // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with + // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified of that some of there proofs were rejected + // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. + // This ensures the client messaging protocol continues receivng verification and error responses until all messages are received. + if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); + + let last_valid_nonce = error_nonce - 1; if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From c3ea68fe83abb3ca21f5664a455ef48dc95d513f Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 23 Dec 2024 19:31:44 -0300 Subject: [PATCH 08/19] fmt --- batcher/aligned-sdk/src/communication/messaging.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 8980bdccb..c030f131e 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,7 +127,7 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the + // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified of that some of there proofs were rejected // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. From 72cff089c01172a74c07b1d67922f6d0a90b8664 Mon Sep 17 00:00:00 2001 From: Uriel Mihura <43704209+uri-99@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:13:25 -0300 Subject: [PATCH 09/19] Update batcher/aligned-sdk/src/communication/messaging.rs --- batcher/aligned-sdk/src/communication/messaging.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index c030f131e..9ac3fae62 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -129,7 +129,7 @@ pub async fn receive( warn!("Error while handling batcher response: {:?}", e); // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with - // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified of that some of there proofs were rejected + // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. // This ensures the client messaging protocol continues receivng verification and error responses until all messages are received. if let SubmitError::InsufficientBalance(_, error_nonce) = e { From 6bdfb70f698159ca6b403cecb790b61a71ff9ea0 Mon Sep 17 00:00:00 2001 From: Uriel Mihura <43704209+uri-99@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:20:26 -0300 Subject: [PATCH 10/19] Update batcher/aligned-sdk/src/communication/messaging.rs --- batcher/aligned-sdk/src/communication/messaging.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 9ac3fae62..d43f680b8 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,11 +127,11 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the - // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with - // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected - // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. - // This ensures the client messaging protocol continues receivng verification and error responses until all messages are received. + // When submitting multiple batches, an InsufficientBalance error may occur, when the required balance of a user would exceed his balance in the BatcherPaymentService.sol + // This leads to a scenario where some of the submitted proofs are accepted and others rejected, with + // the SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected, + // we return upon erroring the nonce of the proof that has errored and set the new `last_proof_nonce` value accordingly. + // This ensures the client messaging protocol continues receiving verification and error responses until all messages are received. if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); From 62657d93cfdad3e18ec23010a276567e98dceb4b Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 10:20:21 -0300 Subject: [PATCH 11/19] remove comments --- batcher/aligned-sdk/src/communication/messaging.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index d43f680b8..a8a7171ce 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -181,12 +181,6 @@ pub async fn receive( aligned_submitted_data.push(Ok(aligned_verification_data)); debug!("Message response handled successfully"); - info!("last_proof_nonce: {}", last_proof_nonce); - info!( - "batch_inclusion_data_message.user_nonce: {}", - batch_inclusion_data_message.user_nonce - ); - if batch_inclusion_data_message.user_nonce == last_proof_nonce { break; } From 35947b643d9369129bdf7a77afbca7f6792edd17 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 10:23:02 -0300 Subject: [PATCH 12/19] rm print --- batcher/aligned-sdk/src/communication/messaging.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index a8a7171ce..742d894ae 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -102,7 +102,6 @@ pub async fn receive( let mut aligned_submitted_data: Vec> = Vec::new(); let last_sent_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); let mut last_proof_nonce = last_sent_proof_nonce; - info!("last_sent_proof_nonce: {}", last_sent_proof_nonce); // read from WS while let Some(Ok(msg)) = response_stream.next().await { From 898bd09e5cdd3ab7ad1da9d4d4015bd52c3be489 Mon Sep 17 00:00:00 2001 From: Uriel Mihura <43704209+uri-99@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:46:36 -0300 Subject: [PATCH 13/19] Update batcher/aligned/src/main.rs --- batcher/aligned/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index fe81f94d8..24561d0f4 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -394,7 +394,7 @@ async fn main() -> Result<(), AlignedError> { warn!("Error while submitting proof: {:?}", e); handle_submit_err(&e).await; // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. - // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. + // This covers the case of a `submit_multiple` in which some submissions succeed but others fail because of a cumulative `insufficient balance`. if let SubmitError::InsufficientBalance(_, _) = e { continue; } else { From 67bf22c60ba4c7e08767f444c411c69a491203f2 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 11:16:57 -0300 Subject: [PATCH 14/19] fix variable names --- batcher/aligned-sdk/src/communication/messaging.rs | 9 +++++---- batcher/aligned-sdk/src/core/errors.rs | 6 +++--- batcher/aligned/src/main.rs | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 742d894ae..00c59be9e 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -2,6 +2,7 @@ use ethers::signers::Signer; use ethers::types::Address; use futures_util::{stream::SplitStream, SinkExt, StreamExt}; use log::{debug, error, info, warn}; +use std::error; use std::sync::Arc; use tokio::{net::TcpStream, sync::Mutex}; @@ -21,7 +22,7 @@ use crate::{ SubmitProofResponseMessage, VerificationData, VerificationDataCommitment, }, }, -}; + }; pub type ResponseStream = TryFilter< SplitStream>>, @@ -211,12 +212,12 @@ async fn handle_batcher_response(msg: Message) -> Result { - // If we receive an invalid balance we should grab the last_sent_valid_nonce. + Ok(SubmitProofResponseMessage::InsufficientBalance(addr, error_nonce)) => { + // If we receive an invalid balance we should grab the error_nonce. error!("Batcher responded with insufficient balance"); Err(SubmitError::InsufficientBalance( addr, - last_sent_valid_nonce, + error_nonce, )) } Ok(SubmitProofResponseMessage::InvalidChainId) => { diff --git a/batcher/aligned-sdk/src/core/errors.rs b/batcher/aligned-sdk/src/core/errors.rs index 5ce83de6c..e0f2eef86 100644 --- a/batcher/aligned-sdk/src/core/errors.rs +++ b/batcher/aligned-sdk/src/core/errors.rs @@ -195,11 +195,11 @@ impl fmt::Display for SubmitError { SubmitError::InvalidProof(reason) => write!(f, "Invalid proof {}", reason), SubmitError::ProofTooLarge => write!(f, "Proof too Large"), SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"), - SubmitError::InsufficientBalance(addr, last_sent_valid_nonce) => { + SubmitError::InsufficientBalance(addr, error_nonce) => { write!( f, - "Insufficient balance, address: {} last_sent_valid_nonce: {}", - addr, last_sent_valid_nonce + "Insufficient balance, address: {} error_nonce: {}", + addr, error_nonce ) } SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => { diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 24561d0f4..c8207c097 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -618,10 +618,10 @@ async fn handle_submit_err(err: &SubmitError) { error!("Batch was reset. try resubmitting the proof"); } SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), - SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { + SubmitError::InsufficientBalance(sender_address, error_nonce) => { error!( - "Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}", - sender_address, last_sent_valid_nonce + "Insufficient balance to pay for the transaction, address: {} error_nonce: {}", + sender_address, error_nonce ) } _ => {} From 3c754bce3fbea3e9201f7e831e058c12e6fb335a Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 11:39:55 -0300 Subject: [PATCH 15/19] clippy --- batcher/aligned-sdk/src/communication/messaging.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 00c59be9e..1c488178f 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -2,7 +2,6 @@ use ethers::signers::Signer; use ethers::types::Address; use futures_util::{stream::SplitStream, SinkExt, StreamExt}; use log::{debug, error, info, warn}; -use std::error; use std::sync::Arc; use tokio::{net::TcpStream, sync::Mutex}; @@ -22,7 +21,7 @@ use crate::{ SubmitProofResponseMessage, VerificationData, VerificationDataCommitment, }, }, - }; +}; pub type ResponseStream = TryFilter< SplitStream>>, @@ -215,10 +214,7 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the error_nonce. error!("Batcher responded with insufficient balance"); - Err(SubmitError::InsufficientBalance( - addr, - error_nonce, - )) + Err(SubmitError::InsufficientBalance(addr, error_nonce)) } Ok(SubmitProofResponseMessage::InvalidChainId) => { error!("Batcher responded with invalid chain id"); From 9cfc7bb365b662813661b0bc9bef9e26d08f4790 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 2 Jan 2025 11:44:46 -0300 Subject: [PATCH 16/19] handle overflow error case --- batcher/aligned-sdk/src/communication/messaging.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 1c488178f..1cdac82b8 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -134,7 +134,10 @@ pub async fn receive( if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - let last_valid_nonce = error_nonce - 1; + // We handle the explicit case that a user sends a proof without an balance deposited. + // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. + // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. + let last_valid_nonce = if error_nonce == U256::zero() { error_nonce } else { error_nonce - 1 }; if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From 593b5ba921929ef496753db9f3ac7e8eb355aaa0 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 2 Jan 2025 13:08:21 -0300 Subject: [PATCH 17/19] fmt --- batcher/aligned-sdk/src/communication/messaging.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 1cdac82b8..f9ea82d56 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -134,10 +134,14 @@ pub async fn receive( if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - // We handle the explicit case that a user sends a proof without an balance deposited. + // We handle the explicit case that a user sends a proof without an balance deposited. // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. - let last_valid_nonce = if error_nonce == U256::zero() { error_nonce } else { error_nonce - 1 }; + let last_valid_nonce = if error_nonce == U256::zero() { + error_nonce + } else { + error_nonce - 1 + }; if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From 5211f448b6a602774c33d687562f6af6b43e7bcb Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 3 Jan 2025 09:53:26 -0300 Subject: [PATCH 18/19] gaston's comments --- batcher/aligned-sdk/src/communication/messaging.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index f9ea82d56..c6bcd2990 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -137,13 +137,14 @@ pub async fn receive( // We handle the explicit case that a user sends a proof without an balance deposited. // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. - let last_valid_nonce = if error_nonce == U256::zero() { - error_nonce + let last_error_nonce = if error_nonce == U256::zero() { + //error_nonce + break } else { error_nonce - 1 }; - if last_valid_nonce < last_proof_nonce { - last_proof_nonce = last_valid_nonce; + if last_error_nonce < last_proof_nonce { + last_proof_nonce = last_error_nonce; } if last_proof_nonce < first_nonce { From 22c14f82cf0e9bd45d34f124b55e8d9e08321596 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 3 Jan 2025 12:42:41 -0300 Subject: [PATCH 19/19] clippy --- batcher/aligned-sdk/src/communication/messaging.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index c6bcd2990..821147c7d 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -138,8 +138,7 @@ pub async fn receive( // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. let last_error_nonce = if error_nonce == U256::zero() { - //error_nonce - break + break; } else { error_nonce - 1 };