Skip to content

Commit 4e01b37

Browse files
Update parameters as per pr suggestion.
1 parent 933dd4f commit 4e01b37

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

libp2p/protocols/pubsub/gossipsub/scoring.nim

+21-22
Original file line numberDiff line numberDiff line change
@@ -265,32 +265,31 @@ proc addCapped*[T](stat: var T, diff, cap: T) =
265265
proc rewardDelivered*(
266266
g: GossipSub,
267267
peer: PubSubPeer,
268-
topics: openArray[string],
268+
topic: string,
269269
first: bool,
270270
delay = ZeroDuration,
271271
) =
272-
for tt in topics:
273-
let t = tt
274-
if t notin g.topics:
275-
continue
272+
let t = topic
273+
if t notin g.topics:
274+
return
276275

277-
let tt = t
276+
let topic = t
278277

279-
let topicParams = g.topicParams.mgetOrPut(t, TopicParams.init())
280-
# if in mesh add more delivery score
278+
let topicParams = g.topicParams.mgetOrPut(t, TopicParams.init())
279+
# if in mesh add more delivery score
281280

282-
if delay > topicParams.meshMessageDeliveriesWindow:
283-
# Too old
284-
continue
281+
if delay > topicParams.meshMessageDeliveriesWindow:
282+
# Too old
283+
continue
284+
285+
g.withPeerStats(peer.peerId) do (stats: var PeerStats):
286+
stats.topicInfos.withValue(topic, tstats):
287+
if first:
288+
tstats[].firstMessageDeliveries.addCapped(
289+
1, topicParams.firstMessageDeliveriesCap)
285290

286-
g.withPeerStats(peer.peerId) do (stats: var PeerStats):
287-
stats.topicInfos.withValue(tt, tstats):
288-
if first:
289-
tstats[].firstMessageDeliveries.addCapped(
290-
1, topicParams.firstMessageDeliveriesCap)
291-
292-
if tstats[].inMesh:
293-
tstats[].meshMessageDeliveries.addCapped(
294-
1, topicParams.meshMessageDeliveriesCap)
295-
do: # make sure we don't lose this information
296-
stats.topicInfos[tt] = TopicInfo(meshMessageDeliveries: 1)
291+
if tstats[].inMesh:
292+
tstats[].meshMessageDeliveries.addCapped(
293+
1, topicParams.meshMessageDeliveriesCap)
294+
do: # make sure we don't lose this information
295+
stats.topicInfos[topic] = TopicInfo(meshMessageDeliveries: 1)

0 commit comments

Comments
 (0)