@@ -494,6 +494,8 @@ pub struct Simulation {
494
494
write_results : Option < WriteResults > ,
495
495
/// Random number generator created from fixed seed.
496
496
seeded_rng : MutRng ,
497
+ /// Results logger that holds the simulation statistics.
498
+ results : Arc < Mutex < PaymentResultLogger > > ,
497
499
}
498
500
499
501
#[ derive( Clone ) ]
@@ -535,6 +537,7 @@ impl Simulation {
535
537
activity_multiplier,
536
538
write_results,
537
539
seeded_rng : MutRng :: new ( seed) ,
540
+ results : Arc :: new ( Mutex :: new ( PaymentResultLogger :: new ( ) ) ) ,
538
541
}
539
542
}
540
543
@@ -739,6 +742,14 @@ impl Simulation {
739
742
self . shutdown_trigger . trigger ( )
740
743
}
741
744
745
+ pub async fn get_total_payments ( & self ) -> u64 {
746
+ self . results . lock ( ) . await . total_attempts ( )
747
+ }
748
+
749
+ pub async fn get_success_rate ( & self ) -> f64 {
750
+ self . results . lock ( ) . await . success_rate ( )
751
+ }
752
+
742
753
/// run_data_collection starts the tasks required for the simulation to report of the results of the activity that
743
754
/// it generates. The simulation should report outputs via the receiver that is passed in.
744
755
fn run_data_collection (
@@ -770,7 +781,7 @@ impl Simulation {
770
781
}
771
782
} ) ;
772
783
773
- let result_logger = Arc :: new ( Mutex :: new ( PaymentResultLogger :: new ( ) ) ) ;
784
+ let result_logger = self . results . clone ( ) ;
774
785
775
786
let result_logger_clone = result_logger. clone ( ) ;
776
787
let result_logger_listener = listener. clone ( ) ;
@@ -1238,17 +1249,24 @@ impl PaymentResultLogger {
1238
1249
1239
1250
self . total_sent += details. amount_msat ;
1240
1251
}
1252
+
1253
+ fn total_attempts ( & self ) -> u64 {
1254
+ self . success_payment + self . failed_payment
1255
+ }
1256
+
1257
+ fn success_rate ( & self ) -> f64 {
1258
+ ( self . success_payment as f64 / self . total_attempts ( ) as f64 ) * 100.0
1259
+ }
1241
1260
}
1242
1261
1243
1262
impl Display for PaymentResultLogger {
1244
1263
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
1245
- let total_payments = self . success_payment + self . failed_payment ;
1246
1264
write ! (
1247
1265
f,
1248
1266
"Processed {} payments sending {} msat total with {:.2}% success rate." ,
1249
- total_payments ,
1267
+ self . total_attempts ( ) ,
1250
1268
self . total_sent,
1251
- ( self . success_payment as f64 / total_payments as f64 ) * 100.0
1269
+ self . success_rate ( )
1252
1270
)
1253
1271
}
1254
1272
}
0 commit comments