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

rpc: add option to whitelist ips in rate limiting #3701

Merged
merged 18 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cumulus/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ pub fn node_config(
rpc_message_buffer_capacity: Default::default(),
rpc_batch_config: RpcBatchRequestConfig::Unlimited,
rpc_rate_limit: None,
rpc_rate_limit_whitelisted_hosts: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub fn node_config(
rpc_message_buffer_capacity: Default::default(),
rpc_batch_config: RpcBatchRequestConfig::Unlimited,
rpc_rate_limit: None,
rpc_rate_limit_whitelisted_hosts: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_message_buffer_capacity: Default::default(),
rpc_batch_config: RpcBatchRequestConfig::Unlimited,
rpc_rate_limit: None,
rpc_rate_limit_whitelisted_hosts: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_message_buffer_capacity: Default::default(),
rpc_batch_config: RpcBatchRequestConfig::Unlimited,
rpc_rate_limit: None,
rpc_rate_limit_whitelisted_hosts: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions substrate/client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ mod tests {
rpc_port: 9944,
rpc_batch_config: sc_service::config::RpcBatchRequestConfig::Unlimited,
rpc_rate_limit: None,
rpc_rate_limit_whitelisted_hosts: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
10 changes: 8 additions & 2 deletions substrate/client/rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ where
Ok::<_, Infallible>(service_fn(move |req| {
let ip = read_ip(conn_ip, &req);

let rate_limit_cfg = if rate_limit_whitelisted_ip_addrs.iter().any(|ip2| ip2 == &ip) {
let rate_limit_cfg = if rate_limit_whitelisted_ip_addrs.iter().any(|ip2| ip2 == &ip)
{
None
} else {
rate_limit
Expand Down Expand Up @@ -306,7 +307,12 @@ fn format_cors(maybe_cors: Option<&Vec<String>>) -> String {
///
/// If that header is missing then remote addr from the socket is used.
fn read_ip(remote_addr: IpAddr, req: &hyper::Request<hyper::Body>) -> IpAddr {
if let Some(ip) = req.headers().get("X-Real-IP").and_then(|v| v.to_str().ok()).and_then(|s| s.parse().ok()) {
if let Some(ip) = req
.headers()
.get("X-Real-IP")
.and_then(|v| v.to_str().ok())
.and_then(|s| s.parse().ok())
{
ip
} else {
remote_addr
Expand Down
1 change: 1 addition & 0 deletions substrate/client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ fn node_config<
rpc_message_buffer_capacity: Default::default(),
rpc_batch_config: RpcBatchRequestConfig::Unlimited,
rpc_rate_limit: None,
rpc_rate_limit_whitelisted_hosts: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down