reth_engine_tree/tree/
invalid_block_hook.rs

1use alloy_primitives::B256;
2use reth_engine_primitives::InvalidBlockHook;
3use reth_primitives_traits::{NodePrimitives, RecoveredBlock, SealedHeader};
4use reth_provider::BlockExecutionOutput;
5use reth_trie::updates::TrieUpdates;
6
7/// A no-op [`InvalidBlockHook`] that does nothing.
8#[derive(Debug, Default)]
9#[non_exhaustive]
10pub struct NoopInvalidBlockHook;
11
12impl<N: NodePrimitives> InvalidBlockHook<N> for NoopInvalidBlockHook {
13    fn on_invalid_block(
14        &self,
15        _parent_header: &SealedHeader<N::BlockHeader>,
16        _block: &RecoveredBlock<N::Block>,
17        _output: &BlockExecutionOutput<N::Receipt>,
18        _trie_updates: Option<(&TrieUpdates, B256)>,
19    ) {
20    }
21}
22
23/// Multiple [`InvalidBlockHook`]s that are executed in order.
24pub struct InvalidBlockHooks<N: NodePrimitives>(pub Vec<Box<dyn InvalidBlockHook<N>>>);
25
26impl<N: NodePrimitives> std::fmt::Debug for InvalidBlockHooks<N> {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        f.debug_struct("InvalidBlockHooks").field("len", &self.0.len()).finish()
29    }
30}
31
32impl<N: NodePrimitives> InvalidBlockHook<N> for InvalidBlockHooks<N> {
33    fn on_invalid_block(
34        &self,
35        parent_header: &SealedHeader<N::BlockHeader>,
36        block: &RecoveredBlock<N::Block>,
37        output: &BlockExecutionOutput<N::Receipt>,
38        trie_updates: Option<(&TrieUpdates, B256)>,
39    ) {
40        for hook in &self.0 {
41            hook.on_invalid_block(parent_header, block, output, trie_updates);
42        }
43    }
44}