mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: --debug.skip-fcu (#7709)
This commit is contained in:
@ -59,6 +59,10 @@ pub struct DebugArgs {
|
||||
)]
|
||||
pub hook_all: bool,
|
||||
|
||||
/// If provided, the engine will skip `n` consecutive FCUs.
|
||||
#[arg(long = "debug.skip-fcu", help_heading = "Debug")]
|
||||
pub skip_fcu: Option<usize>,
|
||||
|
||||
/// The path to store engine API messages at.
|
||||
/// If specified, all of the intercepted engine API messages
|
||||
/// will be written to specified location.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
use reth_beacon_consensus::BeaconEngineMessage;
|
||||
use reth_engine_primitives::EngineTypes;
|
||||
use reth_primitives::fs::{self};
|
||||
use reth_primitives::fs;
|
||||
use reth_rpc_types::{
|
||||
engine::{CancunPayloadFields, ForkchoiceState},
|
||||
ExecutionPayload,
|
||||
|
||||
51
crates/node-core/src/engine_skip_fcu.rs
Normal file
51
crates/node-core/src/engine_skip_fcu.rs
Normal file
@ -0,0 +1,51 @@
|
||||
//! Stores engine API messages to disk for later inspection and replay.
|
||||
|
||||
use reth_beacon_consensus::{BeaconEngineMessage, OnForkChoiceUpdated};
|
||||
use reth_engine_primitives::EngineTypes;
|
||||
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
|
||||
/// Intercept Engine API message and skip FCUs.
|
||||
#[derive(Debug)]
|
||||
pub struct EngineApiSkipFcu {
|
||||
/// The number of FCUs to skip.
|
||||
threshold: usize,
|
||||
/// Current count of skipped FCUs.
|
||||
skipped: usize,
|
||||
}
|
||||
|
||||
impl EngineApiSkipFcu {
|
||||
/// Creates new [EngineApiSkipFcu] interceptor.
|
||||
pub fn new(threshold: usize) -> Self {
|
||||
Self { threshold, skipped: 0 }
|
||||
}
|
||||
|
||||
/// Intercepts an incoming engine API message, skips FCU or forwards it
|
||||
/// to the engine depending on current number of skipped FCUs.
|
||||
pub async fn intercept<Engine>(
|
||||
mut self,
|
||||
mut rx: UnboundedReceiver<BeaconEngineMessage<Engine>>,
|
||||
to_engine: UnboundedSender<BeaconEngineMessage<Engine>>,
|
||||
) where
|
||||
Engine: EngineTypes,
|
||||
BeaconEngineMessage<Engine>: std::fmt::Debug,
|
||||
{
|
||||
while let Some(msg) = rx.recv().await {
|
||||
if let BeaconEngineMessage::ForkchoiceUpdated { state, payload_attrs, tx } = msg {
|
||||
if self.skipped < self.threshold {
|
||||
self.skipped += 1;
|
||||
tracing::warn!(target: "engine::intercept", ?state, ?payload_attrs, threshold=self.threshold, skipped=self.skipped, "Skipping FCU");
|
||||
let _ = tx.send(Ok(OnForkChoiceUpdated::syncing()));
|
||||
} else {
|
||||
self.skipped = 0;
|
||||
let _ = to_engine.send(BeaconEngineMessage::ForkchoiceUpdated {
|
||||
state,
|
||||
payload_attrs,
|
||||
tx,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let _ = to_engine.send(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@ pub mod args;
|
||||
pub mod cli;
|
||||
pub mod dirs;
|
||||
pub mod engine_api_store;
|
||||
pub mod engine_skip_fcu;
|
||||
pub mod events;
|
||||
pub mod exit;
|
||||
pub mod init;
|
||||
|
||||
Reference in New Issue
Block a user