mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(cli): consensus engine events (#2473)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
//! Support for handling events emitted by node components.
|
||||
|
||||
use futures::Stream;
|
||||
use reth_beacon_consensus::BeaconConsensusEngineEvent;
|
||||
use reth_network::{NetworkEvent, NetworkHandle};
|
||||
use reth_network_api::PeersInfo;
|
||||
use reth_primitives::BlockNumber;
|
||||
@ -71,6 +72,20 @@ impl NodeState {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_consensus_engine_event(&self, event: BeaconConsensusEngineEvent) {
|
||||
match event {
|
||||
BeaconConsensusEngineEvent::ForkchoiceUpdated(state) => {
|
||||
info!(target: "reth::cli", ?state, "Forkchoice updated");
|
||||
}
|
||||
BeaconConsensusEngineEvent::CanonicalBlockAdded(number, hash) => {
|
||||
info!(target: "reth::cli", number, ?hash, "Block added to canonical chain");
|
||||
}
|
||||
BeaconConsensusEngineEvent::ForkBlockAdded(number, hash) => {
|
||||
info!(target: "reth::cli", number, ?hash, "Block added to fork chain");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A node event.
|
||||
@ -80,19 +95,28 @@ pub enum NodeEvent {
|
||||
Network(NetworkEvent),
|
||||
/// A sync pipeline event.
|
||||
Pipeline(PipelineEvent),
|
||||
/// A consensus engine event.
|
||||
ConsensusEngine(BeaconConsensusEngineEvent),
|
||||
}
|
||||
|
||||
impl From<NetworkEvent> for NodeEvent {
|
||||
fn from(evt: NetworkEvent) -> NodeEvent {
|
||||
NodeEvent::Network(evt)
|
||||
fn from(event: NetworkEvent) -> NodeEvent {
|
||||
NodeEvent::Network(event)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PipelineEvent> for NodeEvent {
|
||||
fn from(evt: PipelineEvent) -> NodeEvent {
|
||||
NodeEvent::Pipeline(evt)
|
||||
fn from(event: PipelineEvent) -> NodeEvent {
|
||||
NodeEvent::Pipeline(event)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BeaconConsensusEngineEvent> for NodeEvent {
|
||||
fn from(event: BeaconConsensusEngineEvent) -> Self {
|
||||
NodeEvent::ConsensusEngine(event)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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(
|
||||
@ -144,6 +168,9 @@ where
|
||||
NodeEvent::Pipeline(event) => {
|
||||
this.state.handle_pipeline_event(event);
|
||||
}
|
||||
NodeEvent::ConsensusEngine(event) => {
|
||||
this.state.handle_consensus_engine_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -312,13 +312,6 @@ impl Command {
|
||||
.await?
|
||||
};
|
||||
|
||||
let events = stream_select(
|
||||
network.event_listener().map(Into::into),
|
||||
pipeline.events().map(Into::into),
|
||||
);
|
||||
ctx.task_executor
|
||||
.spawn_critical("events task", events::handle_events(Some(network.clone()), events));
|
||||
|
||||
// configure the payload builder
|
||||
let payload_generator = BasicPayloadJobGenerator::new(
|
||||
blockchain_db.clone(),
|
||||
@ -333,6 +326,7 @@ impl Command {
|
||||
debug!(target: "reth::cli", "Spawning payload builder service");
|
||||
ctx.task_executor.spawn_critical("payload builder service", payload_service);
|
||||
|
||||
let pipeline_events = pipeline.events();
|
||||
let (beacon_consensus_engine, beacon_engine_handle) = BeaconConsensusEngine::with_channel(
|
||||
Arc::clone(&db),
|
||||
ctx.task_executor.clone(),
|
||||
@ -346,6 +340,16 @@ impl Command {
|
||||
);
|
||||
info!(target: "reth::cli", "Consensus engine initialized");
|
||||
|
||||
let events = stream_select(
|
||||
stream_select(
|
||||
network.event_listener().map(Into::into),
|
||||
beacon_engine_handle.event_listener().map(Into::into),
|
||||
),
|
||||
pipeline_events.map(Into::into),
|
||||
);
|
||||
ctx.task_executor
|
||||
.spawn_critical("events task", events::handle_events(Some(network.clone()), events));
|
||||
|
||||
let engine_api = EngineApi::new(
|
||||
blockchain_db.clone(),
|
||||
self.chain.clone(),
|
||||
|
||||
Reference in New Issue
Block a user