1
- use bitcoin:: secp256k1:: PublicKey ;
2
1
use anyhow:: anyhow;
2
+ use bitcoin:: secp256k1:: PublicKey ;
3
3
use clap:: { builder:: TypedValueParser , Parser } ;
4
- use std :: path :: PathBuf ;
4
+ use log :: LevelFilter ;
5
5
use serde:: { Deserialize , Serialize } ;
6
6
use simln_lib:: {
7
- Amount , Interval , cln , lnd, serializers, NodeId , SimulationCfg , Simulation , WriteResults , LightningError , LightningNode ,
8
- cln :: ClnNode , lnd :: LndNode , ActivityDefinition , NodeInfo
7
+ cln , cln :: ClnNode , lnd , lnd:: LndNode , serializers, ActivityDefinition , Amount , Interval ,
8
+ LightningError , LightningNode , NodeId , NodeInfo , Simulation , SimulationCfg , WriteResults ,
9
9
} ;
10
- use log:: LevelFilter ;
11
- use std:: sync:: Arc ;
10
+ use std:: collections:: HashMap ;
12
11
use std:: fs;
12
+ use std:: path:: PathBuf ;
13
+ use std:: sync:: Arc ;
13
14
use tokio:: sync:: Mutex ;
14
- use std:: collections:: HashMap ;
15
15
16
16
/// The default directory where the simulation files are stored and where the results will be written to.
17
17
pub const DEFAULT_DATA_DIR : & str = "." ;
@@ -138,10 +138,7 @@ impl TryFrom<&Cli> for SimulationCfg {
138
138
139
139
/// Parses the cli options provided and creates a simulation to be run, connecting to lightning nodes and validating
140
140
/// any activity described in the simulation file.
141
- pub async fn create_simulation (
142
- cli : & Cli ,
143
- ) -> Result < Simulation , anyhow:: Error > {
144
-
141
+ pub async fn create_simulation ( cli : & Cli ) -> Result < Simulation , anyhow:: Error > {
145
142
let cfg: SimulationCfg = SimulationCfg :: try_from ( cli) ?;
146
143
147
144
let sim_path = read_sim_path ( cli. data_dir . clone ( ) , cli. sim_file . clone ( ) ) . await ?;
@@ -168,12 +165,8 @@ pub async fn create_simulation(
168
165
) )
169
166
} ;
170
167
171
- let validated_activities = validate_activities (
172
- activity,
173
- & clients_info,
174
- get_node
175
- ) . await ?;
176
-
168
+ let validated_activities = validate_activities ( activity, & clients_info, get_node) . await ?;
169
+
177
170
Ok ( Simulation :: new ( cfg, clients, validated_activities) )
178
171
}
179
172
@@ -212,7 +205,7 @@ async fn get_clients(
212
205
/// Adds a lightning node to a client map and tracking maps used to lookup node pubkeys and aliases for activity
213
206
/// validation.
214
207
async fn add_node_to_maps (
215
- nodes : & HashMap < PublicKey , NodeInfo >
208
+ nodes : & HashMap < PublicKey , NodeInfo > ,
216
209
) -> Result < ( HashMap < PublicKey , NodeInfo > , HashMap < String , NodeInfo > ) , LightningError > {
217
210
let mut pk_node_map = HashMap :: new ( ) ;
218
211
let mut alias_node_map = HashMap :: new ( ) ;
@@ -255,10 +248,6 @@ async fn validate_activities(
255
248
nodes : & HashMap < PublicKey , NodeInfo > ,
256
249
get_node_info : impl AsyncFn ( & PublicKey ) -> Result < NodeInfo , LightningError > ,
257
250
) -> Result < Vec < ActivityDefinition > , LightningError > {
258
- if activity. is_empty ( ) {
259
- return Ok ( vec ! [ ] ) ;
260
- }
261
-
262
251
let mut validated_activities = vec ! [ ] ;
263
252
let ( pk_node_map, alias_node_map) = add_node_to_maps ( nodes) . await ?;
264
253
0 commit comments