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

feat(core-p2p): implement throttling on outgoing p2p communication #3170

Merged
merged 3 commits into from
Oct 30, 2019

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Oct 29, 2019

Use the rate limiter in reverse to stop ourselves from sending too
many requests to a given peer that could possibly trigger their
protection and result in banning us.

We use the default configuration for rate limits. So this will work as
long as the peer is using the same software and has not changed his
config or has made it more liberal. If the peer has made his limits
more restricted, then we could still trigger their protection.

A more robust solution would be to negotiate the rate limits at peer
handshake and then obey different limits for each peer.

Summary

Checklist

  • Documentation (if necessary)
  • Tests (if necessary)
  • Ready to be merged

Use the rate limiter in reverse to stop ourselves from sending too
many requests to a given peer that could possibly trigger their
protection and result in banning us.

We use the default configuration for rate limits. So this will work as
long as the peer is using the same software and has not changed his
config or has made it more liberal. If the peer has made his limits
more restricted, then we could still trigger their protection.

A more robust solution would be to negotiate the rate limits at peer
handshake and then obey different limits for each peer.
@codecov
Copy link

codecov bot commented Oct 29, 2019

Codecov Report

Merging #3170 into develop will increase coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3170      +/-   ##
===========================================
+ Coverage    65.61%   65.61%   +<.01%     
===========================================
  Files          426      426              
  Lines        11940    11946       +6     
  Branches      1597     1597              
===========================================
+ Hits          7834     7838       +4     
- Misses        4073     4075       +2     
  Partials        33       33
Impacted Files Coverage Δ
packages/core-p2p/src/network-monitor.ts 73.25% <100%> (-0.11%) ⬇️
packages/core-p2p/src/peer-communicator.ts 57.93% <77.77%> (+0.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce92431...5530603. Read the comment docs.

Copy link
Contributor

@spkjp spkjp left a comment

Choose a reason for hiding this comment

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

Seems to work as advertised:

17|ark-relay  | [2019-10-29 15:26:53.407] DEBUG: Downloading blocks in chunks: [4045974, ..]
17|ark-relay  | [2019-10-29 15:26:53.408] DEBUG: Throttling outgoing requests to 209.50.61.104/p2p.peer.getBlocks to avoid triggering their rate limit
17|ark-relay  | [2019-10-29 15:26:53.469] INFO : 80.211.177.153 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:53.740] INFO : 142.44.253.192 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:54.546] INFO : 80.211.177.153 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:54.552] INFO : 35.222.188.169 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:54.805] INFO : 104.237.9.72 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:55.738] ERROR: Could not download blocks [4045974, ..] from any of 27 peers. Last attempt returned 0 blocks from peer 94.177.218.138:4002.
17|ark-relay  | [2019-10-29 15:26:55.742] INFO : Could not download any blocks from any peer from height 4045974
17|ark-relay  | [2019-10-29 15:26:55.743] DEBUG: event 'NOBLOCK': {"syncWithNetwork":"downloadBlocks"} -> {"syncWithNetwork":"syncing"} -> actions: [checkLastDownloadedBlockSynced]
17|ark-relay  | [2019-10-29 15:26:55.744] DEBUG: Queued chunks of blocks (process: 0)
17|ark-relay  | [2019-10-29 15:26:55.745] DEBUG: event 'NOTSYNCED': {"syncWithNetwork":"syncing"} -> {"syncWithNetwork":"downloadBlocks"} -> actions: [downloadBlocks]
17|ark-relay  | [2019-10-29 15:26:55.746] DEBUG: Downloading blocks in chunks: [4045974, ..]
17|ark-relay  | [2019-10-29 15:26:55.747] DEBUG: Throttling outgoing requests to 51.158.164.99/p2p.peer.getBlocks to avoid triggering their rate limit
17|ark-relay  | [2019-10-29 15:26:55.754] INFO : 142.44.253.192 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:55.772] INFO : 50.3.232.142 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:55.945] INFO : 104.237.9.72 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:55.969] INFO : 35.222.188.169 has downloaded 0 blocks from height 4,045,974
17|ark-relay  | [2019-10-29 15:26:56.223] INFO : 50.3.247.191 has downloaded 0 blocks from height 4,045,974

@spkjp spkjp merged commit 4574e6e into develop Oct 30, 2019
@ghost ghost deleted the feat-p2p-outgoing-throttle branch October 30, 2019 01:57
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.

3 participants