Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): Partially sent batch should display results of processing #1675

Open
wants to merge 60 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
92ac39c
addd last_send_valid_nonce to InsufficientBalance Method
PatStiles Dec 20, 2024
de4d543
receive older msg's
PatStiles Dec 20, 2024
820d4f3
works
PatStiles Dec 20, 2024
6e68bff
edge case + msg
PatStiles Dec 21, 2024
4d72694
fmt + clippy
PatStiles Dec 21, 2024
e550b81
julian's comments
PatStiles Dec 23, 2024
7b86ef7
cmt + messaging fix
PatStiles Dec 23, 2024
c3ea68f
fmt
PatStiles Dec 23, 2024
72cff08
Update batcher/aligned-sdk/src/communication/messaging.rs
uri-99 Dec 30, 2024
6bdfb70
Update batcher/aligned-sdk/src/communication/messaging.rs
uri-99 Dec 30, 2024
62657d9
remove comments
PatStiles Dec 30, 2024
35947b6
rm print
PatStiles Dec 30, 2024
898bd09
Update batcher/aligned/src/main.rs
uri-99 Dec 30, 2024
67bf22c
fix variable names
PatStiles Dec 30, 2024
3c754bc
clippy
PatStiles Dec 30, 2024
9cfc7bb
handle overflow error case
PatStiles Jan 2, 2025
593b5ba
fmt
PatStiles Jan 2, 2025
5211f44
gaston's comments
PatStiles Jan 3, 2025
22c14f8
clippy
PatStiles Jan 3, 2025
3be473b
refactor: cut condition of error_nonce, now easier to read and follow
uri-99 Jan 7, 2025
3c97f74
chore: comments
uri-99 Jan 7, 2025
6da71a9
chore: cargo fmt
uri-99 Jan 7, 2025
7189711
refactor: better error messages for the user
uri-99 Jan 7, 2025
29635f6
chore: better info messages
uri-99 Jan 7, 2025
d55f58e
remove NetworkArg type
PatStiles Dec 10, 2024
bd1139b
add lock
PatStiles Dec 10, 2024
bab051a
pass by copy
PatStiles Jan 2, 2025
8c4049a
remove need for ValueEnum
PatStiles Jan 7, 2025
a289328
fmt + clippy
PatStiles Jan 7, 2025
82fa721
move values to constants
PatStiles Jan 8, 2025
510f6e2
add custom network arg
PatStiles Jan 8, 2025
9b2d37b
fmt
PatStiles Jan 8, 2025
a320ab0
change error messages
PatStiles Jan 8, 2025
587a5fa
enforce custom in right place + fix
PatStiles Jan 10, 2025
1a4ef29
remove clap from cargo.toml
PatStiles Jan 9, 2025
0ac4db3
deprecate batcher_url
PatStiles Jan 10, 2025
c765ecf
deprecate more
PatStiles Jan 10, 2025
2f6da7c
feat: better implementation of this pr
uri-99 Jan 15, 2025
0dab9a1
Merge branch 'staging' into feat/deprecate-batcher-url
uri-99 Jan 16, 2025
ec9685d
chore: cargo fmt
uri-99 Jan 16, 2025
9da8dcc
feat: migrate rust task sender
uri-99 Jan 16, 2025
5873fa4
chore: docs
uri-99 Jan 16, 2025
ceafba5
chore: cargo fmt
uri-99 Jan 16, 2025
ab87086
chore: cargo clippy
uri-99 Jan 16, 2025
51f576a
chore: add error failure on CI
uri-99 Jan 17, 2025
79a3b8a
chore: fix comment
uri-99 Jan 17, 2025
d7dc1c1
fix: debugging error in CI
uri-99 Jan 17, 2025
ce35d41
fix(wip): print .json contents
uri-99 Jan 17, 2025
f05869e
fix: prints
uri-99 Jan 17, 2025
1c3b245
fix: revert CI changes, they are in another pr
uri-99 Jan 17, 2025
8e582ca
Merge branch 'pull_fixes_testnet_17_01' into feat/deprecate-batcher-url
uri-99 Jan 17, 2025
5d32849
fix: docs
uri-99 Jan 17, 2025
5447237
chore: cargo fmt
uri-99 Jan 17, 2025
00a252c
fix: batcher urls
JuArce Jan 17, 2025
cc84f6e
fix: missing new line
JuArce Jan 17, 2025
5bd5fb9
fix: remove mix.lock changes
JuArce Jan 17, 2025
5a5447c
fix: remove mix.lock changes
JuArce Jan 17, 2025
a630e1b
Merge branch 'feat/deprecate-batcher-url' into fix/partially-verified…
uri-99 Jan 17, 2025
de617a1
Merge branch 'staging' into fix/partially-verified-batch-should-displ…
uri-99 Jan 20, 2025
9dd8587
fix: pr comments
uri-99 Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions batcher/aligned-batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,10 @@ 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", ""]);
Expand Down Expand Up @@ -749,7 +752,10 @@ 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", ""]);
Expand Down Expand Up @@ -1684,7 +1690,10 @@ 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(());
Expand All @@ -1694,7 +1703,10 @@ 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(());
Expand Down
31 changes: 28 additions & 3 deletions batcher/aligned-sdk/src/communication/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ pub async fn send_messages(
pub async fn receive(
response_stream: Arc<Mutex<ResponseStream>>,
mut sent_verification_data_rev: Vec<Result<NoncedVerificationData, SubmitError>>,
first_nonce: U256,
) -> Vec<Result<AlignedVerificationData, SubmitError>> {
// Responses are filtered to only admit binary or close messages.
let mut response_stream = response_stream.lock().await;
let mut aligned_submitted_data: Vec<Result<AlignedVerificationData, SubmitError>> = Vec::new();
let 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;

// read from WS
while let Some(Ok(msg)) = response_stream.next().await {
Expand All @@ -124,6 +126,25 @@ pub async fn receive(
Ok(data) => data,
Err(e) => {
warn!("Error while handling batcher response: {:?}", e);
// 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));

let last_valid_nonce = error_nonce - 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));
break;
}
Expand Down Expand Up @@ -190,9 +211,13 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
error!("Batcher responded with invalid max fee");
Err(SubmitError::InvalidMaxFee)
}
Ok(SubmitProofResponseMessage::InsufficientBalance(addr)) => {
Ok(SubmitProofResponseMessage::InsufficientBalance(addr, last_sent_valid_nonce)) => {
// If we receive an invalid balance we should grab the 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");
Expand Down
12 changes: 8 additions & 4 deletions batcher/aligned-sdk/src/core/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub enum SubmitError {
InvalidProof(ProofInvalidReason),
ProofTooLarge,
InvalidReplacementMessage,
InsufficientBalance(H160),
InsufficientBalance(H160, U256),
InvalidPaymentServiceAddress(H160, H160),
BatchSubmissionFailed(String),
AddToBatchError,
Expand Down Expand Up @@ -195,8 +195,12 @@ 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!(
Expand Down
2 changes: 1 addition & 1 deletion batcher/aligned-sdk/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ pub enum SubmitProofResponseMessage {
InvalidSignature,
ProofTooLarge,
InvalidMaxFee,
InsufficientBalance(Address),
InsufficientBalance(Address, U256),
InvalidChainId,
InvalidReplacementMessage,
AddToBatchError,
Expand Down
2 changes: 1 addition & 1 deletion batcher/aligned-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 14 additions & 6 deletions batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,22 @@ 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 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;
} else {
return Ok(());
}
}
};
}

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:"),
}

Expand Down Expand Up @@ -601,7 +609,7 @@ fn verification_data_from_args(args: &SubmitArgs) -> Result<VerificationData, Su
})
}

async fn handle_submit_err(err: SubmitError) {
async fn handle_submit_err(err: &SubmitError) {
match err {
SubmitError::InvalidNonce => {
error!("Invalid nonce. try again");
Expand All @@ -610,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) => {
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: {} last_valid_nonce: {}",
sender_address, last_sent_valid_nonce
)
}
_ => {}
Expand Down
Loading