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:
@@ -1294,24 +1294,26 @@ class Channel(AbstractChannel):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
payment_hash = sha256(preimage)
|
payment_hash = sha256(preimage)
|
||||||
for direction, htlc in itertools.chain(self.hm.get_htlcs_in_oldest_unrevoked_ctx(REMOTE),
|
found = {}
|
||||||
self.hm.get_htlcs_in_latest_ctx(REMOTE)):
|
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:
|
if htlc.payment_hash == payment_hash:
|
||||||
is_sent = direction == RECEIVED
|
is_sent = direction == RECEIVED
|
||||||
break
|
found[htlc.htlc_id] = (htlc, is_sent)
|
||||||
else:
|
for direction, htlc in itertools.chain(
|
||||||
for direction, htlc in itertools.chain(self.hm.get_htlcs_in_oldest_unrevoked_ctx(LOCAL),
|
self.hm.get_htlcs_in_oldest_unrevoked_ctx(LOCAL),
|
||||||
self.hm.get_htlcs_in_latest_ctx(LOCAL)):
|
self.hm.get_htlcs_in_latest_ctx(LOCAL)):
|
||||||
if htlc.payment_hash == payment_hash:
|
if htlc.payment_hash == payment_hash:
|
||||||
is_sent = direction == SENT
|
is_sent = direction == SENT
|
||||||
break
|
found[htlc.htlc_id] = (htlc, is_sent)
|
||||||
else:
|
if not found:
|
||||||
return
|
return
|
||||||
if self.lnworker.get_preimage(payment_hash) is None:
|
if self.lnworker.get_preimage(payment_hash) is not None:
|
||||||
self.logger.info(f'found preimage for {payment_hash.hex()} in witness of length {len(witness)}')
|
return
|
||||||
self.lnworker.save_preimage(payment_hash, preimage)
|
self.logger.info(f'found preimage for {payment_hash.hex()} in witness of length {len(witness)}')
|
||||||
info = self.lnworker.get_payment_info(payment_hash)
|
self.lnworker.save_preimage(payment_hash, preimage)
|
||||||
if info is not None and info.status != PR_PAID:
|
for htlc, is_sent in found.values():
|
||||||
if is_sent:
|
if is_sent:
|
||||||
self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id)
|
self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2377,10 +2377,10 @@ class LNWallet(LNWorker):
|
|||||||
|
|
||||||
def get_invoice_status(self, invoice: BaseInvoice) -> int:
|
def get_invoice_status(self, invoice: BaseInvoice) -> int:
|
||||||
invoice_id = invoice.rhash
|
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
|
return PR_INFLIGHT
|
||||||
# status may be PR_FAILED
|
# status may be PR_FAILED
|
||||||
status = self.get_payment_status(bytes.fromhex(invoice_id))
|
|
||||||
if status == PR_UNPAID and invoice_id in self.logs:
|
if status == PR_UNPAID and invoice_id in self.logs:
|
||||||
status = PR_FAILED
|
status = PR_FAILED
|
||||||
return status
|
return status
|
||||||
@@ -2393,7 +2393,7 @@ class LNWallet(LNWorker):
|
|||||||
if status in SAVED_PR_STATUS:
|
if status in SAVED_PR_STATUS:
|
||||||
self.set_payment_status(bfh(key), status)
|
self.set_payment_status(bfh(key), status)
|
||||||
util.trigger_callback('invoice_status', self.wallet, 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
|
# liquidity changed
|
||||||
self.clear_invoices_cache()
|
self.clear_invoices_cache()
|
||||||
|
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ fi
|
|||||||
|
|
||||||
if [[ $1 == "extract_preimage" ]]; then
|
if [[ $1 == "extract_preimage" ]]; then
|
||||||
# instead of settling bob will broadcast
|
# instead of settling bob will broadcast
|
||||||
|
$alice setconfig test_force_disable_mpp false
|
||||||
|
$alice setconfig test_force_mpp true
|
||||||
$bob enable_htlc_settle false
|
$bob enable_htlc_settle false
|
||||||
wait_for_balance alice 1
|
wait_for_balance alice 1
|
||||||
echo "alice opens channel"
|
echo "alice opens channel"
|
||||||
|
|||||||
Reference in New Issue
Block a user