Skip to content

Commit

Permalink
fix(engine): is_fork header traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Oct 1, 2024
1 parent a8a380f commit d1ed0a2
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,28 +927,31 @@ where
/// extension of the canonical chain.
/// * walking back from the current head to verify that the target hash is not already part of
/// the canonical chain.
fn is_fork(&self, target_hash: B256, finalized_hash: Option<B256>) -> ProviderResult<bool> {
fn is_fork(&self, target_hash: B256, _finalized_hash: Option<B256>) -> ProviderResult<bool> {
// verify that the given hash is not part of an extension of the canon chain.
let canonical_head = self.state.tree_state.canonical_head();
let mut current_hash = target_hash;
while let Some(current_block) = self.sealed_header_by_hash(current_hash)? {
if current_block.hash() == self.state.tree_state.canonical_block_hash() {
if current_block.hash() == canonical_head.hash {
return Ok(false)
}
// We already passed the canonical head
if current_block.number <= canonical_head.number {
break
}
current_hash = current_block.parent_hash;
}

// verify that the given hash is not already part of the canon chain
current_hash = self.state.tree_state.canonical_block_hash();
while let Some(current_block) = self.sealed_header_by_hash(current_hash)? {
if Some(current_hash) == finalized_hash {
return Ok(true)
}
// verify that the given hash is not already part of canonical chain stored in memory
if self.canonical_in_memory_state.header_by_hash(target_hash).is_some() {
return Ok(false)
}

if current_block.hash() == target_hash {
return Ok(false)
}
current_hash = current_block.parent_hash;
// verify that the given hash is not already part of persisted canonical chain
if self.provider.block_number(target_hash)?.is_some() {
return Ok(false)
}

Ok(true)
}

Expand Down

0 comments on commit d1ed0a2

Please sign in to comment.