electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 956bd3baaf9ab22ff58ea4e24f83ee140aca2ada
parent 9e57a5961554a8c550868127f0a10d72327da4b8
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 30 Aug 2019 19:51:17 +0200

lnpeer: make per-peer TaskGroup a field (as for interfaces), and use it

lnpeer (and interface) response-handling-code should not run in the
network main_taskgroup as the remote could force an exception
to be raised and that would kill the whole network instead of just the peer

Diffstat:
Melectrum/lnpeer.py | 5+++--
Melectrum/lnworker.py | 7+++++--
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -24,7 +24,7 @@ from . import bitcoin from . import ecc from .ecc import sig_string_from_r_and_s, get_r_and_s_from_sig_string, der_sig_from_sig_string from . import constants -from .util import bh2u, bfh, log_exceptions, list_enabled_bits, ignore_exceptions, chunks +from .util import bh2u, bfh, log_exceptions, list_enabled_bits, ignore_exceptions, chunks, SilentTaskGroup from .transaction import Transaction, TxOutput from .logging import Logger from .lnonion import (new_onion_packet, decode_onion_error, OnionFailureCode, calc_hops_data_for_payment, @@ -90,6 +90,7 @@ class Peer(Logger): self._local_changed_events = defaultdict(asyncio.Event) self._remote_changed_events = defaultdict(asyncio.Event) Logger.__init__(self) + self.group = SilentTaskGroup() def send_message(self, message_name: str, **kwargs): assert type(message_name) is str @@ -231,7 +232,7 @@ class Peer(Logger): @log_exceptions @handle_disconnect async def main_loop(self): - async with aiorpcx.TaskGroup() as group: + async with self.group as group: await group.spawn(self._message_loop()) await group.spawn(self.query_gossip()) await group.spawn(self.process_gossip()) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -1102,8 +1102,11 @@ class LNWallet(LNWorker): if not chan.should_try_to_reestablish_peer(): continue peer = self.peers.get(chan.node_id, None) - coro = peer.reestablish_channel(chan) if peer else self.reestablish_peer_for_given_channel(chan) - await self.network.main_taskgroup.spawn(coro) + if peer: + await peer.group.spawn(peer.reestablish_channel(chan)) + else: + await self.network.main_taskgroup.spawn( + self.reestablish_peer_for_given_channel(chan)) def current_feerate_per_kw(self): from .simple_config import FEE_LN_ETA_TARGET, FEERATE_FALLBACK_STATIC_FEE, FEERATE_REGTEST_HARDCODED