perf: small access list perf (#4505)

This commit is contained in:
Matthias Seitz
2023-09-07 14:21:00 +02:00
committed by GitHub
parent 548d7f1636
commit 00bebfd64d
3 changed files with 16 additions and 13 deletions

View File

@@ -48,15 +48,17 @@ pub struct AccessList(
impl AccessList {
/// Converts the list into a vec, expected by revm
pub fn flattened(self) -> Vec<(Address, Vec<U256>)> {
self.0
.into_iter()
.map(|item| {
(
item.address,
item.storage_keys.into_iter().map(|slot| U256::from_be_bytes(slot.0)).collect(),
)
})
.collect()
self.flatten().collect()
}
/// Returns an iterator over the list's addresses and storage keys.
pub fn flatten(self) -> impl Iterator<Item = (Address, Vec<U256>)> {
self.0.into_iter().map(|item| {
(
item.address,
item.storage_keys.into_iter().map(|slot| U256::from_be_bytes(slot.0)).collect(),
)
})
}
/// Calculates a heuristic for the in-memory size of the [AccessList].

View File

@@ -31,8 +31,8 @@ impl AccessListInspector {
excluded: [from, to].iter().chain(precompiles.iter()).copied().collect(),
access_list: access_list
.0
.iter()
.map(|v| (v.address, v.storage_keys.iter().copied().collect()))
.into_iter()
.map(|v| (v.address, v.storage_keys.into_iter().collect()))
.collect(),
}
}

View File

@@ -340,7 +340,7 @@ where
pub(crate) async fn create_access_list_at(
&self,
request: CallRequest,
mut request: CallRequest,
at: Option<BlockId>,
) -> EthResult<AccessList> {
let block_id = at.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
@@ -373,7 +373,8 @@ where
get_contract_address(from, nonce).into()
};
let initial = request.access_list.clone().unwrap_or_default();
// can consume the list since we're not using the request anymore
let initial = request.access_list.take().unwrap_or_default();
let precompiles = get_precompiles(&env.cfg.spec_id);
let mut inspector = AccessListInspector::new(initial, from, to, precompiles);