feat: --debug.skip-fcu (#7709)

This commit is contained in:
Roman Krasiuk
2024-04-18 08:26:19 +02:00
committed by GitHub
parent 9557ce05ad
commit b846f47fdf
7 changed files with 71 additions and 4 deletions

View File

@ -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.

View File

@ -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,

View 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);
}
}
}
}

View File

@ -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;