Skip to content
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
193 changes: 0 additions & 193 deletions crates/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_account_id::AccountId>,
/// Near responder account for each participant. Refer to `indexer/real.rs` for more details.
#[arg(long, value_delimiter = ',')]
responders: Vec<near_account_id::AccountId>,
#[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<usize>,
},
}
#[derive(Args, Debug)]
pub struct StartCmd {
Expand Down Expand Up @@ -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,
)
}
}
}
}
Expand Down Expand Up @@ -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<AccountId>,
responders: Vec<AccountId>,
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::<Result<Vec<_>, _>>()?;
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<AccountId>,
migrating_nodes: &[usize],
) -> anyhow::Result<Vec<AccountId>> {
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::*;
Expand Down
21 changes: 4 additions & 17 deletions crates/node/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Vec<SigningKey>>,
) -> anyhow::Result<Vec<(MpcConfig, SigningKey)>> {
Comment on lines 1021 to 1024
let p2p_keypairs = if let Some(p2p_keypairs) = p2p_keypairs {
p2p_keypairs
} else {
participant_accounts
.iter()
.map(|_account_id| SigningKey::generate(&mut OsRng))
.collect::<Vec<_>>()
};
let p2p_keypairs = participant_accounts
.iter()
.map(|_account_id| SigningKey::generate(&mut OsRng))
.collect::<Vec<_>>();
let mut participants = Vec::new();
for (i, (participant_account, p2p_signing_key)) in participant_accounts
.iter()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1204,7 +1193,6 @@ mod tests {
],
4,
PortSeed::P2P_WAIT_FOR_READY_TEST,
None,
)
.unwrap();

Expand Down Expand Up @@ -1329,7 +1317,6 @@ mod tests {
&["test0".parse().unwrap(), "test1".parse().unwrap()],
2,
PortSeed::RECONNECTION_TEST,
None,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading