Skip to content

refactor: DB snapshot copy specs into descriptors#7375

Open
francesco-stacks wants to merge 7 commits into
stacks-network:developfrom
francesco-stacks:feat/marf-snapshot-copy-spec-refactor
Open

refactor: DB snapshot copy specs into descriptors#7375
francesco-stacks wants to merge 7 commits into
stacks-network:developfrom
francesco-stacks:feat/marf-snapshot-copy-spec-refactor

Conversation

@francesco-stacks

Copy link
Copy Markdown
Contributor

Description

This PR refactors the DB snapshot copy logic so each snapshot DB owns a DbSnapshotSpec descriptor. Copy specs now act as the single source of truth for row-copied tables, schema-only tables, table classification, and runtime SQL bind requirements.

  • Adds TableCopySource, TableCopySpecs, TableCopyBind, and per-DB DbSnapshotSpec implementations.
  • Moves snapshot-only helper reads out of DB impls and into snapshot-specific extension traits.
  • Makes schema-only tables explicit in copy specs.
  • Replaces table-name based bind matching with explicit bind kinds on the relevant copy specs.
  • Updates drift tests to validate the new descriptor-driven structure.

The change was motivated by these suggestions:

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) plus TableCopySpec/TableCopySource/TableCopyBind and TableCopySpecs helpers 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 ?N binds 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.

Comment thread stackslib/src/chainstate/stacks/db/snapshot/common.rs
@francesco-stacks francesco-stacks marked this pull request as ready for review July 2, 2026 11:09
Comment thread stackslib/src/chainstate/stacks/db/snapshot/common.rs Outdated
Comment thread stackslib/src/chainstate/stacks/db/snapshot/index.rs Outdated
Comment thread stackslib/src/chainstate/stacks/db/snapshot/index.rs Outdated
/// 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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants