From 41149610bf13bc346b834400957b743545e38870 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 19 Aug 2023 17:04:35 +0200 Subject: [PATCH] Add penalty --- libp2p/protocols/pubsub/gossipsub/behavior.nim | 2 +- tests/pubsub/testgossipinternal.nim | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub/behavior.nim b/libp2p/protocols/pubsub/gossipsub/behavior.nim index c62ddd0615..232e1aa7e2 100644 --- a/libp2p/protocols/pubsub/gossipsub/behavior.nim +++ b/libp2p/protocols/pubsub/gossipsub/behavior.nim @@ -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) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 6b0a568c89..3fac352f9f 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -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() \ No newline at end of file