Skip to content

Commit 121cf99

Browse files
FAB-1723 Fix peers filtering for gossip push/pull
File gossip/filter/filter.go Method SelectPeer - in case of small k, log(membership) for example, and many small channels in most cases it will return empty list - as first step it choose k peers from membership and only after that filter them, as result it will remain with zero peers Correct way to implement it is filter peers first and only after that choose k peers from filtered list. Change-Id: I1577df37cc8441adf7e96a0e847dc901afd60ea8 Signed-off-by: Gennady Laventman <[email protected]>
1 parent 48d8df9 commit 121cf99

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

gossip/filter/filter.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,27 @@ func CombineRoutingFilters(filters ...RoutingFilter) RoutingFilter {
4141

4242
// SelectPeers returns a slice of peers that match a list of routing filters
4343
func SelectPeers(k int, peerPool []discovery.NetworkMember, filters ...RoutingFilter) []*comm.RemotePeer {
44+
var filteredPeers []*comm.RemotePeer
45+
for _, peer := range peerPool {
46+
if CombineRoutingFilters(filters ...)(peer) {
47+
filteredPeers = append(filteredPeers, &comm.RemotePeer{PKIID: peer.PKIid, Endpoint: peer.Endpoint})
48+
}
49+
}
50+
4451
var indices []int
45-
if len(peerPool) <= k {
46-
indices = make([]int, len(peerPool))
47-
for i := 0; i < len(peerPool); i++ {
52+
if len(filteredPeers) <= k {
53+
indices = make([]int, len(filteredPeers))
54+
for i := 0; i < len(filteredPeers); i++ {
4855
indices[i] = i
4956
}
5057
} else {
51-
indices = util.GetRandomIndices(k, len(peerPool)-1)
58+
indices = util.GetRandomIndices(k, len(filteredPeers)-1)
5259
}
5360

5461
var remotePeers []*comm.RemotePeer
5562
for _, index := range indices {
56-
peer := peerPool[index]
57-
if CombineRoutingFilters(filters ...)(peer) {
58-
remotePeers = append(remotePeers, &comm.RemotePeer{PKIID: peer.PKIid, Endpoint: peer.Endpoint})
59-
}
60-
63+
remotePeers = append(remotePeers, filteredPeers[index])
6164
}
65+
6266
return remotePeers
6367
}

0 commit comments

Comments
 (0)