diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index 1e300539e2e4..6780a2421c0c 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -999,7 +999,7 @@ mod tests { Ok(None) } - fn bytecode_by_hash(&self, _code_hash: B256) -> ProviderResult> { + fn bytecode_by_hash(&self, _code_hash: &B256) -> ProviderResult> { Ok(None) } } diff --git a/crates/chain-state/src/memory_overlay.rs b/crates/chain-state/src/memory_overlay.rs index 7365a4b09c13..880c95ab3c37 100644 --- a/crates/chain-state/src/memory_overlay.rs +++ b/crates/chain-state/src/memory_overlay.rs @@ -228,9 +228,9 @@ impl StateProvider for MemoryOverlayStateProviderRef<'_, N> { self.historical.storage(address, storage_key) } - fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult> { + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult> { 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)); } } diff --git a/crates/revm/src/database.rs b/crates/revm/src/database.rs index e8f527e58ec9..db4dd554f3b0 100644 --- a/crates/revm/src/database.rs +++ b/crates/revm/src/database.rs @@ -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>; /// Get storage of the given account. @@ -48,7 +48,7 @@ impl EvmStateProvider for T { fn bytecode_by_hash( &self, - code_hash: B256, + code_hash: &B256, ) -> ProviderResult> { ::bytecode_by_hash(self, code_hash) } @@ -148,7 +148,7 @@ impl DatabaseRef for StateProviderDatabase { /// /// Returns `Ok` with the bytecode if found, or the default bytecode otherwise. fn code_by_hash_ref(&self, code_hash: B256) -> Result { - 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. diff --git a/crates/revm/src/test_utils.rs b/crates/revm/src/test_utils.rs index 8349750fb900..6d2dbf2ca01d 100644 --- a/crates/revm/src/test_utils.rs +++ b/crates/revm/src/test_utils.rs @@ -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> { - Ok(self.contracts.get(&code_hash).cloned()) + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult> { + Ok(self.contracts.get(code_hash).cloned()) } } diff --git a/crates/rpc/rpc-eth-types/src/cache/db.rs b/crates/rpc/rpc-eth-types/src/cache/db.rs index 80d1114f530c..dd15f7602179 100644 --- a/crates/rpc/rpc-eth-types/src/cache/db.rs +++ b/crates/rpc/rpc-eth-types/src/cache/db.rs @@ -156,7 +156,7 @@ impl StateProvider for StateProviderTraitObjWrapper<'_> { fn bytecode_by_hash( &self, - code_hash: B256, + code_hash: &B256, ) -> reth_errors::ProviderResult> { self.0.bytecode_by_hash(code_hash) } diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 9edb2763928d..316e6f64a326 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -210,9 +210,9 @@ impl StateProvider for BundleStat self.state_provider.storage(account, storage_key) } - fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult> { + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult> { 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)) } diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index 180a1aa3f5e9..140c9a8b44e4 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -438,8 +438,8 @@ impl ProviderResult> { - self.tx().get::(code_hash).map_err(Into::into) + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult> { + self.tx().get_by_encoded_key::(code_hash).map_err(Into::into) } } diff --git a/crates/storage/provider/src/providers/state/latest.rs b/crates/storage/provider/src/providers/state/latest.rs index 100637657840..46bd8db426fe 100644 --- a/crates/storage/provider/src/providers/state/latest.rs +++ b/crates/storage/provider/src/providers/state/latest.rs @@ -184,8 +184,8 @@ impl StateProv } /// Get account code by its hash - fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult> { - self.tx().get::(code_hash).map_err(Into::into) + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult> { + self.tx().get_by_encoded_key::(code_hash).map_err(Into::into) } } diff --git a/crates/storage/provider/src/providers/state/macros.rs b/crates/storage/provider/src/providers/state/macros.rs index 85cfd9053dfb..d97a5fa7b9d0 100644 --- a/crates/storage/provider/src/providers/state/macros.rs +++ b/crates/storage/provider/src/providers/state/macros.rs @@ -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>; - fn bytecode_by_hash(&self, code_hash: alloy_primitives::B256) -> reth_storage_errors::provider::ProviderResult>; + fn bytecode_by_hash(&self, code_hash: &alloy_primitives::B256) -> reth_storage_errors::provider::ProviderResult>; } StateRootProvider $(where [$($generics)*])? { fn state_root(&self, state: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult; diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index dbaa90acc6a2..5bac034b520a 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -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> { + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult> { 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, diff --git a/crates/storage/storage-api/src/noop.rs b/crates/storage/storage-api/src/noop.rs index d7c8350c9fba..53ff0d61637a 100644 --- a/crates/storage/storage-api/src/noop.rs +++ b/crates/storage/storage-api/src/noop.rs @@ -465,7 +465,7 @@ impl StateProvider for NoopProvider { Ok(None) } - fn bytecode_by_hash(&self, _code_hash: B256) -> ProviderResult> { + fn bytecode_by_hash(&self, _code_hash: &B256) -> ProviderResult> { Ok(None) } } diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index 66dba83c453c..23ba7ebb22e7 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -35,7 +35,7 @@ pub trait StateProvider: ) -> ProviderResult>; /// Get account code by its hash - fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult>; + fn bytecode_by_hash(&self, code_hash: &B256) -> ProviderResult>; /// 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 diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index ea09d61b219a..29430b5d278b 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -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(