Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"http_server_config.ip": "0.0.0.0",
"http_server_config.port": "",
"http_server_config.max_sierra_program_size": 4194304
"http_server_config.dynamic_config.max_sierra_program_size": 4194304,
"http_server_config.static_config.ip": "0.0.0.0",
"http_server_config.static_config.port": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@
"consensus_manager_config.stream_handler_config.channel_buffer_capacity": 1000,
"consensus_manager_config.stream_handler_config.max_streams": 100,
"consensus_manager_config.votes_topic": "consensus_votes"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"http_server_config.ip": "0.0.0.0",
"http_server_config.max_sierra_program_size": 4194304,
"http_server_config.port": "$$$_HTTP_SERVER_CONFIG-PORT_$$$"
"http_server_config.dynamic_config.max_sierra_program_size": 4194304,
"http_server_config.static_config.ip": "0.0.0.0",
"http_server_config.static_config.port": "$$$_HTTP_SERVER_CONFIG-STATIC_CONFIG-PORT_$$$"
}
2 changes: 1 addition & 1 deletion crates/apollo_deployments/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub static KEYS_TO_BE_REPLACED: phf::Set<&'static str> = phf_set! {
"gateway_config.contract_class_manager_config.native_compiler_config.max_cpu_time",
"gateway_config.stateful_tx_validator_config.max_allowed_nonce_gap",
"gateway_config.stateless_tx_validator_config.min_gas_price",
"http_server_config.port",
"http_server_config.static_config.port",
"mempool_config.dynamic_config.transaction_ttl",
"mempool_p2p_config.network_config.advertised_multiaddr.#is_none",
"mempool_p2p_config.network_config.advertised_multiaddr",
Expand Down
4 changes: 2 additions & 2 deletions crates/apollo_http_server/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl HttpServer {
init_metrics();

// Parses the bind address from HttpServerConfig, returning an error for invalid addresses.
let HttpServerConfig { ip, port, max_sierra_program_size: _ } = self.config;
let (ip, port) = self.config.ip_and_port();
let addr = SocketAddr::new(ip, port);
let app = self.app();
info!("HttpServer running using socket: {}", addr);
Expand All @@ -86,7 +86,7 @@ impl HttpServer {
.with_state(self.app_state.clone())
// Rest api endpoint
.route("/gateway/add_transaction", post({
let max_sierra_program_size = self.config.max_sierra_program_size;
let max_sierra_program_size = self.config.dynamic_config.max_sierra_program_size;
move |app_state: State<AppState>, headers: HeaderMap, tx: String| add_tx(app_state, headers, tx, max_sierra_program_size)
}))
.with_state(self.app_state.clone())
Expand Down
15 changes: 4 additions & 11 deletions crates/apollo_http_server/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ impl HttpTestClient {
}

pub fn create_http_server_config(socket: SocketAddr) -> HttpServerConfig {
HttpServerConfig {
ip: socket.ip(),
port: socket.port(),
max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE,
}
HttpServerConfig::new(socket.ip(), socket.port(), DEFAULT_MAX_SIERRA_PROGRAM_SIZE)
}

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

let HttpServerConfig { ip, port, .. } = http_server_config;
let (ip, port) = http_server_config.ip_and_port();
let add_tx_http_client = HttpTestClient::new(SocketAddr::from((ip, port)));

// Ensure the server starts running.
Expand Down Expand Up @@ -155,11 +151,8 @@ pub async fn add_tx_http_client(
let ip = IpAddr::from(Ipv4Addr::LOCALHOST);
let mut available_ports =
AvailablePorts::new(TestIdentifier::HttpServerUnitTests.into(), port_index);
let http_server_config = HttpServerConfig {
ip,
port: available_ports.get_next_port(),
max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE,
};
let http_server_config =
HttpServerConfig::new(ip, available_ports.get_next_port(), DEFAULT_MAX_SIERRA_PROGRAM_SIZE);
http_client_server_setup(mock_gateway_client, http_server_config).await
}

Expand Down
71 changes: 55 additions & 16 deletions crates/apollo_http_server_config/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::net::{IpAddr, Ipv4Addr};

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

/// The http server connection related configuration.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
pub struct HttpServerConfig {
pub dynamic_config: HttpServerDynamicConfig,
pub static_config: HttpServerStaticConfig,
}

impl SerializeConfig for HttpServerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let mut config = BTreeMap::new();
config.extend(prepend_sub_config_name(self.dynamic_config.dump(), "dynamic_config"));
config.extend(prepend_sub_config_name(self.static_config.dump(), "static_config"));
config
}
}

impl HttpServerConfig {
pub fn new(ip: IpAddr, port: u16, max_sierra_program_size: usize) -> Self {
Self {
dynamic_config: HttpServerDynamicConfig { max_sierra_program_size },
static_config: HttpServerStaticConfig { ip, port },
}
}

pub fn ip_and_port(&self) -> (IpAddr, u16) {
(self.static_config.ip, self.static_config.port)
}
}

#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct HttpServerStaticConfig {
pub ip: IpAddr,
pub port: u16,
pub max_sierra_program_size: usize,
}

impl SerializeConfig for HttpServerConfig {
impl SerializeConfig for HttpServerStaticConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param("ip", &self.ip.to_string(), "The http server ip.", ParamPrivacyInput::Public),
ser_param("port", &self.port, "The http server port.", ParamPrivacyInput::Public),
ser_param(
"max_sierra_program_size",
&self.max_sierra_program_size,
"The maximum size of a sierra program in bytes.",
ParamPrivacyInput::Public,
),
])
}
}

impl Default for HttpServerConfig {
impl Default for HttpServerStaticConfig {
fn default() -> Self {
Self {
ip: IpAddr::from(Ipv4Addr::UNSPECIFIED),
port: HTTP_SERVER_PORT,
max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE,
}
Self { ip: IpAddr::from(Ipv4Addr::UNSPECIFIED), port: HTTP_SERVER_PORT }
}
}

#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct HttpServerDynamicConfig {
pub max_sierra_program_size: usize,
}

impl SerializeConfig for HttpServerDynamicConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([ser_param(
"max_sierra_program_size",
&self.max_sierra_program_size,
"The maximum size of a sierra program in bytes.",
ParamPrivacyInput::Public,
)])
}
}

