diff --git a/chain/network/src/config.rs b/chain/network/src/config.rs index 9d5891f0619..037462b0943 100644 --- a/chain/network/src/config.rs +++ b/chain/network/src/config.rs @@ -168,6 +168,48 @@ pub struct NetworkConfig { } impl NetworkConfig { + /// Overrides values of NetworkConfig with values for the JSON config. + /// We need all the values from NetworkConfig to be configurable. + /// We need this in case of emergency. It is faster to change the config than to recompile. + fn override_config(mut self, overrides: crate::config_json::NetworkConfigOverrides) -> Self { + if let Some(connect_to_reliable_peers_on_startup) = + overrides.connect_to_reliable_peers_on_startup + { + self.connect_to_reliable_peers_on_startup = connect_to_reliable_peers_on_startup + } + if let Some(max_send_peers) = overrides.max_send_peers { + self.max_send_peers = max_send_peers + } + if let Some(routed_message_ttl) = overrides.routed_message_ttl { + self.routed_message_ttl = routed_message_ttl + } + if let Some(max_routes_to_store) = overrides.max_routes_to_store { + self.max_routes_to_store = max_routes_to_store + } + if let Some(highest_peer_horizon) = overrides.highest_peer_horizon { + self.highest_peer_horizon = highest_peer_horizon + } + if let Some(millis) = overrides.push_info_period_millis { + self.push_info_period = time::Duration::milliseconds(millis) + } + if let Some(outbound_disabled) = overrides.outbound_disabled { + self.outbound_disabled = outbound_disabled + } + if let (Some(qps), Some(burst)) = ( + overrides.accounts_data_broadcast_rate_limit_qps, + overrides.accounts_data_broadcast_rate_limit_burst, + ) { + self.accounts_data_broadcast_rate_limit = rate::Limit { qps, burst } + } + if let (Some(qps), Some(burst)) = ( + overrides.routing_table_update_rate_limit_qps, + overrides.routing_table_update_rate_limit_burst, + ) { + self.routing_table_update_rate_limit = rate::Limit { qps, burst } + } + self + } + pub fn new( cfg: crate::config_json::Config, node_key: SecretKey, @@ -293,7 +335,7 @@ impl NetworkConfig { }, event_sink: Sink::null(), }; - Ok(this) + Ok(this.override_config(cfg.experimental.network_config_overrides)) } pub fn node_id(&self) -> PeerId { diff --git a/chain/network/src/config_json.rs b/chain/network/src/config_json.rs index 3a3bf19500b..d225018525c 100644 --- a/chain/network/src/config_json.rs +++ b/chain/network/src/config_json.rs @@ -243,6 +243,28 @@ pub struct ExperimentalConfig { /// See `near_network::config::Tier1::new_connections_per_attempt`. #[serde(default = "default_tier1_new_connections_per_attempt")] pub tier1_new_connections_per_attempt: u64, + + /// See `NetworkConfig`. + /// Fields set here will override the NetworkConfig fields. + #[serde(default)] + pub network_config_overrides: NetworkConfigOverrides, +} + +/// Overrides values from NetworkConfig. +/// This enables the user to override the hardcoded values. +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)] +pub struct NetworkConfigOverrides { + pub connect_to_reliable_peers_on_startup: Option, + pub max_send_peers: Option, + pub routed_message_ttl: Option, + pub max_routes_to_store: Option, + pub highest_peer_horizon: Option, + pub push_info_period_millis: Option, + pub outbound_disabled: Option, + pub accounts_data_broadcast_rate_limit_burst: Option, + pub accounts_data_broadcast_rate_limit_qps: Option, + pub routing_table_update_rate_limit_burst: Option, + pub routing_table_update_rate_limit_qps: Option, } impl Default for ExperimentalConfig { @@ -255,6 +277,7 @@ impl Default for ExperimentalConfig { tier1_enable_outbound: default_tier1_enable_outbound(), tier1_connect_interval: default_tier1_connect_interval(), tier1_new_connections_per_attempt: default_tier1_new_connections_per_attempt(), + network_config_overrides: Default::default(), } } }