Cashu: a keyset the mint stopped listing blocks every receive — repair it at connect until cdk#2702 ships

Đang mở
#799 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Forte11Cuba đang làm issue này rồi.

Từ ngày 14/10/2026.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart, rust, sqlite
Lĩnh vực
api, backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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 sat keyset (017bc604…) and one usd keyset, both
    input_fee_ppk: 100.
  • The proof store (cashu-<pubkey>.sqlite) still held the old sat keyset 0184237e… 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::connect refreshes keysets from the mint
    (KeysetLoadPolicy::Refresh). Even after that, active_keyset() returned 0184237e…
    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:

  1. fetch_from_http starts from the cached metadata and only inserts what the mint returns. A
    keyset missing from the response keeps its stored active flag, which is written back to
    the store.
  2. Wallet::keysets() reads those flags, and active_keyset() takes the cheapest active one.
    On a fee tie it depends on HashMap order.
  3. retry_on_inactive_keyset matches only InactiveKeyset, so a 12001 is 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::localstore is pub;
  • cdk::wallet::HttpClient and MintConnector::get_mint_keysets are public;
  • cdk-sqlite's keyset upsert updates active (ON CONFLICT(id) DO UPDATE SET active = excluded.active);
  • Wallet::new builds 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 extra GET /v1/keysets; the wallet
    opens lazily, never at startup);
  • read the stored keysets of that mint (localstore.get_mint_keysets);
  • write back with active: false every stored keyset marked active that the mint no longer
    lists (add_mint_keysets), skipping auth keysets, 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_balance does. Store two sat keysets marked active. Apply the repair with a mint
    list that contains only one of them. Build the Wallet and assert that active_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; an auth keyset 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
Ngôn ngữ chính
Dart
Star
11
Fork
9
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
16

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MostroP2P/app

Tất cả issue của MostroP2P/app

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.