@@ -30,6 +30,7 @@ use crate::blockchain::{DeployedContract, NearBlockchain};
3030use crate :: caller:: { CallMpc , WithWaitLevel } ;
3131use crate :: mpc_node:: { MpcNode , MpcNodeSetup , MpcNodeSetupArgs , NodePorts } ;
3232use crate :: near_sandbox:: NearSandbox ;
33+ use crate :: test_dir:: TestDir ;
3334use test_port_allocator:: TestPorts ;
3435
3536const SANDBOX_ROOT_ACCOUNT : & str = "sandbox" ;
@@ -97,7 +98,8 @@ pub struct MpcClusterConfig {
9798 pub presignatures_to_buffer : usize ,
9899 /// Version of the `near-sandbox` binary (e.g. `"2.6.3"`, `"2.10.4"`).
99100 pub sandbox_version : String ,
100- /// Root directory for all test artifacts (logs, configs, DB). If `None`, a temp dir is created.
101+ /// Parent of the directory holding all test artifacts (logs, configs, DB).
102+ /// If `None`, `E2E_HOME_BASE` is used, else the system temp dir.
101103 pub home_base : Option < PathBuf > ,
102104 /// Indices (into the node array) of nodes that are initial participants.
103105 /// An empty vec means all nodes are participants. Set to a subset to start
@@ -250,8 +252,7 @@ pub struct MpcCluster {
250252 pub threshold : usize ,
251253 pub user_accounts : HashMap < AccountId , SigningKey > ,
252254 pub ports : TestPorts ,
253- /// Held to keep the temp directory alive for the lifetime of the cluster.
254- pub test_dir : tempfile:: TempDir ,
255+ pub test_dir : TestDir ,
255256}
256257
257258impl MpcCluster {
@@ -263,9 +264,19 @@ impl MpcCluster {
263264 /// binaries, and wait for Running state.
264265 pub async fn start ( config : MpcClusterConfig ) -> anyhow:: Result < Self > {
265266 config. validate ( ) ?;
267+ let test_dir = TestDir :: new ( config. home_base . as_deref ( ) ) ?;
268+ Self :: start_in ( & test_dir, config) . await . map_err ( |error| {
269+ test_dir. keep ( ) ;
270+ error. context ( format ! (
271+ "cluster artifacts preserved in {}" ,
272+ test_dir. path( ) . display( )
273+ ) )
274+ } )
275+ }
276+
277+ async fn start_in ( test_dir : & TestDir , config : MpcClusterConfig ) -> anyhow:: Result < Self > {
266278 let threshold = config. threshold ;
267279 let ports = TestPorts :: e2e_tests ( config. port_seed ) ;
268- let test_dir = create_test_dir ( & config. home_base ) ?;
269280
270281 let sandbox = NearSandbox :: start ( & ports, & config. sandbox_version ) . await ?;
271282 let root_secret_key: near_kit:: SecretKey = SANDBOX_ROOT_SECRET_KEY
@@ -371,7 +382,7 @@ impl MpcCluster {
371382 threshold,
372383 user_accounts,
373384 ports,
374- test_dir,
385+ test_dir : test_dir . clone ( ) ,
375386 } )
376387 }
377388
@@ -1192,16 +1203,6 @@ impl MpcNodeState {
11921203 }
11931204}
11941205
1195- fn create_test_dir ( home_base : & Option < PathBuf > ) -> anyhow:: Result < tempfile:: TempDir > {
1196- match home_base {
1197- Some ( base) => {
1198- std:: fs:: create_dir_all ( base) ?;
1199- Ok ( tempfile:: tempdir_in ( base) ?)
1200- }
1201- None => Ok ( tempfile:: tempdir ( ) ?) ,
1202- }
1203- }
1204-
12051206fn generate_signing_keys (
12061207 num_nodes : u64 ,
12071208) -> (
@@ -1637,8 +1638,9 @@ async fn ensure_nodes_alive(nodes: &mut [MpcNodeState]) -> anyhow::Result<()> {
16371638 if let MpcNodeState :: Running ( n) = node {
16381639 anyhow:: ensure!(
16391640 !n. has_exited( ) ,
1640- "mpc-node {i} exited early — check {}/{} " ,
1641+ "mpc-node {i} exited early, check {} ({} holds its logs, {} any panic) " ,
16411642 n. setup( ) . home_dir( ) . display( ) ,
1643+ crate :: mpc_node:: STDOUT_LOG ,
16421644 crate :: mpc_node:: STDERR_LOG
16431645 ) ;
16441646 }
0 commit comments