Skip to content

Commit

Permalink
consensus: check multiple quorums
Browse files Browse the repository at this point in the history
See also #1268
  • Loading branch information
herr-seppia committed Feb 12, 2024
1 parent 02f0f8d commit b761de2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
7 changes: 1 addition & 6 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
19 changes: 13 additions & 6 deletions consensus/src/quorum/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.ratification_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:?}");
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
40 changes: 15 additions & 25 deletions consensus/src/ratification/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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(())
}
}
8 changes: 4 additions & 4 deletions consensus/src/step_votes_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion node-data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,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,
}

Expand Down

0 comments on commit b761de2

Please sign in to comment.