mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: update network status with new head (#9788)
This commit is contained in:
@ -18,6 +18,17 @@ pub enum BeaconConsensusEngineEvent {
|
|||||||
ForkBlockAdded(Arc<SealedBlock>),
|
ForkBlockAdded(Arc<SealedBlock>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BeaconConsensusEngineEvent {
|
||||||
|
/// Returns the canonical header if the event is a
|
||||||
|
/// [`BeaconConsensusEngineEvent::CanonicalChainCommitted`].
|
||||||
|
pub const fn canonical_header(&self) -> Option<&SealedHeader> {
|
||||||
|
match self {
|
||||||
|
Self::CanonicalChainCommitted(header, _) => Some(header),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Progress of the consensus engine during live sync.
|
/// Progress of the consensus engine during live sync.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum ConsensusEngineLiveSyncProgress {
|
pub enum ConsensusEngineLiveSyncProgress {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ use reth_node_builder::{
|
|||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
dirs::{ChainPath, DataDirPath},
|
dirs::{ChainPath, DataDirPath},
|
||||||
exit::NodeExitFuture,
|
exit::NodeExitFuture,
|
||||||
|
primitives::Head,
|
||||||
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
|
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||||
};
|
};
|
||||||
@ -247,6 +248,7 @@ where
|
|||||||
|
|
||||||
// Run consensus engine to completion
|
// Run consensus engine to completion
|
||||||
let network_handle = ctx.components().network().clone();
|
let network_handle = ctx.components().network().clone();
|
||||||
|
let chainspec = ctx.chain_spec();
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
info!(target: "reth::cli", "Starting consensus engine");
|
info!(target: "reth::cli", "Starting consensus engine");
|
||||||
ctx.task_executor().spawn_critical_blocking("consensus engine", async move {
|
ctx.task_executor().spawn_critical_blocking("consensus engine", async move {
|
||||||
@ -267,6 +269,18 @@ where
|
|||||||
}
|
}
|
||||||
ChainEvent::FatalError => break,
|
ChainEvent::FatalError => break,
|
||||||
ChainEvent::Handler(ev) => {
|
ChainEvent::Handler(ev) => {
|
||||||
|
if let Some(head) = ev.canonical_header() {
|
||||||
|
let head_block = Head {
|
||||||
|
number: head.number,
|
||||||
|
hash: head.hash(),
|
||||||
|
difficulty: head.difficulty,
|
||||||
|
timestamp: head.timestamp,
|
||||||
|
total_difficulty: chainspec
|
||||||
|
.final_paris_total_difficulty(head.number)
|
||||||
|
.unwrap_or_default(),
|
||||||
|
};
|
||||||
|
network_handle.update_status(head_block);
|
||||||
|
}
|
||||||
event_sender.notify(ev);
|
event_sender.notify(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user