Skip to content

Commit

Permalink
Merge pull request #1848 from dusk-network/1208-consensus-update-cert…
Browse files Browse the repository at this point in the history
…ificate-and-committee-related-terminology

consensus: Update Consensus naming system
  • Loading branch information
fed-franz authored Jun 13, 2024
2 parents 8ea08b0 + 85fea81 commit 37d55eb
Show file tree
Hide file tree
Showing 28 changed files with 326 additions and 323 deletions.
8 changes: 4 additions & 4 deletions consensus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ let mut consensus = Consensus::new(
Arc::new(Mutex::new(crate::mocks::SimpleDB::default())),
);

let mut most_recent_block = Block::default();
let mut tip = Block::default();

loop {
/// Provisioners list is retrieved from contract storage state.
let provisioners = rusk::get_provisioners();

// Round update is the input data for any consensus round execution.
// Round update includes mostly data from most recent block.
let round_update = from(most_recent_block);
// Round update includes mostly data from the tip.
let round_update = from(tip);

/// Consensus::Spin call initializes a consensus round
/// and spawns main consensus tokio::tasks.
Expand All @@ -76,7 +76,7 @@ loop {
// Max Step Reached - happens only if no consensus is reached for up to 213 steps/71 iterations.
}
}
most_recent_block = winner;
tip = winner;

