electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 2a7b5081c911a4679d3fa34469aea786a20d1c61
parent 111ef9ebb11380cf2ee49b327988a8e21e99934b
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 14 Feb 2020 13:25:04 +0100

channel states: make sure that closing_txid is saved if channel is closed

Diffstat:
Melectrum/lnchannel.py | 6+++++-
Melectrum/lnworker.py | 11+++++++----
Melectrum/wallet.py | 2+-
3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py @@ -218,8 +218,12 @@ class Channel(Logger): def get_state(self): return self._state + def is_closing(self): + return self.get_state() in [channel_states.CLOSING, channel_states.FORCE_CLOSING] + def is_closed(self): - return self.get_state() > channel_states.OPEN + # the closing txid has been saved + return self.get_state() >= channel_states.CLOSED def _check_can_pay(self, amount_msat: int) -> None: # TODO check if this method uses correct ctns (should use "latest" + 1) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -562,6 +562,7 @@ class LNWallet(LNWorker): out.append(item) if not chan.is_closed(): continue + assert closing_txid item = { 'channel_id': bh2u(chan.channel_id), 'txid': closing_txid, @@ -657,6 +658,10 @@ class LNWallet(LNWorker): if not chan: return + # return early to prevent overwriting closing_txid with None + if chan.is_closed(): + return + # save timestamp regardless of state, so that funding tx is returned in get_history self.channel_timestamps[bh2u(chan.channel_id)] = chan.funding_outpoint.txid, funding_height.height, funding_height.timestamp, None, None, None @@ -701,14 +706,12 @@ class LNWallet(LNWorker): if not chan: return - # fixme: this is wasteful - self.channel_timestamps[bh2u(chan.channel_id)] = funding_txid, funding_height.height, funding_height.timestamp, closing_txid, closing_height.height, closing_height.timestamp - # remove from channel_db if chan.short_channel_id is not None: self.channel_db.remove_channel(chan.short_channel_id) if chan.get_state() < channel_states.CLOSED: + self.channel_timestamps[bh2u(chan.channel_id)] = funding_txid, funding_height.height, funding_height.timestamp, closing_txid, closing_height.height, closing_height.timestamp chan.set_state(channel_states.CLOSED) if chan.get_state() == channel_states.CLOSED and not keep_watching: @@ -1309,7 +1312,7 @@ class LNWallet(LNWorker): with self.lock: channels = list(self.channels.values()) for chan in channels: - if chan.is_closed(): + if chan.is_closed() or chan.is_closing(): continue if constants.net is not constants.BitcoinRegtest: chan_feerate = chan.get_latest_feerate(LOCAL) diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -729,7 +729,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): tx_item['lightning'] = True tx_item['ln_value'] = Satoshis(ln_value) tx_item['txpos'] = i # for sorting - key = tx_item['payment_hash'] if 'payment_hash' in tx_item else tx_item['type'] + tx_item['channel_id'] + key = tx_item.get('txid') or tx_item['payment_hash'] transactions[key] = tx_item now = time.time() balance = 0