Skip to content

Commit

Permalink
[dag][bugfix] fix bitmask for incomplete first round
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalajiarun committed Aug 24, 2023
1 parent 644e1b1 commit 178b9f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions consensus/src/dag/dag_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ impl Dag {
}

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

for (round, round_nodes) in &self.nodes_by_round {
if round_nodes.iter().any(|node| node.is_none()) {
return Some(*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 178b9f5

Please sign in to comment.