feat(wallet): implement NUT-XX Efficient Wallet Recovery#1735
feat(wallet): implement NUT-XX Efficient Wallet Recovery#1735a1denvalu3 wants to merge 8 commits intocashubtc:mainfrom
Conversation
|
The compaction logic is handled primarily through an automatic, internal Here is the specific breakdown of how it works:
Because the new proofs are freshly issued, their |
- Add keyset_counter to ProofInfo for Depth Invariant tracking - Add SQL migrations for keyset_counter in SQLite and Postgres - Implement ensure_depth_invariant to enforce keyset_counter > T - d and compaction - Implement O(log N) binary search find_t for fast recovery via restore - Implement scan_gap to handle network gaps in nonce space during fast recovery - Expose RecoveryOptions and RecoveryStrategy (Fast and LinearScan) - Support automatic consolidation on startup for missing keyset_counter proofs - Expose fast recovery options through cdk-ffi and cdk-cli
93283cf to
c40125d
Compare
c40125d to
c121a60
Compare
Ensure that the NUT-XX depth invariant is checked and maintained when generating new proofs during mint and melt (change) operations.
Added a multi-threaded integration test to verify the depth invariant is properly maintained when melting tokens concurrently.
Implemented the addition to NUT-27 from the NUT-342 (Efficient Wallet Recovery) spec proposal, which adds the nut_342 boolean flag to the backup payload to signal that the wallet maintained the depth invariant.
Summary
This pull request implements the new NUT-XX Efficient Wallet Recovery specification for the
cdkwallet, reducing recovery complexity fromO(T)toO(log N)and maintaining the required Depth Invariant.Changes
keyset_countertoProofInfoacross SQLite and PostgreSQL, with corresponding migrations.Wallet::ensure_depth_invariantthat triggers a consolidation swap if unspent proofs exceed theT - dthreshold or the compaction limitd.recv_proofs/change_proofscorrectly acrossissue,melt,receive, andswapsagas to maintain accuracy.find_t(binary search).scan_gap(gap scan) to handle gaps securely.Wallet::restore_fast.restorelogic to accept a newRecoveryOptionswithRecoveryStrategy::Fast(default) andRecoveryStrategy::LinearScanto fall back to the old NUT-13 scan.RecoveryOptionsacross UniFFI (cdk-ffi) and added a--legacy-scanflag to thecdk-clifor backwards compatibility.ensure_depth_invariantat startup whenWallet::recover_incomplete_sagasverifies keysets to migrate pre-existingkeyset_counter = NULLproofs.