diff --git a/node/actors/bft/src/leader/replica_commit.rs b/node/actors/bft/src/leader/replica_commit.rs index 2f038969..ff35c65d 100644 --- a/node/actors/bft/src/leader/replica_commit.rs +++ b/node/actors/bft/src/leader/replica_commit.rs @@ -50,6 +50,9 @@ pub(crate) enum Error { /// Invalid message signature. #[error("invalid signature: {0:#}")] InvalidSignature(#[source] validator::Error), + /// Unexpected error when creating justification from received messages. + #[error("create justification unexpected error: {0:#}")] + CreateJustificationUnexpectedError(#[source] anyhow::Error), } impl StateMachine { @@ -157,9 +160,14 @@ impl StateMachine { .cloned() .collect::>(); + // Clean the caches. + self.block_proposal_cache = None; + self.prepare_message_cache.retain(|k, _| k >= &self.view); + self.commit_message_cache.retain(|k, _| k >= &self.view); + // Create the justification for our message. let justification = validator::CommitQC::from(&replica_messages, &consensus.validator_set) - .expect("Couldn't create justification from valid replica messages!"); + .map_err(Error::CreateJustificationUnexpectedError)?; // Broadcast the leader commit message to all replicas (ourselves included). let output_message = ConsensusInputMessage { @@ -175,11 +183,6 @@ impl StateMachine { }; consensus.pipe.send(output_message.into()); - // Clean the caches. - self.block_proposal_cache = None; - self.prepare_message_cache.retain(|k, _| k >= &self.view); - self.commit_message_cache.retain(|k, _| k >= &self.view); - Ok(()) } } diff --git a/node/actors/bft/src/leader/replica_prepare.rs b/node/actors/bft/src/leader/replica_prepare.rs index 3576892e..c1f958a1 100644 --- a/node/actors/bft/src/leader/replica_prepare.rs +++ b/node/actors/bft/src/leader/replica_prepare.rs @@ -62,6 +62,9 @@ pub(crate) enum Error { /// Invalid `HighQC` message. #[error("invalid high QC: {0:#}")] InvalidHighQC(#[source] anyhow::Error), + /// Unexpected error when creating justification from received messages. + #[error("create justification unexpected error: {0:#}")] + CreateJustificationUnexpectedError(#[source] anyhow::Error), } impl StateMachine { @@ -225,7 +228,7 @@ impl StateMachine { // Create the justification for our message. let justification = validator::PrepareQC::from(&replica_messages, &consensus.validator_set) - .expect("Couldn't create justification from valid replica messages!"); + .map_err(Error::CreateJustificationUnexpectedError)?; // Broadcast the leader prepare message to all replicas (ourselves included). let output_message = ConsensusInputMessage {