Skip to content

Commit f2ba206

Browse files
committed
works
1 parent 802826b commit f2ba206

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

batcher/aligned-batcher/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ impl Batcher {
658658
if self.user_balance_is_unlocked(&addr).await {
659659
send_message(
660660
ws_conn_sink.clone(),
661+
// last_valid_nonce = client_msg.verification_data.nonce - 1.
661662
SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce),
662663
)
663664
.await;
@@ -750,7 +751,8 @@ impl Batcher {
750751
std::mem::drop(batch_state_lock);
751752
send_message(
752753
ws_conn_sink.clone(),
753-
SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce),
754+
// last_valid_nonce = client_msg.verification_data.nonce - 1.
755+
SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce - 1),
754756
)
755757
.await;
756758
self.metrics.user_error(&["insufficient_balance", ""]);
@@ -1685,7 +1687,8 @@ impl Batcher {
16851687
error!("Could not get balance for non-paying address {replacement_addr:?}");
16861688
send_message(
16871689
ws_sink.clone(),
1688-
SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce),
1690+
// last_valid_nonce = client_msg.verification_data.nonce - 1.
1691+
SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1),
16891692
)
16901693
.await;
16911694
return Ok(());
@@ -1695,7 +1698,8 @@ impl Batcher {
16951698
error!("Insufficient funds for non-paying address {replacement_addr:?}");
16961699
send_message(
16971700
ws_sink.clone(),
1698-
SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce),
1701+
// last_valid_nonce = client_msg.verification_data.nonce - 1.
1702+
SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1),
16991703
)
17001704
.await;
17011705
return Ok(());

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ pub async fn send_messages(
9595
pub async fn receive(
9696
response_stream: Arc<Mutex<ResponseStream>>,
9797
mut sent_verification_data_rev: Vec<Result<NoncedVerificationData, SubmitError>>,
98+
first_nonce: U256,
9899
) -> Vec<Result<AlignedVerificationData, SubmitError>> {
99100
// Responses are filtered to only admit binary or close messages.
100101
let mut response_stream = response_stream.lock().await;
101102
let mut aligned_submitted_data: Vec<Result<AlignedVerificationData, SubmitError>> = Vec::new();
102-
let mut last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev);
103+
let last_sent_proof_nonce = get_biggest_nonce(&sent_verification_data_rev);
104+
let mut last_proof_nonce = last_sent_proof_nonce;
105+
info!("last_sent_proof_nonce: {}", last_sent_proof_nonce);
103106

104107
// read from WS
105108
while let Some(Ok(msg)) = response_stream.next().await {
@@ -123,18 +126,25 @@ pub async fn receive(
123126
let batch_inclusion_data_message = match handle_batcher_response(msg).await {
124127
Ok(data) => data,
125128
Err(e) => {
126-
// In the case of an insufficient balance we still want to read and return the proofs.
129+
warn!("Error while handling batcher response: {:?}", e);
130+
// In the case of submitting multiple proofs we can have an multiple proofs be submitted but there
131+
// insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved.
127132
// `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance.
128133
// Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance.
129134
if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e {
130135
aligned_submitted_data.push(Err(e));
131-
last_proof_nonce = last_valid_nonce - 1;
136+
// last_valid_nonce = last_nonce - 1. In the case
137+
info!("last_proof_nonce: {}", last_proof_nonce);
138+
info!("last_valid_nonce: {}", last_valid_nonce);
139+
// In the case all proofs are insufficient balance we go over them.
140+
last_proof_nonce -= U256::from(1);
141+
if last_proof_nonce <= first_nonce {
142+
break;
143+
}
132144
continue;
133-
} else {
134-
warn!("Error while handling batcher response: {:?}", e);
135-
aligned_submitted_data.push(Err(e));
136-
break;
137145
}
146+
aligned_submitted_data.push(Err(e));
147+
break;
138148
}
139149
};
140150

@@ -168,6 +178,9 @@ pub async fn receive(
168178
aligned_submitted_data.push(Ok(aligned_verification_data));
169179
debug!("Message response handled successfully");
170180

181+
info!("last_proof_nonce: {}", last_proof_nonce);
182+
info!("batch_inclusion_data_message.user_nonce: {}", batch_inclusion_data_message.user_nonce);
183+
171184
if batch_inclusion_data_message.user_nonce == last_proof_nonce {
172185
break;
173186
}
@@ -314,4 +327,4 @@ fn get_biggest_nonce(
314327
}
315328
}
316329
biggest_nonce
317-
}
330+
}

batcher/aligned-sdk/src/sdk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ async fn _submit_multiple(
340340
nonce,
341341
)
342342
.await;
343-
receive(response_stream, sent_verification_data_rev).await
343+
receive(response_stream, sent_verification_data_rev, nonce).await
344344
}
345345
.await;
346346

batcher/aligned/src/main.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,14 @@ async fn main() -> Result<(), AlignedError> {
392392
}
393393
Err(e) => {
394394
warn!("Error while submitting proof: {:?}", e);
395-
handle_submit_err(e).await;
396-
return Ok(());
395+
handle_submit_err(&e).await;
396+
// In the case of an InsufficientBalance error we record and process the entire msg queue.
397+
// This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's.
398+
if let SubmitError::InsufficientBalance(_,_) = e {
399+
continue;
400+
} else {
401+
return Ok(());
402+
}
397403
}
398404
};
399405
}
@@ -601,7 +607,7 @@ fn verification_data_from_args(args: &SubmitArgs) -> Result<VerificationData, Su
601607
})
602608
}
603609

604-
async fn handle_submit_err(err: SubmitError) {
610+
async fn handle_submit_err(err: &SubmitError) {
605611
match err {
606612
SubmitError::InvalidNonce => {
607613
error!("Invalid nonce. try again");

0 commit comments

Comments
 (0)