tFix bug with save_funding_height, save_closing_height (it would enter a state where only closing_height was saved) - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 3c111471e9bed1f8e0df43928435cc56a4fd3309 DIR parent 5b23d5ee979c7c6b23cfc3f6fc1f92a99dcab5f8 HTML Author: ThomasV <thomasv@electrum.org> Date: Sat, 7 Mar 2020 10:39:44 +0100 Fix bug with save_funding_height, save_closing_height (it would enter a state where only closing_height was saved) Diffstat: M electrum/lnchannel.py | 3 +++ M electrum/lnwatcher.py | 8 ++++++++ 2 files changed, 11 insertions(+), 0 deletions(-) --- DIR diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py t@@ -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 DIR diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py t@@ -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(): t@@ -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)