Skip to content

Commit 95ba7e7

Browse files
committed
cli: add_peer: make add_peer wait for connection
peer initialization was never awaited in the `add_peer` method. This awaits the initialization of the peer so that the caller actually knows if connection succeeded or timed out.
1 parent d379a66 commit 95ba7e7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

electrum/commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import base64
3434
import asyncio
3535
import inspect
36+
from asyncio import CancelledError
3637
from collections import defaultdict
3738
from functools import wraps
3839
from decimal import Decimal, InvalidOperation
@@ -44,6 +45,7 @@
4445

4546
from . import util
4647
from .lnmsg import OnionWireSerializer
48+
from .lnworker import LN_P2P_NETWORK_TIMEOUT
4749
from .logging import Logger
4850
from .onion_message import create_blinded_path, send_onion_message_to
4951
from .submarine_swaps import NostrTransport
@@ -1684,7 +1686,12 @@ async def add_peer(self, connection_string, timeout=20, gossip=False, wallet: Ab
16841686
arg:int:timeout:Timeout in seconds (default=20)
16851687
"""
16861688
lnworker = self.network.lngossip if gossip else wallet.lnworker
1687-
await lnworker.add_peer(connection_string)
1689+
peer = await lnworker.add_peer(connection_string)
1690+
try:
1691+
await util.wait_for2(peer.initialized, timeout=LN_P2P_NETWORK_TIMEOUT)
1692+
except (CancelledError, Exception) as e:
1693+
# FIXME often simply CancelledError and real cause (e.g. timeout) remains hidden
1694+
raise UserFacingException(f"Connection failed: {repr(e)}")
16881695
return True
16891696

16901697
@command('wnl')

0 commit comments

Comments
 (0)