Skip to content

fix: marf squash boot from pruned#7224

Open
francesco-stacks wants to merge 7 commits into
stacks-network:developfrom
francesco-stacks:feat/marf-squash-boot-from-pruned
Open

fix: marf squash boot from pruned#7224
francesco-stacks wants to merge 7 commits into
stacks-network:developfrom
francesco-stacks:feat/marf-squash-boot-from-pruned

Conversation

@francesco-stacks
Copy link
Copy Markdown
Contributor

@francesco-stacks francesco-stacks commented May 21, 2026

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:

  • A squashed snapshot prunes historical MARF state, so get_coinbase_height and read_reward_set_nakamoto_of_cycle would fail for blocks/cycles below the boundary. This adds SQL side-table fallbacks: nakamoto_tenure_events for coinbase heights and nakamoto_reward_sets for reward sets.
  • Introduces SquashBoundary { marf_height, bitcoin_height } (schema v3->v4 migration adds the bitcoin_height column).

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

  • fixes #

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • For new Clarity features or consensus changes, add property tests (see docs/property-testing.md)
  • Changelog fragment(s) or "no changelog" label added (see changelog.d/README.md)
  • Required documentation changes (e.g., rpc/openapi.yaml for RPC endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@francesco-stacks francesco-stacks self-assigned this May 21, 2026
@francesco-stacks francesco-stacks marked this pull request as draft May 21, 2026 18:10
@francesco-stacks francesco-stacks changed the title Feat/marf squash boot from pruned feat: marf squash boot from pruned May 21, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented May 21, 2026

Coverage Report for CI Build 26646668756

Coverage increased (+0.05%) to 85.761%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 35 uncovered changes across 5 files (250 of 285 lines covered, 87.72%).
  • 6639 coverage regressions across 117 files.

Uncovered Changes

File Changed Covered %
stackslib/src/chainstate/nakamoto/coordinator/mod.rs 29 12 41.38%
stackslib/src/chainstate/stacks/index/trie_sql.rs 55 43 78.18%
stackslib/src/chainstate/nakamoto/mod.rs 91 87 95.6%
stackslib/src/chainstate/stacks/index/storage.rs 17 16 94.12%
stackslib/src/chainstate/stacks/index/test/squash.rs 68 67 98.53%
Total (8 files) 285 250 87.72%

Coverage Regressions

6639 previously-covered lines in 117 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/config/mod.rs 376 68.96%
stackslib/src/net/mod.rs 310 77.88%
stackslib/src/chainstate/stacks/index/storage.rs 280 82.45%
stackslib/src/chainstate/stacks/miner.rs 253 83.4%
clarity/src/vm/database/clarity_db.rs 244 82.23%
stackslib/src/chainstate/stacks/db/transactions.rs 222 97.16%
stackslib/src/net/inv/epoch2x.rs 220 79.55%
stackslib/src/net/chat.rs 201 93.01%
stackslib/src/chainstate/stacks/db/mod.rs 196 86.23%
stackslib/src/core/mempool.rs 193 86.44%

Coverage Stats

Coverage Status
Relevant Lines: 223652
Covered Lines: 191806
Line Coverage: 85.76%
Coverage Strength: 18869202.88 hits per line

💛 - Coveralls

@francesco-stacks francesco-stacks changed the title feat: marf squash boot from pruned fix: marf squash boot from pruned May 28, 2026
@francesco-stacks francesco-stacks requested a review from Copilot May 28, 2026 12:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 through squash_to_path, SquashInfo, SquashStats, and the marf_squash_info table (schema 4 adds bitcoin_height and renames squash_heightmarf_height).
  • Add SQL fallbacks get_coinbase_height_from_tenure_events (against nakamoto_tenure_events) and try_read_squashed_reward_set_of_cycle (against nakamoto_reward_sets), wired into get_coinbase_height and OnChainRewardSetProvider::read_reward_set_nakamoto_at_cycle, both gated by squash_boundary().is_some().
  • Expose squash_boundary() on the StacksDBIndexed trait/impls and on MARF/MarfTransaction; refactor reward-set validation into shared ensure_usable_nakamoto_reward_set; add focused regression tests in nakamoto/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_heightmarf_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.

@francesco-stacks francesco-stacks marked this pull request as ready for review May 29, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants