From 3db1655e2cc841ef80a1f3ec4c49875d426e49ee Mon Sep 17 00:00:00 2001 From: Asmaa Magdoub Date: Thu, 1 Aug 2024 13:36:30 +0300 Subject: [PATCH] fix(consensus): handle nil quorum on different round and enable protobuf nil votes --- crates/papyrus_protobuf/src/converters/consensus.rs | 7 ++----- crates/sequencing/papyrus_consensus/src/state_machine.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/papyrus_protobuf/src/converters/consensus.rs b/crates/papyrus_protobuf/src/converters/consensus.rs index 61f8a2c6b7..1e12b3ee77 100644 --- a/crates/papyrus_protobuf/src/converters/consensus.rs +++ b/crates/papyrus_protobuf/src/converters/consensus.rs @@ -77,11 +77,8 @@ impl TryFrom for Vote { let height = value.height; let round = value.round; - let block_hash: StarkHash = value - .block_hash - .ok_or(ProtobufConversionError::MissingField { field_description: "block_hash" })? - .try_into()?; - let block_hash = Some(BlockHash(block_hash)); + let block_hash: Option = + value.block_hash.map(|block_hash| block_hash.try_into()).transpose()?.map(BlockHash); let voter = value .voter .ok_or(ProtobufConversionError::MissingField { field_description: "voter" })? diff --git a/crates/sequencing/papyrus_consensus/src/state_machine.rs b/crates/sequencing/papyrus_consensus/src/state_machine.rs index 81a2b4bf80..c178754175 100644 --- a/crates/sequencing/papyrus_consensus/src/state_machine.rs +++ b/crates/sequencing/papyrus_consensus/src/state_machine.rs @@ -333,8 +333,13 @@ impl StateMachine { if *count < self.quorum { return VecDeque::new(); } - if block_hash.is_none() && round == self.round { - return self.advance_to_round(round + 1, leader_fn); + if block_hash.is_none() { + if round == self.round { + return self.advance_to_round(round + 1, leader_fn); + } else { + // NIL quorum reached on a different round. + return VecDeque::new(); + } } let Some(proposed_value) = self.proposals.get(&round) else { return VecDeque::new();