Skip to content

Commit

Permalink
Use the param in bps
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Aug 10, 2023
1 parent ba5ba98 commit a4e8833
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions libp2p/protocols/pubsub/gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/gossipsub/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
4 changes: 2 additions & 2 deletions tests/pubsub/testgossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,15 @@ 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)
gossip1 = GossipSub(nodes[0])

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])
Expand Down

0 comments on commit a4e8833

Please sign in to comment.