Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GossipSub Rate Limit #920

Merged
merged 26 commits into from
Sep 22, 2023
Merged

GossipSub Rate Limit #920

merged 26 commits into from
Sep 22, 2023

Conversation

diegomrsantos
Copy link
Collaborator

@diegomrsantos diegomrsantos commented Jun 23, 2023

The main idea here is to eventually disconnect peers that send us too much useless data in a short amount of time (potentially DoSing us). The definition of useless we chose depends if the singing mode is enabled or not. If so, it is everything but the messages themselves. Otherwise, it is everything but the data and the topicIDs inside the message. For now, we just log and measure the number of times peers are above their rate limit - the max amount of useless data they can send us for a given interval.

@diegomrsantos diegomrsantos force-pushed the traffic-scoring branch 4 times, most recently from 8a02654 to 0096fbe Compare June 23, 2023 13:12
@codecov
Copy link

codecov bot commented Jun 23, 2023

Codecov Report

Merging #920 (18f0570) into unstable (20b0e40) will decrease coverage by 0.01%.
The diff coverage is 87.73%.

Impacted file tree graph

@@             Coverage Diff              @@
##           unstable     #920      +/-   ##
============================================
- Coverage     83.10%   83.10%   -0.01%     
============================================
  Files            91       91              
  Lines         15235    15288      +53     
============================================
+ Hits          12661    12705      +44     
- Misses         2574     2583       +9     
Files Changed Coverage
libp2p/protocols/pubsub/gossipsub/scoring.nim 78.57%
libp2p/protocols/pubsub/gossipsub.nim 80.48%
libp2p/protocols/pubsub/pubsub.nim 83.33%
libp2p/protocols/pubsub/pubsubpeer.nim 92.30%
libp2p/protocols/pubsub/floodsub.nim 100.00%
libp2p/protocols/pubsub/rpc/messages.nim 100.00%

@diegomrsantos diegomrsantos force-pushed the traffic-scoring branch 5 times, most recently from 0c948da to f2ff1e3 Compare July 4, 2023 13:27
@diegomrsantos diegomrsantos marked this pull request as ready for review July 4, 2023 13:27
@diegomrsantos diegomrsantos force-pushed the traffic-scoring branch 2 times, most recently from c3f9bec to 397e2c3 Compare July 31, 2023 16:39
@diegomrsantos diegomrsantos marked this pull request as draft August 1, 2023 23:23
@diegomrsantos diegomrsantos force-pushed the traffic-scoring branch 2 times, most recently from 6842b9a to 7ea1c8b Compare August 2, 2023 17:03
@diegomrsantos diegomrsantos marked this pull request as ready for review August 16, 2023 11:37
@@ -78,7 +79,8 @@ proc init*(_: type[GossipSubParams]): GossipSubParams =
disconnectBadPeers: false,
enablePX: false,
bandwidthEstimatebps: 100_000_000, # 100 Mbps or 12.5 MBps
iwantTimeout: 3 * GossipSubHeartbeatInterval
iwantTimeout: 3 * GossipSubHeartbeatInterval,
overheadRateLimitConfOpt: Opt.none(tuple[bytes: int, interval: Duration])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
overheadRateLimitConfOpt: Opt.none(tuple[bytes: int, interval: Duration])
overheadRateLimit: Opt.none(tuple[bytes: int, interval: Duration])

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from the actual rate limit, it is a config. Adding the Opt makes using withValue cleaner.

Copy link
Contributor

@Menduist Menduist Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything in that structure is a config, it's even named GossipSubParams
And since when do we put the type of a variable in its name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Menduist Menduist changed the title Traffic scoring GossipSub Traffic scoring Sep 13, 2023
@@ -116,3 +116,32 @@ func shortLog*(m: RPCMsg): auto =
messages: mapIt(m.messages, it.shortLog),
control: m.control.get(ControlMessage()).shortLog
)

proc byteSize*(msg: Message): int =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as #944 (comment), but I guess we can unify that after merging this PR

@diegomrsantos diegomrsantos merged commit 56599f5 into unstable Sep 22, 2023
10 checks passed
@diegomrsantos diegomrsantos deleted the traffic-scoring branch September 22, 2023 14:45
@diegomrsantos diegomrsantos changed the title GossipSub Traffic scoring GossipSub Rate Limit Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants