Skip to content

Commit

Permalink
feat: scroll mpt (#107)
Browse files Browse the repository at this point in the history
* init scroll-reth-mpt

* add Cargo.* files

* fix: lints

Signed-off-by: Gregory Edison <[email protected]>

* feat: add generic for node types on CLI::run

Signed-off-by: Gregory Edison <[email protected]>

* fix: cargo check

Signed-off-by: Gregory Edison <[email protected]>

* feat: feature gate state root verification

Signed-off-by: Gregory Edison <[email protected]>

* answer comments

Signed-off-by: Gregory Edison <[email protected]>

---------

Signed-off-by: Gregory Edison <[email protected]>
Co-authored-by: frisitano <[email protected]>
  • Loading branch information
greged93 and frisitano authored Dec 27, 2024
1 parent 944bfd0 commit 6942180
Show file tree
Hide file tree
Showing 28 changed files with 389 additions and 159 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ jobs:
- type: optimism
args: --bin op-reth --workspace --lib --examples --tests --benches --locked
features: "optimism asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs"
- type: scroll
- type: scroll-bmpt
args: --bin scroll-reth --workspace --lib --examples --tests --benches --locked
features: "scroll asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs"
- type: scroll-mpt
args: --bin scroll-reth-mpt --workspace --lib --examples --tests --benches --locked
features: "scroll asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs"
- type: book
args: --manifest-path book/sources/Cargo.toml --workspace --bins
features: ""
Expand Down Expand Up @@ -104,8 +107,10 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo hack check --workspace --exclude op-reth --exclude scroll-reth
- run: cargo hack check --workspace --exclude op-reth --exclude scroll-reth --exclude scroll-reth-mpt
- run: cargo check -p op-reth --features "optimism"
- run: cargo check -p scroll-reth --features "scroll"
- run: cargo check -p scroll-reth-mpt --features "scroll"

msrv:
name: MSRV / ${{ matrix.network }}
Expand Down Expand Up @@ -177,8 +182,8 @@ jobs:
cargo udeps --workspace --lib --examples --tests --benches --all-features --locked \
--exclude "reth-optimism-*" --exclude op-reth --exclude "example-*" --exclude reth \
--exclude reth-e2e-test-utils --exclude reth-ethereum-payload-builder --exclude reth-exex-test-utils \
--exclude reth-node-ethereum --exclude scroll-reth --exclude reth-scroll-cli --exclude reth-scroll-evm \
--exclude reth-scroll-node
--exclude reth-node-ethereum --exclude reth-scroll-cli --exclude reth-scroll-evm \
--exclude reth-scroll-node --exclude "scroll-reth*"
book:
name: book
Expand Down
13 changes: 13 additions & 0 deletions 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 @@ -101,7 +101,8 @@ members = [
"crates/rpc/rpc-testing-util/",
"crates/rpc/rpc-types-compat/",
"crates/rpc/rpc/",
"crates/scroll/bin",
"crates/scroll/bin/scroll-reth",
"crates/scroll/bin/scroll-reth-mpt",
"crates/scroll/chainspec",
"crates/scroll/cli",
"crates/scroll/consensus",
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ scroll = [
"reth-scroll-storage/scroll",
"reth-scroll-state-commitment/scroll"
]
skip-state-root-validation = [
"reth-stages/skip-state-root-validation"
]
12 changes: 9 additions & 3 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_builder_primitives::PayloadBuilder;
use reth_payload_primitives::PayloadBuilderAttributes;
use reth_primitives::{
EthPrimitives, GotExpected, NodePrimitives, SealedBlockFor, SealedBlockWithSenders,
SealedHeader,
EthPrimitives, NodePrimitives, SealedBlockFor, SealedBlockWithSenders, SealedHeader,
};
use reth_primitives_traits::Block;
use reth_provider::{
Expand Down Expand Up @@ -2287,6 +2286,9 @@ where
state_provider.state_root_from_state_with_updates(hashed_state.clone())?
};

#[cfg(feature = "skip-state-root-validation")]
let _ = state_root;
#[cfg(not(feature = "skip-state-root-validation"))]
if state_root != block.header().state_root() {
// call post-block hook
self.invalid_block_hook.on_invalid_block(
Expand All @@ -2296,7 +2298,11 @@ where
Some((&trie_output, state_root)),
);
return Err(ConsensusError::BodyStateRootDiff(
GotExpected { got: state_root, expected: block.header().state_root() }.into(),
reth_primitives::GotExpected {
got: state_root,
expected: block.header().state_root(),
}
.into(),
)
.into())
}
Expand Down
4 changes: 4 additions & 0 deletions crates/node/builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ scroll = [
"reth-engine-util/scroll",
"reth-invalid-block-hooks/scroll"
]
skip-state-root-validation = [
"reth-stages/skip-state-root-validation",
"reth-engine-tree/skip-state-root-validation"
]
24 changes: 14 additions & 10 deletions crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#![allow(missing_docs, rustdoc::missing_crate_level_docs)]
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

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

use tracing as _;

#[global_allocator]
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();

// The `optimism` feature must be enabled to use this crate.
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
fn main() {
use clap::Parser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher, Node};
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_node::{args::RollupArgs, OpNode};
use reth_provider::providers::BlockchainProvider2;
use tracing as _;
reth_cli_util::sigsegv_handler::install();

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
Expand Down Expand Up @@ -64,3 +62,9 @@ fn main() {
std::process::exit(1);
}
}

#[cfg(not(all(feature = "optimism", not(feature = "scroll"))))]
fn main() {
eprintln!("Optimism feature is not enabled");
std::process::exit(1);
}
44 changes: 44 additions & 0 deletions crates/scroll/bin/scroll-reth-mpt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "scroll-reth-mpt"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[lints]
workspace = true

[dependencies]
# reth
reth-cli-util.workspace = true
reth-node-builder.workspace = true
reth-provider.workspace = true

# scroll
reth-scroll-cli.workspace = true
reth-scroll-node.workspace = true

# misc
clap = { workspace = true, features = ["derive", "env"] }

[features]
scroll = [
"reth-provider/scroll",
"reth-scroll-cli/scroll",
]
skip-state-root-validation = [
"reth-node-builder/skip-state-root-validation",
"reth-scroll-node/skip-state-root-validation"
]
optimism = [
"reth-provider/optimism",
"reth-scroll-cli/optimism",
"reth-scroll-node/optimism"
]

[[bin]]
name = "scroll-reth-mpt"
path = "src/main.rs"
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
//! Scroll binary
#![cfg(all(feature = "scroll", not(feature = "optimism")))]

use clap::Parser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher, Node};
use reth_provider::providers::BlockchainProvider2;
use reth_scroll_cli::{Cli, ScrollChainSpecParser, ScrollRollupArgs};
use reth_scroll_node::{ScrollAddOns, ScrollNode};
#[global_allocator]
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();

