Skip to content

Commit 490f8f4

Browse files
committed
mark on-chain resolved htlcs as resolved
This is so that lnworker.has_unresolved_sent_htlcs() does not return True after onchain resolution
1 parent 3ce3634 commit 490f8f4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

electrum/lnchannel.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,9 @@ def extract_preimage_from_htlc_txin(self, txin: TxInput, *, is_deeply_mined: boo
15471547
self.lnworker.save_preimage(payment_hash, preimage, mark_as_public=True)
15481548
for htlc, is_sent in found.values():
15491549
if is_sent:
1550+
# if chan is redeemed, we can safely mark all htlcs as resolved
1551+
if self.is_redeemed():
1552+
self.hm.mark_resolved_onchain(htlc.htlc_id, True)
15501553
self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id)
15511554
else:
15521555
# htlc timeout or revocation tx
@@ -1557,6 +1560,9 @@ def extract_preimage_from_htlc_txin(self, txin: TxInput, *, is_deeply_mined: boo
15571560
for htlc, is_sent in found.values():
15581561
if is_sent:
15591562
self.logger.info(f'htlc {"revocation" if is_revocation else "timeout"} tx: failing htlc')
1563+
# if chan is redeemed, we can safely mark all htlcs as resolved
1564+
if self.is_redeemed():
1565+
self.hm.mark_resolved_onchain(htlc.htlc_id, False)
15601566
self.lnworker.htlc_failed(
15611567
self,
15621568
payment_hash=htlc.payment_hash,

electrum/lnhtlc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ def recv_fail(self, htlc_id: int) -> None:
127127
raise Exception(f"(remote) cannot remove htlc that is not there...")
128128
self.log[LOCAL]['fails'][htlc_id] = {LOCAL: next_ctn, REMOTE: None}
129129

130+
@with_lock
131+
def mark_resolved_onchain(self, htlc_id: int, success: bool) -> None:
132+
# so that lnworker.has_unresolved_sent_htlcs() does not return True
133+
if self.was_htlc_failed(htlc_id=htlc_id, htlc_proposer=LOCAL):
134+
return
135+
if self.was_htlc_preimage_released(htlc_id=htlc_id, htlc_proposer=LOCAL):
136+
return
137+
next_ctn = self.ctn_latest(LOCAL) + 1
138+
self.log[LOCAL]['settles' if success else 'fails'][htlc_id] = {LOCAL: next_ctn, REMOTE: None}
139+
130140
@with_lock
131141
def send_update_fee(self, feerate: int) -> None:
132142
fee_update = FeeUpdate(rate=feerate,

0 commit comments

Comments
 (0)