1
0

lnchannel: fix extract_preimage for MPP.

- enforce MPP in the corresponding regtest.
 - fix get_invoice_status returning inflight if it was settled onchain
This commit is contained in:
ThomasV
2024-12-14 08:24:26 +01:00
parent 62af1ee887
commit 67470b92b7
3 changed files with 23 additions and 19 deletions

View File

@@ -1294,24 +1294,26 @@ class Channel(AbstractChannel):
else:
return
payment_hash = sha256(preimage)
for direction, htlc in itertools.chain(self.hm.get_htlcs_in_oldest_unrevoked_ctx(REMOTE),
self.hm.get_htlcs_in_latest_ctx(REMOTE)):
found = {}
for direction, htlc in itertools.chain(
self.hm.get_htlcs_in_oldest_unrevoked_ctx(REMOTE),
self.hm.get_htlcs_in_latest_ctx(REMOTE)):
if htlc.payment_hash == payment_hash:
is_sent = direction == RECEIVED
break
else:
for direction, htlc in itertools.chain(self.hm.get_htlcs_in_oldest_unrevoked_ctx(LOCAL),
self.hm.get_htlcs_in_latest_ctx(LOCAL)):
if htlc.payment_hash == payment_hash:
is_sent = direction == SENT
break
else:
return
if self.lnworker.get_preimage(payment_hash) is None:
self.logger.info(f'found preimage for {payment_hash.hex()} in witness of length {len(witness)}')
self.lnworker.save_preimage(payment_hash, preimage)
info = self.lnworker.get_payment_info(payment_hash)
if info is not None and info.status != PR_PAID:
found[htlc.htlc_id] = (htlc, is_sent)
for direction, htlc in itertools.chain(
self.hm.get_htlcs_in_oldest_unrevoked_ctx(LOCAL),
self.hm.get_htlcs_in_latest_ctx(LOCAL)):
if htlc.payment_hash == payment_hash:
is_sent = direction == SENT
found[htlc.htlc_id] = (htlc, is_sent)
if not found:
return
if self.lnworker.get_preimage(payment_hash) is not None:
return
self.logger.info(f'found preimage for {payment_hash.hex()} in witness of length {len(witness)}')
self.lnworker.save_preimage(payment_hash, preimage)
for htlc, is_sent in found.values():
if is_sent:
self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id)
else:

View File

@@ -2377,10 +2377,10 @@ class LNWallet(LNWorker):
def get_invoice_status(self, invoice: BaseInvoice) -> int:
invoice_id = invoice.rhash
if invoice_id in self.inflight_payments:
status = self.get_payment_status(bfh(invoice_id))
if status == PR_UNPAID and invoice_id in self.inflight_payments:
return PR_INFLIGHT
# status may be PR_FAILED
status = self.get_payment_status(bytes.fromhex(invoice_id))
if status == PR_UNPAID and invoice_id in self.logs:
status = PR_FAILED
return status
@@ -2393,7 +2393,7 @@ class LNWallet(LNWorker):
if status in SAVED_PR_STATUS:
self.set_payment_status(bfh(key), status)
util.trigger_callback('invoice_status', self.wallet, key, status)
self.logger.info(f"invoice status triggered (2) for key {key} and status {status}")
self.logger.info(f"set_invoice_status {key}: {status}")
# liquidity changed
self.clear_invoices_cache()

View File

@@ -277,6 +277,8 @@ fi
if [[ $1 == "extract_preimage" ]]; then
# instead of settling bob will broadcast
$alice setconfig test_force_disable_mpp false
$alice setconfig test_force_mpp true
$bob enable_htlc_settle false
wait_for_balance alice 1
echo "alice opens channel"