Skip to content

Commit

Permalink
chore(consensus): add error for state machine and shc disagreeing
Browse files Browse the repository at this point in the history
update handle_state_machine_vote
  • Loading branch information
matan-starkware committed Dec 26, 2024
1 parent e7f5281 commit ca566e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
26 changes: 19 additions & 7 deletions crates/sequencing/papyrus_consensus/src/single_height_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,26 @@ impl SingleHeightConsensus {
voter: self.id,
};
if let Some(old) = votes.insert((round, self.id), vote.clone()) {
// TODO(matan): Consider refactoring not to panic, rather log and return the error.
panic!("State machine should not send repeat votes: old={:?}, new={:?}", old, vote);
return Err(ConsensusError::InternalInconsistency(format!(
"State machine should not send repeat votes: old={:?}, new={:?}",
old, vote
)));
}
context.broadcast(vote.clone()).await?;
if last_vote.as_ref().map_or(false, |last| round < last.round) {
return Ok(Vec::new());
}
*last_vote = Some(vote);
*last_vote = match last_vote {
None => Some(vote.clone()),
Some(last_vote) if round > last_vote.round => Some(vote.clone()),
Some(_) => {
// According to the Tendermint paper, the state machine should only vote for its
// current round. It should monotonicly increase its round. It should only vote once
// per step.
return Err(ConsensusError::InternalInconsistency(format!(
"State machine must progress in time: last_vote: {:?} new_vote: {:?}",
last_vote, vote,
)));
}
};

context.broadcast(vote).await?;
Ok(vec![task])
}

Expand Down
3 changes: 3 additions & 0 deletions crates/sequencing/papyrus_consensus/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ pub enum ConsensusError {
InternalNetworkError(String),
#[error("{0}")]
SyncError(String),
// For example the state machine and SHC are out of sync.
#[error("{0}")]
InternalInconsistency(String),
#[error("{0}")]
Other(String),
}

0 comments on commit ca566e7

Please sign in to comment.