Cache recent roots to prevent trie wipe on out-of-order commits#2055
Draft
Chen-Yifan wants to merge 2 commits intomainfrom
Draft
Cache recent roots to prevent trie wipe on out-of-order commits#2055Chen-Yifan wants to merge 2 commits intomainfrom
Chen-Yifan wants to merge 2 commits intomainfrom
Conversation
f22a37f to
af278a4
Compare
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent MPT “trie wipe” behavior during out-of-order commits by keeping recent trie roots alive and avoiding destructive child-pointer transfers when traversing/copying tries.
Changes:
- Replace several
move_next(...)calls withnext(...)in MPT update/expire/compact flows to avoid mutating existing nodes while traversing. - Add a small fixed-size ring buffer to cache recent trie roots in
TrieDb(on-disk mode) and route root loads through it. - Add unit tests covering
RootRingBufferbehavior (sequential insert, eviction, gaps, wraparound).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| category/mpt/trie.cpp | Switch child access from destructive moves to non-destructive reads in several recursion paths. |
| category/mpt/copy_trie.cpp | Avoid moving child pointers when constructing nodes during trie copy. |
| category/execution/ethereum/db/trie_db.hpp | Introduce RootRingBuffer template and add root_cache_ to TrieDb. |
| category/execution/ethereum/db/trie_db.cpp | Add load_root() helper and insert committed/finalized roots into the cache. |
| category/execution/ethereum/db/test/test_root_ring_buffer.cpp | Add tests validating ring-buffer caching semantics. |
Comments suppressed due to low confidence (2)
category/execution/ethereum/db/trie_db.hpp:40
RootRingBufferusesMONAD_ASSERTbut this header doesn’t include the header that defines it. This makestrie_db.hppnon-self-contained and can break compilation for translation units that include it directly (e.g. the new unit test). Include the appropriate assert header (or avoid the macro in this header).
#include <nlohmann/json.hpp>
#include <array>
#include <deque>
#include <istream>
#include <memory>
#include <optional>
category/mpt/trie.cpp:368
- In the single-child coalescing path, switching from
move_next()tonext()meanssingle_childremains referenced byorig. But the subsequentmake_node(*single_child, ...)call moves child pointers out ofsingle_child(seemake_node(Node& from, ...)), which will mutate the cached trie node thatorigstill points to and can effectively “wipe” cached children. This path likely still needs to transfer ownership (keepmove_next()here) or use a non-destructive clone that copies child pointers instead of moving them.
if (number_of_children == 1 && !orig->has_value()) {
auto const child_branch = static_cast<uint8_t>(std::countr_zero(mask));
auto const child_index = orig->to_child_index(child_branch);
auto single_child = orig->next(child_index);
if (!single_child) {
node_receiver_t recv{
[aux = &aux,
sm = sm.clone(),
tnode = std::move(tnode),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bf873d6 to
e88c238
Compare
block versions in on-disk mode. This prevents wiping the in-memory trie when loading roots for out-of-order commits, avoiding expensive trie reconstruction from disk. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
e88c238 to
6b47488
Compare
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.
There's a 10% performance regression introduced by the first commit.