Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
PatStiles committed Oct 25, 2024
1 parent dd47ee7 commit 19fe6b6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
13 changes: 2 additions & 11 deletions batcher/aligned-batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,7 @@ impl Batcher {
let msg_chain_id = client_msg.verification_data.chain_id;
if msg_chain_id != self.chain_id {
warn!("Received message with incorrect chain id: {msg_chain_id}");
send_message(
ws_conn_sink.clone(),
ResponseMessage::InvalidChainId,
)
.await;
send_message(ws_conn_sink.clone(), ResponseMessage::InvalidChainId).await;

return Ok(());
}
Expand All @@ -396,11 +392,7 @@ impl Batcher {
info!("Verifying message signature...");
let Ok(addr) = client_msg.verify_signature() else {
error!("Signature verification error");
send_message(
ws_conn_sink.clone(),
ResponseMessage::InvalidSignature,
)
.await;
send_message(ws_conn_sink.clone(), ResponseMessage::InvalidSignature).await;
return Ok(());
};
info!("Message signature verified");
Expand Down Expand Up @@ -466,7 +458,6 @@ impl Batcher {
return Ok(());
}


// We aquire the lock first only to query if the user is already present and the lock is dropped.
// If it was not present, then the user nonce is queried to the Aligned contract.
// Lastly, we get a lock of the batch state again and insert the user state if it was still missing.
Expand Down
24 changes: 13 additions & 11 deletions batcher/aligned-sdk/src/communication/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ pub async fn send_messages(

// This vector is reversed so that when responses are received, the commitments corresponding
// to that response can simply be popped of this vector.
let verification_data_commitments_rev: Vec<VerificationDataCommitment> =
sent_verification_data
.into_iter()
.map(|vd| vd.into())
.rev()
.collect();
let verification_data_commitments_rev: Vec<VerificationDataCommitment> = sent_verification_data
.into_iter()
.map(|vd| vd.into())
.rev()
.collect();

Ok(verification_data_commitments_rev)
}
Expand Down Expand Up @@ -108,7 +107,7 @@ pub async fn receive(
verification_data_commitments_rev,
)
.await?;

num_responses += 1;
if num_responses == total_messages {
info!("All message responses received");
Expand All @@ -126,10 +125,10 @@ async fn process_batch_inclusion_data(
aligned_verification_data: &mut Vec<AlignedVerificationData>,
verification_data_commitments_rev: &mut Vec<VerificationDataCommitment>,
) -> Result<(), SubmitError> {

let data = msg.into_data();
match cbor_deserialize(data.as_slice()) {
Ok(ResponseMessage::BatchInclusionData(batch_inclusion_data)) => { //OK case. Proofs was valid and it was included in this batch.
Ok(ResponseMessage::BatchInclusionData(batch_inclusion_data)) => {
//OK case. Proofs was valid and it was included in this batch.
let _ = handle_batch_inclusion_data(
batch_inclusion_data,
aligned_verification_data,
Expand Down Expand Up @@ -171,12 +170,15 @@ async fn process_batch_inclusion_data(
expected_addr,
));
}
Ok(ResponseMessage::InvalidProof(reason)) => {
Ok(ResponseMessage::InvalidProof(reason)) => {
return Err(SubmitError::InvalidProof(reason));
}
Ok(ResponseMessage::CreateNewTaskError(merkle_root, error)) => {
return Err(SubmitError::BatchSubmissionFailed(
"Could not create task with merkle root ".to_owned() + &merkle_root + ", failed with error: " + &error,
"Could not create task with merkle root ".to_owned()
+ &merkle_root
+ ", failed with error: "
+ &error,
));
}
Ok(ResponseMessage::ProtocolVersion(_)) => {
Expand Down
4 changes: 3 additions & 1 deletion batcher/aligned-sdk/src/core/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ impl fmt::Display for SubmitError {
SubmitError::InvalidProof(reason) => write!(f, "Invalid proof {}", reason),
SubmitError::ProofTooLarge => write!(f, "Proof too Large"),
SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"),
SubmitError::InsufficientBalance(addr) => write!(f, "Insufficient balance, address: {}", addr),
SubmitError::InsufficientBalance(addr) => {
write!(f, "Insufficient balance, address: {}", addr)
}
SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => {
write!(
f,
Expand Down
3 changes: 1 addition & 2 deletions batcher/aligned-sdk/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ impl AlignedVerificationData {
}
}


#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ProofInvalidReason {
RejectedProof,
Expand Down Expand Up @@ -366,7 +365,7 @@ pub enum ResponseMessage {
InvalidReplacementMessage,
AddToBatchError,
EthRpcError,
InvalidPaymentServiceAddress(Address, Address)
InvalidPaymentServiceAddress(Address, Address),
}

#[derive(Debug, Clone, Copy)]
Expand Down
4 changes: 2 additions & 2 deletions batcher/aligned-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ use log::{debug, info};

use futures_util::{
stream::{SplitSink, SplitStream},
StreamExt, TryStreamExt, SinkExt
SinkExt, StreamExt, TryStreamExt,
};

use serde_json::json;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use serde_json::json;

/// Submits multiple proofs to the batcher to be verified in Aligned and waits for the verification on-chain.
/// # Arguments
Expand Down
5 changes: 4 additions & 1 deletion batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ async fn handle_submit_err(err: SubmitError, nonce_file: &str) {
}
SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason),
SubmitError::InsufficientBalance(sender_address) => {
error!("Insufficient balance to pay for the transaction, address: {}", sender_address)
error!(
"Insufficient balance to pay for the transaction, address: {}",
sender_address
)
}
_ => {}
}
Expand Down

0 comments on commit 19fe6b6

Please sign in to comment.