perf: query bytecodes with &B256 to avoid copying code hash (#13559)

This commit is contained in:
Hai | RISE
2024-12-26 21:58:56 +07:00
committed by GitHub
parent 951e2fd641
commit 56ce046317
13 changed files with 23 additions and 23 deletions

View File

@ -25,7 +25,7 @@ pub trait EvmStateProvider: Send + Sync {
/// Get account code by hash.
fn bytecode_by_hash(
&self,
code_hash: B256,
code_hash: &B256,
) -> ProviderResult<Option<reth_primitives::Bytecode>>;
/// Get storage of the given account.
@ -48,7 +48,7 @@ impl<T: reth_storage_api::StateProvider> EvmStateProvider for T {
fn bytecode_by_hash(
&self,
code_hash: B256,
code_hash: &B256,
) -> ProviderResult<Option<reth_primitives::Bytecode>> {
<T as reth_storage_api::StateProvider>::bytecode_by_hash(self, code_hash)
}
@ -148,7 +148,7 @@ impl<DB: EvmStateProvider> DatabaseRef for StateProviderDatabase<DB> {
///
/// Returns `Ok` with the bytecode if found, or the default bytecode otherwise.
fn code_by_hash_ref(&self, code_hash: B256) -> Result<Bytecode, Self::Error> {
Ok(self.bytecode_by_hash(code_hash)?.unwrap_or_default().0)
Ok(self.bytecode_by_hash(&code_hash)?.unwrap_or_default().0)
}
/// Retrieves the storage value at a specific index for a given address.

View File

@ -165,7 +165,7 @@ impl StateProvider for StateProviderTest {
Ok(self.accounts.get(&account).and_then(|(storage, _)| storage.get(&storage_key).copied()))
}
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
Ok(self.contracts.get(&code_hash).cloned())
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
Ok(self.contracts.get(code_hash).cloned())
}
}