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#[deprecated(note = "Use ConsensusEngineEvent instead")]
19pub type BeaconConsensusEngineEvent<N> = ConsensusEngineEvent<N>;
20
21#[derive(Clone, Debug)]
23pub enum ConsensusEngineEvent<N: NodePrimitives = EthPrimitives> {
24 ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
26 ForkBlockAdded(ExecutedBlockWithTrieUpdates<N>, Duration),
28 BlockReceived(BlockNumHash),
30 CanonicalBlockAdded(ExecutedBlockWithTrieUpdates<N>, Duration),
32 CanonicalChainCommitted(Box<SealedHeader<N::BlockHeader>>, Duration),
34 InvalidBlock(Box<SealedBlock<N::Block>>),
36 LiveSyncProgress(ConsensusEngineLiveSyncProgress),
38}
39
40impl<N: NodePrimitives> ConsensusEngineEvent<N> {
41 pub const fn canonical_header(&self) -> Option<&SealedHeader<N::BlockHeader>> {
44 match self {
45 Self::CanonicalChainCommitted(header, _) => Some(header),
46 _ => None,
47 }
48 }
49}
50
51impl<N> Display for ConsensusEngineEvent<N>
52where
53 N: NodePrimitives<BlockHeader: BlockHeader>,
54{
55 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
56 match self {
57 Self::ForkchoiceUpdated(state, status) => {
58 write!(f, "ForkchoiceUpdated({state:?}, {status:?})")
59 }
60 Self::ForkBlockAdded(block, duration) => {
61 write!(f, "ForkBlockAdded({:?}, {duration:?})", block.recovered_block.num_hash())
62 }
63 Self::CanonicalBlockAdded(block, duration) => {
64 write!(
65 f,
66 "CanonicalBlockAdded({:?}, {duration:?})",
67 block.recovered_block.num_hash()
68 )
69 }
70 Self::CanonicalChainCommitted(block, duration) => {
71 write!(f, "CanonicalChainCommitted({:?}, {duration:?})", block.num_hash())
72 }
73 Self::InvalidBlock(block) => {
74 write!(f, "InvalidBlock({:?})", block.num_hash())
75 }
76 Self::LiveSyncProgress(progress) => {
77 write!(f, "LiveSyncProgress({progress:?})")
78 }
79 Self::BlockReceived(num_hash) => {
80 write!(f, "BlockReceived({num_hash:?})")
81 }
82 }
83 }
84}
85
86#[derive(Clone, Debug)]
88pub enum ConsensusEngineLiveSyncProgress {
89 DownloadingBlocks {
91 remaining_blocks: u64,
93 target: B256,
95 },
96}