From 95ba7e7547eb7d1a016793d363dd71410eacab76 Mon Sep 17 00:00:00 2001 From: f321x Date: Tue, 28 Oct 2025 12:32:02 +0100 Subject: [PATCH] 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. --- electrum/commands.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/electrum/commands.py b/electrum/commands.py index 2b2312138..8e350def0 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -33,6 +33,7 @@ import binascii import base64 import asyncio import inspect +from asyncio import CancelledError from collections import defaultdict from functools import wraps from decimal import Decimal, InvalidOperation @@ -44,6 +45,7 @@ import electrum_ecc as ecc from . import util from .lnmsg import OnionWireSerializer +from .lnworker import LN_P2P_NETWORK_TIMEOUT from .logging import Logger from .onion_message import create_blinded_path, send_onion_message_to from .submarine_swaps import NostrTransport @@ -1684,7 +1686,12 @@ class Commands(Logger): arg:int:timeout:Timeout in seconds (default=20) """ 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 @command('wnl')