#[cfg(all(feature = "scroll", not(feature = "optimism")))]
fn main() {
use clap::Parser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
use reth_provider::providers::BlockchainProvider2;
use reth_scroll_cli::{Cli, ScrollChainSpecParser, ScrollRollupArgs};
use reth_scroll_node::{ScrollAddOns, ScrollNodeMpt};
reth_cli_util::sigsegv_handler::install();

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}

if let Err(err) = Cli::<ScrollChainSpecParser, ScrollRollupArgs>::parse().run(
|builder, rollup_args| async move {
if let Err(err) = Cli::<ScrollChainSpecParser, ScrollRollupArgs>::parse()
.run::<_, _, ScrollNodeMpt>(|builder, rollup_args| async move {
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::<ScrollNode, BlockchainProvider2<_>>()
.with_components(ScrollNode.components_builder())
.with_types_and_provider::<ScrollNodeMpt, BlockchainProvider2<_>>()
.with_components(ScrollNodeMpt::components())
.with_add_ons(ScrollAddOns::default())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
Expand All @@ -38,9 +37,15 @@ fn main() {
.await?;

handle.node_exit_future.await
},
) {
})
{
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}

#[cfg(any(feature = "optimism", not(feature = "scroll")))]
fn main() {
eprintln!("Scroll feature is not enabled");
std::process::exit(1);
}
File renamed without changes.
51 changes: 51 additions & 0 deletions crates/scroll/bin/scroll-reth/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Scroll binary
#[global_allocator]
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();

#[cfg(all(feature = "scroll", not(feature = "optimism")))]
fn main() {
use clap::Parser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
use reth_provider::providers::BlockchainProvider2;
use reth_scroll_cli::{Cli, ScrollChainSpecParser, ScrollRollupArgs};
use reth_scroll_node::{ScrollAddOns, ScrollNodeBmpt};
reth_cli_util::sigsegv_handler::install();

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}

if let Err(err) = Cli::<ScrollChainSpecParser, ScrollRollupArgs>::parse()
.run::<_, _, ScrollNodeBmpt>(|builder, rollup_args| async move {
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::<ScrollNodeBmpt, BlockchainProvider2<_>>()
.with_components(ScrollNodeBmpt::components())
.with_add_ons(ScrollAddOns::default())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
.await?;

handle.node_exit_future.await
})
{
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}

#[cfg(any(feature = "optimism", not(feature = "scroll")))]
fn main() {
eprintln!("Scroll feature is not enabled");
std::process::exit(1);
}
24 changes: 10 additions & 14 deletions crates/scroll/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use spec::ScrollChainSpecParser;

use clap::{value_parser, Parser};
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::node::NoArgs;
use reth_cli_commands::{common::CliNodeTypes, node::NoArgs};
use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv;
use reth_eth_wire::EthNetworkPrimitives;
Expand All @@ -24,7 +24,6 @@ use reth_node_core::{
use reth_node_metrics::recorder::install_prometheus_recorder;
use reth_scroll_chainspec::ScrollChainSpec;
use reth_scroll_evm::ScrollExecutorProvider;
use reth_scroll_node::ScrollNode;
use reth_tracing::FileWorkerGuard;
use std::{ffi::OsString, fmt, future::Future, sync::Arc};
use tracing::info;
Expand Down Expand Up @@ -100,10 +99,11 @@ where
///
/// This accepts a closure that is used to launch the node via the
/// [`NodeCommand`](reth_cli_commands::node::NodeCommand).
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
pub fn run<L, Fut, Types>(mut self, launcher: L) -> eyre::Result<()>
where
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, C::ChainSpec>>, Ext) -> Fut,
Fut: Future<Output = eyre::Result<()>>,
Types: CliNodeTypes<ChainSpec = C::ChainSpec>,
{
// add network name to logs dir
self.logs.log_file_directory =
Expand All @@ -120,21 +120,17 @@ where
Commands::Node(command) => {
runner.run_command_until_exit(|ctx| command.execute(ctx, launcher))
}
Commands::Init(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<ScrollNode>())
}
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute::<Types>()),
Commands::InitState(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<ScrollNode>())
runner.run_blocking_until_ctrl_c(command.execute::<Types>())
}
Commands::Import(command) => runner.run_blocking_until_ctrl_c(
command.execute::<ScrollNode, _, _>(ScrollExecutorProvider::scroll),
command.execute::<Types, _, _>(ScrollExecutorProvider::scroll),
),
Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<ScrollNode>())
}
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute::<Types>()),
Commands::Stage(command) => runner.run_command_until_exit(|ctx| {
command.execute::<ScrollNode, _, _, EthNetworkPrimitives>(
command.execute::<Types, _, _, EthNetworkPrimitives>(
ctx,
ScrollExecutorProvider::scroll,
)
Expand All @@ -144,9 +140,9 @@ where
}
Commands::Config(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Recover(command) => {
runner.run_command_until_exit(|ctx| command.execute::<ScrollNode>(ctx))
runner.run_command_until_exit(|ctx| command.execute::<Types>(ctx))
}
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::<ScrollNode>()),
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::<Types>()),
}
}

Expand Down
Loading

0 comments on commit 6942180

Please sign in to comment.