Introduce HashedPostStateProvider (#12607)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
frisitano
2024-12-04 00:56:17 +08:00
committed by GitHub
parent e4c7fac9db
commit 886471d693
42 changed files with 318 additions and 137 deletions

View File

@ -26,6 +26,7 @@ reth-trie.workspace = true
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
revm.workspace = true
# async
tokio = { workspace = true, default-features = false, features = ["sync", "macros"] }
@ -44,7 +45,6 @@ pin-project.workspace = true
alloy-signer = { workspace = true, optional = true }
alloy-signer-local = { workspace = true, optional = true }
rand = { workspace = true, optional = true }
revm = { workspace = true, optional = true }
[dev-dependencies]
reth-testing-utils.workspace = true
@ -52,17 +52,15 @@ alloy-signer.workspace = true
alloy-signer-local.workspace = true
alloy-consensus.workspace = true
rand.workspace = true
revm.workspace = true
[features]
test-utils = [
"alloy-signer",
"alloy-signer-local",
"rand",
"revm",
"reth-chainspec/test-utils",
"reth-primitives/test-utils",
"reth-primitives-traits/test-utils",
"reth-trie/test-utils",
"revm?/test-utils",
"revm/test-utils",
]

View File

@ -949,8 +949,8 @@ mod tests {
use reth_errors::ProviderResult;
use reth_primitives::{Account, Bytecode, EthPrimitives, Receipt};
use reth_storage_api::{
AccountReader, BlockHashReader, StateProofProvider, StateProvider, StateRootProvider,
StorageRootProvider,
AccountReader, BlockHashReader, HashedPostStateProvider, StateProofProvider, StateProvider,
StateRootProvider, StorageRootProvider,
};
use reth_trie::{
AccountProof, HashedStorage, MultiProof, StorageMultiProof, StorageProof, TrieInput,
@ -1047,6 +1047,12 @@ mod tests {
}
}
impl HashedPostStateProvider for MockStateProvider {
fn hashed_post_state(&self, _bundle_state: &revm::db::BundleState) -> HashedPostState {
HashedPostState::default()
}
}
impl StorageRootProvider for MockStateProvider {
fn storage_root(
&self,

View File

@ -8,13 +8,14 @@ use alloy_primitives::{
use reth_errors::ProviderResult;
use reth_primitives::{Account, Bytecode, NodePrimitives};
use reth_storage_api::{
AccountReader, BlockHashReader, StateProofProvider, StateProvider, StateRootProvider,
StorageRootProvider,
AccountReader, BlockHashReader, HashedPostStateProvider, StateProofProvider, StateProvider,
StateRootProvider, StorageRootProvider,
};
use reth_trie::{
updates::TrieUpdates, AccountProof, HashedPostState, HashedStorage, MultiProof,
StorageMultiProof, TrieInput,
};
use revm::db::BundleState;
use std::sync::OnceLock;
/// A state provider that stores references to in-memory blocks along with their state as well as a
@ -218,6 +219,12 @@ macro_rules! impl_state_provider {
}
}
impl $($tokens)* HashedPostStateProvider for $type {
fn hashed_post_state(&self, bundle_state: &BundleState) -> HashedPostState {
self.historical.hashed_post_state(bundle_state)
}
}
impl $($tokens)* StateProvider for $type {
fn storage(
&self,