fix(bin): log latest engine block if pipeline is idle (#3024)

This commit is contained in:
Alexey Shekhirin
2023-06-06 18:07:17 +04:00
committed by GitHub
parent 2163095921
commit eed8be44ec

View File

@ -5,7 +5,10 @@ use futures::Stream;
use reth_beacon_consensus::BeaconConsensusEngineEvent;
use reth_network::{NetworkEvent, NetworkHandle};
use reth_network_api::PeersInfo;
use reth_primitives::stage::{StageCheckpoint, StageId};
use reth_primitives::{
stage::{StageCheckpoint, StageId},
BlockNumber,
};
use reth_stages::{ExecOutput, PipelineEvent};
use std::{
future::Future,
@ -27,11 +30,18 @@ struct NodeState {
current_stage: Option<StageId>,
/// The current checkpoint of the executing stage.
current_checkpoint: StageCheckpoint,
/// The latest canonical block added in the consensus engine.
latest_canonical_engine_block: Option<BlockNumber>,
}
impl NodeState {
fn new(network: Option<NetworkHandle>) -> Self {
Self { network, current_stage: None, current_checkpoint: StageCheckpoint::new(0) }
Self {
network,
current_stage: None,
current_checkpoint: StageCheckpoint::new(0),
latest_canonical_engine_block: None,
}
}
fn num_connected_peers(&self) -> usize {
@ -100,12 +110,14 @@ impl NodeState {
}
}
fn handle_consensus_engine_event(&self, event: BeaconConsensusEngineEvent) {
fn handle_consensus_engine_event(&mut self, event: BeaconConsensusEngineEvent) {
match event {
BeaconConsensusEngineEvent::ForkchoiceUpdated(state) => {
info!(target: "reth::cli", ?state, "Forkchoice updated");
}
BeaconConsensusEngineEvent::CanonicalBlockAdded(block) => {
self.latest_canonical_engine_block = Some(block.number);
info!(target: "reth::cli", number=block.number, hash=?block.hash, "Block added to canonical chain");
}
BeaconConsensusEngineEvent::ForkBlockAdded(block) => {
@ -204,12 +216,22 @@ where
let mut this = self.project();
while this.info_interval.poll_tick(cx).is_ready() {
let stage = this
.state
.current_stage
.map(|id| id.to_string())
.unwrap_or_else(|| "None".to_string());
info!(target: "reth::cli", connected_peers = this.state.num_connected_peers(), %stage, checkpoint = %this.state.current_checkpoint, "Status");
if let Some(stage) = this.state.current_stage.map(|id| id.to_string()) {
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%stage,
checkpoint = %this.state.current_checkpoint,
"Status"
);
} else {
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
latest_block = this.state.latest_canonical_engine_block.unwrap_or(this.state.current_checkpoint.block_number),
"Status"
);
}
}
while let Poll::Ready(Some(event)) = this.events.as_mut().poll_next(cx) {