Skip to content

Commit

Permalink
fix: edge case on not reorg to better height (#175)
Browse files Browse the repository at this point in the history
Description
---
Fixes an edge case where a node will not reorg after it filled in the
blocks between a tip and start.
  • Loading branch information
SWvheerden authored Nov 21, 2024
1 parent 1c6f009 commit 1bd932e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/sharechain/p2chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,22 @@ impl P2Chain {
let mut next_level_data = Vec::new();

// let see if we already have a block that builds on top of this
if let Some(next_level) = self.level_at_height(new_block_height + 1) {
let mut checking_height = new_block_height + 1;
while let Some(next_level) = self.level_at_height(checking_height) {
// we have a height here, lets check the blocks
let mut found_child = false;
for block in next_level.blocks.iter() {
if block.1.prev_hash == hash {
next_level_data.push((next_level.height, *block.0));
found_child = true;
break;
}
}
// if we did not find a next parent to check, then we can break
if !found_child {
break;
}
checking_height += 1;
}

// let search if this block is an uncle of some higher block
Expand Down

0 comments on commit 1bd932e

Please sign in to comment.