Skip to content

Custom engine API to share FCU between other builders #65

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
772 changes: 390 additions & 382 deletions Cargo.lock

Large diffs are not rendered by default.

138 changes: 72 additions & 66 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,62 +40,67 @@ codegen-units = 1
incremental = false

[workspace.dependencies]
reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-chain-state = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-cli = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-db-common = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-errors = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-trie = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-trie-parallel = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1", features = [
reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-chain-state = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-cli = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-db-common = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-errors = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-rpc-engine-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-trie = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-trie-parallel = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3", features = [
"test-utils",
] }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-execution-errors = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-exex = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-metrics = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-payload-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-execution-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-revm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-payload-builder-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-payload-util = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
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-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-rpc-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-execution-errors = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-exex = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-tasks = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-metrics = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-payload-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-execution-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-revm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-payload-builder-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-payload-util = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-rpc-layer = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-network-peers = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-testing-utils = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-rpc-eth-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }

# reth optimism
reth-optimism-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-consensus = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-cli = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-forks = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-node = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-txpool = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.1" }
reth-optimism-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-consensus = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-cli = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-rpc = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-forks = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-node = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }
reth-optimism-txpool = { git = "https://github.com/paradigmxyz/reth", tag = "v1.4.3" }

# compatible with reth "v1.4.1 dependencies
# compatible with reth "v1.4.3 dependencies
revm = { version = "23.1.0", features = [
"std",
"secp256k1",
"optional_balance_check",
], default-features = false }
revm-inspectors = { version = "0.22.0", default-features = false }
revm-inspectors = { version = "0.22.3", default-features = false }
op-revm = { version = "4.0.2", default-features = false }

ethereum_ssz_derive = "0.9.0"
Expand All @@ -104,29 +109,29 @@ ethereum_ssz = "0.9.0"
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", "txpool-api"] }
alloy-pubsub = { version = "1.0.3" }
alloy-eips = { version = "1.0.3" }
alloy-rpc-types = { version = "1.0.3" }
alloy-json-rpc = { version = "1.0.3" }
alloy-transport-http = { version = "1.0.3" }
alloy-network = { version = "1.0.3" }
alloy-network-primitives = { version = "1.0.3" }
alloy-transport = { version = "1.0.3" }
alloy-node-bindings = { version = "1.0.3" }
alloy-consensus = { version = "1.0.3", features = ["kzg"] }
alloy-serde = { version = "1.0.3" }
alloy-rpc-types-beacon = { version = "1.0.3", features = ["ssz"] }
alloy-rpc-types-engine = { version = "1.0.3", features = ["ssz"] }
alloy-rpc-types-eth = { version = "1.0.3" }
alloy-signer-local = { version = "1.0.3" }
alloy-rpc-client = { version = "1.0.3" }
alloy-genesis = { version = "1.0.3" }
alloy-evm = { version = "0.8.1", default-features = false }
alloy-provider = { version = "1.0.5", features = ["ipc", "pubsub", "txpool-api", "engine-api"] }
alloy-pubsub = { version = "1.0.5" }
alloy-eips = { version = "1.0.5" }
alloy-rpc-types = { version = "1.0.5" }
alloy-json-rpc = { version = "1.0.5" }
alloy-transport-http = { version = "1.0.5" }
alloy-network = { version = "1.0.5" }
alloy-network-primitives = { version = "1.0.5" }
alloy-transport = { version = "1.0.5" }
alloy-node-bindings = { version = "1.0.5" }
alloy-consensus = { version = "1.0.5", features = ["kzg"] }
alloy-serde = { version = "1.0.5" }
alloy-rpc-types-beacon = { version = "1.0.5", features = ["ssz"] }
alloy-rpc-types-engine = { version = "1.0.5", features = ["ssz"] }
alloy-rpc-types-eth = { version = "1.0.5" }
alloy-signer-local = { version = "1.0.5" }
alloy-rpc-client = { version = "1.0.5" }
alloy-genesis = { version = "1.0.5" }
alloy-trie = { version = "0.8.1" }

