Cashu: a keyset the mint stopped listing blocks every receive — repair it at connect until cdk#2702 ships
Maintainers usually reply within 1 day
@Forte11Cuba is already working on this.
Since Oct 14, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start in rust/src/cashu/wallet.rs at CashuWallet::connect, where the keyset repair would run before Wallet::new, and read the cdk#2702 trace to see how active flags are read back from the store. The done condition is the seam test in the issue: with two active sat keysets stored and the mint listing only one, active_keyset() picks the listed one. The UnknownKeySet mapping and Dart l10n are separate follow-ups, and the pin in docs/cashu/cdk-spike.md matters for the upstream dependency.
Written by the indexing model from the issue text.
Description
Summary
After testnut.cashu.space was reset, the wallet could no longer receive any token from
it, valid ones included. A 12-sat token in the mint's current sat keyset, which cashu.me
redeemed fine, failed with "That token could not be redeemed. It may be from another mint, or
already spent." (CashuReceiveFailed). Neither cause was true.
The bug is in cdk and is reported upstream as cashubtc/cdk#2702. When a keyset disappears
from the mint's GET /v1/keysets (not marked inactive: gone), the wallet keeps it cached as
active: true. It can then be picked for the swap outputs, the mint answers 12001
(UnknownKeySet), and cdk's retry does not recover. This lasts until the local proof store is
edited by hand. A cdk release with the fix will take time, so this issue proposes a small
workaround in the app, plus the logging that was missing to diagnose it.
What happened, with evidence
- testnut now lists one
satkeyset (017bc604…) and oneusdkeyset, both
input_fee_ppk: 100. - The proof store (
cashu-<pubkey>.sqlite) still held the oldsatkeyset0184237e…with
active = 1, the same fee as the real one. The mint no longer lists it. - On a copy of that store, the app's own
CashuWallet::connectrefreshes keysets from the mint
(KeysetLoadPolicy::Refresh). Even after that,active_keyset()returned0184237e…
5 times out of 5. - Moving the store aside (fresh store, same identity, same mint) fixed it at once: the same
kind of token was received, less the mint's fee. - The 294 sat the wallet still showed were all proofs in
0184237e…, which the mint no longer
knows. The balance was phantom. - Finding this took a manual read of the SQLite store, because the app does not log why a
receive failed. cdk's error is reduced to a marker, Dart hides the tail (correctly), and no
log line keeps it.
Why it happens (cdk 0.18.1)
Full trace in cashubtc/cdk#2702. In short:
fetch_from_httpstarts from the cached metadata and only inserts what the mint returns. A
keyset missing from the response keeps its storedactiveflag, which is written back to
the store.Wallet::keysets()reads those flags, andactive_keyset()takes the cheapest active one.
On a fee tie it depends onHashMaporder.retry_on_inactive_keysetmatches onlyInactiveKeyset, so a12001is not retried.
Scope in production
NUT-02 has a mint keep listing rotated keysets as active: false. cdk then updates the flag
correctly, so a normal key rotation is fine. This only bites when a mint drops keysets from
its list: a test mint reset, or a mint that lost or replaced its database. That is rare, but
when it happens the wallet is stuck with a false message and a balance it cannot spend.
Proposal
All verified against the public API of cdk 0.18.1:
Wallet::localstoreispub;cdk::wallet::HttpClientandMintConnector::get_mint_keysetsare public;- cdk-sqlite's keyset upsert updates
active(ON CONFLICT(id) DO UPDATE SET active = excluded.active); Wallet::newbuilds a fresh metadata cache, whose first load reads the store before refreshing from the mint (mint_metadata_cache.rs,load_from_mint).
1. Repair the store at connect (rust/src/cashu/wallet.rs, CashuWallet::connect, before
Wallet::new):
- fetch the mint's keyset list with
HttpClient(one extraGET /v1/keysets; the wallet
opens lazily, never at startup); - read the stored keysets of that mint (
localstore.get_mint_keysets); - write back with
active: falseevery stored keyset marked active that the mint no longer
lists (add_mint_keysets), skippingauthkeysets, whose list is not fetched.
Nothing is deleted. If the mint lists the keyset again, the next refresh makes it active again.
If the mint does not answer, the repair is skipped and probe fails with
CashuMintUnreachable as today. As a side effect, MintCapabilities::has_sat_keyset stops
counting a dead keyset.
2. A mint reset while the app is open. When an operation fails with
cdk::Error::UnknownKeySet:
- drop the live wallet, so the next action reconnects and repairs;
- return a stable marker, e.g.
CashuMintKeysetsChanged, which Dart maps to "The mint
changed its keys. Try again." (l10n in every locale).
No automatic retry: the mint rejects the whole swap, so a retry would be safe, but it adds
complexity for a rare case.
3. Log the real error. log::warn! the cdk error in cashu_receive_token,
cashu_create_token and cashu_sweep_spent_proofs before it becomes a marker. This stays
useful whatever happens upstream.
4. Remove the workaround when cdk ships the fix. Leave a comment pointing to
cashubtc/cdk#2702 on the repair. When the pin moves past the release that fixes it
(docs/cashu/cdk-spike.md), delete the repair and keep its test.
Tests
- Seam test (fails without the repair): use a temporary
WalletSqliteDatabase, as
stored_balancedoes. Store twosatkeysets marked active. Apply the repair with a mint
list that contains only one of them. Build theWalletand assert thatactive_keyset()
picks the listed one. Without the repair, the same setup returns the dead keyset, as the
test in cdk#2702 shows. - Unit tests for the selection: a missing keyset is deactivated; a listed one is
untouched; an already inactive one is untouched; anauthkeyset is left alone. - Mapping test:
UnknownKeySet→CashuMintKeysetsChanged, and the live wallet is
dropped. - Manual: the store from this report (kept aside) reproduces it. With the repair, a sat
token from the mint's current keyset is received on that store.
Out of scope
- The phantom balance. Proofs in a keyset the mint no longer lists are worthless, but the
balance still counts them. Excluding them and saying so ("N sat are in keys this mint no
longer recognises") is a separate UX decision. The proofs are not deleted, in case the mint
comes back. - #391 / #798. Tokens in a unit other than sats are a different bug.
References
- Upstream: cashubtc/cdk#2702
- Found while testing #798 (#391)
- cdk / cdk-sqlite pinned at
=0.18.1
- Dominant language
- Dart
- Stars
- 11
- Forks
- 9
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 16
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MostroP2P/app
-
documentation priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
area: ui bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
area: ui bug priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Bug: Button "Share logs" does nothingPossibly taken @Luquitasjeffrey claimed this 7 days ago. Open
Difficulty 2/5 Half a day Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
area: rust-core bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Python example: list a model's scenes and their camerasPossibly taken @rudraparmar76 claimed this today. Opendocumentation good first issue python
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
iamahsanmehmood/openskp#796 · 1 comment ·
Maintainers usually reply within 1 day
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Plural rendering: first matching part wins, but gen-l10n lets the last one win (=1 shadows one)Openbug help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
crowdin/flutter-sdk#97 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
MrSpideyNihal/lockfeed#16 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
InlitX/GymMane#529 · 1 comment ·
Maintainers usually reply within 1 day