-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(trie): deduplicate already fetched prefetch targets #14223
Conversation
6dc3915
to
9c63e0c
Compare
crates/engine/tree/src/tree/root.rs
Outdated
targets.retain(|hashed_address, target_storage| { | ||
self.fetched_proof_targets | ||
.get(hashed_address) | ||
.is_none_or(|fetched_storage| fetched_storage == target_storage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
am I reading this wrong, or it will leave in targets
only either accounts that do not exist in self.fetched_proof_targets
, or accounts with storages that are equal to self.fetched_proof_targets
?
Think it should be
.is_none_or(|fetched_storage| fetched_storage == target_storage) | |
.is_none_or(|fetched_storage| fetched_storage != target_storage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe rather it should be checking for target_storage
being a subset of fetched_storage
, and then removing it if so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think checking if it's a subset and removing makes more sense here
crates/engine/tree/src/tree/root.rs
Outdated
// if both storages are empty, then we can skip this account altogether | ||
if target_storage.is_empty() && fetched_storage.is_empty() { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsure about this
if the account exists in both targets
and self.fetched_proof_targets
, but has no associated storage slots in either, we should remove this account from targets
, because it was already fetched
let prev_target_storage_len = target_storage.len(); | ||
|
||
// keep only the storage slots that have not been fetched yet | ||
target_storage.retain(|slot| !fetched_storage.contains(slot)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may result in an empty target_storage
, and then we will need to remove the entry from the targets
map completely to prevent fetching the account proof
Left some comments about logic, I think basically it should be very similar to reth/crates/engine/tree/src/tree/root.rs Lines 855 to 886 in a63f92e
|
5f32dac
to
abe946e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, that looks correct, but would be nice to have some sanity tests
Co-authored-by: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com>
46c6ae3
to
68c3e89
Compare
added some sanity tests |
This prevents fetching proofs that have already been fetched by state updates or other proof fetches. Previously we would only extend
self.fetched_proof_targets
, without checking it or modifying for prefetch calls.