Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Oct 11, 2023
1 parent 075143d commit 0b86475
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
25 changes: 7 additions & 18 deletions node/actors/consensus/src/leader/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use thiserror::Error;
use roles::validator;
use thiserror::Error;

#[derive(Error, Debug)]
#[allow(clippy::missing_docs_in_private_items)]
Expand All @@ -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,
Expand All @@ -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()
}
}
}
14 changes: 6 additions & 8 deletions node/actors/consensus/src/leader/replica_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,17 +40,15 @@ impl StateMachine {
{
return Err(ReplicaMessageError::CommitDuplicated {
existing_message: format!("{:?}", existing_message),
})
});
}

// ----------- Checking the signed part of the message --------------

// 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 --------------

Expand All @@ -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());
Expand Down
20 changes: 8 additions & 12 deletions node/actors/consensus/src/leader/replica_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -42,27 +42,23 @@ impl StateMachine {
{
return Err(ReplicaMessageError::PrepareDuplicated {
existing_message: format!("{:?}", existing_message),
})
});
}

// ----------- Checking the signed part of the message --------------

// 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 --------------

// Verify the high QC.
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
Expand All @@ -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. --------------
Expand All @@ -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 --------------
Expand Down

0 comments on commit 0b86475

Please sign in to comment.