@@ -474,15 +474,9 @@ impl MutRng {
474
474
}
475
475
}
476
476
477
+ /// Contains the configuration options for our simulation.
477
478
#[ derive( Clone ) ]
478
- pub struct Simulation {
479
- /// The lightning node that is being simulated.
480
- nodes : HashMap < PublicKey , Arc < Mutex < dyn LightningNode > > > ,
481
- /// The activity that are to be executed on the node.
482
- activity : Vec < ActivityDefinition > ,
483
- /// High level triggers used to manage simulation tasks and shutdown.
484
- shutdown_trigger : Trigger ,
485
- shutdown_listener : Listener ,
479
+ pub struct SimulationCfg {
486
480
/// Total simulation time. The simulation will run forever if undefined.
487
481
total_time : Option < time:: Duration > ,
488
482
/// The expected payment size for the network.
@@ -498,6 +492,38 @@ pub struct Simulation {
498
492
results : Arc < Mutex < PaymentResultLogger > > ,
499
493
}
500
494
495
+ impl SimulationCfg {
496
+ pub fn new (
497
+ total_time : Option < u32 > ,
498
+ expected_payment_msat : u64 ,
499
+ activity_multiplier : f64 ,
500
+ write_results : Option < WriteResults > ,
501
+ seed : Option < u64 > ,
502
+ ) -> Self {
503
+ Self {
504
+ total_time : total_time. map ( |x| Duration :: from_secs ( x as u64 ) ) ,
505
+ expected_payment_msat,
506
+ activity_multiplier,
507
+ write_results,
508
+ seeded_rng : MutRng :: new ( seed) ,
509
+ results : Arc :: new ( Mutex :: new ( PaymentResultLogger :: new ( ) ) ) ,
510
+ }
511
+ }
512
+ }
513
+
514
+ #[ derive( Clone ) ]
515
+ pub struct Simulation {
516
+ /// Config for the simulation itself.
517
+ cfg : SimulationCfg ,
518
+ /// The lightning node that is being simulated.
519
+ nodes : HashMap < PublicKey , Arc < Mutex < dyn LightningNode > > > ,
520
+ /// The activity that are to be executed on the node.
521
+ activity : Vec < ActivityDefinition > ,
522
+ /// High level triggers used to manage simulation tasks and shutdown.
523
+ shutdown_trigger : Trigger ,
524
+ shutdown_listener : Listener ,
525
+ }
526
+
501
527
#[ derive( Clone ) ]
502
528
pub struct WriteResults {
503
529
/// Data directory where CSV result files are written.
@@ -518,26 +544,17 @@ struct ExecutorKit {
518
544
519
545
impl Simulation {
520
546
pub fn new (
547
+ cfg : SimulationCfg ,
521
548
nodes : HashMap < PublicKey , Arc < Mutex < dyn LightningNode > > > ,
522
549
activity : Vec < ActivityDefinition > ,
523
- total_time : Option < u32 > ,
524
- expected_payment_msat : u64 ,
525
- activity_multiplier : f64 ,
526
- write_results : Option < WriteResults > ,
527
- seed : Option < u64 > ,
528
550
) -> Self {
529
551
let ( shutdown_trigger, shutdown_listener) = triggered:: trigger ( ) ;
530
552
Self {
553
+ cfg,
531
554
nodes,
532
555
activity,
533
556
shutdown_trigger,
534
557
shutdown_listener,
535
- total_time : total_time. map ( |x| Duration :: from_secs ( x as u64 ) ) ,
536
- expected_payment_msat,
537
- activity_multiplier,
538
- write_results,
539
- seeded_rng : MutRng :: new ( seed) ,
540
- results : Arc :: new ( Mutex :: new ( PaymentResultLogger :: new ( ) ) ) ,
541
558
}
542
559
}
543
560
@@ -623,7 +640,7 @@ impl Simulation {
623
640
}
624
641
625
642
pub async fn run ( & self ) -> Result < ( ) , SimulationError > {
626
- if let Some ( total_time) = self . total_time {
643
+ if let Some ( total_time) = self . cfg . total_time {
627
644
log:: info!( "Running the simulation for {}s." , total_time. as_secs( ) ) ;
628
645
} else {
629
646
log:: info!( "Running the simulation forever." ) ;
@@ -709,7 +726,7 @@ impl Simulation {
709
726
} ) ;
710
727
711
728
// Start a task that will shutdown the simulation if the total_time is met.
712
- if let Some ( total_time) = self . total_time {
729
+ if let Some ( total_time) = self . cfg . total_time {
713
730
let t = self . shutdown_trigger . clone ( ) ;
714
731
let l = self . shutdown_listener . clone ( ) ;
715
732
@@ -743,11 +760,11 @@ impl Simulation {
743
760
}
744
761
745
762
pub async fn get_total_payments ( & self ) -> u64 {
746
- self . results . lock ( ) . await . total_attempts ( )
763
+ self . cfg . results . lock ( ) . await . total_attempts ( )
747
764
}
748
765
749
766
pub async fn get_success_rate ( & self ) -> f64 {
750
- self . results . lock ( ) . await . success_rate ( )
767
+ self . cfg . results . lock ( ) . await . success_rate ( )
751
768
}
752
769
753
770
/// run_data_collection starts the tasks required for the simulation to report of the results of the activity that
@@ -781,7 +798,7 @@ impl Simulation {
781
798
}
782
799
} ) ;
783
800
784
- let result_logger = self . results . clone ( ) ;
801
+ let result_logger = self . cfg . results . clone ( ) ;
785
802
786
803
let result_logger_clone = result_logger. clone ( ) ;
787
804
let result_logger_listener = listener. clone ( ) ;
@@ -797,7 +814,7 @@ impl Simulation {
797
814
} ) ;
798
815
799
816
// csr: consume simulation results
800
- let csr_write_results = self . write_results . clone ( ) ;
817
+ let csr_write_results = self . cfg . write_results . clone ( ) ;
801
818
tasks. spawn ( async move {
802
819
log:: debug!( "Starting simulation results consumer." ) ;
803
820
if let Err ( e) = consume_simulation_results (
@@ -864,9 +881,10 @@ impl Simulation {
864
881
for ( pk, node) in self . nodes . iter ( ) {
865
882
let chan_capacity = node. lock ( ) . await . list_channels ( ) . await ?. iter ( ) . sum :: < u64 > ( ) ;
866
883
867
- if let Err ( e) =
868
- RandomPaymentActivity :: validate_capacity ( chan_capacity, self . expected_payment_msat )
869
- {
884
+ if let Err ( e) = RandomPaymentActivity :: validate_capacity (
885
+ chan_capacity,
886
+ self . cfg . expected_payment_msat ,
887
+ ) {
870
888
log:: warn!( "Node: {} not eligible for activity generation: {e}." , * pk) ;
871
889
continue ;
872
890
}
@@ -881,7 +899,7 @@ impl Simulation {
881
899
let network_generator = Arc :: new ( Mutex :: new (
882
900
NetworkGraphView :: new (
883
901
active_nodes. values ( ) . cloned ( ) . collect ( ) ,
884
- self . seeded_rng . clone ( ) ,
902
+ self . cfg . seeded_rng . clone ( ) ,
885
903
)
886
904
. map_err ( SimulationError :: RandomActivityError ) ?,
887
905
) ) ;
@@ -898,9 +916,9 @@ impl Simulation {
898
916
payment_generator : Box :: new (
899
917
RandomPaymentActivity :: new (
900
918
* capacity,
901
- self . expected_payment_msat ,
902
- self . activity_multiplier ,
903
- self . seeded_rng . clone ( ) ,
919
+ self . cfg . expected_payment_msat ,
920
+ self . cfg . activity_multiplier ,
921
+ self . cfg . seeded_rng . clone ( ) ,
904
922
)
905
923
. map_err ( SimulationError :: RandomActivityError ) ?,
906
924
) ,
0 commit comments