From aba57aff1eb71319ecfff3c27f31345ca2f5ab48 Mon Sep 17 00:00:00 2001 From: Alon Haramati Date: Tue, 17 Dec 2024 10:26:17 +0200 Subject: [PATCH] test(starknet_integration_tests): add second node --- Cargo.lock | 1 + crates/papyrus_config/src/dumping.rs | 2 +- crates/papyrus_network/src/gossipsub_impl.rs | 6 +- .../src/network_manager/test_utils.rs | 2 +- crates/starknet_gateway/src/gateway.rs | 3 +- crates/starknet_integration_tests/Cargo.toml | 1 + .../src/config_utils.rs | 69 +++++++++-- .../src/end_to_end_integration.rs | 52 ++++++--- .../src/flow_test_setup.rs | 13 ++- .../src/integration_test_setup.rs | 109 +++++++++++++++--- .../starknet_integration_tests/src/utils.rs | 19 +-- crates/starknet_mempool/src/mempool.rs | 3 +- .../src/test_utils.rs | 13 ++- .../src/test_utils/node_runner.rs | 4 +- 14 files changed, 227 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0255447d2d2..395dfe1bcaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10482,6 +10482,7 @@ dependencies = [ "itertools 0.12.1", "mempool_test_utils", "papyrus_common", + "papyrus_config", "papyrus_consensus", "papyrus_execution", "papyrus_network", diff --git a/crates/papyrus_config/src/dumping.rs b/crates/papyrus_config/src/dumping.rs index 1acddda1123..7b13b046414 100644 --- a/crates/papyrus_config/src/dumping.rs +++ b/crates/papyrus_config/src/dumping.rs @@ -363,7 +363,7 @@ pub fn ser_pointer_target_required_param( /// Updates entries in the map to point to these targets, replacing values of entries that match /// the target parameter paths to contain only the name of the target they point to. /// Fails if a param is not pointing to a same-named pointer target nor whitelisted. -pub(crate) fn combine_config_map_and_pointers( +pub fn combine_config_map_and_pointers( mut config_map: BTreeMap, pointers: &ConfigPointers, non_pointer_params: &Pointers, diff --git a/crates/papyrus_network/src/gossipsub_impl.rs b/crates/papyrus_network/src/gossipsub_impl.rs index f2d4327ff36..eb907768651 100644 --- a/crates/papyrus_network/src/gossipsub_impl.rs +++ b/crates/papyrus_network/src/gossipsub_impl.rs @@ -6,10 +6,10 @@ use crate::mixed_behaviour; use crate::mixed_behaviour::BridgedBehaviour; use crate::sqmr::Bytes; -#[cfg(test)] +// #[cfg(test)] pub type Topic = gossipsub::IdentTopic; -#[cfg(not(test))] -pub type Topic = gossipsub::Sha256Topic; +// #[cfg(not(test))] +// pub type Topic = gossipsub::Sha256Topic; #[derive(Debug)] pub enum ExternalEvent { diff --git a/crates/papyrus_network/src/network_manager/test_utils.rs b/crates/papyrus_network/src/network_manager/test_utils.rs index be1f65427b8..e7b59e4695c 100644 --- a/crates/papyrus_network/src/network_manager/test_utils.rs +++ b/crates/papyrus_network/src/network_manager/test_utils.rs @@ -188,7 +188,7 @@ where const BUFFER_SIZE: usize = 1000; let mut channels_configs = create_connected_network_configs(n_configs + 1); - let broadcast_channels = channels_configs.remove(0); + let broadcast_channels = channels_configs.pop().unwrap(); let mut channels_network_manager = NetworkManager::new(broadcast_channels, None); let broadcast_channels = diff --git a/crates/starknet_gateway/src/gateway.rs b/crates/starknet_gateway/src/gateway.rs index 5c720b7247a..7cb443084b1 100644 --- a/crates/starknet_gateway/src/gateway.rs +++ b/crates/starknet_gateway/src/gateway.rs @@ -11,7 +11,7 @@ use starknet_mempool_types::communication::{AddTransactionArgsWrapper, SharedMem use starknet_mempool_types::mempool_types::{AccountState, AddTransactionArgs}; use starknet_sequencer_infra::component_definitions::ComponentStarter; use starknet_sierra_compile::config::SierraToCasmCompilationConfig; -use tracing::{error, instrument, Span}; +use tracing::{error, info, instrument, Span}; use crate::compilation::GatewayCompiler; use crate::config::{GatewayConfig, RpcStateReaderConfig}; @@ -64,6 +64,7 @@ impl Gateway { tx: RpcTransaction, p2p_message_metadata: Option, ) -> GatewayResult { + info!("Processing tx: {:?}", tx); let blocking_task = ProcessTxBlockingTask::new(self, tx); // Run the blocking task in the current span. let curr_span = Span::current(); diff --git a/crates/starknet_integration_tests/Cargo.toml b/crates/starknet_integration_tests/Cargo.toml index 95a07bf215a..ffbb1f5e38b 100644 --- a/crates/starknet_integration_tests/Cargo.toml +++ b/crates/starknet_integration_tests/Cargo.toml @@ -18,6 +18,7 @@ indexmap.workspace = true infra_utils.workspace = true mempool_test_utils.workspace = true papyrus_common.workspace = true +papyrus_config.workspace = true papyrus_consensus.workspace = true papyrus_execution.workspace = true papyrus_network = { workspace = true, features = ["testing"] } diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index de792df7336..24caabd9b23 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -3,7 +3,8 @@ use std::io::Write; use std::net::SocketAddr; use std::path::PathBuf; -use serde_json::{json, Value}; +use papyrus_config::dumping::{combine_config_map_and_pointers, SerializeConfig}; +use serde_json::{json, Map, Value}; use starknet_sequencer_infra::component_definitions::{ LocalServerConfig, RemoteClientConfig, @@ -16,7 +17,11 @@ use starknet_sequencer_node::config::component_execution_config::{ ReactiveComponentExecutionConfig, ReactiveComponentExecutionMode, }; -use starknet_sequencer_node::config::node_config::SequencerNodeConfig; +use starknet_sequencer_node::config::node_config::{ + SequencerNodeConfig, + CONFIG_NON_POINTERS_WHITELIST, + CONFIG_POINTERS, +}; use starknet_sequencer_node::config::test_utils::RequiredParams; use tracing::info; // TODO(Tsabary): Move here all config-related functions from "integration_test_utils.rs". @@ -55,20 +60,29 @@ pub(crate) fn dump_config_file_changes( ) -> PathBuf { // Dump config changes file for the sequencer node. // TODO(Tsabary): auto dump the entirety of RequiredParams fields. - let json_data = config_fields_to_json!( + let required_params_json = config_fields_to_json!( required_params.chain_id, required_params.eth_fee_token_address, required_params.strk_fee_token_address, required_params.validator_id, - config.rpc_state_reader_config.url, - config.batcher_config.storage.db_config.path_prefix, - config.http_server_config.ip, - config.http_server_config.port, - config.consensus_manager_config.consensus_config.start_height, - config.state_sync_config.storage_config.db_config.path_prefix, - config.state_sync_config.network_config.tcp_port, ); - let node_config_path = dump_json_data(json_data, NODE_CONFIG_CHANGES_FILE_PATH, dir); + + // Create the entire mapping of the config and the pointers, without the required params. + let config_as_map = combine_config_map_and_pointers( + config.dump(), + &CONFIG_POINTERS, + &CONFIG_NON_POINTERS_WHITELIST, + ) + .unwrap(); + + // Extract only the required fields from the config map. + let mut preset = config_to_preset(&config_as_map, "value"); + + // Add the required params to the preset. + add_required_params_to_preset(&mut preset, &required_params_json); + + // Dump the preset to a file, return its path. + let node_config_path = dump_json_data(preset, NODE_CONFIG_CHANGES_FILE_PATH, dir); assert!(node_config_path.exists(), "File does not exist: {:?}", node_config_path); node_config_path @@ -157,3 +171,36 @@ pub async fn get_remote_flow_test_config() -> Vec { get_non_http_component_config(gateway_socket).await, ] } + +fn config_to_preset(config_map: &Value, inner_key: &str) -> Value { + // Ensure the config_map is a JSON object + if let Value::Object(map) = config_map { + let mut result = Map::new(); + + for (key, value) in map { + if let Value::Object(inner_map) = value { + // Extract the value for the specified inner_key + if let Some(inner_value) = inner_map.get(inner_key) { + // Add it to the result map + result.insert(key.clone(), inner_value.clone()); + } + } + } + + // Return the transformed result as a JSON object + Value::Object(result) + } else { + // If the input is not an object, return an empty object + Value::Object(Map::new()) + } +} + +fn add_required_params_to_preset(preset: &mut Value, required_params: &Value) { + if let (Value::Object(preset_map), Value::Object(required_params_map)) = + (preset, required_params) + { + for (key, value) in required_params_map { + preset_map.insert(key.clone(), value.clone()); + } + } +} diff --git a/crates/starknet_integration_tests/src/end_to_end_integration.rs b/crates/starknet_integration_tests/src/end_to_end_integration.rs index d44238fa26e..38ce2485ace 100644 --- a/crates/starknet_integration_tests/src/end_to_end_integration.rs +++ b/crates/starknet_integration_tests/src/end_to_end_integration.rs @@ -1,4 +1,5 @@ use infra_utils::run_until::run_until; +use infra_utils::tracing::{CustomLogger, TraceLevel}; use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator}; use papyrus_execution::execution_utils::get_nonce_at; use papyrus_storage::state::StateStorageReader; @@ -8,6 +9,7 @@ use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::state::StateNumber; use starknet_sequencer_node::test_utils::node_runner::{get_node_executable_path, spawn_run_node}; use starknet_types_core::felt::Felt; +use tokio::join; use tracing::info; use crate::integration_test_setup::IntegrationTestSetup; @@ -43,7 +45,12 @@ async fn await_block( let condition = |&latest_block_number: &BlockNumber| latest_block_number >= target_block_number; let get_latest_block_number_closure = || async move { get_latest_block_number(storage_reader) }; - run_until(interval, max_attempts, get_latest_block_number_closure, condition, None) + let logger = CustomLogger::new( + TraceLevel::Info, + Some("Waiting for storage to include block".to_string()), + ); + + run_until(interval, max_attempts, get_latest_block_number_closure, condition, Some(logger)) .await .ok_or(()) } @@ -58,20 +65,22 @@ pub async fn end_to_end_integration(mut tx_generator: MultiAccountTransactionGen // Creating the storage for the test. let integration_test_setup = IntegrationTestSetup::new_from_tx_generator(&tx_generator).await; - info!("Running sequencer node."); - let node_run_handle = spawn_run_node(integration_test_setup.node_config_path).await; + let node_0_run_handle = + spawn_run_node(integration_test_setup.sequencer_0.node_config_path.clone()); + let node_1_run_handle = + spawn_run_node(integration_test_setup.sequencer_1.node_config_path.clone()); - // Wait for the node to start. - integration_test_setup - .is_alive_test_client - .await_alive(5000, 50) - .await - .expect("Node should be alive."); + info!("Running sequencers."); + let (node_0_run_task, node_1_run_task) = join!(node_0_run_handle, node_1_run_handle); + + // Wait for the nodes to start. + integration_test_setup.await_alive(5000, 50).await; info!("Running integration test simulator."); - let send_rpc_tx_fn = - &mut |rpc_tx| integration_test_setup.add_tx_http_client.assert_add_tx_success(rpc_tx); + let send_rpc_tx_fn = &mut |rpc_tx| { + integration_test_setup.sequencer_0.add_tx_http_client.assert_add_tx_success(rpc_tx) + }; const ACCOUNT_ID_0: AccountId = 0; let n_txs = 50; @@ -83,19 +92,26 @@ pub async fn end_to_end_integration(mut tx_generator: MultiAccountTransactionGen info!("Awaiting until {EXPECTED_BLOCK_NUMBER} blocks have been created."); let (batcher_storage_reader, _) = - papyrus_storage::open_storage(integration_test_setup.batcher_storage_config) + papyrus_storage::open_storage(integration_test_setup.sequencer_0.batcher_storage_config) .expect("Failed to open batcher's storage"); - await_block(5000, EXPECTED_BLOCK_NUMBER, 15, &batcher_storage_reader) + await_block(5000, EXPECTED_BLOCK_NUMBER, 30, &batcher_storage_reader) .await .expect("Block number should have been reached."); - info!("Shutting the node down."); - node_run_handle.abort(); - let res = node_run_handle.await; + info!("Shutting node 0 down."); + node_0_run_task.abort(); + let res = node_0_run_task.await; + assert!( + res.expect_err("Node 0 should have been stopped.").is_cancelled(), + "Node 0 should have been stopped." + ); + info!("Shutting node 1 down."); + node_1_run_task.abort(); + let res = node_1_run_task.await; assert!( - res.expect_err("Node should have been stopped.").is_cancelled(), - "Node should have been stopped." + res.expect_err("Node 1 should have been stopped.").is_cancelled(), + "Node 1 should have been stopped." ); info!("Verifying tx sender account nonce."); diff --git a/crates/starknet_integration_tests/src/flow_test_setup.rs b/crates/starknet_integration_tests/src/flow_test_setup.rs index b60e067d82a..b3fc4c0d477 100644 --- a/crates/starknet_integration_tests/src/flow_test_setup.rs +++ b/crates/starknet_integration_tests/src/flow_test_setup.rs @@ -33,8 +33,8 @@ const SEQUENCER_1: usize = 1; const SEQUENCER_INDICES: [usize; 2] = [SEQUENCER_0, SEQUENCER_1]; pub struct FlowTestSetup { - pub sequencer_0: SequencerSetup, - pub sequencer_1: SequencerSetup, + pub sequencer_0: FlowSequencerSetup, + pub sequencer_1: FlowSequencerSetup, // Channels for consensus proposals, used for asserting the right transactions are proposed. pub consensus_proposals_channels: BroadcastTopicChannels>, @@ -57,7 +57,7 @@ impl FlowTestSetup { 2] = mempool_p2p_configs.try_into().unwrap(); // Create nodes one after the other in order to make sure the ports are not overlapping. - let sequencer_0 = SequencerSetup::new( + let sequencer_0 = FlowSequencerSetup::new( accounts.clone(), SEQUENCER_0, chain_info.clone(), @@ -65,7 +65,8 @@ impl FlowTestSetup { sequencer_0_mempool_p2p_config, ) .await; - let sequencer_1 = SequencerSetup::new( + + let sequencer_1 = FlowSequencerSetup::new( accounts, SEQUENCER_1, chain_info, @@ -82,7 +83,7 @@ impl FlowTestSetup { } } -pub struct SequencerSetup { +pub struct FlowSequencerSetup { /// Used to differentiate between different sequencer nodes. pub sequencer_index: usize, @@ -103,7 +104,7 @@ pub struct SequencerSetup { pub is_alive_test_client: IsAliveClient, } -impl SequencerSetup { +impl FlowSequencerSetup { #[instrument(skip(accounts, chain_info, consensus_manager_config), level = "debug")] pub async fn new( accounts: Vec, diff --git a/crates/starknet_integration_tests/src/integration_test_setup.rs b/crates/starknet_integration_tests/src/integration_test_setup.rs index 8ea1f40e673..d54e62bcd1c 100644 --- a/crates/starknet_integration_tests/src/integration_test_setup.rs +++ b/crates/starknet_integration_tests/src/integration_test_setup.rs @@ -1,13 +1,21 @@ use std::net::SocketAddr; use std::path::PathBuf; -use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator; +use blockifier::context::ChainInfo; +use mempool_test_utils::starknet_api_test_utils::{Contract, MultiAccountTransactionGenerator}; +use papyrus_network::network_manager::BroadcastTopicChannels; +use papyrus_protobuf::consensus::{ProposalPart, StreamMessage}; use papyrus_storage::StorageConfig; +use starknet_api::rpc_transaction::RpcTransaction; +use starknet_api::transaction::TransactionHash; +use starknet_consensus_manager::config::ConsensusManagerConfig; use starknet_http_server::config::HttpServerConfig; use starknet_http_server::test_utils::HttpTestClient; +use starknet_mempool_p2p::config::MempoolP2pConfig; use starknet_monitoring_endpoint::config::MonitoringEndpointConfig; use starknet_monitoring_endpoint::test_utils::IsAliveClient; use tempfile::{tempdir, TempDir}; +use tracing::instrument; use crate::config_utils::dump_config_file_changes; use crate::state_reader::{spawn_test_rpc_state_reader, StorageTestSetup}; @@ -18,12 +26,75 @@ use crate::utils::{ create_mempool_p2p_configs, }; -const SEQUENCER_INDEX: usize = 0; -const SEQUENCER_INDICES: [usize; 1] = [SEQUENCER_INDEX]; +const SEQUENCER_0: usize = 0; +const SEQUENCER_1: usize = 1; +const SEQUENCER_INDICES: [usize; 2] = [SEQUENCER_0, SEQUENCER_1]; pub struct IntegrationTestSetup { + pub sequencer_0: IntegrationSequencerSetup, + pub sequencer_1: IntegrationSequencerSetup, + + // Channels for consensus proposals, used for asserting the right transactions are proposed. + pub consensus_proposals_channels: BroadcastTopicChannels>, +} + +impl IntegrationTestSetup { + pub async fn new_from_tx_generator(tx_generator: &MultiAccountTransactionGenerator) -> Self { + let chain_info = create_chain_info(); + let accounts = tx_generator.accounts(); + + let (mut consensus_manager_configs, consensus_proposals_channels) = + create_consensus_manager_configs_and_channels(SEQUENCER_INDICES.len()); + let mut mempool_p2p_configs = + create_mempool_p2p_configs(SEQUENCER_INDICES.len(), chain_info.chain_id.clone()); + + let sequencer_0_consensus_manager_config = consensus_manager_configs.remove(0); + let sequencer_0_mempool_p2p_config = mempool_p2p_configs.remove(0); + let sequencer_0 = IntegrationSequencerSetup::new( + accounts.clone(), + SEQUENCER_0, + chain_info.clone(), + sequencer_0_consensus_manager_config, + sequencer_0_mempool_p2p_config, + ) + .await; + + let sequencer_1_consensus_manager_config = consensus_manager_configs.remove(0); + let sequencer_1_mempool_p2p_config = mempool_p2p_configs.remove(0); + let sequencer_1 = IntegrationSequencerSetup::new( + accounts.clone(), + SEQUENCER_1, + chain_info.clone(), + sequencer_1_consensus_manager_config, + sequencer_1_mempool_p2p_config, + ) + .await; + + Self { sequencer_0, sequencer_1, consensus_proposals_channels } + } + + pub async fn await_alive(&self, interval: u64, max_attempts: usize) { + self.sequencer_0 + .is_alive_test_client + .await_alive(0, interval, max_attempts) + .await + .expect("Node 0 should be alive."); + + self.sequencer_1 + .is_alive_test_client + .await_alive(1, interval, max_attempts) + .await + .expect("Node 1 should be alive."); + } +} + +pub struct IntegrationSequencerSetup { + /// Used to differentiate between different sequencer nodes. + pub sequencer_index: usize, + // Client for adding transactions to the sequencer node. pub add_tx_http_client: HttpTestClient, + // Client for checking liveness of the sequencer node. pub is_alive_test_client: IsAliveClient, // Path to the node configuration file. @@ -45,11 +116,17 @@ pub struct IntegrationTestSetup { state_sync_storage_handle: TempDir, } -impl IntegrationTestSetup { - pub async fn new_from_tx_generator(tx_generator: &MultiAccountTransactionGenerator) -> Self { - let chain_info = create_chain_info(); +impl IntegrationSequencerSetup { + #[instrument(skip(accounts, chain_info, consensus_manager_config), level = "debug")] + pub async fn new( + accounts: Vec, + sequencer_index: usize, + chain_info: ChainInfo, + consensus_manager_config: ConsensusManagerConfig, + mempool_p2p_config: MempoolP2pConfig, + ) -> Self { // Creating the storage for the test. - let storage_for_test = StorageTestSetup::new(tx_generator.accounts(), &chain_info); + let storage_for_test = StorageTestSetup::new(accounts, &chain_info); // Spawn a papyrus rpc server for a papyrus storage reader. let rpc_server_addr = spawn_test_rpc_state_reader( @@ -58,20 +135,15 @@ impl IntegrationTestSetup { ) .await; - let (mut consensus_manager_configs, _consensus_proposals_channels) = - create_consensus_manager_configs_and_channels(SEQUENCER_INDICES.len()); - let mut mempool_p2p_configs = - create_mempool_p2p_configs(SEQUENCER_INDICES.len(), chain_info.chain_id.clone()); - // Derive the configuration for the sequencer node. let (config, required_params) = create_config( - SEQUENCER_INDEX, + sequencer_index, chain_info, rpc_server_addr, storage_for_test.batcher_storage_config, storage_for_test.state_sync_storage_config, - consensus_manager_configs.pop().unwrap(), - mempool_p2p_configs.pop().unwrap(), + consensus_manager_config, + mempool_p2p_config, ) .await; @@ -89,7 +161,8 @@ impl IntegrationTestSetup { let HttpServerConfig { ip, port } = config.http_server_config; let add_tx_http_client = HttpTestClient::new(SocketAddr::from((ip, port))); - IntegrationTestSetup { + Self { + sequencer_index, add_tx_http_client, is_alive_test_client, batcher_storage_handle: storage_for_test.batcher_storage_handle, @@ -101,4 +174,8 @@ impl IntegrationTestSetup { state_sync_storage_config: config.state_sync_config.storage_config, } } + + pub async fn assert_add_tx_success(&self, tx: RpcTransaction) -> TransactionHash { + self.add_tx_http_client.assert_add_tx_success(tx).await + } } diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index 56680b65a3c..0df52f8e922 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -7,7 +7,7 @@ use blockifier::test_utils::contracts::FeatureContract; use blockifier::test_utils::{CairoVersion, RunnableCairo1}; use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator}; use papyrus_consensus::config::ConsensusConfig; -use papyrus_consensus::types::{ValidatorId, DEFAULT_VALIDATOR_ID}; +use papyrus_consensus::types::ValidatorId; use papyrus_network::network_manager::test_utils::{ create_connected_network_configs, create_network_configs_connected_to_broadcast_channels, @@ -17,7 +17,7 @@ use papyrus_network::NetworkConfig; use papyrus_protobuf::consensus::{ProposalPart, StreamMessage}; use papyrus_storage::StorageConfig; use starknet_api::block::BlockNumber; -use starknet_api::core::{ChainId, ContractAddress}; +use starknet_api::core::ChainId; use starknet_api::rpc_transaction::RpcTransaction; use starknet_api::transaction::TransactionHash; use starknet_batcher::block_builder::BlockBuilderConfig; @@ -60,7 +60,7 @@ pub async fn create_config( mut consensus_manager_config: ConsensusManagerConfig, mempool_p2p_config: MempoolP2pConfig, ) -> (SequencerNodeConfig, RequiredParams) { - set_validator_id(&mut consensus_manager_config, sequencer_index); + let validator_id = set_validator_id(&mut consensus_manager_config, sequencer_index); let fee_token_addresses = chain_info.fee_token_addresses.clone(); let batcher_config = create_batcher_config(batcher_storage_config, chain_info.clone()); let gateway_config = create_gateway_config(chain_info.clone()).await; @@ -85,7 +85,7 @@ pub async fn create_config( chain_id: chain_info.chain_id, eth_fee_token_address: fee_token_addresses.eth_fee_token_address, strk_fee_token_address: fee_token_addresses.strk_fee_token_address, - validator_id: ContractAddress::from(DEFAULT_VALIDATOR_ID), + validator_id, }, ) } @@ -115,7 +115,7 @@ pub fn create_consensus_manager_configs_and_channels( consensus_config: ConsensusConfig { start_height: BlockNumber(1), // TODO(Matan, Dan): Set the right amount - consensus_delay: Duration::from_secs(5), + consensus_delay: Duration::from_secs(15), network_config, num_validators: u64::try_from(n_managers).unwrap(), timeouts: timeouts.clone(), @@ -266,12 +266,17 @@ pub fn create_batcher_config( } } -fn set_validator_id(consensus_manager_config: &mut ConsensusManagerConfig, sequencer_index: usize) { - consensus_manager_config.consensus_config.validator_id = ValidatorId::try_from( +fn set_validator_id( + consensus_manager_config: &mut ConsensusManagerConfig, + sequencer_index: usize, +) -> ValidatorId { + let validator_id = ValidatorId::try_from( Felt::from(consensus_manager_config.consensus_config.validator_id) + Felt::from(sequencer_index), ) .unwrap(); + consensus_manager_config.consensus_config.validator_id = validator_id; + validator_id } fn create_monitoring_endpoint_config(sequencer_index: usize) -> MonitoringEndpointConfig { diff --git a/crates/starknet_mempool/src/mempool.rs b/crates/starknet_mempool/src/mempool.rs index 2962e47ba91..b6b60c21a34 100644 --- a/crates/starknet_mempool/src/mempool.rs +++ b/crates/starknet_mempool/src/mempool.rs @@ -171,7 +171,7 @@ impl Mempool { self.state.stage(tx_reference)?; } - tracing::debug!( + tracing::info!( "Returned {} out of {n_txs} transactions, ready for sequencing.", eligible_tx_references.len() ); @@ -201,6 +201,7 @@ impl Mempool { )] pub fn add_tx(&mut self, args: AddTransactionArgs) -> MempoolResult<()> { let AddTransactionArgs { tx, account_state } = args; + tracing::debug!("Adding transaction to mempool: {tx:?}."); let tx_reference = TransactionReference::new(&tx); self.validate_incoming_tx(tx_reference)?; diff --git a/crates/starknet_monitoring_endpoint/src/test_utils.rs b/crates/starknet_monitoring_endpoint/src/test_utils.rs index 8d284fc5aab..f30668b3e01 100644 --- a/crates/starknet_monitoring_endpoint/src/test_utils.rs +++ b/crates/starknet_monitoring_endpoint/src/test_utils.rs @@ -34,12 +34,19 @@ impl IsAliveClient { /// Blocks until 'alive', up to a maximum number of query attempts. Returns 'Ok(())' if the /// target is alive, otherwise 'Err(())'. - pub async fn await_alive(&self, interval: u64, max_attempts: usize) -> Result<(), ()> { + pub async fn await_alive( + &self, + node_index: u64, + interval: u64, + max_attempts: usize, + ) -> Result<(), ()> { let condition = |node_is_alive: &bool| *node_is_alive; let query_alive_closure = || async move { self.query_alive().await }; - let logger = - CustomLogger::new(TraceLevel::Info, Some("Waiting for node to be alive".to_string())); + let logger = CustomLogger::new( + TraceLevel::Info, + Some(format!("Waiting for node {node_index} to be alive")), + ); run_until(interval, max_attempts, query_alive_closure, condition, Some(logger)) .await diff --git a/crates/starknet_sequencer_node/src/test_utils/node_runner.rs b/crates/starknet_sequencer_node/src/test_utils/node_runner.rs index e929f158723..5e4036f23ba 100644 --- a/crates/starknet_sequencer_node/src/test_utils/node_runner.rs +++ b/crates/starknet_sequencer_node/src/test_utils/node_runner.rs @@ -12,7 +12,7 @@ pub const NODE_EXECUTABLE_PATH: &str = "target/debug/starknet_sequencer_node"; pub async fn spawn_run_node(node_config_path: PathBuf) -> JoinHandle<()> { task::spawn(async move { info!("Running the node from its spawned task."); - let _node_run_result = spawn_node_child_task(node_config_path). + let _node_run_result = spawn_node_child_process(node_config_path). await. // awaits the completion of spawn_node_child_task. wait(). // runs the node until completion -- should be running indefinitely. await; // awaits the completion of the node. @@ -20,7 +20,7 @@ pub async fn spawn_run_node(node_config_path: PathBuf) -> JoinHandle<()> { }) } -async fn spawn_node_child_task(node_config_path: PathBuf) -> Child { +async fn spawn_node_child_process(node_config_path: PathBuf) -> Child { // TODO(Tsabary): Capture output to a log file, and present it in case of a failure. info!("Getting the node executable."); let node_executable = get_node_executable_path();