refactor: DB snapshot copy specs into descriptors#7375
refactor: DB snapshot copy specs into descriptors#7375francesco-stacks wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors snapshot DB copying so each snapshot DB defines a DbSnapshotSpec descriptor that owns its static table-copy specs (including schema-only tables) and any runtime bind requirements, making the copy-spec list the single source of truth for table classification and copy behavior.
Changes:
- Introduces descriptor-driven snapshot specs (
DbSnapshotSpec) plusTableCopySpec/TableCopySource/TableCopyBindandTableCopySpecshelpers to centralize table sets and runtime bind handling. - Refactors SPV, sortition, index, burnchain, and Nakamoto staging snapshot copy code to use static SQL templates with
?Nbinds instead of runtime-formatted SQL strings. - Moves snapshot-only helper reads out of DB impls into snapshot-scoped extension traits and updates snapshot drift/guard tests accordingly.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| stackslib/src/chainstate/stacks/db/snapshot/tests/spv.rs | Updates SPV copy-spec well-formedness guard to use TableCopySpecs and schema-only assertions. |
| stackslib/src/chainstate/stacks/db/snapshot/tests/sortition.rs | Updates sortition copy-spec guards and adds boundary invariance tests for spec table sets/ordering. |
| stackslib/src/chainstate/stacks/db/snapshot/tests/index.rs | Simplifies index copy-spec guard to focus on duplicate detection with descriptor-derived tables. |
| stackslib/src/chainstate/stacks/db/snapshot/tests/burnchain.rs | Updates burnchain copy-spec guard to use TableCopySpecs and clarifies schema-only overrides. |
| stackslib/src/chainstate/stacks/db/snapshot/tests/blocks.rs | Updates Nakamoto staging copy-spec guard to use TableCopySpecs and schema-only assertions. |
| stackslib/src/chainstate/stacks/db/snapshot/spv.rs | Introduces SpvDbSnapshotSpec, converts SPV specs to static templates with explicit bind kinds. |
| stackslib/src/chainstate/stacks/db/snapshot/sortition.rs | Introduces SortitionDbSnapshotSpec, adds snapshot extension trait reads, and refactors boundary-sensitive memo SQL to static templates with binds. |
| stackslib/src/chainstate/stacks/db/snapshot/index.rs | Introduces IndexDbSnapshotSpec, makes schema-only tables explicit in specs, and refactors reward-cycle filtering to use binds. |
| stackslib/src/chainstate/stacks/db/snapshot/common.rs | Adds TableCopySource/TableCopyBind/TableCopySpecs and DbSnapshotSpec; updates copy execution to support runtime binds. |
| stackslib/src/chainstate/stacks/db/snapshot/burnchain.rs | Introduces BurnchainDbSnapshotSpec, moves snapshot-only reads into extension traits, and makes overrides schema-only via specs. |
| stackslib/src/chainstate/stacks/db/snapshot/blocks.rs | Introduces NakamotoStagingDbSnapshotSpec and refactors staging/microblock copy-spec definitions to static slices. |
| stackslib/src/chainstate/burn/db/sortdb.rs | Removes snapshot-only helper methods from SortitionDB impl (moved to snapshot extension traits). |
| stackslib/src/burnchains/db.rs | Removes snapshot-only helper from BurnchainDB impl (moved to snapshot extension traits). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// keeps the dst complete and drift-guarded without copying rows. | ||
| pub(super) const SCHEMA_ONLY_TABLES: &[&str] = &["overrides"]; | ||
| fn classify_hint() -> &'static str { | ||
| "burnchain_copy_specs() in snapshot/burnchain.rs" |
There was a problem hiding this comment.
nit: here and others classify_hint to avoid this string becoming stale, we could derive it from the function itself instead of hardcoding it:
macro_rules! classify_hint {
($f:path) => {{
// Forces `$f` to resolve to a real value (fn item). Wrong name fails at compile time.
const _: () = { let _ = $f; };
concat!(stringify!($f), "() in ", file!())
}};
}
fn classify_hint() -> &'static str {
fn_hint!(burnchain_copy_specs)
}However, I haven't a strong opinion on this. I'm also fine to keep it as-is.
Description
This PR refactors the DB snapshot copy logic so each snapshot DB owns a
DbSnapshotSpecdescriptor. Copy specs now act as the single source of truth for row-copied tables, schema-only tables, table classification, and runtime SQL bind requirements.TableCopySource,TableCopySpecs,TableCopyBind, and per-DBDbSnapshotSpecimplementations.The change was motivated by these suggestions:
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