mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 09:37:31 +00:00
channel states: make sure that closing_txid is saved if channel is closed
This commit is contained in:
parent
111ef9ebb1
commit
2a7b5081c9
3 changed files with 13 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue