Skip to content

Commit 3f755e1

Browse files
authored
Merge pull request #9988 from SomberNight/202506_txbatcher_cleanup
txbatcher: add type-hints
2 parents c2b99f0 + 2b92e8a commit 3f755e1

File tree

3 files changed

+92
-75
lines changed

3 files changed

+92
-75
lines changed

electrum/lnwatcher.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file LICENCE or http://www.opensource.org/licenses/mit-license.php
44

5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Optional
66

77
from . import util
88
from .util import TxMinedInfo, BelowDustLimit
@@ -88,13 +88,13 @@ def add_channel(self, chan: 'AbstractChannel') -> None:
8888
if chan.need_to_subscribe():
8989
self.add_callback(address, callback)
9090

91-
def unwatch_channel(self, address, funding_outpoint):
91+
def unwatch_channel(self, address: str, funding_outpoint: str) -> None:
9292
self.logger.info(f'unwatching {funding_outpoint}')
9393
self.remove_callback(address)
9494

9595
@ignore_exceptions
9696
@log_exceptions
97-
async def check_onchain_situation(self, address, funding_outpoint):
97+
async def check_onchain_situation(self, address: str, funding_outpoint: str) -> None:
9898
# early return if address has not been added yet
9999
if not self.adb.is_mine(address):
100100
return
@@ -142,17 +142,18 @@ async def update_channel_state(
142142
self._pending_force_closes.discard(chan)
143143
await self.lnworker.handle_onchain_state(chan)
144144

145-
async def sweep_commitment_transaction(self, funding_outpoint, closing_tx) -> bool:
145+
async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx: Transaction) -> bool:
146146
"""This function is called when a channel was closed. In this case
147147
we need to check for redeemable outputs of the commitment transaction
148148
or spenders down the line (HTLC-timeout/success transactions).
149149
150150
Returns whether we should continue to monitor.
151151
152-
Side-effécts:
152+
Side-effects:
153153
- sets defaults labels
154154
- populates wallet._accounting_addresses
155155
"""
156+
assert closing_tx
156157
chan = self.lnworker.channel_by_txo(funding_outpoint)
157158
if not chan:
158159
return False
@@ -188,7 +189,8 @@ async def sweep_commitment_transaction(self, funding_outpoint, closing_tx) -> bo
188189
self.maybe_add_accounting_address(spender_txid, sweep_info)
189190
else:
190191
keep_watching |= was_added
191-
self.maybe_add_pending_forceclose(chan, spender_txid, is_local_ctx, sweep_info, was_added)
192+
self.maybe_add_pending_forceclose(
193+
chan=chan, spender_txid=spender_txid, is_local_ctx=is_local_ctx, sweep_info=sweep_info, was_added=was_added)
192194
return keep_watching
193195

194196
def get_pending_force_closes(self):
@@ -242,7 +244,15 @@ def maybe_add_accounting_address(self, spender_txid: str, sweep_info: 'SweepInfo
242244
txout = prev_tx.outputs()[int(prev_index)]
243245
self.lnworker.wallet._accounting_addresses.add(txout.address)
244246

245-
def maybe_add_pending_forceclose(self, chan, spender_txid, is_local_ctx, sweep_info, was_added):
247+
def maybe_add_pending_forceclose(
248+
self,
249+
*,
250+
chan: 'AbstractChannel',
251+
spender_txid: Optional[str],
252+
is_local_ctx: bool,
253+
sweep_info: 'SweepInfo',
254+
was_added: bool,
255+
):
246256
""" we are waiting for ctx to be confirmed and there are received htlcs """
247257
if was_added and is_local_ctx and sweep_info.name == 'received-htlc' and chan.has_anchors():
248258
tx_mined_status = self.adb.get_tx_height(spender_txid)

electrum/lnworker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ def channel_by_txo(self, txo: str) -> Optional[AbstractChannel]:
12111211
for chan in self.channel_backups.values():
12121212
if chan.funding_outpoint.to_str() == txo:
12131213
return chan
1214+
return None
12141215

12151216
async def handle_onchain_state(self, chan: Channel):
12161217
if self.network is None:
@@ -1511,6 +1512,7 @@ def get_channel_by_short_id(self, short_channel_id: bytes) -> Optional[Channel]:
15111512
return chan
15121513
if chan.get_local_scid_alias() == short_channel_id:
15131514
return chan
1515+
return None
15141516

15151517
def can_pay_invoice(self, invoice: Invoice) -> bool:
15161518
assert invoice.is_lightning()

0 commit comments

Comments
 (0)