Revert "Moving Optimism bin to Optimism Cli" (#9875)

This commit is contained in:
Matthias Seitz
2024-07-29 22:52:59 +02:00
committed by GitHub
parent 700e660337
commit 700caca7a8
22 changed files with 134 additions and 157 deletions

View File

@ -70,7 +70,7 @@ jobs:
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
cache-on-failure: true cache-on-failure: true
- run: cargo hack check --workspace --exclude op-reth - run: cargo hack check
msrv: msrv:
name: MSRV / ${{ matrix.network }} name: MSRV / ${{ matrix.network }}

View File

@ -33,7 +33,8 @@ jobs:
with: with:
cache-on-failure: true cache-on-failure: true
- name: Build op-reth - name: Build op-reth
run: make install-op run: |
cargo install --features asm-keccak,jemalloc,optimism --bin op-reth --path bin/reth
- name: Run sync - name: Run sync
# https://basescan.org/block/10000 # https://basescan.org/block/10000
run: | run: |

19
Cargo.lock generated
View File

@ -5256,19 +5256,6 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "op-reth"
version = "1.0.3"
dependencies = [
"clap",
"reth-cli-util",
"reth-node-builder",
"reth-node-optimism",
"reth-optimism-cli",
"reth-tracing",
"tikv-jemallocator",
]
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"
version = "0.3.1" version = "0.3.1"
@ -6274,6 +6261,9 @@ dependencies = [
"reth-node-ethereum", "reth-node-ethereum",
"reth-node-events", "reth-node-events",
"reth-node-metrics", "reth-node-metrics",
"reth-node-optimism",
"reth-optimism-cli",
"reth-optimism-primitives",
"reth-payload-builder", "reth-payload-builder",
"reth-payload-primitives", "reth-payload-primitives",
"reth-payload-validator", "reth-payload-validator",
@ -7918,7 +7908,6 @@ dependencies = [
"reth-chainspec", "reth-chainspec",
"reth-cli", "reth-cli",
"reth-cli-commands", "reth-cli-commands",
"reth-cli-runner",
"reth-config", "reth-config",
"reth-consensus", "reth-consensus",
"reth-db", "reth-db",
@ -7929,7 +7918,6 @@ dependencies = [
"reth-evm-optimism", "reth-evm-optimism",
"reth-execution-types", "reth-execution-types",
"reth-network-p2p", "reth-network-p2p",
"reth-node-builder",
"reth-node-core", "reth-node-core",
"reth-node-events", "reth-node-events",
"reth-optimism-primitives", "reth-optimism-primitives",
@ -7940,7 +7928,6 @@ dependencies = [
"reth-stages-types", "reth-stages-types",
"reth-static-file", "reth-static-file",
"reth-static-file-types", "reth-static-file-types",
"reth-tracing",
"serde_json", "serde_json",
"shellexpand", "shellexpand",
"tempfile", "tempfile",

View File

@ -67,7 +67,6 @@ members = [
"crates/node/builder/", "crates/node/builder/",
"crates/node/events/", "crates/node/events/",
"crates/node/metrics", "crates/node/metrics",
"crates/optimism/bin",
"crates/optimism/cli", "crates/optimism/cli",
"crates/optimism/consensus", "crates/optimism/consensus",
"crates/optimism/evm/", "crates/optimism/evm/",
@ -338,7 +337,6 @@ reth-node-ethereum = { path = "crates/ethereum/node" }
reth-node-events = { path = "crates/node/events" } reth-node-events = { path = "crates/node/events" }
reth-node-metrics = { path = "crates/node/metrics" } reth-node-metrics = { path = "crates/node/metrics" }
reth-node-optimism = { path = "crates/optimism/node" } reth-node-optimism = { path = "crates/optimism/node" }
reth-optimism-bin = { path = "crates/optimism/bin" }
reth-optimism-cli = { path = "crates/optimism/cli" } reth-optimism-cli = { path = "crates/optimism/cli" }
reth-optimism-consensus = { path = "crates/optimism/consensus" } reth-optimism-consensus = { path = "crates/optimism/consensus" }
reth-optimism-payload-builder = { path = "crates/optimism/payload" } reth-optimism-payload-builder = { path = "crates/optimism/payload" }
@ -546,5 +544,3 @@ serial_test = "3"
similar-asserts = "1.5.0" similar-asserts = "1.5.0"
test-fuzz = "5" test-fuzz = "5"
iai-callgrind = "0.11" iai-callgrind = "0.11"
tikv-jemallocator = { version = "0.5.0" }

View File

@ -52,7 +52,7 @@ install: ## Build and install the reth binary under `~/.cargo/bin`.
.PHONY: install-op .PHONY: install-op
install-op: ## Build and install the op-reth binary under `~/.cargo/bin`. install-op: ## Build and install the op-reth binary under `~/.cargo/bin`.
cargo install --path crates/optimism/bin --bin op-reth --force --locked \ cargo install --path bin/reth --bin op-reth --force --locked \
--features "optimism,$(FEATURES)" \ --features "optimism,$(FEATURES)" \
--profile "$(PROFILE)" \ --profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS) $(CARGO_INSTALL_EXTRA_FLAGS)
@ -63,14 +63,14 @@ build: ## Build the reth binary into `target` directory.
.PHONY: build-op .PHONY: build-op
build-op: ## Build the op-reth binary into `target` directory. build-op: ## Build the op-reth binary into `target` directory.
cargo build --bin op-reth --features "optimism,$(FEATURES)" --profile "$(PROFILE)" --manifest-path crates/optimism/bin/Cargo.toml cargo build --bin op-reth --features "optimism,$(FEATURES)" --profile "$(PROFILE)"
# Builds the reth binary natively. # Builds the reth binary natively.
build-native-%: build-native-%:
cargo build --bin reth --target $* --features "$(FEATURES)" --profile "$(PROFILE)" cargo build --bin reth --target $* --features "$(FEATURES)" --profile "$(PROFILE)"
op-build-native-%: op-build-native-%:
cargo build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)" --manifest-path crates/optimism/bin/Cargo.toml cargo build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"
# The following commands use `cross` to build a cross-compile. # The following commands use `cross` to build a cross-compile.
# #
@ -105,7 +105,7 @@ build-%:
op-build-%: op-build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \ RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)" --manifest-path crates/optimism/bin/Cargo.toml cross build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"
# Unfortunately we can't easily use cross to build for Darwin because of licensing issues. # Unfortunately we can't easily use cross to build for Darwin because of licensing issues.
# If we wanted to, we would need to build a custom Docker image with the SDK available. # If we wanted to, we would need to build a custom Docker image with the SDK available.
@ -313,7 +313,7 @@ maxperf: ## Builds `reth` with the most aggressive optimisations.
.PHONY: maxperf-op .PHONY: maxperf-op
maxperf-op: ## Builds `op-reth` with the most aggressive optimisations. maxperf-op: ## Builds `op-reth` with the most aggressive optimisations.
RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc,asm-keccak,optimism --bin op-reth --manifest-path crates/optimism/bin/Cargo.toml RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc,asm-keccak,optimism --bin op-reth
.PHONY: maxperf-no-asm .PHONY: maxperf-no-asm
maxperf-no-asm: ## Builds `reth` with the most aggressive optimisations, minus the "asm-keccak" feature. maxperf-no-asm: ## Builds `reth` with the most aggressive optimisations, minus the "asm-keccak" feature.

View File

@ -72,7 +72,7 @@ clap = { workspace = true, features = ["derive", "env"] }
csv = "1.3.0" csv = "1.3.0"
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true } tikv-jemallocator = { version = "0.5.0", optional = true }
libc = "0.2" libc = "0.2"
[dev-dependencies] [dev-dependencies]

View File

@ -56,6 +56,9 @@ reth-static-file-types = { workspace = true, features = ["clap"] }
reth-trie = { workspace = true, features = ["metrics"] } reth-trie = { workspace = true, features = ["metrics"] }
reth-trie-db = { workspace = true, features = ["metrics"] } reth-trie-db = { workspace = true, features = ["metrics"] }
reth-node-api.workspace = true reth-node-api.workspace = true
reth-node-optimism = { workspace = true, optional = true, features = [
"optimism",
] }
reth-node-core.workspace = true reth-node-core.workspace = true
reth-ethereum-payload-builder.workspace = true reth-ethereum-payload-builder.workspace = true
reth-db-common.workspace = true reth-db-common.workspace = true
@ -64,9 +67,11 @@ reth-node-builder.workspace = true
reth-node-events.workspace = true reth-node-events.workspace = true
reth-node-metrics.workspace = true reth-node-metrics.workspace = true
reth-consensus.workspace = true reth-consensus.workspace = true
reth-optimism-primitives.workspace = true
reth-engine-util.workspace = true reth-engine-util.workspace = true
reth-prune.workspace = true reth-prune.workspace = true
reth-stages-api.workspace = true reth-stages-api.workspace = true
reth-optimism-cli = { workspace = true, optional = true }
# crypto # crypto
alloy-rlp.workspace = true alloy-rlp.workspace = true
@ -106,7 +111,7 @@ itertools.workspace = true
discv5.workspace = true discv5.workspace = true
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true } tikv-jemallocator = { version = "0.5.0", optional = true }
libc = "0.2" libc = "0.2"
[dev-dependencies] [dev-dependencies]
@ -128,6 +133,21 @@ min-info-logs = ["tracing/release_max_level_info"]
min-debug-logs = ["tracing/release_max_level_debug"] min-debug-logs = ["tracing/release_max_level_debug"]
min-trace-logs = ["tracing/release_max_level_trace"] min-trace-logs = ["tracing/release_max_level_trace"]
optimism = [
"dep:reth-node-optimism",
"dep:reth-optimism-cli",
"reth-beacon-consensus/optimism",
"reth-blockchain-tree/optimism",
"reth-node-core/optimism",
"reth-optimism-cli?/optimism",
"reth-primitives/optimism",
"reth-provider/optimism",
"reth-rpc/optimism",
]
# no-op feature flag for switching between the `optimism` and default functionality in CI matrices
ethereum = []
[[bin]] [[bin]]
name = "reth" name = "reth"
path = "src/main.rs" path = "src/main.rs"
@ -135,3 +155,8 @@ path = "src/main.rs"
[[bin]] [[bin]]
name = "engine2" name = "engine2"
path = "src/engine2.rs" path = "src/engine2.rs"
[[bin]]
name = "op-reth"
path = "src/optimism.rs"
required-features = ["optimism"]

View File

@ -6,6 +6,7 @@ use crate::{
LogArgs, LogArgs,
}, },
commands::debug_cmd, commands::debug_cmd,
macros::block_executor,
version::{LONG_VERSION, SHORT_VERSION}, version::{LONG_VERSION, SHORT_VERSION},
}; };
use clap::{value_parser, Parser, Subcommand}; use clap::{value_parser, Parser, Subcommand};
@ -18,7 +19,6 @@ use reth_cli_commands::{
use reth_cli_runner::CliRunner; use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv; use reth_db::DatabaseEnv;
use reth_node_builder::{NodeBuilder, WithLaunchContext}; use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_ethereum::EthExecutorProvider;
use reth_tracing::FileWorkerGuard; use reth_tracing::FileWorkerGuard;
use std::{ffi::OsString, fmt, future::Future, sync::Arc}; use std::{ffi::OsString, fmt, future::Future, sync::Arc};
use tracing::info; use tracing::info;
@ -151,13 +151,20 @@ impl<Ext: clap::Args + fmt::Debug> Cli<Ext> {
} }
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()), Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()), Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => { Commands::Import(command) => runner.run_blocking_until_ctrl_c(
runner.run_blocking_until_ctrl_c(command.execute(EthExecutorProvider::ethereum)) command.execute(|chain_spec| block_executor!(chain_spec)),
),
#[cfg(feature = "optimism")]
Commands::ImportOp(command) => runner.run_blocking_until_ctrl_c(command.execute()),
#[cfg(feature = "optimism")]
Commands::ImportReceiptsOp(command) => {
runner.run_blocking_until_ctrl_c(command.execute())
} }
Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()), Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()), Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Stage(command) => runner Commands::Stage(command) => runner.run_command_until_exit(|ctx| {
.run_command_until_exit(|ctx| command.execute(ctx, EthExecutorProvider::ethereum)), command.execute(ctx, |chain_spec| block_executor!(chain_spec))
}),
Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()), Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()),
#[cfg(feature = "dev")] #[cfg(feature = "dev")]
Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()),
@ -193,6 +200,14 @@ pub enum Commands<Ext: clap::Args + fmt::Debug = NoArgs> {
/// This syncs RLP encoded blocks from a file. /// This syncs RLP encoded blocks from a file.
#[command(name = "import")] #[command(name = "import")]
Import(import::ImportCommand), Import(import::ImportCommand),
/// This syncs RLP encoded OP blocks below Bedrock from a file, without executing.
#[cfg(feature = "optimism")]
#[command(name = "import-op")]
ImportOp(reth_optimism_cli::ImportOpCommand),
/// This imports RLP encoded receipts from a file.
#[cfg(feature = "optimism")]
#[command(name = "import-receipts-op")]
ImportReceiptsOp(reth_optimism_cli::ImportReceiptsOpCommand),
/// Dumps genesis block JSON configuration to stdout. /// Dumps genesis block JSON configuration to stdout.
DumpGenesis(dump_genesis::DumpGenesisCommand), DumpGenesis(dump_genesis::DumpGenesisCommand),
/// Database debugging utilities /// Database debugging utilities

View File

@ -1,4 +1,5 @@
//! Command for debugging block building. //! Command for debugging block building.
use crate::macros::block_executor;
use alloy_rlp::Decodable; use alloy_rlp::Decodable;
use clap::Parser; use clap::Parser;
use eyre::Context; use eyre::Context;
@ -18,7 +19,6 @@ use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_fs_util as fs; use reth_fs_util as fs;
use reth_node_api::PayloadBuilderAttributes; use reth_node_api::PayloadBuilderAttributes;
use reth_node_ethereum::EthExecutorProvider;
use reth_payload_builder::database::CachedReads; use reth_payload_builder::database::CachedReads;
use reth_primitives::{ use reth_primitives::{
constants::eip4844::LoadKzgSettingsError, revm_primitives::KzgSettings, Address, constants::eip4844::LoadKzgSettingsError, revm_primitives::KzgSettings, Address,
@ -120,7 +120,7 @@ impl Command {
let consensus: Arc<dyn Consensus> = let consensus: Arc<dyn Consensus> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));
let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); let executor = block_executor!(provider_factory.chain_spec());
// configure blockchain tree // configure blockchain tree
let tree_externals = let tree_externals =
@ -221,6 +221,17 @@ impl Command {
let payload_config = PayloadConfig::new( let payload_config = PayloadConfig::new(
Arc::clone(&best_block), Arc::clone(&best_block),
Bytes::default(), Bytes::default(),
#[cfg(feature = "optimism")]
reth_node_optimism::OptimismPayloadBuilderAttributes::try_new(
best_block.hash(),
reth_rpc_types::engine::OptimismPayloadAttributes {
payload_attributes: payload_attrs,
transactions: None,
no_tx_pool: None,
gas_limit: None,
},
)?,
#[cfg(not(feature = "optimism"))]
reth_payload_builder::EthPayloadBuilderAttributes::try_new( reth_payload_builder::EthPayloadBuilderAttributes::try_new(
best_block.hash(), best_block.hash(),
payload_attrs, payload_attrs,
@ -237,6 +248,13 @@ impl Command {
None, None,
); );
#[cfg(feature = "optimism")]
let payload_builder = reth_node_optimism::OptimismPayloadBuilder::new(
reth_node_optimism::OptimismEvmConfig::default(),
)
.compute_pending_block();
#[cfg(not(feature = "optimism"))]
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::default(); let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::default();
match payload_builder.try_build(args)? { match payload_builder.try_build(args)? {
@ -253,8 +271,7 @@ impl Command {
SealedBlockWithSenders::new(block.clone(), senders).unwrap(); SealedBlockWithSenders::new(block.clone(), senders).unwrap();
let db = StateProviderDatabase::new(blockchain_db.latest()?); let db = StateProviderDatabase::new(blockchain_db.latest()?);
let executor = let executor = block_executor!(provider_factory.chain_spec()).executor(db);
EthExecutorProvider::ethereum(provider_factory.chain_spec()).executor(db);
let BlockExecutionOutput { state, receipts, requests, .. } = let BlockExecutionOutput { state, receipts, requests, .. } =
executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?; executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?;

View File

@ -1,6 +1,6 @@
//! Command for debugging execution. //! Command for debugging execution.
use crate::{args::NetworkArgs, utils::get_single_header}; use crate::{args::NetworkArgs, macros::block_executor, utils::get_single_header};
use clap::Parser; use clap::Parser;
use futures::{stream::select as stream_select, StreamExt}; use futures::{stream::select as stream_select, StreamExt};
use reth_beacon_consensus::EthBeaconConsensus; use reth_beacon_consensus::EthBeaconConsensus;
@ -19,7 +19,6 @@ use reth_exex::ExExManagerHandle;
use reth_network::{NetworkEvents, NetworkHandle}; use reth_network::{NetworkEvents, NetworkHandle};
use reth_network_api::NetworkInfo; use reth_network_api::NetworkInfo;
use reth_network_p2p::{bodies::client::BodiesClient, headers::client::HeadersClient}; use reth_network_p2p::{bodies::client::BodiesClient, headers::client::HeadersClient};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::{BlockHashOrNumber, BlockNumber, B256}; use reth_primitives::{BlockHashOrNumber, BlockNumber, B256};
use reth_provider::{ use reth_provider::{
BlockExecutionWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader, BlockExecutionWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader,
@ -81,7 +80,7 @@ impl Command {
let prune_modes = config.prune.clone().map(|prune| prune.segments).unwrap_or_default(); let prune_modes = config.prune.clone().map(|prune| prune.segments).unwrap_or_default();
let (tip_tx, tip_rx) = watch::channel(B256::ZERO); let (tip_tx, tip_rx) = watch::channel(B256::ZERO);
let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); let executor = block_executor!(provider_factory.chain_spec());
let pipeline = Pipeline::builder() let pipeline = Pipeline::builder()
.with_tip_sender(tip_tx) .with_tip_sender(tip_tx)

View File

@ -2,6 +2,7 @@
use crate::{ use crate::{
args::NetworkArgs, args::NetworkArgs,
macros::block_executor,
utils::{get_single_body, get_single_header}, utils::{get_single_body, get_single_header},
}; };
use backon::{ConstantBuilder, Retryable}; use backon::{ConstantBuilder, Retryable};
@ -16,7 +17,6 @@ use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_network_api::NetworkInfo; use reth_network_api::NetworkInfo;
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber; use reth_primitives::BlockHashOrNumber;
use reth_provider::{ use reth_provider::{
writer::StorageWriter, AccountExtReader, ChainSpecProvider, HashingWriter, HeaderProvider, writer::StorageWriter, AccountExtReader, ChainSpecProvider, HashingWriter, HeaderProvider,
@ -130,7 +130,7 @@ impl Command {
provider_factory.static_file_provider(), provider_factory.static_file_provider(),
)); ));
let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()).executor(db); let executor = block_executor!(provider_factory.chain_spec()).executor(db);
let merkle_block_td = let merkle_block_td =
provider.header_td_by_number(merkle_block_number)?.unwrap_or_default(); provider.header_td_by_number(merkle_block_number)?.unwrap_or_default();

View File

@ -1,5 +1,5 @@
//! Command for debugging merkle trie calculation. //! Command for debugging merkle trie calculation.
use crate::{args::NetworkArgs, utils::get_single_header}; use crate::{args::NetworkArgs, macros::block_executor, utils::get_single_header};
use backon::{ConstantBuilder, Retryable}; use backon::{ConstantBuilder, Retryable};
use clap::Parser; use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus; use reth_beacon_consensus::EthBeaconConsensus;
@ -14,7 +14,6 @@ use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_network_api::NetworkInfo; use reth_network_api::NetworkInfo;
use reth_network_p2p::full_block::FullBlockClient; use reth_network_p2p::full_block::FullBlockClient;
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber; use reth_primitives::BlockHashOrNumber;
use reth_provider::{ use reth_provider::{
writer::StorageWriter, BlockNumReader, BlockWriter, ChainSpecProvider, HeaderProvider, writer::StorageWriter, BlockNumReader, BlockWriter, ChainSpecProvider, HeaderProvider,
@ -92,7 +91,7 @@ impl Command {
) )
.await?; .await?;
let executor_provider = EthExecutorProvider::ethereum(provider_factory.chain_spec()); let executor_provider = block_executor!(provider_factory.chain_spec());
// Initialize the fetch client // Initialize the fetch client
info!(target: "reth::cli", target_block_number=self.to, "Downloading tip of block range"); info!(target: "reth::cli", target_block_number=self.to, "Downloading tip of block range");

View File

@ -1,4 +1,4 @@
use crate::args::NetworkArgs; use crate::{args::NetworkArgs, macros::block_executor};
use clap::Parser; use clap::Parser;
use eyre::Context; use eyre::Context;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
@ -16,7 +16,6 @@ use reth_engine_util::engine_store::{EngineMessageStore, StoredEngineApiMessage}
use reth_fs_util as fs; use reth_fs_util as fs;
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_network_api::NetworkInfo; use reth_network_api::NetworkInfo;
use reth_node_ethereum::EthExecutorProvider;
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_provider::{ use reth_provider::{
providers::BlockchainProvider, CanonStateSubscriptions, ChainSpecProvider, ProviderFactory, providers::BlockchainProvider, CanonStateSubscriptions, ChainSpecProvider, ProviderFactory,
@ -79,7 +78,7 @@ impl Command {
let consensus: Arc<dyn Consensus> = let consensus: Arc<dyn Consensus> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));
let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); let executor = block_executor!(provider_factory.chain_spec());
// Configure blockchain tree // Configure blockchain tree
let tree_externals = let tree_externals =
@ -108,8 +107,15 @@ impl Command {
.await?; .await?;
// Set up payload builder // Set up payload builder
#[cfg(not(feature = "optimism"))]
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::default(); let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::default();
// Optimism's payload builder is implemented on the OptimismPayloadBuilder type.
#[cfg(feature = "optimism")]
let payload_builder = reth_node_optimism::OptimismPayloadBuilder::new(
reth_node_optimism::OptimismEvmConfig::default(),
);
let payload_generator = BasicPayloadJobGenerator::with_builder( let payload_generator = BasicPayloadJobGenerator::with_builder(
blockchain_db.clone(), blockchain_db.clone(),
NoopTransactionPool::default(), NoopTransactionPool::default(),
@ -119,6 +125,13 @@ impl Command {
payload_builder, payload_builder,
); );
#[cfg(feature = "optimism")]
let (payload_service, payload_builder): (
_,
PayloadBuilderHandle<reth_node_optimism::OptimismEngineTypes>,
) = PayloadBuilderService::new(payload_generator, blockchain_db.canonical_state_stream());
#[cfg(not(feature = "optimism"))]
let (payload_service, payload_builder): ( let (payload_service, payload_builder): (
_, _,
PayloadBuilderHandle<reth_node_ethereum::EthEngineTypes>, PayloadBuilderHandle<reth_node_ethereum::EthEngineTypes>,

View File

@ -6,6 +6,7 @@
#[global_allocator] #[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(not(feature = "optimism"))]
fn main() { fn main() {
use reth::cli::Cli; use reth::cli::Cli;
use reth_node_ethereum::{launch::EthNodeLauncher, node::EthereumAddOns, EthereumNode}; use reth_node_ethereum::{launch::EthNodeLauncher, node::EthereumAddOns, EthereumNode};

View File

@ -31,6 +31,7 @@
pub mod cli; pub mod cli;
pub mod commands; pub mod commands;
mod macros;
/// Re-exported utils. /// Re-exported utils.
pub mod utils { pub mod utils {

20
bin/reth/src/macros.rs Normal file
View File

@ -0,0 +1,20 @@
//! Helper macros
/// Creates the block executor type based on the configured feature.
///
/// Note(mattsse): This is incredibly horrible and will be replaced
#[cfg(not(feature = "optimism"))]
macro_rules! block_executor {
($chain_spec:expr) => {
reth_node_ethereum::EthExecutorProvider::ethereum($chain_spec)
};
}
#[cfg(feature = "optimism")]
macro_rules! block_executor {
($chain_spec:expr) => {
reth_node_optimism::OpExecutorProvider::optimism($chain_spec)
};
}
pub(crate) use block_executor;

View File

@ -5,6 +5,10 @@
#[global_allocator] #[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(all(feature = "optimism", not(test)))]
compile_error!("Cannot build the `reth` binary with the `optimism` feature flag enabled. Did you mean to build `op-reth`?");
#[cfg(not(feature = "optimism"))]
fn main() { fn main() {
use reth::cli::Cli; use reth::cli::Cli;
use reth_node_ethereum::EthereumNode; use reth_node_ethereum::EthereumNode;

View File

@ -1,8 +1,7 @@
#![allow(missing_docs, rustdoc::missing_crate_level_docs)] #![allow(missing_docs, rustdoc::missing_crate_level_docs)]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
use clap::Parser; use clap::Parser;
use reth::cli::Cli;
use reth_node_optimism::{args::RollupArgs, rpc::SequencerClient, OptimismNode}; use reth_node_optimism::{args::RollupArgs, rpc::SequencerClient, OptimismNode};
use std::sync::Arc; use std::sync::Arc;
@ -11,8 +10,11 @@ use std::sync::Arc;
#[global_allocator] #[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(not(feature = "optimism"))]
compile_error!("Cannot build the `op-reth` binary with the `optimism` feature flag disabled. Did you mean to build `reth`?");
#[cfg(feature = "optimism")]
fn main() { fn main() {
use reth_optimism_cli::Cli;
reth_cli_util::sigsegv_handler::install(); reth_cli_util::sigsegv_handler::install();
// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided. // Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.

View File

@ -1,42 +0,0 @@
[package]
name = "op-reth"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true
[dependencies]
reth-node-builder.workspace = true
reth-cli-util.workspace = true
reth-optimism-cli.workspace = true
reth-tracing.workspace = true
reth-node-optimism.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }
[lints]
workspace = true
[[bin]]
name = "op-reth"
path = "src/main.rs"
[features]
default = ["jemalloc"]
jemalloc = ["dep:tikv-jemallocator"]
jemalloc-prof = ["jemalloc", "tikv-jemallocator?/profiling"]
asm-keccak = ["reth-node-optimism/asm-keccak"]
optimism = [
"reth-optimism-cli/optimism",
"reth-node-optimism/optimism",
]

View File

@ -36,10 +36,6 @@ reth-errors.workspace = true
reth-config.workspace = true reth-config.workspace = true
reth-evm-optimism.workspace = true reth-evm-optimism.workspace = true
reth-cli.workspace = true reth-cli.workspace = true
reth-cli-runner.workspace = true
reth-node-builder.workspace = true
reth-tracing.workspace = true
# eth # eth
alloy-genesis.workspace = true alloy-genesis.workspace = true

View File

@ -34,22 +34,15 @@ use std::{ffi::OsString, fmt, sync::Arc};
use chainspec::OpChainSpecParser; use chainspec::OpChainSpecParser;
use clap::{command, value_parser, Parser}; use clap::{command, value_parser, Parser};
use commands::Commands; use commands::Commands;
use futures_util::Future;
use reth_chainspec::ChainSpec; use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser; use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::node::NoArgs; use reth_cli_commands::node::NoArgs;
use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv;
use reth_evm_optimism::OpExecutorProvider;
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_core::{ use reth_node_core::{
args::{utils::chain_help, LogArgs}, args::{utils::chain_help, LogArgs},
version::{LONG_VERSION, SHORT_VERSION}, version::{LONG_VERSION, SHORT_VERSION},
}; };
use reth_tracing::FileWorkerGuard;
use tracing::info;
/// The main op-reth cli interface. /// The main reth cli interface.
/// ///
/// This is the entrypoint to the executable. /// This is the entrypoint to the executable.
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
@ -107,52 +100,3 @@ impl Cli {
Self::try_parse_from(itr) Self::try_parse_from(itr)
} }
} }
impl<Ext: clap::Args + fmt::Debug> Cli<Ext> {
/// Execute the configured cli command.
///
/// 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<()>
where
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
Fut: Future<Output = eyre::Result<()>>,
{
// add network name to logs dir
self.logs.log_file_directory =
self.logs.log_file_directory.join(self.chain.chain.to_string());
let _guard = self.init_tracing()?;
info!(target: "reth::cli", "Initialized tracing, debug log directory: {}", self.logs.log_file_directory);
let runner = CliRunner::default();
match self.command {
Commands::Node(command) => {
runner.run_command_until_exit(|ctx| command.execute(ctx, launcher))
}
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::ImportOp(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::ImportReceiptsOp(command) => {
runner.run_blocking_until_ctrl_c(command.execute())
}
Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Stage(command) => runner
.run_command_until_exit(|ctx| command.execute(ctx, OpExecutorProvider::optimism)),
Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Config(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Recover(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute()),
}
}
/// Initializes tracing with the configured options.
///
/// If file logging is enabled, this function returns a guard that must be kept alive to ensure
/// that all logs are flushed to disk.
pub fn init_tracing(&self) -> eyre::Result<Option<FileWorkerGuard>> {
let guard = self.logs.init_tracing()?;
Ok(guard)
}
}

View File

@ -82,5 +82,4 @@ optimism = [
"reth-auto-seal-consensus/optimism", "reth-auto-seal-consensus/optimism",
"reth-optimism-rpc/optimism" "reth-optimism-rpc/optimism"
] ]
asm-keccak = ["reth-primitives/asm-keccak"]
test-utils = ["reth-node-builder/test-utils"] test-utils = ["reth-node-builder/test-utils"]