Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
6 changes: 5 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ reth-rpc-layer = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-network-peers = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-testing-utils = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-rpc-eth-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }

# reth optimism
reth-optimism-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
Expand Down Expand Up @@ -104,7 +105,7 @@ alloy-primitives = { version = "1.1.0", default-features = false }
alloy-rlp = "0.3.10"
alloy-chains = "0.2.0"
alloy-evm = { version = "0.8.0", default-features = false }
alloy-provider = { version = "1.0.3", features = ["ipc", "pubsub"] }
alloy-provider = { version = "1.0.3", features = ["ipc", "pubsub", "txpool-api"] }
alloy-pubsub = { version = "1.0.3" }
alloy-eips = { version = "1.0.3" }
alloy-rpc-types = { version = "1.0.3" }
Expand Down
3 changes: 3 additions & 0 deletions crates/op-rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ reth-network-peers.workspace = true
reth-testing-utils.workspace = true
reth-optimism-forks.workspace = true
reth-node-builder.workspace = true
reth-rpc-eth-types.workspace = true

alloy-primitives.workspace = true
alloy-consensus.workspace = true
Expand All @@ -61,6 +62,7 @@ alloy-serde.workspace = true
alloy-op-evm.workspace = true
op-alloy-consensus.workspace = true
op-alloy-rpc-types-engine.workspace = true
op-alloy-rpc-types.workspace = true
op-alloy-network.workspace = true

revm.workspace = true
Expand All @@ -73,6 +75,7 @@ serde.workspace = true
secp256k1.workspace = true
tokio.workspace = true
jsonrpsee = { workspace = true }
jsonrpsee-types.workspace = true
async-trait = { workspace = true }
clap_builder = { workspace = true }
clap.workspace = true
Expand Down
12 changes: 0 additions & 12 deletions crates/op-rbuilder/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ pub struct BlockPayloadJobGenerator<Client, Tasks, Builder> {
last_payload: Arc<Mutex<CancellationToken>>,
/// The extra block deadline in seconds
extra_block_deadline: std::time::Duration,
/// Whether to enable revert protection
enable_revert_protection: bool,
}

// === impl EmptyBlockPayloadJobGenerator ===
Expand All @@ -90,7 +88,6 @@ impl<Client, Tasks, Builder> BlockPayloadJobGenerator<Client, Tasks, Builder> {
builder: Builder,
ensure_only_one_payload: bool,
extra_block_deadline: std::time::Duration,
enable_revert_protection: bool,
) -> Self {
Self {
client,
Expand All @@ -100,7 +97,6 @@ impl<Client, Tasks, Builder> BlockPayloadJobGenerator<Client, Tasks, Builder> {
ensure_only_one_payload,
last_payload: Arc::new(Mutex::new(CancellationToken::new())),
extra_block_deadline,
enable_revert_protection,
}
}
}
Expand Down Expand Up @@ -186,7 +182,6 @@ where
cancel: cancel_token,
deadline,
build_complete: None,
enable_revert_protection: self.enable_revert_protection,
};

job.spawn_build_job();
Expand Down Expand Up @@ -219,8 +214,6 @@ where
pub(crate) cancel: CancellationToken,
pub(crate) deadline: Pin<Box<Sleep>>, // Add deadline
pub(crate) build_complete: Option<oneshot::Receiver<Result<(), PayloadBuilderError>>>,
/// Block building options
pub(crate) enable_revert_protection: bool,
}

impl<Tasks, Builder> PayloadJob for BlockPayloadJob<Tasks, Builder>
Expand Down Expand Up @@ -263,8 +256,6 @@ pub struct BuildArguments<Attributes, Payload: BuiltPayload> {
pub config: PayloadConfig<Attributes, HeaderTy<Payload::Primitives>>,
/// A marker that can be used to cancel the job.
pub cancel: CancellationToken,
/// Whether to enable revert protection
pub enable_revert_protection: bool,
}

/// A [PayloadJob] is a future that's being polled by the `PayloadBuilderService`
Expand All @@ -280,7 +271,6 @@ where
let payload_config = self.config.clone();
let cell = self.cell.clone();
let cancel = self.cancel.clone();
let enable_revert_protection = self.enable_revert_protection;

let (tx, rx) = oneshot::channel();
self.build_complete = Some(rx);
Expand All @@ -290,7 +280,6 @@ where
cached_reads: Default::default(),
config: payload_config,
cancel,
enable_revert_protection,
};

let result = builder.try_build(args, cell);
Expand Down Expand Up @@ -650,7 +639,6 @@ mod tests {
builder.clone(),
false,
std::time::Duration::from_secs(1),
false,
);

// this is not nice but necessary
Expand Down
60 changes: 48 additions & 12 deletions crates/op-rbuilder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use args::CliExt;
use clap::Parser;
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_node::{node::OpAddOnsBuilder, OpNode};
use reth_optimism_node::{
node::{OpAddOnsBuilder, OpPoolBuilder},
OpNode,
};
use reth_transaction_pool::TransactionPool;

/// CLI argument parsing.
pub mod args;
pub mod generator;
mod metrics;
mod monitor_tx_pool;
mod primitives;
mod tx_signer;

#[cfg(feature = "flashblocks")]
pub mod payload_builder;
mod primitives;
mod revert_protection;
mod tx;
mod tx_signer;

