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:
@ -999,7 +999,7 @@ mod tests {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,9 +228,9 @@ impl<N: NodePrimitives> StateProvider for MemoryOverlayStateProviderRef<'_, N> {
|
||||
self.historical.storage(address, storage_key)
|
||||
}
|
||||
|
||||
fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
|
||||
fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult<Option<Bytecode>> {
|
||||
for block in &self.in_memory {
|
||||
if let Some(contract) = block.execution_output.bytecode(&code_hash) {
|
||||
if let Some(contract) = block.execution_output.bytecode(code_hash) {
|
||||
return Ok(Some(contract));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
2
crates/rpc/rpc-eth-types/src/cache/db.rs
vendored
2
crates/rpc/rpc-eth-types/src/cache/db.rs
vendored
@ -156,7 +156,7 @@ impl StateProvider for StateProviderTraitObjWrapper<'_> {
|
||||
|
||||
fn bytecode_by_hash(
|
||||
&self,
|
||||
code_hash: B256,
|
||||
code_hash: &B256,
|
||||
) -> reth_errors::ProviderResult<Option<reth_primitives::Bytecode>> {
|
||||
self.0.bytecode_by_hash(code_hash)
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -380,9 +380,9 @@ where
|
||||
//
|
||||
// Any other case means that the account is not an EOA, and should not be able to send
|
||||
// transactions.
|
||||
if account.has_bytecode() {
|
||||
if let Some(code_hash) = &account.bytecode_hash {
|
||||
let is_eip7702 = if self.fork_tracker.is_prague_activated() {
|
||||
match state.bytecode_by_hash(account.get_bytecode_hash()) {
|
||||
match state.bytecode_by_hash(code_hash) {
|
||||
Ok(bytecode) => bytecode.unwrap_or_default().is_eip7702(),
|
||||
Err(err) => {
|
||||
return TransactionValidationOutcome::Error(
|
||||
|
||||
Reference in New Issue
Block a user