state root
Posts on the state root in Cinder: how the node calculates it for each block, and the changes that made it faster.
- A 10 ms wait that did its job and still lost: why we rejected itAt persist depth 0, the writer often computes a state root over its batch. The reason: the trie-node job of the newest block still runs at the hand-over. A bounded wait of at most 10 ms removed that fallback. About 1 100 batches per run went to about 19. But newPayload and the writer were slower in 4 of 5 rounds, and there was no gain. The interval over blocks said that the cost was certain. The A/A control said that this interval was too narrow. We rejected the change, and here is the data.
- An estimate of 3.9% and a result in the noise: why we rejected lazy branch decodeWe wanted to decode the 16 children of a trie branch only when a walk reaches them. A scratch build first estimated the possible gain at 3.9% of the block time. We built two versions and measured them on 1 074 mainnet blocks. The first was slower. The second was in the noise of the A/A control. The work memory went down by 13%, but the block time did not. This post shows the data behind the decision, and why the estimate was too high.
- A hash is not a node: trie references of 36 bytes instead of 208A profile of the state root found about 109 000 trie node objects per mainnet block for about 9 500 decoded nodes. Most of them were children that are only a hash, and each one got a full node of 208 bytes. We made a hash reference a node of 36 bytes. On 1 074 mainnet blocks, a block took 0.923 of the time before. The work memory of a block is 37% smaller, and every root is the same.
- One night of A/B tests: from 6 ms behind reth to fasterAn overnight queue of interleaved A/B tests on live mainnet kept three changes. They are a streaming state root, a core of its own for the executing thread, and memory kept between blocks. Together they took 8.7 ms off each block. On the same blocks, Cinder was faster than reth 2.7.
- A state root on a parent that is not on disk yetWhen blocks are written in the background, the next block often arrives before its parent is on disk. Keeping each block's new trie nodes in memory made catching up 1.8 times faster.