Skip to content

Commit bdae043

Browse files
apollo_http_server_config: split config to dynamic and static
1 parent 16563c3 commit bdae043

File tree

14 files changed

+92
-58
lines changed

14 files changed

+92
-58
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"http_server_config.ip": "0.0.0.0",
3-
"http_server_config.port": "",
4-
"http_server_config.max_sierra_program_size": 4194304
2+
"http_server_config.dynamic_config.max_sierra_program_size": 4194304,
3+
"http_server_config.static_config.ip": "0.0.0.0",
4+
"http_server_config.static_config.port": ""
55
}

crates/apollo_deployments/resources/app_configs/replacer_consensus_manager_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@
7474
"consensus_manager_config.stream_handler_config.channel_buffer_capacity": 1000,
7575
"consensus_manager_config.stream_handler_config.max_streams": 100,
7676
"consensus_manager_config.votes_topic": "consensus_votes"
77-
}
77+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"http_server_config.ip": "0.0.0.0",
3-
"http_server_config.max_sierra_program_size": 4194304,
4-
"http_server_config.port": "$$$_HTTP_SERVER_CONFIG-PORT_$$$"
2+
"http_server_config.dynamic_config.max_sierra_program_size": 4194304,
3+
"http_server_config.static_config.ip": "0.0.0.0",
4+
"http_server_config.static_config.port": "$$$_HTTP_SERVER_CONFIG-STATIC_CONFIG-PORT_$$$"
55
}

crates/apollo_deployments/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub static KEYS_TO_BE_REPLACED: phf::Set<&'static str> = phf_set! {
7777
"gateway_config.contract_class_manager_config.native_compiler_config.max_cpu_time",
7878
"gateway_config.stateful_tx_validator_config.max_allowed_nonce_gap",
7979
"gateway_config.stateless_tx_validator_config.min_gas_price",
80-
"http_server_config.port",
80+
"http_server_config.static_config.port",
8181
"mempool_config.dynamic_config.transaction_ttl",
8282
"mempool_p2p_config.network_config.advertised_multiaddr.#is_none",
8383
"mempool_p2p_config.network_config.advertised_multiaddr",

