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

add builder tx to new op-rbuilder #361

Merged
merged 20 commits into from
Jan 22, 2025
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ auto_impl = { version = "1.2.0" }
reqwest = { version = "0.12.8" }
serde = { version = "1.0.210" }
serde_json = { version = "1.0.128" }
serde_with = { version = "3.8.1" }
secp256k1 = { version = "0.29" }
clap_builder = { version = "4.5.19" }
derive_more = { version = "1" }
tokio-stream = "0.1.16"
Expand Down
4 changes: 3 additions & 1 deletion crates/op-rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ futures-util = "0.3.31"
eyre.workspace = true
alloy-provider.workspace = true
tower = "0.4"

serde_with.workspace = true
serde.workspace = true
secp256k1.workspace = true
tokio.workspace = true
jsonrpsee = { workspace = true }
async-trait = { workspace = true }
Expand Down
20 changes: 20 additions & 0 deletions crates/op-rbuilder/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Additional Node command arguments.
//!
//! Copied from OptimismNode to allow easy extension.

//! clap [Args](clap::Args) for optimism rollup configuration
use reth_optimism_node::args::RollupArgs;

use crate::tx_signer::Signer;

/// Parameters for rollup configuration
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
#[command(next_help_heading = "Rollup")]
pub struct OpRbuilderArgs {
/// Rollup configuration
#[command(flatten)]
pub rollup_args: RollupArgs,
/// Builder secret key for signing last transaction in block
#[arg(long = "rollup.builder-secret-key", env = "BUILDER_SECRET_KEY")]
pub builder_signer: Option<Signer>,
}
44 changes: 30 additions & 14 deletions crates/op-rbuilder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use args::OpRbuilderArgs;
use clap::Parser;
use generator::EmptyBlockPayloadJobGenerator;
use payload_builder::OpPayloadBuilder as FBPayloadBuilder;
use payload_builder_vanilla::VanillaOpPayloadBuilder;
use payload_builder_vanilla::OpPayloadBuilderVanilla;
use reth::{
builder::{components::PayloadServiceBuilder, node::FullNodeTypes, BuilderContext},
payload::PayloadBuilderHandle,
Expand All @@ -18,16 +19,29 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_evm::OpEvmConfig;
use reth_optimism_node::OpEngineTypes;
use reth_optimism_node::{args::RollupArgs, node::OpAddOns, OpNode};
use reth_optimism_node::{node::OpAddOns, OpNode};
use reth_payload_builder::PayloadBuilderService;
use tx_signer::Signer;

/// CLI argument parsing.
pub mod args;

pub mod generator;
pub mod payload_builder;
mod payload_builder_vanilla;
mod tx_signer;

#[derive(Debug, Clone, Copy, Default)]
#[non_exhaustive]
pub struct CustomPayloadBuilder;
pub struct CustomPayloadBuilder {
builder_secret_key: Option<Signer>,
}

impl CustomPayloadBuilder {
pub fn new(builder_secret_key: Option<Signer>) -> Self {
Self { builder_secret_key }
}
}

impl<Node, Pool> PayloadServiceBuilder<Node, Pool> for CustomPayloadBuilder
where
Expand All @@ -42,7 +56,10 @@ where
) -> eyre::Result<PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>> {
tracing::info!("Spawning a custom payload builder");
let _fb_builder = FBPayloadBuilder::new(OpEvmConfig::new(ctx.chain_spec()));
let vanilla_builder = VanillaOpPayloadBuilder::new(OpEvmConfig::new(ctx.chain_spec()));
let vanilla_builder = OpPayloadBuilderVanilla::new(
OpEvmConfig::new(ctx.chain_spec()),
self.builder_secret_key,
);
let payload_job_config = BasicPayloadJobGeneratorConfig::default();

let payload_generator = EmptyBlockPayloadJobGenerator::with_builder(
Expand All @@ -65,23 +82,22 @@ where
}

fn main() {
Cli::<OpChainSpecParser, RollupArgs>::parse()
.run(|builder, rollup_args| async move {
if rollup_args.experimental {
Cli::<OpChainSpecParser, OpRbuilderArgs>::parse()
.run(|builder, op_rbuilder_args| async move {
if op_rbuilder_args.rollup_args.experimental {
tracing::warn!(target: "reth::cli", "Experimental engine is default now, and the --engine.experimental flag is deprecated. To enable the legacy functionality, use --engine.legacy.");
}
let use_legacy_engine = rollup_args.legacy;
let sequencer_http_arg = rollup_args.sequencer_http.clone();

let use_legacy_engine = op_rbuilder_args.rollup_args.legacy;
let sequencer_http_arg = op_rbuilder_args.rollup_args.sequencer_http.clone();
match use_legacy_engine {
false => {
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(rollup_args.persistence_threshold)
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);
.with_persistence_threshold(op_rbuilder_args.rollup_args.persistence_threshold)
.with_memory_block_buffer_target(op_rbuilder_args.rollup_args.memory_block_buffer_target);
let handle = builder
.with_types_and_provider::<OpNode, BlockchainProvider2<_>>()
.with_components(
OpNode::components(rollup_args).payload(CustomPayloadBuilder::default()),
OpNode::components(op_rbuilder_args.rollup_args).payload(CustomPayloadBuilder::new(op_rbuilder_args.builder_signer)),
)
.with_add_ons(OpAddOns::new(sequencer_http_arg))
.launch_with_fn(|builder| {
Expand All @@ -98,7 +114,7 @@ fn main() {
},
true => {
let handle =
builder.node(OpNode::new(rollup_args.clone())).launch().await?;
builder.node(OpNode::new(op_rbuilder_args.rollup_args.clone())).launch().await?;

handle.node_exit_future.await
},
Expand Down
Loading
Loading