Skip to content

Commit

Permalink
[dag][bugfix] fix bitmask for incomplete first round (#9723)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalajiarun authored Aug 24, 2023
1 parent b806bf1 commit cf625f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions consensus/src/dag/dag_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,22 @@ impl Dag {
}
}

pub fn lowest_incomplete_round(&self) -> Option<Round> {
pub fn lowest_incomplete_round(&self) -> Round {
if self.nodes_by_round.is_empty() {
return self.lowest_round();
}

for (round, round_nodes) in &self.nodes_by_round {
if round_nodes.iter().any(|node| node.is_none()) {
return Some(*round);
return *round;
}
}
None

self.highest_round() + 1
}

pub fn bitmask(&self, target_round: Round) -> DagSnapshotBitmask {
let lowest_round = match self.lowest_incomplete_round() {
Some(round) => round,
None => {
return DagSnapshotBitmask::new(self.highest_round() + 1, vec![]);
},
};
let lowest_round = self.lowest_incomplete_round();

let bitmask = self
.nodes_by_round
Expand Down
5 changes: 2 additions & 3 deletions consensus/src/dag/tests/dag_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,14 @@ fn test_dag_recover_from_storage() {
fn test_dag_bitmask() {
let (signers, epoch_state, mut dag, _) = setup();

let mut metadatas = vec![];
assert_eq!(dag.bitmask(15), DagSnapshotBitmask::new(1, vec![]));

for round in 1..5 {
let parents = dag
.get_strong_links_for_round(round, &epoch_state.verifier)
.unwrap_or_default();
for signer in &signers[0..3] {
let node = new_certified_node(round, signer.author(), parents.clone());
metadatas.push(node.metadata().clone());
assert!(dag.add_node(node).is_ok());
}
}
Expand All @@ -226,12 +225,12 @@ fn test_dag_bitmask() {
DagSnapshotBitmask::new(1, vec![vec![true, true, true, false]; 4])
);

// Populate the fourth author for all rounds
for round in 1..5 {
let parents = dag
.get_strong_links_for_round(round, &epoch_state.verifier)
.unwrap_or_default();
let node = new_certified_node(round, signers[3].author(), parents.clone());
metadatas.push(node.metadata().clone());
assert!(dag.add_node(node).is_ok());
}
assert_eq!(dag.bitmask(15), DagSnapshotBitmask::new(5, vec![]));
Expand Down

0 comments on commit cf625f6

Please sign in to comment.