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