Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: more caching friendly with sorted storage keys #27

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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