mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf: query bytecodes with &B256 to avoid copying code hash (#13559)
This commit is contained in:
@ -210,9 +210,9 @@ impl<SP: StateProvider, EDP: ExecutionDataProvider> StateProvider for BundleStat
|
||||
self.state_provider.storage(account, storage_key)
|
||||
}
|
||||
|
||||
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
|
||||
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
|
||||
if let Some(bytecode) =
|
||||
self.block_execution_data_provider.execution_outcome().bytecode(&code_hash)
|
||||
self.block_execution_data_provider.execution_outcome().bytecode(code_hash)
|
||||
{
|
||||
return Ok(Some(bytecode))
|
||||
}
|
||||
|
||||
@ -438,8 +438,8 @@ impl<Provider: DBProvider + BlockNumReader + BlockHashReader + StateCommitmentPr
|
||||
}
|
||||
|
||||
/// Get account code by its hash
|
||||
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
|
||||
self.tx().get::<tables::Bytecodes>(code_hash).map_err(Into::into)
|
||||
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
|
||||
self.tx().get_by_encoded_key::<tables::Bytecodes>(code_hash).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -184,8 +184,8 @@ impl<Provider: DBProvider + BlockHashReader + StateCommitmentProvider> StateProv
|
||||
}
|
||||
|
||||
/// Get account code by its hash
|
||||
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
|
||||
self.tx().get::<tables::Bytecodes>(code_hash).map_err(Into::into)
|
||||
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
|
||||
self.tx().get_by_encoded_key::<tables::Bytecodes>(code_hash).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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::Bytecode>>;
|
||||
}
|
||||
StateRootProvider $(where [$($generics)*])? {
|
||||
fn state_root(&self, state: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult<alloy_primitives::B256>;
|
||||
|
||||
@ -693,11 +693,11 @@ impl StateProvider for MockEthProvider {
|
||||
Ok(lock.get(&account).and_then(|account| account.storage.get(&storage_key)).copied())
|
||||
}
|
||||
|
||||
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
|
||||
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
|
||||
let lock = self.accounts.lock();
|
||||
Ok(lock.values().find_map(|account| {
|
||||
match (account.account.bytecode_hash.as_ref(), account.bytecode.as_ref()) {
|
||||
(Some(bytecode_hash), Some(bytecode)) if *bytecode_hash == code_hash => {
|
||||
(Some(bytecode_hash), Some(bytecode)) if bytecode_hash == code_hash => {
|
||||
Some(bytecode.clone())
|
||||
}
|
||||
_ => None,
|
||||
|
||||
@ -465,7 +465,7 @@ impl<C: Send + Sync, N: NodePrimitives> StateProvider for NoopProvider<C, N> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn bytecode_by_hash(&self, _code_hash: B256) -> ProviderResult<Option<Bytecode>> {
|
||||
fn bytecode_by_hash(&self, _code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ pub trait StateProvider:
|
||||
) -> ProviderResult<Option<StorageValue>>;
|
||||
|
||||
/// Get account code by its hash
|
||||
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>>;
|
||||
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>>;
|
||||
|
||||
/// Get account code by its address.
|
||||
///
|
||||
@ -53,7 +53,7 @@ pub trait StateProvider:
|
||||
return Ok(None)
|
||||
}
|
||||
// Get the code from the code hash
|
||||
return self.bytecode_by_hash(code_hash)
|
||||
return self.bytecode_by_hash(&code_hash)
|
||||
}
|
||||
|
||||
// Return `None` if no code hash is set
|
||||
|
||||
Reference in New Issue
Block a user