@@ -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 ) ]
7551pub 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) ]
529336mod tests {
530337 use super :: * ;
0 commit comments