From 76a1c891e6030ccaa995d22b3c47f5b72290ec36 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 16:28:53 +0200 Subject: [PATCH 1/8] Start untangling reth_provider but use reth_storage_api --- Cargo.lock | 1 + crates/rpc/rpc-eth-types/Cargo.toml | 1 + crates/rpc/rpc-eth-types/src/builder/ctx.rs | 3 ++- crates/rpc/rpc-eth-types/src/cache/db.rs | 10 +++++----- crates/rpc/rpc-eth-types/src/cache/mod.rs | 5 ++--- crates/rpc/rpc-eth-types/src/fee_history.rs | 3 ++- crates/rpc/rpc-eth-types/src/gas_oracle.rs | 2 +- crates/rpc/rpc-eth-types/src/logs_utils.rs | 3 ++- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3447ba7f553..683ba3749484 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8450,6 +8450,7 @@ dependencies = [ "reth-rpc-server-types", "reth-rpc-types", "reth-rpc-types-compat", + "reth-storage-api", "reth-tasks", "reth-transaction-pool", "reth-trie", diff --git a/crates/rpc/rpc-eth-types/Cargo.toml b/crates/rpc/rpc-eth-types/Cargo.toml index 247ca35fe701..83f884a759f6 100644 --- a/crates/rpc/rpc-eth-types/Cargo.toml +++ b/crates/rpc/rpc-eth-types/Cargo.toml @@ -19,6 +19,7 @@ reth-execution-types.workspace = true reth-metrics.workspace = true reth-primitives = { workspace = true, features = ["secp256k1"] } reth-provider.workspace = true +reth-storage-api.workspace = true reth-revm.workspace = true reth-rpc-server-types.workspace = true reth-rpc-types.workspace = true diff --git a/crates/rpc/rpc-eth-types/src/builder/ctx.rs b/crates/rpc/rpc-eth-types/src/builder/ctx.rs index 6741f2f651bf..fc76f9da6d26 100644 --- a/crates/rpc/rpc-eth-types/src/builder/ctx.rs +++ b/crates/rpc/rpc-eth-types/src/builder/ctx.rs @@ -1,6 +1,7 @@ //! Context required for building `eth` namespace APIs. -use reth_provider::{BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider}; +use reth_provider::{CanonStateSubscriptions, ChainSpecProvider}; +use reth_storage_api::BlockReaderIdExt; use reth_tasks::TaskSpawner; use crate::{ diff --git a/crates/rpc/rpc-eth-types/src/cache/db.rs b/crates/rpc/rpc-eth-types/src/cache/db.rs index 51ecef5d6a47..fd610a99e4f5 100644 --- a/crates/rpc/rpc-eth-types/src/cache/db.rs +++ b/crates/rpc/rpc-eth-types/src/cache/db.rs @@ -4,7 +4,7 @@ use reth_errors::ProviderResult; use reth_primitives::{Address, B256, U256}; -use reth_provider::StateProvider; +use reth_storage_api::StateProvider; use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef}; use reth_trie::HashedStorage; use revm::Database; @@ -17,7 +17,7 @@ pub type StateCacheDb<'a> = CacheDB(pub &'a dyn StateProvider); -impl<'a> reth_provider::StateRootProvider for StateProviderTraitObjWrapper<'a> { +impl<'a> reth_storage_api::StateRootProvider for StateProviderTraitObjWrapper<'a> { fn hashed_state_root( &self, hashed_state: reth_trie::HashedPostState, @@ -41,7 +41,7 @@ impl<'a> reth_provider::StateRootProvider for StateProviderTraitObjWrapper<'a> { } } -impl<'a> reth_provider::StateProofProvider for StateProviderTraitObjWrapper<'a> { +impl<'a> reth_storage_api::StateProofProvider for StateProviderTraitObjWrapper<'a> { fn hashed_proof( &self, hashed_state: reth_trie::HashedPostState, @@ -60,7 +60,7 @@ impl<'a> reth_provider::StateProofProvider for StateProviderTraitObjWrapper<'a> } } -impl<'a> reth_provider::AccountReader for StateProviderTraitObjWrapper<'a> { +impl<'a> reth_storage_api::AccountReader for StateProviderTraitObjWrapper<'a> { fn basic_account( &self, address: revm_primitives::Address, @@ -69,7 +69,7 @@ impl<'a> reth_provider::AccountReader for StateProviderTraitObjWrapper<'a> { } } -impl<'a> reth_provider::BlockHashReader for StateProviderTraitObjWrapper<'a> { +impl<'a> reth_storage_api::BlockHashReader for StateProviderTraitObjWrapper<'a> { fn block_hash( &self, block_number: reth_primitives::BlockNumber, diff --git a/crates/rpc/rpc-eth-types/src/cache/mod.rs b/crates/rpc/rpc-eth-types/src/cache/mod.rs index cda3d72584c3..bce20ff72ce8 100644 --- a/crates/rpc/rpc-eth-types/src/cache/mod.rs +++ b/crates/rpc/rpc-eth-types/src/cache/mod.rs @@ -8,9 +8,8 @@ use reth_primitives::{ Block, BlockHashOrNumber, BlockWithSenders, Receipt, SealedBlock, SealedBlockWithSenders, TransactionSigned, TransactionSignedEcRecovered, B256, }; -use reth_provider::{ - BlockReader, CanonStateNotification, EvmEnvProvider, StateProviderFactory, TransactionVariant, -}; +use reth_provider::{CanonStateNotification, EvmEnvProvider, TransactionVariant}; +use reth_storage_api::{BlockReader, StateProviderFactory}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; use schnellru::{ByLength, Limiter}; diff --git a/crates/rpc/rpc-eth-types/src/fee_history.rs b/crates/rpc/rpc-eth-types/src/fee_history.rs index fef2dc9eab21..3be958745ff5 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -17,8 +17,9 @@ use reth_primitives::{ eip4844::{calc_blob_gasprice, calculate_excess_blob_gas}, Receipt, SealedBlock, TransactionSigned, B256, }; -use reth_provider::{BlockReaderIdExt, CanonStateNotification, ChainSpecProvider}; +use reth_provider::{CanonStateNotification, ChainSpecProvider}; use reth_rpc_types::TxGasAndReward; +use reth_storage_api::BlockReaderIdExt; use serde::{Deserialize, Serialize}; use tracing::trace; diff --git a/crates/rpc/rpc-eth-types/src/gas_oracle.rs b/crates/rpc/rpc-eth-types/src/gas_oracle.rs index 92226748cead..f89dc01ff691 100644 --- a/crates/rpc/rpc-eth-types/src/gas_oracle.rs +++ b/crates/rpc/rpc-eth-types/src/gas_oracle.rs @@ -5,8 +5,8 @@ use std::fmt::{self, Debug, Formatter}; use derive_more::{Deref, DerefMut, From, Into}; use reth_primitives::{constants::GWEI_TO_WEI, BlockNumberOrTag, B256, U256}; -use reth_provider::BlockReaderIdExt; use reth_rpc_server_types::constants; +use reth_storage_api::BlockReaderIdExt; use schnellru::{ByLength, LruMap}; use serde::{Deserialize, Serialize}; use tokio::sync::Mutex; diff --git a/crates/rpc/rpc-eth-types/src/logs_utils.rs b/crates/rpc/rpc-eth-types/src/logs_utils.rs index 5cd5fa789d04..cbd80528ad37 100644 --- a/crates/rpc/rpc-eth-types/src/logs_utils.rs +++ b/crates/rpc/rpc-eth-types/src/logs_utils.rs @@ -4,9 +4,10 @@ use reth_chainspec::ChainInfo; use reth_primitives::{BlockNumHash, Receipt, TxHash}; -use reth_provider::{BlockReader, ProviderError}; +use reth_provider::ProviderError; use reth_rpc_server_types::result::rpc_error_with_code; use reth_rpc_types::{FilterId, FilteredParams, Log}; +use reth_storage_api::{BlockReader}; use crate::EthApiError; From a50fec7712b6347daa9ac8cb711498a97aa78dd8 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 17:13:29 +0200 Subject: [PATCH 2/8] Switching chain-state --- Cargo.lock | 1 + crates/rpc/rpc-eth-types/Cargo.toml | 1 + crates/rpc/rpc-eth-types/src/builder/ctx.rs | 3 ++- crates/rpc/rpc-eth-types/src/cache/mod.rs | 6 +++--- crates/rpc/rpc-eth-types/src/fee_history.rs | 3 ++- crates/rpc/rpc-eth-types/src/logs_utils.rs | 2 +- crates/rpc/rpc-eth-types/src/pending_block.rs | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 683ba3749484..2f5a0dda12a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8439,6 +8439,7 @@ dependencies = [ "jsonrpsee-types", "metrics", "rand 0.8.5", + "reth-chain-state", "reth-chainspec", "reth-errors", "reth-evm", diff --git a/crates/rpc/rpc-eth-types/Cargo.toml b/crates/rpc/rpc-eth-types/Cargo.toml index 83f884a759f6..6b68ad4b0aaf 100644 --- a/crates/rpc/rpc-eth-types/Cargo.toml +++ b/crates/rpc/rpc-eth-types/Cargo.toml @@ -13,6 +13,7 @@ workspace = true [dependencies] reth-chainspec.workspace = true +reth-chain-state.workspace = true reth-errors.workspace = true reth-evm.workspace = true reth-execution-types.workspace = true diff --git a/crates/rpc/rpc-eth-types/src/builder/ctx.rs b/crates/rpc/rpc-eth-types/src/builder/ctx.rs index fc76f9da6d26..4e06982117ec 100644 --- a/crates/rpc/rpc-eth-types/src/builder/ctx.rs +++ b/crates/rpc/rpc-eth-types/src/builder/ctx.rs @@ -1,6 +1,7 @@ //! Context required for building `eth` namespace APIs. -use reth_provider::{CanonStateSubscriptions, ChainSpecProvider}; +use reth_chain_state::CanonStateSubscriptions; +use reth_provider::ChainSpecProvider; use reth_storage_api::BlockReaderIdExt; use reth_tasks::TaskSpawner; diff --git a/crates/rpc/rpc-eth-types/src/cache/mod.rs b/crates/rpc/rpc-eth-types/src/cache/mod.rs index bce20ff72ce8..3ecffd96a208 100644 --- a/crates/rpc/rpc-eth-types/src/cache/mod.rs +++ b/crates/rpc/rpc-eth-types/src/cache/mod.rs @@ -8,8 +8,8 @@ use reth_primitives::{ Block, BlockHashOrNumber, BlockWithSenders, Receipt, SealedBlock, SealedBlockWithSenders, TransactionSigned, TransactionSignedEcRecovered, B256, }; -use reth_provider::{CanonStateNotification, EvmEnvProvider, TransactionVariant}; -use reth_storage_api::{BlockReader, StateProviderFactory}; +use reth_provider::{CanonStateNotification, EvmEnvProvider}; +use reth_storage_api::{BlockReader, StateProviderFactory, TransactionVariant}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; use schnellru::{ByLength, Limiter}; @@ -264,7 +264,7 @@ impl EthStateCache { /// A task than manages caches for data required by the `eth` rpc implementation. /// -/// It provides a caching layer on top of the given [`StateProvider`](reth_provider::StateProvider) +/// It provides a caching layer on top of the given [`StateProvider`](reth_storage_api::StateProvider) /// and keeps data fetched via the provider in memory in an LRU cache. If the requested data is /// missing in the cache it is fetched and inserted into the cache afterwards. While fetching data /// from disk is sync, this service is async since requests and data is shared via channels. diff --git a/crates/rpc/rpc-eth-types/src/fee_history.rs b/crates/rpc/rpc-eth-types/src/fee_history.rs index 3be958745ff5..c82a64f4c4e8 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -11,13 +11,14 @@ use futures::{ FutureExt, Stream, StreamExt, }; use metrics::atomics::AtomicU64; +use reth_chain_state::CanonStateNotification; use reth_chainspec::ChainSpec; use reth_primitives::{ basefee::calc_next_block_base_fee, eip4844::{calc_blob_gasprice, calculate_excess_blob_gas}, Receipt, SealedBlock, TransactionSigned, B256, }; -use reth_provider::{CanonStateNotification, ChainSpecProvider}; +use reth_provider::ChainSpecProvider; use reth_rpc_types::TxGasAndReward; use reth_storage_api::BlockReaderIdExt; use serde::{Deserialize, Serialize}; diff --git a/crates/rpc/rpc-eth-types/src/logs_utils.rs b/crates/rpc/rpc-eth-types/src/logs_utils.rs index cbd80528ad37..af4bddced302 100644 --- a/crates/rpc/rpc-eth-types/src/logs_utils.rs +++ b/crates/rpc/rpc-eth-types/src/logs_utils.rs @@ -4,10 +4,10 @@ use reth_chainspec::ChainInfo; use reth_primitives::{BlockNumHash, Receipt, TxHash}; -use reth_provider::ProviderError; use reth_rpc_server_types::result::rpc_error_with_code; use reth_rpc_types::{FilterId, FilteredParams, Log}; use reth_storage_api::{BlockReader}; +use reth_storage_api::errors::provider::ProviderError; use crate::EthApiError; diff --git a/crates/rpc/rpc-eth-types/src/pending_block.rs b/crates/rpc/rpc-eth-types/src/pending_block.rs index 64dd2aeb59b4..70a093da8af9 100644 --- a/crates/rpc/rpc-eth-types/src/pending_block.rs +++ b/crates/rpc/rpc-eth-types/src/pending_block.rs @@ -7,7 +7,7 @@ use std::{fmt, time::Instant}; use derive_more::Constructor; use reth_chainspec::ChainSpec; use reth_primitives::{BlockId, BlockNumberOrTag, SealedBlockWithSenders, SealedHeader, B256}; -use reth_provider::ProviderError; +use reth_storage_api::errors::provider::ProviderError; use reth_revm::state_change::apply_blockhashes_update; use revm_primitives::{ db::{Database, DatabaseCommit}, From 82e56f0801e449f74d765f95af490c201fdddfa3 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 17:23:34 +0200 Subject: [PATCH 3/8] Remove reth-provider from dependency of reth-eth-types --- Cargo.lock | 2 +- crates/chainspec/Cargo.toml | 1 + crates/chainspec/src/lib.rs | 4 ++-- crates/chainspec/src/spec.rs | 7 +++++++ crates/rpc/rpc-eth-types/Cargo.toml | 1 - crates/rpc/rpc-eth-types/src/builder/ctx.rs | 2 +- crates/rpc/rpc-eth-types/src/cache/db.rs | 2 +- crates/rpc/rpc-eth-types/src/cache/mod.rs | 13 +++++++------ crates/rpc/rpc-eth-types/src/fee_history.rs | 3 +-- crates/rpc/rpc-eth-types/src/logs_utils.rs | 4 ++-- crates/rpc/rpc-eth-types/src/pending_block.rs | 2 +- crates/storage/provider/src/traits/spec.rs | 10 +--------- 12 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f5a0dda12a3..fe24b29337d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6511,6 +6511,7 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "alloy-trie", + "auto_impl", "derive_more", "once_cell", "op-alloy-rpc-types", @@ -8446,7 +8447,6 @@ dependencies = [ "reth-execution-types", "reth-metrics", "reth-primitives", - "reth-provider", "reth-revm", "reth-rpc-server-types", "reth-rpc-types", diff --git a/crates/chainspec/Cargo.toml b/crates/chainspec/Cargo.toml index 5e0150547536..41db578254f3 100644 --- a/crates/chainspec/Cargo.toml +++ b/crates/chainspec/Cargo.toml @@ -29,6 +29,7 @@ op-alloy-rpc-types = { workspace = true, optional = true } # misc +auto_impl.workspace = true once_cell.workspace = true serde = { workspace = true, optional = true } serde_json.workspace = true diff --git a/crates/chainspec/src/lib.rs b/crates/chainspec/src/lib.rs index 17f766f5b0fd..24f050d6f641 100644 --- a/crates/chainspec/src/lib.rs +++ b/crates/chainspec/src/lib.rs @@ -12,8 +12,8 @@ pub use alloy_chains::{Chain, ChainKind, NamedChain}; pub use info::ChainInfo; pub use spec::{ - BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, DepositContract, - ForkBaseFeeParams, DEV, HOLESKY, MAINNET, SEPOLIA, + BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, ChainSpecProvider, + DepositContract, ForkBaseFeeParams, DEV, HOLESKY, MAINNET, SEPOLIA, }; #[cfg(feature = "optimism")] pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA}; diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 3df772f20f8d..9e36f57f90ab 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -808,6 +808,13 @@ impl From for ChainSpec { } } +/// A trait for reading the current [`ChainSpec`]. +#[auto_impl::auto_impl(&, Arc)] +pub trait ChainSpecProvider: Send + Sync { + /// Get an [`Arc`] to the [`ChainSpec`]. + fn chain_spec(&self) -> Arc; +} + /// A helper to build custom chain specs #[derive(Debug, Default, Clone)] pub struct ChainSpecBuilder { diff --git a/crates/rpc/rpc-eth-types/Cargo.toml b/crates/rpc/rpc-eth-types/Cargo.toml index 6b68ad4b0aaf..5add0b976d3b 100644 --- a/crates/rpc/rpc-eth-types/Cargo.toml +++ b/crates/rpc/rpc-eth-types/Cargo.toml @@ -19,7 +19,6 @@ reth-evm.workspace = true reth-execution-types.workspace = true reth-metrics.workspace = true reth-primitives = { workspace = true, features = ["secp256k1"] } -reth-provider.workspace = true reth-storage-api.workspace = true reth-revm.workspace = true reth-rpc-server-types.workspace = true diff --git a/crates/rpc/rpc-eth-types/src/builder/ctx.rs b/crates/rpc/rpc-eth-types/src/builder/ctx.rs index 4e06982117ec..cd585921155f 100644 --- a/crates/rpc/rpc-eth-types/src/builder/ctx.rs +++ b/crates/rpc/rpc-eth-types/src/builder/ctx.rs @@ -1,7 +1,7 @@ //! Context required for building `eth` namespace APIs. use reth_chain_state::CanonStateSubscriptions; -use reth_provider::ChainSpecProvider; +use reth_chainspec::ChainSpecProvider; use reth_storage_api::BlockReaderIdExt; use reth_tasks::TaskSpawner; diff --git a/crates/rpc/rpc-eth-types/src/cache/db.rs b/crates/rpc/rpc-eth-types/src/cache/db.rs index fd610a99e4f5..1b7c956f3221 100644 --- a/crates/rpc/rpc-eth-types/src/cache/db.rs +++ b/crates/rpc/rpc-eth-types/src/cache/db.rs @@ -4,8 +4,8 @@ use reth_errors::ProviderResult; use reth_primitives::{Address, B256, U256}; -use reth_storage_api::StateProvider; use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef}; +use reth_storage_api::StateProvider; use reth_trie::HashedStorage; use revm::Database; diff --git a/crates/rpc/rpc-eth-types/src/cache/mod.rs b/crates/rpc/rpc-eth-types/src/cache/mod.rs index 3ecffd96a208..6fc0ab9f4812 100644 --- a/crates/rpc/rpc-eth-types/src/cache/mod.rs +++ b/crates/rpc/rpc-eth-types/src/cache/mod.rs @@ -1,14 +1,14 @@ //! Async caching support for eth RPC use futures::{future::Either, Stream, StreamExt}; +use reth_chain_state::CanonStateNotification; use reth_errors::{ProviderError, ProviderResult}; -use reth_evm::ConfigureEvm; +use reth_evm::{provider::EvmEnvProvider, ConfigureEvm}; use reth_execution_types::Chain; use reth_primitives::{ Block, BlockHashOrNumber, BlockWithSenders, Receipt, SealedBlock, SealedBlockWithSenders, TransactionSigned, TransactionSignedEcRecovered, B256, }; -use reth_provider::{CanonStateNotification, EvmEnvProvider}; use reth_storage_api::{BlockReader, StateProviderFactory, TransactionVariant}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; @@ -264,10 +264,11 @@ impl EthStateCache { /// A task than manages caches for data required by the `eth` rpc implementation. /// -/// It provides a caching layer on top of the given [`StateProvider`](reth_storage_api::StateProvider) -/// and keeps data fetched via the provider in memory in an LRU cache. If the requested data is -/// missing in the cache it is fetched and inserted into the cache afterwards. While fetching data -/// from disk is sync, this service is async since requests and data is shared via channels. +/// It provides a caching layer on top of the given +/// [`StateProvider`](reth_storage_api::StateProvider) and keeps data fetched via the provider in +/// memory in an LRU cache. If the requested data is missing in the cache it is fetched and inserted +/// into the cache afterwards. While fetching data from disk is sync, this service is async since +/// requests and data is shared via channels. /// /// This type is an endless future that listens for incoming messages from the user facing /// [`EthStateCache`] via a channel. If the requested data is not cached then it spawns a new task diff --git a/crates/rpc/rpc-eth-types/src/fee_history.rs b/crates/rpc/rpc-eth-types/src/fee_history.rs index c82a64f4c4e8..94e52eb959db 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -12,13 +12,12 @@ use futures::{ }; use metrics::atomics::AtomicU64; use reth_chain_state::CanonStateNotification; -use reth_chainspec::ChainSpec; +use reth_chainspec::{ChainSpec, ChainSpecProvider}; use reth_primitives::{ basefee::calc_next_block_base_fee, eip4844::{calc_blob_gasprice, calculate_excess_blob_gas}, Receipt, SealedBlock, TransactionSigned, B256, }; -use reth_provider::ChainSpecProvider; use reth_rpc_types::TxGasAndReward; use reth_storage_api::BlockReaderIdExt; use serde::{Deserialize, Serialize}; diff --git a/crates/rpc/rpc-eth-types/src/logs_utils.rs b/crates/rpc/rpc-eth-types/src/logs_utils.rs index af4bddced302..e2edc57f5db5 100644 --- a/crates/rpc/rpc-eth-types/src/logs_utils.rs +++ b/crates/rpc/rpc-eth-types/src/logs_utils.rs @@ -3,11 +3,11 @@ //! Log parsing for building filter. use reth_chainspec::ChainInfo; +use reth_errors::ProviderError; use reth_primitives::{BlockNumHash, Receipt, TxHash}; use reth_rpc_server_types::result::rpc_error_with_code; use reth_rpc_types::{FilterId, FilteredParams, Log}; -use reth_storage_api::{BlockReader}; -use reth_storage_api::errors::provider::ProviderError; +use reth_storage_api::BlockReader; use crate::EthApiError; diff --git a/crates/rpc/rpc-eth-types/src/pending_block.rs b/crates/rpc/rpc-eth-types/src/pending_block.rs index 70a093da8af9..db1dfab933c0 100644 --- a/crates/rpc/rpc-eth-types/src/pending_block.rs +++ b/crates/rpc/rpc-eth-types/src/pending_block.rs @@ -7,8 +7,8 @@ use std::{fmt, time::Instant}; use derive_more::Constructor; use reth_chainspec::ChainSpec; use reth_primitives::{BlockId, BlockNumberOrTag, SealedBlockWithSenders, SealedHeader, B256}; -use reth_storage_api::errors::provider::ProviderError; use reth_revm::state_change::apply_blockhashes_update; +use reth_storage_api::errors::provider::ProviderError; use revm_primitives::{ db::{Database, DatabaseCommit}, BlockEnv, CfgEnvWithHandlerCfg, diff --git a/crates/storage/provider/src/traits/spec.rs b/crates/storage/provider/src/traits/spec.rs index 798bfeae16fd..3c4c896c861e 100644 --- a/crates/storage/provider/src/traits/spec.rs +++ b/crates/storage/provider/src/traits/spec.rs @@ -1,9 +1 @@ -use reth_chainspec::ChainSpec; -use std::sync::Arc; - -/// A trait for reading the current chainspec. -#[auto_impl::auto_impl(&, Arc)] -pub trait ChainSpecProvider: Send + Sync { - /// Get an [`Arc`] to the chainspec. - fn chain_spec(&self) -> Arc; -} +pub use reth_chainspec::ChainSpecProvider; From 7b72f90024684aee37ac4ce922ed87372ca9bf72 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 17:54:06 +0200 Subject: [PATCH 4/8] Remove reth-provider from reth-transaction-pool --- Cargo.lock | 2 ++ Makefile | 5 +---- crates/transaction-pool/Cargo.toml | 3 ++- crates/transaction-pool/src/blobstore/tracker.rs | 2 +- crates/transaction-pool/src/lib.rs | 15 ++++++++------- crates/transaction-pool/src/maintain.rs | 7 +++---- crates/transaction-pool/src/validate/eth.rs | 2 +- crates/transaction-pool/src/validate/task.rs | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe24b29337d8..20c97c081abc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8753,6 +8753,7 @@ dependencies = [ "proptest", "proptest-arbitrary-interop", "rand 0.8.5", + "reth-chain-state", "reth-chainspec", "reth-eth-wire-types", "reth-execution-types", @@ -8760,6 +8761,7 @@ dependencies = [ "reth-metrics", "reth-primitives", "reth-provider", + "reth-storage-api", "reth-tasks", "reth-tracing", "revm", diff --git a/Makefile b/Makefile index 119d1825048c..533c71d5dd48 100644 --- a/Makefile +++ b/Makefile @@ -470,8 +470,5 @@ pr: check-features: cargo hack check \ - --package reth-codecs \ - --package reth-primitives-traits \ - --package reth-primitives \ - --package reth-rpc-types \ + --package reth-provider \ --feature-powerset \ No newline at end of file diff --git a/crates/transaction-pool/Cargo.toml b/crates/transaction-pool/Cargo.toml index 8790db64a61a..8b8ac34ddd46 100644 --- a/crates/transaction-pool/Cargo.toml +++ b/crates/transaction-pool/Cargo.toml @@ -13,12 +13,13 @@ workspace = true [dependencies] # reth +reth-chain-state.workspace = true reth-chainspec.workspace = true reth-eth-wire-types.workspace = true reth-primitives = { workspace = true, features = ["c-kzg", "secp256k1"] } reth-execution-types.workspace = true reth-fs-util.workspace = true -reth-provider.workspace = true +reth-storage-api.workspace = true reth-tasks.workspace = true revm.workspace = true diff --git a/crates/transaction-pool/src/blobstore/tracker.rs b/crates/transaction-pool/src/blobstore/tracker.rs index 96cb5552fc1e..f121dfed2d63 100644 --- a/crates/transaction-pool/src/blobstore/tracker.rs +++ b/crates/transaction-pool/src/blobstore/tracker.rs @@ -1,7 +1,7 @@ //! Support for maintaining the blob pool. +use reth_execution_types::ChainBlocks; use reth_primitives::{BlockNumber, B256}; -use reth_provider::ChainBlocks; use std::collections::BTreeMap; /// The type that is used to track canonical blob transactions. diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index ed9e3ec65cd1..e986733f9554 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -79,8 +79,8 @@ //! Listen for new transactions and print them: //! //! ``` -//! use reth_chainspec::MAINNET; -//! use reth_provider::{BlockReaderIdExt, ChainSpecProvider, StateProviderFactory}; +//! use reth_chainspec::{MAINNET, ChainSpecProvider}; +//! use reth_storage_api::{BlockReaderIdExt, StateProviderFactory}; //! use reth_tasks::TokioTaskExecutor; //! use reth_transaction_pool::{TransactionValidationTaskExecutor, Pool, TransactionPool}; //! use reth_transaction_pool::blobstore::InMemoryBlobStore; @@ -107,8 +107,9 @@ //! //! ``` //! use futures_util::Stream; -//! use reth_chainspec::MAINNET; -//! use reth_provider::{BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, StateProviderFactory}; +//! use reth_chain_state::CanonStateNotification +//! use reth_chainspec::{MAINNET, ChainSpecProvider}; +//! use reth_storage_api::{BlockReaderIdExt, StateProviderFactory}; //! use reth_tasks::TokioTaskExecutor; //! use reth_tasks::TaskSpawner; //! use reth_tasks::TaskManager; @@ -153,7 +154,7 @@ use crate::{identifier::TransactionId, pool::PoolInner}; use aquamarine as _; use reth_eth_wire_types::HandleMempoolData; use reth_primitives::{Address, BlobTransactionSidecar, PooledTransactionsElement, TxHash, U256}; -use reth_provider::StateProviderFactory; +use reth_storage_api::StateProviderFactory; use std::{collections::HashSet, sync::Arc}; use tokio::sync::mpsc::Receiver; use tracing::{instrument, trace}; @@ -275,7 +276,7 @@ where impl EthTransactionPool where - Client: StateProviderFactory + reth_provider::BlockReaderIdExt + Clone + 'static, + Client: StateProviderFactory + reth_storage_api::BlockReaderIdExt + Clone + 'static, S: BlobStore, { /// Returns a new [`Pool`] that uses the default [`TransactionValidationTaskExecutor`] when @@ -285,7 +286,7 @@ where /// /// ``` /// use reth_chainspec::MAINNET; - /// use reth_provider::{BlockReaderIdExt, StateProviderFactory}; + /// use reth_storage_api::{BlockReaderIdExt, StateProviderFactory}; /// use reth_tasks::TokioTaskExecutor; /// use reth_transaction_pool::{ /// blobstore::InMemoryBlobStore, Pool, TransactionValidationTaskExecutor, diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index f2023afa5f61..b95dce88632f 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -11,16 +11,15 @@ use futures_util::{ future::{BoxFuture, Fuse, FusedFuture}, FutureExt, Stream, StreamExt, }; +use reth_chain_state::CanonStateNotification; +use reth_chainspec::ChainSpecProvider; use reth_execution_types::ExecutionOutcome; use reth_fs_util::FsPathError; use reth_primitives::{ Address, BlockHash, BlockNumber, BlockNumberOrTag, IntoRecoveredTransaction, PooledTransactionsElementEcRecovered, TransactionSigned, }; -use reth_provider::{ - BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, ProviderError, - StateProviderFactory, -}; +use reth_storage_api::{errors::provider::ProviderError, BlockReaderIdExt, StateProviderFactory}; use reth_tasks::TaskSpawner; use std::{ borrow::Borrow, diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index 23b4f26e9d69..1c0e1cc8262e 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -15,7 +15,7 @@ use reth_primitives::{ EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID, LEGACY_TX_TYPE_ID, }; -use reth_provider::{AccountReader, BlockReaderIdExt, StateProviderFactory}; +use reth_storage_api::{AccountReader, BlockReaderIdExt, StateProviderFactory}; use reth_tasks::TaskSpawner; use revm::{ interpreter::gas::validate_initial_tx_gas, diff --git a/crates/transaction-pool/src/validate/task.rs b/crates/transaction-pool/src/validate/task.rs index 72ab1d81a13a..df05b0a4469f 100644 --- a/crates/transaction-pool/src/validate/task.rs +++ b/crates/transaction-pool/src/validate/task.rs @@ -9,7 +9,7 @@ use crate::{ use futures_util::{lock::Mutex, StreamExt}; use reth_chainspec::ChainSpec; use reth_primitives::SealedBlock; -use reth_provider::BlockReaderIdExt; +use reth_storage_api::BlockReaderIdExt; use reth_tasks::TaskSpawner; use std::{future::Future, pin::Pin, sync::Arc}; use tokio::{ From fb19052c7684f27cacf4e91e54f688d8800a497e Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 18:13:45 +0200 Subject: [PATCH 5/8] Rollback check-features edit --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 533c71d5dd48..119d1825048c 100644 --- a/Makefile +++ b/Makefile @@ -470,5 +470,8 @@ pr: check-features: cargo hack check \ - --package reth-provider \ + --package reth-codecs \ + --package reth-primitives-traits \ + --package reth-primitives \ + --package reth-rpc-types \ --feature-powerset \ No newline at end of file From bfd38e455abd907a8bba215d5047cc2621d88de6 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 18:52:06 +0200 Subject: [PATCH 6/8] Re-export directly from traits/mod.rs --- crates/storage/provider/src/traits/mod.rs | 3 +-- crates/storage/provider/src/traits/spec.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 crates/storage/provider/src/traits/spec.rs diff --git a/crates/storage/provider/src/traits/mod.rs b/crates/storage/provider/src/traits/mod.rs index c89815a9f670..3e692b7ed905 100644 --- a/crates/storage/provider/src/traits/mod.rs +++ b/crates/storage/provider/src/traits/mod.rs @@ -18,8 +18,7 @@ pub use header_sync_gap::{HeaderSyncGap, HeaderSyncGapProvider}; mod state; pub use state::{StateChangeWriter, StateWriter}; -mod spec; -pub use spec::ChainSpecProvider; +pub use reth_chainspec::ChainSpecProvider; mod hashing; pub use hashing::HashingWriter; diff --git a/crates/storage/provider/src/traits/spec.rs b/crates/storage/provider/src/traits/spec.rs deleted file mode 100644 index 3c4c896c861e..000000000000 --- a/crates/storage/provider/src/traits/spec.rs +++ /dev/null @@ -1 +0,0 @@ -pub use reth_chainspec::ChainSpecProvider; From 66a9c700e9ca48516d4370c798e8eb7f4e21221f Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 18:57:48 +0200 Subject: [PATCH 7/8] Failing doctest fix --- crates/transaction-pool/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index e986733f9554..0d67c327b4cf 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -107,7 +107,7 @@ //! //! ``` //! use futures_util::Stream; -//! use reth_chain_state::CanonStateNotification +//! use reth_chain_state::CanonStateNotification; //! use reth_chainspec::{MAINNET, ChainSpecProvider}; //! use reth_storage_api::{BlockReaderIdExt, StateProviderFactory}; //! use reth_tasks::TokioTaskExecutor; @@ -276,7 +276,7 @@ where impl EthTransactionPool where - Client: StateProviderFactory + reth_storage_api::BlockReaderIdExt + Clone + 'static, + Client: StateProviderFactory + reth_provider::BlockReaderIdExt + Clone + 'static, S: BlobStore, { /// Returns a new [`Pool`] that uses the default [`TransactionValidationTaskExecutor`] when From 4d05c45c739834451ef3a12892445996d138a280 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Wed, 7 Aug 2024 19:03:18 +0200 Subject: [PATCH 8/8] Hm, how this got in --- crates/transaction-pool/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 0d67c327b4cf..4bf22e62ce1a 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -276,7 +276,7 @@ where impl EthTransactionPool where - Client: StateProviderFactory + reth_provider::BlockReaderIdExt + Clone + 'static, + Client: StateProviderFactory + reth_storage_api::BlockReaderIdExt + Clone + 'static, S: BlobStore, { /// Returns a new [`Pool`] that uses the default [`TransactionValidationTaskExecutor`] when