Skip to content

Commit 8396a22

Browse files
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.
1 parent 2c3b558 commit 8396a22

3 files changed

Lines changed: 5 additions & 211 deletions

File tree

crates/node/src/cli.rs

Lines changed: 0 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,6 @@ pub enum CliCommand {
4646
ImportKeyshare(ImportKeyshareCmd),
4747
/// Exports a keyshare from local encrypted storage and prints it to the console
4848
ExportKeyshare(ExportKeyshareCmd),
49-
/// Generates a set of test configurations suitable for running MPC in
50-
/// an integration test.
51-
#[cfg(feature = "test-utils")]
52-
GenerateTestConfigs {
53-
#[arg(long)]
54-
output_dir: String,
55-
#[arg(long, value_delimiter = ',', required = true)]
56-
/// Near signer account for each participant
57-
participants: Vec<near_account_id::AccountId>,
58-
/// Near responder account for each participant. Refer to `indexer/real.rs` for more details.
59-
#[arg(long, value_delimiter = ',')]
60-
responders: Vec<near_account_id::AccountId>,
61-
#[arg(long)]
62-
threshold: usize,
63-
#[arg(long, default_value = "65536")]
64-
desired_triples_to_buffer: usize,
65-
#[arg(long, default_value = "8192")]
66-
desired_presignatures_to_buffer: usize,
67-
#[arg(long, default_value = "1")]
68-
desired_responder_keys_per_participant: usize,
69-
/// optional argument. If set, generates additional config for participants\[id\] for each id in migrating_nodes.
70-
#[arg(long, value_delimiter = ',')]
71-
migrating_nodes: Vec<usize>,
72-
},
7349
}
7450
#[derive(Args, Debug)]
7551
pub struct StartCmd {
@@ -256,32 +232,6 @@ impl Cli {
256232
}
257233
CliCommand::ImportKeyshare(cmd) => cmd.run().await,
258234
CliCommand::ExportKeyshare(cmd) => cmd.run().await,
259-
#[cfg(feature = "test-utils")]
260-
CliCommand::GenerateTestConfigs {
261-
ref output_dir,
262-
ref participants,
263-
ref responders,
264-
threshold,
265-
desired_triples_to_buffer,
266-
desired_presignatures_to_buffer,
267-
desired_responder_keys_per_participant,
268-
ref migrating_nodes,
269-
} => {
270-
anyhow::ensure!(
271-
participants.len() == responders.len(),
272-
"Number of participants must match number of responders"
273-
);
274-
testing::run_generate_test_configs(
275-
output_dir,
276-
participants.clone(),
277-
responders.clone(),
278-
threshold,
279-
desired_triples_to_buffer,
280-
desired_presignatures_to_buffer,
281-
desired_responder_keys_per_participant,
282-
migrating_nodes,
283-
)
284-
}
285235
}
286236
}
287237
}
@@ -382,149 +332,6 @@ impl ExportKeyshareCmd {
382332
}
383333
}
384334

