commit adaa016e78667b3051b8661a8b0387a6a04557a4
parent 2ce8dd460b254bf56c5fbad38aadbaad41331316
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 29 Nov 2019 00:53:18 +0100
LNPeerAddr: fix equality tests and hence lnworker._last_tried_peer
follow-up 13d69973555fef8802cce264f7ea324e89e36684
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/electrum/lnutil.py b/electrum/lnutil.py
@@ -684,6 +684,19 @@ class LNPeerAddr:
def net_addr_str(self) -> str:
return self._net_addr_str
+ def __eq__(self, other):
+ if not isinstance(other, LNPeerAddr):
+ return False
+ return (self.host == other.host
+ and self.port == other.port
+ and self.pubkey == other.pubkey)
+
+ def __ne__(self, other):
+ return not (self == other)
+
+ def __hash__(self):
+ return hash((self.host, self.port, self.pubkey))
+
def get_compressed_pubkey_from_bech32(bech32_pubkey: str) -> bytes:
hrp, data_5bits = segwit_addr.bech32_decode(bech32_pubkey)
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -186,7 +186,7 @@ class LNWorker(Logger):
self.network = network
self.config = network.config
self.channel_db = self.network.channel_db
- self._last_tried_peer = {} # LNPeerAddr -> unix timestamp
+ self._last_tried_peer = {} # type: Dict[LNPeerAddr, float] # LNPeerAddr -> unix timestamp
self._add_peers_from_config()
asyncio.run_coroutine_threadsafe(self.network.main_taskgroup.spawn(self.main_loop()), self.network.asyncio_loop)