-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor(trie): use Vec<(B256, Option<...>)> in HashedPostStateCursors #18868
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
Conversation
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.
@avorylli This PR is unfortunately not complete, the compare_entries
function is not sufficient to merge the in-memory overlay with the DB trie cursor as it does not take into account deleted nodes at all. Please also ensure that CI is passing before marking a PR as ready for review.
Additionally, please make sure you are assigned to an issue before attempting a PR for it, so we don't duplicate work. @quantix9 has said they will be working on an implementation for this, there's no point having competing ones.
} | ||
|
||
/// Converts hashed post state into [`HashedPostStateSorted`]. | ||
pub fn into_sorted(self) -> HashedPostStateSorted { |
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.
You can use drain_into_sorted
internally here and deduplicate the implementation. See the TrieUpdates
method.
let mut updated_accounts = Vec::new(); | ||
let mut destroyed_accounts = HashSet::default(); | ||
let mut accounts = Vec::new(); | ||
for (hashed_address, info) in self.accounts.drain() { |
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 for loop could just be let mut accounts = self.accounts.drain().collect::<Vec<_>>()
instead.
let mut non_zero_valued_slots = Vec::new(); | ||
let mut zero_valued_slots = HashSet::default(); | ||
let mut storage_slots = Vec::new(); | ||
for (hashed_slot, value) in self.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.
This for loop could just be let mut storage_slots = self.storage.into_iter().collect::<Vec<_>>()
instead.
/// | ||
/// This function only checks the post state, not the database, because the latter does not | ||
/// store destroyed accounts. | ||
fn is_account_cleared(&self, account: &B256) -> bool { |
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.
just remove this method
|
||
/// Check if the slot was zeroed out in the post state. | ||
/// The database is not checked since it already has no zero-valued slots. | ||
fn is_slot_zero_valued(&self, slot: &B256) -> bool { |
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.
Just remove this method
CodSpeed Performance ReportMerging #18868 will not alter performanceComparing Summary
|
@mediocregopher I completely dont know how to solve these tests, wasted half a day to solve it, feel free to close this pr, and sorry for wasting your time |
Summary
Replaces separate
HashSet
collections with unifiedVec<(B256, Option<...>)>
pattern inHashedPostStateCursors
for improved efficiency.Changes
accounts: Vec<(B256, Option<Account>)>
whereNone
indicates destroyed accountstorage_slots: Vec<(B256, U256)>
whereU256::ZERO
indicates deleted slotHashedPostStateAccountCursor
andHashedPostStateStorageCursor
logicdestroyed_accounts: B256Set
andzero_valued_slots: B256Set
Closes: #18848