fix: return preimages for Phoenixd invoices and settled payments (#4068)
What changed, and why it matters
This commit fixes a data-handling bug in LNbits, a Bitcoin Lightning wallet server. When checking whether a payment succeeded, the system now correctly returns the 'preimage' (a proof-of-payment secret) and the fee. It also adds a fallback to fetch the preimage from the connected Phoenixd node when creating invoices, because Phoenixd sometimes doesn't include it in the initial response. This is a correctness/reliability fix, not a vulnerability that attackers can exploit.
No urgent security action required. Treat as a normal reliability fix. Review any downstream services that depend on preimage presence to confirm they now behave correctly.
Security signals we found
Missing preimage could break payment proof verification workflows
Incomplete PaymentSuccessStatus may cause downstream logic to treat confirmed payments as lacking proof
No input validation changes or trust-boundary crossings introduced
Evidence from the diff
The patch modifies two files. In payments.py, PaymentSuccessStatus is now constructed with fee_msat and preimage fields populated from the stored Payment record, rather than omitting them. In phoenixd.py, a new helper _incoming_preimage queries the Phoenixd /payments/incoming/{payment_hash} endpoint to retrieve the preimage when createinvoice does not return paymentPreimage. The change improves API consistency and ensures callers receive complete payment status data.
Changed components
lnbits/core/services/payments.pylnbits/wallets/phoenixd.pyPayment status reporting for Phoenixd wallet backendInspect captured patch +24 / −3
diff --git a/lnbits/core/services/payments.py b/lnbits/core/services/payments.py
index 712b8c3..38439c8 100644
--- a/lnbits/core/services/payments.py
+++ b/lnbits/core/services/payments.py
@@ -632,7 +632,7 @@ async def check_transaction_status(
return PaymentPendingStatus()
if payment.status == PaymentState.SUCCESS.value:
- return PaymentSuccessStatus(fee_msat=payment.fee)
+ return PaymentSuccessStatus(fee_msat=payment.fee, preimage=payment.preimage)
return await check_payment_status(payment)
@@ -640,7 +640,7 @@ async def check_transaction_status(
async def check_payment_status(payment: Payment) -> PaymentStatus:
if payment.is_internal:
if payment.success:
- return PaymentSuccessStatus()
+ return PaymentSuccessStatus(fee_msat=payment.fee, preimage=payment.preimage)
if payment.failed:
return PaymentFailedStatus()
if payment.is_in and payment.fiat_provider:
diff --git a/lnbits/wallets/phoenixd.py b/lnbits/wallets/phoenixd.py
index fe84470..0d508b2 100644
--- a/lnbits/wallets/phoenixd.py
+++ b/lnbits/wallets/phoenixd.py
@@ -98,6 +98,24 @@ class PhoenixdWallet(Wallet):
logger.warning(exc)
return StatusResponse(f"Unable to connect to {self.endpoint}.", 0)
+ async def _incoming_preimage(self, payment_hash: str) -> str | None:
+ """Fetch preimage from Phoenixd incoming payment (createinvoice omits it)."""
+ try:
+ r = await self.client.get(
+ f"/payments/incoming/{payment_hash}",
+ timeout=40,
+ )
+ if r.is_error:
+ return None
+ return r.json().get("preimage") or None
+ except Exception as exc:
+ logger.warning(
+ "Phoenixd: could not fetch preimage for %s: %s",
+ payment_hash,
+ exc,
+ )
+ return None
+
async def create_invoice(
self,
amount: int,
@@ -147,7 +165,10 @@ class PhoenixdWallet(Wallet):
checking_id = data["paymentHash"]
payment_request = data["serialized"]
- preimage = data.get("paymentPreimage", None) # if available
+ # Phoenixd createinvoice often omits paymentPreimage.
+ preimage = data.get("paymentPreimage") or await self._incoming_preimage(
+ checking_id
+ )
return InvoiceResponse(
ok=True,
checking_id=checking_id,
Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.