diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py index 64ef7a59e..675ca9087 100644 --- a/electrum/lnchannel.py +++ b/electrum/lnchannel.py @@ -372,6 +372,9 @@ class Channel(Logger): def get_closing_height(self): return self.storage.get('closing_height') + def delete_closing_height(self): + self.storage.pop('closing_height', None) + def is_redeemed(self): return self.get_state() == channel_states.REDEEMED diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py index 0a6320f16..9ff3efe9c 100644 --- a/electrum/lnwatcher.py +++ b/electrum/lnwatcher.py @@ -174,6 +174,9 @@ class LNWatcher(AddressSynchronizer): await self.check_onchain_situation(address, outpoint) async def check_onchain_situation(self, address, funding_outpoint): + # early return if address has not been added yet + if not self.is_mine(address): + return spenders = self.inspect_tx_candidate(funding_outpoint, 0) # inspect_tx_candidate might have added new addresses, in which case we return ealy if not self.is_up_to_date(): @@ -335,16 +338,21 @@ class LNWalletWatcher(LNWatcher): @ignore_exceptions @log_exceptions async def update_channel_state(self, funding_outpoint, funding_txid, funding_height, closing_txid, closing_height, keep_watching): + # note: state transitions are irreversible, but + # save_funding_height, save_closing_height are reversible chan = self.lnworker.channel_by_txo(funding_outpoint) if not chan: return if funding_height.height == TX_HEIGHT_LOCAL: chan.delete_funding_height() + chan.delete_closing_height() await self.lnworker.update_unfunded_channel(chan, funding_txid) elif closing_height.height == TX_HEIGHT_LOCAL: chan.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp) + chan.delete_closing_height() await self.lnworker.update_open_channel(chan, funding_txid, funding_height) else: + chan.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp) chan.save_closing_height(closing_txid, closing_height.height, closing_height.timestamp) await self.lnworker.update_closed_channel(chan, funding_txid, funding_height, closing_txid, closing_height, keep_watching)