Cashu: a keyset the mint stopped listing blocks every receive — repair it at connect until cdk#2702 ships
I maintainer di solito rispondono entro 1 giorno
@Forte11Cuba ci sta già lavorando.
Dal 14/10/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Dart
- Stelle
- 11
- Fork
- 9
- Merge medio
- 2g 1h
- PR unite (30g)
- 16
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MostroP2P/app
-
documentation priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
I maintainer di solito rispondono entro 1 giorno
-
area: ui bug priority: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area: ui bug priority: high
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Bug: Button "Share logs" does nothingForse già presa @Luquitasjeffrey l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
area: rust-core bug priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MostroP2P/app
Issue simili
-
Python example: list a model's scenes and their camerasForse già presa @rudraparmar76 l’ha presa oggi. Apertadocumentation good first issue python
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
iamahsanmehmood/openskp#796 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Plural rendering: first matching part wins, but gen-l10n lets the last one win (=1 shadows one)Apertabug help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
crowdin/flutter-sdk#97 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
MrSpideyNihal/lockfeed#16 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
InlitX/GymMane#529 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno