diff --git a/electrum/interface.py b/electrum/interface.py index f67479fd8..a0c416a63 100644 --- a/electrum/interface.py +++ b/electrum/interface.py @@ -45,7 +45,7 @@ from aiorpcx.jsonrpc import JSONRPC, CodeMessageError 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 @@ -376,7 +376,7 @@ class Interface(Logger): # 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()) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 8be82c3c1..d9072c148 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -21,7 +21,7 @@ from . import bitcoin, util 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 @@ -105,7 +105,7 @@ class Peer(Logger): 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() diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 6c9e8ce92..b22824f79 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -39,7 +39,7 @@ from .crypto import sha256 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 @@ -200,7 +200,7 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]): 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] diff --git a/electrum/network.py b/electrum/network.py index b3e33f0e6..a24349427 100644 --- a/electrum/network.py +++ b/electrum/network.py @@ -45,7 +45,7 @@ from aiohttp import ClientResponse 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 @@ -1184,7 +1184,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]): 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 diff --git a/electrum/util.py b/electrum/util.py index 16012e573..a218dd668 100644 --- a/electrum/util.py +++ b/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) -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 @@ -1260,7 +1251,7 @@ class NetworkJobOnDefaultServer(Logger, ABC): """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