1
0

Fix bug with save_funding_height, save_closing_height

(it would enter a state where only closing_height was saved)
This commit is contained in:
ThomasV
2020-03-07 10:39:44 +01:00
parent 5b23d5ee97
commit 3c111471e9
2 changed files with 11 additions and 0 deletions

View File

@@ -372,6 +372,9 @@ class Channel(Logger):
def get_closing_height(self): def get_closing_height(self):
return self.storage.get('closing_height') return self.storage.get('closing_height')
def delete_closing_height(self):
self.storage.pop('closing_height', None)
def is_redeemed(self): def is_redeemed(self):
return self.get_state() == channel_states.REDEEMED return self.get_state() == channel_states.REDEEMED

View File

@@ -174,6 +174,9 @@ class LNWatcher(AddressSynchronizer):
await self.check_onchain_situation(address, outpoint) await self.check_onchain_situation(address, outpoint)
async def check_onchain_situation(self, address, funding_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) spenders = self.inspect_tx_candidate(funding_outpoint, 0)
# inspect_tx_candidate might have added new addresses, in which case we return ealy # inspect_tx_candidate might have added new addresses, in which case we return ealy
if not self.is_up_to_date(): if not self.is_up_to_date():
@@ -335,16 +338,21 @@ class LNWalletWatcher(LNWatcher):
@ignore_exceptions @ignore_exceptions
@log_exceptions @log_exceptions
async def update_channel_state(self, funding_outpoint, funding_txid, funding_height, closing_txid, closing_height, keep_watching): 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) chan = self.lnworker.channel_by_txo(funding_outpoint)
if not chan: if not chan:
return return
if funding_height.height == TX_HEIGHT_LOCAL: if funding_height.height == TX_HEIGHT_LOCAL:
chan.delete_funding_height() chan.delete_funding_height()
chan.delete_closing_height()
await self.lnworker.update_unfunded_channel(chan, funding_txid) await self.lnworker.update_unfunded_channel(chan, funding_txid)
elif closing_height.height == TX_HEIGHT_LOCAL: elif closing_height.height == TX_HEIGHT_LOCAL:
chan.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp) 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) await self.lnworker.update_open_channel(chan, funding_txid, funding_height)
else: 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) 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) await self.lnworker.update_closed_channel(chan, funding_txid, funding_height, closing_txid, closing_height, keep_watching)