From 4d0ec8d1776e1d16c48d49855bd0d58311bdbaf4 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 30 Aug 2023 09:32:34 +0200 Subject: [PATCH] lnworker: choose IP address with recent timestamp (Rogach) --- electrum/lnworker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 295245c4a..b1b4837ae 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -512,8 +512,8 @@ class LNWorker(Logger, EventListener, NetworkRetryManager[LNPeerAddr]): @staticmethod def choose_preferred_address(addr_list: Sequence[Tuple[str, int, int]]) -> Tuple[str, int, int]: assert len(addr_list) >= 1 - # choose first one that is an IP - for host, port, timestamp in addr_list: + # choose the most recent one that is an IP + for host, port, timestamp in sorted(addr_list, key=lambda a: -a[2]): if is_ip_address(host): return host, port, timestamp # otherwise choose one at random