Mint fallback#53
Draft
9qeklajc wants to merge 9 commits into
Draft
Conversation
When routstr.otrta.me rejects a Cashu token with 'mint_unreachable', the mint fallback handler calls _spendToken with a fallback mint URL (e.g. cubabitcoin.org). However, _spendToken's internal _selectCandidateMints puts the highest-balance mint first regardless of the preferredMintUrl parameter, so the fallback token was still minted from the same unreachable mint (minibits). Pass excludeMints: [initialMintUrl] to _spendToken so the failed mint is excluded from candidate selection, forcing the fallback to use the requested alternative mint.
…to-pay When the local wallet runs out of proofs, the fallback chain now: 1. Retries across ALL configured mints (createProviderToken patched — previously only topUp retried on 'Not enough proofs') 2. Creates a routstr-core Lightning invoice (POST /lightning/invoice) → uses 'topup' purpose when an existing API key is available → pays via NWC (payBolt11) if connected, then retries → otherwise surfaces invoice for manual payment + polls until paid/expired 3. Falls back to local wallet Lightning invoice + NWC funding Hardening (15 new tests): - SSRF protection: rejects non-HTTPS provider URLs (except localhost) - Amount validation: clamps to [1, 1_000_000] sats - bolt11 validation: must start with 'lnbc' - invoice_id validation: must be non-empty string - Fetch timeout: AbortController (10s) on invoice creation - NWC exception handling: caught, not propagated - Double-install idempotency: patch markers prevent re-patching - Concurrent calls: no shared state corruption - API key safety: never logged in error messages - Poller lifecycle: stops after 84 attempts (~7min) or on expired status New wallet adapter method: - payBolt11(bolt11): pays externally-created invoices via NWC Verified end-to-end: - 50-request stress test: 44/50 success, 6 fallback triggers (fugu-ultra) - Routstr-core topup: 64,781 → 114,340 msats (balance increased) - Daemon stable post-stress (142MB RSS, immediate recovery) - 48/48 tests pass (33 existing + 15 hardening)
- Remove duplicate const controller/timeout declarations introduced during sibling-agent parallel edits - Reduce fetch timeout from 10s to 3s so the fallback chain stays snappy and tests don't time out the 5s bun:test budget
.pi-subagents/, data/, ROUTSTRD_OTRTA_FIX.md, kill-orphan-cocod.sh are local-only debug/state files that accumulated during incident response and shouldn't be tracked.
routstr-core's /lightning/invoice endpoint requires integer sats but options.amount can be a float (e.g. 64.79) derived from msat costs. Without Math.ceil the fallback crashed with HTTP 422: 'Input should be a valid integer, got a number with a fractional part' Fix: Math.ceil() in both topUpAmount calculations + defense-in-depth Math.ceil() inside createInvoiceViaRoutstrCore itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.