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