Skip to content

Commit

Permalink
Fix committee selection on small node counts
Browse files Browse the repository at this point in the history
  • Loading branch information
daltoncoder committed Sep 18, 2023
1 parent da9a6d8 commit 0bb3262
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions core/application/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,13 @@ impl<B: Backend> State<B> {
Some(Value::Epoch(epoch)) => epoch,
_ => 0,
};
let num_of_nodes = match self.metadata.get(&Metadata::NextNodeIndex) {
Some(Value::NextNodeIndex(index)) => index,
_ => 0,
};

let mut node_registry: Vec<NodeIndex> = self.get_node_registry().keys().copied().collect();
let committee_size = self.parameters.get(&ProtocolParams::CommitteeSize).unwrap();
let num_of_nodes = node_registry.len() as u128;
// if total number of nodes are less than committee size, all nodes are part of committee
if committee_size >= num_of_nodes.into() {
return (0..num_of_nodes).collect();
return node_registry;
}

let committee = self.committee_info.get(&epoch).unwrap();
Expand All @@ -1163,7 +1162,6 @@ impl<B: Backend> State<B> {
let mut seed = [0u8; 32];
seed.copy_from_slice(&result.as_bytes()[0..32]);
let mut rng: StdRng = SeedableRng::from_seed(seed);
let mut node_registry: Vec<NodeIndex> = self.get_node_registry().keys().copied().collect();
node_registry.shuffle(&mut rng);
node_registry
.into_iter()
Expand Down

0 comments on commit 0bb3262

Please sign in to comment.