From 7ded8a1333593a355b38b9317e0be82e48964619 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sat, 19 Feb 2022 02:32:12 -0300 Subject: [PATCH] make active an explicit ordered dict --- lbry/dht/protocol/iterative_find.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lbry/dht/protocol/iterative_find.py b/lbry/dht/protocol/iterative_find.py index 409efcdb4..ab89edddc 100644 --- a/lbry/dht/protocol/iterative_find.py +++ b/lbry/dht/protocol/iterative_find.py @@ -1,6 +1,6 @@ import asyncio from itertools import chain -from collections import defaultdict +from collections import defaultdict, OrderedDict import typing import logging from typing import TYPE_CHECKING @@ -88,7 +88,7 @@ class IterativeFinder: self.max_results = max(constants.K, max_results) self.exclude = exclude or [] - self.active: typing.Dict['KademliaPeer', int] = {} # peer: distance, sorted + self.active: typing.Dict['KademliaPeer', int] = OrderedDict() # peer: distance, sorted self.contacted: typing.Set['KademliaPeer'] = set() self.distance = Distance(key) @@ -139,7 +139,7 @@ class IterativeFinder: return if peer not in self.active and peer.node_id and peer.node_id != self.protocol.node_id: self.active[peer] = self.distance(peer.node_id) - self.active = dict(sorted(self.active.items(), key=lambda item: item[1])) + self.active = OrderedDict(sorted(self.active.items(), key=lambda item: item[1])) async def _handle_probe_result(self, peer: 'KademliaPeer', response: FindResponse): self._add_active(peer)