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

add rate limiting to outbound p2p msg sending #3560

Merged
merged 1 commit into from
Feb 15, 2021

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Feb 10, 2021

Resolves #3553

We treat peers as abusive if inbound or outbound msg rates exceed 500/min.

This PR modifies this to only consider inbound msg rate.
We do not want to treat a peer as abusive if we are responsible for sending lots of p2p messages.

Add basic "rate limiting" to write_message() by inspecting the previous timestamp tracked by the tracker.
We ensure 150ms has elapsed based on previous sent message before attempting to send another.
In normal operation this is rarely the case. We occasionally send a ping and a block header close together and these are now separated by 150ms.
The scenario where this does come into play is during "fast sync" when requesting large numbers of full blocks from a small number of peers. Specifically "block archival sync" against archival nodes.
We no longer flood the peer connection with hundreds of block requests and these are now spaced out to avoid hitting the abusive peer limit on the receiving end.


As part of this PR cleaned up the readonly usage of tracker.
The following fns have been removed, replaced with exposing a simple tracker() accessor -

  • last_min_sent_bytes
  • last_min_received_bytes
  • last_min_message_counts

For example -

    let received = peer.tracker().received_bytes.read().count_per_min();

This makes the read locks more explicit and removes a case where we take multiple read locks in one go.


Introduced elapsed_since_last_msg() to RateCounter for convenience.
This simplifies the implementation of the rate limiting logic.

treat peers as abusive based on incoming msgs, not outgoing msg rates
@antiochp
Copy link
Member Author

Going to merge.
Inbound "abusive" peer checking is unchanged. This only applies to outbound traffic, which we should not be flagging as abusive.

@antiochp antiochp merged commit 4ab7290 into mimblewimble:master Feb 15, 2021
@antiochp antiochp deleted the rate_limit_p2p_requests branch February 15, 2021 13:49
@antiochp antiochp mentioned this pull request May 6, 2021
bayk added a commit to mwcproject/mwc-node that referenced this pull request Jun 12, 2024
…ewimble#3560)

treat peers as abusive based on incoming msgs, not outgoing msg rates
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.

Rate limit outbound p2p messages
1 participant