Browse Source

util: rm SilentTaskGroup. this does not seem to be needed anymore

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`:
239002689a
patch-4
SomberNight 3 years ago
parent
commit
c131831373
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/interface.py
  2. 4
      electrum/lnpeer.py
  3. 4
      electrum/lnworker.py
  4. 4
      electrum/network.py
  5. 11
      electrum/util.py

4
electrum/interface.py

@ -45,7 +45,7 @@ from aiorpcx.jsonrpc import JSONRPC, CodeMessageError
from aiorpcx.rawsocket import RSClient from aiorpcx.rawsocket import RSClient
import certifi 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_integer, is_non_negative_integer, is_hash256_str, is_hex_str,
is_int_or_float, is_non_negative_int_or_float) is_int_or_float, is_non_negative_int_or_float)
from . import util from . import util
@ -376,7 +376,7 @@ class Interface(Logger):
# Dump network messages (only for this interface). Set at runtime from the console. # Dump network messages (only for this interface). Set at runtime from the console.
self.debug = False self.debug = False
self.taskgroup = SilentTaskGroup() self.taskgroup = TaskGroup()
async def spawn_task(): async def spawn_task():
task = await self.network.taskgroup.spawn(self.run()) task = await self.network.taskgroup.spawn(self.run())

4
electrum/lnpeer.py

@ -21,7 +21,7 @@ from . import bitcoin, util
from . import ecc from . import ecc
from .ecc import sig_string_from_r_and_s, der_sig_from_sig_string from .ecc import sig_string_from_r_and_s, der_sig_from_sig_string
from . import constants 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) UnrelatedTransactionException)
from . import transaction from . import transaction
from .bitcoin import make_op_return from .bitcoin import make_op_return
@ -105,7 +105,7 @@ class Peer(Logger):
self.announcement_signatures = defaultdict(asyncio.Queue) self.announcement_signatures = defaultdict(asyncio.Queue)
self.orphan_channel_updates = OrderedDict() # type: OrderedDict[ShortChannelID, dict] self.orphan_channel_updates = OrderedDict() # type: OrderedDict[ShortChannelID, dict]
Logger.__init__(self) Logger.__init__(self)
self.taskgroup = SilentTaskGroup() self.taskgroup = TaskGroup()
# HTLCs offered by REMOTE, that we started removing but are still active: # 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_htlcs_pending_removal = set() # type: Set[Tuple[Channel, int]]
self.received_htlc_removed_event = asyncio.Event() self.received_htlc_removed_event = asyncio.Event()

4
electrum/lnworker.py

@ -39,7 +39,7 @@ from .crypto import sha256
from .bip32 import BIP32Node from .bip32 import BIP32Node
from .util import bh2u, bfh, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions from .util import bh2u, bfh, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
from .crypto import chacha20_encrypt, chacha20_decrypt 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 timestamp_to_datetime, random_shuffled_copy
from .util import MyEncoder, is_private_netaddress from .util import MyEncoder, is_private_netaddress
from .logging import Logger from .logging import Logger
@ -200,7 +200,7 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]):
self.node_keypair = generate_keypair(BIP32Node.from_xkey(xprv), LnKeyFamily.NODE_KEY) 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.backup_key = generate_keypair(BIP32Node.from_xkey(xprv), LnKeyFamily.BACKUP_CIPHER).privkey
self._peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer # needs self.lock 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.listen_server = None # type: Optional[asyncio.AbstractServer]
self.features = features self.features = features
self.network = None # type: Optional[Network] self.network = None # type: Optional[Network]

4
electrum/network.py

@ -45,7 +45,7 @@ from aiohttp import ClientResponse
from . import util from . import util
from .util import (log_exceptions, ignore_exceptions, 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, is_hash256_str, is_non_negative_integer, MyEncoder, NetworkRetryManager,
nullcontext) nullcontext)
from .bitcoin import COIN from .bitcoin import COIN
@ -1184,7 +1184,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
async def _start(self): async def _start(self):
assert not self.taskgroup assert not self.taskgroup
self.taskgroup = taskgroup = SilentTaskGroup() self.taskgroup = taskgroup = TaskGroup()
assert not self.interface and not self.interfaces assert not self.interface and not self.interfaces
assert not self._connecting_ifaces assert not self._connecting_ifaces
assert not self._closing_ifaces assert not self._closing_ifaces

11
electrum/util.py

@ -1226,15 +1226,6 @@ def make_aiohttp_session(proxy: Optional[dict], headers=None, timeout=None):
return aiohttp.ClientSession(headers=headers, timeout=timeout, connector=connector) 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): class NetworkJobOnDefaultServer(Logger, ABC):
"""An abstract base class for a job that runs on the main network """An abstract base class for a job that runs on the main network
interface. Every time the main interface changes, the job is interface. Every time the main interface changes, the job is
@ -1260,7 +1251,7 @@ class NetworkJobOnDefaultServer(Logger, ABC):
"""Initialise fields. Called every time the underlying """Initialise fields. Called every time the underlying
server connection changes. server connection changes.
""" """
self.taskgroup = SilentTaskGroup() self.taskgroup = TaskGroup()
async def _start(self, interface: 'Interface'): async def _start(self, interface: 'Interface'):
self.interface = interface self.interface = interface

Loading…
Cancel
Save