Skip to content

Commit 34fa146

Browse files
committed
fix(core): calling CheckPoint::insert with existing block must succeed
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.
1 parent 8760653 commit 34fa146

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

crates/core/src/checkpoint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,14 @@ impl CheckPoint {
173173
/// passed in. Of course, if the `block_id` was already present then this just returns `self`.
174174
#[must_use]
175175
pub fn insert(self, block_id: BlockId) -> Self {
176-
assert_ne!(block_id.height, 0, "cannot insert the genesis block");
177-
178176
let mut cp = self.clone();
179177
let mut tail = vec![];
180178
let base = loop {
181179
if cp.height() == block_id.height {
182180
if cp.hash() == block_id.hash {
183181
return self;
184182
}
183+
assert_ne!(cp.height(), 0, "cannot replace genesis block");
185184
// if we have a conflict we just return the inserted block because the tail is by
186185
// implication invalid.
187186
tail = vec![];

0 commit comments

Comments
 (0)