Skip to content

Commit

Permalink
Simulation branch with one committee fix (#402)
Browse files Browse the repository at this point in the history
* Tree and branch overlay comparison tests

* Update leader super majority fn in branch overlay

* Cleanup tests
  • Loading branch information
bacv authored Sep 15, 2023
1 parent 8449c81 commit 70dc4f3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
5 changes: 3 additions & 2 deletions consensus-engine/src/overlay/branch_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ where
(committee_size * 2 / 3) + 1
}

fn leader_super_majority_threshold(&self, id: NodeId) -> usize {
self.super_majority_threshold(id)
fn leader_super_majority_threshold(&self, _id: NodeId) -> usize {
let committee_size = self.root_committee().len();
(committee_size * 2 / 3) + 1
}

fn update_leader_selection<F, E>(&self, f: F) -> Result<Self, E>
Expand Down
61 changes: 61 additions & 0 deletions consensus-engine/src/overlay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,64 @@ pub trait LeaderSelection: Clone {
pub trait CommitteeMembership: Clone {
fn reshape_committees(&self, nodes: &mut [NodeId]);
}

#[cfg(test)]
mod tests {
use super::*;
use crate::overlay::{FisherYatesShuffle, RoundRobin};

const ENTROPY: [u8; 32] = [0; 32];

fn overlay_fns_match(a: &impl Overlay, b: &impl Overlay, nodes: &[NodeId]) {
assert_eq!(a.root_committee(), b.root_committee());
assert_eq!(
a.is_member_of_child_committee(nodes[0], nodes[1]),
b.is_member_of_child_committee(nodes[0], nodes[1]),
);
assert_eq!(
a.is_member_of_root_committee(nodes[0]),
b.is_member_of_root_committee(nodes[0]),
);
assert_eq!(
a.is_member_of_leaf_committee(nodes[0]),
b.is_member_of_leaf_committee(nodes[0]),
);
assert_eq!(
a.is_child_of_root_committee(nodes[0]),
b.is_child_of_root_committee(nodes[0])
);
assert_eq!(a.parent_committee(nodes[0]), b.parent_committee(nodes[0]));
assert_eq!(a.child_committees(nodes[0]), b.child_committees(nodes[0]));
assert_eq!(a.leaf_committees(nodes[0]), b.leaf_committees(nodes[0]));
assert_eq!(a.node_committee(nodes[0]), b.node_committee(nodes[0]));
assert_eq!(
a.super_majority_threshold(nodes[0]),
b.super_majority_threshold(nodes[0])
);
assert_eq!(
a.leader_super_majority_threshold(nodes[0]),
b.leader_super_majority_threshold(nodes[0])
);
}

#[test]
fn compare_tree_branch_one_committee() {
let nodes: Vec<_> = (0..10).map(|i| NodeId::new([i as u8; 32])).collect();
let tree_overlay = TreeOverlay::new(TreeOverlaySettings {
nodes: nodes.clone(),
current_leader: nodes[0],
number_of_committees: 1,
leader: RoundRobin::new(),
committee_membership: FisherYatesShuffle::new(ENTROPY),
});
let branch_overlay = BranchOverlay::new(BranchOverlaySettings {
current_leader: nodes[0],
nodes: nodes.clone(),
branch_depth: 1,
leader: RoundRobin::new(),
committee_membership: FisherYatesShuffle::new(ENTROPY),
});

overlay_fns_match(&tree_overlay, &branch_overlay, &nodes);
}
}

0 comments on commit 70dc4f3

Please sign in to comment.