per-chain rpc rate limits

This commit is contained in:
Bryan Stitt 2023-02-21 21:10:23 -08:00
parent 6c33b1ae1e
commit 0ab7738393
2 changed files with 24 additions and 23 deletions

View File

@ -334,6 +334,7 @@ These are not yet ordered. There might be duplicates. We might not actually need
- [x] improve eth_sendRawTransaction server selection - [x] improve eth_sendRawTransaction server selection
- [x] don't cache methods that are usually very large - [x] don't cache methods that are usually very large
- [x] use http provider when available - [x] use http provider when available
- [x] per-chain rpc rate limits
- [ ] don't use new_head_provider anywhere except new head subscription - [ ] don't use new_head_provider anywhere except new head subscription
- [-] proxy mode for benchmarking all backends - [-] proxy mode for benchmarking all backends
- [-] proxy mode for sending to multiple backends - [-] proxy mode for sending to multiple backends

View File

@ -645,31 +645,31 @@ impl Web3ProxyApp {
let mut login_rate_limiter = None; let mut login_rate_limiter = None;
if let Some(redis_pool) = vredis_pool.as_ref() { if let Some(redis_pool) = vredis_pool.as_ref() {
let rpc_rrl = RedisRateLimiter::new( if let Some(public_requests_per_period) = top_config.app.public_requests_per_period {
"web3_proxy", // chain id is included in the app name so that rpc rate limits are per-chain
"frontend", let rpc_rrl = RedisRateLimiter::new(
// TODO: think about this unwrapping &format!("web3_proxy:{}", top_config.app.chain_id),
top_config "frontend",
.app public_requests_per_period,
.public_requests_per_period 60.0,
.unwrap_or(u64::MAX), redis_pool.clone(),
60.0, );
redis_pool.clone(),
);
// these two rate limiters can share the base limiter // these two rate limiters can share the base limiter
// these are deferred rate limiters because we don't want redis network requests on the hot path // these are deferred rate limiters because we don't want redis network requests on the hot path
// TODO: take cache_size from config // TODO: take cache_size from config
frontend_ip_rate_limiter = Some(DeferredRateLimiter::<IpAddr>::new( frontend_ip_rate_limiter = Some(DeferredRateLimiter::<IpAddr>::new(
10_000, 10_000,
"ip", "ip",
rpc_rrl.clone(), rpc_rrl.clone(),
None, None,
)); ));
frontend_registered_user_rate_limiter = Some(DeferredRateLimiter::<u64>::new( frontend_registered_user_rate_limiter = Some(DeferredRateLimiter::<u64>::new(
10_000, "key", rpc_rrl, None, 10_000, "key", rpc_rrl, None,
)); ));
}
// login rate limiter
login_rate_limiter = Some(RedisRateLimiter::new( login_rate_limiter = Some(RedisRateLimiter::new(
"web3_proxy", "web3_proxy",
"login", "login",