Skip to content

Commit

Permalink
code: Address some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Dec 8, 2023
1 parent db5f756 commit a6afbb9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 36 deletions.
2 changes: 0 additions & 2 deletions Code/common/src/validator_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use core::fmt::{Debug, Display};
use crate::{Context, PublicKey};

/// Voting power held by a validator.
///
/// TODO: Do we need to abstract over this as well?
pub type VotingPower = u64;

/// Defines the requirements for an address.
Expand Down
6 changes: 2 additions & 4 deletions Code/driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ where
proposer_selector: impl ProposerSelector<Ctx> + 'static,
validator_set: Ctx::ValidatorSet,
address: Ctx::Address,
threshold_params: ThresholdParams,
) -> Self {
let votes = VoteKeeper::new(
validator_set.total_voting_power(),
ThresholdParams::default(), // TODO: Make this configurable
);
let votes = VoteKeeper::new(validator_set.total_voting_power(), threshold_params);

Self {
ctx,
Expand Down
5 changes: 0 additions & 5 deletions Code/test/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ pub fn propose_state_with_proposal_and_valid(
valid_round: Round,
proposal: Proposal,
) -> State<TestContext> {
// TODO - set_valid doesn't work because the valid round is set to state round
// we need to set it to something different.
// propose_state(round)
// .set_proposal(proposal.clone())
// .set_valid(proposal.value)
State {
height: Height::new(1),
round: state_round,
Expand Down
3 changes: 1 addition & 2 deletions Code/test/src/validator_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ impl ValidatorSet {

/// The total voting power of the validator set
pub fn total_voting_power(&self) -> VotingPower {
// TODO: Cache this?
self.validators.iter().map(|v| v.voting_power).sum()
}

Expand Down Expand Up @@ -115,7 +114,7 @@ impl ValidatorSet {
pub fn remove(&mut self, address: &Address) {
self.validators.retain(|v| &v.address != address);

Self::sort_validators(&mut self.validators); // TODO: Not needed
Self::sort_validators(&mut self.validators);
}

/// Get a validator by its address
Expand Down
26 changes: 13 additions & 13 deletions Code/test/tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn driver_steps_proposer() {
let sel = FixedProposer::new(my_addr);
let vs = ValidatorSet::new(vec![v1, v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let proposal = Proposal::new(Height::new(1), Round::new(0), value, Round::new(-1));

Expand Down Expand Up @@ -218,7 +218,7 @@ fn driver_steps_proposer_timeout_get_value() {
let sel = FixedProposer::new(my_addr);
let vs = ValidatorSet::new(vec![v1, v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -270,7 +270,7 @@ fn driver_steps_not_proposer_valid() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let proposal = Proposal::new(Height::new(1), Round::new(0), value, Round::new(-1));

Expand Down Expand Up @@ -439,7 +439,7 @@ fn driver_steps_not_proposer_invalid() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let proposal = Proposal::new(Height::new(1), Round::new(0), value, Round::new(-1));

Expand Down Expand Up @@ -548,7 +548,7 @@ fn driver_steps_not_proposer_other_height() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

// Proposal is for another height
let proposal = Proposal::new(Height::new(2), Round::new(0), value, Round::new(-1));
Expand Down Expand Up @@ -598,7 +598,7 @@ fn driver_steps_not_proposer_other_round() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

// Proposal is for another round
let proposal = Proposal::new(Height::new(1), Round::new(1), value, Round::new(-1));
Expand Down Expand Up @@ -648,7 +648,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
// Start round 0, we, v3, are not the proposer
Expand Down Expand Up @@ -820,7 +820,7 @@ fn driver_steps_no_value_to_propose() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let mut outputs = block_on(driver.process(Input::NewRound(Height::new(1), Round::new(0))))
.expect("execute succeeded");
Expand Down Expand Up @@ -848,7 +848,7 @@ fn driver_steps_proposer_not_found() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let output = block_on(driver.process(Input::NewRound(Height::new(1), Round::new(0))));
assert_eq!(output, Err(Error::ProposerNotFound(v1.address)));
Expand All @@ -868,7 +868,7 @@ fn driver_steps_validator_not_found() {
// We omit v2 from the validator set
let vs = ValidatorSet::new(vec![v1.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

// Start new height
block_on(driver.process(Input::NewRound(Height::new(1), Round::new(0))))
Expand All @@ -894,7 +894,7 @@ fn driver_steps_invalid_signature() {
let sel = FixedProposer::new(v1.address);
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

// Start new round
block_on(driver.process(Input::NewRound(Height::new(1), Round::new(0))))
Expand Down Expand Up @@ -924,7 +924,7 @@ fn driver_steps_skip_round_skip_threshold() {
let height = Height::new(1);

let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);
let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
// Start round 0, we, v3, are not the proposer
Expand Down Expand Up @@ -1023,7 +1023,7 @@ fn driver_steps_skip_round_quorum_threshold() {
let height = Height::new(1);

let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);
let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
// Start round 0, we, v3, are not the proposer
Expand Down
19 changes: 9 additions & 10 deletions Code/test/tests/driver_extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use malachite_test::utils::*;
// - L34 with previously received polkaAny and entering prevote (due to received poposal)
// `driver_steps_polka_any_then_proposal_other()`

// TODO - move all below to utils?
struct TestStep {
desc: &'static str,
input: Input<TestContext>,
Expand Down Expand Up @@ -79,7 +78,7 @@ fn driver_steps_decide_current_with_no_locked_no_valid() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -151,7 +150,7 @@ fn driver_steps_decide_previous_with_no_locked_no_valid() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -251,7 +250,7 @@ fn driver_steps_decide_previous_with_locked_and_valid() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -371,7 +370,7 @@ fn driver_steps_polka_previous_with_locked() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -478,7 +477,7 @@ fn driver_steps_polka_previous_invalid_proposal() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -576,7 +575,7 @@ fn driver_steps_polka_previous_with_no_locked() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -684,7 +683,7 @@ fn driver_steps_polka_nil_and_timout_propose() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -744,7 +743,7 @@ fn driver_steps_polka_value_then_proposal() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down Expand Up @@ -807,7 +806,7 @@ fn driver_steps_polka_any_then_proposal_other() {
let sel = RotateProposer;
let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);

let mut driver = Driver::new(ctx, sel, vs, my_addr);
let mut driver = Driver::new(ctx, sel, vs, my_addr, Default::default());

let steps = vec![
TestStep {
Expand Down

0 comments on commit a6afbb9

Please sign in to comment.