A state root on a parent that is not on disk yet
TL;DR
When blocks are written in the background, the next block often arrives before its parent is on disk. This post shows how such a block computes its state root, and why the obvious method was slow.
2026-10-07. Measured on the desktop against reth 2.0, before testing moved to a dedicated server. The numbers are kept as they were measured.
Every Ethereum block names a state root: the hash of the whole state after the block, as a Merkle Patricia trie. An execution client must compute the same root, or the block is invalid. In Cinder, the root is usually the second-largest cost of a block after execution.
In an earlier post we moved block writes to a background thread. That fixed the backlog, but it created a new case. A block now often arrives before its parent is written to the database. We call such a parent “unwritten”: it is valid and executed, but it is only in memory. This post is about how such a block computes its root, and why the obvious method was slow.
Two ways to compute a root
On the database head. The parent is the newest block in the database. The database holds the parent’s trie, so the block opens the account trie at the parent’s root, applies its own changes, and hashes only the paths it touched.
On an unwritten parent: the replay path. The parent is only in memory, as a diff: the accounts and slots it changed. The database still holds the grandparent’s trie, or an older one. The first version did this:
- Open a fresh state over the database.
- Apply the diff of every unwritten ancestor again, oldest first.
- Update the tries for the changes of all of them, then for the block itself.
- Hash everything that changed.
The work grows with every unwritten ancestor. One ancestor added 15 to 19 ms of root: the root mean went from 40.0 to 58.9 ms. At the head, the root took 54 ms against 27 ms on the database head. When the node was behind, each block replayed up to four ancestors, and catching up ran at 197 blocks in 10 minutes. The chain makes 50 in that time, so a long stop took hours to recover.
The idea: a hash names exactly one node
A trie node that is 32 bytes or longer is referenced by its keccak hash. The parent’s trie is the grandparent’s trie plus the nodes that the parent changed. The parent already computed those nodes when it computed its own root. We only threw them away.
So now each block keeps them:
- After a block’s root is computed, the trie code lists every node that the block changed, in the account trie and in every storage trie: its hash, its encoding, and which of its children are stored nodes.
- The block keeps them in its own small hash table (open addressing on the hash) until the block is written or dropped.
A database view gets an optional overlay: when a trie read asks for a node by hash, the view asks the ancestors’ tables first, newest first, then the cache, then the database. The overlay never needs an invalidation rule. A hash names exactly one node, so a node from the overlay is always the node that the parent expects.
With the overlay, a block on an unwritten parent takes the same path as a block on the database head. It opens the account trie at the parent’s root, reads the parent’s new nodes from memory and the older ones from disk, and hashes only its own changes.
The safety net
The direct path is only taken when every unwritten ancestor has its node table. A block that comes from an undo record (a fork below the database head) has none, so that case keeps the replay path.
If the direct path fails anyway, for example a node is in none of the three places, the root is computed again on the replay path and the event is counted. A valid block is never rejected because of the overlay. In the live runs, the count of fallbacks was 0.
Testing a path that the tests rarely take
The Ethereum test fixtures are short chains, and most of their blocks run on the database head. To make every fixture use the new path, the Engine API runner keeps two blocks unwritten by default. Then almost every block executes on an unwritten parent, and its root is checked against the fixture’s expected root. Osaka and Prague, with and without the background writer, all pass. On one subset, 142 roots took the direct path, 0 took the replay path, and 0 fell back.
Results
The limit of unwritten blocks is the number of executed blocks that may wait in memory for the writer. When the limit is reached, the node waits for the writer before it takes the next block.
Catching up over the network for 10 minutes, blocks written:
| blocks in 10 minutes | |
|---|---|
| replay path, limit of 4 unwritten blocks | 197 |
| direct path, limit of 4 | 352 |
| direct path, limit of 16 | 368 |
The direct path wrote 1.8 times more blocks in 10 minutes at the same limit.
| Row | replay path (before) | direct path (now) |
|---|---|---|
| Limit of 1 unwritten block | 14 blocks | not measured |
| Limit of 4 unwritten blocks (the limit we keep) | 197 blocks | 352 blocks |
| Limit of 16 unwritten blocks (the replay count is approximate) | 120 blocks | 368 blocks |
That is 1.8 times faster. A higher limit gave almost nothing more, so the limit stays at 4, which uses less memory. On the replay path, both ends were slow. At a limit of 1, each commit held one or two blocks. At a limit of 16, each block replayed up to 16 ancestors for its root.
At the head, the root on an unwritten parent dropped from 54 ms to 33 ms. The 30-minute window against reth went from 1.15 to 1.11 times reth’s mean latency. The blocks on an unwritten parent were still slower, but now mostly in execution, not in the root: they run while the writer writes, on the same disk. That is the next problem, and an earlier post explains why our first three attempts to measure it were wrong.
What we take from it
- Before you cache something, check whether you already compute it and throw it away. The parent’s new trie nodes were free.
- Content-addressed data makes caches simple. A table keyed by hash needs no invalidation, because a hash can only ever mean one thing.
- Give the fast path a slow path behind it, and count every fallback.
- Bend the test runner so that the shared test suite exercises your new path, instead of hoping that it does.
Updated 2026-10-23: the 197 blocks in 10 minutes here ran on the replay path with a limit of 4 unwritten blocks. The write post gives 380 blocks in about 12 minutes for the writer alone, with batches of up to 16 blocks and no limit of 4. The setups are different, so the two rates do not show a slowdown. The roots of 27 to 58.9 ms in this post are desktop results with reth 2.0. The dedicated server, with the later root changes, gives much shorter roots.