diff --git a/consensus/src/commons.rs b/consensus/src/commons.rs index 574932df4e..589f8861b1 100644 --- a/consensus/src/commons.rs +++ b/consensus/src/commons.rs @@ -144,12 +144,7 @@ impl QuorumMsgSender { /// Sends an quorum (internally) to the quorum loop. pub(crate) async fn send_quorum(&self, msg: Message) { match &msg.payload { - // TODO: Change me accordingly to https://github.com/dusk-network/rusk/issues/1268 - Payload::Quorum(q) - if !q.validation.is_empty() - && !q.ratification.is_empty() - && q.vote() != &Vote::NoCandidate => - { + Payload::Quorum(q) if !q.ratification.is_empty() => { tracing::debug!( event = "send quorum_msg", vote = %q.vote(), diff --git a/consensus/src/quorum/task.rs b/consensus/src/quorum/task.rs index f634d97004..46327f63dd 100644 --- a/consensus/src/quorum/task.rs +++ b/consensus/src/quorum/task.rs @@ -10,7 +10,7 @@ use crate::queue::Queue; use crate::user::committee::CommitteeSet; use crate::user::provisioners::Provisioners; use node_data::ledger::{to_str, Block, Certificate}; -use node_data::message::payload::Vote; +use node_data::message::payload::{RatificationResult, Vote}; use node_data::message::{AsyncQueue, Message, Payload, Status}; use crate::quorum::verifiers; @@ -158,14 +158,21 @@ impl<'p, D: Database> Executor<'p, D> { .await .ok()?; + debug!(event = "quorum_collected", ?quorum); + // Publish the quorum self.publish(msg.clone()).await; - if let Vote::Valid(hash) = quorum.vote() { - // Create winning block - debug!("generate block from quorum msg"); - let cert = quorum.generate_certificate(); - return self.create_winning_block(hash, &cert).await; + match &quorum.result { + RatificationResult::Success(Vote::Valid(hash)) => { + // Create winning block + debug!("generate block from quorum msg"); + let cert = quorum.generate_certificate(); + return self.create_winning_block(hash, &cert).await; + } + failed => { + debug!("Valid QUORUM for {failed:?}"); + } } } diff --git a/consensus/src/quorum/verifiers.rs b/consensus/src/quorum/verifiers.rs index 2ec87078ca..fe5d62270c 100644 --- a/consensus/src/quorum/verifiers.rs +++ b/consensus/src/quorum/verifiers.rs @@ -135,13 +135,14 @@ pub fn verify_votes( target_quorum, }; - if !quorum_result.quorum_reached() { + if vote != &Vote::NoQuorum && !quorum_result.quorum_reached() { tracing::error!( desc = "vote_set_too_small", committee = format!("{:#?}", sub_committee), bitset, target_quorum, total, + %vote ); return Err(StepSigError::VoteSetTooSmall); } diff --git a/consensus/src/ratification/handler.rs b/consensus/src/ratification/handler.rs index 87ec0b54de..4820fc1359 100644 --- a/consensus/src/ratification/handler.rs +++ b/consensus/src/ratification/handler.rs @@ -15,9 +15,7 @@ use crate::aggregator::Aggregator; use crate::iteration_ctx::RoundCommittees; use crate::quorum::verifiers::verify_votes; -use node_data::message::payload::{ - QuorumType, Ratification, ValidationResult, Vote, -}; +use node_data::message::payload::{Ratification, ValidationResult, Vote}; use node_data::message::{ payload, ConsensusHeader, Message, Payload, StepMessage, }; @@ -222,27 +220,19 @@ impl RatificationHandler { round_committees: &RoundCommittees, result: &ValidationResult, ) -> Result<(), ConsensusError> { - // TODO: Check all quorums - match result.quorum() { - QuorumType::Valid | QuorumType::NoCandidate => { - if let Some(validation_committee) = - round_committees.get_validation_committee(iter) - { - verify_votes( - header, - StepName::Validation, - result.vote(), - result.sv(), - validation_committee, - )?; - - return Ok(()); - } else { - error!("could not get validation committee"); - } - } - _ => {} - } - Err(ConsensusError::InvalidValidation(result.quorum())) + let validation_committee = round_committees + .get_validation_committee(iter) + .ok_or_else(|| { + error!("could not get validation committee"); + ConsensusError::InvalidValidation(result.quorum()) + })?; + verify_votes( + header, + StepName::Validation, + result.vote(), + result.sv(), + validation_committee, + )?; + Ok(()) } } diff --git a/consensus/src/step_votes_reg.rs b/consensus/src/step_votes_reg.rs index 6019aca993..edbc944186 100644 --- a/consensus/src/step_votes_reg.rs +++ b/consensus/src/step_votes_reg.rs @@ -175,7 +175,7 @@ impl CertInfoRegistry { fn build_quorum_msg( ru: &RoundUpdate, iteration: u8, - result: &CertificateInfo, + cert_info: &CertificateInfo, ) -> Message { let header = node_data::message::ConsensusHeader { prev_block_hash: ru.hash(), @@ -185,9 +185,9 @@ impl CertInfoRegistry { let payload = payload::Quorum { header, - result: result.result.clone(), - validation: result.cert.validation, - ratification: result.cert.ratification, + result: cert_info.result.clone(), + validation: cert_info.cert.validation, + ratification: cert_info.cert.ratification, }; Message::new_quorum(payload) diff --git a/node-data/src/message.rs b/node-data/src/message.rs index 1229db84c2..deaa6a6309 100644 --- a/node-data/src/message.rs +++ b/node-data/src/message.rs @@ -419,11 +419,11 @@ pub mod payload { #[cfg_attr(any(feature = "faker", test), derive(fake::Dummy))] #[repr(u8)] pub enum Vote { - #[default] NoCandidate = 0, Valid(Hash) = 1, Invalid(Hash) = 2, + #[default] NoQuorum = 3, }