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: add storage_proof_only argument to RollupArgs #13009

Open
wants to merge 8 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
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.

9 changes: 4 additions & 5 deletions crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#![cfg(feature = "optimism")]

use clap::Parser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher, Node};
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_node::{args::RollupArgs, node::OpAddOns, OpNode};
use reth_optimism_node::{args::RollupArgs, OpNode};
use reth_provider::providers::BlockchainProvider2;

use tracing as _;
Expand All @@ -27,16 +27,15 @@ fn main() {
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();
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);
let handle = builder
.with_types_and_provider::<OpNode, BlockchainProvider2<_>>()
.with_components(OpNode::components(rollup_args))
.with_add_ons(OpAddOns::new(sequencer_http_arg))
.with_components(OpNode::components(&rollup_args))
.with_add_ons(OpNode::new(rollup_args).add_ons())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
Expand Down
7 changes: 7 additions & 0 deletions crates/optimism/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//! clap [Args](clap::Args) for optimism rollup configuration

use alloy_primitives::Address;
use reth_node_builder::engine_tree_config::{
DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD,
};
Expand Down Expand Up @@ -56,6 +57,11 @@ pub struct RollupArgs {
/// Configure the target number of blocks to keep in memory.
#[arg(long = "engine.memory-block-buffer-target", conflicts_with = "legacy", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
pub memory_block_buffer_target: u64,

/// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called
/// with `eth_getProof`.
#[arg(long = "rpc.storage-proof-addresses", value_delimiter = ',', num_args(1..))]
pub storage_proof_only: Vec<Address>,
}

impl Default for RollupArgs {
Expand All @@ -70,6 +76,7 @@ impl Default for RollupArgs {
legacy: false,
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
storage_proof_only: vec![],
}
}
}
Expand Down
96 changes: 83 additions & 13 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
OpEngineTypes,
};
use alloy_consensus::Header;
use alloy_primitives::Address;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_db::transaction::{DbTx, DbTxMut};
Expand All @@ -31,7 +32,7 @@ use reth_optimism_payload_builder::builder::OpPayloadTransactions;
use reth_optimism_primitives::OpPrimitives;
use reth_optimism_rpc::{
witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi},
OpEthApi,
OpEthApi, SequencerClient,
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_primitives::BlockBody;
Expand All @@ -46,7 +47,7 @@ use reth_transaction_pool::{
TransactionValidationTaskExecutor,
};
use reth_trie_db::MerklePatriciaTrie;
use std::sync::Arc;
use std::{marker::PhantomData, sync::Arc};

/// Storage implementation for Optimism.
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -122,7 +123,7 @@ impl OpNode {

/// Returns the components for the given [`RollupArgs`].
pub fn components<Node>(
args: RollupArgs,
args: &RollupArgs,
) -> ComponentsBuilder<
Node,
OpPoolBuilder,
Expand All @@ -144,9 +145,9 @@ impl OpNode {
ComponentsBuilder::default()
.node_types::<Node>()
.pool(OpPoolBuilder::default())
.payload(OpPayloadBuilder::new(compute_pending_block))
.payload(OpPayloadBuilder::new(*compute_pending_block))
.network(OpNetworkBuilder {
disable_txpool_gossip,
disable_txpool_gossip: *disable_txpool_gossip,
disable_discovery_v4: !discovery_v4,
})
.executor(OpExecutorBuilder::default())
Expand Down Expand Up @@ -178,12 +179,20 @@ where
OpAddOns<NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>>;

fn components_builder(&self) -> Self::ComponentsBuilder {
let Self { args } = self;
Self::components(args.clone())
Self::components(&self.args)
}

fn add_ons(&self) -> Self::AddOns {
OpAddOns::new(self.args.sequencer_http.clone())
let mut builder = OpAddOns::builder();
if let Some(sequencer) = &self.args.sequencer_http {
builder = builder.with_sequencer(sequencer.clone());
}

if !self.args.storage_proof_only.is_empty() {
builder = builder.with_storage_proof_only(self.args.storage_proof_only.clone());
}

builder.build()
Comment on lines +186 to +195
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be a chain of with_ calls instead, we can make the args on builder optional instead

}
}

Expand All @@ -204,14 +213,14 @@ pub struct OpAddOns<N: FullNodeComponents>(pub RpcAddOns<N, OpEthApi<N>, OpEngin

impl<N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>> Default for OpAddOns<N> {
fn default() -> Self {
Self::new(None)
Self::builder().build()
}
}

impl<N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>> OpAddOns<N> {
/// Create a new instance with the given `sequencer_http` URL.
pub fn new(sequencer_http: Option<String>) -> Self {
Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http), Default::default()))
impl<N: FullNodeComponents> OpAddOns<N> {
/// Build a [`OpAddOns`] using [`OpAddOnsBuilder`].
pub fn builder() -> OpAddOnsBuilder<N> {
OpAddOnsBuilder::default()
}
}

Expand Down Expand Up @@ -270,6 +279,67 @@ where
}
}

