fix: await ln payment before gift card confetti#929
Draft
Conversation
Member
Author
|
Looking for a reliable way to reproduce it |
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.
This PR:
Description
1. False-positive confetti
BlocktankRepo.claimGiftCodeWithLiquiditypreviously returned success as soon as Blocktank'sgiftPayHTTP RPC returned — but that response only confirms the LSP accepted the request, not that the LN payment actually landed. If Blocktank's background payer subsequently failed to route the HTLC, Bitkit still played confetti and surfaced a "received" sheet with the requested amount, while no incoming payment ever arrived.The repo now subscribes to
LightningRepo.nodeEventsfor theEvent.PaymentReceivedmatching the freshly-created invoice's payment hash before triggeringgiftPay, then awaits that event with a 45 second timeout. On timeout it throwsServiceError.GiftClaimPaymentNotReceived, which the existing error handler inGiftViewModelroutes to the standardGiftRoute.Errorscreen. The success result reports the actual received sat amount instead of the requested amount.The without-liquidity path (channel open +
openChannel) is unchanged — that path already blocks on the funding transaction.2. Intent re-delivery on Activity recreate
When the app language is changed, Android destroys and recreates the Activity, re-delivering the original launching intent.
MainActivity.onCreatewas unconditionally callinghandleDeeplinkIntent(intent), so any deeplink-driven flow (gift sheet, send sheet, pubky auth, etc.) re-fired on the locale switch.onCreatenow only processes the launching intent on a fresh start (savedInstanceState == null). New deeplinks that arrive while the app is running are still handled viaonNewIntent.Preview
N/A
QA Notes
Manual Tests
GiftErrorSheetappears. No confetti, no NewTransactionSheet, no new activity entry, balance unchanged.regression:No inbound capacity → scan a gift code: existing channel-open flow runs (openChannel+ChannelReady), gift activity inserted, no regression vs current behavior.regression:Code already redeemed → "used" sheet still appears. Code with count exhausted → "used up" sheet still appears. (GIFT_CODE_ALREADY_USEDandGIFT_CODE_USED_UPpaths unchanged.)Failed to claim gift codeis logged withGiftClaimPaymentNotReceived. For case 2 confirmEvent.PaymentReceivedis logged beforeGift payment confirmed by LDKandGift claim successful: SuccessWithLiquidity.bitkit://gift-…deeplink) → on the gift sheet, change the app language via Settings → General → Language. The gift sheet should not re-open after the language switch. Same check applies to other deeplink-driven sheets (send / pubky auth) launched the same way.Reproducing the failure path
The originally-reported
gUCdzXfm12V71xztGzDoiQ-3000is now exhausted and returnsGIFT_CODE_USED_UP(a separate, already-handled path), so it can no longer reproduce the false-positive. To exercise case 1, use one of:giftPayreturns success butEvent.PaymentReceivednever fires.To make the wifi-toggle approach reliable, debug builds include a
GIFT_QA_PRE_RECEIVE_DELAYconstant inBlocktankRepo(default15.seconds) that pauses aftergiftPayreturns and beforeawait PaymentReceived. Use the window to disable wifi (or kill the LSP peer) and force a routing failure. Set the constant toDuration.ZEROto skip the pause. The pause only fires whenEnv.isDebugis true.Regtest helpers
Fire the gift deeplink directly without scanning a QR (replace the package id per flavor —
to.bitkit.devfor dev/regtest,to.bitkit.tnetfor testnet,to.bitkitfor mainnet):adb shell am start -a android.intent.action.VIEW -d "bitkit://gift-gUCdzXfm12V71xztGzDoiQ-3000" to.bitkit.devTail the relevant logs while reproducing:
Or pull the on-disk log file after the attempt: