Skip to content

Commit

Permalink
fix(core): calling CheckPoint::insert with existing block must succeed
Browse files Browse the repository at this point in the history
Previously, we were panicing when the caller tried to insert a block at
height 0. However, this should succeed if the block hash does not
change.
  • Loading branch information
evanlinjin committed Sep 12, 2024
1 parent 8760653 commit 34fa146
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions crates/core/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ impl CheckPoint {
/// passed in. Of course, if the `block_id` was already present then this just returns `self`.
#[must_use]
pub fn insert(self, block_id: BlockId) -> Self {
assert_ne!(block_id.height, 0, "cannot insert the genesis block");

let mut cp = self.clone();
let mut tail = vec![];
let base = loop {
if cp.height() == block_id.height {
if cp.hash() == block_id.hash {
return self;
}
assert_ne!(cp.height(), 0, "cannot replace genesis block");
// if we have a conflict we just return the inserted block because the tail is by
// implication invalid.
tail = vec![];
Expand Down

0 comments on commit 34fa146

Please sign in to comment.