From 40242ac277912d692e434936efb481219dd1f190 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Wed, 27 Mar 2024 23:10:09 +0100 Subject: [PATCH] rank peers by their score instead of their memory address The `<` function to compare peers was not exported, leading to the same peer be acquired over and over again until kick. `mixin` doesn't pull it into `peerCmp` without `*` export, and with the export no mixin needed. --- beacon_chain/networking/eth2_network.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 4c2628e4f..39369e9f3 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -456,15 +456,15 @@ func netKbps*(peer: Peer): float {.inline.} = ## Returns current network throughput average value in Kbps for peer ``peer``. round(((peer.netThroughput.average / 1024) * 10_000) / 10_000) -func `<`(a, b: Peer): bool = - ## Comparison function, which first checks peer's scores, and if the peers' - ## score is equal it compares peers' network throughput. - if a.score < b.score: - true - elif a.score == b.score: - (a.netThroughput.average < b.netThroughput.average) +# /!\ Must be exported to be seen by `peerCmp` +func `<`*(a, b: Peer): bool = + ## Comparison function indicating `true` if peer `a` ranks worse than peer `b` + if a.score != b.score: + a.score < b.score + elif a.netThroughput.average != b.netThroughput.average: + a.netThroughput.average < b.netThroughput.average else: - false + system.`<`(a, b) const maxRequestQuota = 1000000