# optimism
alloy-op-evm = { version = "0.8.0", default-features = false }
alloy-op-evm = { version = "0.8.1", default-features = false }
op-alloy-rpc-types = { version = "0.16.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.16.0", default-features = false }
op-alloy-rpc-jsonrpsee = { version = "0.16.0", default-features = false }
Expand All @@ -141,6 +146,7 @@ thiserror = { version = "1.0.64" }
eyre = { version = "0.6.12" }
jsonrpsee = { version = "0.25.1" }
jsonrpsee-types = { version = "0.25.1" }
jsonrpsee-core = { version = "0.25.1" }
parking_lot = { version = "0.12.3" }
tokio = { version = "1.40.0" }
auto_impl = { version = "1.2.0" }
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ lt: lint test ## Run "lint" and "test"
.PHONY: fmt
fmt: ## Format the code
cargo +nightly fmt
cargo +nightly fix --allow-staged
cargo +nightly clippy --features "$(FEATURES)" --fix --allow-staged
cargo +nightly clippy -p op-rbuilder --features "$(FEATURES)" --fix --allow-staged
cargo +nightly clippy --features "$(FEATURES)" --fix --allow-staged --allow-dirty
cargo +nightly clippy -p op-rbuilder --features "$(FEATURES)" --fix --allow-staged --allow-dirty
cargo +nightly fix --allow-staged --allow-dirty

.PHONY: bench
bench: ## Run benchmarks
Expand Down
10 changes: 9 additions & 1 deletion crates/op-rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository.workspace = true
reth.workspace = true
reth-optimism-node.workspace = true
reth-optimism-cli.workspace = true
reth-optimism-rpc.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-payload-builder.workspace = true
reth-optimism-evm.workspace = true
Expand All @@ -26,6 +27,8 @@ reth-chainspec.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-node-api.workspace = true
reth-rpc-engine-api.workspace = true
reth-node-core.workspace = true
reth-basic-payload-builder.workspace = true
reth-payload-builder.workspace = true
reth-node-ethereum.workspace = true
Expand All @@ -43,7 +46,10 @@ reth-network-peers.workspace = true
reth-testing-utils.workspace = true
reth-optimism-forks.workspace = true
reth-node-builder.workspace = true
reth-storage-api.workspace = true
reth-rpc-api.workspace = true
reth-rpc-eth-types.workspace = true
reth-tasks.workspace = true

alloy-primitives.workspace = true
alloy-consensus.workspace = true
Expand Down Expand Up @@ -76,7 +82,8 @@ serde.workspace = true
secp256k1.workspace = true
tokio.workspace = true
jsonrpsee = { workspace = true }
jsonrpsee-types.workspace = true
jsonrpsee-core = { workspace = true }
jsonrpsee-types = { workspace = true }
async-trait = { workspace = true }
clap_builder = { workspace = true }
clap.workspace = true
Expand All @@ -87,6 +94,7 @@ tokio-util.workspace = true
thiserror.workspace = true
parking_lot.workspace = true
url.workspace = true
anyhow = "1"

tower = "0.5"
futures = "0.3"
Expand Down
51 changes: 45 additions & 6 deletions crates/op-rbuilder/src/args/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
//! Copied from OptimismNode to allow easy extension.

//! clap [Args](clap::Args) for optimism rollup configuration
use std::path::PathBuf;

use crate::tx_signer::Signer;
use crate::{primitives::reth::engine_api_builder::EnginePeer, tx_signer::Signer};
use alloy_rpc_types_engine::JwtSecret;
use anyhow::{anyhow, Result};
use reth_optimism_node::args::RollupArgs;
use std::path::PathBuf;
use url::Url;

/// Parameters for rollup configuration
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
Expand Down Expand Up @@ -63,6 +65,7 @@ pub struct OpRbuilderArgs {
#[arg(long = "builder.enable-revert-protection", default_value = "false")]
pub enable_revert_protection: bool,

/// Path to builder playgorund to automatically start up the node connected to it
#[arg(
long = "builder.playground",
num_args = 0..=1,
Expand All @@ -71,12 +74,48 @@ pub struct OpRbuilderArgs {
env = "PLAYGROUND_DIR",
)]
pub playground: Option<PathBuf>,
/// List or builders in the network that FCU would be propagated to
#[arg(long = "builder.engine-api-peer", value_parser = parse_engine_peer_arg, action = clap::ArgAction::Append)]
pub engine_peers: Vec<EnginePeer>,
}

