From bf92a5fb59861ccadc664c4b18f228a787f0e606 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sat, 16 Nov 2024 18:36:57 +0100 Subject: [PATCH] feat: split reth-payload-primitives (#12600) --- .github/assets/check_wasm.sh | 1 + Cargo.lock | 37 ++++-- Cargo.toml | 2 + crates/consensus/beacon/Cargo.toml | 1 + crates/consensus/beacon/src/engine/mod.rs | 3 +- crates/e2e-test-utils/Cargo.toml | 1 + crates/e2e-test-utils/src/payload.rs | 5 +- crates/engine/local/Cargo.toml | 1 + crates/engine/local/src/miner.rs | 5 +- crates/engine/primitives/Cargo.toml | 1 + crates/engine/primitives/src/message.rs | 2 +- crates/engine/tree/Cargo.toml | 1 + crates/engine/tree/src/tree/mod.rs | 3 +- crates/ethereum/payload/Cargo.toml | 1 + crates/ethereum/payload/src/lib.rs | 3 +- crates/node/api/Cargo.toml | 1 + crates/node/api/src/lib.rs | 4 + crates/node/api/src/node.rs | 2 +- crates/node/builder/Cargo.toml | 1 - crates/node/builder/src/launch/engine.rs | 4 +- crates/node/builder/src/rpc.rs | 2 +- crates/optimism/payload/Cargo.toml | 1 + crates/optimism/payload/src/builder.rs | 3 +- crates/payload/basic/Cargo.toml | 1 + crates/payload/basic/src/lib.rs | 5 +- crates/payload/builder-primitives/Cargo.toml | 33 ++++++ .../payload/builder-primitives/src/error.rs | 58 +++++++++ .../src/events.rs | 2 +- crates/payload/builder-primitives/src/lib.rs | 19 +++ .../payload/builder-primitives/src/traits.rs | 111 ++++++++++++++++++ crates/payload/builder/Cargo.toml | 1 + crates/payload/builder/src/lib.rs | 3 +- crates/payload/builder/src/service.rs | 6 +- crates/payload/builder/src/test_utils.rs | 3 +- crates/payload/builder/src/traits.rs | 5 +- crates/payload/primitives/Cargo.toml | 11 -- crates/payload/primitives/src/error.rs | 57 --------- crates/payload/primitives/src/lib.rs | 9 +- crates/payload/primitives/src/traits.rs | 109 ----------------- crates/rpc/rpc-engine-api/Cargo.toml | 1 + crates/rpc/rpc-engine-api/src/error.rs | 3 +- examples/custom-engine-types/Cargo.toml | 1 - 42 files changed, 301 insertions(+), 222 deletions(-) create mode 100644 crates/payload/builder-primitives/Cargo.toml create mode 100644 crates/payload/builder-primitives/src/error.rs rename crates/payload/{primitives => builder-primitives}/src/events.rs (98%) create mode 100644 crates/payload/builder-primitives/src/lib.rs create mode 100644 crates/payload/builder-primitives/src/traits.rs diff --git a/.github/assets/check_wasm.sh b/.github/assets/check_wasm.sh index c34f82d2e315..0d9c9b34a036 100755 --- a/.github/assets/check_wasm.sh +++ b/.github/assets/check_wasm.sh @@ -52,6 +52,7 @@ exclude_crates=( reth-optimism-payload-builder reth-optimism-rpc reth-payload-builder + reth-payload-builder-primitives reth-payload-primitives reth-rpc reth-rpc-api diff --git a/Cargo.lock b/Cargo.lock index 2b6ea4f34315..fefa6fb5c1d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2867,7 +2867,6 @@ dependencies = [ "reth-node-core", "reth-node-ethereum", "reth-payload-builder", - "reth-primitives", "reth-tracing", "reth-trie-db", "serde", @@ -6436,6 +6435,7 @@ dependencies = [ "reth-evm", "reth-metrics", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-primitives", "reth-primitives-traits", @@ -6480,6 +6480,7 @@ dependencies = [ "reth-network-p2p", "reth-node-types", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-payload-validator", "reth-primitives", @@ -7103,6 +7104,7 @@ dependencies = [ "reth-network-peers", "reth-node-builder", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-provider", "reth-rpc-layer", @@ -7164,6 +7166,7 @@ dependencies = [ "reth-ethereum-engine-primitives", "reth-evm", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-payload-validator", "reth-provider", @@ -7185,6 +7188,7 @@ dependencies = [ "futures", "reth-errors", "reth-execution-types", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-primitives", "reth-trie", @@ -7250,6 +7254,7 @@ dependencies = [ "reth-metrics", "reth-network-p2p", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-payload-validator", "reth-primitives", @@ -7456,6 +7461,7 @@ dependencies = [ "reth-evm-ethereum", "reth-execution-types", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-primitives", "reth-provider", @@ -7936,6 +7942,7 @@ dependencies = [ "reth-network-api", "reth-node-core", "reth-node-types", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-provider", "reth-tasks", @@ -7983,7 +7990,6 @@ dependencies = [ "reth-node-events", "reth-node-metrics", "reth-payload-builder", - "reth-payload-primitives", "reth-payload-validator", "reth-primitives", "reth-provider", @@ -8360,6 +8366,7 @@ dependencies = [ "reth-optimism-evm", "reth-optimism-forks", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-payload-util", "reth-primitives", @@ -8459,6 +8466,7 @@ dependencies = [ "reth-chain-state", "reth-ethereum-engine-primitives", "reth-metrics", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-primitives", "revm", @@ -8468,28 +8476,38 @@ dependencies = [ ] [[package]] -name = "reth-payload-primitives" +name = "reth-payload-builder-primitives" version = "1.1.1" dependencies = [ - "alloy-eips", "alloy-primitives", "alloy-rpc-types-engine", "async-trait", - "op-alloy-rpc-types-engine", "pin-project", - "reth-chain-state", - "reth-chainspec", "reth-errors", - "reth-primitives", + "reth-payload-primitives", "reth-transaction-pool", "revm-primitives", - "serde", "thiserror 1.0.69", "tokio", "tokio-stream", "tracing", ] +[[package]] +name = "reth-payload-primitives" +version = "1.1.1" +dependencies = [ + "alloy-eips", + "alloy-primitives", + "alloy-rpc-types-engine", + "op-alloy-rpc-types-engine", + "reth-chain-state", + "reth-chainspec", + "reth-primitives", + "serde", + "thiserror 1.0.69", +] + [[package]] name = "reth-payload-util" version = "1.1.1" @@ -8887,6 +8905,7 @@ dependencies = [ "reth-evm", "reth-metrics", "reth-payload-builder", + "reth-payload-builder-primitives", "reth-payload-primitives", "reth-primitives", "reth-provider", diff --git a/Cargo.toml b/Cargo.toml index 398be3e5faf7..2f2f9aa884ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,6 +80,7 @@ members = [ "crates/optimism/storage", "crates/payload/basic/", "crates/payload/builder/", + "crates/payload/builder-primitives/", "crates/payload/primitives/", "crates/payload/validator/", "crates/payload/util/", @@ -380,6 +381,7 @@ reth-optimism-primitives = { path = "crates/optimism/primitives" } reth-optimism-rpc = { path = "crates/optimism/rpc" } reth-optimism-storage = { path = "crates/optimism/storage" } reth-payload-builder = { path = "crates/payload/builder" } +reth-payload-builder-primitives = { path = "crates/payload/builder-primitives" } reth-payload-primitives = { path = "crates/payload/primitives" } reth-payload-validator = { path = "crates/payload/validator" } reth-payload-util = { path = "crates/payload/util" } diff --git a/crates/consensus/beacon/Cargo.toml b/crates/consensus/beacon/Cargo.toml index d926fc09c356..245ebe8541e0 100644 --- a/crates/consensus/beacon/Cargo.toml +++ b/crates/consensus/beacon/Cargo.toml @@ -20,6 +20,7 @@ reth-errors.workspace = true reth-provider.workspace = true reth-tasks.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-payload-validator.workspace = true reth-prune.workspace = true diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index bc6bd3bc4f43..0b93ae0f29ae 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -23,7 +23,8 @@ use reth_network_p2p::{ }; use reth_node_types::NodeTypesWithEngine; use reth_payload_builder::PayloadBuilderHandle; -use reth_payload_primitives::{PayloadAttributes, PayloadBuilder, PayloadBuilderAttributes}; +use reth_payload_builder_primitives::PayloadBuilder; +use reth_payload_primitives::{PayloadAttributes, PayloadBuilderAttributes}; use reth_payload_validator::ExecutionPayloadValidator; use reth_primitives::{Head, SealedBlock, SealedHeader}; use reth_provider::{ diff --git a/crates/e2e-test-utils/Cargo.toml b/crates/e2e-test-utils/Cargo.toml index e56449551bbc..c4c74ebcdf12 100644 --- a/crates/e2e-test-utils/Cargo.toml +++ b/crates/e2e-test-utils/Cargo.toml @@ -17,6 +17,7 @@ reth-tracing.workspace = true reth-db = { workspace = true, features = ["test-utils"] } reth-rpc-layer.workspace = true reth-payload-builder = { workspace = true, features = ["test-utils"] } +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-provider.workspace = true reth-node-builder = { workspace = true, features = ["test-utils"] } diff --git a/crates/e2e-test-utils/src/payload.rs b/crates/e2e-test-utils/src/payload.rs index 29aa11895b7d..7828f61c2afb 100644 --- a/crates/e2e-test-utils/src/payload.rs +++ b/crates/e2e-test-utils/src/payload.rs @@ -1,7 +1,8 @@ use futures_util::StreamExt; -use reth::api::{BuiltPayload, PayloadBuilderAttributes}; +use reth::api::BuiltPayload; use reth_payload_builder::{PayloadBuilderHandle, PayloadId}; -use reth_payload_primitives::{Events, PayloadBuilder, PayloadTypes}; +use reth_payload_builder_primitives::{Events, PayloadBuilder}; +use reth_payload_primitives::{PayloadBuilderAttributes, PayloadTypes}; use tokio_stream::wrappers::BroadcastStream; /// Helper for payload operations diff --git a/crates/engine/local/Cargo.toml b/crates/engine/local/Cargo.toml index 2ab448e3bbfc..a1b74d13fee7 100644 --- a/crates/engine/local/Cargo.toml +++ b/crates/engine/local/Cargo.toml @@ -19,6 +19,7 @@ reth-engine-tree.workspace = true reth-evm.workspace = true reth-ethereum-engine-primitives.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-payload-validator.workspace = true reth-provider.workspace = true diff --git a/crates/engine/local/src/miner.rs b/crates/engine/local/src/miner.rs index 2085aa81f9ba..3a0f5a2f1925 100644 --- a/crates/engine/local/src/miner.rs +++ b/crates/engine/local/src/miner.rs @@ -7,9 +7,8 @@ use futures_util::{stream::Fuse, StreamExt}; use reth_chainspec::EthereumHardforks; use reth_engine_primitives::{BeaconEngineMessage, EngineApiMessageVersion, EngineTypes}; use reth_payload_builder::PayloadBuilderHandle; -use reth_payload_primitives::{ - BuiltPayload, PayloadAttributesBuilder, PayloadBuilder, PayloadKind, PayloadTypes, -}; +use reth_payload_builder_primitives::PayloadBuilder; +use reth_payload_primitives::{BuiltPayload, PayloadAttributesBuilder, PayloadKind, PayloadTypes}; use reth_provider::{BlockReader, ChainSpecProvider}; use reth_rpc_types_compat::engine::payload::block_to_payload; use reth_transaction_pool::TransactionPool; diff --git a/crates/engine/primitives/Cargo.toml b/crates/engine/primitives/Cargo.toml index de4786553d3c..42cbd932d45b 100644 --- a/crates/engine/primitives/Cargo.toml +++ b/crates/engine/primitives/Cargo.toml @@ -14,6 +14,7 @@ workspace = true # reth reth-execution-types.workspace = true reth-payload-primitives.workspace = true +reth-payload-builder-primitives.workspace = true reth-primitives.workspace = true reth-trie.workspace = true reth-errors.workspace = true diff --git a/crates/engine/primitives/src/message.rs b/crates/engine/primitives/src/message.rs index 11fd383a1e26..d8a4c1322ad0 100644 --- a/crates/engine/primitives/src/message.rs +++ b/crates/engine/primitives/src/message.rs @@ -5,7 +5,7 @@ use alloy_rpc_types_engine::{ }; use futures::{future::Either, FutureExt}; use reth_errors::RethResult; -use reth_payload_primitives::PayloadBuilderError; +use reth_payload_builder_primitives::PayloadBuilderError; use std::{ fmt::Display, future::Future, diff --git a/crates/engine/tree/Cargo.toml b/crates/engine/tree/Cargo.toml index fb259d085601..278457145e70 100644 --- a/crates/engine/tree/Cargo.toml +++ b/crates/engine/tree/Cargo.toml @@ -23,6 +23,7 @@ reth-errors.workspace = true reth-evm.workspace = true reth-network-p2p.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-payload-validator.workspace = true reth-primitives.workspace = true diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 67e692b5c6c0..39843377684c 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -33,7 +33,8 @@ use reth_engine_primitives::{ use reth_errors::{ConsensusError, ProviderResult}; use reth_evm::execute::BlockExecutorProvider; use reth_payload_builder::PayloadBuilderHandle; -use reth_payload_primitives::{PayloadAttributes, PayloadBuilder, PayloadBuilderAttributes}; +use reth_payload_builder_primitives::PayloadBuilder; +use reth_payload_primitives::{PayloadAttributes, PayloadBuilderAttributes}; use reth_payload_validator::ExecutionPayloadValidator; use reth_primitives::{Block, GotExpected, SealedBlock, SealedBlockWithSenders, SealedHeader}; use reth_provider::{ diff --git a/crates/ethereum/payload/Cargo.toml b/crates/ethereum/payload/Cargo.toml index a29cc4733623..4e0880d1d153 100644 --- a/crates/ethereum/payload/Cargo.toml +++ b/crates/ethereum/payload/Cargo.toml @@ -18,6 +18,7 @@ reth-revm.workspace = true reth-transaction-pool.workspace = true reth-provider.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-execution-types.workspace = true reth-basic-payload-builder.workspace = true diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 7d795c510e21..2b55ea87dd0a 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -23,7 +23,8 @@ use reth_evm::{system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes} use reth_evm_ethereum::{eip6110::parse_deposits_from_receipts, EthEvmConfig}; use reth_execution_types::ExecutionOutcome; use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes}; -use reth_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError}; +use reth_payload_builder_primitives::PayloadBuilderError; +use reth_payload_primitives::PayloadBuilderAttributes; use reth_primitives::{ proofs::{self}, Block, BlockBody, EthereumHardforks, Receipt, diff --git a/crates/node/api/Cargo.toml b/crates/node/api/Cargo.toml index a4cc0eb7eb64..ab4595d33624 100644 --- a/crates/node/api/Cargo.toml +++ b/crates/node/api/Cargo.toml @@ -18,6 +18,7 @@ reth-evm.workspace = true reth-provider.workspace = true reth-engine-primitives.workspace = true reth-transaction-pool.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-tasks.workspace = true reth-network-api.workspace = true diff --git a/crates/node/api/src/lib.rs b/crates/node/api/src/lib.rs index 099cf82b5fe0..105cac47d942 100644 --- a/crates/node/api/src/lib.rs +++ b/crates/node/api/src/lib.rs @@ -16,6 +16,10 @@ pub use reth_engine_primitives::*; pub use reth_payload_primitives as payload; pub use reth_payload_primitives::*; +/// Traits and helper types used to abstract over payload builder types. +pub use reth_payload_builder_primitives as payload_builder; +pub use reth_payload_builder_primitives::*; + /// Traits and helper types used to abstract over EVM methods and types. pub use reth_evm::{ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes}; diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index 90b9e2999bf0..5d25d8d592c7 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -9,7 +9,7 @@ use reth_evm::execute::BlockExecutorProvider; use reth_network_api::FullNetwork; use reth_node_core::node_config::NodeConfig; use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine}; -use reth_payload_primitives::PayloadBuilder; +use reth_payload_builder_primitives::PayloadBuilder; use reth_provider::FullProvider; use reth_tasks::TaskExecutor; use reth_transaction_pool::TransactionPool; diff --git a/crates/node/builder/Cargo.toml b/crates/node/builder/Cargo.toml index b0b62d1b2ed5..781112d93c8a 100644 --- a/crates/node/builder/Cargo.toml +++ b/crates/node/builder/Cargo.toml @@ -41,7 +41,6 @@ reth-node-core.workspace = true reth-node-events.workspace = true reth-node-metrics.workspace = true reth-payload-builder.workspace = true -reth-payload-primitives.workspace = true reth-payload-validator.workspace = true reth-primitives.workspace = true reth-provider.workspace = true diff --git a/crates/node/builder/src/launch/engine.rs b/crates/node/builder/src/launch/engine.rs index 65433176ba99..86ab0b9a3d74 100644 --- a/crates/node/builder/src/launch/engine.rs +++ b/crates/node/builder/src/launch/engine.rs @@ -19,7 +19,8 @@ use reth_exex::ExExManagerHandle; use reth_network::{NetworkSyncUpdater, SyncState}; use reth_network_api::{BlockDownloaderProvider, NetworkEventListenerProvider}; use reth_node_api::{ - BuiltPayload, FullNodeTypes, NodeTypesWithEngine, PayloadAttributesBuilder, PayloadTypes, + BuiltPayload, FullNodeTypes, NodeTypesWithEngine, PayloadAttributesBuilder, PayloadBuilder, + PayloadTypes, }; use reth_node_core::{ dirs::{ChainPath, DataDirPath}, @@ -27,7 +28,6 @@ use reth_node_core::{ primitives::Head, }; use reth_node_events::{cl::ConsensusLayerHealthEvents, node}; -use reth_payload_primitives::PayloadBuilder; use reth_primitives::EthereumHardforks; use reth_provider::providers::{BlockchainProvider2, ProviderNodeTypes}; use reth_tasks::TaskExecutor; diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index 9680c221d7ce..adee942748c1 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -11,13 +11,13 @@ use alloy_rpc_types::engine::ClientVersionV1; use futures::TryFutureExt; use reth_node_api::{ AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine, + PayloadBuilder, }; use reth_node_core::{ node_config::NodeConfig, version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA}, }; use reth_payload_builder::PayloadStore; -use reth_payload_primitives::PayloadBuilder; use reth_provider::providers::ProviderNodeTypes; use reth_rpc::{ eth::{EthApiTypes, FullEthApiServer}, diff --git a/crates/optimism/payload/Cargo.toml b/crates/optimism/payload/Cargo.toml index 19a47be4951a..7f47da7e2360 100644 --- a/crates/optimism/payload/Cargo.toml +++ b/crates/optimism/payload/Cargo.toml @@ -22,6 +22,7 @@ reth-rpc-types-compat.workspace = true reth-evm.workspace = true reth-execution-types.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-util.workspace = true reth-payload-primitives = { workspace = true, features = ["op"] } reth-basic-payload-builder.workspace = true diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 7047c587b0cb..3644d8f71a54 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -15,7 +15,8 @@ use reth_execution_types::ExecutionOutcome; use reth_optimism_chainspec::OpChainSpec; use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism; use reth_optimism_forks::OpHardforks; -use reth_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError}; +use reth_payload_builder_primitives::PayloadBuilderError; +use reth_payload_primitives::PayloadBuilderAttributes; use reth_payload_util::PayloadTransactions; use reth_primitives::{proofs, Block, BlockBody, Receipt, SealedHeader, TransactionSigned, TxType}; use reth_provider::{ProviderError, StateProofProvider, StateProviderFactory, StateRootProvider}; diff --git a/crates/payload/basic/Cargo.toml b/crates/payload/basic/Cargo.toml index 5e9e524f79b1..0315f73cae4e 100644 --- a/crates/payload/basic/Cargo.toml +++ b/crates/payload/basic/Cargo.toml @@ -19,6 +19,7 @@ reth-primitives-traits.workspace = true reth-transaction-pool.workspace = true reth-provider.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-tasks.workspace = true reth-evm.workspace = true diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index a905f8544481..e3193ec6deb1 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -17,9 +17,8 @@ use futures_util::FutureExt; use reth_chainspec::EthereumHardforks; use reth_evm::state_change::post_block_withdrawals_balance_increments; use reth_payload_builder::{KeepPayloadJobAlive, PayloadId, PayloadJob, PayloadJobGenerator}; -use reth_payload_primitives::{ - BuiltPayload, PayloadBuilderAttributes, PayloadBuilderError, PayloadKind, -}; +use reth_payload_builder_primitives::PayloadBuilderError; +use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadKind}; use reth_primitives::{proofs, SealedHeader}; use reth_primitives_traits::constants::RETH_CLIENT_VERSION; use reth_provider::{BlockReaderIdExt, CanonStateNotification, StateProviderFactory}; diff --git a/crates/payload/builder-primitives/Cargo.toml b/crates/payload/builder-primitives/Cargo.toml new file mode 100644 index 000000000000..c3665dbc58ec --- /dev/null +++ b/crates/payload/builder-primitives/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "reth-payload-builder-primitives" +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-errors.workspace = true +reth-payload-primitives.workspace = true +reth-transaction-pool.workspace = true +revm-primitives.workspace = true + +# alloy +alloy-primitives.workspace = true +alloy-rpc-types-engine = { workspace = true, features = ["serde"] } + +# async +async-trait.workspace = true +pin-project.workspace = true +tokio = { workspace = true, features = ["sync"] } +tokio-stream.workspace = true + +# misc +thiserror.workspace = true +tracing.workspace = true diff --git a/crates/payload/builder-primitives/src/error.rs b/crates/payload/builder-primitives/src/error.rs new file mode 100644 index 000000000000..0d988c829e48 --- /dev/null +++ b/crates/payload/builder-primitives/src/error.rs @@ -0,0 +1,58 @@ +//! Error types emitted by types or implementations of this crate. + +use alloy_primitives::B256; +use reth_errors::{ProviderError, RethError}; +use reth_transaction_pool::BlobStoreError; +use revm_primitives::EVMError; +use tokio::sync::oneshot; + +/// Possible error variants during payload building. +#[derive(Debug, thiserror::Error)] +pub enum PayloadBuilderError { + /// Thrown when the parent header cannot be found + #[error("missing parent header: {0}")] + MissingParentHeader(B256), + /// Thrown when the parent block is missing. + #[error("missing parent block {0}")] + MissingParentBlock(B256), + /// An oneshot channels has been closed. + #[error("sender has been dropped")] + ChannelClosed, + /// If there's no payload to resolve. + #[error("missing payload")] + MissingPayload, + /// Error occurring in the blob store. + #[error(transparent)] + BlobStore(#[from] BlobStoreError), + /// Other internal error + #[error(transparent)] + Internal(#[from] RethError), + /// Unrecoverable error during evm execution. + #[error("evm execution error: {0}")] + EvmExecutionError(EVMError), + /// Any other payload building errors. + #[error(transparent)] + Other(Box), +} + +impl PayloadBuilderError { + /// Create a new error from a boxed error. + pub fn other(error: E) -> Self + where + E: core::error::Error + Send + Sync + 'static, + { + Self::Other(Box::new(error)) + } +} + +impl From for PayloadBuilderError { + fn from(error: ProviderError) -> Self { + Self::Internal(RethError::Provider(error)) + } +} + +impl From for PayloadBuilderError { + fn from(_: oneshot::error::RecvError) -> Self { + Self::ChannelClosed + } +} diff --git a/crates/payload/primitives/src/events.rs b/crates/payload/builder-primitives/src/events.rs similarity index 98% rename from crates/payload/primitives/src/events.rs rename to crates/payload/builder-primitives/src/events.rs index 3fb3813adb1e..d51f13f7c4cb 100644 --- a/crates/payload/primitives/src/events.rs +++ b/crates/payload/builder-primitives/src/events.rs @@ -1,4 +1,4 @@ -use crate::PayloadTypes; +use reth_payload_primitives::PayloadTypes; use std::{ pin::Pin, task::{ready, Context, Poll}, diff --git a/crates/payload/builder-primitives/src/lib.rs b/crates/payload/builder-primitives/src/lib.rs new file mode 100644 index 000000000000..003a385c6c02 --- /dev/null +++ b/crates/payload/builder-primitives/src/lib.rs @@ -0,0 +1,19 @@ +//! This crate defines abstractions to create and update payloads (blocks) + +#![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(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +mod error; +pub use error::PayloadBuilderError; + +mod events; +pub use crate::events::{Events, PayloadEvents}; + +/// Contains the payload builder trait to abstract over payload attributes. +mod traits; +pub use traits::{PayloadBuilder, PayloadStoreExt}; diff --git a/crates/payload/builder-primitives/src/traits.rs b/crates/payload/builder-primitives/src/traits.rs new file mode 100644 index 000000000000..b5e8910b6c26 --- /dev/null +++ b/crates/payload/builder-primitives/src/traits.rs @@ -0,0 +1,111 @@ +use crate::{PayloadBuilderError, PayloadEvents}; +use alloy_rpc_types_engine::PayloadId; +use reth_payload_primitives::{PayloadKind, PayloadTypes}; +use std::fmt::Debug; +use tokio::sync::oneshot; + +/// A helper trait for internal usage to retrieve and resolve payloads. +#[async_trait::async_trait] +pub trait PayloadStoreExt: Debug + Send + Sync + Unpin { + /// Resolves the payload job and returns the best payload that has been built so far. + async fn resolve_kind( + &self, + id: PayloadId, + kind: PayloadKind, + ) -> Option>; + + /// Resolves the payload job as fast and possible and returns the best payload that has been + /// built so far. + async fn resolve(&self, id: PayloadId) -> Option> { + self.resolve_kind(id, PayloadKind::Earliest).await + } + + /// Returns the best payload for the given identifier. + async fn best_payload( + &self, + id: PayloadId, + ) -> Option>; + + /// Returns the payload attributes associated with the given identifier. + async fn payload_attributes( + &self, + id: PayloadId, + ) -> Option>; +} + +#[async_trait::async_trait] +impl PayloadStoreExt for P +where + P: PayloadBuilder, +{ + async fn resolve_kind( + &self, + id: PayloadId, + kind: PayloadKind, + ) -> Option> { + Some(PayloadBuilder::resolve_kind(self, id, kind).await?.map_err(Into::into)) + } + + async fn best_payload( + &self, + id: PayloadId, + ) -> Option> { + Some(PayloadBuilder::best_payload(self, id).await?.map_err(Into::into)) + } + + async fn payload_attributes( + &self, + id: PayloadId, + ) -> Option> { + Some(PayloadBuilder::payload_attributes(self, id).await?.map_err(Into::into)) + } +} + +/// A type that can request, subscribe to and resolve payloads. +#[async_trait::async_trait] +pub trait PayloadBuilder: Debug + Send + Sync + Unpin { + /// The Payload type for the builder. + type PayloadType: PayloadTypes; + /// The error type returned by the builder. + type Error: Into; + + /// Sends a message to the service to start building a new payload for the given payload. + /// + /// Returns a receiver that will receive the payload id. + fn send_new_payload( + &self, + attr: ::PayloadBuilderAttributes, + ) -> oneshot::Receiver>; + + /// Returns the best payload for the given identifier. + async fn best_payload( + &self, + id: PayloadId, + ) -> Option::BuiltPayload, Self::Error>>; + + /// Resolves the payload job and returns the best payload that has been built so far. + async fn resolve_kind( + &self, + id: PayloadId, + kind: PayloadKind, + ) -> Option::BuiltPayload, Self::Error>>; + + /// Resolves the payload job as fast and possible and returns the best payload that has been + /// built so far. + async fn resolve( + &self, + id: PayloadId, + ) -> Option::BuiltPayload, Self::Error>> { + self.resolve_kind(id, PayloadKind::Earliest).await + } + + /// Sends a message to the service to subscribe to payload events. + /// Returns a receiver that will receive them. + async fn subscribe(&self) -> Result, Self::Error>; + + /// Returns the payload attributes associated with the given identifier. + async fn payload_attributes( + &self, + id: PayloadId, + ) -> Option::PayloadBuilderAttributes, Self::Error>>; +} diff --git a/crates/payload/builder/Cargo.toml b/crates/payload/builder/Cargo.toml index 8b2fef7b8782..78814da50664 100644 --- a/crates/payload/builder/Cargo.toml +++ b/crates/payload/builder/Cargo.toml @@ -15,6 +15,7 @@ workspace = true # reth reth-primitives = { workspace = true, optional = true } reth-chain-state.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-ethereum-engine-primitives.workspace = true diff --git a/crates/payload/builder/src/lib.rs b/crates/payload/builder/src/lib.rs index da44072c99d2..0887a5ca74ac 100644 --- a/crates/payload/builder/src/lib.rs +++ b/crates/payload/builder/src/lib.rs @@ -113,7 +113,8 @@ pub mod noop; pub mod test_utils; pub use alloy_rpc_types::engine::PayloadId; -pub use reth_payload_primitives::{PayloadBuilderError, PayloadKind}; +pub use reth_payload_builder_primitives::PayloadBuilderError; +pub use reth_payload_primitives::PayloadKind; pub use service::{ PayloadBuilderHandle, PayloadBuilderService, PayloadServiceCommand, PayloadStore, }; diff --git a/crates/payload/builder/src/service.rs b/crates/payload/builder/src/service.rs index 267a1e355b0e..af11ba75ce6a 100644 --- a/crates/payload/builder/src/service.rs +++ b/crates/payload/builder/src/service.rs @@ -10,10 +10,10 @@ use crate::{ use alloy_rpc_types::engine::PayloadId; use futures_util::{future::FutureExt, Stream, StreamExt}; use reth_chain_state::CanonStateNotification; -use reth_payload_primitives::{ - BuiltPayload, Events, PayloadBuilder, PayloadBuilderAttributes, PayloadBuilderError, - PayloadEvents, PayloadKind, PayloadStoreExt, PayloadTypes, +use reth_payload_builder_primitives::{ + Events, PayloadBuilder, PayloadBuilderError, PayloadEvents, PayloadStoreExt, }; +use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadKind, PayloadTypes}; use std::{ fmt, future::Future, diff --git a/crates/payload/builder/src/test_utils.rs b/crates/payload/builder/src/test_utils.rs index 780df5c84636..5025a12ed718 100644 --- a/crates/payload/builder/src/test_utils.rs +++ b/crates/payload/builder/src/test_utils.rs @@ -7,7 +7,8 @@ use crate::{ use alloy_primitives::U256; use reth_chain_state::{CanonStateNotification, ExecutedBlock}; -use reth_payload_primitives::{PayloadBuilderError, PayloadKind, PayloadTypes}; +use reth_payload_builder_primitives::PayloadBuilderError; +use reth_payload_primitives::{PayloadKind, PayloadTypes}; use reth_primitives::Block; use std::{ future::Future, diff --git a/crates/payload/builder/src/traits.rs b/crates/payload/builder/src/traits.rs index ba8486b69079..d9d54ccd0e45 100644 --- a/crates/payload/builder/src/traits.rs +++ b/crates/payload/builder/src/traits.rs @@ -1,9 +1,8 @@ //! Trait abstractions used by the payload crate. use reth_chain_state::CanonStateNotification; -use reth_payload_primitives::{ - BuiltPayload, PayloadBuilderAttributes, PayloadBuilderError, PayloadKind, -}; +use reth_payload_builder_primitives::PayloadBuilderError; +use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadKind}; use std::future::Future; /// A type that can build a payload. diff --git a/crates/payload/primitives/Cargo.toml b/crates/payload/primitives/Cargo.toml index b1a115f12c8a..332964de96bf 100644 --- a/crates/payload/primitives/Cargo.toml +++ b/crates/payload/primitives/Cargo.toml @@ -14,9 +14,7 @@ workspace = true [dependencies] # reth reth-chainspec.workspace = true -reth-errors.workspace = true reth-primitives.workspace = true -reth-transaction-pool.workspace = true reth-chain-state.workspace = true # alloy @@ -25,18 +23,9 @@ alloy-primitives.workspace = true alloy-rpc-types-engine = { workspace = true, features = ["serde"] } op-alloy-rpc-types-engine = { workspace = true, optional = true } -revm-primitives.workspace = true - -# async -async-trait.workspace = true -tokio = { workspace = true, features = ["sync"] } -tokio-stream.workspace = true -pin-project.workspace = true - # misc serde.workspace = true thiserror.workspace = true -tracing.workspace = true [features] op = ["dep:op-alloy-rpc-types-engine"] \ No newline at end of file diff --git a/crates/payload/primitives/src/error.rs b/crates/payload/primitives/src/error.rs index 82891919feb9..67b6dbe4b931 100644 --- a/crates/payload/primitives/src/error.rs +++ b/crates/payload/primitives/src/error.rs @@ -1,62 +1,5 @@ //! Error types emitted by types or implementations of this crate. -use alloy_primitives::B256; -use reth_errors::{ProviderError, RethError}; -use reth_transaction_pool::BlobStoreError; -use revm_primitives::EVMError; -use tokio::sync::oneshot; - -/// Possible error variants during payload building. -#[derive(Debug, thiserror::Error)] -pub enum PayloadBuilderError { - /// Thrown when the parent header cannot be found - #[error("missing parent header: {0}")] - MissingParentHeader(B256), - /// Thrown when the parent block is missing. - #[error("missing parent block {0}")] - MissingParentBlock(B256), - /// An oneshot channels has been closed. - #[error("sender has been dropped")] - ChannelClosed, - /// If there's no payload to resolve. - #[error("missing payload")] - MissingPayload, - /// Error occurring in the blob store. - #[error(transparent)] - BlobStore(#[from] BlobStoreError), - /// Other internal error - #[error(transparent)] - Internal(#[from] RethError), - /// Unrecoverable error during evm execution. - #[error("evm execution error: {0}")] - EvmExecutionError(EVMError), - /// Any other payload building errors. - #[error(transparent)] - Other(Box), -} - -impl PayloadBuilderError { - /// Create a new error from a boxed error. - pub fn other(error: E) -> Self - where - E: core::error::Error + Send + Sync + 'static, - { - Self::Other(Box::new(error)) - } -} - -impl From for PayloadBuilderError { - fn from(error: ProviderError) -> Self { - Self::Internal(RethError::Provider(error)) - } -} - -impl From for PayloadBuilderError { - fn from(_: oneshot::error::RecvError) -> Self { - Self::ChannelClosed - } -} - /// Thrown when the payload or attributes are known to be invalid before processing. /// /// This is used mainly for diff --git a/crates/payload/primitives/src/lib.rs b/crates/payload/primitives/src/lib.rs index 3604ff5d8d81..a2bdb58bc516 100644 --- a/crates/payload/primitives/src/lib.rs +++ b/crates/payload/primitives/src/lib.rs @@ -9,18 +9,13 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] mod error; - -pub use error::{EngineObjectValidationError, PayloadBuilderError, VersionSpecificValidationError}; - -mod events; -pub use crate::events::{Events, PayloadEvents}; +pub use error::{EngineObjectValidationError, VersionSpecificValidationError}; /// Contains traits to abstract over payload attributes types and default implementations of the /// [`PayloadAttributes`] trait for ethereum mainnet and optimism types. mod traits; pub use traits::{ - BuiltPayload, PayloadAttributes, PayloadAttributesBuilder, PayloadBuilder, - PayloadBuilderAttributes, PayloadStoreExt, + BuiltPayload, PayloadAttributes, PayloadAttributesBuilder, PayloadBuilderAttributes, }; mod payload; diff --git a/crates/payload/primitives/src/traits.rs b/crates/payload/primitives/src/traits.rs index 197a7fe3af99..8d5c429e6c64 100644 --- a/crates/payload/primitives/src/traits.rs +++ b/crates/payload/primitives/src/traits.rs @@ -1,4 +1,3 @@ -use crate::{PayloadBuilderError, PayloadEvents, PayloadKind, PayloadTypes}; use alloy_eips::{ eip4895::{Withdrawal, Withdrawals}, eip7685::Requests, @@ -7,114 +6,6 @@ use alloy_primitives::{Address, B256, U256}; use alloy_rpc_types_engine::{PayloadAttributes as EthPayloadAttributes, PayloadId}; use reth_chain_state::ExecutedBlock; use reth_primitives::SealedBlock; -use std::fmt::Debug; -use tokio::sync::oneshot; - -/// A type that can request, subscribe to and resolve payloads. -#[async_trait::async_trait] -pub trait PayloadBuilder: Debug + Send + Sync + Unpin { - /// The Payload type for the builder. - type PayloadType: PayloadTypes; - /// The error type returned by the builder. - type Error: Into; - - /// Sends a message to the service to start building a new payload for the given payload. - /// - /// Returns a receiver that will receive the payload id. - fn send_new_payload( - &self, - attr: ::PayloadBuilderAttributes, - ) -> oneshot::Receiver>; - - /// Returns the best payload for the given identifier. - async fn best_payload( - &self, - id: PayloadId, - ) -> Option::BuiltPayload, Self::Error>>; - - /// Resolves the payload job and returns the best payload that has been built so far. - async fn resolve_kind( - &self, - id: PayloadId, - kind: PayloadKind, - ) -> Option::BuiltPayload, Self::Error>>; - - /// Resolves the payload job as fast and possible and returns the best payload that has been - /// built so far. - async fn resolve( - &self, - id: PayloadId, - ) -> Option::BuiltPayload, Self::Error>> { - self.resolve_kind(id, PayloadKind::Earliest).await - } - - /// Sends a message to the service to subscribe to payload events. - /// Returns a receiver that will receive them. - async fn subscribe(&self) -> Result, Self::Error>; - - /// Returns the payload attributes associated with the given identifier. - async fn payload_attributes( - &self, - id: PayloadId, - ) -> Option::PayloadBuilderAttributes, Self::Error>>; -} - -/// A helper trait for internal usage to retrieve and resolve payloads. -#[async_trait::async_trait] -pub trait PayloadStoreExt: Debug + Send + Sync + Unpin { - /// Resolves the payload job and returns the best payload that has been built so far. - async fn resolve_kind( - &self, - id: PayloadId, - kind: PayloadKind, - ) -> Option>; - - /// Resolves the payload job as fast and possible and returns the best payload that has been - /// built so far. - async fn resolve(&self, id: PayloadId) -> Option> { - self.resolve_kind(id, PayloadKind::Earliest).await - } - - /// Returns the best payload for the given identifier. - async fn best_payload( - &self, - id: PayloadId, - ) -> Option>; - - /// Returns the payload attributes associated with the given identifier. - async fn payload_attributes( - &self, - id: PayloadId, - ) -> Option>; -} - -#[async_trait::async_trait] -impl PayloadStoreExt for P -where - P: PayloadBuilder, -{ - async fn resolve_kind( - &self, - id: PayloadId, - kind: PayloadKind, - ) -> Option> { - Some(PayloadBuilder::resolve_kind(self, id, kind).await?.map_err(Into::into)) - } - - async fn best_payload( - &self, - id: PayloadId, - ) -> Option> { - Some(PayloadBuilder::best_payload(self, id).await?.map_err(Into::into)) - } - - async fn payload_attributes( - &self, - id: PayloadId, - ) -> Option> { - Some(PayloadBuilder::payload_attributes(self, id).await?.map_err(Into::into)) - } -} /// Represents a built payload type that contains a built [`SealedBlock`] and can be converted into /// engine API execution payloads. diff --git a/crates/rpc/rpc-engine-api/Cargo.toml b/crates/rpc/rpc-engine-api/Cargo.toml index 62d1eea32254..4854ac44dc59 100644 --- a/crates/rpc/rpc-engine-api/Cargo.toml +++ b/crates/rpc/rpc-engine-api/Cargo.toml @@ -19,6 +19,7 @@ reth-rpc-api.workspace = true reth-storage-api.workspace = true reth-beacon-consensus.workspace = true reth-payload-builder.workspace = true +reth-payload-builder-primitives.workspace = true reth-payload-primitives.workspace = true reth-tasks.workspace = true reth-rpc-types-compat.workspace = true diff --git a/crates/rpc/rpc-engine-api/src/error.rs b/crates/rpc/rpc-engine-api/src/error.rs index 82665ca35fde..4210d415bfed 100644 --- a/crates/rpc/rpc-engine-api/src/error.rs +++ b/crates/rpc/rpc-engine-api/src/error.rs @@ -4,7 +4,8 @@ use jsonrpsee_types::error::{ }; use reth_beacon_consensus::BeaconForkChoiceUpdateError; use reth_engine_primitives::BeaconOnNewPayloadError; -use reth_payload_primitives::{EngineObjectValidationError, PayloadBuilderError}; +use reth_payload_builder_primitives::PayloadBuilderError; +use reth_payload_primitives::EngineObjectValidationError; use thiserror::Error; /// The Engine API result type diff --git a/examples/custom-engine-types/Cargo.toml b/examples/custom-engine-types/Cargo.toml index 9afd16bea160..d6642a8edfe5 100644 --- a/examples/custom-engine-types/Cargo.toml +++ b/examples/custom-engine-types/Cargo.toml @@ -10,7 +10,6 @@ reth.workspace = true reth-chainspec.workspace = true reth-node-api.workspace = true reth-node-core.workspace = true -reth-primitives.workspace = true reth-payload-builder.workspace = true reth-basic-payload-builder.workspace = true reth-ethereum-payload-builder.workspace = true