Skip to content

Use backend invoice payment hash for settlement checks#2

Open
libertas-primordium wants to merge 1 commit into
btcjt:mainfrom
libertas-primordium:fix-phoenixd-payment-hash
Open

Use backend invoice payment hash for settlement checks#2
libertas-primordium wants to merge 1 commit into
btcjt:mainfrom
libertas-primordium:fix-phoenixd-payment-hash

Conversation

@libertas-primordium

Copy link
Copy Markdown

Summary

This fixes phoenixd-backed Lightning settlement reconciliation by storing the payment hash returned by the Lightning backend when creating a pending LNURL purchase session.

The existing code generated a local preimage/payment hash and stored that generated hash in the session row. With phoenixd, however, the invoice returned by createinvoice has its own backend-created paymentHash. Settlement polling later checks the stored session hash, so phoenixd-backed sessions can remain pending even after the invoice is paid because Europa is polling phoenixd for a hash phoenixd does not recognize.

This change stores invoice.paymentHash || paymentHash, preserving the existing fallback behavior while using the actual backend-created invoice hash when available.

Validation

  • Ran pnpm install --frozen-lockfile
  • Ran pnpm build
  • Ran pnpm test
  • All 6 test files passed; 55 tests passed
  • Validated on a live phoenixd-backed Europa node:
    • A 100 sat Lightning payment increased phoenixd balance
    • The Europa session changed from pending to active automatically
    • The WireGuard peer was added automatically without manual database or wg intervention

Notes

This patch only fixes phoenixd-backed payment reconciliation by storing the payment hash returned by the backend-created invoice.

There is a separate phoenixd-related issue with the LNURL successAction response. Europa currently encrypts the AES successAction using its locally generated preimage, but phoenixd creates the actual payable invoice with its own preimage/payment hash. As a result, the wallet that sends the payment receives a different payment preimage and cannot decrypt the returned successAction payload. In live testing, the session activated correctly after this patch, but Phoenix Wallet Android still crashed when trying to view the payment receipt/config.

That appears to require a separate design fix: either phoenixd would need to support caller-supplied invoice preimages/payment hashes, or Europa’s phoenixd backend should use a different authenticated config-delivery flow instead of AES successAction.

Store the payment hash returned by the Lightning backend when creating a pending LNURL purchase session instead of always storing the locally generated preimage hash.

This fixes phoenixd-backed payment reconciliation because phoenixd creates invoices with its own payment hash while Europa previously stored the generated preimage hash and then polled phoenixd for a hash it did not recognize.

Validated with pnpm install --frozen-lockfile, pnpm build, and pnpm test. Also validated on a live phoenixd-backed Europa node: after this change, a 100 sat Lightning purchase increased phoenixd balance, the session changed from pending to active automatically, and the WireGuard peer was added without manual database or wg intervention.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant