Skip to content

Signatory: share keysets across instances via periodic reload - #2273

Merged
thesimplekid merged 2 commits into
cashubtc:mainfrom
crodas:feat/share-signatories
Aug 11, 2026
Merged

Signatory: share keysets across instances via periodic reload#2273
thesimplekid merged 2 commits into
cashubtc:mainfrom
crodas:feat/share-signatories

Conversation

@crodas

@crodas crodas commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Description

This depends on #2270

Let multiple signatories (or embedded mints) run active/active on one keys database without putting it on the signing path. The derivation index is allocated in the database under a per-unit lock and a version token gates reloads, so peers stay consistent; keys are served from an ArcSwap so a reload never blocks signing. The reload is opt-in, off by default.

See docs/adr/0004-signatory-multi-instance-sharing.md.


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

  • I followed the code style guidelines
  • I ran just quick-check before committing
  • If the Wallet API was modified (added/removed/changed), I have reflected those changes in the FFI bindings (crates/cdk-ffi)

@crodas
crodas requested a review from thesimplekid July 29, 2026 00:52
@crodas crodas self-assigned this Jul 29, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in CDK Jul 29, 2026
@crodas

crodas commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@crodas
crodas force-pushed the feat/share-signatories branch 2 times, most recently from 31499c1 to 6abbf4b Compare July 29, 2026 11:43
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.45917% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.82%. Comparing base (c051ff9) to head (cc02d2d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/cdk-signatory/src/db_signatory.rs 98.40% 6 Missing ⚠️
crates/cdk/src/mint/builder.rs 73.33% 4 Missing ⚠️
crates/cdk-signatory/src/common.rs 93.10% 2 Missing ⚠️
crates/cdk-sql-common/src/mint/keys.rs 96.92% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2273      +/-   ##
==========================================
+ Coverage   75.64%   75.82%   +0.17%     
==========================================
  Files         369      369              
  Lines       89142    89594     +452     
==========================================
+ Hits        67431    67931     +500     
+ Misses      21711    21663      -48     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@crodas crodas mentioned this pull request Jul 29, 2026
3 tasks
@thesimplekid

Copy link
Copy Markdown
Collaborator

@thesimplekid

Copy link
Copy Markdown
Collaborator

@crodas if you could rebase now that #2270 is merged.

@crodas
crodas force-pushed the feat/share-signatories branch from 6abbf4b to f81c207 Compare July 30, 2026 11:57
@thesimplekid

Copy link
Copy Markdown
Collaborator

@cdk-bot review

@cdk-bot cdk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified findings approved for disclosure:

  • Sub-millisecond refresh interval panics the refresh task with division by zero (low) - see inline comment
  • rotate_keyset now returns Err after the rotation has already committed, leaving memory stale with no self-heal in the default config (low) - see inline comment
    Unanchored locations included in summary:
    • crates/cdk-signatory/src/db_signatory.rs:452
  • next_derivation_index ignores NULL derivation_path_index rows, so legacy keysets can cause index reuse and a silent non-rotation (low) - see inline comment

Comment thread crates/cdk-signatory/src/db_signatory.rs
Comment thread crates/cdk-sql-common/src/mint/keys.rs Outdated
@crodas

crodas commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

Comment thread crates/cdk-signatory/Cargo.toml Outdated
Comment thread crates/cdk-signatory/src/db_signatory.rs Outdated
Comment thread crates/cdk-signatory/src/db_signatory.rs
Comment thread crates/cdk-signatory/src/db_signatory.rs
Comment thread crates/cdk/src/mint/builder.rs Outdated
@crodas

crodas commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@cdk-bot cdk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified findings approved for disclosure:

  • Boot can deadlock across instances: init_keysets takes per-unit advisory locks in nondeterministic HashMap order (medium) - see inline comment
    Additional locations included in summary:
    • crates/cdk-sql-common/src/mint/keys.rs:197

Comment thread crates/cdk-signatory/src/common.rs Outdated
@crodas

crodas commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@crodas
crodas force-pushed the feat/share-signatories branch from ff2aff2 to afe25c0 Compare July 31, 2026 15:06
@crodas
crodas requested a review from thesimplekid July 31, 2026 16:37

@thesimplekid thesimplekid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One comment otherwise I think this is good

@crodas
crodas force-pushed the feat/share-signatories branch from afe25c0 to 19adae0 Compare August 3, 2026 16:35
@crodas

crodas commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

1 similar comment
@crodas

crodas commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@cdk-bot cdk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified findings approved for disclosure:

  • ADR-0004 references non-existent KeysDatabase::keysets_version / keyset_version table; code implements keysets_epoch / keyset_epoch (low) - see inline comment

Comment thread docs/adr/0004-signatory-multi-instance-sharing.md Outdated
@crodas
crodas force-pushed the feat/share-signatories branch from 19adae0 to bac4a9b Compare August 5, 2026 23:15
@crodas

crodas commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@cdk-bot cdk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified findings approved for disclosure:

  • Boot-time reactivation unconditionally bumps keyset_epoch even when nothing changed, causing unnecessary fleet-wide reloads (low) - Every boot of every instance in steady state bumps the persisted keyset_epoch via the unconditional add_keyset_info/set_active_keyset writes in init_keysets. Refresh-enabled peers observe the epoch mismatch and perform a full reload + snapshot republish even though no keyset was added or (de)activated. In a fleet with frequent restarts, each boot fans out redundant reloads across all peers.
    Unanchored locations included in summary:
    • crates/cdk-sql-common/src/mint/keys.rs:110

Comment thread crates/cdk-signatory/src/common.rs
@thesimplekid thesimplekid added this to the 0.17.4 milestone Aug 10, 2026
Comment thread crates/cdk-signatory/src/db_signatory.rs
Comment thread crates/cdk-signatory/src/db_signatory.rs
@crodas
crodas force-pushed the feat/share-signatories branch from d85e1ef to 52b0552 Compare August 10, 2026 17:39
@crodas

crodas commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@cdk-bot cdk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified findings approved for disclosure:

  • Cargo.lock.msrv not regenerated for new dependency edges — MSRV CI build will fail (high) - see inline comment
    Additional locations included in summary:
    • crates/cdk-integration-tests/Cargo.toml:72

Comment thread crates/cdk-signatory/Cargo.toml
@crodas

crodas commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@crodas

crodas commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@thesimplekid I simplified a lot, and all reading and writing from the database happens in a transaction, serialized by the database. That is OK to simplify complexity since all operations are happening off-memory and waiting for a database

@crodas
crodas requested a review from thesimplekid August 10, 2026 19:12
@crodas
crodas force-pushed the feat/share-signatories branch 2 times, most recently from 1f2d76e to aac24d8 Compare August 10, 2026 22:40
@crodas

crodas commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@cdk-bot review

@thesimplekid
thesimplekid force-pushed the feat/share-signatories branch 2 times, most recently from 05cab90 to 4c97d56 Compare August 11, 2026 09:08
crodas and others added 2 commits August 11, 2026 11:45
Coordinate keyset reads and rotations across processes with a global database
lock and persisted epoch. Allocate derivation indexes transactionally and
reload immutable in-memory snapshots on an opt-in interval.

Add SQL migrations, builder and CLI configuration, concurrency regression
coverage, and an ADR for the active/active design.

BREAKING CHANGE: MintKeysDatabase removes autocommit keyset reads and requires
epoch and transaction-scoped keyset operations.
Run the cross-instance rotation integration test in the Postgres CI job so it
cannot silently pass through its missing-database guard.

Update ADR wording to match the final refresh API and database-backed rotation
behavior.
@thesimplekid
thesimplekid force-pushed the feat/share-signatories branch from 4c97d56 to cc02d2d Compare August 11, 2026 11:46
@thesimplekid
thesimplekid merged commit cc02d2d into cashubtc:main Aug 11, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in CDK Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants