Skip to content

Commit

Permalink
util: rm SilentTaskGroup. this does not seem to be needed anymore
Browse files Browse the repository at this point in the history
I think this was originally needed due to incorrect management of group lifecycles,
which our current code is doing better.

also note that if we needed this, in newer aiorpcx, the name of
the field was ~changed from `_closed` to `joined`:
kyuupichan/aiorpcX@2390026
  • Loading branch information
SomberNight committed Feb 8, 2022
1 parent 259c1fe commit 5eebc00
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions electrum/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from aiorpcx.rawsocket import RSClient
import certifi

from .util import (ignore_exceptions, log_exceptions, bfh, SilentTaskGroup, MySocksProxy,
from .util import (ignore_exceptions, log_exceptions, bfh, MySocksProxy,
is_integer, is_non_negative_integer, is_hash256_str, is_hex_str,
is_int_or_float, is_non_negative_int_or_float)
from . import util
Expand Down Expand Up @@ -376,7 +376,7 @@ def __init__(self, *, network: 'Network', server: ServerAddr, proxy: Optional[di
# Dump network messages (only for this interface). Set at runtime from the console.
self.debug = False

self.taskgroup = SilentTaskGroup()
self.taskgroup = TaskGroup()

async def spawn_task():
task = await self.network.taskgroup.spawn(self.run())
Expand Down
4 changes: 2 additions & 2 deletions electrum/lnpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from . import ecc
from .ecc import sig_string_from_r_and_s, der_sig_from_sig_string
from . import constants
from .util import (bh2u, bfh, log_exceptions, ignore_exceptions, chunks, SilentTaskGroup,
from .util import (bh2u, bfh, log_exceptions, ignore_exceptions, chunks, TaskGroup,
UnrelatedTransactionException)
from . import transaction
from .bitcoin import make_op_return
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(
self.announcement_signatures = defaultdict(asyncio.Queue)
self.orphan_channel_updates = OrderedDict() # type: OrderedDict[ShortChannelID, dict]
Logger.__init__(self)
self.taskgroup = SilentTaskGroup()
self.taskgroup = TaskGroup()
# HTLCs offered by REMOTE, that we started removing but are still active:
self.received_htlcs_pending_removal = set() # type: Set[Tuple[Channel, int]]
self.received_htlc_removed_event = asyncio.Event()
Expand Down
4 changes: 2 additions & 2 deletions electrum/lnworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .bip32 import BIP32Node
from .util import bh2u, bfh, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
from .crypto import chacha20_encrypt, chacha20_decrypt
from .util import ignore_exceptions, make_aiohttp_session, SilentTaskGroup
from .util import ignore_exceptions, make_aiohttp_session
from .util import timestamp_to_datetime, random_shuffled_copy
from .util import MyEncoder, is_private_netaddress
from .logging import Logger
Expand Down Expand Up @@ -200,7 +200,7 @@ def __init__(self, xprv, features: LnFeatures):
self.node_keypair = generate_keypair(BIP32Node.from_xkey(xprv), LnKeyFamily.NODE_KEY)
self.backup_key = generate_keypair(BIP32Node.from_xkey(xprv), LnKeyFamily.BACKUP_CIPHER).privkey
self._peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer # needs self.lock
self.taskgroup = SilentTaskGroup()
self.taskgroup = TaskGroup()
self.listen_server = None # type: Optional[asyncio.AbstractServer]
self.features = features
self.network = None # type: Optional[Network]
Expand Down
4 changes: 2 additions & 2 deletions electrum/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

from . import util
from .util import (log_exceptions, ignore_exceptions,
bfh, SilentTaskGroup, make_aiohttp_session, send_exception_to_crash_reporter,
bfh, make_aiohttp_session, send_exception_to_crash_reporter,
is_hash256_str, is_non_negative_integer, MyEncoder, NetworkRetryManager,
nullcontext)
from .bitcoin import COIN
Expand Down Expand Up @@ -1184,7 +1184,7 @@ def export_checkpoints(self, path):

async def _start(self):
assert not self.taskgroup
self.taskgroup = taskgroup = SilentTaskGroup()
self.taskgroup = taskgroup = TaskGroup()
assert not self.interface and not self.interfaces
assert not self._connecting_ifaces
assert not self._closing_ifaces
Expand Down
11 changes: 1 addition & 10 deletions electrum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,15 +1226,6 @@ def make_aiohttp_session(proxy: Optional[dict], headers=None, timeout=None):
return aiohttp.ClientSession(headers=headers, timeout=timeout, connector=connector)


class SilentTaskGroup(TaskGroup):

def spawn(self, *args, **kwargs):
# don't complain if group is already closed.
if self._closed:
raise asyncio.CancelledError()
return super().spawn(*args, **kwargs)


class NetworkJobOnDefaultServer(Logger, ABC):
"""An abstract base class for a job that runs on the main network
interface. Every time the main interface changes, the job is
Expand All @@ -1260,7 +1251,7 @@ def _reset(self):
"""Initialise fields. Called every time the underlying
server connection changes.
"""
self.taskgroup = SilentTaskGroup()
self.taskgroup = TaskGroup()

async def _start(self, interface: 'Interface'):
self.interface = interface
Expand Down

0 comments on commit 5eebc00

Please sign in to comment.