@@ -6,6 +6,7 @@ use lightning::ln::features::NodeFeatures;
6
6
use lightning:: ln:: PaymentHash ;
7
7
use random_activity:: RandomActivityError ;
8
8
use serde:: { Deserialize , Serialize } ;
9
+ use sim_node:: { SimGraph , SimulatedChannel } ;
9
10
use std:: collections:: HashSet ;
10
11
use std:: fmt:: { Display , Formatter } ;
11
12
use std:: marker:: Send ;
@@ -21,6 +22,7 @@ use triggered::{Listener, Trigger};
21
22
22
23
use self :: defined_activity:: DefinedPaymentActivity ;
23
24
use self :: random_activity:: { NetworkGraphView , RandomPaymentActivity } ;
25
+ use self :: sim_node:: { ln_node_from_graph, populate_network_graph} ;
24
26
25
27
pub mod cln;
26
28
mod defined_activity;
@@ -134,6 +136,8 @@ pub enum SimulationError {
134
136
FileError ,
135
137
#[ error( "{0}" ) ]
136
138
RandomActivityError ( RandomActivityError ) ,
139
+ #[ error( "{0}" ) ]
140
+ RandomGraphError ( String ) ,
137
141
}
138
142
139
143
#[ derive( Debug , Error ) ]
@@ -368,20 +372,53 @@ impl Simulation {
368
372
expected_payment_msat : u64 ,
369
373
activity_multiplier : f64 ,
370
374
write_results : Option < WriteResults > ,
371
- shutdown : ( Trigger , Listener ) ,
372
375
) -> Self {
376
+ let ( shutdown_trigger, shutdown_listener) = triggered:: trigger ( ) ;
377
+
373
378
Self {
374
379
nodes,
375
380
activity,
376
- shutdown_trigger : shutdown . 0 ,
377
- shutdown_listener : shutdown . 1 ,
381
+ shutdown_trigger,
382
+ shutdown_listener,
378
383
total_time : total_time. map ( |x| Duration :: from_secs ( x as u64 ) ) ,
379
384
expected_payment_msat,
380
385
activity_multiplier,
381
386
write_results,
382
387
}
383
388
}
384
389
390
+ pub async fn from_sim_channels (
391
+ channels : Vec < SimulatedChannel > ,
392
+ activity : Vec < ActivityDefinition > ,
393
+ total_time : Option < u32 > ,
394
+ expected_payment_msat : u64 ,
395
+ activity_multiplier : f64 ,
396
+ write_results : Option < WriteResults > ,
397
+ ) -> Result < ( Self , Arc < Mutex < SimGraph > > ) , SimulationError > {
398
+ let ( shutdown_trigger, shutdown_listener) = triggered:: trigger ( ) ;
399
+
400
+ let sim_graph = SimGraph :: new ( channels. clone ( ) , shutdown_trigger. clone ( ) )
401
+ . map ( |graph| Arc :: new ( Mutex :: new ( graph) ) )
402
+ . map_err ( |e| SimulationError :: RandomGraphError ( e. err ) ) ?;
403
+
404
+ let routing_graph = populate_network_graph ( channels)
405
+ . map_err ( |e| SimulationError :: RandomGraphError ( e. err ) ) ?;
406
+
407
+ Ok ( (
408
+ Self {
409
+ nodes : ln_node_from_graph ( sim_graph. clone ( ) , Arc :: new ( routing_graph) ) . await ,
410
+ activity,
411
+ shutdown_trigger,
412
+ shutdown_listener,
413
+ total_time : total_time. map ( |x| Duration :: from_secs ( x as u64 ) ) ,
414
+ expected_payment_msat,
415
+ activity_multiplier,
416
+ write_results,
417
+ } ,
418
+ sim_graph. clone ( ) ,
419
+ ) )
420
+ }
421
+
385
422
/// validate_activity validates that the user-provided activity description is achievable for the network that
386
423
/// we're working with. If no activity description is provided, then it ensures that we have configured a network
387
424
/// that is suitable for random activity generation.
0 commit comments