From 0b86475863c0e60c41114763987d9a6d0929f098 Mon Sep 17 00:00:00 2001 From: moshababo Date: Wed, 11 Oct 2023 10:46:05 -0500 Subject: [PATCH] cargo fmt --- node/actors/consensus/src/leader/error.rs | 25 ++++++------------- .../consensus/src/leader/replica_commit.rs | 14 +++++------ .../consensus/src/leader/replica_prepare.rs | 20 ++++++--------- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/node/actors/consensus/src/leader/error.rs b/node/actors/consensus/src/leader/error.rs index 1a118aa6..4a063aca 100644 --- a/node/actors/consensus/src/leader/error.rs +++ b/node/actors/consensus/src/leader/error.rs @@ -1,5 +1,5 @@ -use thiserror::Error; use roles::validator; +use thiserror::Error; #[derive(Error, Debug)] #[allow(clippy::missing_docs_in_private_items)] @@ -21,13 +21,9 @@ pub(crate) enum ReplicaMessageError { #[error("prepare for a view when we are not a leader")] PrepareWhenNotLeaderInView, #[error("commit duplicated (existing message: {existing_message:?}")] - CommitDuplicated { - existing_message: String - }, + CommitDuplicated { existing_message: String }, #[error("prepare duplicated (existing message: {existing_message:?}")] - PrepareDuplicated { - existing_message: String - }, + PrepareDuplicated { existing_message: String }, #[error("commit while number of received messages below threshold, waiting for more (received: {num_messages:?}, threshold: {threshold:?}")] CommitNumReceivedBelowThreshold { num_messages: usize, @@ -44,23 +40,16 @@ pub(crate) enum ReplicaMessageError { current_view: validator::ViewNumber, }, #[error("commit with invalid signature")] - CommitInvalidSignature { - inner_err: crypto::bls12_381::Error - }, + CommitInvalidSignature { inner_err: crypto::bls12_381::Error }, #[error("prepare with invalid signature")] - PrepareInvalidSignature { - inner_err: crypto::bls12_381::Error - }, + PrepareInvalidSignature { inner_err: crypto::bls12_381::Error }, #[error("prepare with invalid high QC")] - PrepareInvalidHighQC { - inner_err: anyhow::Error - } + PrepareInvalidHighQC { inner_err: anyhow::Error }, } - /// Needed due to inner errors. impl PartialEq for ReplicaMessageError { fn eq(&self, other: &Self) -> bool { self.to_string() == other.to_string() } -} \ No newline at end of file +} diff --git a/node/actors/consensus/src/leader/replica_commit.rs b/node/actors/consensus/src/leader/replica_commit.rs index bb7c1ce2..31652df2 100644 --- a/node/actors/consensus/src/leader/replica_commit.rs +++ b/node/actors/consensus/src/leader/replica_commit.rs @@ -23,8 +23,8 @@ impl StateMachine { if (message.view, validator::Phase::Commit) < (self.view, self.phase) { return Err(ReplicaMessageError::CommitOld { current_view: self.view, - current_phase: self.phase - }) + current_phase: self.phase, + }); } // If the message is for a view when we are not a leader, we discard it. @@ -40,7 +40,7 @@ impl StateMachine { { return Err(ReplicaMessageError::CommitDuplicated { existing_message: format!("{:?}", existing_message), - }) + }); } // ----------- Checking the signed part of the message -------------- @@ -48,9 +48,7 @@ impl StateMachine { // Check the signature on the message. signed_message .verify() - .map_err(|err| ReplicaMessageError::CommitInvalidSignature { - inner_err: err - })?; + .map_err(|err| ReplicaMessageError::CommitInvalidSignature { inner_err: err })?; // ----------- Checking the contents of the message -------------- @@ -74,8 +72,8 @@ impl StateMachine { if num_messages < consensus.threshold() { return Err(ReplicaMessageError::CommitNumReceivedBelowThreshold { num_messages, - threshold: consensus.threshold() - }) + threshold: consensus.threshold(), + }); } debug_assert!(num_messages == consensus.threshold()); diff --git a/node/actors/consensus/src/leader/replica_prepare.rs b/node/actors/consensus/src/leader/replica_prepare.rs index 950410d1..ad8fba43 100644 --- a/node/actors/consensus/src/leader/replica_prepare.rs +++ b/node/actors/consensus/src/leader/replica_prepare.rs @@ -26,12 +26,12 @@ impl StateMachine { return Err(ReplicaMessageError::PrepareOld { current_view: self.view, current_phase: self.phase, - }) + }); } // If the message is for a view when we are not a leader, we discard it. if consensus.view_leader(message.view) != consensus.secret_key.public() { - return Err(ReplicaMessageError::PrepareWhenNotLeaderInView) + return Err(ReplicaMessageError::PrepareWhenNotLeaderInView); } // If we already have a message from the same validator and for the same view, we discard it. @@ -42,7 +42,7 @@ impl StateMachine { { return Err(ReplicaMessageError::PrepareDuplicated { existing_message: format!("{:?}", existing_message), - }) + }); } // ----------- Checking the signed part of the message -------------- @@ -50,9 +50,7 @@ impl StateMachine { // Check the signature on the message. signed_message .verify() - .map_err(|err| ReplicaMessageError::PrepareInvalidSignature { - inner_err: err - })?; + .map_err(|err| ReplicaMessageError::PrepareInvalidSignature { inner_err: err })?; // ----------- Checking the contents of the message -------------- @@ -60,9 +58,7 @@ impl StateMachine { message .high_qc .verify(&consensus.validator_set, consensus.threshold()) - .map_err(|err| ReplicaMessageError::PrepareInvalidHighQC { - inner_err: err - })?; + .map_err(|err| ReplicaMessageError::PrepareInvalidHighQC { inner_err: err })?; // If the high QC is for a future view, we discard the message. // This check is not necessary for correctness, but it's useful to @@ -71,7 +67,7 @@ impl StateMachine { return Err(ReplicaMessageError::PrepareHighQCOfFutureView { high_qc_view: message.high_qc.message.view, current_view: message.view, - }) + }); } // ----------- All checks finished. Now we process the message. -------------- @@ -88,8 +84,8 @@ impl StateMachine { if num_messages < consensus.threshold() { return Err(ReplicaMessageError::PrepareNumReceivedBelowThreshold { num_messages, - threshold: consensus.threshold() - }) + threshold: consensus.threshold(), + }); } // ----------- Creating the block proposal --------------