lnwatcher: keep_watching should wait at least until closing_tx is deep
Even if it decides there is nothing to sweep from the ctx/etc, it still needs to keep watching until a reorg-safe depth.
This commit is contained in:
@@ -99,6 +99,7 @@ class LNWatcher(Logger, EventListener):
|
|||||||
if not self.adb.is_mine(address):
|
if not self.adb.is_mine(address):
|
||||||
return
|
return
|
||||||
# inspect_tx_candidate might have added new addresses, in which case we return early
|
# inspect_tx_candidate might have added new addresses, in which case we return early
|
||||||
|
# note: maybe we should wait until adb.is_up_to_date... (?)
|
||||||
funding_txid = funding_outpoint.split(':')[0]
|
funding_txid = funding_outpoint.split(':')[0]
|
||||||
funding_height = self.adb.get_tx_height(funding_txid)
|
funding_height = self.adb.get_tx_height(funding_txid)
|
||||||
closing_txid = self.adb.get_spender(funding_outpoint)
|
closing_txid = self.adb.get_spender(funding_outpoint)
|
||||||
@@ -159,7 +160,9 @@ class LNWatcher(Logger, EventListener):
|
|||||||
return False
|
return False
|
||||||
# detect who closed and get information about how to claim outputs
|
# detect who closed and get information about how to claim outputs
|
||||||
is_local_ctx, sweep_info_dict = chan.get_ctx_sweep_info(closing_tx)
|
is_local_ctx, sweep_info_dict = chan.get_ctx_sweep_info(closing_tx)
|
||||||
keep_watching = False if sweep_info_dict else not self.adb.is_deeply_mined(closing_tx.txid())
|
# note: we need to keep watching *at least* until the closing tx is deeply mined,
|
||||||
|
# possibly longer if there are TXOs to sweep
|
||||||
|
keep_watching = not self.adb.is_deeply_mined(closing_tx.txid())
|
||||||
# create and broadcast transactions
|
# create and broadcast transactions
|
||||||
for prevout, sweep_info in sweep_info_dict.items():
|
for prevout, sweep_info in sweep_info_dict.items():
|
||||||
prev_txid, prev_index = prevout.split(':')
|
prev_txid, prev_index = prevout.split(':')
|
||||||
@@ -170,7 +173,7 @@ class LNWatcher(Logger, EventListener):
|
|||||||
self.logger.info(f'prevout does not exist for {name}: {prevout}')
|
self.logger.info(f'prevout does not exist for {name}: {prevout}')
|
||||||
continue
|
continue
|
||||||
was_added = self.maybe_redeem(sweep_info)
|
was_added = self.maybe_redeem(sweep_info)
|
||||||
spender_txid = self.adb.get_spender(prevout)
|
spender_txid = self.adb.get_spender(prevout) # note: LOCAL spenders don't count
|
||||||
spender_tx = self.adb.get_transaction(spender_txid) if spender_txid else None
|
spender_tx = self.adb.get_transaction(spender_txid) if spender_txid else None
|
||||||
if spender_tx:
|
if spender_tx:
|
||||||
# the spender might be the remote, revoked or not
|
# the spender might be the remote, revoked or not
|
||||||
|
|||||||
@@ -202,9 +202,10 @@ class WatchTower(Logger, EventListener):
|
|||||||
result.update(r)
|
result.update(r)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def sweep_commitment_transaction(self, funding_outpoint, closing_tx):
|
async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx: Transaction) -> bool:
|
||||||
|
assert closing_tx
|
||||||
spenders = self.inspect_tx_candidate(funding_outpoint, 0)
|
spenders = self.inspect_tx_candidate(funding_outpoint, 0)
|
||||||
keep_watching = False
|
keep_watching = not self.adb.is_deeply_mined(closing_tx.txid())
|
||||||
for prevout, spender in spenders.items():
|
for prevout, spender in spenders.items():
|
||||||
if spender is not None:
|
if spender is not None:
|
||||||
keep_watching |= not self.adb.is_deeply_mined(spender)
|
keep_watching |= not self.adb.is_deeply_mined(spender)
|
||||||
|
|||||||
Reference in New Issue
Block a user