1
0

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.
This commit is contained in:
f321x
2025-10-28 12:32:02 +01:00
parent d379a66a8f
commit 95ba7e7547

View File

@@ -33,6 +33,7 @@ import binascii
import base64 import base64
import asyncio import asyncio
import inspect import inspect
from asyncio import CancelledError
from collections import defaultdict from collections import defaultdict
from functools import wraps from functools import wraps
from decimal import Decimal, InvalidOperation from decimal import Decimal, InvalidOperation
@@ -44,6 +45,7 @@ import electrum_ecc as ecc
from . import util from . import util
from .lnmsg import OnionWireSerializer from .lnmsg import OnionWireSerializer
from .lnworker import LN_P2P_NETWORK_TIMEOUT
from .logging import Logger from .logging import Logger
from .onion_message import create_blinded_path, send_onion_message_to from .onion_message import create_blinded_path, send_onion_message_to
from .submarine_swaps import NostrTransport from .submarine_swaps import NostrTransport
@@ -1684,7 +1686,12 @@ class Commands(Logger):
arg:int:timeout:Timeout in seconds (default=20) arg:int:timeout:Timeout in seconds (default=20)
""" """
lnworker = self.network.lngossip if gossip else wallet.lnworker lnworker = self.network.lngossip if gossip else wallet.lnworker
await lnworker.add_peer(connection_string) peer = await lnworker.add_peer(connection_string)
try:
await util.wait_for2(peer.initialized, timeout=LN_P2P_NETWORK_TIMEOUT)
except (CancelledError, Exception) as e:
# FIXME often simply CancelledError and real cause (e.g. timeout) remains hidden
raise UserFacingException(f"Connection failed: {repr(e)}")
return True return True
@command('wnl') @command('wnl')