/// A regular optimism evm and executor builder.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct OpAddOnsBuilder<N> {
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
sequencer_client: Option<SequencerClient>,
/// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called
/// with `eth_getProof`.
storage_proof_only: Vec<Address>,
_marker: PhantomData<N>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, we can probably get rid of this entirely if we make this accept the type on fn build instead
then this doesn't need a generic at all

}

impl<N> Default for OpAddOnsBuilder<N> {
fn default() -> Self {
Self { sequencer_client: None, storage_proof_only: vec![], _marker: PhantomData }
}
}

impl<N> OpAddOnsBuilder<N> {
/// With a [`SequencerClient`].
pub fn with_sequencer(mut self, sequencer_client: String) -> Self {
self.sequencer_client = Some(SequencerClient::new(sequencer_client));
self
}

/// With a list of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when
/// called with `eth_getProof`.
pub fn with_storage_proof_only(mut self, storage_proof_only: Vec<Address>) -> Self {
self.storage_proof_only = storage_proof_only;
self
}
}

impl<N> OpAddOnsBuilder<N>
where
N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>,
{
/// Builds an instance of [`OpAddOns`].
pub fn build(self) -> OpAddOns<N> {
let Self { sequencer_client, storage_proof_only, .. } = self;

OpAddOns(RpcAddOns::new(
move |ctx| {
let mut builder = OpEthApi::builder(ctx);

if let Some(sequencer_client) = sequencer_client {
builder = builder.with_sequencer(sequencer_client)
}

if !storage_proof_only.is_empty() {
builder = builder.with_storage_proof_only(storage_proof_only);
}

builder.build()
Comment on lines +326 to +336
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

},
Default::default(),
))
}
}

/// A regular optimism evm and executor builder.
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/node/tests/it/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn test_basic_setup() {
let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<OpNode>()
.with_components(OpNode::components(Default::default()))
.with_add_ons(OpAddOns::new(None))
.with_components(OpNode::components(&Default::default()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels weird, imo we should consume here, no reference

.with_add_ons(OpAddOns::builder().build())
.on_component_initialized(move |ctx| {
let _provider = ctx.provider();
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workspace = true
[dependencies]
# reth
reth-evm.workspace = true
reth-errors.workspace = true
reth-primitives.workspace = true
reth-provider.workspace = true
reth-rpc-eth-api.workspace = true
Expand All @@ -23,10 +24,12 @@ reth-tasks = { workspace = true, features = ["rayon"] }
reth-transaction-pool.workspace = true
reth-rpc.workspace = true
reth-rpc-api.workspace = true
reth-rpc-types-compat.workspace = true
reth-node-api.workspace = true
reth-network-api.workspace = true
reth-node-builder.workspace = true
reth-chainspec.workspace = true
reth-trie-common.workspace = true

# op-reth
reth-optimism-chainspec.workspace = true
Expand All @@ -41,6 +44,7 @@ alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-rpc-types-debug.workspace = true
alloy-serde.workspace = true
alloy-consensus.workspace = true
op-alloy-network.workspace = true
op-alloy-rpc-types.workspace = true
Expand Down
Loading
Loading