Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(starknet_integration_tests): support running a node with a delay in the integration test #3271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl From<SequencerExecutionId> 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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
}

Expand Down
30 changes: 23 additions & 7 deletions crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;

Expand Down Expand Up @@ -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::<Vec<_>>();

Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 18 additions & 6 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<ParamPath, SerializedParam> {
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"),
Expand All @@ -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()
}
}

Expand All @@ -71,6 +82,7 @@ impl ComponentConfig {
consensus_manager: ActiveComponentExecutionConfig::disabled(),
http_server: ActiveComponentExecutionConfig::disabled(),
monitoring_endpoint: ActiveComponentExecutionConfig::disabled(),
delay_in_sec: 0,
}
}
}
Loading