mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: replace reth-provider dep in reth-evm (#8430)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -7727,7 +7727,7 @@ dependencies = [
|
||||
"reth-consensus-common",
|
||||
"reth-execution-errors",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-storage-api",
|
||||
"reth-storage-errors",
|
||||
"reth-trie",
|
||||
"revm",
|
||||
|
||||
@ -14,10 +14,10 @@ workspace = true
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-primitives.workspace = true
|
||||
reth-provider.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
reth-execution-errors.workspace = true
|
||||
reth-consensus-common.workspace = true
|
||||
reth-storage-api.workspace = true
|
||||
reth-trie = { workspace = true, optional = true }
|
||||
|
||||
# revm
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use reth_primitives::{Address, B256, KECCAK_EMPTY, U256};
|
||||
use reth_provider::StateProvider;
|
||||
use reth_storage_errors::provider::ProviderError;
|
||||
use crate::primitives::alloy_primitives::{BlockNumber, StorageKey, StorageValue};
|
||||
use reth_primitives::{Account, Address, B256, KECCAK_EMPTY, U256};
|
||||
use reth_storage_errors::provider::{ProviderError, ProviderResult};
|
||||
use revm::{
|
||||
db::DatabaseRef,
|
||||
primitives::{AccountInfo, Bytecode},
|
||||
@ -8,7 +8,61 @@ use revm::{
|
||||
};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// Wrapper around StateProvider that implements revm database trait
|
||||
/// A helper trait responsible for providing that necessary state for the EVM execution.
|
||||
///
|
||||
/// This servers as the data layer for [Database].
|
||||
pub trait EvmStateProvider: Send + Sync {
|
||||
/// Get basic account information.
|
||||
///
|
||||
/// Returns `None` if the account doesn't exist.
|
||||
fn basic_account(&self, address: Address) -> ProviderResult<Option<Account>>;
|
||||
|
||||
/// Get the hash of the block with the given number. Returns `None` if no block with this number
|
||||
/// exists.
|
||||
fn block_hash(&self, number: BlockNumber) -> ProviderResult<Option<B256>>;
|
||||
|
||||
/// Get account code by its hash
|
||||
fn bytecode_by_hash(
|
||||
&self,
|
||||
code_hash: B256,
|
||||
) -> ProviderResult<Option<reth_primitives::Bytecode>>;
|
||||
|
||||
/// Get storage of given account.
|
||||
fn storage(
|
||||
&self,
|
||||
account: Address,
|
||||
storage_key: StorageKey,
|
||||
) -> ProviderResult<Option<StorageValue>>;
|
||||
}
|
||||
|
||||
// Blanket implementation of EvmStateProvider for any type that implements StateProvider.
|
||||
impl<T: reth_storage_api::StateProvider> EvmStateProvider for T {
|
||||
fn basic_account(&self, address: Address) -> ProviderResult<Option<Account>> {
|
||||
<T as reth_storage_api::AccountReader>::basic_account(self, address)
|
||||
}
|
||||
|
||||
fn block_hash(&self, number: BlockNumber) -> ProviderResult<Option<B256>> {
|
||||
<T as reth_storage_api::BlockHashReader>::block_hash(self, number)
|
||||
}
|
||||
|
||||
fn bytecode_by_hash(
|
||||
&self,
|
||||
code_hash: B256,
|
||||
) -> ProviderResult<Option<reth_primitives::Bytecode>> {
|
||||
<T as reth_storage_api::StateProvider>::bytecode_by_hash(self, code_hash)
|
||||
}
|
||||
|
||||
fn storage(
|
||||
&self,
|
||||
account: Address,
|
||||
storage_key: StorageKey,
|
||||
) -> ProviderResult<Option<StorageValue>> {
|
||||
<T as reth_storage_api::StateProvider>::storage(self, account, storage_key)
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Database] and [DatabaseRef] implementation that uses [EvmStateProvider] as the underlying
|
||||
/// data source.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StateProviderDatabase<DB>(pub DB);
|
||||
|
||||
@ -38,7 +92,7 @@ impl<DB> DerefMut for StateProviderDatabase<DB> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB: StateProvider> Database for StateProviderDatabase<DB> {
|
||||
impl<DB: EvmStateProvider> Database for StateProviderDatabase<DB> {
|
||||
type Error = ProviderError;
|
||||
|
||||
/// Retrieves basic account information for a given address.
|
||||
@ -72,7 +126,7 @@ impl<DB: StateProvider> Database for StateProviderDatabase<DB> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB: StateProvider> DatabaseRef for StateProviderDatabase<DB> {
|
||||
impl<DB: EvmStateProvider> DatabaseRef for StateProviderDatabase<DB> {
|
||||
type Error = <Self as Database>::Error;
|
||||
|
||||
/// Retrieves basic account information for a given address.
|
||||
|
||||
@ -2,7 +2,7 @@ use reth_primitives::{
|
||||
keccak256, trie::AccountProof, Account, Address, BlockNumber, Bytecode, Bytes, StorageKey,
|
||||
B256, U256,
|
||||
};
|
||||
use reth_provider::{AccountReader, BlockHashReader, StateProvider, StateRootProvider};
|
||||
use reth_storage_api::{AccountReader, BlockHashReader, StateProvider, StateRootProvider};
|
||||
use reth_storage_errors::provider::ProviderResult;
|
||||
use reth_trie::updates::TrieUpdates;
|
||||
use revm::db::BundleState;
|
||||
|
||||
Reference in New Issue
Block a user