Skip to content

Commit

Permalink
Rotate the proposer each height and round
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Feb 27, 2024
1 parent d77f9cf commit 6c47d84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions code/node/src/util/make_node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;
use std::time::Duration;

use malachite_test::utils::FixedProposer;
use malachite_test::utils::RotateProposer;
use malachite_test::{Address, Height, PrivateKey, TestContext, ValidatorSet};

use crate::network::broadcast;
Expand All @@ -20,7 +20,7 @@ pub async fn make_broadcast_node(
) -> Node<TestContext, broadcast::Handle> {
let start_height = Height::new(1);
let ctx = TestContext::new(private_key);
let proposer_selector = Arc::new(FixedProposer::new(validator_set.validators[0].address));
let proposer_selector = Arc::new(RotateProposer);
let proposal_builder = Arc::new(TestValueBuilder::default());

let params = Params {
Expand Down Expand Up @@ -65,7 +65,7 @@ pub async fn make_gossip_node(

let start_height = Height::new(1);
let ctx = TestContext::new(private_key);
let proposer_selector = Arc::new(FixedProposer::new(validator_set.validators[0].address));
let proposer_selector = Arc::new(RotateProposer);
let proposal_builder = Arc::new(TestValueBuilder::default());

let params = Params {
Expand Down
9 changes: 7 additions & 2 deletions code/test/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ pub struct RotateProposer;
impl ProposerSelector<TestContext> for RotateProposer {
fn select_proposer(
&self,
_height: Height,
height: Height,
round: Round,
validator_set: &ValidatorSet,
) -> Address {
let proposer_index = round.as_i64() as usize % validator_set.validators.len();
assert!(round != Round::Nil && round.as_i64() >= 0);

let height = height.as_u64() as usize;
let round = round.as_i64() as usize;

let proposer_index = (height - 1 + round) % validator_set.validators.len();
validator_set.validators[proposer_index].address
}
}
Expand Down

0 comments on commit 6c47d84

Please sign in to comment.