stratus/eth/rpc/
rpc_config.rs

1use std::collections::HashSet;
2use std::net::SocketAddr;
3
4use anyhow::anyhow;
5use clap::Parser;
6
7use super::RpcClientApp;
8
9#[derive(Parser, Clone, serde::Serialize)]
10pub struct RpcServerConfig {
11    /// JSON-RPC server binding address.
12    #[arg(short = 'a', long = "address", env = "ADDRESS", default_value = "0.0.0.0:3000")]
13    pub rpc_address: SocketAddr,
14
15    /// JSON-RPC server max active connections
16    #[arg(long = "max-connections", env = "MAX_CONNECTIONS", default_value = "400")]
17    pub rpc_max_connections: u32,
18
19    /// JSON-RPC server max response size limit in bytes
20    #[arg(long = "max-response-size-bytes", env = "MAX_RESPONSE_SIZE_BYTES", default_value = "10485760")]
21    pub rpc_max_response_size_bytes: u32,
22
23    /// JSON-RPC server max active subscriptions per client.
24    #[arg(long = "max-subscriptions", env = "MAX_SUBSCRIPTIONS", default_value = "30")]
25    pub rpc_max_subscriptions: u32,
26
27    /// Health check interval in seconds
28    #[arg(long = "health-check-interval", env = "HEALTH_CHECK_INTERVAL_MS", default_value = "100")]
29    pub health_check_interval_ms: u64,
30
31    #[arg(long = "rpc-debug-trace-unsuccessful-only", value_parser=Self::parse_rpc_client_app_hashset ,env = "RPC_DEBUG_TRACE_UNSUCCESSFUL_ONLY")]
32    pub rpc_debug_trace_unsuccessful_only: Option<HashSet<RpcClientApp>>,
33}
34
35impl RpcServerConfig {
36    pub fn parse_rpc_client_app_hashset(input: &str) -> anyhow::Result<HashSet<RpcClientApp>> {
37        if input.is_empty() {
38            return Err(anyhow!("invalid client list"));
39        }
40
41        let set: HashSet<RpcClientApp> = input.split(',').map(|s| RpcClientApp::parse(s.trim())).collect();
42
43        if set.is_empty() { Err(anyhow!("invalid client list")) } else { Ok(set) }
44    }
45}