reth_engine_primitives/
event.rs1use crate::ForkchoiceStatus;
4use alloc::boxed::Box;
5use alloy_consensus::BlockHeader;
6use alloy_eips::BlockNumHash;
7use alloy_primitives::B256;
8use alloy_rpc_types_engine::ForkchoiceState;
9use core::{
10 fmt::{Display, Formatter, Result},
11 time::Duration,
12};
13use reth_chain_state::ExecutedBlockWithTrieUpdates;
14use reth_ethereum_primitives::EthPrimitives;
15use reth_primitives_traits::{NodePrimitives, SealedBlock, SealedHeader};
16
17#[derive(Clone, Debug)]
19pub enum BeaconConsensusEngineEvent<N: NodePrimitives = EthPrimitives> {
20 ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
22 ForkBlockAdded(ExecutedBlockWithTrieUpdates<N>, Duration),
24 BlockReceived(BlockNumHash),
26 CanonicalBlockAdded(ExecutedBlockWithTrieUpdates<N>, Duration),
28 CanonicalChainCommitted(Box<SealedHeader<N::BlockHeader>>, Duration),
30 InvalidBlock(Box<SealedBlock<N::Block>>),
32 LiveSyncProgress(ConsensusEngineLiveSyncProgress),
34}
35
36impl<N: NodePrimitives> BeaconConsensusEngineEvent<N> {
37 pub const fn canonical_header(&self) -> Option<&SealedHeader<N::BlockHeader>> {
40 match self {
41 Self::CanonicalChainCommitted(header, _) => Some(header),
42 _ => None,
43 }
44 }
45}
46
47impl<N> Display for BeaconConsensusEngineEvent<N>
48where
49 N: NodePrimitives<BlockHeader: BlockHeader>,
50{
51 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
52 match self {
53 Self::ForkchoiceUpdated(state, status) => {
54 write!(f, "ForkchoiceUpdated({state:?}, {status:?})")
55 }
56 Self::ForkBlockAdded(block, duration) => {
57 write!(f, "ForkBlockAdded({:?}, {duration:?})", block.recovered_block.num_hash())
58 }
59 Self::CanonicalBlockAdded(block, duration) => {
60 write!(
61 f,
62 "CanonicalBlockAdded({:?}, {duration:?})",
63 block.recovered_block.num_hash()
64 )
65 }
66 Self::CanonicalChainCommitted(block, duration) => {
67 write!(f, "CanonicalChainCommitted({:?}, {duration:?})", block.num_hash())
68 }
69 Self::InvalidBlock(block) => {
70 write!(f, "InvalidBlock({:?})", block.num_hash())
71 }
72 Self::LiveSyncProgress(progress) => {
73 write!(f, "LiveSyncProgress({progress:?})")
74 }
75 Self::BlockReceived(num_hash) => {
76 write!(f, "BlockReceived({num_hash:?})")
77 }
78 }
79 }
80}
81
82#[derive(Clone, Debug)]
84pub enum ConsensusEngineLiveSyncProgress {
85 DownloadingBlocks {
87 remaining_blocks: u64,
89 target: B256,
91 },
92}