diff --git a/electrum/commands.py b/electrum/commands.py index 9a50100c4..695632be0 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -776,7 +776,9 @@ class Commands: # lightning network commands @command('wn') def add_peer(self, connection_string, timeout=20): - return self.lnworker.add_peer(connection_string) + coro = self.lnworker.add_peer(connection_string) + self.network.run_from_another_thread(coro, timeout=timeout) + return True @command('wpn') def open_channel(self, connection_string, amount, channel_push=0, password=None): diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 3626579c4..1d86a7704 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -643,7 +643,7 @@ class LNWallet(LNWorker): def on_channels_updated(self): self.network.trigger_callback('channels') - async def add_peer(self, connect_str, timeout=20): + async def add_peer(self, connect_str: str) -> Peer: node_id, rest = extract_nodeid(connect_str) peer = self.peers.get(node_id) if not peer: diff --git a/electrum/network.py b/electrum/network.py index d42873a9a..2158081c3 100644 --- a/electrum/network.py +++ b/electrum/network.py @@ -311,10 +311,10 @@ class Network(Logger): self.lnwatcher = None self.lngossip = None - def run_from_another_thread(self, coro): + def run_from_another_thread(self, coro, *, timeout=None): assert self._loop_thread != threading.current_thread(), 'must not be called from network thread' fut = asyncio.run_coroutine_threadsafe(coro, self.asyncio_loop) - return fut.result() + return fut.result(timeout) @staticmethod def get_instance() -> Optional["Network"]: