feat: update network status with new head (#9788)

This commit is contained in:
Matthias Seitz
2024-07-25 11:29:44 +02:00
committed by GitHub
parent e230517409
commit ec9af398c4
2 changed files with 25 additions and 0 deletions

View File

@ -18,6 +18,17 @@ pub enum BeaconConsensusEngineEvent {
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.
#[derive(Clone, Debug)]
pub enum ConsensusEngineLiveSyncProgress {

View File

@ -20,6 +20,7 @@ use reth_node_builder::{
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
primitives::Head,
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
};
@ -247,6 +248,7 @@ where
// Run consensus engine to completion
let network_handle = ctx.components().network().clone();
let chainspec = ctx.chain_spec();
let (tx, rx) = oneshot::channel();
info!(target: "reth::cli", "Starting consensus engine");
ctx.task_executor().spawn_critical_blocking("consensus engine", async move {
@ -267,6 +269,18 @@ where
}
ChainEvent::FatalError => break,
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);
}
}