fix: spark l2 `USER_SWAP_RETURNED` means it failed (#4258)
What changed, and why it matters
This commit fixes how LNbits handles a specific payment status from the Breez Spark SDK called USER_SWAP_RETURNED. Previously, this status was not treated as a failure, which could cause LNbits to incorrectly believe a Lightning payment succeeded when it actually failed. This could lead to incorrect accounting, such as marking an invoice as paid when the funds were returned to the sender.
Review related Spark L2 payment status handling to ensure all SDK terminal states are mapped correctly. Consider adding tests covering each Breez Spark SDK terminal status. Users relying on Spark L2 wallets should update to include this fix.
Security signals we found
Incorrect payment status classification
Potential financial/accounting inconsistency
Reliance on third-party SDK status semantics
Evidence from the diff
In lnbits/wallets/sparkl2.py, the set of statuses treated as payment failures was expanded to include USER_SWAP_RETURNED. The commit comment notes that Breez Spark SDK explicitly maps this status to failed. Without this change, USER_SWAP_RETURNED would fall through to the default handling and likely be treated as a success or pending state, causing LNbits to misreport the outcome of a Spark L2 wallet payment.
Changed components
lnbits/wallets/sparkl2.pyInspect captured patch +1 / −0
diff --git a/lnbits/wallets/sparkl2.py b/lnbits/wallets/sparkl2.py
index 562e49d..0d26f44 100644
--- a/lnbits/wallets/sparkl2.py
+++ b/lnbits/wallets/sparkl2.py
@@ -315,6 +315,7 @@ class SparkL2Wallet(Wallet):
"PREIMAGE_PROVIDING_FAILED",
"USER_TRANSFER_VALIDATION_FAILED",
"USER_SWAP_RETURN_FAILED",
+ "USER_SWAP_RETURNED", # - Breez Spark SDK explicitly maps it to failed
}
if status in success:
return PaymentSuccessStatus()
Why this scored 42/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.