mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: move beacon consensus engine event (#13718)
This commit is contained in:
76
crates/engine/primitives/src/event.rs
Normal file
76
crates/engine/primitives/src/event.rs
Normal file
@ -0,0 +1,76 @@
|
||||
//! Events emitted by the beacon consensus engine.
|
||||
|
||||
use crate::ForkchoiceStatus;
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_primitives::B256;
|
||||
use alloy_rpc_types_engine::ForkchoiceState;
|
||||
use reth_primitives::{EthPrimitives, SealedBlockFor};
|
||||
use reth_primitives_traits::{NodePrimitives, SealedHeader};
|
||||
use std::{
|
||||
fmt::{Display, Formatter, Result},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
/// Events emitted by the consensus engine.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum BeaconConsensusEngineEvent<N: NodePrimitives = EthPrimitives> {
|
||||
/// The fork choice state was updated, and the current fork choice status
|
||||
ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
|
||||
/// A block was added to the fork chain.
|
||||
ForkBlockAdded(Arc<SealedBlockFor<N::Block>>, Duration),
|
||||
/// A block was added to the canonical chain, and the elapsed time validating the block
|
||||
CanonicalBlockAdded(Arc<SealedBlockFor<N::Block>>, Duration),
|
||||
/// A canonical chain was committed, and the elapsed time committing the data
|
||||
CanonicalChainCommitted(Box<SealedHeader<N::BlockHeader>>, Duration),
|
||||
/// The consensus engine is involved in live sync, and has specific progress
|
||||
LiveSyncProgress(ConsensusEngineLiveSyncProgress),
|
||||
}
|
||||
|
||||
impl<N: NodePrimitives> BeaconConsensusEngineEvent<N> {
|
||||
/// Returns the canonical header if the event is a
|
||||
/// [`BeaconConsensusEngineEvent::CanonicalChainCommitted`].
|
||||
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:?})")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Progress of the consensus engine during live sync.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ConsensusEngineLiveSyncProgress {
|
||||
/// The consensus engine is downloading blocks from the network.
|
||||
DownloadingBlocks {
|
||||
/// The number of blocks remaining to download.
|
||||
remaining_blocks: u64,
|
||||
/// The target block hash and number to download.
|
||||
target: B256,
|
||||
},
|
||||
}
|
||||
@ -22,6 +22,9 @@ pub use forkchoice::{ForkchoiceStateHash, ForkchoiceStateTracker, ForkchoiceStat
|
||||
mod message;
|
||||
pub use message::*;
|
||||
|
||||
mod event;
|
||||
pub use event::*;
|
||||
|
||||
mod invalid_block_hook;
|
||||
pub use invalid_block_hook::InvalidBlockHook;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user