1
0

wallet: store wanted_height in future_tx, instead of remaining blocks

This commit is contained in:
ThomasV
2021-03-22 11:00:42 +01:00
parent 03d9b29eee
commit aa1fcc784e
2 changed files with 15 additions and 14 deletions

View File

@@ -411,16 +411,16 @@ class LNWalletWatcher(LNWatcher):
async def try_redeem(self, prevout: str, sweep_info: 'SweepInfo', chan_id_for_log: str, name: str) -> None:
prev_txid, prev_index = prevout.split(':')
broadcast = True
local_height = self.network.get_local_height()
if sweep_info.cltv_expiry:
local_height = self.network.get_local_height()
remaining = sweep_info.cltv_expiry - local_height
if remaining > 0:
wanted_height = sweep_info.cltv_expiry - local_height
if wanted_height - local_height > 0:
broadcast = False
reason = 'waiting for {}: CLTV ({} > {}), prevout {}'.format(name, local_height, sweep_info.cltv_expiry, prevout)
if sweep_info.csv_delay:
prev_height = self.get_tx_height(prev_txid)
remaining = sweep_info.csv_delay - prev_height.conf
if remaining > 0:
wanted_height = sweep_info.csv_delay + prev_height.height - 1
if wanted_height - local_height > 0:
broadcast = False
reason = 'waiting for {}: CSV ({} >= {}), prevout: {}'.format(name, prev_height.conf, sweep_info.csv_delay, prevout)
tx = sweep_info.gen_tx()
@@ -432,13 +432,13 @@ class LNWalletWatcher(LNWatcher):
if broadcast:
await self.network.try_broadcasting(tx, name)
else:
if self.lnworker.wallet.db.get_transaction(txid):
if txid in self.lnworker.wallet.future_tx:
return
self.logger.debug(f'(chan {chan_id_for_log}) trying to redeem {name}: {prevout}')
self.logger.info(reason)
# it's OK to add local transaction, the fee will be recomputed
try:
tx_was_added = self.lnworker.wallet.add_future_tx(tx, remaining)
tx_was_added = self.lnworker.wallet.add_future_tx(tx, wanted_height)
except Exception as e:
self.logger.info(f'could not add future tx: {name}. prevout: {prevout} {str(e)}')
tx_was_added = False