385-
#[cfg(feature = "test-utils")]
386-
mod testing {
387-
use std::{
388-
net::{Ipv4Addr, SocketAddr},
389-
path::PathBuf,
390-
};
391-
392-
use crate::{
393-
config::PersistentSecrets,
394-
p2p::testing::{PortSeed, generate_test_p2p_configs},
395-
};
396-
use mpc_node_config::{
397-
BlockArgs, CKDConfig, ConfigFile, ForeignChainsConfig, IndexerConfig, KeygenConfig,
398-
PresignatureConfig, SignatureConfig, SyncMode, TripleConfig,
399-
};
400-
use near_indexer_primitives::types::Finality;
401-
use near_sdk::AccountId;
402-
403-
#[expect(clippy::too_many_arguments)]
404-
pub(crate) fn run_generate_test_configs(
405-
output_dir: &str,
406-
participants: Vec<AccountId>,
407-
responders: Vec<AccountId>,
408-
threshold: usize,
409-
desired_triples_to_buffer: usize,
410-
desired_presignatures_to_buffer: usize,
411-
desired_responder_keys_per_participant: usize,
412-
migrating_nodes: &[usize],
413-
) -> anyhow::Result<()> {
414-
let participants = duplicate_migrating_accounts(participants, migrating_nodes)?;
415-
let responders = duplicate_migrating_accounts(responders, migrating_nodes)?;
416-
417-
let p2p_key_pairs = participants
418-
.iter()
419-
.enumerate()
420-
.map(|(idx, _account_id)| {
421-
let subdir = PathBuf::from(output_dir).join(idx.to_string());
422-
PersistentSecrets::generate_or_get_existing(
423-
&subdir,
424-
desired_responder_keys_per_participant,
425-
)
426-
.map(|secret| secret.p2p_private_key)
427-
})
428-
.collect::<Result<Vec<_>, _>>()?;
429-
let configs = generate_test_p2p_configs(
430-
&participants,
431-
threshold,
432-
PortSeed::CLI_FOR_PYTEST,
433-
Some(p2p_key_pairs),
434-
)?;
435-
let participants_config = configs[0].0.participants.clone();
436-
for (i, (_config, _p2p_private_key)) in configs.into_iter().enumerate() {
437-
let subdir = format!("{}/{}", output_dir, i);
438-
std::fs::create_dir_all(&subdir)?;
439-
let file_config = create_file_config(
440-
&participants[i],
441-
&responders[i],
442-
i,
443-
desired_triples_to_buffer,
444-
desired_presignatures_to_buffer,
445-
);
446-
std::fs::write(
447-
format!("{}/mpc_node_config.json", subdir),
448-
serde_json::to_string_pretty(&file_config)?,
449-
)?;
450-
}
451-
std::fs::write(
452-
format!("{}/participants.json", output_dir),
453-
serde_json::to_string(&participants_config)?,
454-
)?;
455-
Ok(())
456-
}
457-
458-
fn duplicate_migrating_accounts(
459-
mut accounts: Vec<AccountId>,
460-
migrating_nodes: &[usize],
461-
) -> anyhow::Result<Vec<AccountId>> {
462-
for migrating_node_idx in migrating_nodes {
463-
let migrating_node_account: AccountId = accounts
464-
.get(*migrating_node_idx)
465-
.ok_or_else(|| {
466-
anyhow::anyhow!("index {} out of bounds for accounts", migrating_node_idx)
467-
})?
468-
.clone();
469-
470-
accounts.push(migrating_node_account);
471-
}
472-
Ok(accounts)
473-
}
474-
475-
fn create_file_config(
476-
participant: &AccountId,
477-
responder: &AccountId,
478-
index: usize,
479-
desired_triples_to_buffer: usize,
480-
desired_presignatures_to_buffer: usize,
481-
) -> ConfigFile {
482-
ConfigFile {
483-
my_near_account_id: participant.clone(),
484-
near_responder_account_id: responder.clone(),
485-
number_of_responder_keys: 1,
486-
web_ui: SocketAddr::new(
487-
Ipv4Addr::LOCALHOST.into(),
488-
PortSeed::CLI_FOR_PYTEST.web_port(index),
489-
),
490-
migration_web_ui: SocketAddr::new(
491-
Ipv4Addr::LOCALHOST.into(),
492-
PortSeed::CLI_FOR_PYTEST.migration_web_port(index),
493-
),
494-
pprof_bind_address: SocketAddr::new(
495-
Ipv4Addr::LOCALHOST.into(),
496-
PortSeed::CLI_FOR_PYTEST.pprof_web_port(index),
497-
),
498-
indexer: IndexerConfig {
499-
validate_genesis: true,
500-
sync_mode: SyncMode::Block(BlockArgs { height: 0 }),
501-
concurrency: 1.try_into().unwrap(),
502-
mpc_contract_id: "test0".parse().unwrap(),
503-
finality: Finality::None,
504-
port_override: None,
505-
wipe_near_data_token: 0,
506-
},
507-
triple: TripleConfig {
508-
concurrency: 2,
509-
desired_triples_to_buffer,
510-
timeout_sec: 60,
511-
parallel_triple_generation_stagger_time_sec: 1,
512-
},
513-
presignature: PresignatureConfig {
514-
concurrency: 2,
515-
desired_presignatures_to_buffer,
516-
timeout_sec: 60,
517-
},
518-
signature: SignatureConfig { timeout_sec: 60 },
519-
ckd: CKDConfig { timeout_sec: 60 },
520-
keygen: KeygenConfig { timeout_sec: 60 },
521-
foreign_chains: ForeignChainsConfig::default(),
522-
cores: Some(4),
523-
separate_asset_generation_runtime: true,
524-
}
525-
}
526-
}
527-
528335
#[cfg(test)]
529336
mod tests {
530337
use super::*;

crates/node/src/p2p.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,6 @@ pub mod testing {
942942
impl PortSeed {
943943
// The base port number used, hoping the OS is not using ports in this range
944944
pub const BASE_PORT: u16 = 10000;
945-
// This constant must be equal to the total number of ports defined below
946-
pub const TOTAL_DEFINED_PORTS: u16 = 23;
947945
// Maximum number of nodes that can be handled without port collisions
948946
pub const MAX_NODES: u16 = 10;
949947
// Maximum number of cases that can be handled without port collisions
@@ -989,8 +987,6 @@ pub mod testing {
989987
pub fn pprof_web_port(&self, node_index: usize) -> u16 {
990988
self.compute_port(node_index as u16, 3)
991989
}
992-
993-
pub const CLI_FOR_PYTEST: Self = Self::new(0);
994990
}
995991

996992
impl PortSeed {
@@ -1025,17 +1021,11 @@ pub mod testing {
10251021
// this is a hack to make sure that when tests run in parallel, they don't
10261022
// collide on the same port.
10271023
port_seed: PortSeed,
1028-
// Supply `Some` value here if you want to use pre-existing p2p key pairs
1029-
p2p_keypairs: Option<Vec<SigningKey>>,
10301024
) -> anyhow::Result<Vec<(MpcConfig, SigningKey)>> {
1031-
let p2p_keypairs = if let Some(p2p_keypairs) = p2p_keypairs {
1032-
p2p_keypairs
1033-
} else {
1034-
participant_accounts
1035-
.iter()
1036-
.map(|_account_id| SigningKey::generate(&mut OsRng))
1037-
.collect::<Vec<_>>()
1038-
};
1025+
let p2p_keypairs = participant_accounts
1026+
.iter()
1027+
.map(|_account_id| SigningKey::generate(&mut OsRng))
1028+
.collect::<Vec<_>>();
10391029
let mut participants = Vec::new();
10401030
for (i, (participant_account, p2p_signing_key)) in participant_accounts
10411031
.iter()
@@ -1097,7 +1087,6 @@ mod tests {
10971087
&["test0".parse().unwrap(), "test1".parse().unwrap()],
10981088
2,
10991089
PortSeed::P2P_BASIC_TEST,
1100-
None,
11011090
)
11021091
.unwrap();
11031092
let participant0 = configs[0].0.my_participant_id;
@@ -1204,7 +1193,6 @@ mod tests {
12041193
],
12051194
4,
12061195
PortSeed::P2P_WAIT_FOR_READY_TEST,
1207-
None,
12081196
)
12091197
.unwrap();
12101198

@@ -1329,7 +1317,6 @@ mod tests {
13291317
&["test0".parse().unwrap(), "test1".parse().unwrap()],
13301318
2,
13311319
PortSeed::RECONNECTION_TEST,
1332-
None,
13331320
)
13341321
.unwrap();
13351322

crates/node/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl IntegrationTestSetup {
194194
block_time: std::time::Duration,
195195
) -> IntegrationTestSetup {
196196
let p2p_configs =
197-
generate_test_p2p_configs(&participant_accounts, threshold, port_seed, None).unwrap();
197+
generate_test_p2p_configs(&participant_accounts, threshold, port_seed).unwrap();
198198
let participants = p2p_configs[0].0.participants.clone();
199199
let mut indexer_manager =
200200
FakeIndexerManager::new(clock.clone(), txn_delay_blocks, block_time);

0 commit comments

Comments
 (0)