@@ -52,47 +52,72 @@ pub struct DevnetTopology {
52
52
pub pool_nodes : Vec < PoolNode > ,
53
53
}
54
54
55
+ #[ derive( Debug , Clone ) ]
56
+ pub struct DevnetBootstrapArgs {
57
+ pub devnet_scripts_dir : PathBuf ,
58
+ pub artifacts_target_dir : PathBuf ,
59
+ pub number_of_bft_nodes : u8 ,
60
+ pub number_of_pool_nodes : u8 ,
61
+ pub cardano_slot_length : f64 ,
62
+ pub cardano_epoch_length : f64 ,
63
+ pub cardano_hard_fork_latest_era_at_epoch : u16 ,
64
+ pub skip_cardano_bin_download : bool ,
65
+ }
66
+
55
67
impl Devnet {
56
- pub async fn bootstrap (
57
- devnet_scripts_dir : PathBuf ,
58
- artifacts_target_dir : PathBuf ,
59
- number_of_bft_nodes : u8 ,
60
- number_of_pool_nodes : u8 ,
61
- cardano_slot_length : f64 ,
62
- cardano_epoch_length : f64 ,
63
- skip_cardano_bin_download : bool ,
64
- ) -> StdResult < Devnet > {
68
+ pub async fn bootstrap ( bootstrap_args : & DevnetBootstrapArgs ) -> StdResult < Devnet > {
65
69
let bootstrap_script = "devnet-mkfiles.sh" ;
66
- let bootstrap_script_path = devnet_scripts_dir
70
+ let bootstrap_script_path = bootstrap_args
71
+ . devnet_scripts_dir
67
72
. canonicalize ( )
68
73
. with_context ( || {
69
74
format ! (
70
75
"Can't find bootstrap script '{}' in {}" ,
71
76
bootstrap_script,
72
- devnet_scripts_dir. display( ) ,
77
+ bootstrap_args . devnet_scripts_dir. display( ) ,
73
78
)
74
79
} ) ?
75
80
. join ( bootstrap_script) ;
76
81
77
- if artifacts_target_dir. exists ( ) {
78
- fs:: remove_dir_all ( & artifacts_target_dir)
82
+ if bootstrap_args . artifacts_target_dir . exists ( ) {
83
+ fs:: remove_dir_all ( & bootstrap_args . artifacts_target_dir )
79
84
. with_context ( || "Previous artifacts dir removal failed" ) ?;
80
85
}
81
86
82
87
let mut bootstrap_command = Command :: new ( & bootstrap_script_path) ;
83
88
bootstrap_command. env (
84
89
"SKIP_CARDANO_BIN_DOWNLOAD" ,
85
- skip_cardano_bin_download. to_string ( ) ,
90
+ bootstrap_args. skip_cardano_bin_download . to_string ( ) ,
91
+ ) ;
92
+ bootstrap_command. env (
93
+ "ARTIFACTS_DIR" ,
94
+ bootstrap_args. artifacts_target_dir . to_str ( ) . unwrap ( ) ,
95
+ ) ;
96
+ bootstrap_command. env (
97
+ "NUM_BFT_NODES" ,
98
+ bootstrap_args. number_of_bft_nodes . to_string ( ) ,
99
+ ) ;
100
+ bootstrap_command. env (
101
+ "NUM_POOL_NODES" ,
102
+ bootstrap_args. number_of_pool_nodes . to_string ( ) ,
103
+ ) ;
104
+ bootstrap_command. env (
105
+ "SLOT_LENGTH" ,
106
+ bootstrap_args. cardano_slot_length . to_string ( ) ,
107
+ ) ;
108
+ bootstrap_command. env (
109
+ "EPOCH_LENGTH" ,
110
+ bootstrap_args. cardano_epoch_length . to_string ( ) ,
111
+ ) ;
112
+ bootstrap_command. env (
113
+ "CARDANO_HARD_FORK_LATEST_ERA_AT_EPOCH" ,
114
+ bootstrap_args
115
+ . cardano_hard_fork_latest_era_at_epoch
116
+ . to_string ( ) ,
86
117
) ;
87
- bootstrap_command. env ( "ARTIFACTS_DIR" , artifacts_target_dir. to_str ( ) . unwrap ( ) ) ;
88
- bootstrap_command. env ( "NUM_BFT_NODES" , number_of_bft_nodes. to_string ( ) ) ;
89
- bootstrap_command. env ( "NUM_POOL_NODES" , number_of_pool_nodes. to_string ( ) ) ;
90
- bootstrap_command. env ( "SLOT_LENGTH" , cardano_slot_length. to_string ( ) ) ;
91
- bootstrap_command. env ( "EPOCH_LENGTH" , cardano_epoch_length. to_string ( ) ) ;
92
- bootstrap_command. env ( "HARD_FORK_LATEST_ERA_AT_EPOCH" , "1000" ) ; //TODO: set as configuration parameter
93
118
94
119
bootstrap_command
95
- . current_dir ( devnet_scripts_dir)
120
+ . current_dir ( & bootstrap_args . devnet_scripts_dir )
96
121
. stdout ( Stdio :: null ( ) )
97
122
. kill_on_drop ( true ) ;
98
123
@@ -106,9 +131,9 @@ impl Devnet {
106
131
. with_context ( || format ! ( "{bootstrap_script} failed to run" ) ) ?;
107
132
108
133
Ok ( Devnet {
109
- artifacts_dir : artifacts_target_dir,
110
- number_of_bft_nodes,
111
- number_of_pool_nodes,
134
+ artifacts_dir : bootstrap_args . artifacts_target_dir . to_owned ( ) ,
135
+ number_of_bft_nodes : bootstrap_args . number_of_bft_nodes ,
136
+ number_of_pool_nodes : bootstrap_args . number_of_pool_nodes ,
112
137
} )
113
138
}
114
139
0 commit comments