#[cfg(not(feature = "flashblocks"))]
mod payload_builder_vanilla;
Expand All @@ -29,6 +33,8 @@ use metrics::{
VERGEN_CARGO_FEATURES, VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
};
use monitor_tx_pool::monitor_tx_pool;
use revert_protection::{EthApiOverrideServer, RevertProtectionExt};
use tx::FBPooledTransaction;

// Prefer jemalloc for performance reasons.
#[cfg(all(feature = "jemalloc", unix))]
Expand All @@ -53,20 +59,50 @@ fn main() {
let op_node = OpNode::new(rollup_args.clone());
let handle = builder
.with_types::<OpNode>()
.with_components(op_node.components().payload(CustomOpPayloadBuilder::new(
builder_args.builder_signer,
std::time::Duration::from_secs(builder_args.extra_block_deadline_secs),
builder_args.enable_revert_protection,
builder_args.flashblocks_ws_url,
builder_args.chain_block_time,
builder_args.flashblock_block_time,
)))
.with_components(
op_node
.components()
.pool(
OpPoolBuilder::<FBPooledTransaction>::default()
.with_enable_tx_conditional(
// Revert protection uses the same internal pool logic as conditional transactions
// to garbage collect transactions out of the bundle range.
rollup_args.enable_tx_conditional
|| builder_args.enable_revert_protection,
)
.with_supervisor(
rollup_args.supervisor_http.clone(),
rollup_args.supervisor_safety_level,
),
)
.payload(CustomOpPayloadBuilder::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we can make CustomOpPayloadBuilder accept BuilderArgs as a constructor parameter to avoid passing too many individual arguments and changing this code as the list of arguments grows over time.

builder_args.builder_signer,
std::time::Duration::from_secs(builder_args.extra_block_deadline_secs),
builder_args.flashblocks_ws_url,
builder_args.chain_block_time,
builder_args.flashblock_block_time,
)),
)
.with_add_ons(
OpAddOnsBuilder::default()
.with_sequencer(rollup_args.sequencer.clone())
.with_enable_tx_conditional(rollup_args.enable_tx_conditional)
.build(),
)
.extend_rpc_modules(move |ctx| {
if builder_args.enable_revert_protection {
tracing::info!("Revert protection enabled");

let pool = ctx.pool().clone();
let provider = ctx.provider().clone();
let revert_protection_ext = RevertProtectionExt::new(pool, provider);

ctx.modules
.merge_configured(revert_protection_ext.into_rpc())?;
}

Ok(())
})
.on_node_started(move |ctx| {
version.register_version_metrics();
if builder_args.log_pool_transactions {
Expand Down
1 change: 1 addition & 0 deletions crates/op-rbuilder/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct OpRBuilderMetrics {
#[cfg(feature = "flashblocks")]
pub messages_sent_count: Counter,
/// Total duration of building a block
#[cfg(feature = "flashblocks")]
pub total_block_built_duration: Histogram,
/// Flashblock build duration
#[cfg(feature = "flashblocks")]
Expand Down
6 changes: 3 additions & 3 deletions crates/op-rbuilder/src/monitor_tx_pool.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::tx::FBPooledTransaction;
use futures_util::StreamExt;
use reth_optimism_node::txpool::OpPooledTransaction;
use reth_transaction_pool::{AllTransactionsEvents, FullTransactionEvent};
use tracing::info;

pub async fn monitor_tx_pool(mut new_transactions: AllTransactionsEvents<OpPooledTransaction>) {
pub async fn monitor_tx_pool(mut new_transactions: AllTransactionsEvents<FBPooledTransaction>) {
while let Some(event) = new_transactions.next().await {
transaction_event_log(event);
}
}

fn transaction_event_log(event: FullTransactionEvent<OpPooledTransaction>) {
fn transaction_event_log(event: FullTransactionEvent<FBPooledTransaction>) {
match event {
FullTransactionEvent::Pending(hash) => {
info!(
Expand Down
5 changes: 0 additions & 5 deletions crates/op-rbuilder/src/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,12 @@ pub struct CustomOpPayloadBuilder {
chain_block_time: u64,
flashblock_block_time: u64,
extra_block_deadline: std::time::Duration,
enable_revert_protection: bool,
}

impl CustomOpPayloadBuilder {
pub fn new(
builder_signer: Option<Signer>,
extra_block_deadline: std::time::Duration,
enable_revert_protection: bool,
flashblocks_ws_url: String,
chain_block_time: u64,
flashblock_block_time: u64,
Expand All @@ -118,7 +116,6 @@ impl CustomOpPayloadBuilder {
chain_block_time,
flashblock_block_time,
extra_block_deadline,
enable_revert_protection,
}
}
}
Expand Down Expand Up @@ -185,7 +182,6 @@ where
) -> eyre::Result<PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>> {
tracing::info!("Spawning a custom payload builder");
let extra_block_deadline = self.extra_block_deadline;
let enable_revert_protection = self.enable_revert_protection;
let payload_builder = self.build_payload_builder(ctx, pool, evm_config).await?;
let payload_job_config = BasicPayloadJobGeneratorConfig::default();

Expand All @@ -196,7 +192,6 @@ where
payload_builder,
true,
extra_block_deadline,
enable_revert_protection,
);

let (payload_service, payload_builder) =
Expand Down
Loading
Loading