Repository navigation
Block changes and incremental state root - #28
Merged
Merged
Conversation
While a `Block` runs, each transaction, system call and the withdrawals that commit add to `BlockChanges` what each account field and slot they changed held before the block, the block's first change of a value keeping it, and `begin` adds the BLOCKHASH entries it writes. One pass over the journal before `settle` feeds both the changes and the access list; for a touched account that settlement deletes, it keeps the account and its slots. A run whose changes cannot grow is undone and fails as a host failure.
`BlockChanges::undo` puts the world back as it was before `begin`: slots first, then each account's existence, balance, nonce and code, then the BLOCKHASH entries. `abandon` undoes the block, and so does a `finish` that fails; a host can undo a finished block with its output's changes.
`Chain::import` no longer clones the world before each block. A block that faults is abandoned, `finish` undoes one that fails, and a finished block whose output or roots do not match its header, or whose roots cannot be computed, is undone from its changes.
The fixture fails the growth of a block's changes past 16 accounts. The transfer that needed it fails as a host failure and is undone, and abandoning the block undoes the transfers before it.
A Merkle-Patricia trie of the state held in arenas, with each node's reference in its parent cached. Rereading a changed account or slot from the world updates its leaf and marks its path stale, and the root rehashes only stale nodes. Tested against `state_root` and fixture roots.
`Chain` builds the trie of its world once and, after `finish`, rereads the accounts and slots of the block's changes before taking the root. A block rejected after `finish` is undone and its keys reread, so the trie is the head's again. A trie an allocation failed is rebuilt from the world when the chain next needs it, before a block runs; the driver's genesis check takes the chain's root.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chain::importcloned the world to undo an invalid block and computed the state root from the whole world, so each block cost time in proportion to the state. Both now cost in proportion to what the block changed.BlockChanges: what a block changed, with what each value held before it: each account's existence, balance, nonce and code, each storage slot, and the BLOCKHASH entriesbeginwrote. It is derived when a transaction, a system call or the withdrawals commit, in the journal traversal that also feeds the access list; nothing is tracked per write.Block::finishgives it inBlockOutput, andundo(world)puts the world back.Block::abandonand a failingfinishundo the block.StateTrie: the state trie kept in memory with each node's hash.reread_accountandreread_slotreread one key from the world, androotrehashes only the changed paths. The trie depends only on what it holds, so restoring the world and rereading the same keys undoes a block.Chainholds aStateTrie, rereads a block's changes into it, and for a rejected block undoes the world and the trie.state_root(world)stays as the one-pass function.Notes for review:
Block.Chainrebuilds it from the world before the next block.