Skip to content

Commit

Permalink
consensus: change sortition::Config::new
Browse files Browse the repository at this point in the history
- Remove `step`
- Remove `committee_size`
  • Loading branch information
herr-seppia committed Jan 8, 2024
1 parent 2cfafea commit 6401acb
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 47 deletions.
5 changes: 2 additions & 3 deletions consensus/src/execution_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,13 @@ impl<'a, DB: Database, T: Operations + 'static> ExecutionCtx<'a, DB, T> {

pub fn get_sortition_config(
&self,
size: usize,
exclusion: Option<PublicKeyBytes>,
) -> sortition::Config {
sortition::Config::new(
self.round_update.seed(),
self.round_update.round,
self.step(),
size,
self.iteration,
self.step_name(),
exclusion,
)
}
Expand Down
16 changes: 1 addition & 15 deletions consensus/src/phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ macro_rules! await_phase {
};
}

macro_rules! call_phase {
($e:expr, $n:ident ( $($args:expr), *)) => {
{
match $e {
Phase::Proposal(p) => p.$n($($args,)*),
Phase::Validation(p) => p.$n($($args,)*),
Phase::Ratification(p) => p.$n($($args,)*),
}
}
};
}

pub enum Phase<T: Operations, D: Database> {
Proposal(proposal::step::ProposalStep<T, D>),
Validation(validation::step::ValidationStep<T>),
Expand Down Expand Up @@ -74,8 +62,6 @@ impl<T: Operations + 'static, D: Database + 'static> Phase<T, D> {
let timeout = ctx.iter_ctx.get_timeout(ctx.step_name());
debug!(event = "execute_step", ?timeout);

let size = call_phase!(self, get_committee_size());

let exclusion = match ctx.step_name() {
StepName::Proposal => None,
_ => {
Expand All @@ -94,7 +80,7 @@ impl<T: Operations + 'static, D: Database + 'static> Phase<T, D> {
// block.
let step_committee = Committee::new(
ctx.provisioners,
&ctx.get_sortition_config(size, exclusion),
&ctx.get_sortition_config(exclusion),
);

debug!(
Expand Down
3 changes: 0 additions & 3 deletions consensus/src/proposal/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,4 @@ impl<T: Operations + 'static, D: Database> ProposalStep<T, D> {
pub fn name(&self) -> &'static str {
"sel"
}
pub fn get_committee_size(&self) -> usize {
config::PROPOSAL_COMMITTEE_SIZE
}
}
9 changes: 2 additions & 7 deletions consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::user::committee::{Committee, CommitteeSet};
use crate::user::sortition;
use bytes::Buf;

use crate::config;
use dusk_bytes::Serializable;
use node_data::bls::PublicKey;
use node_data::message::{marshal_signable_vote, Header, Message, Payload};
Expand Down Expand Up @@ -48,7 +47,6 @@ pub async fn verify_quorum(
seed,
&msg.header,
StepName::Validation,
config::VALIDATION_COMMITTEE_SIZE,
true,
)
.await
Expand All @@ -68,7 +66,6 @@ pub async fn verify_quorum(
seed,
&msg.header,
StepName::Ratification,
config::RATIFICATION_COMMITTEE_SIZE,
true,
)
.await
Expand All @@ -94,15 +91,13 @@ pub async fn verify_step_votes(
seed: Seed,
hdr: &Header,
step_name: StepName,
committee_size: usize,
enable_quorum_check: bool,
) -> Result<QuorumResult, Error> {
if step_name == StepName::Proposal {
return Err(Error::InvalidStepNum);
}

let iteration = hdr.iteration;
let step = step_name.to_step(iteration);
let generator = committees_set
.read()
.await
Expand All @@ -112,8 +107,8 @@ pub async fn verify_step_votes(
let cfg = sortition::Config::new(
seed,
hdr.round,
step,
committee_size,
hdr.iteration,
step_name,
Some(generator),
);

Expand Down
5 changes: 2 additions & 3 deletions consensus/src/ratification/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use tracing::{error, warn};

use crate::aggregator::Aggregator;

use crate::config;
use crate::iteration_ctx::RoundCommittees;
use crate::quorum::verifiers::verify_votes;
use node_data::message::payload::{QuorumType, Ratification, ValidationResult};
Expand Down Expand Up @@ -219,8 +218,8 @@ impl RatificationHandler {
let cfg = sortition::Config::new(
ru.seed(),
ru.round,
StepName::Validation.to_step(iter),
config::VALIDATION_COMMITTEE_SIZE,
iter,
StepName::Validation,
Some(generator),
);

Expand Down
5 changes: 0 additions & 5 deletions consensus/src/ratification/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::commons::{ConsensusError, Database, RoundUpdate};
use crate::config;
use crate::contract_state::Operations;
use crate::execution_ctx::ExecutionCtx;
use std::marker::PhantomData;
Expand Down Expand Up @@ -155,8 +154,4 @@ impl<T: Operations + 'static, DB: Database> RatificationStep<T, DB> {
pub fn name(&self) -> &'static str {
"ratification"
}

pub fn get_committee_size(&self) -> usize {
config::RATIFICATION_COMMITTEE_SIZE
}
}
7 changes: 3 additions & 4 deletions consensus/src/user/provisioners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::user::sortition;
use crate::user::stake::Stake;
use crate::{config::PROPOSAL_COMMITTEE_SIZE, user::sortition};
use node_data::bls::{PublicKey, PublicKeyBytes};
use node_data::StepName;

Expand Down Expand Up @@ -171,12 +171,11 @@ impl Provisioners {
seed: Seed,
round: u64,
) -> PublicKeyBytes {
let step = StepName::Proposal.to_step(iteration);
let cfg = sortition::Config::new(
seed,
round,
step,
PROPOSAL_COMMITTEE_SIZE,
iteration,
StepName::Proposal,
None,
);
let committee_keys = Committee::new(self, &cfg);
Expand Down
17 changes: 14 additions & 3 deletions consensus/src/user/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ use num_bigint::Sign::Plus;

use sha3::{Digest, Sha3_256};

use node_data::{bls::PublicKeyBytes, ledger::Seed};
use node_data::{bls::PublicKeyBytes, ledger::Seed, StepName};

use crate::config::{
PROPOSAL_COMMITTEE_SIZE, RATIFICATION_COMMITTEE_SIZE,
VALIDATION_COMMITTEE_SIZE,
};

#[derive(Debug, Clone, Default, Eq, Hash, PartialEq)]
pub struct Config {
Expand All @@ -24,10 +29,16 @@ impl Config {
pub fn new(
seed: Seed,
round: u64,
step: u16,
committee_size: usize,
iteration: u8,
step: StepName,
exclusion: Option<PublicKeyBytes>,
) -> Config {
let committee_size = match step {
StepName::Proposal => PROPOSAL_COMMITTEE_SIZE,
StepName::Ratification => RATIFICATION_COMMITTEE_SIZE,
StepName::Validation => VALIDATION_COMMITTEE_SIZE,
};
let step = step.to_step(iteration);
Self {
seed,
round,
Expand Down
4 changes: 0 additions & 4 deletions consensus/src/validation/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::commons::{ConsensusError, Database, RoundUpdate};
use crate::config;
use crate::contract_state::{CallParams, Operations};
use crate::execution_ctx::ExecutionCtx;
use crate::validation::handler;
Expand Down Expand Up @@ -220,7 +219,4 @@ impl<T: Operations + 'static> ValidationStep<T> {
pub fn name(&self) -> &'static str {
"validation"
}
pub fn get_committee_size(&self) -> usize {
config::VALIDATION_COMMITTEE_SIZE
}
}

0 comments on commit 6401acb

Please sign in to comment.