Skip to content

Conversation

avorylli
Copy link
Contributor

@avorylli avorylli commented Oct 5, 2025

Summary

Replaces separate HashSet collections with unified Vec<(B256, Option<...>)> pattern in HashedPostStateCursors for improved efficiency.

Changes

  • HashedAccountsSorted: accounts: Vec<(B256, Option<Account>)> where None indicates destroyed account
  • HashedStorageSorted: storage_slots: Vec<(B256, U256)> where U256::ZERO indicates deleted slot
  • Cursors: Updated HashedPostStateAccountCursor and HashedPostStateStorageCursor logic
  • Removed: destroyed_accounts: B256Set and zero_valued_slots: B256Set

Closes: #18848

Copy link
Collaborator

@mediocregopher mediocregopher left a 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 {
Copy link
Collaborator

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() {
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove this method

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Oct 6, 2025
@mediocregopher mediocregopher marked this pull request as draft October 6, 2025 09:07
Copy link

codspeed-hq bot commented Oct 8, 2025

CodSpeed Performance Report

Merging #18868 will not alter performance

Comparing avorylli:18848 (c2a0417) with main (d2070f4)

Summary

✅ 77 untouched

@avorylli
Copy link
Contributor Author

avorylli commented Oct 9, 2025

@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

@avorylli avorylli closed this Oct 9, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Oct 9, 2025
@avorylli avorylli reopened this Oct 9, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in Reth Tracker Oct 9, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Use Vec<(B256, Option<...>)> in HashedPostStateCursors

2 participants