Skip to content

Commit 928e242

Browse files
committed
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.
1 parent 50d48ae commit 928e242

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

electrum/lnwatcher.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ async def check_onchain_situation(self, address: str, funding_outpoint: str) ->
9999
if not self.adb.is_mine(address):
100100
return
101101
# inspect_tx_candidate might have added new addresses, in which case we return early
102+
# note: maybe we should wait until adb.is_up_to_date... (?)
102103
funding_txid = funding_outpoint.split(':')[0]
103104
funding_height = self.adb.get_tx_height(funding_txid)
104105
closing_txid = self.adb.get_spender(funding_outpoint)
@@ -159,7 +160,9 @@ async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx:
159160
return False
160161
# detect who closed and get information about how to claim outputs
161162
is_local_ctx, sweep_info_dict = chan.get_ctx_sweep_info(closing_tx)
162-
keep_watching = False if sweep_info_dict else not self.adb.is_deeply_mined(closing_tx.txid())
163+
# note: we need to keep watching *at least* until the closing tx is deeply mined,
164+
# possibly longer if there are TXOs to sweep
165+
keep_watching = not self.adb.is_deeply_mined(closing_tx.txid())
163166
# create and broadcast transactions
164167
for prevout, sweep_info in sweep_info_dict.items():
165168
prev_txid, prev_index = prevout.split(':')
@@ -170,7 +173,7 @@ async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx:
170173
self.logger.info(f'prevout does not exist for {name}: {prevout}')
171174
continue
172175
was_added = self.maybe_redeem(sweep_info)
173-
spender_txid = self.adb.get_spender(prevout)
176+
spender_txid = self.adb.get_spender(prevout) # note: LOCAL spenders don't count
174177
spender_tx = self.adb.get_transaction(spender_txid) if spender_txid else None
175178
if spender_tx:
176179
# the spender might be the remote, revoked or not

electrum/plugins/watchtower/watchtower.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ def inspect_tx_candidate(self, outpoint, n: int) -> Dict[str, str]:
202202
result.update(r)
203203
return result
204204

205-
async def sweep_commitment_transaction(self, funding_outpoint, closing_tx):
205+
async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx: Transaction) -> bool:
206+
assert closing_tx
206207
spenders = self.inspect_tx_candidate(funding_outpoint, 0)
207-
keep_watching = False
208+
keep_watching = not self.adb.is_deeply_mined(closing_tx.txid())
208209
for prevout, spender in spenders.items():
209210
if spender is not None:
210211
keep_watching |= not self.adb.is_deeply_mined(spender)

0 commit comments

Comments
 (0)