Skip to content

Commit

Permalink
feat(node): remove freelist from status log (paradigmxyz#10395)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Aug 20, 2024
1 parent 3373670 commit 5470574
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 48 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ impl Command {
Some(Box::new(network)),
latest_block_number,
events,
provider_factory.db_ref().clone(),
),
);

Expand Down
7 changes: 1 addition & 6 deletions crates/cli/commands/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ where
Some(Box::new(ctx.components().network().clone())),
Some(ctx.head().number),
events,
database.clone(),
),
);

Expand Down
1 change: 0 additions & 1 deletion crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ where
Some(Box::new(ctx.components().network().clone())),
Some(ctx.head().number),
events,
database.clone(),
),
);

Expand Down
1 change: 0 additions & 1 deletion crates/node/events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 7 additions & 31 deletions crates/node/events/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -444,27 +429,24 @@ 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 = ();

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
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
{
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -531,7 +509,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
%latest_block,
"Status"
);
Expand All @@ -540,7 +517,6 @@ where
info!(
target: "reth::cli",
connected_peers = this.state.num_connected_peers(),
%freelist,
"Status"
);
}
Expand Down
7 changes: 1 addition & 6 deletions crates/optimism/cli/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 5470574

Please sign in to comment.