From f21f560611cde681062e4651244455ccddbfeda9 Mon Sep 17 00:00:00 2001 From: julio4 <30329843+julio4@users.noreply.github.com> Date: Thu, 14 May 2026 18:00:10 +0800 Subject: [PATCH] feat: chain task to proxy reth chain event logs --- crates/op-rbuilder/src/launcher.rs | 52 +++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/crates/op-rbuilder/src/launcher.rs b/crates/op-rbuilder/src/launcher.rs index 8789f4c9..3953534e 100644 --- a/crates/op-rbuilder/src/launcher.rs +++ b/crates/op-rbuilder/src/launcher.rs @@ -1,6 +1,9 @@ +use alloy_consensus::BlockHeader; use eyre::Result; +use futures_util::StreamExt; +use reth_node_api::{ConsensusEngineEvent, ForkchoiceStatus}; use reth_optimism_rpc::OpEthApiBuilder; -use tracing::info; +use tracing::{debug, info}; use crate::{ args::*, @@ -143,6 +146,53 @@ impl Launcher for BuilderLauncher { ctx.task_executor.spawn_critical_task("txlogging", task); } + let mut engine_events = ctx.engine_events.new_listener(); + ctx.task_executor.spawn_task(async move { + while let Some(event) = engine_events.next().await { + match event { + ConsensusEngineEvent::CanonicalBlockAdded(executed, _) => { + let block = executed.sealed_block(); + debug!( + target: "op_rbuilder::chain", + number = block.number(), + hash = %block.hash(), + txs = block.transaction_count(), + "Block added to canonical chain" + ); + } + ConsensusEngineEvent::CanonicalChainCommitted(head, _) => { + debug!( + target: "op_rbuilder::chain", + number = head.number(), + hash = %head.hash(), + "Canonical chain committed" + ); + } + ConsensusEngineEvent::BlockReceived(num_hash) => { + debug!( + target: "op_rbuilder::chain", + number = num_hash.number, + hash = %num_hash.hash, + "Received new payload from consensus engine" + ); + } + ConsensusEngineEvent::ForkchoiceUpdated( + state, + ForkchoiceStatus::Valid, + ) => { + debug!( + target: "op_rbuilder::chain", + head = %state.head_block_hash, + safe = %state.safe_block_hash, + finalized = %state.finalized_block_hash, + "Forkchoice updated" + ); + } + _ => {} + } + } + }); + Ok(()) }) .launch()