Skip to content

Commit

Permalink
perf: more caching friendly with sorted storage keys (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Aug 23, 2024
1 parent 9a5d46f commit 378ccee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/executor/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::marker::PhantomData;
use alloy_provider::Provider;
use alloy_transport::Transport;
use eyre::{eyre, Ok};
use itertools::Itertools;
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{proofs, Block, Bloom, Receipts, B256};
use revm::db::CacheDB;
Expand Down Expand Up @@ -121,10 +122,11 @@ impl<T: Transport + Clone, P: Provider<T> + Clone> HostExecutor<T, P> {
);

// For every account we touched, fetch the storage proofs for all the slots we touched.
tracing::info!("fetching modified storage proofs");
let mut dirty_storage_proofs = Vec::new();
for (address, account) in executor_outcome.bundle_accounts_iter() {
let mut storage_keys = Vec::new();
for key in account.storage.keys() {
for key in account.storage.keys().sorted() {
let slot = B256::new(key.to_be_bytes());
storage_keys.push(slot);
}
Expand Down
3 changes: 2 additions & 1 deletion crates/storage/rpc-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ impl<T: Transport + Clone, P: Provider<T> + Clone> RpcDb<T, P> {
.into_iter()
.map(|address| {
// Get all of the storage keys for the address.
let storage_keys_for_address: Vec<B256> = storage
let mut storage_keys_for_address: Vec<B256> = storage
.get(&address)
.map(|storage_map| storage_map.keys().map(|k| (*k).into()).collect())
.unwrap_or_default();
storage_keys_for_address.sort();

// Fetch the proof for the address + storage keys.
async move {
Expand Down

0 comments on commit 378ccee

Please sign in to comment.