feat: common "snapshotting" code to copy canonical side-table data + index copy#7254
Open
francesco-stacks wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a new snapshot module under chainstate::stacks::db that provides shared SQL utilities and a canonical-only copy of the chainstate index side-tables into a squashed output directory. This is the first slice of a series; validation and remaining DBs (SPV, sortition, burnchain, staging blocks) will follow.
Changes:
- Adds shared offline-copy framework in
snapshot/common.rs(strict schema cloning from an attachedsrc, offline write session with aggressive pragmas + ATTACH via percent-encodedfile:URI, index drop/recreate around bulk inserts, drift-guard helpers). - Adds MARF-aware
snapshot/fork_storage.rsthat walks the squashed trie to collect canonical leafvalue_hashes and stream-filterssrc.__fork_storage. - Adds
snapshot/index.rsthat copies canonical-only rows of index side-tables (filtered bymarf_squashed_blocks), with a customsigner_statscutoff derived from the canonical tip's reward cycle, and a drift-guard test ensuring future migrations can't silently drop tables.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| stackslib/src/chainstate/stacks/db/mod.rs | Registers the new snapshot submodule. |
| stackslib/src/chainstate/stacks/db/snapshot/mod.rs | Module wiring; re-exports copy_index_side_tables and IndexSideTableStats. |
| stackslib/src/chainstate/stacks/db/snapshot/common.rs | Shared SQL helpers: schema cloning, offline write session, index drop/recreate, drift-guard utilities. |
| stackslib/src/chainstate/stacks/db/snapshot/fork_storage.rs | MARF-aware collection of canonical leaf hashes and filtered __fork_storage copy. |
| stackslib/src/chainstate/stacks/db/snapshot/index.rs | Canonical-only copy of the chainstate index side-tables plus signer_stats cutoff logic. |
| stackslib/src/chainstate/stacks/db/snapshot/tests/mod.rs | Tests for the index copy, fork-storage filtering, staging blocks, and drift guard. |
| changelog.d/marf-snapshot-framework.added | Changelog fragment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
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
Add the
snapshotmodule for copying chainstate side-tables (canonical data only) into a squashed output directory. This slice contains the shared copy framework (schema cloning, canonical fork-storage filtering) and theindexside-table copy.Validation and the remaining DBs (SPV, sortition, burnchain, staging blocks) are intentionally left out and will land in follow-up PRs.
Summary
snapshot/common.rs: shared SQL utilities - schema cloning from the attached source, offline write sessions, drop/recreate of user indexes around bulk inserts, and path percent-encoding forATTACH.snapshot/fork_storage.rs: MARF-aware__fork_storagecopy - walk the squashed trie to collect the canonical leafvalue_hashset, then stream-filtersrc.__fork_storagedown to only those rows.snapshot/index.rs: copy canonical-only rows of the index side-tables, filtered by the squashed MARF'smarf_squashed_blocksmetadata;signer_statsis additionally filtered by the derived max reward cycle.staging_microblocks*,invalidated_microblocks_data,user_supporters) are schema-cloned but not populated.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