compute_block_trie_updates

Function compute_block_trie_updates 

Source
pub fn compute_block_trie_updates<Provider>(
    cache: &ChangesetCache,
    provider: &Provider,
    block_number: u64,
) -> Result<TrieUpdatesSorted, ProviderError>
Available on crate features trie and trie-db only.
Expand description

Computes block trie updates using the changeset cache.

§Algorithm

For block N:

  1. Get cumulative trie reverts from block N+1 to db tip using the cache
  2. Create an overlay cursor factory with these reverts (representing trie state after block N)
  3. Walk through account trie changesets for block N
  4. For each changed path, look up the current value using the overlay cursor
  5. Walk through storage trie changesets for block N
  6. For each changed path, look up the current value using the overlay cursor
  7. Return the collected trie updates

§Arguments

  • cache - Handle to the changeset cache for retrieving trie reverts
  • provider - Database provider for accessing changesets and block data
  • block_number - Block number to compute trie updates for

§Returns

Trie updates representing the state of trie nodes after the block was processed

§Errors

Returns error if:

  • Block number exceeds database tip
  • Database access fails
  • Cache retrieval fails