Skip to content

Commit 613e4e5

Browse files
Soubhik-10Aideepakchaudharymattsse
authored
chore: invoke invalid block hook for new invalid blocks (paradigmxyz#14776)
Co-authored-by: Aideepakchaudhary <aideepakchaudhary@gmail.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
1 parent 89e3e55 commit 613e4e5

File tree

1 file changed

+19
-9
lines changed
  • crates/engine/tree/src/tree

1 file changed

+19
-9
lines changed

crates/engine/tree/src/tree/mod.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub use invalid_headers::InvalidHeaderCache;
8383
pub use payload_processor::*;
8484
pub use persistence_state::PersistenceState;
8585
pub use reth_engine_primitives::TreeConfig;
86+
use reth_evm::execute::BlockExecutionOutput;
8687

8788
/// The largest gap for which the tree will be used for sync. See docs for `pipeline_run_threshold`
8889
/// for more information.
@@ -2203,6 +2204,21 @@ where
22032204
}
22042205
}
22052206

2207+
/// Invoke the invalid block hook if this is a new invalid block.
2208+
fn on_invalid_block(
2209+
&mut self,
2210+
parent_header: &SealedHeader<N::BlockHeader>,
2211+
block: &RecoveredBlock<N::Block>,
2212+
output: &BlockExecutionOutput<N::Receipt>,
2213+
trie_updates: Option<(&TrieUpdates, B256)>,
2214+
) {
2215+
if self.state.invalid_headers.get(&block.hash()).is_some() {
2216+
// we already marked this block as invalid
2217+
return;
2218+
}
2219+
self.invalid_block_hook.on_invalid_block(parent_header, block, output, trie_updates);
2220+
}
2221+
22062222
/// This handles downloaded blocks that are shown to be disconnected from the canonical chain.
22072223
///
22082224
/// This mainly compares the missing parent of the downloaded block with the current canonical
@@ -2314,7 +2330,6 @@ where
23142330
.map_err(|kind| InsertBlockError::new(block.into_sealed_block(), kind))
23152331
}
23162332

2317-
#[allow(unused)]
23182333
fn insert_block_inner(
23192334
&mut self,
23202335
block: RecoveredBlock<N::Block>,
@@ -2432,7 +2447,7 @@ where
24322447

24332448
if let Err(err) = self.consensus.validate_block_post_execution(&block, &output) {
24342449
// call post-block hook
2435-
self.invalid_block_hook.on_invalid_block(&parent_block, &block, &output, None);
2450+
self.on_invalid_block(&parent_block, &block, &output, None);
24362451
return Err(err.into())
24372452
}
24382453

@@ -2443,7 +2458,7 @@ where
24432458
.validate_block_post_execution_with_hashed_state(&hashed_state, &block)
24442459
{
24452460
// call post-block hook
2446-
self.invalid_block_hook.on_invalid_block(&parent_block, &block, &output, None);
2461+
self.on_invalid_block(&parent_block, &block, &output, None);
24472462
return Err(err.into())
24482463
}
24492464

@@ -2517,12 +2532,7 @@ where
25172532
// ensure state root matches
25182533
if state_root != block.header().state_root() {
25192534
// call post-block hook
2520-
self.invalid_block_hook.on_invalid_block(
2521-
&parent_block,
2522-
&block,
2523-
&output,
2524-
Some((&trie_output, state_root)),
2525-
);
2535+
self.on_invalid_block(&parent_block, &block, &output, Some((&trie_output, state_root)));
25262536
return Err(ConsensusError::BodyStateRootDiff(
25272537
GotExpected { got: state_root, expected: block.header().state_root() }.into(),
25282538
)

0 commit comments

Comments
 (0)