Skip to content

Commit

Permalink
Add penalty
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Aug 19, 2023
1 parent fab4fb7 commit 4114961
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/gossipsub/behavior.nim
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ proc checkIWANTTimeouts(g: GossipSub, timeoutDuration: Duration) {.raises: [].}
for msgId, request in g.outstandingIWANTs.pairs():
if currentTime - request.timestamp > timeoutDuration:
trace "IWANT request timed out", messageID=msgId, peer=request.peer
# applyBehaviorPenalty(g, request.peer)
request.peer.behaviourPenalty += 0.1
idsToRemove.add(msgId)
for msgId in idsToRemove:
g.outstandingIWANTs.del(msgId)
Expand Down
4 changes: 3 additions & 1 deletion tests/pubsub/testgossipinternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,13 @@ suite "GossipSub internal":

# Check that the message ID is in outstandingIWANTs
check: gossipSub.outstandingIWANTs.contains(ihaveMessageId)
check: peer.behaviourPenalty == 0.0

await sleepAsync(60.milliseconds)

# Check that the message ID has been removed from outstandingIWANTs after the timeout
# Check that the message ID has been removed from outstandingIWANTs after the timeout and peer has been penalized
check: not gossipSub.outstandingIWANTs.contains(ihaveMessageId)
check: peer.behaviourPenalty == 0.1

await allFuturesThrowing(conns.mapIt(it.close()))
await gossipSub.switch.stop()

0 comments on commit 4114961

Please sign in to comment.