reth_beacon_consensus/engine/
event.rs1use alloy_consensus::BlockHeader;
2use alloy_primitives::B256;
3use alloy_rpc_types_engine::ForkchoiceState;
4use reth_engine_primitives::ForkchoiceStatus;
5use reth_primitives::{EthPrimitives, NodePrimitives, SealedBlockFor, SealedHeader};
6use std::{
7 fmt::{Display, Formatter, Result},
8 sync::Arc,
9 time::Duration,
10};
11
12#[derive(Clone, Debug)]
14pub enum BeaconConsensusEngineEvent<N: NodePrimitives = EthPrimitives> {
15 ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
17 ForkBlockAdded(Arc<SealedBlockFor<N::Block>>, Duration),
19 CanonicalBlockAdded(Arc<SealedBlockFor<N::Block>>, Duration),
21 CanonicalChainCommitted(Box<SealedHeader<N::BlockHeader>>, Duration),
23 LiveSyncProgress(ConsensusEngineLiveSyncProgress),
25}
26
27impl<N: NodePrimitives> BeaconConsensusEngineEvent<N> {
28 pub const fn canonical_header(&self) -> Option<&SealedHeader<N::BlockHeader>> {
31 match self {
32 Self::CanonicalChainCommitted(header, _) => Some(header),
33 _ => None,
34 }
35 }
36}
37
38impl<N> Display for BeaconConsensusEngineEvent<N>
39where
40 N: NodePrimitives<BlockHeader: BlockHeader>,
41{
42 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
43 match self {
44 Self::ForkchoiceUpdated(state, status) => {
45 write!(f, "ForkchoiceUpdated({state:?}, {status:?})")
46 }
47 Self::ForkBlockAdded(block, duration) => {
48 write!(f, "ForkBlockAdded({:?}, {duration:?})", block.num_hash())
49 }
50 Self::CanonicalBlockAdded(block, duration) => {
51 write!(f, "CanonicalBlockAdded({:?}, {duration:?})", block.num_hash())
52 }
53 Self::CanonicalChainCommitted(block, duration) => {
54 write!(f, "CanonicalChainCommitted({:?}, {duration:?})", block.num_hash())
55 }
56 Self::LiveSyncProgress(progress) => {
57 write!(f, "LiveSyncProgress({progress:?})")
58 }
59 }
60 }
61}
62
63#[derive(Clone, Debug)]
65pub enum ConsensusEngineLiveSyncProgress {
66 DownloadingBlocks {
68 remaining_blocks: u64,
70 target: B256,
72 },
73}