Skip to content

Commit 57615c4

Browse files
committed
chore: improve comments
1 parent f3bc8b7 commit 57615c4

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub type ResponseStream = TryFilter<
2929
fn(&Message) -> Ready<bool>,
3030
>;
3131

32+
// Sends the proofs to the batcher via WS
33+
// Stores the proofs sent in an array
34+
// Returns the array
3235
pub async fn send_messages(
3336
ws_write: Arc<Mutex<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>,
3437
payment_service_addr: Address,
@@ -73,10 +76,16 @@ pub async fn send_messages(
7376

7477

7578
// Instead of using a channel, use a storage.
79+
// Using a
7680
// From there, you can match received messages to the ones you sent.
7781

7882
// TODO missing analyzing which is the last expected nonce.
7983
// When received message of last expected nonce, i can exit this function
84+
85+
// Receives the array of proofs sent
86+
// Reads the WS responses
87+
// Matches each response with the corresponding proof sent
88+
// finishes when the last proof sent receives its response
8089
pub async fn receive(
8190
response_stream: Arc<Mutex<ResponseStream>>,
8291
mut sent_verification_data: Vec<NoncedVerificationData>,
@@ -217,8 +226,8 @@ async fn handle_batcher_response(
217226
}
218227

219228
// Used to match the message received from the batcher,
220-
// a BatchInclusionData corresponding to the data you need to verify your proof is in a batch
221-
// with the NoncedVerificationData you sent, used to verify the proof was indeed included in the batch
229+
// with the NoncedVerificationData you sent
230+
// This is used to verify the proof you sent was indeed included in the batch
222231
fn match_batcher_response_with_stored_verification_data(
223232
batch_inclusion_data: &BatchInclusionData,
224233
sent_verification_data: &mut Vec<NoncedVerificationData>,
@@ -241,6 +250,9 @@ fn match_batcher_response_with_stored_verification_data(
241250
Err(SubmitError::InvalidProofInclusionData)
242251
}
243252

253+
// Returns the biggest nonce from the sent verification data
254+
// Used to know which is the last proof sent to the Batcher,
255+
// to know when to stop reading the WS for responses
244256
fn get_biggest_nonce(sent_verification_data: &Vec<NoncedVerificationData>) -> U256 {
245257
let mut biggest_nonce = U256::zero();
246258
for verification_data in sent_verification_data.iter() {

batcher/aligned-sdk/src/core/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl fmt::Display for SubmitError {
212212
SubmitError::ProofQueueFlushed => write!(f, "Batch reset"),
213213
SubmitError::AddToBatchError => write!(f, "Error while adding entry to batch"),
214214
SubmitError::InvalidProofInclusionData => {
215-
write!(f, "Batcher responded with invalid batch inclusion data. Your proof was not correctly included in the batch.")
215+
write!(f, "Batcher responded with invalid batch inclusion data. Can't verify your proof was correctly included in the batch.")
216216
}
217217
}
218218
}

batcher/aligned-sdk/src/sdk.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ pub async fn submit_multiple_and_wait_verification(
9696
)
9797
.await?;
9898

99-
// TODO maybe use a join to .await all at the same time, avoiding the loop
99+
// TODO: open issue: use a join to .await all at the same time, avoiding the loop
100+
// And await only once per batch, no need to await multiple proofs if they are in the same batch.
100101
for aligned_verification_data_item in aligned_verification_data.iter() {
101102
await_batch_verification(aligned_verification_data_item, eth_rpc_url, network).await?;
102103
}
@@ -296,7 +297,7 @@ async fn _submit_multiple(
296297
"verification_data".to_string(),
297298
));
298299
}
299-
if verification_data.len() > 10000 { //TODO unhardcode value
300+
if verification_data.len() > 10000 { //TODO Magic number
300301
return Err(errors::SubmitError::GenericError(
301302
"Trying to submit too many proofs at once".to_string(),
302303
));
@@ -311,11 +312,6 @@ async fn _submit_multiple(
311312

312313
let payment_service_addr = get_payment_service_address(network);
313314

314-
// done sequencial
315-
// added size check to avoid sequencial is too big
316-
// done added nonce en la respuesta del batcher al sender
317-
// done check last nonce to close connection.
318-
319315
let result = async {
320316
let sent_verification_data = send_messages(ws_write, payment_service_addr, verification_data, max_fees, wallet, nonce).await?;
321317
receive(response_stream, sent_verification_data).await

0 commit comments

Comments
 (0)