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

chore: rate limit peer exchange protocol, enhanced response status in RPC #3035

Merged
merged 9 commits into from
Sep 18, 2024

Conversation

NagyZoltanPeter
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter commented Sep 12, 2024

Description

As part of DOS protection for req-res protocols and metrics Waku PeerExchange protocol must be protected just as Lightpush/Store and Filter.

Changes

  • Ratlimit config and check was added to WakuPeerExchange
  • Due to the protocol RPC structure limiter status response capabilities, new fields had been added (status and optional descritpion)
  • Better error handling and reporting in WakuPeerExchange request/response side.
  • Test adjustments.
  • Enhance Waku CLI Rate Limit configuration (allow multiple configuration added, separately for each protocol)
  • Added new gauge to help dashboard show effective applied rate limit of protocols

Warning

The last bullet point introduces a refactored rate limit configuration over CLI/TOML file.
This was necessary as identified different needs for different protocols (out of dogfooding and dashboard data)
This change will break former CLI as removed two former rate-limit option and replaced them by one - formatted string - that can be repeated.

As rate-limit configuration is not yet used this breaking change shall not cause trouble, just we need to handle upgrades with care.

New CLI option is --rate-limit which has to be set as string in a proper format.
Examples:

  • --rate-limit="lightpush:13/10s"
  • --rate-limit="storev3:15/1500ms"
  • --rate-limit="px:1/1m"
  • --rate-limit="100/10m"
    • this last one is taken as global and will be used as default for protocols not set otherwise

As this option can be repeated rate limit configuration can be fine-grained for every needs.

How to test

Tests are adjusted and extended. Every peer exchange test must run without error.

Issue

#3028

Further actions:

@NagyZoltanPeter NagyZoltanPeter self-assigned this Sep 12, 2024
@NagyZoltanPeter NagyZoltanPeter changed the title Chore: rate limit peer exchange protocol, enhanced response status in RPC chore: rate limit peer exchange protocol, enhanced response status in RPC Sep 12, 2024
Copy link

github-actions bot commented Sep 12, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3035

Built from cf4e167

Copy link
Contributor

@gabrielmer gabrielmer left a comment

Choose a reason for hiding this comment

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

Woow, amazing job! Thanks so much! 😍

Added just some minor questions

waku/common/rate_limit/setting.nim Outdated Show resolved Hide resolved
Comment on lines 44 to 60
proc translate(sProtocol: string): RateLimitedProtocol =
if sProtocol.len == 0:
return GLOBAL

case sProtocol
of "global":
return GLOBAL
of "storev2":
return STOREV2
of "storev3":
return STOREV3
of "lightpush":
return LIGHTPUSH
of "px":
return PEEREXCHG
of "filter":
return FILTER
Copy link
Contributor

Choose a reason for hiding this comment

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

should we handle the case of a string being passed that doesn't match any of the protocols?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mmm, yes it worth a double check. Originally invalid strings are filtered with regex.

waku/common/rate_limit/setting.nim Outdated Show resolved Hide resolved
waku/waku_peer_exchange/rpc.nim Outdated Show resolved Hide resolved
Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for it! 💯
Just a few comments:)

case sProtocol
of "global":
return GLOBAL
of "storev2":
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should instead use the const items that we already have, such as:

WakuLegacyStoreCodec* = "/vac/waku/store/2.0.0-beta4"

waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/waku_peer_exchange/protocol.nim Outdated Show resolved Hide resolved
waku/waku_peer_exchange/rpc.nim Show resolved Hide resolved
@NagyZoltanPeter
Copy link
Contributor Author

Latest changes done on the peer-exchange specification is reflected now in nwaku code.
This was necessary to ensure backward compatibility of the protocol while allowing added status to return.
Also all review findings addressed.

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

Thanks for this. Reviewed for functionality and not detail.

@NagyZoltanPeter NagyZoltanPeter merged commit 0a7f16a into master Sep 18, 2024
10 of 11 checks passed
@NagyZoltanPeter NagyZoltanPeter deleted the chore-rate-limit-peer-ex branch September 18, 2024 13:58
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.

4 participants