mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 16:07:57 +00:00
rpc server: add rate limiting middleware (#3301)
Add RPC server rate limiting which can be utilized by the CLI `--rpc-rate-limit <calls/per minute>` Resolves first part of https://github.com/paritytech/polkadot-sdk/issues/3028 //cc @PierreBesson @kogeler you might be interested in this one --------- Co-authored-by: James Wilson <james@jsdw.me> Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
This commit is contained in:
@@ -33,7 +33,7 @@ use sc_service::{
|
||||
BlocksPruning, ChainSpec, TracingReceiver,
|
||||
};
|
||||
use sc_tracing::logging::LoggerBuilder;
|
||||
use std::{net::SocketAddr, path::PathBuf};
|
||||
use std::{net::SocketAddr, num::NonZeroU32, path::PathBuf};
|
||||
|
||||
/// The maximum number of characters for a node name.
|
||||
pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64;
|
||||
@@ -338,6 +338,11 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
Ok(RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN)
|
||||
}
|
||||
|
||||
/// Rate limit calls per minute.
|
||||
fn rpc_rate_limit(&self) -> Result<Option<NonZeroU32>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Get the prometheus configuration (`None` if disabled)
|
||||
///
|
||||
/// By default this is `None`.
|
||||
@@ -510,6 +515,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
rpc_max_subs_per_conn: self.rpc_max_subscriptions_per_connection()?,
|
||||
rpc_port: DCV::rpc_listen_port(),
|
||||
rpc_message_buffer_capacity: self.rpc_buffer_capacity_per_connection()?,
|
||||
rpc_rate_limit: self.rpc_rate_limit()?,
|
||||
prometheus_config: self
|
||||
.prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?,
|
||||
telemetry_endpoints,
|
||||
|
||||
Reference in New Issue
Block a user