Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(consensus): update handle_state_machine_decision to return InternalInconsistency #2957

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions crates/sequencing/papyrus_consensus/src/single_height_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,30 @@ impl SingleHeightConsensus {
proposal_id: ProposalContentId,
round: Round,
) -> Result<ShcReturn, ConsensusError> {
let invalid_decision = |msg: String| {
ConsensusError::InternalInconsistency(format!(
"Invalid decision: sm_proposal_id: {:?}, round: {:?}. {}",
proposal_id, round, msg
))
};
let block = self
.proposals
.remove(&round)
.expect("StateMachine arrived at an unknown decision")
.expect("StateMachine should not decide on a missing proposal");
assert_eq!(block, proposal_id, "StateMachine block hash should match the stored block");
.ok_or_else(|| {
// No ProposalInit received for this round.
invalid_decision("Decided on an unknown proposal".to_string())
})?
.ok_or_else(|| {
// Either invalid or validations haven't yet completed.
invalid_decision(
"Decided on a proposal which was not succesfully validated".to_string(),
)
})?;
if block != proposal_id {
return Err(invalid_decision(format!(
"StateMachine block hash should match the stored block. Shc.block_id: {block}"
)));
}
let supporting_precommits: Vec<Vote> = self
.validators
.iter()
Expand All @@ -573,12 +591,17 @@ impl SingleHeightConsensus {
if vote.block_hash == Some(proposal_id) { Some(vote.clone()) } else { None }
})
.collect();
let quorum_size =
usize::try_from(self.state_machine.quorum_size()).expect("u32 should fit in usize");
// TODO(matan): Check actual weights.
assert!(
supporting_precommits.len()
>= usize::try_from(self.state_machine.quorum_size())
.expect("u32 should fit in usize")
);
if quorum_size > supporting_precommits.len() {
let msg = format!(
"Not enough supporting votes. quorum_size: {quorum_size}, num_supporting_votes: \
{}. supporting_votes: {supporting_precommits:?}",
supporting_precommits.len(),
);
return Err(invalid_decision(msg));
}
Ok(ShcReturn::Decision(Decision { precommits: supporting_precommits, block }))
}
}
Loading