@@ -139,6 +139,12 @@ pub struct ActivityParser {
139
139
/// The destination of the payment.
140
140
#[ serde( with = "serializers::serde_node_id" ) ]
141
141
pub destination : NodeId ,
142
+ /// The time in the simulation to start the payment
143
+ #[ serde( default ) ]
144
+ pub start_secs : u16 ,
145
+ /// The number of payments to send over the course of the simulation
146
+ #[ serde( default ) ]
147
+ pub count : Option < u64 > ,
142
148
/// The interval of the event, as in every how many seconds the payment is performed.
143
149
pub interval_secs : u16 ,
144
150
/// The amount of m_sat to used in this payment.
@@ -153,6 +159,10 @@ pub struct ActivityDefinition {
153
159
pub source : NodeInfo ,
154
160
/// The destination of the payment.
155
161
pub destination : NodeInfo ,
162
+ /// The time in the simulation to start the payment
163
+ pub start_secs : u16 ,
164
+ /// The number of payments to send over the course of the simulation
165
+ pub count : Option < u64 > ,
156
166
/// The interval of the event, as in every how many seconds the payment is performed.
157
167
pub interval_secs : u16 ,
158
168
/// The amount of m_sat to used in this payment.
@@ -261,6 +271,12 @@ pub trait DestinationGenerator: Send {
261
271
pub struct PaymentGenerationError ( String ) ;
262
272
263
273
pub trait PaymentGenerator : Display + Send {
274
+ /// Returns the time that the payments should start
275
+ fn payment_start ( & self ) -> Duration ;
276
+
277
+ /// Returns the number of payments that should be made
278
+ fn payment_count ( & self ) -> Option < u64 > ;
279
+
264
280
/// Returns the number of seconds that a node should wait until firing its next payment.
265
281
fn next_payment_wait ( & self ) -> time:: Duration ;
266
282
@@ -667,6 +683,8 @@ impl Simulation {
667
683
for description in self . activity . iter ( ) {
668
684
let activity_generator = DefinedPaymentActivity :: new (
669
685
description. destination . clone ( ) ,
686
+ Duration :: from_secs ( description. start_secs . into ( ) ) ,
687
+ description. count ,
670
688
Duration :: from_secs ( description. interval_secs . into ( ) ) ,
671
689
description. amount_msat ,
672
690
) ;
@@ -918,8 +936,21 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
918
936
sender : Sender < SimulationEvent > ,
919
937
listener : Listener ,
920
938
) -> Result < ( ) , SimulationError > {
939
+ let mut current_count = 0 ;
921
940
loop {
922
- let wait = node_generator. next_payment_wait ( ) ;
941
+ if let Some ( c) = node_generator. payment_count ( ) {
942
+ if c == current_count {
943
+ log:: info!( "Payment count has been met: {c} payments. Stopping the activity." ) ;
944
+ return Ok ( ( ) ) ;
945
+ }
946
+ }
947
+
948
+ let wait: Duration = if current_count == 0 {
949
+ node_generator. payment_start ( )
950
+ } else {
951
+ node_generator. next_payment_wait ( )
952
+ } ;
953
+
923
954
log:: debug!( "Next payment for {source} in {:?} seconds." , wait) ;
924
955
925
956
select ! {
@@ -956,6 +987,7 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
956
987
return Err ( SimulationError :: MpscChannelError ( format!( "Stopped random producer for {amount}: {source} -> {destination}." ) ) ) ;
957
988
}
958
989
990
+ current_count += 1 ;
959
991
} ,
960
992
}
961
993
}
0 commit comments