diff --git a/Cargo.lock b/Cargo.lock index d3447ba7f55..20c97c081ab 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", @@ -8439,17 +8440,18 @@ dependencies = [ "jsonrpsee-types", "metrics", "rand 0.8.5", + "reth-chain-state", "reth-chainspec", "reth-errors", "reth-evm", "reth-execution-types", "reth-metrics", "reth-primitives", - "reth-provider", "reth-revm", "reth-rpc-server-types", "reth-rpc-types", "reth-rpc-types-compat", + "reth-storage-api", "reth-tasks", "reth-transaction-pool", "reth-trie", @@ -8751,6 +8753,7 @@ dependencies = [ "proptest", "proptest-arbitrary-interop", "rand 0.8.5", + "reth-chain-state", "reth-chainspec", "reth-eth-wire-types", "reth-execution-types", @@ -8758,6 +8761,7 @@ dependencies = [ "reth-metrics", "reth-primitives", "reth-provider", + "reth-storage-api", "reth-tasks", "reth-tracing", "revm", diff --git a/crates/chainspec/Cargo.toml b/crates/chainspec/Cargo.toml index 5e015054753..41db578254f 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 17f766f5b0f..24f050d6f64 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 3df772f20f8..9e36f57f90a 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 247ca35fe70..5add0b976d3 100644 --- a/crates/rpc/rpc-eth-types/Cargo.toml +++ b/crates/rpc/rpc-eth-types/Cargo.toml @@ -13,12 +13,13 @@ 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 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 6741f2f651b..cd585921155 100644 --- a/crates/rpc/rpc-eth-types/src/builder/ctx.rs +++ b/crates/rpc/rpc-eth-types/src/builder/ctx.rs @@ -1,6 +1,8 @@ //! Context required for building `eth` namespace APIs. -use reth_provider::{BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider}; +use reth_chain_state::CanonStateSubscriptions; +use reth_chainspec::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 51ecef5d6a4..1b7c956f322 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_provider::StateProvider; use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef}; +use reth_storage_api::StateProvider; 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 cda3d72584c..6fc0ab9f481 100644 --- a/crates/rpc/rpc-eth-types/src/cache/mod.rs +++ b/crates/rpc/rpc-eth-types/src/cache/mod.rs @@ -1,16 +1,15 @@ //! 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::{ - BlockReader, CanonStateNotification, EvmEnvProvider, StateProviderFactory, TransactionVariant, -}; +use reth_storage_api::{BlockReader, StateProviderFactory, TransactionVariant}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; use schnellru::{ByLength, Limiter}; @@ -265,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_provider::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 fef2dc9eab2..94e52eb959d 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -11,14 +11,15 @@ use futures::{ FutureExt, Stream, StreamExt, }; use metrics::atomics::AtomicU64; -use reth_chainspec::ChainSpec; +use reth_chain_state::CanonStateNotification; +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::{BlockReaderIdExt, 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 92226748cea..f89dc01ff69 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 5cd5fa789d0..e2edc57f5db 100644 --- a/crates/rpc/rpc-eth-types/src/logs_utils.rs +++ b/crates/rpc/rpc-eth-types/src/logs_utils.rs @@ -3,10 +3,11 @@ //! Log parsing for building filter. use reth_chainspec::ChainInfo; +use reth_errors::ProviderError; use reth_primitives::{BlockNumHash, Receipt, TxHash}; -use reth_provider::{BlockReader, 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; diff --git a/crates/rpc/rpc-eth-types/src/pending_block.rs b/crates/rpc/rpc-eth-types/src/pending_block.rs index 64dd2aeb59b..db1dfab933c 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_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/mod.rs b/crates/storage/provider/src/traits/mod.rs index c89815a9f67..3e692b7ed90 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 798bfeae16f..00000000000 --- a/crates/storage/provider/src/traits/spec.rs +++ /dev/null @@ -1,9 +0,0 @@ -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; -} diff --git a/crates/transaction-pool/Cargo.toml b/crates/transaction-pool/Cargo.toml index 8790db64a61..8b8ac34ddd4 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 96cb5552fc1..f121dfed2d6 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 ed9e3ec65cd..4bf22e62ce1 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 f2023afa5f6..b95dce88632 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 23b4f26e9d6..1c0e1cc8262 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 72ab1d81a13..df05b0a4469 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::{