From 739dd00ce685dcdae510660015e9277e3f34b3ae Mon Sep 17 00:00:00 2001 From: nadin-Starkware Date: Mon, 13 Jan 2025 13:35:09 +0200 Subject: [PATCH] feat(starknet_integration_tests): support running a node with a delay in the integration test commit-id:ea14cf9d --- config/sequencer/default_config.json | 5 ++++ .../src/integration_test_setup.rs | 4 +++ .../src/sequencer_manager.rs | 30 ++++++++++++++----- .../src/config/component_config.rs | 24 +++++++++++---- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index dc7394cce9..98e8f820a0 100644 --- a/config/sequencer/default_config.json +++ b/config/sequencer/default_config.json @@ -344,6 +344,11 @@ "privacy": "Public", "value": "Enabled" }, + "components.delay_in_sec": { + "description": "The delay in seconds before starting the node.", + "privacy": "Public", + "value": 0 + }, "components.gateway.execution_mode": { "description": "The component execution mode.", "privacy": "Public", diff --git a/crates/starknet_integration_tests/src/integration_test_setup.rs b/crates/starknet_integration_tests/src/integration_test_setup.rs index 7d47929672..5bdeb23be3 100644 --- a/crates/starknet_integration_tests/src/integration_test_setup.rs +++ b/crates/starknet_integration_tests/src/integration_test_setup.rs @@ -50,6 +50,8 @@ impl From for NodeRunner { pub struct SequencerSetup { // Sequencer test identifier. pub sequencer_execution_id: SequencerExecutionId, + // Delay in seconds before starting the node. + pub delay_in_sec: u64, // Client for adding transactions to the sequencer node. pub add_tx_http_client: HttpTestClient, // Client for checking liveness of the sequencer node. @@ -84,6 +86,7 @@ impl SequencerSetup { mut state_sync_config: StateSyncConfig, mut available_ports: AvailablePorts, component_config: ComponentConfig, + delay_in_sec: u64, ) -> Self { // TODO(Nadin): pass the test storage as an argument. // Creating the storage for the test. @@ -131,6 +134,7 @@ impl SequencerSetup { node_config_path, state_sync_storage_handle: storage_for_test.state_sync_storage_handle, state_sync_storage_config: config.state_sync_config.storage_config, + delay_in_sec, } } diff --git a/crates/starknet_integration_tests/src/sequencer_manager.rs b/crates/starknet_integration_tests/src/sequencer_manager.rs index 528f461f70..50e6003b27 100644 --- a/crates/starknet_integration_tests/src/sequencer_manager.rs +++ b/crates/starknet_integration_tests/src/sequencer_manager.rs @@ -22,9 +22,10 @@ use starknet_sequencer_node::config::component_execution_config::{ ActiveComponentExecutionConfig, ReactiveComponentExecutionConfig, }; -use starknet_sequencer_node::test_utils::node_runner::spawn_run_node; +use starknet_sequencer_node::test_utils::node_runner::{spawn_run_node, NodeRunner}; use starknet_types_core::felt::Felt; -use tokio::task::JoinHandle; +use tokio::task::{self, JoinHandle}; +use tokio::time::{sleep, Duration}; use tracing::info; use crate::integration_test_setup::{SequencerExecutionId, SequencerSetup}; @@ -38,7 +39,7 @@ use crate::utils::{ }; /// The number of consolidated local sequencers that participate in the test. -const N_CONSOLIDATED_SEQUENCERS: usize = 3; +const N_CONSOLIDATED_SEQUENCERS: usize = 2; /// The number of distributed remote sequencers that participate in the test. const N_DISTRIBUTED_SEQUENCERS: usize = 2; @@ -72,10 +73,20 @@ impl SequencerSetupManager { let sequencer_run_handles = sequencers .iter() .map(|sequencer_setup| { - spawn_run_node( - sequencer_setup.node_config_path.clone(), - sequencer_setup.sequencer_execution_id.into(), - ) + let node_config_path = sequencer_setup.node_config_path.clone(); + let execution_id: NodeRunner = sequencer_setup.sequencer_execution_id.into(); + let delay_seconds = sequencer_setup.delay_in_sec; + + task::spawn(async move { + info!( + "Delaying {} start by {} seconds...", + execution_id.get_description(), + delay_seconds + ); + sleep(Duration::from_secs(delay_seconds)).await; + + spawn_run_node(node_config_path, execution_id); + }) }) .collect::>(); @@ -204,6 +215,10 @@ pub(crate) async fn get_sequencer_setup_configs( &mut available_ports, N_DISTRIBUTED_SEQUENCERS, )); + combined.extend(vec![ComposedComponentConfigs::new(vec![ComponentConfig { + delay_in_sec: 30, + ..ComponentConfig::default() + }])]); combined }; @@ -280,6 +295,7 @@ pub(crate) async fn get_sequencer_setup_configs( state_sync_config, AvailablePorts::new(test_unique_id.into(), index.try_into().unwrap()), component_config.clone(), + component_config.delay_in_sec, ) .await } diff --git a/crates/starknet_sequencer_node/src/config/component_config.rs b/crates/starknet_sequencer_node/src/config/component_config.rs index 50f959a690..cd94b11246 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; -use papyrus_config::dumping::{append_sub_config_name, SerializeConfig}; -use papyrus_config::{ParamPath, SerializedParam}; +use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; +use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use serde::{Deserialize, Serialize}; use validator::Validate; @@ -36,11 +36,21 @@ pub struct ComponentConfig { pub l1_scraper: ActiveComponentExecutionConfig, #[validate] pub monitoring_endpoint: ActiveComponentExecutionConfig, + + // Delay in seconds before starting the node. + pub delay_in_sec: u64, } impl SerializeConfig for ComponentConfig { fn dump(&self) -> BTreeMap { - let sub_configs = vec![ + let members = BTreeMap::from_iter([ser_param( + "delay_in_sec", + &self.delay_in_sec, + "The delay in seconds before starting the node.", + ParamPrivacyInput::Public, + )]); + vec![ + members, append_sub_config_name(self.batcher.dump(), "batcher"), append_sub_config_name(self.consensus_manager.dump(), "consensus_manager"), append_sub_config_name(self.gateway.dump(), "gateway"), @@ -51,9 +61,10 @@ impl SerializeConfig for ComponentConfig { append_sub_config_name(self.mempool_p2p.dump(), "mempool_p2p"), append_sub_config_name(self.monitoring_endpoint.dump(), "monitoring_endpoint"), append_sub_config_name(self.state_sync.dump(), "state_sync"), - ]; - - sub_configs.into_iter().flatten().collect() + ] + .into_iter() + .flatten() + .collect() } } @@ -71,6 +82,7 @@ impl ComponentConfig { consensus_manager: ActiveComponentExecutionConfig::disabled(), http_server: ActiveComponentExecutionConfig::disabled(), monitoring_endpoint: ActiveComponentExecutionConfig::disabled(), + delay_in_sec: 0, } } }