From 02e45690868bd1fd86b92329697cf9539edb8747 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 12 Jul 2022 10:13:19 +0200 Subject: [PATCH] auto-remove redeemed channel backups. fix indentation. --- electrum/lnchannel.py | 20 +++++++++++++------- electrum/lnwatcher.py | 11 ++++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py index 37c351852..456d6e610 100644 --- a/electrum/lnchannel.py +++ b/electrum/lnchannel.py @@ -282,13 +282,16 @@ class AbstractChannel(Logger, ABC): if funding_height.height == TX_HEIGHT_LOCAL: self.update_unfunded_state() elif closing_height.height == TX_HEIGHT_LOCAL: - self.update_funded_state(funding_txid=funding_txid, funding_height=funding_height) + self.update_funded_state( + funding_txid=funding_txid, + funding_height=funding_height) else: - self.update_closed_state(funding_txid=funding_txid, - funding_height=funding_height, - closing_txid=closing_txid, - closing_height=closing_height, - keep_watching=keep_watching) + self.update_closed_state( + funding_txid=funding_txid, + funding_height=funding_height, + closing_txid=closing_txid, + closing_height=closing_height, + keep_watching=keep_watching) def update_unfunded_state(self): self.delete_funding_height() @@ -314,7 +317,7 @@ class AbstractChannel(Logger, ABC): break else: now = int(time.time()) - if now - self.storage.get('init_timestamp', 0) > CHANNEL_OPENING_TIMEOUT: + if self.lnworker and (now - self.storage.get('init_timestamp', 0) > CHANNEL_OPENING_TIMEOUT): self.lnworker.remove_channel(self.channel_id) def update_funded_state(self, *, funding_txid: str, funding_height: TxMinedInfo) -> None: @@ -348,6 +351,9 @@ class AbstractChannel(Logger, ABC): if self.get_state() == ChannelState.CLOSED and not keep_watching: self.set_state(ChannelState.REDEEMED) + if self.lnworker and self.is_backup(): + # auto-remove redeemed backups + self.lnworker.remove_channel_backup(self.channel_id) @property def sweep_address(self) -> str: diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py index 39c8130d5..055202f28 100644 --- a/electrum/lnwatcher.py +++ b/electrum/lnwatcher.py @@ -425,11 +425,12 @@ class LNWalletWatcher(LNWatcher): chan = self.lnworker.channel_by_txo(funding_outpoint) if not chan: return - chan.update_onchain_state(funding_txid=funding_txid, - funding_height=funding_height, - closing_txid=closing_txid, - closing_height=closing_height, - keep_watching=keep_watching) + chan.update_onchain_state( + funding_txid=funding_txid, + funding_height=funding_height, + closing_txid=closing_txid, + closing_height=closing_height, + keep_watching=keep_watching) await self.lnworker.on_channel_update(chan) @log_exceptions