From 8396a22432deccedaf4fec2cfef8414e6e923ab9 Mon Sep 17 00:00:00 2001 From: Haiyue Chen Date: Fri, 10 Jul 2026 17:29:18 +0200 Subject: [PATCH] chore: remove orphaned pytest config-generation code The generate-test-configs subcommand and its scaffolding were only ever invoked by the removed pytest suite (#3076). Removes the CLI command and its testing module, the CLI_FOR_PYTEST port seed, the now-dead TOTAL_DEFINED_PORTS constant, and the unused p2p_keypairs parameter of generate_test_p2p_configs. --- crates/node/src/cli.rs | 193 --------------------------------------- crates/node/src/p2p.rs | 21 +---- crates/node/src/tests.rs | 2 +- 3 files changed, 5 insertions(+), 211 deletions(-) diff --git a/crates/node/src/cli.rs b/crates/node/src/cli.rs index e5766c0cd7..0f04b0d1e6 100644 --- a/crates/node/src/cli.rs +++ b/crates/node/src/cli.rs @@ -46,30 +46,6 @@ pub enum CliCommand { ImportKeyshare(ImportKeyshareCmd), /// Exports a keyshare from local encrypted storage and prints it to the console ExportKeyshare(ExportKeyshareCmd), - /// Generates a set of test configurations suitable for running MPC in - /// an integration test. - #[cfg(feature = "test-utils")] - GenerateTestConfigs { - #[arg(long)] - output_dir: String, - #[arg(long, value_delimiter = ',', required = true)] - /// Near signer account for each participant - participants: Vec, - /// Near responder account for each participant. Refer to `indexer/real.rs` for more details. - #[arg(long, value_delimiter = ',')] - responders: Vec, - #[arg(long)] - threshold: usize, - #[arg(long, default_value = "65536")] - desired_triples_to_buffer: usize, - #[arg(long, default_value = "8192")] - desired_presignatures_to_buffer: usize, - #[arg(long, default_value = "1")] - desired_responder_keys_per_participant: usize, - /// optional argument. If set, generates additional config for participants\[id\] for each id in migrating_nodes. - #[arg(long, value_delimiter = ',')] - migrating_nodes: Vec, - }, } #[derive(Args, Debug)] pub struct StartCmd { @@ -256,32 +232,6 @@ impl Cli { } CliCommand::ImportKeyshare(cmd) => cmd.run().await, CliCommand::ExportKeyshare(cmd) => cmd.run().await, - #[cfg(feature = "test-utils")] - CliCommand::GenerateTestConfigs { - ref output_dir, - ref participants, - ref responders, - threshold, - desired_triples_to_buffer, - desired_presignatures_to_buffer, - desired_responder_keys_per_participant, - ref migrating_nodes, - } => { - anyhow::ensure!( - participants.len() == responders.len(), - "Number of participants must match number of responders" - ); - testing::run_generate_test_configs( - output_dir, - participants.clone(), - responders.clone(), - threshold, - desired_triples_to_buffer, - desired_presignatures_to_buffer, - desired_responder_keys_per_participant, - migrating_nodes, - ) - } } } } @@ -382,149 +332,6 @@ impl ExportKeyshareCmd { } } -#[cfg(feature = "test-utils")] -mod testing { - use std::{ - net::{Ipv4Addr, SocketAddr}, - path::PathBuf, - }; - - use crate::{ - config::PersistentSecrets, - p2p::testing::{PortSeed, generate_test_p2p_configs}, - }; - use mpc_node_config::{ - BlockArgs, CKDConfig, ConfigFile, ForeignChainsConfig, IndexerConfig, KeygenConfig, - PresignatureConfig, SignatureConfig, SyncMode, TripleConfig, - }; - use near_indexer_primitives::types::Finality; - use near_sdk::AccountId; - - #[expect(clippy::too_many_arguments)] - pub(crate) fn run_generate_test_configs( - output_dir: &str, - participants: Vec, - responders: Vec, - threshold: usize, - desired_triples_to_buffer: usize, - desired_presignatures_to_buffer: usize, - desired_responder_keys_per_participant: usize, - migrating_nodes: &[usize], - ) -> anyhow::Result<()> { - let participants = duplicate_migrating_accounts(participants, migrating_nodes)?; - let responders = duplicate_migrating_accounts(responders, migrating_nodes)?; - - let p2p_key_pairs = participants - .iter() - .enumerate() - .map(|(idx, _account_id)| { - let subdir = PathBuf::from(output_dir).join(idx.to_string()); - PersistentSecrets::generate_or_get_existing( - &subdir, - desired_responder_keys_per_participant, - ) - .map(|secret| secret.p2p_private_key) - }) - .collect::, _>>()?; - let configs = generate_test_p2p_configs( - &participants, - threshold, - PortSeed::CLI_FOR_PYTEST, - Some(p2p_key_pairs), - )?; - let participants_config = configs[0].0.participants.clone(); - for (i, (_config, _p2p_private_key)) in configs.into_iter().enumerate() { - let subdir = format!("{}/{}", output_dir, i); - std::fs::create_dir_all(&subdir)?; - let file_config = create_file_config( - &participants[i], - &responders[i], - i, - desired_triples_to_buffer, - desired_presignatures_to_buffer, - ); - std::fs::write( - format!("{}/mpc_node_config.json", subdir), - serde_json::to_string_pretty(&file_config)?, - )?; - } - std::fs::write( - format!("{}/participants.json", output_dir), - serde_json::to_string(&participants_config)?, - )?; - Ok(()) - } - - fn duplicate_migrating_accounts( - mut accounts: Vec, - migrating_nodes: &[usize], - ) -> anyhow::Result> { - for migrating_node_idx in migrating_nodes { - let migrating_node_account: AccountId = accounts - .get(*migrating_node_idx) - .ok_or_else(|| { - anyhow::anyhow!("index {} out of bounds for accounts", migrating_node_idx) - })? - .clone(); - - accounts.push(migrating_node_account); - } - Ok(accounts) - } - - fn create_file_config( - participant: &AccountId, - responder: &AccountId, - index: usize, - desired_triples_to_buffer: usize, - desired_presignatures_to_buffer: usize, - ) -> ConfigFile { - ConfigFile { - my_near_account_id: participant.clone(), - near_responder_account_id: responder.clone(), - number_of_responder_keys: 1, - web_ui: SocketAddr::new( - Ipv4Addr::LOCALHOST.into(), - PortSeed::CLI_FOR_PYTEST.web_port(index), - ), - migration_web_ui: SocketAddr::new( - Ipv4Addr::LOCALHOST.into(), - PortSeed::CLI_FOR_PYTEST.migration_web_port(index), - ), - pprof_bind_address: SocketAddr::new( - Ipv4Addr::LOCALHOST.into(), - PortSeed::CLI_FOR_PYTEST.pprof_web_port(index), - ), - indexer: IndexerConfig { - validate_genesis: true, - sync_mode: SyncMode::Block(BlockArgs { height: 0 }), - concurrency: 1.try_into().unwrap(), - mpc_contract_id: "test0".parse().unwrap(), - finality: Finality::None, - port_override: None, - wipe_near_data_token: 0, - }, - triple: TripleConfig { - concurrency: 2, - desired_triples_to_buffer, - timeout_sec: 60, - parallel_triple_generation_stagger_time_sec: 1, - }, - presignature: PresignatureConfig { - concurrency: 2, - desired_presignatures_to_buffer, - timeout_sec: 60, - }, - signature: SignatureConfig { timeout_sec: 60 }, - ckd: CKDConfig { timeout_sec: 60 }, - keygen: KeygenConfig { timeout_sec: 60 }, - foreign_chains: ForeignChainsConfig::default(), - cores: Some(4), - separate_asset_generation_runtime: true, - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/node/src/p2p.rs b/crates/node/src/p2p.rs index f0f9f85df6..d9cb6a22d8 100644 --- a/crates/node/src/p2p.rs +++ b/crates/node/src/p2p.rs @@ -942,8 +942,6 @@ pub mod testing { impl PortSeed { // The base port number used, hoping the OS is not using ports in this range pub const BASE_PORT: u16 = 10000; - // This constant must be equal to the total number of ports defined below - pub const TOTAL_DEFINED_PORTS: u16 = 23; // Maximum number of nodes that can be handled without port collisions pub const MAX_NODES: u16 = 10; // Maximum number of cases that can be handled without port collisions @@ -989,8 +987,6 @@ pub mod testing { pub fn pprof_web_port(&self, node_index: usize) -> u16 { self.compute_port(node_index as u16, 3) } - - pub const CLI_FOR_PYTEST: Self = Self::new(0); } impl PortSeed { @@ -1025,17 +1021,11 @@ pub mod testing { // this is a hack to make sure that when tests run in parallel, they don't // collide on the same port. port_seed: PortSeed, - // Supply `Some` value here if you want to use pre-existing p2p key pairs - p2p_keypairs: Option>, ) -> anyhow::Result> { - let p2p_keypairs = if let Some(p2p_keypairs) = p2p_keypairs { - p2p_keypairs - } else { - participant_accounts - .iter() - .map(|_account_id| SigningKey::generate(&mut OsRng)) - .collect::>() - }; + let p2p_keypairs = participant_accounts + .iter() + .map(|_account_id| SigningKey::generate(&mut OsRng)) + .collect::>(); let mut participants = Vec::new(); for (i, (participant_account, p2p_signing_key)) in participant_accounts .iter() @@ -1097,7 +1087,6 @@ mod tests { &["test0".parse().unwrap(), "test1".parse().unwrap()], 2, PortSeed::P2P_BASIC_TEST, - None, ) .unwrap(); let participant0 = configs[0].0.my_participant_id; @@ -1204,7 +1193,6 @@ mod tests { ], 4, PortSeed::P2P_WAIT_FOR_READY_TEST, - None, ) .unwrap(); @@ -1329,7 +1317,6 @@ mod tests { &["test0".parse().unwrap(), "test1".parse().unwrap()], 2, PortSeed::RECONNECTION_TEST, - None, ) .unwrap(); diff --git a/crates/node/src/tests.rs b/crates/node/src/tests.rs index b081fb4532..6e48646d60 100644 --- a/crates/node/src/tests.rs +++ b/crates/node/src/tests.rs @@ -194,7 +194,7 @@ impl IntegrationTestSetup { block_time: std::time::Duration, ) -> IntegrationTestSetup { let p2p_configs = - generate_test_p2p_configs(&participant_accounts, threshold, port_seed, None).unwrap(); + generate_test_p2p_configs(&participant_accounts, threshold, port_seed).unwrap(); let participants = p2p_configs[0].0.participants.clone(); let mut indexer_manager = FakeIndexerManager::new(clock.clone(), txn_delay_blocks, block_time);