Skip to content

Commit 802826b

Browse files
committed
receive older msg's
1 parent f3988c4 commit 802826b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

batcher/aligned-sdk/src/communication/messaging.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub async fn receive(
9999
// Responses are filtered to only admit binary or close messages.
100100
let mut response_stream = response_stream.lock().await;
101101
let mut aligned_submitted_data: Vec<Result<AlignedVerificationData, SubmitError>> = Vec::new();
102-
let last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev);
102+
let mut last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev);
103103

104104
// read from WS
105105
while let Some(Ok(msg)) = response_stream.next().await {
@@ -123,9 +123,18 @@ pub async fn receive(
123123
let batch_inclusion_data_message = match handle_batcher_response(msg).await {
124124
Ok(data) => data,
125125
Err(e) => {
126-
warn!("Error while handling batcher response: {:?}", e);
127-
aligned_submitted_data.push(Err(e));
128-
break;
126+
// In the case of an insufficient balance we still want to read and return the proofs.
127+
// `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance.
128+
// Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance.
129+
if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e {
130+
aligned_submitted_data.push(Err(e));
131+
last_proof_nonce = last_valid_nonce - 1;
132+
continue;
133+
} else {
134+
warn!("Error while handling batcher response: {:?}", e);
135+
aligned_submitted_data.push(Err(e));
136+
break;
137+
}
129138
}
130139
};
131140

@@ -191,6 +200,7 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
191200
Err(SubmitError::InvalidMaxFee)
192201
}
193202
Ok(SubmitProofResponseMessage::InsufficientBalance(addr, last_sent_valid_nonce)) => {
203+
// If we receive an invalid balance we should grab the last_sent_valid_nonce.
194204
error!("Batcher responded with insufficient balance");
195205
Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce))
196206
}

batcher/aligned/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ async fn handle_submit_err(err: SubmitError) {
612612
SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason),
613613
SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => {
614614
error!(
615-
"Insufficient balance to pay for the transaction, address: {} nonce: {}",
615+
"Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}",
616616
sender_address,
617617
last_sent_valid_nonce
618618
)

0 commit comments

Comments
 (0)