Skip to content

Commit 42ec9f0

Browse files
committed
chore: cargo fmt
1 parent 57615c4 commit 42ec9f0

File tree

8 files changed

+53
-56
lines changed

8 files changed

+53
-56
lines changed

batcher/aligned-batcher/src/connection.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use aligned_sdk::{
66
};
77
use futures_util::{stream::SplitSink, SinkExt};
88
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
9-
use log::{error, debug};
9+
use log::{debug, error};
1010
use serde::Serialize;
1111
use tokio::{net::TcpStream, sync::RwLock};
1212
use tokio_tungstenite::{
@@ -23,7 +23,11 @@ pub(crate) async fn send_batch_inclusion_data_responses(
2323
batch_merkle_tree: &MerkleTree<VerificationCommitmentBatch>,
2424
) -> Result<(), BatcherError> {
2525
for (vd_batch_idx, entry) in finalized_batch.iter().enumerate() {
26-
let batch_inclusion_data = BatchInclusionData::new(vd_batch_idx, batch_merkle_tree, entry.nonced_verification_data.nonce);
26+
let batch_inclusion_data = BatchInclusionData::new(
27+
vd_batch_idx,
28+
batch_merkle_tree,
29+
entry.nonced_verification_data.nonce,
30+
);
2731
let response = ResponseMessage::BatchInclusionData(batch_inclusion_data);
2832

2933
let serialized_response = cbor_serialize(&response)

batcher/aligned-batcher/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,7 @@ impl Batcher {
368368
let msg_chain_id = client_msg.verification_data.chain_id;
369369
if msg_chain_id != self.chain_id {
370370
warn!("Received message with incorrect chain id: {msg_chain_id}");
371-
send_message(
372-
ws_conn_sink.clone(),
373-
ResponseMessage::InvalidChainId,
374-
)
375-
.await;
371+
send_message(ws_conn_sink.clone(), ResponseMessage::InvalidChainId).await;
376372

377373
return Ok(());
378374
}
@@ -396,11 +392,7 @@ impl Batcher {
396392
info!("Verifying message signature...");
397393
let Ok(addr) = client_msg.verify_signature() else {
398394
error!("Signature verification error");
399-
send_message(
400-
ws_conn_sink.clone(),
401-
ResponseMessage::InvalidSignature,
402-
)
403-
.await;
395+
send_message(ws_conn_sink.clone(), ResponseMessage::InvalidSignature).await;
404396
return Ok(());
405397
};
406398
info!("Message signature verified");

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
core::{
55
errors,
66
types::{
7-
AlignedVerificationData, BatchInclusionData, Network, VerificationCommitmentBatch, VerificationDataCommitment
7+
AlignedVerificationData, BatchInclusionData, Network, VerificationCommitmentBatch,
8+
VerificationDataCommitment,
89
},
910
},
1011
sdk::is_proof_verified,
@@ -25,12 +26,10 @@ pub fn process_batcher_response(
2526
debug!("Index in batch: {}", batch_inclusion_data.index_in_batch);
2627

2728
if verify_proof_inclusion(verification_data_commitment, batch_inclusion_data) {
28-
Ok(
29-
AlignedVerificationData::new(
30-
verification_data_commitment,
31-
batch_inclusion_data,
32-
)
33-
)
29+
Ok(AlignedVerificationData::new(
30+
verification_data_commitment,
31+
batch_inclusion_data,
32+
))
3433
} else {
3534
Err(errors::SubmitError::InvalidProofInclusionData)
3635
}

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

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,15 @@ pub async fn send_messages(
6565
.map_err(SubmitError::WebSocketConnectionError)?;
6666

6767
debug!("{:?} Message sent", idx);
68-
68+
6969
// Save the verification data commitment to read its response later
7070
sent_verification_data.push(verification_data);
7171
}
7272

7373
info!("All messages sent");
74-
Ok(sent_verification_data)
74+
Ok(sent_verification_data)
7575
}
7676

77-
78-
// Instead of using a channel, use a storage.
79-
// Using a
80-
// From there, you can match received messages to the ones you sent.
81-
82-
// TODO missing analyzing which is the last expected nonce.
83-
// When received message of last expected nonce, i can exit this function
84-
8577
// Receives the array of proofs sent
8678
// Reads the WS responses
8779
// Matches each response with the corresponding proof sent
@@ -105,24 +97,19 @@ pub async fn receive(
10597
));
10698
}
10799
return Err(SubmitError::GenericError(
108-
"Connection was closed before receive() processed all sent messages "
109-
.to_string(),
100+
"Connection was closed before receive() processed all sent messages ".to_string(),
110101
));
111102
}
112-
113-
let batch_inclusion_data_message = handle_batcher_response(
114-
msg,
115-
).await?;
103+
104+
let batch_inclusion_data_message = handle_batcher_response(msg).await?;
116105

117106
let related_verification_data = match_batcher_response_with_stored_verification_data(
118107
&batch_inclusion_data_message,
119108
&mut sent_verification_data,
120109
)?;
121-
122-
let aligned_verification_data = process_batcher_response(
123-
&batch_inclusion_data_message,
124-
&related_verification_data,
125-
)?;
110+
111+
let aligned_verification_data =
112+
process_batcher_response(&batch_inclusion_data_message, &related_verification_data)?;
126113

127114
aligned_submitted_data.push(aligned_verification_data);
128115
info!("Message response handled succesfully");
@@ -136,13 +123,11 @@ pub async fn receive(
136123
Ok(aligned_submitted_data)
137124
}
138125

139-
async fn handle_batcher_response(
140-
msg: Message,
141-
) -> Result<BatchInclusionData, SubmitError> {
142-
126+
async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, SubmitError> {
143127
let data = msg.into_data();
144128
match cbor_deserialize(data.as_slice()) {
145-
Ok(ResponseMessage::BatchInclusionData(batch_inclusion_data)) => { //OK case. Proofs was valid and it was included in this batch.
129+
Ok(ResponseMessage::BatchInclusionData(batch_inclusion_data)) => {
130+
//OK case. Proofs was valid and it was included in this batch.
146131
return Ok(batch_inclusion_data);
147132
}
148133
Ok(ResponseMessage::InvalidNonce) => {
@@ -193,14 +178,17 @@ async fn handle_batcher_response(
193178
expected_addr,
194179
));
195180
}
196-
Ok(ResponseMessage::InvalidProof(reason)) => {
181+
Ok(ResponseMessage::InvalidProof(reason)) => {
197182
error!("Batcher responded with invalid proof: {}", reason);
198183
return Err(SubmitError::InvalidProof(reason));
199184
}
200185
Ok(ResponseMessage::CreateNewTaskError(merkle_root, error)) => {
201186
error!("Batcher responded with create new task error: {}", error);
202187
return Err(SubmitError::BatchSubmissionFailed(
203-
"Could not create task with merkle root ".to_owned() + &merkle_root + ", failed with error: " + &error,
188+
"Could not create task with merkle root ".to_owned()
189+
+ &merkle_root
190+
+ ", failed with error: "
191+
+ &error,
204192
));
205193
}
206194
Ok(ResponseMessage::ProtocolVersion(_)) => {
@@ -216,7 +204,7 @@ async fn handle_batcher_response(
216204
}
217205
Ok(ResponseMessage::Error(e)) => {
218206
error!("Batcher responded with error: {}", e);
219-
return Err(SubmitError::GenericError(e))
207+
return Err(SubmitError::GenericError(e));
220208
}
221209
Err(e) => {
222210
error!("Error while deserializing batch inclusion data: {}", e);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ impl fmt::Display for SubmitError {
201201
SubmitError::InvalidProof(reason) => write!(f, "Invalid proof {}", reason),
202202
SubmitError::ProofTooLarge => write!(f, "Proof too Large"),
203203
SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"),
204-
SubmitError::InsufficientBalance(addr) => write!(f, "Insufficient balance, address: {}", addr),
204+
SubmitError::InsufficientBalance(addr) => {
205+
write!(f, "Insufficient balance, address: {}", addr)
206+
}
205207
SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => {
206208
write!(
207209
f,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ impl AlignedVerificationData {
332332
}
333333
}
334334

335-
336335
#[derive(Debug, Clone, Serialize, Deserialize)]
337336
pub enum ProofInvalidReason {
338337
RejectedProof,

batcher/aligned-sdk/src/sdk.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ use log::{debug, info};
3838

3939
use futures_util::{
4040
stream::{SplitSink, SplitStream},
41-
StreamExt, TryStreamExt, SinkExt
41+
SinkExt, StreamExt, TryStreamExt,
4242
};
4343

44+
use serde_json::json;
4445
use std::fs::File;
4546
use std::io::Write;
4647
use std::path::PathBuf;
47-
use serde_json::json;
4848

4949
/// Submits multiple proofs to the batcher to be verified in Aligned and waits for the verification on-chain.
5050
/// # Arguments
@@ -297,7 +297,8 @@ async fn _submit_multiple(
297297
"verification_data".to_string(),
298298
));
299299
}
300-
if verification_data.len() > 10000 { //TODO Magic number
300+
if verification_data.len() > 10000 {
301+
//TODO Magic number
301302
return Err(errors::SubmitError::GenericError(
302303
"Trying to submit too many proofs at once".to_string(),
303304
));
@@ -313,9 +314,18 @@ async fn _submit_multiple(
313314
let payment_service_addr = get_payment_service_address(network);
314315

315316
let result = async {
316-
let sent_verification_data = send_messages(ws_write, payment_service_addr, verification_data, max_fees, wallet, nonce).await?;
317+
let sent_verification_data = send_messages(
318+
ws_write,
319+
payment_service_addr,
320+
verification_data,
321+
max_fees,
322+
wallet,
323+
nonce,
324+
)
325+
.await?;
317326
receive(response_stream, sent_verification_data).await
318-
}.await;
327+
}
328+
.await;
319329

320330
// Close connection
321331
info!("Closing WS connection");

batcher/aligned/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,10 @@ async fn handle_submit_err(err: SubmitError, nonce_file: &str) {
551551
}
552552
SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason),
553553
SubmitError::InsufficientBalance(sender_address) => {
554-
error!("Insufficient balance to pay for the transaction, address: {}", sender_address)
554+
error!(
555+
"Insufficient balance to pay for the transaction, address: {}",
556+
sender_address
557+
)
555558
}
556559
_ => {}
557560
}

0 commit comments

Comments
 (0)