The write that our latency windows did not show
TL;DR
Cinder answered engine_newPayload in 97 ms on average and still fell 400 blocks behind. This post is about the work that the latency number did not count, and how it moved out of the way.
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.
For a while we compared Cinder with reth on one number: how long
engine_newPayload takes, the call in which the consensus client hands
the execution client a new block. In one 30-minute window Cinder
took 97 ms on average and reth
took 215 ms. It looked like a clear win.
In the same window Cinder answered 83 calls. Reth answered 149. Cinder was 400 blocks (80 minutes) behind the chain, and the gap grew. This post is about the work that our latency number did not count, and about how we moved it out of the way.
Where the time went
After Cinder answered a forkchoice update (the call in which the consensus client names the new head), its engine loop wrote every finished block to the database (MDBX), one block per transaction:
- the undo record of the block (the reverse diff, so that a reorg can step back: a reorg is a change of the head to another branch of the chain),
- a second state root over the database, to check what goes to disk,
- a durable commit: a write that waits until the data is safe on the disk.
The answer to newPayload came before this work, so our latency number
did not include it. But the next request waited behind the write.
| write after the answer: mean / median / p90 | |
|---|---|
| 11 runs of the node | 4.2 to 6.6 s / 1.4 to 7.6 s / 10.5 to 13.2 s |
The p90 is the time that 90% of the writes stayed under.
In the slowest runs, one write in ten took longer than the 12 seconds between two blocks.
| Row | lowest of the 11 runs | highest of the 11 runs |
|---|---|---|
| Mean | 4.2 s | 6.6 s |
| Median | 1.4 s | 7.6 s |
| p90 | 10.5 s | 13.2 s |
A block arrives every 12 seconds. The median write fits. The p90 does not. A node that sometimes needs 13.2 seconds for 12 seconds of chain cannot catch up.
Why so slow? One minute of /proc/<pid>/io
showed 841 MB written for 12
blocks: about 70 MB per block, for a few
hundred kilobytes of state change. MDBX is a copy-on-write B-tree. Each
commit copies every page it touches and every branch page above it, then
syncs. A block touches pages all over the state, so each commit rewrites a
large part of the tree’s upper levels.
The design: a writer thread with batches
Reth writes in the background, in batches. We did the same.
- A writer thread takes the blocks that are due for the database (canonical, and deeper than the configured depth or at or below the finalized block). It writes them in one transaction: the undo records of each block, one root replay for the whole batch, one durable commit.
- The engine loop only hands blocks over and publishes finished batches between requests. A block write never delays an answer.
- When the node is behind, blocks wait while the writer is busy, so the next batch is larger. Batches grow exactly when they help most.
The hard part is not the thread. It is everything that reads the database while the writer changes it.
One snapshot per view
A block executes on many threads at once: execution, prewarming, trie prefetch, sender recovery. Each thread reads the database through its own read transaction. Before the writer, nothing committed while a block executed, so all those transactions saw the same snapshot. With the writer, a commit can land between the first thread’s read and the last one’s.
So a view now opens all its read transactions at once and retries until they share one transaction ID. Cost: 13.8 µs per block view of 72 transactions, against 0.6 µs before.
The cache must not run ahead of the snapshot
Cinder keeps a cross-block cache of accounts and storage. The first version updated it when the writer committed. A block that was still executing on the old snapshot then read an account’s new storage root from the cache and tried to open a storage trie that its snapshot did not contain: a trie node hash mismatch. The EEST suite found it. Now the writer hands its cache updates back, and the engine thread applies them when it publishes the batch. At that moment no block is executing.
Byte-for-byte the same database
A batch must give the same database as one commit per block. A test runner option writes every test both ways and compares all 13 tables entry by entry. The tests found one real bug here. Suppose one block in a batch sets a contract’s code and a later block in the same batch replaces it, as EIP-7702 delegations do. A batch that wrote only the final state lost the first code. Now each block’s code goes into the batch.
Results
| one commit per block on the engine loop | writer thread | |
|---|---|---|
| wait of the next request behind a write | 0.4 to 14 s | 4 ms mean, 7 ms p90 (2026-10-02, 150 blocks) |
| catching up after a stop | fell 400 blocks behind | 380 blocks in about 12 minutes (2026-10-02, the writer alone, batches up to 16 blocks) |
INVALID answers |
0 | 0 |
The reorg we did not test
Soon after the writer went live, mainnet block 26109905 came in two versions: a one-block reorg. The first version became the head and went to the writer. The writer was still busy with the previous batch (the first write after a restart is cold and took 60 seconds). The second version arrived, executed as valid on the same parent, and the consensus client switched the head to it.
When the batch was published, the writer had written the first version. The branch of the second version no longer connected to the database head, so the node dropped it as dead. From then on, every payload was SYNCING: the answer that tells the consensus client that the node cannot judge the block yet. The node stood on that block for two days. It never answered INVALID, so nothing looked wrong in the error counts.
Our review had covered a fork that arrives during a write. It had not covered a forkchoice switch to a sibling that executed before the handover.
The fix has two parts:
- A forkchoice update to a head that is not on the batch in flight waits for the writer first.
- Executed blocks keep their raw RLP until they are written. If the writer writes the other branch, a valid block that died under it goes back to “pending”. A later forkchoice update to it unwinds the database to the fork base, as if the sibling had arrived after the write.
The test for it is deterministic: a helper thread holds MDBX’s write lock, so the writer stops at exactly the two moments that matter. The test failed before the fix and passes after it. We recovered the live node without a resync: we replayed the second version from its slot, which made it pending, and the next forkchoice update unwound the first.
What came next
The writer made the node keep up, but it moved a cost. A block now often arrives before its parent is written, and such a block had to replay its unwritten ancestors to compute its state root: +15 to 19 ms. The next step was to keep each block’s changed trie nodes in memory, so that a block on an unwritten parent computes its root like a block on the database head. That made catching up 1.8 times faster (352 blocks in 10 minutes against 197). It is the subject of another post.
What we take from it
- Measure the whole loop, not the answer. A latency number that stops at the response can hide a growing backlog.
- Count the answers in a window, not only their speed. 83 against 149 said more than 97 ms against 215 ms.
- Every new thread that writes needs an answer to “what do the readers see, and when”. For us: one snapshot per view, and cache updates at publish time.
- To test a race, stop the thread at the exact moment with a held lock. Sleeps only make the race less likely.
Updated 2026-10-23: the writer wait of 4 ms mean (7 ms p90) is from 150 blocks on 2026-10-02. A later desktop window on 2026-10-05 gave 5 ms mean (7 ms p90), and other posts use that run. The 380 blocks in about 12 minutes ran with the writer alone and batches of up to 16 blocks. The 197 blocks in 10 minutes of the state-root post ran with a limit of 4 unwritten blocks and the replay path. The setups are different, so the two rates do not show a slowdown.