Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: engine reorg interceptor #8110

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions crates/node-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ reth-consensus-common.workspace = true
reth-beacon-consensus.workspace = true
reth-etl.workspace = true
reth-codecs.workspace = true
reth-revm.workspace = true
reth-payload-validator.workspace = true
revm.workspace = true

# ethereum
discv5.workspace = true

# async
futures.workspace = true
tokio.workspace = true
tokio-util.workspace = true
pin-project.workspace = true
Expand All @@ -63,6 +67,7 @@ thiserror.workspace = true
const-str = "0.5.6"
rand.workspace = true
derive_more.workspace = true
itertools.workspace = true

# io
dirs-next = "2.0.0"
Expand All @@ -83,9 +88,6 @@ secp256k1 = { workspace = true, features = [
"recovery",
] }

# async
futures.workspace = true

[target.'cfg(unix)'.dependencies]
tikv-jemalloc-ctl = { version = "0.5.0", optional = true }

Expand Down
4 changes: 4 additions & 0 deletions crates/node-core/src/args/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub struct DebugArgs {
#[arg(long = "debug.skip-new-payload", help_heading = "Debug")]
pub skip_new_payload: Option<usize>,

/// If provided, the chain will be reorged at specified frequency.
#[arg(long = "debug.reorg-frequency", help_heading = "Debug")]
pub reorg_frequency: 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.
Expand Down
6 changes: 3 additions & 3 deletions crates/node-core/src/engine/engine_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ impl<S> EngineStoreStream<S> {
}
}

impl<Engine, S> Stream for EngineStoreStream<S>
impl<S, Engine> Stream for EngineStoreStream<S>
where
Engine: EngineTypes,
S: Stream<Item = BeaconEngineMessage<Engine>>,
Engine: EngineTypes,
{
type Item = S::Item;

Expand All @@ -147,7 +147,7 @@ where
let next = ready!(this.stream.poll_next_unpin(cx));
if let Some(msg) = &next {
if let Err(error) = this.store.on_message(msg, SystemTime::now()) {
error!(target: "engine::intercept", ?msg, %error, "Error handling Engine API message");
error!(target: "engine::stream::store", ?msg, %error, "Error handling Engine API message");
}
}
Poll::Ready(next)
Expand Down
34 changes: 34 additions & 0 deletions crates/node-core/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use tokio_util::either::Either;
pub mod engine_store;
use engine_store::EngineStoreStream;

pub mod reorg;
use reorg::EngineReorg;

pub mod skip_fcu;
use skip_fcu::EngineSkipFcu;

Expand Down Expand Up @@ -89,6 +92,37 @@ pub trait EngineMessageStreamExt<Engine: EngineTypes>:
Either::Right(self)
}
}

/// Creates reorgs with specified frequency.
fn reorg<Provider>(
self,
provider: Provider,
payload_validator: reth_payload_validator::ExecutionPayloadValidator,
frequency: usize,
) -> EngineReorg<Self, Engine, Provider>
where
Self: Sized,
{
EngineReorg::new(self, provider, payload_validator, frequency)
}

/// If frequency is [Some], returns the stream that creates reorgs with
/// specified frequency. Otherwise, returns `Self`.
fn maybe_reorg<Provider>(
self,
provider: Provider,
payload_validator: reth_payload_validator::ExecutionPayloadValidator,
frequency: Option<usize>,
) -> Either<EngineReorg<Self, Engine, Provider>, Self>
where
Self: Sized,
{
if let Some(frequency) = frequency {
Either::Left(reorg::EngineReorg::new(self, provider, payload_validator, frequency))
} else {
Either::Right(self)
}
}
}

impl<Engine, T> EngineMessageStreamExt<Engine> for T
Expand Down
Loading
Loading