feat(cdk-mintd): add nutshell database migration subcommand#2016
feat(cdk-mintd): add nutshell database migration subcommand#2016a1denvalu3 wants to merge 11 commits into
Conversation
0ad2613 to
7375dbf
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2016 +/- ##
==========================================
+ Coverage 69.54% 70.28% +0.74%
==========================================
Files 353 359 +6
Lines 69975 75479 +5504
==========================================
+ Hits 48666 53053 +4387
- Misses 21309 22426 +1117 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Architectural Note: Standalone Fuzzer Design & Nutshell Mint Lifecycle SpawningDuring my review and cleanup of the nutshell-to-CDK database migration integration test ( Path A: Programmatic, Self-Contained Spawning in Rust (Current Design)Currently, the fuzzer test manages the entire lifecycle of both the Nutshell mint (via Python Poetry or Docker container) and the subsequent migrated CDK mint directly within the Rust process (
Path B: Bash/Shell Orchestration & Multi-Phase Binaries (Alternative Design)An alternative would be to strip all setup, process management, and docker lifecycle handling out of the Rust codebase, delegating it to an external bash script (similar to the way
Both options are viable, but the current Path A keeps integration testing robust, fully portable, and extremely simple to run with a single Cargo invocation. |
a34344b to
12754fc
Compare
12754fc to
653c105
Compare
|
This is amazing! 🫶 |
Co-authored-by: tsk <tsk@thesimplekid.com>
cdk-bot
left a comment
There was a problem hiding this comment.
Verified findings approved for disclosure:
- Onchain melt quote migration drops rows with empty fee_options (high) - Onchain melt quotes in a Nutshell database are not migrated, causing systematic loss of those quote records during the new migration flow.
- Mint quote migration doubles paid and issued totals (high) - Migrated paid/issued mint quotes record twice the actual paid and issued amount, corrupting quote accounting and quote state after migration.
| // Start main database transaction after keysets are committed to avoid SQLite lock deadlock | ||
| let mut tx = MintDatabase::begin_transaction(&db).await?; | ||
|
|
||
| // 4. Chunked Migration of Mint Quotes |
There was a problem hiding this comment.
Paid/issued mint quotes are migrated with doubled totals. The reader builds quote_obj with amount_paid/amount_issued already set to the legacy amount, but after add_mint_quote the migration calls add_payment(amount, ...) and add_issuance(amount). Those mutators are additive on the in-memory quote, so a paid quote goes from amount to 2 * amount before update_mint_quote writes quote.amount_paid()/quote.amount_issued() back to the row. The initial insert does not persist the pre-populated totals, so the fix is to either construct the quote with zero counters and replay the payment/issuance events, or persist the legacy totals directly without replaying additive events.
| let mut skipped_promises_count = 0; | ||
| let mut skipped_proofs_count = 0; | ||
| let seen_paid_pending_lookup_ids = RefCell::new(HashSet::new()); | ||
|
|
There was a problem hiding this comment.
Paid/issued mint quotes are migrated with doubled totals. The reader builds quote_obj with amount_paid/amount_issued already set to the legacy amount, but after add_mint_quote the migration calls add_payment(amount, ...) and add_issuance(amount). Those mutators are additive on the in-memory quote, so a paid quote goes from amount to 2 * amount before update_mint_quote writes quote.amount_paid()/quote.amount_issued() back to the row. The initial insert does not persist the pre-populated totals, so the fix is to either construct the quote with zero counters and replay the payment/issuance events, or persist the legacy totals directly without replaying additive events.
This PR implements a new subcommand
migrate-nutshellforcdk-mintdto automatically migrate a Nutshell mint database (SQLite or Postgres) to the configured CDK mint database.Key Features:
MintKeySetInfo,MintQuote,MeltQuote,BlindSignature,BlindedMessage,Proof).keysets,mint_quotes,melt_quotes,promises, andproofstables in segments of 2000 rows. Memory consumption stays flat and negligible even when migrating massive production databases (such as Minibits).tx.add_mint_quote,tx.add_proofs,tx.update_proofs_state, etc.), maintaining the integrity of all database validations, state transitions, and historic payment/issuance tracking.