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

Use a client side rate limit to reduce chance of getting banned #4637

Merged
merged 3 commits into from Jan 24, 2020

Conversation

prestonvanloon
Copy link
Member

@prestonvanloon prestonvanloon commented Jan 23, 2020

Resolves #4588
Resolves #4621

Maybe helps #4631

Part of the issue is that when there are large ranges of skip slots, we might be asking for the peer for many blocks very quickly. Even when there are no blocks present in that range, the server increments that rate limit by the request count. Adding this client side rate limit should reduce the risk of bombing peers with requests.

@prestonvanloon prestonvanloon added the Ready For Review A pull request ready for code review label Jan 23, 2020
@mcdee
Copy link
Contributor

mcdee commented Jan 23, 2020

Even when there are no blocks present in that range, the server increments that rate limit by the request count

Is this valid for the server to do? It it a similar magnitude of work to check for empty slots as it is to serve those with blocks in it? Or should the rate limiting be done on actual blocks served?

@prestonvanloon
Copy link
Member Author

@mcdee I think it's valid. The client is knowingly requesting a high rate of blocks/slots per second, although they do not know if there are actually blocks in those slots.

@mcdee
Copy link
Contributor

mcdee commented Jan 23, 2020

True, but the only reason it is requesting more blocks soon after the last request is because there were few-to-none blocks returned last time around.

Given this situation only really occurs when we have finality issues, I'm wondering if being more lenient on the server side here would help the network get back on its feet if such a thing happened in production. I'm not suggesting the server hurt itself in the process, but if it is cheap and easy to return 0 blocks I'd be inclined to reflect that in the rate limiting.

@prestonvanloon
Copy link
Member Author

Supporting that type of rate limiting will require some database changes to determine how many blocks are present in a given range without unmarshalling them. As it is now, we check the rate limit, if OK then we fetch the request range of blocks.

We could enhance this process to be:

  • Secure peer ID based mutex
  • Fetch up to min(remainingLimit, req.Count) blocks from db in the requested range
  • Increment limit by the amount of blocks returned
  • Return blocks

For now it's simpler on the server side to check if the requested count exceeds the limit and exit early without a database read. Given that the limit allows bursts of 320 blocks per second, I think this is a reasonable response from any given peer.

@codecov
Copy link

codecov bot commented Jan 23, 2020

Codecov Report

Merging #4637 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #4637   +/-   ##
======================================
  Coverage     6.9%    6.9%           
======================================
  Files         192     192           
  Lines       13374   13374           
======================================
  Hits          923     923           
  Misses      12313   12313           
  Partials      138     138

@prestonvanloon prestonvanloon merged commit 62a5931 into master Jan 24, 2020
@delete-merged-branch delete-merged-branch bot deleted the client-side-rate-limit branch January 24, 2020 01:33
cryptomental pushed a commit to cryptomental/prysm that referenced this pull request Feb 24, 2020
…maticlabs#4637)

* Use a client side rate limit to reduce chance of getting banned

* fix test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
cryptomental pushed a commit to cryptomental/prysm that referenced this pull request Feb 28, 2020
…maticlabs#4637)

* Use a client side rate limit to reduce chance of getting banned

* fix test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beacon Chain peers disconnect in block 35848 - using bazel Rapid drop off peers
3 participants