Skip to content

Commit 0de8d9b

Browse files
committed
feat: check latest nonce response to know when to cut the connection
1 parent d66ed15 commit 0de8d9b

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const RETRIES: u64 = 10;
1414
const TIME_BETWEEN_RETRIES: u64 = 10;
1515

1616
pub fn process_batcher_response(
17-
batch_inclusion_data: BatchInclusionData,
18-
verification_data_commitment: VerificationDataCommitment,
17+
batch_inclusion_data: &BatchInclusionData,
18+
verification_data_commitment: &VerificationDataCommitment,
1919
) -> Result<AlignedVerificationData, errors::SubmitError> {
2020
debug!("Received response from batcher");
2121
debug!(
@@ -24,11 +24,11 @@ pub fn process_batcher_response(
2424
);
2525
debug!("Index in batch: {}", batch_inclusion_data.index_in_batch);
2626

27-
if verify_proof_inclusion(&verification_data_commitment, &batch_inclusion_data) {
27+
if verify_proof_inclusion(verification_data_commitment, batch_inclusion_data) {
2828
Ok(
2929
AlignedVerificationData::new(
30-
&verification_data_commitment,
31-
&batch_inclusion_data,
30+
verification_data_commitment,
31+
batch_inclusion_data,
3232
)
3333
)
3434
} else {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub async fn receive(
8484
// Responses are filtered to only admit binary or close messages.
8585
let mut response_stream = response_stream.lock().await;
8686
let mut aligned_submitted_data: Vec<AlignedVerificationData> = Vec::new();
87+
let last_proof_nonce = get_biggest_nonce(&sent_verification_data);
8788

8889
// read from WS
8990
while let Some(Ok(msg)) = response_stream.next().await {
@@ -110,11 +111,16 @@ pub async fn receive(
110111
)?;
111112

112113
let aligned_verification_data = process_batcher_response(
113-
batch_inclusion_data_message,
114-
related_verification_data,
114+
&batch_inclusion_data_message,
115+
&related_verification_data,
115116
)?;
116117

117118
aligned_submitted_data.push(aligned_verification_data);
119+
info!("Message response handled succesfully");
120+
121+
if batch_inclusion_data_message.user_nonce == last_proof_nonce {
122+
break;
123+
}
118124
}
119125

120126
debug!("All message responses handled succesfully");
@@ -234,3 +240,13 @@ fn match_batcher_response_with_stored_verification_data(
234240

235241
Err(SubmitError::InvalidProofInclusionData)
236242
}
243+
244+
fn get_biggest_nonce(sent_verification_data: &Vec<NoncedVerificationData>) -> U256 {
245+
let mut biggest_nonce = U256::zero();
246+
for verification_data in sent_verification_data.iter() {
247+
if verification_data.nonce > biggest_nonce {
248+
biggest_nonce = verification_data.nonce;
249+
}
250+
}
251+
biggest_nonce
252+
}

batcher/aligned-sdk/src/sdk.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ async fn _submit_multiple(
313313

314314
// done sequencial
315315
// added size check to avoid sequencial is too big
316-
// chequeando el nonce del ultimo, puedo cortar la conexión cuando recibo su respuesta
317-
// agregar nonce en la respuesta del batcher al sender
318-
// sacar el mensaje de que la proof es una replacement
316+
// done added nonce en la respuesta del batcher al sender
317+
// done check last nonce to close connection.
319318

320319
let result = async {
321320
let sent_verification_data = send_messages(ws_write, payment_service_addr, verification_data, max_fees, wallet, nonce).await?;

0 commit comments

Comments
 (0)