From 1223895466e4a47d7537bccdf7a9aeb23e16d27f Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:03:03 -0500 Subject: [PATCH] feat: separate node-builder crate (#6302) --- Cargo.lock | 61 ++++++++++++------- Cargo.toml | 6 +- bin/reth/Cargo.toml | 5 +- bin/reth/src/builder.rs | 8 +-- .../src/commands/debug_cmd/build_block.rs | 4 +- bin/reth/src/commands/debug_cmd/execution.rs | 2 +- .../commands/debug_cmd/in_memory_merkle.rs | 2 +- bin/reth/src/commands/debug_cmd/merkle.rs | 2 +- .../src/commands/debug_cmd/replay_engine.rs | 4 +- bin/reth/src/commands/import.rs | 2 +- bin/reth/src/commands/stage/dump/execution.rs | 2 +- bin/reth/src/commands/stage/dump/merkle.rs | 2 +- bin/reth/src/commands/stage/run.rs | 2 +- crates/blockchain-tree/Cargo.toml | 3 +- crates/blockchain-tree/src/blockchain_tree.rs | 2 +- crates/consensus/auto-seal/Cargo.toml | 2 +- crates/consensus/beacon/Cargo.toml | 4 +- .../consensus/beacon/src/engine/test_utils.rs | 2 +- crates/node-ethereum/Cargo.toml | 21 +++++++ .../src/engine.rs | 0 .../src/evm.rs | 0 .../src/lib.rs | 8 +-- .../Cargo.toml | 2 +- crates/node-optimism/src/engine.rs | 26 ++++++++ .../optimism.rs => node-optimism/src/evm.rs} | 53 ++++++++-------- crates/node-optimism/src/lib.rs | 20 ++++++ crates/revm/Cargo.toml | 3 +- crates/revm/src/processor.rs | 2 +- crates/rpc/rpc-builder/Cargo.toml | 4 +- crates/rpc/rpc-builder/src/lib.rs | 2 +- crates/rpc/rpc-builder/tests/it/auth.rs | 2 +- crates/rpc/rpc-builder/tests/it/utils.rs | 2 +- crates/rpc/rpc-engine-api/Cargo.toml | 3 +- crates/rpc/rpc-engine-api/src/engine_api.rs | 2 +- crates/rpc/rpc/Cargo.toml | 3 +- crates/rpc/rpc/src/eth/api/server.rs | 2 +- crates/rpc/rpc/src/eth/api/state.rs | 2 +- crates/rpc/rpc/src/eth/api/transactions.rs | 2 +- crates/stages/Cargo.toml | 3 +- crates/stages/src/lib.rs | 2 +- crates/stages/src/sets.rs | 4 +- crates/stages/src/stages/execution.rs | 2 +- crates/stages/src/stages/mod.rs | 2 +- testing/ef-tests/Cargo.toml | 2 +- testing/ef-tests/src/cases/blockchain_test.rs | 2 +- 45 files changed, 191 insertions(+), 100 deletions(-) create mode 100644 crates/node-ethereum/Cargo.toml rename crates/{node-builder => node-ethereum}/src/engine.rs (100%) rename crates/{node-builder => node-ethereum}/src/evm.rs (100%) rename crates/{node-builder => node-ethereum}/src/lib.rs (69%) rename crates/{node-builder => node-optimism}/Cargo.toml (93%) create mode 100644 crates/node-optimism/src/engine.rs rename crates/{node-builder/src/optimism.rs => node-optimism/src/evm.rs} (56%) create mode 100644 crates/node-optimism/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d27f4f4e0..16ba50294 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2284,7 +2284,7 @@ dependencies = [ "alloy-rlp", "reth-db", "reth-interfaces", - "reth-node-builder", + "reth-node-ethereum", "reth-primitives", "reth-provider", "reth-revm", @@ -5760,8 +5760,9 @@ dependencies = [ "reth-network-api", "reth-nippy-jar", "reth-node-api", - "reth-node-builder", "reth-node-core", + "reth-node-ethereum", + "reth-node-optimism", "reth-optimism-payload-builder", "reth-payload-builder", "reth-payload-validator", @@ -5805,7 +5806,7 @@ dependencies = [ "reth-beacon-consensus", "reth-interfaces", "reth-node-api", - "reth-node-builder", + "reth-node-ethereum", "reth-primitives", "reth-provider", "reth-revm", @@ -5855,7 +5856,8 @@ dependencies = [ "reth-interfaces", "reth-metrics", "reth-node-api", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-payload-builder", "reth-payload-validator", "reth-primitives", @@ -5898,7 +5900,8 @@ dependencies = [ "reth-db", "reth-interfaces", "reth-metrics", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-primitives", "reth-provider", "reth-revm", @@ -6381,17 +6384,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "reth-node-builder" -version = "0.1.0-alpha.16" -dependencies = [ - "reth-node-api", - "reth-payload-builder", - "reth-primitives", - "reth-rpc-types", - "serde", -] - [[package]] name = "reth-node-core" version = "0.1.0-alpha.16" @@ -6461,6 +6453,28 @@ dependencies = [ "vergen", ] +[[package]] +name = "reth-node-ethereum" +version = "0.1.0-alpha.16" +dependencies = [ + "reth-node-api", + "reth-payload-builder", + "reth-primitives", + "reth-rpc-types", + "serde", +] + +[[package]] +name = "reth-node-optimism" +version = "0.1.0-alpha.16" +dependencies = [ + "reth-node-api", + "reth-payload-builder", + "reth-primitives", + "reth-rpc-types", + "serde", +] + [[package]] name = "reth-optimism-payload-builder" version = "0.1.0-alpha.16" @@ -6624,7 +6638,8 @@ dependencies = [ "reth-consensus-common", "reth-interfaces", "reth-node-api", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-primitives", "reth-provider", "reth-trie", @@ -6663,7 +6678,8 @@ dependencies = [ "reth-network", "reth-network-api", "reth-node-api", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-primitives", "reth-provider", "reth-revm", @@ -6730,7 +6746,8 @@ dependencies = [ "reth-metrics", "reth-network-api", "reth-node-api", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-payload-builder", "reth-primitives", "reth-provider", @@ -6766,7 +6783,8 @@ dependencies = [ "reth-interfaces", "reth-metrics", "reth-node-api", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-payload-builder", "reth-primitives", "reth-provider", @@ -6862,7 +6880,8 @@ dependencies = [ "reth-eth-wire", "reth-interfaces", "reth-metrics", - "reth-node-builder", + "reth-node-ethereum", + "reth-node-optimism", "reth-primitives", "reth-provider", "reth-revm", diff --git a/Cargo.toml b/Cargo.toml index 09fa887b6..d6b33e28b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,8 @@ members = [ "crates/rpc/rpc-testing-util/", "crates/rpc/rpc-types/", "crates/rpc/rpc-types-compat/", - "crates/node-builder/", + "crates/node-ethereum/", + "crates/node-optimism/", "crates/node-core/", "crates/node-api/", "crates/snapshot/", @@ -121,7 +122,8 @@ reth-consensus-common = { path = "crates/consensus/common" } reth-db = { path = "crates/storage/db" } reth-discv4 = { path = "crates/net/discv4" } reth-dns-discovery = { path = "crates/net/dns" } -reth-node-builder = { path = "crates/node-builder" } +reth-node-ethereum = { path = "crates/node-ethereum" } +reth-node-optimism = { path = "crates/node-optimism" } reth-node-core = { path = "crates/node-core" } reth-node-api = { path = "crates/node-api" } reth-downloaders = { path = "crates/net/downloaders" } diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index a6c0a5a43..d40081390 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -54,7 +54,8 @@ reth-snapshot = { workspace = true, features = ["clap"] } reth-trie.workspace = true reth-nippy-jar.workspace = true reth-node-api.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism = { workspace = true, optional = true } reth-node-core.workspace = true # crypto @@ -150,7 +151,7 @@ optimism = [ "reth-optimism-payload-builder/optimism", "reth-ethereum-payload-builder/optimism", "reth-node-api/optimism", - "reth-node-builder/optimism", + "dep:reth-node-optimism", "reth-node-core/optimism", ] diff --git a/bin/reth/src/builder.rs b/bin/reth/src/builder.rs index d55c27465..464024769 100644 --- a/bin/reth/src/builder.rs +++ b/bin/reth/src/builder.rs @@ -24,10 +24,6 @@ use reth_db::{ use reth_interfaces::p2p::either::EitherDownloader; use reth_network::NetworkEvents; use reth_network_api::{NetworkInfo, PeersInfo}; -#[cfg(not(feature = "optimism"))] -use reth_node_builder::{EthEngineTypes, EthEvmConfig}; -#[cfg(feature = "optimism")] -use reth_node_builder::{OptimismEngineTypes, OptimismEvmConfig}; use reth_node_core::{ cli::{ components::{RethNodeComponentsImpl, RethRpcServerHandles}, @@ -38,6 +34,10 @@ use reth_node_core::{ dirs::{ChainPath, DataDirPath}, version::SHORT_VERSION, }; +#[cfg(not(feature = "optimism"))] +use reth_node_ethereum::{EthEngineTypes, EthEvmConfig}; +#[cfg(feature = "optimism")] +use reth_node_optimism::{OptimismEngineTypes, OptimismEvmConfig}; use reth_payload_builder::PayloadBuilderHandle; use reth_primitives::DisplayHardforks; use reth_provider::{providers::BlockchainProvider, ProviderFactory}; diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 1da61834d..698e7bcd9 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -15,9 +15,9 @@ use reth_db::{init_db, mdbx::DatabaseArguments, DatabaseEnv}; use reth_interfaces::{consensus::Consensus, RethResult}; use reth_node_api::PayloadBuilderAttributes; #[cfg(not(feature = "optimism"))] -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; #[cfg(feature = "optimism")] -use reth_node_builder::OptimismEvmConfig; +use reth_node_optimism::OptimismEvmConfig; use reth_payload_builder::database::CachedReads; #[cfg(feature = "optimism")] use reth_payload_builder::OptimismPayloadBuilderAttributes; diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index 4ecc6cba5..6b12dfdfc 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -27,7 +27,7 @@ use reth_interfaces::{ }; use reth_network::{NetworkEvents, NetworkHandle}; use reth_network_api::NetworkInfo; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{fs, stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, B256}; use reth_provider::{BlockExecutionWriter, HeaderSyncMode, ProviderFactory, StageCheckpointReader}; use reth_stages::{ diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index 4d280b7e4..858520ecb 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -17,7 +17,7 @@ use reth_db::{init_db, mdbx::DatabaseArguments, DatabaseEnv}; use reth_interfaces::executor::BlockValidationError; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{fs, stage::StageId, BlockHashOrNumber, ChainSpec}; use reth_provider::{ AccountExtReader, BlockWriter, ExecutorFactory, HashingWriter, HeaderProvider, diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 25c0960ac..dc78162cb 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -20,7 +20,7 @@ use reth_db::{ use reth_interfaces::{consensus::Consensus, p2p::full_block::FullBlockClient}; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{ fs, stage::{StageCheckpoint, StageId}, diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index fd45630f4..ba84baac5 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -21,9 +21,9 @@ use reth_interfaces::consensus::Consensus; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; #[cfg(not(feature = "optimism"))] -use reth_node_builder::{EthEngineTypes, EthEvmConfig}; +use reth_node_ethereum::{EthEngineTypes, EthEvmConfig}; #[cfg(feature = "optimism")] -use reth_node_builder::{OptimismEngineTypes, OptimismEvmConfig}; +use reth_node_optimism::{OptimismEngineTypes, OptimismEvmConfig}; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; use reth_primitives::{fs, ChainSpec}; use reth_provider::{providers::BlockchainProvider, CanonStateSubscriptions, ProviderFactory}; diff --git a/bin/reth/src/commands/import.rs b/bin/reth/src/commands/import.rs index acd04e97d..b6ba0c1f0 100644 --- a/bin/reth/src/commands/import.rs +++ b/bin/reth/src/commands/import.rs @@ -16,7 +16,7 @@ use reth_downloaders::{ headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; use reth_interfaces::consensus::Consensus; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{stage::StageId, ChainSpec, B256}; use reth_provider::{HeaderSyncMode, ProviderFactory, StageCheckpointReader}; use reth_stages::{ diff --git a/bin/reth/src/commands/stage/dump/execution.rs b/bin/reth/src/commands/stage/dump/execution.rs index 48bfc67df..b6a2c94cf 100644 --- a/bin/reth/src/commands/stage/dump/execution.rs +++ b/bin/reth/src/commands/stage/dump/execution.rs @@ -5,7 +5,7 @@ use reth_db::{ cursor::DbCursorRO, database::Database, table::TableImporter, tables, transaction::DbTx, DatabaseEnv, }; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{stage::StageCheckpoint, ChainSpec}; use reth_provider::ProviderFactory; use reth_revm::EvmProcessorFactory; diff --git a/bin/reth/src/commands/stage/dump/merkle.rs b/bin/reth/src/commands/stage/dump/merkle.rs index 3f7481be1..f0f1fc233 100644 --- a/bin/reth/src/commands/stage/dump/merkle.rs +++ b/bin/reth/src/commands/stage/dump/merkle.rs @@ -2,7 +2,7 @@ use super::setup; use crate::utils::DbTool; use eyre::Result; use reth_db::{database::Database, table::TableImporter, tables, DatabaseEnv}; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{stage::StageCheckpoint, BlockNumber, ChainSpec, PruneModes}; use reth_provider::ProviderFactory; use reth_stages::{ diff --git a/bin/reth/src/commands/stage/run.rs b/bin/reth/src/commands/stage/run.rs index d32fe9ae7..5e2a6552b 100644 --- a/bin/reth/src/commands/stage/run.rs +++ b/bin/reth/src/commands/stage/run.rs @@ -17,7 +17,7 @@ use reth_beacon_consensus::BeaconConsensus; use reth_config::Config; use reth_db::{init_db, mdbx::DatabaseArguments}; use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::ChainSpec; use reth_provider::{ProviderFactory, StageCheckpointReader}; use reth_stages::{ diff --git a/crates/blockchain-tree/Cargo.toml b/crates/blockchain-tree/Cargo.toml index 56c45ab9f..6ba766c30 100644 --- a/crates/blockchain-tree/Cargo.toml +++ b/crates/blockchain-tree/Cargo.toml @@ -45,7 +45,8 @@ reth-interfaces = { workspace = true, features = ["test-utils"] } reth-primitives = { workspace = true , features = ["test-utils"] } reth-provider = { workspace = true, features = ["test-utils"] } reth-revm.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism.workspace = true parking_lot.workspace = true assert_matches.workspace = true diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index fe90047f6..dc5914de2 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1239,7 +1239,7 @@ mod tests { use linked_hash_set::LinkedHashSet; use reth_db::{tables, test_utils::TempDatabase, transaction::DbTxMut, DatabaseEnv}; use reth_interfaces::test_utils::TestConsensus; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{ constants::{EIP1559_INITIAL_BASE_FEE, EMPTY_ROOT_HASH, ETHEREUM_BLOCK_GAS_LIMIT}, keccak256, diff --git a/crates/consensus/auto-seal/Cargo.toml b/crates/consensus/auto-seal/Cargo.toml index 25b5db192..6cbae8bfa 100644 --- a/crates/consensus/auto-seal/Cargo.toml +++ b/crates/consensus/auto-seal/Cargo.toml @@ -21,7 +21,7 @@ reth-stages.workspace = true reth-revm.workspace = true reth-transaction-pool.workspace = true reth-node-api.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true # async diff --git a/crates/consensus/beacon/Cargo.toml b/crates/consensus/beacon/Cargo.toml index ef6242edc..938b3b4db 100644 --- a/crates/consensus/beacon/Cargo.toml +++ b/crates/consensus/beacon/Cargo.toml @@ -55,7 +55,8 @@ reth-rpc-types-compat.workspace = true reth-tracing.workspace = true reth-revm.workspace = true reth-downloaders.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism.workspace = true assert_matches.workspace = true @@ -67,4 +68,5 @@ optimism = [ "reth-rpc-types/optimism", "reth-payload-builder/optimism", "reth-blockchain-tree/optimism", + "reth-node-api/optimism", ] diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index bbe0f8492..f89aad873 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -22,7 +22,7 @@ use reth_interfaces::{ sync::NoopSyncStateUpdater, test_utils::{NoopFullBlockClient, TestConsensus}, }; -use reth_node_builder::{EthEngineTypes, EthEvmConfig}; +use reth_node_ethereum::{EthEngineTypes, EthEvmConfig}; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::{BlockNumber, ChainSpec, PruneModes, Receipt, B256, U256}; use reth_provider::{ diff --git a/crates/node-ethereum/Cargo.toml b/crates/node-ethereum/Cargo.toml new file mode 100644 index 000000000..051c505d2 --- /dev/null +++ b/crates/node-ethereum/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "reth-node-ethereum" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[lints] +workspace = true + +[dependencies] +# reth +reth-primitives.workspace = true +reth-payload-builder.workspace = true +reth-rpc-types.workspace = true +reth-node-api.workspace = true + +# io +serde.workspace = true diff --git a/crates/node-builder/src/engine.rs b/crates/node-ethereum/src/engine.rs similarity index 100% rename from crates/node-builder/src/engine.rs rename to crates/node-ethereum/src/engine.rs diff --git a/crates/node-builder/src/evm.rs b/crates/node-ethereum/src/evm.rs similarity index 100% rename from crates/node-builder/src/evm.rs rename to crates/node-ethereum/src/evm.rs diff --git a/crates/node-builder/src/lib.rs b/crates/node-ethereum/src/lib.rs similarity index 69% rename from crates/node-builder/src/lib.rs rename to crates/node-ethereum/src/lib.rs index 13050eb40..a21d5f5d7 100644 --- a/crates/node-builder/src/lib.rs +++ b/crates/node-ethereum/src/lib.rs @@ -1,4 +1,4 @@ -//! Standalone crate for Reth configuration and builder types. +//! Standalone crate for ethereum-specific Reth configuration and builder types. #![doc( html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", @@ -16,9 +16,3 @@ pub use engine::EthEngineTypes; /// trait. pub mod evm; pub use evm::EthEvmConfig; - -/// Exports optimism-specific types that implement traits in [reth_node_api]. -#[cfg(feature = "optimism")] -pub mod optimism; -#[cfg(feature = "optimism")] -pub use optimism::{OptimismEngineTypes, OptimismEvmConfig}; diff --git a/crates/node-builder/Cargo.toml b/crates/node-optimism/Cargo.toml similarity index 93% rename from crates/node-builder/Cargo.toml rename to crates/node-optimism/Cargo.toml index bf0a7eb9b..13df047f1 100644 --- a/crates/node-builder/Cargo.toml +++ b/crates/node-optimism/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "reth-node-builder" +name = "reth-node-optimism" version.workspace = true edition.workspace = true rust-version.workspace = true diff --git a/crates/node-optimism/src/engine.rs b/crates/node-optimism/src/engine.rs new file mode 100644 index 000000000..155b94430 --- /dev/null +++ b/crates/node-optimism/src/engine.rs @@ -0,0 +1,26 @@ +use reth_node_api::{ + optimism_validate_version_specific_fields, AttributesValidationError, EngineApiMessageVersion, + EngineTypes, PayloadOrAttributes, +}; +use reth_payload_builder::{EthBuiltPayload, OptimismPayloadBuilderAttributes}; +use reth_primitives::ChainSpec; +use reth_rpc_types::engine::OptimismPayloadAttributes; + +/// The types used in the optimism beacon consensus engine. +#[derive(Debug, Default, Clone)] +#[non_exhaustive] +pub struct OptimismEngineTypes; + +impl EngineTypes for OptimismEngineTypes { + type PayloadAttributes = OptimismPayloadAttributes; + type PayloadBuilderAttributes = OptimismPayloadBuilderAttributes; + type BuiltPayload = EthBuiltPayload; + + fn validate_version_specific_fields( + chain_spec: &ChainSpec, + version: EngineApiMessageVersion, + payload_or_attrs: PayloadOrAttributes<'_, OptimismPayloadAttributes>, + ) -> Result<(), AttributesValidationError> { + optimism_validate_version_specific_fields(chain_spec, version, payload_or_attrs) + } +} diff --git a/crates/node-builder/src/optimism.rs b/crates/node-optimism/src/evm.rs similarity index 56% rename from crates/node-builder/src/optimism.rs rename to crates/node-optimism/src/evm.rs index 8385fb6f8..e3ad9dc2e 100644 --- a/crates/node-builder/src/optimism.rs +++ b/crates/node-optimism/src/evm.rs @@ -1,34 +1,9 @@ -#![cfg(feature = "optimism")] -use reth_node_api::{ - optimism_validate_version_specific_fields, AttributesValidationError, EngineApiMessageVersion, - EngineTypes, EvmEnvConfig, PayloadOrAttributes, -}; -use reth_payload_builder::{EthBuiltPayload, OptimismPayloadBuilderAttributes}; +use reth_node_api::EvmEnvConfig; use reth_primitives::{ revm::{config::revm_spec, env::fill_op_tx_env}, revm_primitives::{AnalysisKind, CfgEnv, TxEnv}, Address, Bytes, ChainSpec, Head, Header, Transaction, U256, }; -use reth_rpc_types::engine::OptimismPayloadAttributes; - -/// The types used in the optimism beacon consensus engine. -#[derive(Debug, Default, Clone)] -#[non_exhaustive] -pub struct OptimismEngineTypes; - -impl EngineTypes for OptimismEngineTypes { - type PayloadAttributes = OptimismPayloadAttributes; - type PayloadBuilderAttributes = OptimismPayloadBuilderAttributes; - type BuiltPayload = EthBuiltPayload; - - fn validate_version_specific_fields( - chain_spec: &ChainSpec, - version: EngineApiMessageVersion, - payload_or_attrs: PayloadOrAttributes<'_, OptimismPayloadAttributes>, - ) -> Result<(), AttributesValidationError> { - optimism_validate_version_specific_fields(chain_spec, version, payload_or_attrs) - } -} /// Optimism-related EVM configuration. #[derive(Debug, Default, Clone, Copy)] @@ -70,3 +45,29 @@ impl EvmEnvConfig for OptimismEvmConfig { cfg_env.optimism = chain_spec.is_optimism(); } } + +#[cfg(test)] +mod tests { + use super::*; + use reth_primitives::revm_primitives::BlockEnv; + + #[test] + #[ignore] + fn test_fill_cfg_and_block_env() { + let mut cfg_env = CfgEnv::default(); + let mut block_env = BlockEnv::default(); + let header = Header::default(); + let chain_spec = ChainSpec::default(); + let total_difficulty = U256::ZERO; + + OptimismEvmConfig::fill_cfg_and_block_env( + &mut cfg_env, + &mut block_env, + &chain_spec, + &header, + total_difficulty, + ); + + assert_eq!(cfg_env.chain_id, chain_spec.chain().id()); + } +} diff --git a/crates/node-optimism/src/lib.rs b/crates/node-optimism/src/lib.rs new file mode 100644 index 000000000..e5628c9ab --- /dev/null +++ b/crates/node-optimism/src/lib.rs @@ -0,0 +1,20 @@ +//! Standalone crate for Optimism-specific Reth configuration and builder types. + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +// The `optimism` feature must be enabled to use this crate. +#![cfg(feature = "optimism")] + +/// Exports optimism-specific implementations of the [EngineTypes](reth_node_api::EngineTypes) +/// trait. +pub mod engine; +pub use engine::OptimismEngineTypes; + +/// Exports optimism-specific implementations of the [EvmEnvConfig](reth_node_api::EvmEnvConfig) +/// trait. +pub mod evm; +pub use evm::OptimismEvmConfig; diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 2ca18b165..64a525bfb 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -28,7 +28,8 @@ tracing.workspace = true [dev-dependencies] reth-trie.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism.workspace = true [features] optimism = [ diff --git a/crates/revm/src/processor.rs b/crates/revm/src/processor.rs index c56b4ec84..ced3206b8 100644 --- a/crates/revm/src/processor.rs +++ b/crates/revm/src/processor.rs @@ -556,7 +556,7 @@ pub fn verify_receipt<'a>( mod tests { use super::*; use reth_interfaces::provider::ProviderResult; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{ bytes, constants::{BEACON_ROOTS_ADDRESS, SYSTEM_ADDRESS}, diff --git a/crates/rpc/rpc-builder/Cargo.toml b/crates/rpc/rpc-builder/Cargo.toml index afea11c31..375822514 100644 --- a/crates/rpc/rpc-builder/Cargo.toml +++ b/crates/rpc/rpc-builder/Cargo.toml @@ -26,7 +26,8 @@ reth-tasks.workspace = true reth-transaction-pool.workspace = true reth-rpc-types-compat.workspace = true reth-node-api.workspace = true -reth-node-builder.workspace = true +reth-node-optimism = { workspace = true, optional = true } +reth-node-ethereum.workspace = true # rpc/net jsonrpsee = { workspace = true, features = ["server"] } @@ -53,7 +54,6 @@ reth-network-api.workspace = true reth-interfaces = { workspace = true, features = ["test-utils"] } reth-beacon-consensus.workspace = true reth-payload-builder = { workspace = true, features = ["test-utils"] } -reth-node-builder.workspace = true tokio = { workspace = true, features = ["rt", "rt-multi-thread"] } serde_json.workspace = true diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 22c624c23..39ae87153 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -168,7 +168,7 @@ use jsonrpsee::{ Methods, RpcModule, }; use reth_node_api::{EngineTypes, EvmEnvConfig}; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use serde::{Deserialize, Serialize, Serializer}; use strum::{AsRefStr, EnumIter, EnumVariantNames, IntoStaticStr, ParseError, VariantNames}; use tower::layer::util::{Identity, Stack}; diff --git a/crates/rpc/rpc-builder/tests/it/auth.rs b/crates/rpc/rpc-builder/tests/it/auth.rs index e4aada9f0..51ba2f145 100644 --- a/crates/rpc/rpc-builder/tests/it/auth.rs +++ b/crates/rpc/rpc-builder/tests/it/auth.rs @@ -2,7 +2,7 @@ use crate::utils::launch_auth; use jsonrpsee::core::client::{ClientT, SubscriptionClientT}; -use reth_node_builder::EthEngineTypes; +use reth_node_ethereum::EthEngineTypes; use reth_primitives::{Block, U64}; use reth_rpc::JwtSecret; use reth_rpc_api::clients::EngineApiClient; diff --git a/crates/rpc/rpc-builder/tests/it/utils.rs b/crates/rpc/rpc-builder/tests/it/utils.rs index a16b8dbb1..69d18201c 100644 --- a/crates/rpc/rpc-builder/tests/it/utils.rs +++ b/crates/rpc/rpc-builder/tests/it/utils.rs @@ -1,6 +1,6 @@ use reth_beacon_consensus::BeaconConsensusEngineHandle; use reth_network_api::noop::NoopNetwork; -use reth_node_builder::{EthEngineTypes, EthEvmConfig}; +use reth_node_ethereum::{EthEngineTypes, EthEvmConfig}; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::MAINNET; use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions}; diff --git a/crates/rpc/rpc-engine-api/Cargo.toml b/crates/rpc/rpc-engine-api/Cargo.toml index 358737dcc..342600c32 100644 --- a/crates/rpc/rpc-engine-api/Cargo.toml +++ b/crates/rpc/rpc-engine-api/Cargo.toml @@ -41,7 +41,8 @@ serde.workspace = true [dev-dependencies] alloy-rlp.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism.workspace = true reth-interfaces = { workspace = true, features = ["test-utils"] } reth-provider = { workspace = true, features = ["test-utils"] } reth-payload-builder = { workspace = true, features = ["test-utils"] } diff --git a/crates/rpc/rpc-engine-api/src/engine_api.rs b/crates/rpc/rpc-engine-api/src/engine_api.rs index 4b0933a9c..d066344d9 100644 --- a/crates/rpc/rpc-engine-api/src/engine_api.rs +++ b/crates/rpc/rpc-engine-api/src/engine_api.rs @@ -687,7 +687,7 @@ mod tests { use assert_matches::assert_matches; use reth_beacon_consensus::BeaconEngineMessage; use reth_interfaces::test_utils::generators::random_block; - use reth_node_builder::EthEngineTypes; + use reth_node_ethereum::EthEngineTypes; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::{SealedBlock, B256, MAINNET}; use reth_provider::test_utils::MockEthProvider; diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index 532e0005d..3199e320e 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -83,7 +83,8 @@ jsonrpsee = { workspace = true, features = ["client"] } assert_matches.workspace = true tempfile.workspace = true reth-interfaces = { workspace = true, features = ["test-utils"] } -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism.workspace = true [features] optimism = [ diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index 6e97eaa57..38b7c2473 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -404,7 +404,7 @@ mod tests { use jsonrpsee::types::error::INVALID_PARAMS_CODE; use reth_interfaces::test_utils::{generators, generators::Rng}; use reth_network_api::noop::NoopNetwork; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{ basefee::calculate_next_block_base_fee, constants::ETHEREUM_BLOCK_GAS_LIMIT, BaseFeeParams, Block, BlockNumberOrTag, Header, TransactionSigned, B256, U256, diff --git a/crates/rpc/rpc/src/eth/api/state.rs b/crates/rpc/rpc/src/eth/api/state.rs index 9bd219b7b..de2f95f68 100644 --- a/crates/rpc/rpc/src/eth/api/state.rs +++ b/crates/rpc/rpc/src/eth/api/state.rs @@ -133,7 +133,7 @@ mod tests { }, BlockingTaskPool, }; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, StorageKey, StorageValue}; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider, NoopProvider}; use reth_transaction_pool::test_utils::testing_pool; diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index c93de8f21..ccab9dbd9 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -1295,7 +1295,7 @@ mod tests { BlockingTaskPool, EthApi, }; use reth_network_api::noop::NoopNetwork; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, hex_literal::hex, Bytes}; use reth_provider::test_utils::NoopProvider; use reth_transaction_pool::{test_utils::testing_pool, TransactionPool}; diff --git a/crates/stages/Cargo.toml b/crates/stages/Cargo.toml index 20a73e87c..3f58fdc83 100644 --- a/crates/stages/Cargo.toml +++ b/crates/stages/Cargo.toml @@ -62,7 +62,8 @@ reth-db = { workspace = true, features = ["test-utils", "mdbx"] } reth-interfaces = { workspace = true, features = ["test-utils"] } reth-downloaders.workspace = true reth-eth-wire.workspace = true # TODO(onbjerg): We only need this for [BlockBody] -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true +reth-node-optimism.workspace = true reth-blockchain-tree.workspace = true reth-revm.workspace = true reth-trie = { workspace = true, features = ["test-utils"] } diff --git a/crates/stages/src/lib.rs b/crates/stages/src/lib.rs index 23254e4ab..0ad60c621 100644 --- a/crates/stages/src/lib.rs +++ b/crates/stages/src/lib.rs @@ -22,7 +22,7 @@ //! # use reth_stages::Pipeline; //! # use reth_stages::sets::DefaultStages; //! # use tokio::sync::watch; -//! # use reth_node_builder::EthEvmConfig; +//! # use reth_node_ethereum::EthEvmConfig; //! # use reth_provider::ProviderFactory; //! # use reth_provider::HeaderSyncMode; //! # use reth_provider::test_utils::create_test_provider_factory; diff --git a/crates/stages/src/sets.rs b/crates/stages/src/sets.rs index d4b7a8c61..7879c20d8 100644 --- a/crates/stages/src/sets.rs +++ b/crates/stages/src/sets.rs @@ -14,7 +14,7 @@ //! # use reth_stages::sets::{OfflineStages}; //! # use reth_revm::EvmProcessorFactory; //! # use reth_primitives::MAINNET; -//! # use reth_node_builder::EthEvmConfig; +//! # use reth_node_ethereum::EthEvmConfig; //! # use reth_provider::test_utils::create_test_provider_factory; //! //! # let executor_factory = EvmProcessorFactory::new(MAINNET.clone(), EthEvmConfig::default()); @@ -27,7 +27,7 @@ //! # use reth_stages::Pipeline; //! # use reth_stages::{StageSet, sets::OfflineStages}; //! # use reth_revm::EvmProcessorFactory; -//! # use reth_node_builder::EthEvmConfig; +//! # use reth_node_ethereum::EthEvmConfig; //! # use reth_primitives::MAINNET; //! // Build a pipeline with all offline stages and a custom stage at the end. //! # let executor_factory = EvmProcessorFactory::new(MAINNET.clone(), EthEvmConfig::default()); diff --git a/crates/stages/src/stages/execution.rs b/crates/stages/src/stages/execution.rs index 84ecacb68..beefd98a6 100644 --- a/crates/stages/src/stages/execution.rs +++ b/crates/stages/src/stages/execution.rs @@ -502,7 +502,7 @@ mod tests { use assert_matches::assert_matches; use reth_db::{models::AccountBeforeTx, test_utils::create_test_rw_db}; use reth_interfaces::executor::BlockValidationError; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{ address, hex_literal::hex, keccak256, stage::StageUnitCheckpoint, Account, Bytecode, ChainSpecBuilder, PruneModes, SealedBlock, StorageEntry, B256, MAINNET, U256, diff --git a/crates/stages/src/stages/mod.rs b/crates/stages/src/stages/mod.rs index cf6f5480b..62ffbfc26 100644 --- a/crates/stages/src/stages/mod.rs +++ b/crates/stages/src/stages/mod.rs @@ -55,7 +55,7 @@ mod tests { AccountHistory, DatabaseEnv, }; use reth_interfaces::test_utils::generators::{self, random_block}; - use reth_node_builder::EthEvmConfig; + use reth_node_ethereum::EthEvmConfig; use reth_primitives::{ address, hex_literal::hex, keccak256, Account, Bytecode, ChainSpecBuilder, PruneMode, PruneModes, SealedBlock, U256, diff --git a/testing/ef-tests/Cargo.toml b/testing/ef-tests/Cargo.toml index c5eabaf17..35480d7e8 100644 --- a/testing/ef-tests/Cargo.toml +++ b/testing/ef-tests/Cargo.toml @@ -21,7 +21,7 @@ reth-provider.workspace = true reth-stages.workspace = true reth-interfaces.workspace = true reth-revm.workspace = true -reth-node-builder.workspace = true +reth-node-ethereum.workspace = true alloy-rlp.workspace = true tokio = "1.28.1" diff --git a/testing/ef-tests/src/cases/blockchain_test.rs b/testing/ef-tests/src/cases/blockchain_test.rs index dece7eb82..220b5b4dd 100644 --- a/testing/ef-tests/src/cases/blockchain_test.rs +++ b/testing/ef-tests/src/cases/blockchain_test.rs @@ -6,7 +6,7 @@ use crate::{ }; use alloy_rlp::Decodable; use reth_db::test_utils::create_test_rw_db; -use reth_node_builder::EthEvmConfig; +use reth_node_ethereum::EthEvmConfig; use reth_primitives::{BlockBody, SealedBlock}; use reth_provider::{BlockWriter, HashingWriter, ProviderFactory}; use reth_stages::{stages::ExecutionStage, ExecInput, Stage};