feat(node): remove freelist from status log (#10395)

This commit is contained in:
Alexey Shekhirin
2024-08-20 07:20:55 -07:00
committed by GitHub
parent 3373670723
commit 5470574bf2
8 changed files with 9 additions and 48 deletions

1
Cargo.lock generated
View File

@ -7817,7 +7817,6 @@ dependencies = [
"humantime",
"pin-project",
"reth-beacon-consensus",
"reth-db-api",
"reth-network",
"reth-network-api",
"reth-primitives",

View File

@ -209,7 +209,6 @@ impl Command {
Some(Box::new(network)),
latest_block_number,
events,
provider_factory.db_ref().clone(),
),
);

View File

@ -114,12 +114,7 @@ impl ImportCommand {
let latest_block_number =
provider.get_stage_checkpoint(StageId::Finish)?.map(|ch| ch.block_number);
tokio::spawn(reth_node_events::node::handle_events(
None,
latest_block_number,
events,
provider_factory.db_ref().clone(),
));
tokio::spawn(reth_node_events::node::handle_events(None, latest_block_number, events));
// Run pipeline
info!(target: "reth::cli", "Starting sync pipeline");

View File

@ -240,7 +240,6 @@ where
Some(Box::new(ctx.components().network().clone())),
Some(ctx.head().number),
events,
database.clone(),
),
);

View File

@ -326,7 +326,6 @@ where
Some(Box::new(ctx.components().network().clone())),
Some(ctx.head().number),
events,
database.clone(),
),
);

View File

@ -18,7 +18,6 @@ reth-network-api.workspace = true
reth-stages.workspace = true
reth-prune.workspace = true
reth-static-file.workspace = true
reth-db-api.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true

View File

@ -6,7 +6,6 @@ use futures::Stream;
use reth_beacon_consensus::{
BeaconConsensusEngineEvent, ConsensusEngineLiveSyncProgress, ForkchoiceStatus,
};
use reth_db_api::{database::Database, database_metrics::DatabaseMetadata};
use reth_network::NetworkEvent;
use reth_network_api::PeersInfo;
use reth_primitives::{constants, BlockNumber, B256};
@ -31,11 +30,7 @@ const INFO_MESSAGE_INTERVAL: Duration = Duration::from_secs(25);
/// connections, current processing stage, and the latest block information. It provides
/// methods to handle different types of events that affect the node's state, such as pipeline
/// events, network events, and consensus engine events.
struct NodeState<DB> {
/// Database environment.
/// Used for freelist calculation reported in the "Status" log message.
/// See [`EventHandler::poll`].
db: DB,
struct NodeState {
/// Information about connected peers.
peers_info: Option<Box<dyn PeersInfo>>,
/// The stage currently being executed.
@ -52,14 +47,12 @@ struct NodeState<DB> {
finalized_block_hash: Option<B256>,
}
impl<DB> NodeState<DB> {
impl NodeState {
const fn new(
db: DB,
peers_info: Option<Box<dyn PeersInfo>>,
latest_block: Option<BlockNumber>,
) -> Self {
Self {
db,
peers_info,
current_stage: None,
latest_block,
@ -332,12 +325,6 @@ impl<DB> NodeState<DB> {
}
}
impl<DB: DatabaseMetadata> NodeState<DB> {
fn freelist(&self) -> Option<usize> {
self.db.metadata().freelist_size()
}
}
/// Helper type for formatting of optional fields:
/// - If [Some(x)], then `x` is written
/// - If [None], then `None` is written
@ -423,16 +410,14 @@ impl From<StaticFileProducerEvent> for NodeEvent {
/// Displays relevant information to the user from components of the node, and periodically
/// displays the high-level status of the node.
pub async fn handle_events<E, DB>(
pub async fn handle_events<E>(
peers_info: Option<Box<dyn PeersInfo>>,
latest_block_number: Option<BlockNumber>,
events: E,
db: DB,
) where
E: Stream<Item = NodeEvent> + Unpin,
DB: DatabaseMetadata + Database + 'static,
{
let state = NodeState::new(db, peers_info, latest_block_number);
let state = NodeState::new(peers_info, latest_block_number);
let start = tokio::time::Instant::now() + Duration::from_secs(3);
let mut info_interval = tokio::time::interval_at(start, INFO_MESSAGE_INTERVAL);
@ -444,18 +429,17 @@ pub async fn handle_events<E, DB>(
/// Handles events emitted by the node and logs them accordingly.
#[pin_project::pin_project]
struct EventHandler<E, DB> {
state: NodeState<DB>,
struct EventHandler<E> {
state: NodeState,
#[pin]
events: E,
#[pin]
info_interval: Interval,
}
impl<E, DB> Future for EventHandler<E, DB>
impl<E> Future for EventHandler<E>
where
E: Stream<Item = NodeEvent> + Unpin,
DB: DatabaseMetadata + Database + 'static,
{
type Output = ();
@ -463,8 +447,6 @@ where
let mut this = self.project();
while this.info_interval.poll_tick(cx).is_ready() {
let freelist = OptionalField(this.state.freelist());
if let Some(CurrentStage { stage_id, eta, checkpoint, entities_checkpoint, target }) =
&this.state.current_stage
{
@ -477,7 +459,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
stage = %stage_id,
checkpoint = checkpoint.block_number,
target = %OptionalField(*target),
@ -490,7 +471,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
stage = %stage_id,
checkpoint = checkpoint.block_number,
target = %OptionalField(*target),
@ -502,7 +482,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
stage = %stage_id,
checkpoint = checkpoint.block_number,
target = %OptionalField(*target),
@ -514,7 +493,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
stage = %stage_id,
checkpoint = checkpoint.block_number,
target = %OptionalField(*target),
@ -531,7 +509,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
%latest_block,
"Status"
);
@ -540,7 +517,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
"Status"
);
}

View File

@ -103,12 +103,7 @@ impl ImportOpCommand {
let latest_block_number =
provider.get_stage_checkpoint(StageId::Finish)?.map(|ch| ch.block_number);
tokio::spawn(reth_node_events::node::handle_events(
None,
latest_block_number,
events,
provider_factory.db_ref().clone(),
));
tokio::spawn(reth_node_events::node::handle_events(None, latest_block_number, events));
// Run pipeline
info!(target: "reth::cli", "Starting sync pipeline");