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

fix(starknet_integration_tests): fix config when creating multiple nodes #2426

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
7 changes: 4 additions & 3 deletions crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl FlowTestSetup {

pub struct SequencerSetup {
/// Used to differentiate between different sequencer nodes.
pub sequencer_id: usize,
pub sequencer_index: usize,

// Client for adding transactions to the sequencer node.
pub add_tx_http_client: HttpTestClient,
Expand All @@ -93,7 +93,7 @@ impl SequencerSetup {
)]
pub async fn new(
accounts: Vec<Contract>,
sequencer_id: usize,
sequencer_index: usize,
chain_info: ChainInfo,
task_executor: &TokioExecutor,
consensus_manager_config: ConsensusManagerConfig,
Expand All @@ -109,6 +109,7 @@ impl SequencerSetup {

// Derive the configuration for the sequencer node.
let (config, _required_params) = create_config(
sequencer_index,
chain_info,
rpc_server_addr,
storage_for_test.batcher_storage_config,
Expand All @@ -133,7 +134,7 @@ impl SequencerSetup {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

Self {
sequencer_id,
sequencer_index,
add_tx_http_client,
batcher_storage_file_handle: storage_for_test.batcher_storage_handle,
rpc_storage_file_handle: storage_for_test.rpc_storage_handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::utils::{
create_consensus_manager_configs_and_channels,
};

const SEQUENCER_ID: usize = 0;
const SEQUENCER_IDS: [usize; 1] = [SEQUENCER_ID];
const SEQUENCER_INDEX: usize = 0;
const SEQUENCER_INDICES: [usize; 1] = [SEQUENCER_INDEX];

pub struct IntegrationTestSetup {
// Client for adding transactions to the sequencer node.
Expand Down Expand Up @@ -54,10 +54,11 @@ impl IntegrationTestSetup {
.await;

let (mut consensus_manager_configs, _consensus_proposals_channels) =
create_consensus_manager_configs_and_channels(SEQUENCER_IDS.len());
create_consensus_manager_configs_and_channels(SEQUENCER_INDICES.len());

// Derive the configuration for the sequencer node.
let (config, required_params) = create_config(
SEQUENCER_INDEX,
chain_info,
rpc_server_addr,
storage_for_test.batcher_storage_config,
Expand Down
41 changes: 39 additions & 2 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ 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;
use papyrus_network::network_manager::test_utils::create_network_configs_connected_to_broadcast_channels;
use papyrus_network::network_manager::BroadcastTopicChannels;
use papyrus_protobuf::consensus::{ProposalPart, StreamMessage};
use papyrus_storage::StorageConfig;
use starknet_api::block::BlockNumber;
use starknet_api::core::ChainId;
use starknet_api::rpc_transaction::RpcTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_batcher::block_builder::BlockBuilderConfig;
Expand All @@ -24,9 +26,12 @@ use starknet_gateway::config::{
StatelessTransactionValidatorConfig,
};
use starknet_http_server::config::HttpServerConfig;
use starknet_mempool_p2p::config::MempoolP2pConfig;
use starknet_monitoring_endpoint::config::MonitoringEndpointConfig;
use starknet_sequencer_infra::test_utils::get_available_socket;
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
use starknet_sequencer_node::config::test_utils::RequiredParams;
use starknet_types_core::felt::Felt;

pub fn create_chain_info() -> ChainInfo {
let mut chain_info = ChainInfo::create_for_testing();
Expand All @@ -39,16 +44,21 @@ pub fn create_chain_info() -> ChainInfo {
// TODO(yair, Tsabary): Create config presets for tests, then remove all the functions that modify
// the config.
pub async fn create_config(
sequencer_index: usize,
chain_info: ChainInfo,
rpc_server_addr: SocketAddr,
batcher_storage_config: StorageConfig,
consensus_manager_config: ConsensusManagerConfig,
mut consensus_manager_config: ConsensusManagerConfig,
) -> (SequencerNodeConfig, RequiredParams) {
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;
let http_server_config = create_http_server_config().await;
let rpc_state_reader_config = test_rpc_state_reader_config(rpc_server_addr);
let mempool_p2p_config =
create_mempool_p2p_config(sequencer_index, chain_info.chain_id.clone());
let monitoring_endpoint_config = create_monitoring_endpoint_config(sequencer_index);

(
SequencerNodeConfig {
Expand All @@ -57,7 +67,9 @@ pub async fn create_config(
gateway_config,
http_server_config,
rpc_state_reader_config,
..SequencerNodeConfig::default()
mempool_p2p_config,
monitoring_endpoint_config,
..Default::default()
},
RequiredParams {
chain_id: chain_info.chain_id,
Expand Down Expand Up @@ -87,6 +99,7 @@ pub fn create_consensus_manager_configs_and_channels(
start_height: BlockNumber(1),
consensus_delay: Duration::from_secs(1),
network_config,
num_validators: u64::try_from(n_managers).unwrap(),
..Default::default()
},
})
Expand Down Expand Up @@ -231,3 +244,27 @@ pub fn create_batcher_config(
pub fn run_integration_test() -> bool {
std::env::var("SEQUENCER_INTEGRATION_TESTS").is_ok()
}

fn set_validator_id(consensus_manager_config: &mut ConsensusManagerConfig, sequencer_index: usize) {
consensus_manager_config.consensus_config.validator_id = ValidatorId::try_from(
Felt::from(consensus_manager_config.consensus_config.validator_id)
+ Felt::from(sequencer_index),
)
.unwrap();
}

fn create_mempool_p2p_config(sequencer_index: usize, chain_id: ChainId) -> MempoolP2pConfig {
let mut config = MempoolP2pConfig::default();
// When running multiple sequencers on the same machine, we need to make sure their ports are
// different. Use the sequencer_index to differentiate between them.
config.network_config.tcp_port += u16::try_from(sequencer_index).unwrap();
config.network_config.quic_port += u16::try_from(sequencer_index).unwrap();
config.network_config.chain_id = chain_id;
config
}

fn create_monitoring_endpoint_config(sequencer_index: usize) -> MonitoringEndpointConfig {
let mut config = MonitoringEndpointConfig::default();
config.port += u16::try_from(sequencer_index).unwrap();
config
}
Loading