remove reth-primitives dep from reth-provider (#15203)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Ishika Choudhury
2025-03-24 19:23:49 +05:30
committed by GitHub
parent 5a7cd15e94
commit 914fc51f23
25 changed files with 146 additions and 179 deletions

View File

@@ -90,6 +90,7 @@ pub use alloy_consensus::{
transaction::{Recovered, TransactionMeta},
ReceiptWithBloom,
};
pub use transaction::{
execute::FillTxEnv,
signed::{FullSignedTx, SignedTransaction},

View File

@@ -15,8 +15,8 @@ workspace = true
# reth
reth-chainspec.workspace = true
reth-execution-types.workspace = true
reth-primitives = { workspace = true, features = ["reth-codec", "secp256k1"] }
reth-primitives-traits = { workspace = true, features = ["reth-codec"] }
reth-ethereum-primitives = { workspace = true, features = ["reth-codec"] }
reth-primitives-traits = { workspace = true, features = ["reth-codec", "secp256k1"] }
reth-fs-util.workspace = true
reth-errors.workspace = true
reth-storage-errors.workspace = true
@@ -33,7 +33,7 @@ reth-codecs.workspace = true
reth-evm.workspace = true
reth-chain-state.workspace = true
reth-node-types.workspace = true
reth-static-file-types.workspace = true
# ethereum
alloy-eips.workspace = true
alloy-primitives.workspace = true

View File

@@ -27,10 +27,12 @@ pub use providers::{
#[cfg(any(test, feature = "test-utils"))]
/// Common test helpers for mocking the Provider.
pub mod test_utils;
/// Re-export provider error.
pub use reth_storage_errors::provider::{ProviderError, ProviderResult};
pub use reth_static_file_types as static_file;
pub use static_file::StaticFileSegment;
pub use reth_execution_types::*;
pub mod bundle_state;

View File

@@ -26,14 +26,13 @@ use reth_db_api::{
transaction::DbTx,
Database,
};
use reth_ethereum_primitives::{Block, EthPrimitives, Receipt, TransactionSigned};
use reth_evm::{ConfigureEvm, EvmEnv};
use reth_execution_types::ExecutionOutcome;
use reth_node_types::{BlockTy, HeaderTy, NodeTypesWithDB, ReceiptTy, TxTy};
use reth_primitives::{
Account, Block, EthPrimitives, NodePrimitives, Receipt, RecoveredBlock, SealedBlock,
SealedHeader, StorageEntry, TransactionSigned,
use reth_primitives_traits::{
Account, BlockBody, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader, StorageEntry,
};
use reth_primitives_traits::BlockBody;
use reth_prune_types::{PruneCheckpoint, PruneSegment};
use reth_stages_types::{StageCheckpoint, StageId};
use reth_storage_api::{

View File

@@ -2,7 +2,7 @@ use crate::{
AccountReader, BlockHashReader, ExecutionDataProvider, StateProvider, StateRootProvider,
};
use alloy_primitives::{Address, BlockNumber, Bytes, B256};
use reth_primitives::{Account, Bytecode};
use reth_primitives_traits::{Account, Bytecode};
use reth_storage_api::{HashedPostStateProvider, StateProofProvider, StorageRootProvider};
use reth_storage_errors::provider::ProviderResult;
use reth_trie::{

View File

@@ -20,8 +20,9 @@ use reth_chainspec::{ChainInfo, EthereumHardforks};
use reth_db_api::models::{AccountBeforeTx, BlockNumberAddress, StoredBlockBodyIndices};
use reth_execution_types::{BundleStateInit, ExecutionOutcome, RevertsInit};
use reth_node_types::{BlockTy, HeaderTy, ReceiptTy, TxTy};
use reth_primitives::{Account, RecoveredBlock, SealedBlock, SealedHeader, StorageEntry};
use reth_primitives_traits::BlockBody;
use reth_primitives_traits::{
Account, BlockBody, RecoveredBlock, SealedBlock, SealedHeader, StorageEntry,
};
use reth_prune_types::{PruneCheckpoint, PruneSegment};
use reth_stages_types::{StageCheckpoint, StageId};
use reth_storage_api::{

View File

@@ -1,7 +1,8 @@
use crate::{providers::NodeTypesForProvider, DatabaseProvider};
use reth_db_api::transaction::{DbTx, DbTxMut};
use reth_node_types::{FullNodePrimitives, FullSignedTx};
use reth_primitives_traits::FullBlockHeader;
use reth_node_types::FullNodePrimitives;
use reth_primitives_traits::{FullBlockHeader, FullSignedTx};
use reth_storage_api::{ChainStorageReader, ChainStorageWriter, EthStorage};
/// Trait that provides access to implementations of [`ChainStorage`]
@@ -24,9 +25,9 @@ where
T: FullSignedTx,
H: FullBlockHeader,
N: FullNodePrimitives<
Block = reth_primitives::Block<T, H>,
Block = alloy_consensus::Block<T, H>,
BlockHeader = H,
BlockBody = reth_primitives::BlockBody<T, H>,
BlockBody = alloy_consensus::BlockBody<T, H>,
SignedTx = T,
>,
{

View File

@@ -18,9 +18,10 @@ use reth_errors::{RethError, RethResult};
use reth_node_types::{
BlockTy, HeaderTy, NodeTypes, NodeTypesWithDB, NodeTypesWithDBAdapter, ReceiptTy, TxTy,
};
use reth_primitives::{RecoveredBlock, SealedBlock, SealedHeader, StaticFileSegment};
use reth_primitives_traits::{RecoveredBlock, SealedBlock, SealedHeader};
use reth_prune_types::{PruneCheckpoint, PruneModes, PruneSegment};
use reth_stages_types::{StageCheckpoint, StageId};
use reth_static_file_types::StaticFileSegment;
use reth_storage_api::{
BlockBodyIndicesProvider, NodePrimitivesProvider, OmmersProvider, StateCommitmentProvider,
TryIntoHistoricalStateProvider,

View File

@@ -44,15 +44,15 @@ use reth_db_api::{
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_network_p2p::headers::downloader::SyncTarget;
use reth_node_types::{BlockTy, BodyTy, HeaderTy, NodeTypes, ReceiptTy, TxTy};
use reth_primitives::{
Account, Bytecode, GotExpected, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader,
StaticFileSegment, StorageEntry,
use reth_primitives_traits::{
Account, Block as _, BlockBody as _, Bytecode, GotExpected, NodePrimitives, RecoveredBlock,
SealedBlock, SealedHeader, SignedTransaction, StorageEntry,
};
use reth_primitives_traits::{Block as _, BlockBody as _, SignedTransaction};
use reth_prune_types::{
PruneCheckpoint, PruneMode, PruneModes, PruneSegment, MINIMUM_PRUNING_DISTANCE,
};
use reth_stages_types::{StageCheckpoint, StageId};
use reth_static_file_types::StaticFileSegment;
use reth_storage_api::{
BlockBodyIndicesProvider, BlockBodyReader, NodePrimitivesProvider, OmmersProvider,
StateProvider, StorageChangeSetReader, TryIntoHistoricalStateProvider,

View File

@@ -12,7 +12,7 @@ use reth_db_api::{
transaction::DbTx,
BlockNumberList,
};
use reth_primitives::{Account, Bytecode};
use reth_primitives_traits::{Account, Bytecode};
use reth_storage_api::{
BlockNumReader, DBProvider, StateCommitmentProvider, StateProofProvider, StorageRootProvider,
};

View File

@@ -4,7 +4,7 @@ use crate::{
};
use alloy_primitives::{Address, BlockNumber, Bytes, StorageKey, StorageValue, B256};
use reth_db_api::{cursor::DbDupCursorRO, tables, transaction::DbTx};
use reth_primitives::{Account, Bytecode};
use reth_primitives_traits::{Account, Bytecode};
use reth_storage_api::{
DBProvider, StateCommitmentProvider, StateProofProvider, StorageRootProvider,
};

View File

@@ -31,7 +31,7 @@ macro_rules! delegate_provider_impls {
$crate::providers::state::macros::delegate_impls_to_as_ref!(
for $target =>
AccountReader $(where [$($generics)*])? {
fn basic_account(&self, address: &alloy_primitives::Address) -> reth_storage_errors::provider::ProviderResult<Option<reth_primitives::Account>>;
fn basic_account(&self, address: &alloy_primitives::Address) -> reth_storage_errors::provider::ProviderResult<Option<reth_primitives_traits::Account>>;
}
BlockHashReader $(where [$($generics)*])? {
fn block_hash(&self, number: u64) -> reth_storage_errors::provider::ProviderResult<Option<alloy_primitives::B256>>;
@@ -39,7 +39,7 @@ macro_rules! delegate_provider_impls {
}
StateProvider $(where [$($generics)*])? {
fn storage(&self, account: alloy_primitives::Address, storage_key: alloy_primitives::StorageKey) -> reth_storage_errors::provider::ProviderResult<Option<alloy_primitives::StorageValue>>;
fn bytecode_by_hash(&self, code_hash: &alloy_primitives::B256) -> reth_storage_errors::provider::ProviderResult<Option<reth_primitives::Bytecode>>;
fn bytecode_by_hash(&self, code_hash: &alloy_primitives::B256) -> reth_storage_errors::provider::ProviderResult<Option<reth_primitives_traits::Bytecode>>;
}
StateRootProvider $(where [$($generics)*])? {
fn state_root(&self, state: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult<alloy_primitives::B256>;

View File

@@ -19,8 +19,7 @@ use reth_db_api::{
table::{Decompress, Value},
};
use reth_node_types::{FullNodePrimitives, NodePrimitives};
use reth_primitives::SealedHeader;
use reth_primitives_traits::SignedTransaction;
use reth_primitives_traits::{SealedHeader, SignedTransaction};
use reth_storage_api::{BlockBodyIndicesProvider, OmmersProvider, WithdrawalsProvider};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::{
@@ -28,7 +27,6 @@ use std::{
ops::{Deref, RangeBounds, RangeInclusive},
sync::Arc,
};
/// Provider over a specific `NippyJar` and range.
#[derive(Debug)]
pub struct StaticFileJarProvider<'a, N> {

View File

@@ -30,17 +30,15 @@ use reth_db_api::{
tables,
transaction::DbTx,
};
use reth_ethereum_primitives::{Receipt, TransactionSigned};
use reth_nippy_jar::{NippyJar, NippyJarChecker, CONFIG_FILE_EXTENSION};
use reth_node_types::{FullNodePrimitives, NodePrimitives};
use reth_primitives::{
static_file::{
find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive,
DEFAULT_BLOCKS_PER_STATIC_FILE,
},
Receipt, RecoveredBlock, SealedBlock, SealedHeader, StaticFileSegment, TransactionSigned,
};
use reth_primitives_traits::SignedTransaction;
use reth_primitives_traits::{RecoveredBlock, SealedBlock, SealedHeader, SignedTransaction};
use reth_stages_types::{PipelineTarget, StageId};
use reth_static_file_types::{
find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive, StaticFileSegment,
DEFAULT_BLOCKS_PER_STATIC_FILE,
};
use reth_storage_api::{BlockBodyIndicesProvider, DBProvider, OmmersProvider};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::{

View File

@@ -3,7 +3,7 @@ use std::{collections::HashMap, time::Duration};
use itertools::Itertools;
use metrics::{Counter, Gauge, Histogram};
use reth_metrics::Metrics;
use reth_primitives::StaticFileSegment;
use reth_static_file_types::StaticFileSegment;
use strum::{EnumIter, IntoEnumIterator};
/// Metrics for the static file provider.

View File

@@ -8,9 +8,8 @@ mod writer;
pub use writer::{StaticFileProviderRW, StaticFileProviderRWRefMut};
mod metrics;
use reth_nippy_jar::NippyJar;
use reth_primitives::{static_file::SegmentHeader, StaticFileSegment};
use reth_static_file_types::{SegmentHeader, StaticFileSegment};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::{ops::Deref, sync::Arc};

View File

@@ -11,10 +11,7 @@ use reth_db_api::models::{
};
use reth_nippy_jar::{NippyJar, NippyJarError, NippyJarWriter};
use reth_node_types::NodePrimitives;
use reth_primitives::{
static_file::{SegmentHeader, SegmentRangeInclusive},
StaticFileSegment,
};
use reth_static_file_types::{SegmentHeader, SegmentRangeInclusive, StaticFileSegment};
use reth_storage_errors::provider::{ProviderError, ProviderResult, StaticFileWriterError};
use std::{
borrow::Borrow,

View File

@@ -9,11 +9,9 @@ use alloy_consensus::Header;
use alloy_eips::eip4895::{Withdrawal, Withdrawals};
use alloy_primitives::PrimitiveSignature as Signature;
use reth_db_api::{database::Database, models::StoredBlockBodyIndices, tables};
use reth_ethereum_primitives::{BlockBody, Receipt, Transaction, TransactionSigned, TxType};
use reth_node_types::NodeTypes;
use reth_primitives::{
Account, BlockBody, Receipt, RecoveredBlock, SealedBlock, SealedHeader, Transaction,
TransactionSigned, TxType,
};
use reth_primitives_traits::{Account, RecoveredBlock, SealedBlock, SealedHeader};
use reth_trie::root::{state_root_unhashed, storage_root_unhashed};
use revm_database::BundleState;
use revm_state::AccountInfo;
@@ -22,7 +20,7 @@ use std::{str::FromStr, sync::LazyLock};
/// Assert genesis block
pub fn assert_genesis_block<DB: Database, N: NodeTypes>(
provider: &DatabaseProviderRW<DB, N>,
g: SealedBlock,
g: SealedBlock<reth_ethereum_primitives::Block>,
) {
let n = g.number;
let h = B256::ZERO;
@@ -63,39 +61,40 @@ pub fn assert_genesis_block<DB: Database, N: NodeTypes>(
// StageCheckpoints is not updated in tests
}
pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| {
SealedBlock::from_sealed_parts(
SealedHeader::new(
Header {
parent_hash: hex!(
"c86e8cc0310ae7c531c758678ddbfd16fc51c8cef8cec650b032de9869e8b94f"
)
.into(),
ommers_hash: EMPTY_OMMER_ROOT_HASH,
beneficiary: hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").into(),
state_root: hex!(
"50554882fbbda2c2fd93fdc466db9946ea262a67f7a76cc169e714f105ab583d"
)
.into(),
transactions_root: hex!(
"0967f09ef1dfed20c0eacfaa94d5cd4002eda3242ac47eae68972d07b106d192"
)
.into(),
receipts_root: hex!(
"e3c8b47fbfc94667ef4cceb17e5cc21e3b1eebd442cebb27f07562b33836290d"
)
.into(),
difficulty: U256::from(131_072),
number: 1,
gas_limit: 1_000_000,
gas_used: 14_352,
timestamp: 1_000,
..Default::default()
},
hex!("cf7b274520720b50e6a4c3e5c4d553101f44945396827705518ce17cb7219a42").into(),
),
BlockBody {
transactions: vec![TransactionSigned::new(
pub(crate) static TEST_BLOCK: LazyLock<SealedBlock<reth_ethereum_primitives::Block>> =
LazyLock::new(|| {
SealedBlock::from_sealed_parts(
SealedHeader::new(
Header {
parent_hash: hex!(
"c86e8cc0310ae7c531c758678ddbfd16fc51c8cef8cec650b032de9869e8b94f"
)
.into(),
ommers_hash: EMPTY_OMMER_ROOT_HASH,
beneficiary: hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").into(),
state_root: hex!(
"50554882fbbda2c2fd93fdc466db9946ea262a67f7a76cc169e714f105ab583d"
)
.into(),
transactions_root: hex!(
"0967f09ef1dfed20c0eacfaa94d5cd4002eda3242ac47eae68972d07b106d192"
)
.into(),
receipts_root: hex!(
"e3c8b47fbfc94667ef4cceb17e5cc21e3b1eebd442cebb27f07562b33836290d"
)
.into(),
difficulty: U256::from(131_072),
number: 1,
gas_limit: 1_000_000,
gas_used: 14_352,
timestamp: 1_000,
..Default::default()
},
hex!("cf7b274520720b50e6a4c3e5c4d553101f44945396827705518ce17cb7219a42").into(),
),
BlockBody {
transactions: vec![TransactionSigned::new(
Transaction::Legacy(TxLegacy {
gas_price: 10,
gas_limit: 400_000,
@@ -115,19 +114,19 @@ pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| {
),
b256!("0x3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397"),
)],
..Default::default()
},
)
});
..Default::default()
},
)
});
/// Test chain with genesis, blocks, execution results
/// that have valid changesets.
#[derive(Debug)]
pub struct BlockchainTestData {
/// Genesis
pub genesis: SealedBlock,
pub genesis: SealedBlock<reth_ethereum_primitives::Block>,
/// Blocks with its execution result
pub blocks: Vec<(RecoveredBlock<reth_primitives::Block>, ExecutionOutcome)>,
pub blocks: Vec<(RecoveredBlock<reth_ethereum_primitives::Block>, ExecutionOutcome)>,
}
impl BlockchainTestData {
@@ -162,7 +161,7 @@ impl Default for BlockchainTestData {
}
/// Genesis block
pub fn genesis() -> SealedBlock {
pub fn genesis() -> SealedBlock<reth_ethereum_primitives::Block> {
SealedBlock::from_sealed_parts(
SealedHeader::new(
Header { number: 0, difficulty: U256::from(1), ..Default::default() },
@@ -192,7 +191,9 @@ fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 {
}
/// Block one that points to genesis
fn block1(number: BlockNumber) -> (RecoveredBlock<reth_primitives::Block>, ExecutionOutcome) {
fn block1(
number: BlockNumber,
) -> (RecoveredBlock<reth_ethereum_primitives::Block>, ExecutionOutcome) {
// block changes
let account1: Address = [0x60; 20].into();
let account2: Address = [0x61; 20].into();
@@ -242,7 +243,7 @@ fn block2(
number: BlockNumber,
parent_hash: B256,
prev_execution_outcome: &ExecutionOutcome,
) -> (RecoveredBlock<reth_primitives::Block>, ExecutionOutcome) {
) -> (RecoveredBlock<reth_ethereum_primitives::Block>, ExecutionOutcome) {
// block changes
let account: Address = [0x60; 20].into();
let slot = U256::from(5);
@@ -300,7 +301,7 @@ fn block3(
number: BlockNumber,
parent_hash: B256,
prev_execution_outcome: &ExecutionOutcome,
) -> (RecoveredBlock<reth_primitives::Block>, ExecutionOutcome) {
) -> (RecoveredBlock<reth_ethereum_primitives::Block>, ExecutionOutcome) {
let address_range = 1..=20;
let slot_range = 1..=100;
@@ -358,7 +359,7 @@ fn block4(
number: BlockNumber,
parent_hash: B256,
prev_execution_outcome: &ExecutionOutcome,
) -> (RecoveredBlock<reth_primitives::Block>, ExecutionOutcome) {
) -> (RecoveredBlock<reth_ethereum_primitives::Block>, ExecutionOutcome) {
let address_range = 1..=20;
let slot_range = 1..=100;
@@ -441,7 +442,7 @@ fn block5(
number: BlockNumber,
parent_hash: B256,
prev_execution_outcome: &ExecutionOutcome,
) -> (RecoveredBlock<reth_primitives::Block>, ExecutionOutcome) {
) -> (RecoveredBlock<reth_ethereum_primitives::Block>, ExecutionOutcome) {
let address_range = 1..=20;
let slot_range = 1..=100;

View File

@@ -5,9 +5,7 @@ use crate::{
StateProvider, StateProviderBox, StateProviderFactory, StateReader, StateRootProvider,
TransactionVariant, TransactionsProvider, WithdrawalsProvider,
};
use alloy_consensus::{
constants::EMPTY_ROOT_HASH, transaction::TransactionMeta, Header, Transaction,
};
use alloy_consensus::{constants::EMPTY_ROOT_HASH, transaction::TransactionMeta, Header};
use alloy_eips::{eip4895::Withdrawals, BlockHashOrNumber, BlockId, BlockNumberOrTag};
use alloy_primitives::{
keccak256, map::HashMap, Address, BlockHash, BlockNumber, Bytes, StorageKey, StorageValue,
@@ -20,13 +18,12 @@ use reth_db_api::{
mock::{DatabaseMock, TxMock},
models::{AccountBeforeTx, StoredBlockBodyIndices},
};
use reth_ethereum_primitives::{EthPrimitives, Receipt};
use reth_execution_types::ExecutionOutcome;
use reth_node_types::NodeTypes;
use reth_primitives::{
Account, Block, Bytecode, EthPrimitives, GotExpected, Receipt, RecoveredBlock, SealedBlock,
SealedHeader, TransactionSigned,
use reth_primitives_traits::{
Account, Bytecode, GotExpected, RecoveredBlock, SealedBlock, SealedHeader, SignedTransaction,
};
use reth_primitives_traits::SignedTransaction;
use reth_prune_types::PruneModes;
use reth_stages_types::{StageCheckpoint, StageId};
use reth_storage_api::{
@@ -49,9 +46,9 @@ use tokio::sync::broadcast;
/// A mock implementation for Provider interfaces.
#[derive(Debug)]
pub struct MockEthProvider<T = TransactionSigned, ChainSpec = reth_chainspec::ChainSpec> {
pub struct MockEthProvider<ChainSpec = reth_chainspec::ChainSpec> {
/// Local block store
pub blocks: Arc<Mutex<HashMap<B256, Block<T>>>>,
pub blocks: Arc<Mutex<HashMap<B256, reth_ethereum_primitives::Block>>>,
/// Local header store
pub headers: Arc<Mutex<HashMap<B256, Header>>>,
/// Local account store
@@ -64,7 +61,7 @@ pub struct MockEthProvider<T = TransactionSigned, ChainSpec = reth_chainspec::Ch
prune_modes: Arc<PruneModes>,
}
impl<T, ChainSpec> Clone for MockEthProvider<T, ChainSpec> {
impl<ChainSpec> Clone for MockEthProvider<ChainSpec> {
fn clone(&self) -> Self {
Self {
blocks: self.blocks.clone(),
@@ -78,7 +75,7 @@ impl<T, ChainSpec> Clone for MockEthProvider<T, ChainSpec> {
}
}
impl<T> MockEthProvider<T> {
impl MockEthProvider {
/// Create a new, empty instance
pub fn new() -> Self {
Self {
@@ -92,16 +89,18 @@ impl<T> MockEthProvider<T> {
}
}
}
impl<T, ChainSpec> MockEthProvider<T, ChainSpec> {
impl<ChainSpec> MockEthProvider<ChainSpec> {
/// Add block to local block store
pub fn add_block(&self, hash: B256, block: Block<T>) {
pub fn add_block(&self, hash: B256, block: reth_ethereum_primitives::Block) {
self.add_header(hash, block.header.clone());
self.blocks.lock().insert(hash, block);
}
/// Add multiple blocks to local block store
pub fn extend_blocks(&self, iter: impl IntoIterator<Item = (B256, Block<T>)>) {
pub fn extend_blocks(
&self,
iter: impl IntoIterator<Item = (B256, reth_ethereum_primitives::Block)>,
) {
for (hash, block) in iter {
self.add_header(hash, block.header.clone());
self.add_block(hash, block)
@@ -138,7 +137,7 @@ impl<T, ChainSpec> MockEthProvider<T, ChainSpec> {
}
/// Set chain spec.
pub fn with_chain_spec<C>(self, chain_spec: C) -> MockEthProvider<T, C> {
pub fn with_chain_spec<C>(self, chain_spec: C) -> MockEthProvider<C> {
MockEthProvider {
blocks: self.blocks,
headers: self.headers,
@@ -205,14 +204,12 @@ impl NodeTypes for MockNode {
type Storage = EthStorage;
}
impl<T: Transaction, ChainSpec: EthChainSpec> StateCommitmentProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> StateCommitmentProvider for MockEthProvider<ChainSpec> {
type StateCommitment = <MockNode as NodeTypes>::StateCommitment;
}
impl<T: Transaction, ChainSpec: EthChainSpec + Clone + 'static> DatabaseProviderFactory
for MockEthProvider<T, ChainSpec>
impl<ChainSpec: EthChainSpec + Clone + 'static> DatabaseProviderFactory
for MockEthProvider<ChainSpec>
{
type DB = DatabaseMock;
type Provider = Self;
@@ -233,9 +230,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec + Clone + 'static> DatabaseProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec + 'static> DBProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec + 'static> DBProvider for MockEthProvider<ChainSpec> {
type Tx = TxMock;
fn tx_ref(&self) -> &Self::Tx {
@@ -255,7 +250,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec + 'static> DBProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> HeaderProvider for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> HeaderProvider for MockEthProvider<ChainSpec> {
type Header = Header;
fn header(&self, block_hash: &BlockHash) -> ProviderResult<Option<Header>> {
@@ -314,9 +309,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> HeaderProvider for MockEthProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec + 'static> ChainSpecProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec + 'static> ChainSpecProvider for MockEthProvider<ChainSpec> {
type ChainSpec = ChainSpec;
fn chain_spec(&self) -> Arc<ChainSpec> {
@@ -324,10 +317,8 @@ impl<T: Transaction, ChainSpec: EthChainSpec + 'static> ChainSpecProvider
}
}
impl<T: SignedTransaction, ChainSpec: EthChainSpec> TransactionsProvider
for MockEthProvider<T, ChainSpec>
{
type Transaction = T;
impl<ChainSpec: EthChainSpec> TransactionsProvider for MockEthProvider<ChainSpec> {
type Transaction = reth_ethereum_primitives::TransactionSigned;
fn transaction_id(&self, tx_hash: TxHash) -> ProviderResult<Option<TxNumber>> {
let lock = self.blocks.lock();
@@ -465,7 +456,7 @@ impl<T: SignedTransaction, ChainSpec: EthChainSpec> TransactionsProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> ReceiptProvider for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> ReceiptProvider for MockEthProvider<ChainSpec> {
type Receipt = Receipt;
fn receipt(&self, _id: TxNumber) -> ProviderResult<Option<Receipt>> {
@@ -488,12 +479,9 @@ impl<T: Transaction, ChainSpec: EthChainSpec> ReceiptProvider for MockEthProvide
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> ReceiptProviderIdExt
for MockEthProvider<T, ChainSpec>
{
}
impl<ChainSpec: EthChainSpec> ReceiptProviderIdExt for MockEthProvider<ChainSpec> {}
impl<T: Transaction, ChainSpec: EthChainSpec> BlockHashReader for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> BlockHashReader for MockEthProvider<ChainSpec> {
fn block_hash(&self, number: u64) -> ProviderResult<Option<B256>> {
let lock = self.blocks.lock();
@@ -517,7 +505,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> BlockHashReader for MockEthProvide
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> BlockNumReader for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> BlockNumReader for MockEthProvider<ChainSpec> {
fn chain_info(&self) -> ProviderResult<ChainInfo> {
let best_block_number = self.best_block_number()?;
let lock = self.headers.lock();
@@ -548,7 +536,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> BlockNumReader for MockEthProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> BlockIdReader for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> BlockIdReader for MockEthProvider<ChainSpec> {
fn pending_block_num_hash(&self) -> ProviderResult<Option<alloy_eips::BlockNumHash>> {
Ok(None)
}
@@ -562,8 +550,8 @@ impl<T: Transaction, ChainSpec: EthChainSpec> BlockIdReader for MockEthProvider<
}
}
impl<T: SignedTransaction, ChainSpec: EthChainSpec> BlockReader for MockEthProvider<T, ChainSpec> {
type Block = Block<T>;
impl<ChainSpec: EthChainSpec> BlockReader for MockEthProvider<ChainSpec> {
type Block = reth_ethereum_primitives::Block;
fn find_block_by_hash(
&self,
@@ -636,10 +624,8 @@ impl<T: SignedTransaction, ChainSpec: EthChainSpec> BlockReader for MockEthProvi
}
}
impl<T: SignedTransaction, ChainSpec: EthChainSpec> BlockReaderIdExt
for MockEthProvider<T, ChainSpec>
{
fn block_by_id(&self, id: BlockId) -> ProviderResult<Option<Block<T>>> {
impl<ChainSpec: EthChainSpec> BlockReaderIdExt for MockEthProvider<ChainSpec> {
fn block_by_id(&self, id: BlockId) -> ProviderResult<Option<reth_ethereum_primitives::Block>> {
match id {
BlockId::Number(num) => self.block_by_number_or_tag(num),
BlockId::Hash(hash) => self.block_by_hash(hash.block_hash),
@@ -665,15 +651,13 @@ impl<T: SignedTransaction, ChainSpec: EthChainSpec> BlockReaderIdExt
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> AccountReader for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> AccountReader for MockEthProvider<ChainSpec> {
fn basic_account(&self, address: &Address) -> ProviderResult<Option<Account>> {
Ok(self.accounts.lock().get(address).cloned().map(|a| a.account))
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> StageCheckpointReader
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> StageCheckpointReader for MockEthProvider<ChainSpec> {
fn get_stage_checkpoint(&self, _id: StageId) -> ProviderResult<Option<StageCheckpoint>> {
Ok(None)
}
@@ -687,7 +671,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> StageCheckpointReader
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> StateRootProvider for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> StateRootProvider for MockEthProvider<ChainSpec> {
fn state_root(&self, _state: HashedPostState) -> ProviderResult<B256> {
Ok(self.state_roots.lock().pop().unwrap_or_default())
}
@@ -713,9 +697,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> StateRootProvider for MockEthProvi
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> StorageRootProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> StorageRootProvider for MockEthProvider<ChainSpec> {
fn storage_root(
&self,
_address: Address,
@@ -743,7 +725,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> StorageRootProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> StateProofProvider for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> StateProofProvider for MockEthProvider<ChainSpec> {
fn proof(
&self,
_input: TrieInput,
@@ -766,17 +748,13 @@ impl<T: Transaction, ChainSpec: EthChainSpec> StateProofProvider for MockEthProv
}
}
impl<T: Transaction, ChainSpec: EthChainSpec + 'static> HashedPostStateProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec + 'static> HashedPostStateProvider for MockEthProvider<ChainSpec> {
fn hashed_post_state(&self, _state: &revm_database::BundleState) -> HashedPostState {
HashedPostState::default()
}
}
impl<T: Transaction, ChainSpec: EthChainSpec + 'static> StateProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec + 'static> StateProvider for MockEthProvider<ChainSpec> {
fn storage(
&self,
account: Address,
@@ -799,9 +777,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec + 'static> StateProvider
}
}
impl<T: SignedTransaction, ChainSpec: EthChainSpec + 'static> StateProviderFactory
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec + 'static> StateProviderFactory for MockEthProvider<ChainSpec> {
fn latest(&self) -> ProviderResult<StateProviderBox> {
Ok(Box::new(self.clone()))
}
@@ -853,9 +829,7 @@ impl<T: SignedTransaction, ChainSpec: EthChainSpec + 'static> StateProviderFacto
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> WithdrawalsProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> WithdrawalsProvider for MockEthProvider<ChainSpec> {
fn withdrawals_by_block(
&self,
_id: BlockHashOrNumber,
@@ -865,15 +839,13 @@ impl<T: Transaction, ChainSpec: EthChainSpec> WithdrawalsProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> OmmersProvider for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> OmmersProvider for MockEthProvider<ChainSpec> {
fn ommers(&self, _id: BlockHashOrNumber) -> ProviderResult<Option<Vec<Header>>> {
Ok(None)
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> BlockBodyIndicesProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> BlockBodyIndicesProvider for MockEthProvider<ChainSpec> {
fn block_body_indices(&self, _num: u64) -> ProviderResult<Option<StoredBlockBodyIndices>> {
Ok(None)
}
@@ -885,7 +857,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> BlockBodyIndicesProvider
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> ChangeSetReader for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> ChangeSetReader for MockEthProvider<ChainSpec> {
fn account_block_changeset(
&self,
_block_number: BlockNumber,
@@ -894,7 +866,7 @@ impl<T: Transaction, ChainSpec: EthChainSpec> ChangeSetReader for MockEthProvide
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> StateReader for MockEthProvider<T, ChainSpec> {
impl<ChainSpec: EthChainSpec> StateReader for MockEthProvider<ChainSpec> {
type Receipt = Receipt;
fn get_state(&self, _block: BlockNumber) -> ProviderResult<Option<ExecutionOutcome>> {
@@ -902,16 +874,12 @@ impl<T: Transaction, ChainSpec: EthChainSpec> StateReader for MockEthProvider<T,
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> CanonStateSubscriptions
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> CanonStateSubscriptions for MockEthProvider<ChainSpec> {
fn subscribe_to_canonical_state(&self) -> CanonStateNotifications<EthPrimitives> {
broadcast::channel(1).1
}
}
impl<T: Transaction, ChainSpec: EthChainSpec> NodePrimitivesProvider
for MockEthProvider<T, ChainSpec>
{
impl<ChainSpec: EthChainSpec> NodePrimitivesProvider for MockEthProvider<ChainSpec> {
type Primitives = EthPrimitives;
}

View File

@@ -10,7 +10,7 @@ use reth_db::{
};
use reth_errors::ProviderResult;
use reth_node_types::{NodeTypes, NodeTypesWithDBAdapter};
use reth_primitives::{Account, StorageEntry};
use reth_primitives_traits::{Account, StorageEntry};
use reth_trie::StateRoot;
use reth_trie_db::DatabaseStateRoot;
use std::sync::Arc;
@@ -25,7 +25,7 @@ pub use reth_chain_state::test_utils::TestCanonStateSubscriptions;
/// Mock [`reth_node_types::NodeTypes`] for testing.
pub type MockNodeTypes = reth_node_types::AnyNodeTypesWithEngine<
reth_primitives::EthPrimitives,
reth_ethereum_primitives::EthPrimitives,
reth_ethereum_engine_primitives::EthEngineTypes,
reth_chainspec::ChainSpec,
reth_trie_db::MerklePatriciaTrie,

View File

@@ -2,8 +2,7 @@ use alloy_primitives::BlockNumber;
use reth_db_api::models::StoredBlockBodyIndices;
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_node_types::NodePrimitives;
use reth_primitives::RecoveredBlock;
use reth_primitives_traits::Block;
use reth_primitives_traits::{Block, RecoveredBlock};
use reth_storage_api::{NodePrimitivesProvider, StorageLocation};
use reth_storage_errors::provider::ProviderResult;
use reth_trie::{updates::TrieUpdates, HashedPostStateSorted};

View File

@@ -2,7 +2,7 @@ use alloy_consensus::{BlockHeader, Header};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockNumber, Sealable, B256};
use reth_network_p2p::headers::downloader::SyncTarget;
use reth_primitives::SealedHeader;
use reth_primitives_traits::SealedHeader;
use reth_storage_errors::provider::ProviderResult;
use tokio::sync::watch;

View File

@@ -7,8 +7,8 @@ use alloy_consensus::BlockHeader;
use reth_chain_state::{ExecutedBlock, ExecutedBlockWithTrieUpdates};
use reth_db_api::transaction::{DbTx, DbTxMut};
use reth_errors::ProviderResult;
use reth_primitives::{NodePrimitives, StaticFileSegment};
use reth_primitives_traits::SignedTransaction;
use reth_primitives_traits::{NodePrimitives, SignedTransaction};
use reth_static_file_types::StaticFileSegment;
use reth_storage_api::{DBProvider, StageCheckpointWriter, TransactionsProviderExt};
use reth_storage_errors::writer::UnifiedStorageWriterError;
use revm_database::OriginalValuesKnown;
@@ -234,8 +234,9 @@ mod tests {
tables,
transaction::{DbTx, DbTxMut},
};
use reth_ethereum_primitives::Receipt;
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{Account, Receipt, StorageEntry};
use reth_primitives_traits::{Account, StorageEntry};
use reth_storage_api::{DatabaseProviderFactory, HashedPostStateProvider};
use reth_trie::{
test_utils::{state_root, storage_root_prehashed},