@@ -149,6 +149,8 @@ pub struct ActivityParser {
149
149
pub interval_secs : u16 ,
150
150
/// The amount of m_sat to used in this payment.
151
151
pub amount_msat : u64 ,
152
+ /// an optional name for the activity.
153
+ pub activity_name : Option < String > ,
152
154
}
153
155
154
156
/// Data structure used internally by the simulator. Both source and destination are represented as [PublicKey] here.
@@ -167,6 +169,8 @@ pub struct ActivityDefinition {
167
169
pub interval_secs : u16 ,
168
170
/// The amount of m_sat to used in this payment.
169
171
pub amount_msat : u64 ,
172
+ /// An optional name for the activity.
173
+ pub activity_name : Option < String > ,
170
174
}
171
175
172
176
#[ derive( Debug , Error ) ]
@@ -336,14 +340,16 @@ pub enum PaymentOutcome {
336
340
}
337
341
338
342
/// Describes a payment from a source node to a destination node.
339
- #[ derive( Debug , Clone , Copy , Serialize ) ]
343
+ #[ derive( Debug , Clone , Serialize ) ]
340
344
struct Payment {
341
345
/// Pubkey of the source node dispatching the payment.
342
346
source : PublicKey ,
343
347
/// Pubkey of the destination node receiving the payment.
344
348
destination : PublicKey ,
345
349
/// Amount of the payment in msat.
346
350
amount_msat : u64 ,
351
+ /// Name of the activity.
352
+ activity_name : String ,
347
353
/// Hash of the payment if it has been successfully dispatched.
348
354
#[ serde( with = "serializers::serde_option_payment_hash" ) ]
349
355
hash : Option < PaymentHash > ,
@@ -352,6 +358,16 @@ struct Payment {
352
358
dispatch_time : SystemTime ,
353
359
}
354
360
361
+ impl Payment {
362
+ fn formatted_activity_name ( & self ) -> String {
363
+ if !self . activity_name . is_empty ( ) {
364
+ format ! ( "{} activity:" , self . activity_name)
365
+ } else {
366
+ "" . to_string ( )
367
+ }
368
+ }
369
+ }
370
+
355
371
impl Display for Payment {
356
372
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
357
373
let dispatch_time = self
@@ -361,7 +377,8 @@ impl Display for Payment {
361
377
362
378
write ! (
363
379
f,
364
- "Payment {} dispatched at {:?} sending {} msat from {} -> {}." ,
380
+ "{} Payment {} dispatched at {:?} sending {} msat from {} -> {}." ,
381
+ self . formatted_activity_name( ) ,
365
382
self . hash. map( |h| hex:: encode( h. 0 ) ) . unwrap_or_default( ) ,
366
383
dispatch_time,
367
384
self . amount_msat,
@@ -377,7 +394,7 @@ impl Display for Payment {
377
394
enum SimulationEvent {
378
395
/// Dispatch a payment of the specified amount to the public key provided.
379
396
/// Results in `SimulationOutput::SendPaymentSuccess` or `SimulationOutput::SendPaymentFailure`.
380
- SendPayment ( NodeInfo , u64 ) ,
397
+ SendPayment ( NodeInfo , u64 , String ) ,
381
398
}
382
399
383
400
/// SimulationOutput provides the output of a simulation event.
@@ -427,6 +444,7 @@ struct ExecutorKit {
427
444
/// See [NetworkGraphView] for details.
428
445
network_generator : Arc < Mutex < dyn DestinationGenerator > > ,
429
446
payment_generator : Box < dyn PaymentGenerator > ,
447
+ activity_name : String ,
430
448
}
431
449
432
450
impl Simulation {
@@ -696,7 +714,12 @@ impl Simulation {
696
714
// Note: when we allow configuring both defined and random activity, this will no longer be an if/else, we'll
697
715
// just populate with each type as configured.
698
716
if !self . activity . is_empty ( ) {
699
- for description in self . activity . iter ( ) {
717
+ for ( index, description) in self . activity . iter ( ) . enumerate ( ) {
718
+ let activity_name = match & description. activity_name {
719
+ Some ( name) => name. clone ( ) ,
720
+ None => format ! ( "Index {}" , index) ,
721
+ } ;
722
+
700
723
let activity_generator = DefinedPaymentActivity :: new (
701
724
description. destination . clone ( ) ,
702
725
Duration :: from_secs ( description. start_secs . into ( ) ) ,
@@ -711,6 +734,7 @@ impl Simulation {
711
734
// a single struct which we just cheaply clone.
712
735
network_generator : Arc :: new ( Mutex :: new ( activity_generator. clone ( ) ) ) ,
713
736
payment_generator : Box :: new ( activity_generator) ,
737
+ activity_name,
714
738
} ) ;
715
739
}
716
740
} else {
@@ -762,6 +786,7 @@ impl Simulation {
762
786
generators. push ( ExecutorKit {
763
787
source_info : node_info. clone ( ) ,
764
788
network_generator : network_generator. clone ( ) ,
789
+ activity_name : "" . to_string ( ) ,
765
790
payment_generator : Box :: new (
766
791
RandomPaymentActivity :: new (
767
792
* capacity,
@@ -845,13 +870,15 @@ impl Simulation {
845
870
let source = executor. source_info . clone ( ) ;
846
871
847
872
log:: info!(
848
- "Starting activity producer for {}: {}." ,
873
+ "Starting {} activity producer for {}: {}." ,
874
+ executor. activity_name,
849
875
source,
850
876
executor. payment_generator
851
877
) ;
852
878
853
879
if let Err ( e) = produce_events (
854
880
executor. source_info ,
881
+ executor. activity_name ,
855
882
executor. network_generator ,
856
883
executor. payment_generator ,
857
884
pe_sender,
@@ -888,7 +915,7 @@ async fn consume_events(
888
915
simulation_event = receiver. recv( ) => {
889
916
if let Some ( event) = simulation_event {
890
917
match event {
891
- SimulationEvent :: SendPayment ( dest, amt_msat) => {
918
+ SimulationEvent :: SendPayment ( dest, amt_msat, activity_name ) => {
892
919
let mut node = node. lock( ) . await ;
893
920
894
921
let mut payment = Payment {
@@ -897,6 +924,7 @@ async fn consume_events(
897
924
amount_msat: amt_msat,
898
925
destination: dest. pubkey,
899
926
dispatch_time: SystemTime :: now( ) ,
927
+ activity_name,
900
928
} ;
901
929
902
930
let outcome = match node. send_payment( dest. pubkey, amt_msat) . await {
@@ -947,6 +975,7 @@ async fn consume_events(
947
975
/// exit if other threads signal that they have errored out.
948
976
async fn produce_events < N : DestinationGenerator + ?Sized , A : PaymentGenerator + ?Sized > (
949
977
source : NodeInfo ,
978
+ activity_name : String ,
950
979
network_generator : Arc < Mutex < N > > ,
951
980
node_generator : Box < A > ,
952
981
sender : Sender < SimulationEvent > ,
@@ -996,7 +1025,7 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
996
1025
let amount = match node_generator. payment_amount( capacity) {
997
1026
Ok ( amt) => {
998
1027
if amt == 0 {
999
- log:: debug!( "Skipping zero amount payment for {source} -> {destination}." ) ;
1028
+ log:: debug!( "{activity_name} activity : Skipping zero amount payment for {source} -> {destination}." ) ;
1000
1029
continue ;
1001
1030
}
1002
1031
amt
@@ -1009,7 +1038,7 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
1009
1038
log:: debug!( "Generated payment: {source} -> {}: {amount} msat." , destination) ;
1010
1039
1011
1040
// Send the payment, exiting if we can no longer send to the consumer.
1012
- let event = SimulationEvent :: SendPayment ( destination. clone( ) , amount) ;
1041
+ let event = SimulationEvent :: SendPayment ( destination. clone( ) , amount, activity_name . clone ( ) ) ;
1013
1042
if sender. send( event. clone( ) ) . await . is_err( ) {
1014
1043
return Err ( SimulationError :: MpscChannelError ( format!( "Stopped activity producer for {amount}: {source} -> {destination}." ) ) ) ;
1015
1044
}
@@ -1076,11 +1105,12 @@ async fn consume_simulation_results(
1076
1105
}
1077
1106
1078
1107
/// PaymentResultLogger is an aggregate logger that will report on a summary of the payments that have been reported.
1079
- #[ derive( Default ) ]
1108
+ #[ derive( Default , Clone ) ]
1080
1109
struct PaymentResultLogger {
1081
1110
success_payment : u64 ,
1082
1111
failed_payment : u64 ,
1083
1112
total_sent : u64 ,
1113
+ activity_name : String ,
1084
1114
}
1085
1115
1086
1116
impl PaymentResultLogger {
@@ -1097,6 +1127,7 @@ impl PaymentResultLogger {
1097
1127
}
1098
1128
1099
1129
self . total_sent += details. amount_msat ;
1130
+ self . activity_name = details. formatted_activity_name ( ) ;
1100
1131
}
1101
1132
}
1102
1133
@@ -1105,7 +1136,8 @@ impl Display for PaymentResultLogger {
1105
1136
let total_payments = self . success_payment + self . failed_payment ;
1106
1137
write ! (
1107
1138
f,
1108
- "Processed {} payments sending {} msat total with {:.2}% success rate." ,
1139
+ "{} Processed {} payments sending {} msat total with {:.2}% success rate." ,
1140
+ self . activity_name,
1109
1141
total_payments,
1110
1142
self . total_sent,
1111
1143
( self . success_payment as f64 / total_payments as f64 ) * 100.0
@@ -1174,7 +1206,7 @@ async fn produce_simulation_results(
1174
1206
}
1175
1207
} ,
1176
1208
SimulationOutput :: SendPaymentFailure ( payment, result) => {
1177
- if results. send( ( payment, result. clone( ) ) ) . await . is_err( ) {
1209
+ if results. send( ( payment. clone ( ) , result. clone( ) ) ) . await . is_err( ) {
1178
1210
return Err ( SimulationError :: MpscChannelError (
1179
1211
format!( "Failed to send payment result: {result} for payment {:?} dispatched at {:?}." , payment. hash, payment. dispatch_time) ,
1180
1212
) ) ;
@@ -1245,7 +1277,7 @@ async fn track_payment_result(
1245
1277
_ = listener. clone( ) => {
1246
1278
log:: debug!( "Track payment result received a shutdown signal." ) ;
1247
1279
} ,
1248
- send_payment_result = results. send( ( payment, res. clone( ) ) ) => {
1280
+ send_payment_result = results. send( ( payment. clone ( ) , res. clone( ) ) ) => {
1249
1281
if send_payment_result. is_err( ) {
1250
1282
return Err ( SimulationError :: MpscChannelError ( format!( "Failed to send payment result {res} for payment {payment}." ) ) )
1251
1283
}
0 commit comments