Skip to content

Commit

Permalink
add builder tx to new op-rbuilder (#361)
Browse files Browse the repository at this point in the history
## 📝 Summary

<!--- A general summary of your changes -->

## 💡 Motivation and Context

<!--- (Optional) Why is this change required? What problem does it
solve? Remove this section if not applicable. -->

---

## ✅ I have completed the following steps:

* [ ] Run `make lint`
* [ ] Run `make test`
* [ ] Added tests (if applicable)

---------

Co-authored-by: Ferran Borreguero <[email protected]>
  • Loading branch information
avalonche and ferranbt authored Jan 22, 2025
1 parent 2182f96 commit 3d00697
Show file tree
Hide file tree
Showing 12 changed files with 1,171 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

# editors
.code
.idea
.idea
.vscode
4 changes: 4 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 @@ -142,6 +142,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
5 changes: 4 additions & 1 deletion crates/op-rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ 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 }
clap_builder = { workspace = true }
clap.workspace = true
derive_more.workspace = true

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { version = "0.6", optional = 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>,
}
35 changes: 26 additions & 9 deletions crates/op-rbuilder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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::Node;
use reth::{
builder::{components::PayloadServiceBuilder, node::FullNodeTypes, BuilderContext},
Expand All @@ -19,20 +19,32 @@ use reth_node_api::TxTy;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_evm::OpEvmConfig;
use reth_optimism_node::args::RollupArgs;
use reth_optimism_node::OpEngineTypes;
use reth_optimism_node::OpNode;
use reth_optimism_primitives::OpPrimitives;
use reth_payload_builder::PayloadBuilderService;
use tx_signer::Signer;

/// CLI argument parsing.
pub mod args;

use reth_optimism_primitives::OpPrimitives;
use reth_transaction_pool::PoolTransaction;

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 @@ -54,7 +66,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 @@ -77,8 +92,10 @@ where
}

fn main() {
Cli::<OpChainSpecParser, RollupArgs>::parse()
.run(|builder, rollup_args| async move {
Cli::<OpChainSpecParser, args::OpRbuilderArgs>::parse()
.run(|builder, builder_args| async move {
let rollup_args = builder_args.rollup_args;

let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(rollup_args.persistence_threshold)
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);
Expand All @@ -89,7 +106,7 @@ fn main() {
.with_components(
op_node
.components()
.payload(CustomPayloadBuilder::default()),
.payload(CustomPayloadBuilder::new(builder_args.builder_signer)),
)
.with_add_ons(op_node.add_ons())
.launch_with_fn(|builder| {
Expand Down
Loading

0 comments on commit 3d00697

Please sign in to comment.