Skip to content

Commit ad52ba3

Browse files
authored
PeerPool refactoring and custom filtering (#7023)
* Add custom filters for PeerPool. * Update AllTests. * Eliminate unneeded constructions. * Address review comments. Fix clear() does not properly cleanup empties[] array. * Attempt to fix crash but still use binary search instead of linear. * Make iterators safe in async environment. * Add comments about iterators usage. * Address review comments.
1 parent 14e8b62 commit ad52ba3

File tree

4 files changed

+997
-482
lines changed

4 files changed

+997
-482
lines changed

AllTests-mainnet.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ AllTests-mainnet
791791
+ Access peers by key test OK
792792
+ Acquire from empty pool OK
793793
+ Acquire/Sorting and consistency test OK
794+
+ Custom filters test OK
794795
+ Delete peer on release text OK
795796
+ Iterators test OK
796797
+ Peer lifetime test OK

beacon_chain/networking/eth2_network.nim

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,12 @@ func netKbps*(peer: Peer): float {.inline.} =
480480
## Returns current network throughput average value in Kbps for peer ``peer``.
481481
round(((peer.netThroughput.average / 1024) * 10_000) / 10_000)
482482
483-
# /!\ Must be exported to be seen by `peerCmp`
484-
func `<`*(a, b: Peer): bool =
485-
## Comparison function indicating `true` if peer `a` ranks worse than peer `b`
486-
if a.score != b.score:
487-
a.score < b.score
488-
elif a.netThroughput.average != b.netThroughput.average:
489-
a.netThroughput.average < b.netThroughput.average
483+
# /!\ Must be exported to be seen by `peerpool`.
484+
func cmp*(a, b: Peer): int =
485+
if a.score == b.score:
486+
cmp(a.netThroughput.average, b.netThroughput.average)
490487
else:
491-
system.`<`(a, b)
488+
cmp(a.score, b.score)
492489
493490
const
494491
maxRequestQuota = 1000000

0 commit comments

Comments
 (0)