Skip to content

fix(wallet-db): keep the melt quote payment proof on updates without one (redb, supabase) - #2831

Merged
thesimplekid merged 3 commits into
cashubtc:mainfrom
amartya1523:fix/wallet-db-keep-melt-payment-proof
Nov 18, 2026
Merged

thesimplekid merged 3 commits into
cashubtc:mainfrom
amartya1523:fix/wallet-db-keep-melt-payment-proof

Conversation

@amartya1523

Copy link
Copy Markdown
Contributor

Description

On redb and Supabase wallets, a melt quote's stored payment proof (the preimage) is erased by a later quote update that doesn't carry one.

The wallet writes melt quotes back with whatever the mint's status response contains. update_melt_quote_state sets quote.payment_proof from response.payment_preimage / response.outpoint and calls add_melt_quote. A response without a preimage (some backends and custom methods don't echo it, and later status checks of a paid quote can omit it) therefore sets payment_proof = None.

The backends handle that update differently:

  • SQL (SQLite/Postgres): keeps the stored value: payment_proof = COALESCE(excluded.payment_proof, melt_quote.payment_proof), added in 3012af9. test_add_melt_quote_preserves_existing_payment_proof_when_update_has_none in the melt saga covers it, but only against in-memory SQLite.
  • redb: writes the incoming quote as is, so None overwrites the stored proof.
  • Supabase: PATCHes the whole MeltQuoteTable, which serialized "payment_proof": null and cleared the column.

Fix:

  • redb: on update, a quote without a payment proof keeps the stored one.
  • Supabase: MeltQuoteTable::payment_proof is left out of the request body when it is None. On INSERT that is the same as null; on the update PATCH the stored value is kept.

A new payment proof still replaces the stored one on every backend, as before.

Notes to the reviewers

  • I moved the contract into the shared wallet DB suite as add_melt_quote_keeps_payment_proof, registered in wallet_db_test!, so every backend runs it. It fails on main for redb (left: None, right: Some("preimage")) and passes for SQLite and Postgres.
  • Supabase only runs the shared suite with --features integration-tests. I also added a unit test (melt_quote_row_without_payment_proof_leaves_the_column_out) that checks the serialized row, so it is covered in normal CI.
cargo test -p cdk-redb --lib wallet          # 54 passed
cargo test -p cdk-sqlite --lib wallet        # 57 passed
cargo test -p cdk-supabase --lib melt_quote_row
cargo clippy -p cdk-redb -p cdk-supabase -p cdk-sqlite --lib --tests -- -D warnings

Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED

  • cdk-redb, cdk-supabase: updating a wallet melt quote without a payment proof no longer erases the stored one, matching the SQL backend.

Checklist

  • I followed the code style guidelines
  • I ran just quick-check before committing (ran nightly rustfmt, clippy and the tests above instead)
  • If the Wallet API was modified (added/removed/changed), I have reflected those changes in the FFI bindings (crates/cdk-ffi) (no API change)

The wallet updates a melt quote with whatever the mint's status response
carries, and a response without a preimage set payment_proof to None.
The SQL backend keeps the stored payment proof in that case
(COALESCE in add_melt_quote), but redb wrote the incoming quote as is,
so the proof of payment was lost.
add_melt_quote PATCHes the whole row, and a quote without a payment
proof was sent as "payment_proof": null, which cleared the stored one.
Leave the column out when it is None, as the SQL backend keeps it.
@github-project-automation github-project-automation Bot moved this to Backlog in CDK Nov 5, 2026
@amartya1523

amartya1523 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

The red checks look unrelated to this change. Integration regtest Onchain tests (POSTGRES) panicked in the regtest harness before any test ran, at init_regtest.rs:392 (bitcoind "Couldn't connect to host: Resource temporarily unavailable"), and the SQLITE variant was cancelled after it. The checks that have finished so far, including the wallet DB tests, pass. Could someone re-run the two regtest onchain jobs? I can't from a fork.

@github-project-automation github-project-automation Bot moved this from Backlog to Todo in CDK Nov 18, 2026
@thesimplekid
thesimplekid merged commit d66328e into cashubtc:main Nov 18, 2026
86 of 89 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in CDK Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants