Skip to content

Commit 8f9731c

Browse files
apollo_integration_tests: set only required configs for nodes (#8425)
1 parent 24297c2 commit 8f9731c

File tree

3 files changed

+74
-38
lines changed

3 files changed

+74
-38
lines changed

crates/apollo_integration_tests/src/utils.rs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use apollo_monitoring_endpoint::config::MonitoringEndpointConfig;
3838
use apollo_network::network_manager::test_utils::create_connected_network_configs;
3939
use apollo_network::NetworkConfig;
4040
use apollo_node::config::component_config::ComponentConfig;
41+
use apollo_node::config::component_execution_config::ExpectedComponentConfig;
4142
use apollo_node::config::definitions::ConfigPointersMap;
4243
use apollo_node::config::monitoring::MonitoringConfig;
4344
use apollo_node::config::node_config::{SequencerNodeConfig, CONFIG_POINTERS};
@@ -255,23 +256,43 @@ pub fn create_node_config(
255256
to_value(starknet_url).expect("Failed to serialize starknet_url"),
256257
);
257258

259+
// A helper macro that wraps the config in `Some(...)` if `components.<field>` expects it;
260+
// otherwise returns `None`. Assumes `components` is in scope.
261+
macro_rules! wrap_if_component_config_expected {
262+
($component_field:ident, $config_field:expr) => {{
263+
if components.$component_field.is_component_config_expected() {
264+
Some($config_field)
265+
} else {
266+
None
267+
}
268+
}};
269+
}
270+
271+
// Retain only the required configs.
258272
let base_layer_config = Some(base_layer_config);
259-
let batcher_config = Some(batcher_config);
260-
let class_manager_config = Some(class_manager_config);
261-
let consensus_manager_config = Some(consensus_manager_config);
262-
let gateway_config = Some(gateway_config);
263-
let http_server_config = Some(http_server_config);
264-
let l1_endpoint_monitor_config = Some(l1_endpoint_monitor_config);
265-
let l1_gas_price_provider_config = Some(l1_gas_price_provider_config);
266-
let l1_gas_price_scraper_config = Some(l1_gas_price_scraper_config);
267-
let l1_provider_config = Some(l1_provider_config);
268-
let l1_scraper_config = Some(l1_scraper_config);
269-
let mempool_config = Some(mempool_config);
270-
let mempool_p2p_config = Some(mempool_p2p_config);
271-
let monitoring_endpoint_config = Some(monitoring_endpoint_config);
273+
let batcher_config = wrap_if_component_config_expected!(batcher, batcher_config);
274+
let class_manager_config =
275+
wrap_if_component_config_expected!(class_manager, class_manager_config);
276+
let consensus_manager_config =
277+
wrap_if_component_config_expected!(consensus_manager, consensus_manager_config);
278+
let gateway_config = wrap_if_component_config_expected!(gateway, gateway_config);
279+
let http_server_config = wrap_if_component_config_expected!(http_server, http_server_config);
280+
let l1_endpoint_monitor_config =
281+
wrap_if_component_config_expected!(l1_endpoint_monitor, l1_endpoint_monitor_config);
282+
let l1_gas_price_provider_config =
283+
wrap_if_component_config_expected!(l1_gas_price_provider, l1_gas_price_provider_config);
284+
let l1_gas_price_scraper_config =
285+
wrap_if_component_config_expected!(l1_gas_price_scraper, l1_gas_price_scraper_config);
286+
let l1_provider_config = wrap_if_component_config_expected!(l1_provider, l1_provider_config);
287+
let l1_scraper_config = wrap_if_component_config_expected!(l1_scraper, l1_scraper_config);
288+
let mempool_config = wrap_if_component_config_expected!(mempool, mempool_config);
289+
let mempool_p2p_config = wrap_if_component_config_expected!(mempool_p2p, mempool_p2p_config);
290+
let monitoring_endpoint_config =
291+
wrap_if_component_config_expected!(monitoring_endpoint, monitoring_endpoint_config);
272292
let monitoring_config = MonitoringConfig::default();
273-
let sierra_compiler_config = Some(sierra_compiler_config);
274-
let state_sync_config = Some(state_sync_config);
293+
let sierra_compiler_config =
294+
wrap_if_component_config_expected!(sierra_compiler, sierra_compiler_config);
295+
let state_sync_config = wrap_if_component_config_expected!(state_sync, state_sync_config);
275296

276297
let sequencer_node_config = SequencerNodeConfig {
277298
base_layer_config,
@@ -328,7 +349,7 @@ pub(crate) fn create_consensus_manager_configs_from_network_configs(
328349
builder_address: ContractAddress::from(4_u128),
329350
..Default::default()
330351
},
331-
cende_config: CendeConfig{
352+
cende_config: CendeConfig {
332353
skip_write_height: Some(BlockNumber(1)),
333354
..Default::default()
334355
},

crates/apollo_node/src/config/component_execution_config.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const DEFAULT_INVALID_PORT: u16 = 0;
1717

1818
pub const MAX_CONCURRENCY: usize = 8;
1919

20+
pub trait ExpectedComponentConfig {
21+
fn is_component_config_expected(&self) -> bool;
22+
}
23+
2024
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
2125
pub enum ReactiveComponentExecutionMode {
2226
Disabled,
@@ -25,12 +29,33 @@ pub enum ReactiveComponentExecutionMode {
2529
LocalExecutionWithRemoteDisabled,
2630
}
2731

32+
impl ExpectedComponentConfig for ReactiveComponentExecutionMode {
33+
fn is_component_config_expected(&self) -> bool {
34+
match self {
35+
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => {
36+
false
37+
}
38+
ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled
39+
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled => true,
40+
}
41+
}
42+
}
43+
2844
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
2945
pub enum ActiveComponentExecutionMode {
3046
Disabled,
3147
Enabled,
3248
}
3349

50+
impl ExpectedComponentConfig for ActiveComponentExecutionMode {
51+
fn is_component_config_expected(&self) -> bool {
52+
match self {
53+
ActiveComponentExecutionMode::Disabled => false,
54+
ActiveComponentExecutionMode::Enabled => true,
55+
}
56+
}
57+
}
58+
3459
/// Reactive component configuration.
3560
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
3661
#[validate(schema(function = "validate_reactive_component_execution_config"))]
@@ -154,6 +179,12 @@ impl ReactiveComponentExecutionConfig {
154179
}
155180
}
156181

182+
impl ExpectedComponentConfig for ReactiveComponentExecutionConfig {
183+
fn is_component_config_expected(&self) -> bool {
184+
self.execution_mode.is_component_config_expected()
185+
}
186+
}
187+
157188
/// Active component configuration.
158189
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
159190
#[validate(schema(function = "validate_active_component_execution_config"))]
@@ -178,6 +209,12 @@ impl Default for ActiveComponentExecutionConfig {
178209
}
179210
}
180211

212+
impl ExpectedComponentConfig for ActiveComponentExecutionConfig {
213+
fn is_component_config_expected(&self) -> bool {
214+
self.execution_mode.is_component_config_expected()
215+
}
216+
}
217+
181218
impl ActiveComponentExecutionConfig {
182219
pub fn disabled() -> Self {
183220
Self { execution_mode: ActiveComponentExecutionMode::Disabled }

crates/apollo_node/src/config/config_utils.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ use apollo_config::dumping::{combine_config_map_and_pointers, Pointers, Serializ
66
use apollo_config::{ParamPath, SerializedParam};
77
use apollo_infra_utils::dumping::serialize_to_file;
88
use apollo_infra_utils::path::resolve_project_relative_path;
9-
use apollo_monitoring_endpoint::config::MonitoringEndpointConfig;
109
use serde_json::{Map, Value};
1110
use tracing::error;
1211
use validator::ValidationError;
1312

14-
use crate::config::component_config::ComponentConfig;
1513
use crate::config::definitions::ConfigPointersMap;
1614
use crate::config::node_config::{
1715
SequencerNodeConfig,
@@ -121,20 +119,6 @@ fn validate_all_pointer_targets_set(preset: Value) -> Result<(), ValidationError
121119
}
122120
}
123121

124-
pub struct BaseAppConfigOverride {
125-
component_config: ComponentConfig,
126-
monitoring_endpoint_config: Option<MonitoringEndpointConfig>,
127-
}
128-
129-
impl BaseAppConfigOverride {
130-
pub fn new(
131-
component_config: ComponentConfig,
132-
monitoring_endpoint_config: Option<MonitoringEndpointConfig>,
133-
) -> Self {
134-
Self { component_config, monitoring_endpoint_config }
135-
}
136-
}
137-
138122
#[derive(Debug, Clone, Default)]
139123
pub struct DeploymentBaseAppConfig {
140124
pub config: SequencerNodeConfig,
@@ -173,12 +157,6 @@ impl DeploymentBaseAppConfig {
173157
modify_config_pointers_fn(&mut self.config_pointers_map);
174158
}
175159

176-
pub fn override_base_app_config(&mut self, base_app_config_override: BaseAppConfigOverride) {
177-
self.config.components = base_app_config_override.component_config;
178-
self.config.monitoring_endpoint_config =
179-
base_app_config_override.monitoring_endpoint_config;
180-
}
181-
182160
pub fn as_value(&self) -> Value {
183161
// Create the entire mapping of the config and the pointers, without the required params.
184162
let config_as_map = combine_config_map_and_pointers(

0 commit comments

Comments
 (0)