diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py index 658e48a84..c3f6cd3bc 100644 --- a/electrum/lnchannel.py +++ b/electrum/lnchannel.py @@ -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: diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 4a7f43e50..935370ea8 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -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() diff --git a/tests/regtest/regtest.sh b/tests/regtest/regtest.sh index b206fc209..1600f4cd3 100755 --- a/tests/regtest/regtest.sh +++ b/tests/regtest/regtest.sh @@ -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"