From a4e8833d55a9fa1e4de0593c28e3f84873b375dd Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 11 Aug 2023 00:42:12 +0200 Subject: [PATCH] Use the param in bps --- libp2p/protocols/pubsub/gossipsub.nim | 6 +++--- libp2p/protocols/pubsub/gossipsub/types.nim | 2 +- tests/pubsub/testgossipsub.nim | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 4e15a20e85..ef4cbafeae 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -75,7 +75,7 @@ proc init*(_: type[GossipSubParams]): GossipSubParams = behaviourPenaltyDecay: 0.999, disconnectBadPeers: false, enablePX: false, - bandwidthEstimateMbps: 100 + bandwidthEstimatebps: 100_000_000 # 100 Mbps or 12.5 MBps ) proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] = @@ -523,9 +523,9 @@ method publish*(g: GossipSub, # but a peer's own messages will always be published to all known peers in the topic, limited # to the amount of peers we can send it to in one heartbeat var maxPeersToFlodOpt: Opt[int64] - if g.parameters.bandwidthEstimateMbps > 0: + if g.parameters.bandwidthEstimatebps > 0: let - bandwidth = (g.parameters.bandwidthEstimateMbps * 1_000_000) div 8 div 1000 # 100 Mbps or 12.5 MBps TODO replace with bandwidth estimate + bandwidth = (g.parameters.bandwidthEstimatebps) div 8 div 1000 # Divisions are to convert it to Bytes per ms TODO replace with bandwidth estimate msToTransmit = max(data.len div bandwidth, 1) maxPeersToFlodOpt = Opt.some(max(g.parameters.heartbeatInterval.milliseconds div msToTransmit, g.parameters.dLow)) diff --git a/libp2p/protocols/pubsub/gossipsub/types.nim b/libp2p/protocols/pubsub/gossipsub/types.nim index 8749e52757..333b9fae17 100644 --- a/libp2p/protocols/pubsub/gossipsub/types.nim +++ b/libp2p/protocols/pubsub/gossipsub/types.nim @@ -142,7 +142,7 @@ type disconnectBadPeers*: bool enablePX*: bool - bandwidthEstimateMbps*: int # This is currently used only for limting flood publishing. 0 disables flood-limiting completely + bandwidthEstimatebps*: int # This is currently used only for limting flood publishing. 0 disables flood-limiting completely BackoffTable* = Table[string, Table[PeerId, Moment]] ValidationSeenTable* = Table[MessageId, HashSet[PubSubPeer]] diff --git a/tests/pubsub/testgossipsub.nim b/tests/pubsub/testgossipsub.nim index 4d8a4ef606..9a4d9aa450 100644 --- a/tests/pubsub/testgossipsub.nim +++ b/tests/pubsub/testgossipsub.nim @@ -694,7 +694,7 @@ suite "GossipSub": await baseTestProcedure(nodes, gossip1, gossip1.parameters.dLow, 17) await stopNodes(nodes) - asyncTest "e2e - GossipSub floodPublish limit with bandwidthEstimateMbps = 0": + asyncTest "e2e - GossipSub floodPublish limit with bandwidthEstimatebps = 0": let nodes = setupNodes(20) @@ -702,7 +702,7 @@ suite "GossipSub": gossip1.parameters.floodPublish = true gossip1.parameters.heartbeatInterval = milliseconds(700) - gossip1.parameters.bandwidthEstimateMbps = 0 + gossip1.parameters.bandwidthEstimatebps = 0 await startNodes(nodes) await connectNodes(nodes[1..^1], nodes[0])