Skip to content

Commit

Permalink
feat(starknet_integration_tests): enable state sync in integration te…
Browse files Browse the repository at this point in the history
…st (#3261)

* refactor(starknet_integration_tests): refactor create_state_sync_config to create multi configs

commit-id:da683768

* feat(starknet_integration_tests): enable state sync in integration test

commit-id:0a4937c9
  • Loading branch information
nadin-Starkware authored Jan 13, 2025
1 parent 034a3d0 commit d6ecbe4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
10 changes: 9 additions & 1 deletion crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::utils::{
create_consensus_manager_configs_from_network_configs,
create_mempool_p2p_configs,
create_node_config,
create_state_sync_configs,
spawn_success_recorder,
};

Expand Down Expand Up @@ -137,13 +138,20 @@ impl FlowSequencerSetup {

let component_config = ComponentConfig::default();

let state_sync_config = create_state_sync_configs(
storage_for_test.state_sync_storage_config,
available_ports.get_next_ports(1),
)
.pop()
.unwrap();

// Derive the configuration for the sequencer node.
let (node_config, _required_params) = create_node_config(
&mut available_ports,
SequencerExecutionId::new(sequencer_index, 0),
chain_info,
storage_for_test.batcher_storage_config,
storage_for_test.state_sync_storage_config,
state_sync_config,
consensus_manager_config,
mempool_p2p_config,
component_config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use starknet_monitoring_endpoint::test_utils::MonitoringClient;
use starknet_sequencer_infra::test_utils::AvailablePorts;
use starknet_sequencer_node::config::component_config::ComponentConfig;
use starknet_sequencer_node::test_utils::node_runner::NodeRunner;
use starknet_state_sync::config::StateSyncConfig;
use tempfile::{tempdir, TempDir};
use tracing::instrument;

Expand Down Expand Up @@ -71,6 +72,7 @@ pub struct SequencerSetup {
}

// TODO(Tsabary/ Nadin): reduce number of args.
#[allow(clippy::too_many_arguments)]
impl SequencerSetup {
#[instrument(skip(accounts, chain_info, consensus_manager_config), level = "debug")]
pub async fn new(
Expand All @@ -79,22 +81,26 @@ impl SequencerSetup {
chain_info: ChainInfo,
mut consensus_manager_config: ConsensusManagerConfig,
mempool_p2p_config: MempoolP2pConfig,
mut state_sync_config: StateSyncConfig,
mut available_ports: AvailablePorts,
component_config: ComponentConfig,
) -> Self {
// TODO(Nadin): pass the test storage as an argument.
// Creating the storage for the test.
let storage_for_test = StorageTestSetup::new(accounts, &chain_info);

let recorder_url = spawn_success_recorder(available_ports.get_next_port());
consensus_manager_config.cende_config.recorder_url = recorder_url;

state_sync_config.storage_config = storage_for_test.state_sync_storage_config;

// Derive the configuration for the sequencer node.
let (config, required_params) = create_node_config(
&mut available_ports,
sequencer_execution_id,
chain_info,
storage_for_test.batcher_storage_config,
storage_for_test.state_sync_storage_config,
state_sync_config,
consensus_manager_config,
mempool_p2p_config,
component_config,
Expand Down
21 changes: 18 additions & 3 deletions crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransac
use papyrus_execution::execution_utils::get_nonce_at;
use papyrus_network::network_manager::test_utils::create_connected_network_configs;
use papyrus_storage::state::StateStorageReader;
use papyrus_storage::StorageReader;
use papyrus_storage::{StorageConfig, StorageReader};
use starknet_api::block::BlockNumber;
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::rpc_transaction::RpcTransaction;
Expand All @@ -33,6 +33,7 @@ use crate::utils::{
create_chain_info,
create_consensus_manager_configs_from_network_configs,
create_mempool_p2p_configs,
create_state_sync_configs,
send_account_txs,
};

Expand Down Expand Up @@ -218,6 +219,13 @@ pub(crate) async fn get_sequencer_setup_configs(
create_connected_network_configs(available_ports.get_next_ports(n_distributed_sequencers)),
);

// TODO(Nadin): define the test storage here and pass it to the create_state_sync_configs and to
// the SequencerSetup
let state_sync_configs = create_state_sync_configs(
StorageConfig::default(),
available_ports.get_next_ports(n_distributed_sequencers),
);

let mempool_p2p_configs = create_mempool_p2p_configs(
chain_info.chain_id.clone(),
available_ports.get_next_ports(n_distributed_sequencers),
Expand All @@ -243,8 +251,13 @@ pub(crate) async fn get_sequencer_setup_configs(
// needs only one of them, but the current setup creates one per part. Need to refactor.

stream::iter(
izip!(indexed_component_configs, consensus_manager_configs, mempool_p2p_configs)
.enumerate(),
izip!(
indexed_component_configs,
consensus_manager_configs,
mempool_p2p_configs,
state_sync_configs
)
.enumerate(),
)
.then(
|(
Expand All @@ -253,6 +266,7 @@ pub(crate) async fn get_sequencer_setup_configs(
(sequencer_execution_id, component_config),
consensus_manager_config,
mempool_p2p_config,
state_sync_config,
),
)| {
let chain_info = chain_info.clone();
Expand All @@ -263,6 +277,7 @@ pub(crate) async fn get_sequencer_setup_configs(
chain_info,
consensus_manager_config,
mempool_p2p_config,
state_sync_config,
AvailablePorts::new(test_unique_id.into(), index.try_into().unwrap()),
component_config.clone(),
)
Expand Down
22 changes: 12 additions & 10 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn create_node_config(
sequencer_execution_id: SequencerExecutionId,
chain_info: ChainInfo,
batcher_storage_config: StorageConfig,
state_sync_storage_config: StorageConfig,
state_sync_config: StateSyncConfig,
mut consensus_manager_config: ConsensusManagerConfig,
mempool_p2p_config: MempoolP2pConfig,
component_config: ComponentConfig,
Expand All @@ -89,8 +89,6 @@ pub async fn create_node_config(
create_http_server_config(available_ports.get_next_local_host_socket());
let monitoring_endpoint_config =
MonitoringEndpointConfig { port: available_ports.get_next_port(), ..Default::default() };
let state_sync_config =
create_state_sync_config(state_sync_storage_config, available_ports.get_next_port());

(
SequencerNodeConfig {
Expand Down Expand Up @@ -328,12 +326,16 @@ fn set_validator_id(
validator_id
}

pub fn create_state_sync_config(
pub fn create_state_sync_configs(
state_sync_storage_config: StorageConfig,
port: u16,
) -> StateSyncConfig {
let mut config =
StateSyncConfig { storage_config: state_sync_storage_config, ..Default::default() };
config.network_config.tcp_port = port;
config
ports: Vec<u16>,
) -> Vec<StateSyncConfig> {
create_connected_network_configs(ports)
.into_iter()
.map(|network_config| StateSyncConfig {
storage_config: state_sync_storage_config.clone(),
network_config,
..Default::default()
})
.collect()
}

0 comments on commit d6ecbe4

Please sign in to comment.