impl Default for HttpServerDynamicConfig {
fn default() -> Self {
Self { max_sierra_program_size: DEFAULT_MAX_SIERRA_PROGRAM_SIZE }
}
}
1 change: 0 additions & 1 deletion crates/apollo_integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ apollo_consensus_orchestrator_config.workspace = true
apollo_deployments.workspace = true
apollo_gateway_config.workspace = true
apollo_http_server = { workspace = true, features = ["testing"] }
apollo_http_server_config.workspace = true
apollo_infra = { workspace = true, features = ["testing"] }
apollo_infra_utils = { workspace = true, features = ["testing"] }
apollo_l1_gas_price.workspace = true
Expand Down
4 changes: 1 addition & 3 deletions crates/apollo_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use apollo_base_layer_tests::anvil_base_layer::AnvilBaseLayer;
use apollo_config::secrets::Sensitive;
use apollo_consensus_manager_config::config::ConsensusManagerConfig;
use apollo_http_server::test_utils::HttpTestClient;
use apollo_http_server_config::config::HttpServerConfig;
use apollo_infra::metrics::{metrics_recorder, MetricsConfig};
use apollo_infra_utils::test_utils::AvailablePorts;
use apollo_l1_gas_price_provider_config::config::EthToStrkOracleConfig;
Expand Down Expand Up @@ -295,8 +294,7 @@ impl FlowSequencerSetup {
node_config.monitoring_endpoint_config.as_ref().unwrap().to_owned();
let monitoring_client = MonitoringClient::new(SocketAddr::from((ip, port)));

let HttpServerConfig { ip, port, .. } =
node_config.http_server_config.as_ref().unwrap().to_owned();
let (ip, port) = node_config.http_server_config.as_ref().unwrap().ip_and_port();
let add_tx_http_client = HttpTestClient::new(SocketAddr::from((ip, port)));

// Run the sequencer node.
Expand Down
18 changes: 12 additions & 6 deletions crates/apollo_integration_tests/src/integration_test_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use apollo_base_layer_tests::anvil_base_layer::AnvilBaseLayer;
use apollo_deployments::deployment_definitions::ComponentConfigInService;
use apollo_deployments::service::{NodeService, NodeType};
use apollo_http_server::test_utils::HttpTestClient;
use apollo_http_server_config::config::HttpServerConfig;
use apollo_infra_utils::dumping::serialize_to_file;
use apollo_infra_utils::test_utils::{AvailablePortsGenerator, TestIdentifier};
use apollo_infra_utils::tracing::{CustomLogger, TraceLevel};
Expand Down Expand Up @@ -143,8 +142,8 @@ impl NodeSetup {
.as_ref()
.unwrap_or_else(|| panic!("Http server config should be set for this node"));

let HttpServerConfig { ip, port, .. } = http_server_config;
let add_tx_http_client = HttpTestClient::new(SocketAddr::new(*ip, *port));
let (ip, port) = http_server_config.ip_and_port();
let add_tx_http_client = HttpTestClient::new(SocketAddr::new(ip, port));

Self { node_type, executables, add_tx_http_client, storage_handles }
}
Expand Down Expand Up @@ -180,8 +179,15 @@ impl NodeSetup {
}

pub fn generate_simulator_ports_json(&self, path: &str) {
let (_, http_port) = self
.get_http_server()
.get_config()
.http_server_config
.as_ref()
.expect("Should have http server config")
.ip_and_port();
let json_data = serde_json::json!({
HTTP_PORT_ARG: self.get_http_server().get_config().http_server_config.as_ref().expect("Should have http server config").port,
HTTP_PORT_ARG: http_port,
MONITORING_PORT_ARG: self.get_batcher().get_config().monitoring_endpoint_config.as_ref().expect("Should have monitoring endpoint config").port
});
serialize_to_file(&json_data, path);
Expand Down Expand Up @@ -641,12 +647,12 @@ impl IntegrationTestManager {
.unwrap_or_else(|| self.idle_nodes.get(&0).expect("Node 0 doesn't exist"));

let http_server = node_0_setup.get_http_server();
let http_server_port = http_server
let (_, http_server_port) = http_server
.get_config()
.http_server_config
.as_ref()
.expect("No executable with a set http server.")
.port;
.ip_and_port();
let localhost_url = format!("http://{}", Ipv4Addr::LOCALHOST);
let monitoring_port = http_server
.get_config()
Expand Down
14 changes: 7 additions & 7 deletions crates/apollo_node/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2509,17 +2509,17 @@
"privacy": "TemporaryValue",
"value": false
},
"http_server_config.ip": {
"description": "The http server ip.",
"privacy": "Public",
"value": "0.0.0.0"
},
"http_server_config.max_sierra_program_size": {
"http_server_config.dynamic_config.max_sierra_program_size": {
"description": "The maximum size of a sierra program in bytes.",
"privacy": "Public",
"value": 4194304
},
"http_server_config.port": {
"http_server_config.static_config.ip": {
"description": "The http server ip.",
"privacy": "Public",
"value": "0.0.0.0"
},
"http_server_config.static_config.port": {
"description": "The http server port.",
"privacy": "Public",
"value": 8080
Expand Down
4 changes: 2 additions & 2 deletions deployments/monitoring/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ services:
echo 'Injecting config changes...' && \
jq '.\"recorder_url\" = \"http://dummy_recorder:8080\"' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
jq '.\"l1_gas_price_provider_config.eth_to_strk_oracle_config.url_header_list\" = \"http://dummy_eth_to_strk_oracle:9000/eth_to_strk_oracle\"' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
jq '.\"http_server_config.ip\" = \"0.0.0.0\"' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
jq '.\"http_server_config.port\" = ${SEQUENCER_HTTP_PORT}' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
jq '.\"http_server_config.static_config.ip\" = \"0.0.0.0\"' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
jq '.\"http_server_config.static_config.port\" = ${SEQUENCER_HTTP_PORT}' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
jq '.\"monitoring_endpoint_config.port\" = ${SEQUENCER_MONITORING_PORT}' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
# These are here to avoid using an L1 baselayer. This is because anvil was deliberately disabled in the docker test.
jq '.\"components.l1_scraper.execution_mode\" = \"Disabled\"' ${SEQUENCER_CONFIG_PATH} | sponge ${SEQUENCER_CONFIG_PATH} && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ config:
gateway_config_contract_class_manager_config_native_compiler_config_max_cpu_time: 600
gateway_config_stateful_tx_validator_config_max_allowed_nonce_gap: 200
gateway_config_stateless_tx_validator_config_min_gas_price: 3000000000
http_server_config_port: 8080
http_server_config_static_config_port: 8080

service:
enabled: true
Expand Down
Loading