fix: marf squash boot from pruned#7224
Open
francesco-stacks wants to merge 7 commits into
Open
Conversation
Coverage Report for CI Build 26646668756Coverage increased (+0.05%) to 85.761%Details
Uncovered Changes
Coverage Regressions6639 previously-covered lines in 117 files lost coverage.
Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
Pull request overview
Fixes the squashed-MARF boot path so a node booted from a snapshot whose historical MARF state is pruned can still resolve get_coinbase_height and read_reward_set_nakamoto_of_cycle via SQL side-tables. The PR adds a richer squash boundary (MARF height + Bitcoin height), a schema v3→v4 migration, and gated SQL fallbacks invoked only when the storage is squashed.
Changes:
- Introduce
SquashBoundary { marf_height, bitcoin_height }, threaded throughsquash_to_path,SquashInfo,SquashStats, and themarf_squash_infotable (schema 4 addsbitcoin_heightand renamessquash_height→marf_height). - Add SQL fallbacks
get_coinbase_height_from_tenure_events(againstnakamoto_tenure_events) andtry_read_squashed_reward_set_of_cycle(againstnakamoto_reward_sets), wired intoget_coinbase_heightandOnChainRewardSetProvider::read_reward_set_nakamoto_at_cycle, both gated bysquash_boundary().is_some(). - Expose
squash_boundary()on theStacksDBIndexedtrait/impls and onMARF/MarfTransaction; refactor reward-set validation into sharedensure_usable_nakamoto_reward_set; add focused regression tests innakamoto/tests/mod.rs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| stackslib/src/chainstate/stacks/index/storage.rs | Introduces SquashBoundary, updates SquashInfo, replaces squash_height() with squash_boundary()/squash_marf_height(). |
| stackslib/src/chainstate/stacks/index/trie_sql.rs | Schema 4 migration, SqlSquashInfo struct, updated read_/write_squash_info to round-trip the boundary; stricter handling when squash_root_node_hash is NULL. |
| stackslib/src/chainstate/stacks/index/trie.rs | Renames call site to squash_marf_height(). |
| stackslib/src/chainstate/stacks/index/squash.rs | Threads SquashBoundary through squash_to_path/persist metadata; renames squash_height→marf_height in stats; documents squash preconditions. |
| stackslib/src/chainstate/stacks/index/marf.rs | Adds squash_boundary() on MARF/MarfTransaction; renames call site. |
| stackslib/src/chainstate/stacks/index/test/squash.rs | Updates all squash test sites to the new SquashBoundary API and SqlSquashInfo struct. |
| stackslib/src/chainstate/nakamoto/mod.rs | Adds squash_boundary() to StacksDBIndexed and impls; adds SQL fallbacks for coinbase height and reward set lookups gated on a squash boundary. |
| stackslib/src/chainstate/nakamoto/coordinator/mod.rs | Wires the reward-set SQL fallback into read_reward_set_nakamoto_at_cycle; extracts shared ensure_usable_nakamoto_reward_set. |
| stackslib/src/chainstate/nakamoto/tests/mod.rs | New tests covering tenure-events coinbase height resolution, reward-set SQL behavior (match, boundary exclusion, equal/distinct duplicates, gate above boundary), and end-to-end gating in get_coinbase_height. |
| changelog.d/marf-squash-boot-from-pruned.added | Changelog entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
Builds on top of #7060
In #7060 we introduced guards for MARF lookups that goes in the squashed range. In my first version, I didn't put them in place. This allowed the node to still query certain values (coinbase height, reward set, etc) used during normal operations. Now though, it's not working anymore! So the fixes below:
get_coinbase_heightandread_reward_set_nakamoto_of_cyclewould fail for blocks/cycles below the boundary. This adds SQL side-table fallbacks:nakamoto_tenure_eventsfor coinbase heights andnakamoto_reward_setsfor reward sets.SquashBoundary { marf_height, bitcoin_height }(schema v3->v4 migration adds thebitcoin_heightcolumn).Note that an alternative approach (that could have taken less code..) would have been to loose a bit the squash guards to still allow whitelisted keys to be queried in the squash range. Eventually I left that direction because I couldn't perfectly evaluate if it could cause some side effect, maybe reading wrong values in unknown cases...
Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/property-testing.md)changelog.d/README.md)rpc/openapi.yamlfor RPC endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepo