Browse Source

Fix bug with save_funding_height, save_closing_height

(it would enter a state where only closing_height was saved)
hard-fail-on-bad-server-string
ThomasV 5 years ago
parent
commit
3c111471e9
  1. 3
      electrum/lnchannel.py
  2. 8
      electrum/lnwatcher.py

3
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

8
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)

Loading…
Cancel
Save