Skip to content

Commit

Permalink
rate limit (#145)
Browse files Browse the repository at this point in the history
* rate limit

* clippy

* clippy

* update

* cleanup

* make rate_limit an extension

* change config

* fix

* update test

* reduce default jitter

* Update config.yml

---------

Co-authored-by: Xiliang Chen <[email protected]>
  • Loading branch information
ermalkaleci and xlc authored Nov 27, 2023
1 parent 158538e commit 43cbd17
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 25 deletions.
83 changes: 66 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ tracing = "0.1.37"
tracing-serde = "0.1.3"
tracing-subscriber = { version = "0.3.16", features = ["env-filter", "json"] }

jsonrpsee = { version = "0.20.0", path = "./vendor/jsonrpsee/jsonrpsee", features = ["full"] }
governor = { version = "0.6.0", path = "./vendor/governor/governor" }
jsonrpsee = { path = "./vendor/jsonrpsee/jsonrpsee", features = ["full"] }
governor = "0.6.0"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["async_tokio", "html_reports"] }
Expand Down
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ extensions:
- path: /liveness
method: chain_getBlockHash
cors: all
rate_limit: # 20 requests per second per connection
burst: 20
period_secs: 1

middlewares:
methods:
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod cache;
pub mod client;
pub mod event_bus;
pub mod merge_subscription;
pub mod rate_limit;
pub mod server;
pub mod telemetry;

Expand Down Expand Up @@ -136,4 +137,5 @@ define_all_extensions! {
eth_api: api::EthApi,
server: server::SubwayServerBuilder,
event_bus: event_bus::EventBus,
rate_limit: rate_limit::RateLimitBuilder,
}
Loading

0 comments on commit 43cbd17

Please sign in to comment.