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)
|
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)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -228,9 +228,9 @@ impl<N: NodePrimitives> StateProvider for MemoryOverlayStateProviderRef<'_, N> {
|
|||||||
self.historical.storage(address, storage_key)
|
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 {
|
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));
|
return Ok(Some(contract));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ pub trait EvmStateProvider: Send + Sync {
|
|||||||
/// Get account code by hash.
|
/// Get account code by hash.
|
||||||
fn bytecode_by_hash(
|
fn bytecode_by_hash(
|
||||||
&self,
|
&self,
|
||||||
code_hash: B256,
|
code_hash: &B256,
|
||||||
) -> ProviderResult<Option<reth_primitives::Bytecode>>;
|
) -> ProviderResult<Option<reth_primitives::Bytecode>>;
|
||||||
|
|
||||||
/// Get storage of the given account.
|
/// Get storage of the given account.
|
||||||
@ -48,7 +48,7 @@ impl<T: reth_storage_api::StateProvider> EvmStateProvider for T {
|
|||||||
|
|
||||||
fn bytecode_by_hash(
|
fn bytecode_by_hash(
|
||||||
&self,
|
&self,
|
||||||
code_hash: B256,
|
code_hash: &B256,
|
||||||
) -> ProviderResult<Option<reth_primitives::Bytecode>> {
|
) -> ProviderResult<Option<reth_primitives::Bytecode>> {
|
||||||
<T as reth_storage_api::StateProvider>::bytecode_by_hash(self, code_hash)
|
<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.
|
/// 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> {
|
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.
|
/// 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()))
|
Ok(self.accounts.get(&account).and_then(|(storage, _)| 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>> {
|
||||||
Ok(self.contracts.get(&code_hash).cloned())
|
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(
|
fn bytecode_by_hash(
|
||||||
&self,
|
&self,
|
||||||
code_hash: B256,
|
code_hash: &B256,
|
||||||
) -> reth_errors::ProviderResult<Option<reth_primitives::Bytecode>> {
|
) -> reth_errors::ProviderResult<Option<reth_primitives::Bytecode>> {
|
||||||
self.0.bytecode_by_hash(code_hash)
|
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)
|
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) =
|
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))
|
return Ok(Some(bytecode))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -438,8 +438,8 @@ impl<Provider: DBProvider + BlockNumReader + BlockHashReader + StateCommitmentPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get account code by its hash
|
/// 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>> {
|
||||||
self.tx().get::<tables::Bytecodes>(code_hash).map_err(Into::into)
|
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
|
/// 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>> {
|
||||||
self.tx().get::<tables::Bytecodes>(code_hash).map_err(Into::into)
|
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)*])? {
|
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 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)*])? {
|
StateRootProvider $(where [$($generics)*])? {
|
||||||
fn state_root(&self, state: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult<alloy_primitives::B256>;
|
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())
|
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();
|
let lock = self.accounts.lock();
|
||||||
Ok(lock.values().find_map(|account| {
|
Ok(lock.values().find_map(|account| {
|
||||||
match (account.account.bytecode_hash.as_ref(), account.bytecode.as_ref()) {
|
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())
|
Some(bytecode.clone())
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
@ -465,7 +465,7 @@ impl<C: Send + Sync, N: NodePrimitives> StateProvider for NoopProvider<C, N> {
|
|||||||
Ok(None)
|
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)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ pub trait StateProvider:
|
|||||||
) -> ProviderResult<Option<StorageValue>>;
|
) -> ProviderResult<Option<StorageValue>>;
|
||||||
|
|
||||||
/// Get account code by its hash
|
/// 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.
|
/// Get account code by its address.
|
||||||
///
|
///
|
||||||
@ -53,7 +53,7 @@ pub trait StateProvider:
|
|||||||
return Ok(None)
|
return Ok(None)
|
||||||
}
|
}
|
||||||
// Get the code from the code hash
|
// 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
|
// 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
|
// Any other case means that the account is not an EOA, and should not be able to send
|
||||||
// transactions.
|
// transactions.
|
||||||
if account.has_bytecode() {
|
if let Some(code_hash) = &account.bytecode_hash {
|
||||||
let is_eip7702 = if self.fork_tracker.is_prague_activated() {
|
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(),
|
Ok(bytecode) => bytecode.unwrap_or_default().is_eip7702(),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return TransactionValidationOutcome::Error(
|
return TransactionValidationOutcome::Error(
|
||||||
|
|||||||
Reference in New Issue
Block a user