Browse Source

Fix CTNs in should_be_closed_due_to_expiring_htlcs (fixes #7906).

Also fix sending too many fee updates.
Rename lnworker.on_channel_update, that name was misleading.
patch-4
ThomasV 3 years ago
parent
commit
a5965933d2
  1. 8
      electrum/lnchannel.py
  2. 2
      electrum/lnhtlc.py
  3. 2
      electrum/lnpeer.py
  4. 2
      electrum/lnwatcher.py
  5. 4
      electrum/lnworker.py

8
electrum/lnchannel.py

@ -1576,8 +1576,8 @@ class Channel(AbstractChannel):
# to the present, then unilaterally close channel
recv_htlc_deadline = lnutil.NBLOCK_DEADLINE_BEFORE_EXPIRY_FOR_RECEIVED_HTLCS
for sub, dir, ctn in ((LOCAL, RECEIVED, self.get_latest_ctn(LOCAL)),
(REMOTE, SENT, self.get_oldest_unrevoked_ctn(LOCAL)),
(REMOTE, SENT, self.get_latest_ctn(LOCAL)),):
(REMOTE, SENT, self.get_oldest_unrevoked_ctn(REMOTE)),
(REMOTE, SENT, self.get_latest_ctn(REMOTE)),):
for htlc_id, htlc in self.hm.htlcs_by_direction(subject=sub, direction=dir, ctn=ctn).items():
if not self.hm.was_htlc_preimage_released(htlc_id=htlc_id, htlc_proposer=REMOTE):
continue
@ -1588,8 +1588,8 @@ class Channel(AbstractChannel):
# will unilaterally close the channel and time out the HTLC
offered_htlc_deadline = lnutil.NBLOCK_DEADLINE_AFTER_EXPIRY_FOR_OFFERED_HTLCS
for sub, dir, ctn in ((LOCAL, SENT, self.get_latest_ctn(LOCAL)),
(REMOTE, RECEIVED, self.get_oldest_unrevoked_ctn(LOCAL)),
(REMOTE, RECEIVED, self.get_latest_ctn(LOCAL)),):
(REMOTE, RECEIVED, self.get_oldest_unrevoked_ctn(REMOTE)),
(REMOTE, RECEIVED, self.get_latest_ctn(REMOTE)),):
for htlc_id, htlc in self.hm.htlcs_by_direction(subject=sub, direction=dir, ctn=ctn).items():
if htlc.cltv_expiry + offered_htlc_deadline > local_height:
continue

2
electrum/lnhtlc.py

@ -19,7 +19,7 @@ class HTLCManager:
'locked_in': {}, # "side who offered htlc" -> action -> htlc_id -> whose ctx -> ctn
'settles': {}, # "side who offered htlc" -> action -> htlc_id -> whose ctx -> ctn
'fails': {}, # "side who offered htlc" -> action -> htlc_id -> whose ctx -> ctn
'fee_updates': {}, # "side who initiated fee update" -> action -> list of FeeUpdates
'fee_updates': {}, # "side who initiated fee update" -> index -> list of FeeUpdates
'revack_pending': False,
'next_htlc_id': 0,
'ctn': -1, # oldest unrevoked ctx of sub

2
electrum/lnpeer.py

@ -1896,7 +1896,7 @@ class Peer(Logger):
self.logger.info("FEES HAVE FALLEN")
elif feerate_per_kw > chan_fee * 2:
self.logger.info("FEES HAVE RISEN")
elif chan.get_oldest_unrevoked_ctn(REMOTE) == 0:
elif chan.get_latest_ctn(REMOTE) == 0:
# workaround eclair issue https://github.com/ACINQ/eclair/issues/1730
self.logger.info("updating fee to bump remote ctn")
if feerate_per_kw == chan_fee:

2
electrum/lnwatcher.py

@ -431,7 +431,7 @@ class LNWalletWatcher(LNWatcher):
closing_txid=closing_txid,
closing_height=closing_height,
keep_watching=keep_watching)
await self.lnworker.on_channel_update(chan)
await self.lnworker.handle_onchain_state(chan)
@log_exceptions
async def do_breach_remedy(self, funding_outpoint, closing_tx, spenders):

4
electrum/lnworker.py

@ -609,7 +609,7 @@ class LNGossip(LNWorker):
orphaned_ids = [c['short_channel_id'] for c in orphaned]
await self.add_new_ids(orphaned_ids)
if categorized_chan_upds.good:
self.logger.debug(f'on_channel_update: {len(categorized_chan_upds.good)}/{len(chan_upds)}')
self.logger.debug(f'process_gossip: {len(categorized_chan_upds.good)}/{len(chan_upds)}')
class LNWallet(LNWorker):
@ -985,7 +985,7 @@ class LNWallet(LNWorker):
if chan.funding_outpoint.to_str() == txo:
return chan
async def on_channel_update(self, chan: Channel):
async def handle_onchain_state(self, chan: Channel):
if type(chan) is ChannelBackup:
util.trigger_callback('channel', self.wallet, chan)
return

Loading…
Cancel
Save