/// Internally, consensus instance may accept future messages for next round.
/// They will be drained on running the round, that's why same consensus instance is used for all round executions.
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ mod tests {
// Also populate a vector of headers
let mut p = Provisioners::empty();
let mut input = vec![];
let mut mrb_header = Header::default();
mrb_header.height = 0;
let mut tip_header = Header::default();
tip_header.height = 0;

for secret_key in sks {
let pubkey_bls = node_data::bls::PublicKey::new(
Expand All @@ -247,7 +247,7 @@ mod tests {
let ru = RoundUpdate::new(
pubkey_bls,
secret_key,
&mrb_header,
&tip_header,
HashMap::new(),
);

Expand Down
22 changes: 11 additions & 11 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct RoundUpdate {

seed: Seed,
hash: [u8; 32],
cert: Certificate,
att: Attestation,

pub base_timeouts: TimeoutSet,
}
Expand All @@ -42,17 +42,17 @@ impl RoundUpdate {
pub fn new(
pubkey_bls: PublicKey,
secret_key: StakeSecretKey,
mrb_header: &Header,
tip_header: &Header,
base_timeouts: TimeoutSet,
) -> Self {
let round = mrb_header.height + 1;
let round = tip_header.height + 1;
RoundUpdate {
round,
pubkey_bls,
secret_key,
cert: mrb_header.cert,
hash: mrb_header.hash,
seed: mrb_header.seed,
att: tip_header.att,
hash: tip_header.hash,
seed: tip_header.seed,
base_timeouts,
}
}
Expand All @@ -65,8 +65,8 @@ impl RoundUpdate {
self.hash
}

pub fn cert(&self) -> &Certificate {
&self.cert
pub fn att(&self) -> &Attestation {
&self.att
}
}

Expand Down Expand Up @@ -141,14 +141,14 @@ impl QuorumMsgSender {
/// Sends an quorum (internally) to the lower layer.
pub(crate) async fn send_quorum(&self, msg: Message) {
match &msg.payload {
Payload::Quorum(q) if !q.cert.ratification.is_empty() => {
Payload::Quorum(q) if !q.att.ratification.is_empty() => {
tracing::debug!(
event = "send quorum_msg",
vote = ?q.vote(),
round = msg.header.round,
iteration = msg.header.iteration,
validation = ?q.cert.validation,
ratification = ?q.cert.ratification,
validation = ?q.att.validation,
ratification = ?q.att.ratification,
);
}
_ => return,
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub const CONSENSUS_ROLLING_FINALITY_THRESHOLD: u64 = 20;
pub const SUPERMAJORITY_THRESHOLD: f64 = 0.67;
pub const MAJORITY_THRESHOLD: f64 = 0.5;

/// Steps committee sizes
pub const PROPOSAL_COMMITTEE_SIZE: usize = 1;
pub const VALIDATION_COMMITTEE_SIZE: usize = 64;
pub const RATIFICATION_COMMITTEE_SIZE: usize = 64;
/// Total credits of steps committees
pub const PROPOSAL_COMMITTEE_CREDITS: usize = 1;
pub const VALIDATION_COMMITTEE_CREDITS: usize = 64;
pub const RATIFICATION_COMMITTEE_CREDITS: usize = 64;

/// Artifical delay on each Proposal step.
/// Artificial delay on each Proposal step.
pub const CONSENSUS_DELAY_MS: u64 = 1000;

pub const DEFAULT_BLOCK_GAS_LIMIT: u64 = 5 * 1_000_000_000;
Expand Down
5 changes: 2 additions & 3 deletions consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use crate::{ratification, validation};
use tracing::{debug, info, Instrument};

use crate::iteration_ctx::IterationCtx;
use crate::step_votes_reg::CertInfoRegistry;

use crate::step_votes_reg::AttInfoRegistry;
use std::env;
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -141,7 +140,7 @@ impl<T: Operations + 'static, D: Database + 'static> Consensus<T, D> {
}

let sv_registry =
Arc::new(Mutex::new(CertInfoRegistry::new(ru.clone())));
Arc::new(Mutex::new(AttInfoRegistry::new(ru.clone())));

let proposal_handler = Arc::new(Mutex::new(
proposal::handler::ProposalHandler::new(db.clone()),
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/execution_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::iteration_ctx::IterationCtx;
use crate::msg_handler::{HandleMsgOutput, MsgHandler};
use crate::operations::Operations;
use crate::queue::MsgRegistry;
use crate::step_votes_reg::SafeCertificateInfoRegistry;
use crate::step_votes_reg::SafeAttestationInfoRegistry;
use crate::user::committee::Committee;
use crate::user::provisioners::Provisioners;
use crate::user::sortition;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub struct ExecutionCtx<'a, DB: Database, T> {

pub client: Arc<Mutex<T>>,

pub sv_registry: SafeCertificateInfoRegistry,
pub sv_registry: SafeAttestationInfoRegistry,
quorum_sender: QuorumMsgSender,
}

Expand All @@ -69,7 +69,7 @@ impl<'a, DB: Database, T: Operations + 'static> ExecutionCtx<'a, DB, T> {
iteration: u8,
step: StepName,
client: Arc<Mutex<T>>,
sv_registry: SafeCertificateInfoRegistry,
sv_registry: SafeAttestationInfoRegistry,
quorum_sender: QuorumMsgSender,
) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait Operations: Send + Sync {
async fn verify_block_header(
&self,
candidate_header: &Header,
disable_winning_cert_check: bool,
disable_winning_att_check: bool,
) -> Result<(), Error>;

async fn verify_state_transition(
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::commons::{get_current_timestamp, RoundUpdate};
use crate::operations::{CallParams, Operations};
use node_data::ledger::{to_str, Block, Certificate, IterationsInfo, Seed};
use node_data::ledger::{to_str, Attestation, Block, IterationsInfo, Seed};

use crate::config;
use crate::merkle::merkle_root;
Expand Down Expand Up @@ -117,8 +117,8 @@ impl<T: Operations> Generator<T> {
state_hash: result.verification_output.state_root,
event_hash: result.verification_output.event_hash,
hash: [0; 32],
cert: Certificate::default(),
prev_block_cert: *ru.cert(),
att: Attestation::default(),
prev_block_cert: *ru.att(),
txroot,
iteration,
failed_iterations,
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/proposal/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ impl<T: Operations + 'static, D: Database> ProposalStep<T, D> {
let iteration =
cmp::min(config::RELAX_ITERATION_THRESHOLD, ctx.iteration);

// Fetch failed certificates from sv_registry
let failed_certificates =
ctx.sv_registry.lock().await.get_failed_certs(iteration);
// Fetch failed attestations from sv_registry
let failed_attestations =
ctx.sv_registry.lock().await.get_failed_atts(iteration);

if let Ok(msg) = self
.bg
.generate_candidate_message(
&ctx.round_update,
ctx.iteration,
IterationsInfo::new(failed_certificates),
IterationsInfo::new(failed_attestations),
)
.await
{
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn verify_quorum(
verify_step_votes(
&quorum.header,
quorum.vote(),
&quorum.cert.validation,
&quorum.att.validation,
committees_set,
seed,
StepName::Validation,
Expand All @@ -39,7 +39,7 @@ pub async fn verify_quorum(
.map_err(|e| {
error!(
desc = "invalid validation",
sv = ?quorum.cert.validation,
sv = ?quorum.att.validation,
hdr = ?quorum.header,
);
e
Expand All @@ -49,7 +49,7 @@ pub async fn verify_quorum(
verify_step_votes(
&quorum.header,
quorum.vote(),
&quorum.cert.ratification,
&quorum.att.ratification,
committees_set,
seed,
StepName::Ratification,
Expand All @@ -58,7 +58,7 @@ pub async fn verify_quorum(
.map_err(|e| {
error!(
desc = "invalid ratification",
sv = ?quorum.cert.ratification,
sv = ?quorum.att.ratification,
hdr = ?quorum.header,
);
e
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn verify_votes(
}

// If bitset=0 this means that we are checking for failed iteration
// certificates. If a winning certificate is checked with bitset=0 it will
// attestations. If a winning attestation is checked with bitset=0 it will
// fail to pass the quorum and results in VoteSetTooSmall.
// FIXME: Anyway this should be handled properly, maybe with a different
// function
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/ratification/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use crate::commons::{ConsensusError, RoundUpdate};
use crate::msg_handler::{HandleMsgOutput, MsgHandler};
use crate::step_votes_reg::SafeCertificateInfoRegistry;
use crate::step_votes_reg::SafeAttestationInfoRegistry;
use async_trait::async_trait;
use node_data::ledger::Certificate;
use node_data::ledger::Attestation;
use node_data::{ledger, StepName};
use tracing::{error, warn};

Expand All @@ -24,7 +24,7 @@ use node_data::message::{
use crate::user::committee::Committee;

pub struct RatificationHandler {
pub(crate) sv_registry: SafeCertificateInfoRegistry,
pub(crate) sv_registry: SafeAttestationInfoRegistry,

pub(crate) aggregator: Aggregator,
validation_result: ValidationResult,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl MsgHandler for RatificationHandler {
}

impl RatificationHandler {
pub(crate) fn new(sv_registry: SafeCertificateInfoRegistry) -> Self {
pub(crate) fn new(sv_registry: SafeAttestationInfoRegistry) -> Self {
Self {
sv_registry,
aggregator: Default::default(),
Expand All @@ -197,7 +197,7 @@ impl RatificationHandler {

let quorum = payload::Quorum {
header,
cert: Certificate {
att: Attestation {
result: vote.into(),
validation,
ratification,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/ratification/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<T: Operations + 'static, DB: Database> RatificationStep<T, DB> {
// There are these possible outputs:
// - Quorum on Valid Candidate
// - (unsupported) Quorum on Invalid Candidate
// - Quorum on Timeout (NilQuorum)
// - Quorum on Timeout
// - No Quorum (Validation step time-ed out)
match msg.payload {
Payload::ValidationResult(p) => handler.reset(iteration, *p),
Expand Down
Loading

0 comments on commit 37d55eb

Please sign in to comment.