reth_beacon_consensus/engine/
event.rsuse crate::engine::forkchoice::ForkchoiceStatus;
use alloy_primitives::B256;
use alloy_rpc_types_engine::ForkchoiceState;
use reth_primitives::{SealedBlock, SealedHeader};
use std::{
fmt::{Display, Formatter, Result},
sync::Arc,
time::Duration,
};
#[derive(Clone, Debug)]
pub enum BeaconConsensusEngineEvent {
ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
ForkBlockAdded(Arc<SealedBlock>, Duration),
CanonicalBlockAdded(Arc<SealedBlock>, Duration),
CanonicalChainCommitted(Box<SealedHeader>, Duration),
LiveSyncProgress(ConsensusEngineLiveSyncProgress),
}
impl BeaconConsensusEngineEvent {
pub const fn canonical_header(&self) -> Option<&SealedHeader> {
match self {
Self::CanonicalChainCommitted(header, _) => Some(header),
_ => None,
}
}
}
impl Display for BeaconConsensusEngineEvent {
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,
},
}