Skip to content

Commit

Permalink
Merge pull request #4780 from ElrondNetwork/fix_peers_rating_handler
Browse files Browse the repository at this point in the history
Fix missing call to decrease rating into peers rating handler
  • Loading branch information
sstanculeanu committed Dec 13, 2022
2 parents 1eeb896 + 834c36f commit 9406531
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions dataRetriever/topicSender/topicRequestSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (trs *topicRequestSender) sendOnTopic(
if err != nil {
continue
}
trs.peersRatingHandler.DecreaseRating(peer)

logData = append(logData, peerType)
logData = append(logData, peer.Pretty())
Expand Down
18 changes: 18 additions & 0 deletions dataRetriever/topicSender/topicRequestSender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,23 @@ func TestTopicResolverSender_SendOnRequestTopic(t *testing.T) {
return []core.PeerID{pID2}
},
}
decreaseCalledCounter := 0
arg.PeersRatingHandler = &p2pmocks.PeersRatingHandlerStub{
DecreaseRatingCalled: func(pid core.PeerID) {
decreaseCalledCounter++
if !bytes.Equal(pid.Bytes(), pID1.Bytes()) && !bytes.Equal(pid.Bytes(), pID2.Bytes()) {
assert.Fail(t, "should be one of the provided pids")
}
},
}
trs, _ := topicsender.NewTopicRequestSender(arg)

err := trs.SendOnRequestTopic(&dataRetriever.RequestData{}, defaultHashes)

assert.Nil(t, err)
assert.True(t, sentToPid1)
assert.True(t, sentToPid2)
assert.Equal(t, 2, decreaseCalledCounter)
})
t.Run("should work and send to full history", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -284,11 +294,19 @@ func TestTopicResolverSender_SendOnRequestTopic(t *testing.T) {
return false
},
}
decreaseCalledCounter := 0
arg.PeersRatingHandler = &p2pmocks.PeersRatingHandlerStub{
DecreaseRatingCalled: func(pid core.PeerID) {
decreaseCalledCounter++
assert.Equal(t, pIDfullHistory, pid)
},
}
trs, _ := topicsender.NewTopicRequestSender(arg)

err := trs.SendOnRequestTopic(&dataRetriever.RequestData{}, defaultHashes)
assert.Nil(t, err)
assert.True(t, sentToFullHistoryPeer)
assert.Equal(t, 1, decreaseCalledCounter)
})
t.Run("should work and send to preferred peers", func(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 9406531

Please sign in to comment.