crates/apollo_http_server/src/http_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl HttpServer {
6969
init_metrics();
7070

7171
// Parses the bind address from HttpServerConfig, returning an error for invalid addresses.
72-
let HttpServerConfig { ip, port, max_sierra_program_size: _ } = self.config;
72+
let (ip, port) = self.config.ip_and_port();
7373
let addr = SocketAddr::new(ip, port);
7474
let app = self.app();
7575
info!("HttpServer running using socket: {}", addr);
@@ -86,7 +86,7 @@ impl HttpServer {
8686
.with_state(self.app_state.clone())
8787
// Rest api endpoint
8888
.route("/gateway/add_transaction", post({
89-
let max_sierra_program_size = self.config.max_sierra_program_size;
89+
let max_sierra_program_size = self.config.dynamic_config.max_sierra_program_size;
9090
move |app_state: State<AppState>, headers: HeaderMap, tx: String| add_tx(app_state, headers, tx, max_sierra_program_size)
9191
}))
9292
.with_state(self.app_state.clone())

crates/apollo_http_server/src/test_utils.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ impl HttpTestClient {
8383
}
8484

8585
pub fn create_http_server_config(socket: SocketAddr) -> HttpServerConfig {
86-
HttpServerConfig {
87-
ip: socket.ip(),
88-
port: socket.port(),
89-
max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE,
90-
}
86+
HttpServerConfig::new(socket.ip(), socket.port(), DEFAULT_MAX_SIERRA_PROGRAM_SIZE)
9187
}
9288

9389
/// Creates an HTTP server and an HttpTestClient that can interact with it.
@@ -100,7 +96,7 @@ pub async fn http_client_server_setup(
10096
HttpServer::new(http_server_config.clone(), Arc::new(mock_gateway_client));
10197
tokio::spawn(async move { http_server.run().await });
10298

103-
let HttpServerConfig { ip, port, .. } = http_server_config;
99+
let (ip, port) = http_server_config.ip_and_port();
104100
let add_tx_http_client = HttpTestClient::new(SocketAddr::from((ip, port)));
105101

106102
// Ensure the server starts running.
@@ -155,11 +151,8 @@ pub async fn add_tx_http_client(
155151
let ip = IpAddr::from(Ipv4Addr::LOCALHOST);
156152
let mut available_ports =
157153
AvailablePorts::new(TestIdentifier::HttpServerUnitTests.into(), port_index);
158-
let http_server_config = HttpServerConfig {
159-
ip,
160-
port: available_ports.get_next_port(),
161-
max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE,
162-
};
154+
let http_server_config =
155+
HttpServerConfig::new(ip, available_ports.get_next_port(), DEFAULT_MAX_SIERRA_PROGRAM_SIZE);
163156
http_client_server_setup(mock_gateway_client, http_server_config).await
164157
}
165158

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BTreeMap;
22
use std::net::{IpAddr, Ipv4Addr};
33

4-
use apollo_config::dumping::{ser_param, SerializeConfig};
4+
use apollo_config::dumping::{prepend_sub_config_name, ser_param, SerializeConfig};
55
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
66
use serde::{Deserialize, Serialize};
77
use validator::Validate;
@@ -10,34 +10,73 @@ pub const HTTP_SERVER_PORT: u16 = 8080;
1010
pub const DEFAULT_MAX_SIERRA_PROGRAM_SIZE: usize = 4 * 1024 * 1024; // 4MB
1111

1212
/// The http server connection related configuration.
13-
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
13+
#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
1414
pub struct HttpServerConfig {
15+
pub dynamic_config: HttpServerDynamicConfig,
16+
pub static_config: HttpServerStaticConfig,
17+
}
18+
19+
impl SerializeConfig for HttpServerConfig {
20+
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
21+
let mut config = BTreeMap::new();
22+
config.extend(prepend_sub_config_name(self.dynamic_config.dump(), "dynamic_config"));
23+
config.extend(prepend_sub_config_name(self.static_config.dump(), "static_config"));
24+
config
25+
}
26+
}
27+
28+
impl HttpServerConfig {
29+
pub fn new(ip: IpAddr, port: u16, max_sierra_program_size: usize) -> Self {
30+
Self {
31+
dynamic_config: HttpServerDynamicConfig { max_sierra_program_size },
32+
static_config: HttpServerStaticConfig { ip, port },
33+
}
34+
}
35+
36+
pub fn ip_and_port(&self) -> (IpAddr, u16) {
37+
(self.static_config.ip, self.static_config.port)
38+
}
39+
}
40+
41+
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
42+
pub struct HttpServerStaticConfig {
1543
pub ip: IpAddr,
1644
pub port: u16,
17-
pub max_sierra_program_size: usize,
1845
}
1946

20-
impl SerializeConfig for HttpServerConfig {
47+
impl SerializeConfig for HttpServerStaticConfig {
2148
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
2249
BTreeMap::from_iter([
2350
ser_param("ip", &self.ip.to_string(), "The http server ip.", ParamPrivacyInput::Public),
2451
ser_param("port", &self.port, "The http server port.", ParamPrivacyInput::Public),
25-
ser_param(
26-
"max_sierra_program_size",
27-
&self.max_sierra_program_size,
28-
"The maximum size of a sierra program in bytes.",
29-
ParamPrivacyInput::Public,
30-
),
3152
])
3253
}
3354
}
3455

35-
impl Default for HttpServerConfig {
56+
impl Default for HttpServerStaticConfig {
3657
fn default() -> Self {
37-
Self {
38-
ip: IpAddr::from(Ipv4Addr::UNSPECIFIED),
39-
port: HTTP_SERVER_PORT,
40-
max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE,
41-
}
58+
Self { ip: IpAddr::from(Ipv4Addr::UNSPECIFIED), port: HTTP_SERVER_PORT }
59+
}
60+
}
61+
62+
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
63+
pub struct HttpServerDynamicConfig {
64+
pub max_sierra_program_size: usize,
65+
}
66+
67+
impl SerializeConfig for HttpServerDynamicConfig {
68+
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
69+
BTreeMap::from_iter([ser_param(
70+
"max_sierra_program_size",
71+
&self.max_sierra_program_size,
72+
"The maximum size of a sierra program in bytes.",
73+
ParamPrivacyInput::Public,
74+
)])
75+
}
76+
}
77+
78+
impl Default for HttpServerDynamicConfig {
79+
fn default() -> Self {
80+
Self { max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE }
4281
}
4382
}

crates/apollo_integration_tests/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ apollo_consensus_orchestrator_config.workspace = true
3131
apollo_deployments.workspace = true
3232
apollo_gateway_config.workspace = true
3333
apollo_http_server = { workspace = true, features = ["testing"] }
34-
apollo_http_server_config.workspace = true
3534
apollo_infra = { workspace = true, features = ["testing"] }
3635
apollo_infra_utils = { workspace = true, features = ["testing"] }
3736
apollo_l1_gas_price.workspace = true

crates/apollo_integration_tests/src/flow_test_setup.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use apollo_base_layer_tests::anvil_base_layer::AnvilBaseLayer;
66
use apollo_config::secrets::Sensitive;
77
use apollo_consensus_manager_config::config::ConsensusManagerConfig;
88
use apollo_http_server::test_utils::HttpTestClient;
9-
use apollo_http_server_config::config::HttpServerConfig;
109
use apollo_infra::metrics::{metrics_recorder, MetricsConfig};
1110
use apollo_infra_utils::test_utils::AvailablePorts;
1211
use apollo_l1_gas_price_provider_config::config::EthToStrkOracleConfig;
@@ -295,8 +294,7 @@ impl FlowSequencerSetup {
295294
node_config.monitoring_endpoint_config.as_ref().unwrap().to_owned();
296295
let monitoring_client = MonitoringClient::new(SocketAddr::from((ip, port)));
297296

298-
let HttpServerConfig { ip, port, .. } =
299-
node_config.http_server_config.as_ref().unwrap().to_owned();
297+
let (ip, port) = node_config.http_server_config.as_ref().unwrap().ip_and_port();
300298
let add_tx_http_client = HttpTestClient::new(SocketAddr::from((ip, port)));
301299

302300
// Run the sequencer node.

0 commit comments

Comments
 (0)