fix: populate settlementVia.preImage in lnInvoicePaymentSend response#507
Open
blink-claw-bot wants to merge 1 commit intoblinkbitcoin:mainfrom
Open
fix: populate settlementVia.preImage in lnInvoicePaymentSend response#507blink-claw-bot wants to merge 1 commit intoblinkbitcoin:mainfrom
blink-claw-bot wants to merge 1 commit intoblinkbitcoin:mainfrom
Conversation
- Add optional revealedPreImage field to LnSendAttemptResult type - Pass revealedPreImage from successful Lightning payments to result - Inject preImage into wallet transaction settlementVia before returning - Fix race condition by awaiting persistAll() in helpers.ts Closes blinkbitcoin#506
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.
Closes #506
Problem
The
lnInvoicePaymentSendGraphQL mutation was returningnullforsettlementVia.preImageeven when Lightning payments succeeded. This was due to a race condition where:lockedPaymentViaLnStepscallsLedgerFacade.updateMetadataByHash()to persist the preimageexecutePaymentViaLncallsgetTransactionForWalletByJournalIdto fetch the wallet transactionhelpers.ts,persistAndReturnEntrydoes NOT awaittxMetadataRepo.persistAll()(fire-and-forget)updateMetadataByHashruns, the metadata documents may not exist yet, causingmodifiedCount: 0→NoTransactionToUpdateErrorRoot Cause Analysis
The race condition occurs in
core/api/src/services/ledger/helpers.tsline 28 wheretxMetadataRepo.persistAll()is called withoutawait.Solution
This PR implements two fixes:
Primary Fix: Direct PreImage Injection
LnSendAttemptResult.ok()to accept an optionalrevealedPreImageparameterlockedPaymentViaLnSteps, pass thepayResult.revealedPreImagetoLnSendAttemptResult.ok()executePaymentViaLn, inject the preImage directly into the wallet transaction'ssettlementViabefore returningSecondary Fix: Race Condition
awaittotxMetadataRepo.persistAll()inhelpers.tsto prevent the race conditionTesting
pnpm tsc --noEmit)Files Modified
core/api/src/app/payments/send-lightning.ts— main fixcore/api/src/app/payments/ln-send-result.ts— result type updatecore/api/src/app/payments/index.types.d.ts— type definitionscore/api/src/services/ledger/helpers.ts— race condition fix