reth_beacon_consensus/engine/
event.rsuse alloy_consensus::BlockHeader;
use alloy_primitives::B256;
use alloy_rpc_types_engine::ForkchoiceState;
use reth_engine_primitives::ForkchoiceStatus;
use reth_primitives::{EthPrimitives, NodePrimitives, SealedBlockFor, SealedHeader};
use std::{
fmt::{Display, Formatter, Result},
sync::Arc,
time::Duration,
};
#[derive(Clone, Debug)]
pub enum BeaconConsensusEngineEvent<N: NodePrimitives = EthPrimitives> {
ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
ForkBlockAdded(Arc<SealedBlockFor<N::Block>>, Duration),
CanonicalBlockAdded(Arc<SealedBlockFor<N::Block>>, Duration),
CanonicalChainCommitted(Box<SealedHeader<N::BlockHeader>>, Duration),
LiveSyncProgress(ConsensusEngineLiveSyncProgress),
}
impl<N: NodePrimitives> BeaconConsensusEngineEvent<N> {
pub const fn canonical_header(&self) -> Option<&SealedHeader<N::BlockHeader>> {
match self {
Self::CanonicalChainCommitted(header, _) => Some(header),
_ => None,
}
}
}
impl<N> Display for BeaconConsensusEngineEvent<N>
where
N: NodePrimitives<BlockHeader: BlockHeader>,
{
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::ForkchoiceUpdated(state, status) => {
write!(f, "ForkchoiceUpdated({state:?}, {status:?})")
}
Self::ForkBlockAdded(block, duration) => {
write!(f, "ForkBlockAdded({:?}, {duration:?})", block.num_hash())
}
Self::CanonicalBlockAdded(block, duration) => {
write!(f, "CanonicalBlockAdded({:?}, {duration:?})", block.num_hash())
}
Self::CanonicalChainCommitted(block, duration) => {
write!(f, "CanonicalChainCommitted({:?}, {duration:?})", block.num_hash())
}
Self::LiveSyncProgress(progress) => {
write!(f, "LiveSyncProgress({progress:?})")
}
}
}
}
#[derive(Clone, Debug)]
pub enum ConsensusEngineLiveSyncProgress {
DownloadingBlocks {
remaining_blocks: u64,
target: B256,
},
}