fn expand_path(s: &str) -> Result<PathBuf, String> {
fn expand_path(s: &str) -> Result<PathBuf> {
shellexpand::full(s)
.map_err(|e| format!("expansion error for `{s}`: {e}"))?
.map_err(|e| anyhow!("expansion error for `{s}`: {e}"))?
.into_owned()
.parse()
.map_err(|e| format!("invalid path after expansion: {e}"))
.map_err(|e| anyhow!("invalid path after expansion: {e}"))
}

/// Parse engine peer configuration string for clap argument parsing.
///
/// Format: "url@jwt_path" (JWT path is required)
/// - url: HTTP/HTTPS endpoint of the peer builder
/// - jwt_path: File path to JWT token for authentication (required after @)
fn parse_engine_peer_arg(s: &str) -> Result<EnginePeer> {
let s = s.trim();

if s.is_empty() {
return Err(anyhow!("Engine peer cannot be empty"));
}

// Find the @ delimiter - it's required
// Caution: this will misshandle cases when pathname contains `@` symbols, we do not expect such filenames tho
let (url_part, jwt_path_part) = s.rsplit_once('@').ok_or_else(|| anyhow!("Engine peer must include JWT path after '@' (format: url@jwt_path). Urls with @ in the path are not accepted."))?;

if url_part.is_empty() {
return Err(anyhow!("URL part cannot be empty"));
}

if jwt_path_part.is_empty() {
return Err(anyhow!("JWT path cannot be empty (format: url@jwt_path)"));
}

let url = Url::parse(url_part)?;

let jwt_path = PathBuf::from(jwt_path_part);

let jwt_secret = JwtSecret::from_file(&jwt_path)?;

Ok(EnginePeer::new(url, jwt_secret))
}
3 changes: 3 additions & 0 deletions crates/op-rbuilder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pub mod tx_signer;

#[cfg(any(test, feature = "testing"))]
pub mod tests;

pub mod traits;
pub mod tx;
14 changes: 12 additions & 2 deletions crates/op-rbuilder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use args::*;
use builders::{BuilderConfig, BuilderMode, FlashblocksBuilder, StandardBuilder};
use core::fmt::Debug;
use reth_optimism_node::{
node::{OpAddOnsBuilder, OpPoolBuilder},
node::{OpAddOnsBuilder, OpEngineValidatorBuilder, OpPoolBuilder},
OpNode,
};

use reth_transaction_pool::TransactionPool;

/// CLI argument parsing.
Expand All @@ -23,6 +24,7 @@ use metrics::{
VERGEN_CARGO_FEATURES, VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
};
use monitor_tx_pool::monitor_tx_pool;
use primitives::reth::engine_api_builder::OpEngineApiBuilder;
use revert_protection::{EthApiOverrideServer, RevertProtectionExt};
use tx::FBPooledTransaction;

Expand Down Expand Up @@ -68,6 +70,12 @@ where
cli.run(|builder, builder_args| async move {
let builder_config = BuilderConfig::<B::Config>::try_from(builder_args.clone())
.expect("Failed to convert rollup args to builder config");

// Engine peers are already parsed in the config
let engine_peers = builder_args.engine_peers;

let engine_builder: OpEngineApiBuilder<OpEngineValidatorBuilder> =
OpEngineApiBuilder::default().with_engine_peers(engine_peers);
let da_config = builder_config.da_config.clone();
let rollup_args = builder_args.rollup_args;
let op_node = OpNode::new(rollup_args.clone());
Expand Down Expand Up @@ -96,7 +104,9 @@ where
.with_sequencer(rollup_args.sequencer.clone())
.with_enable_tx_conditional(rollup_args.enable_tx_conditional)
.with_da_config(da_config)
.build(),
.build()
.rpc_add_ons
.with_engine_api(engine_builder),
)
.extend_rpc_modules(move |ctx| {
if builder_args.enable_revert_protection {
Expand Down
Loading