@@ -84,6 +84,10 @@ pub struct Cli {
84
84
/// Seed to run random activity generator deterministically
85
85
#[ clap( long, short) ]
86
86
pub fix_seed : Option < u64 > ,
87
+ /// A multiplier to wall time to speed up the simulation's clock. Only available when when running on a network of
88
+ /// simulated nodes.
89
+ #[ clap( long, short) ]
90
+ pub speedup_clock : Option < u16 > ,
87
91
}
88
92
89
93
impl Cli {
@@ -103,6 +107,12 @@ impl Cli {
103
107
nodes or sim_graph to run with simulated nodes"
104
108
) ) ;
105
109
}
110
+ if !sim_params. nodes . is_empty ( ) && self . speedup_clock . is_some ( ) {
111
+ return Err ( anyhow ! (
112
+ "Clock speedup is only allowed when running on a simulated network"
113
+ ) ) ;
114
+ }
115
+
106
116
Ok ( ( ) )
107
117
}
108
118
}
@@ -229,11 +239,13 @@ pub async fn create_simulation_with_network(
229
239
. map_err ( |e| SimulationError :: SimulatedNetworkError ( format ! ( "{:?}" , e) ) ) ?,
230
240
) ) ;
231
241
242
+ let clock = Arc :: new ( SimulationClock :: new ( cli. speedup_clock . unwrap_or ( 1 ) ) ?) ;
243
+
232
244
// Copy all simulated channels into a read-only routing graph, allowing to pathfind for
233
245
// individual payments without locking th simulation graph (this is a duplication of the channels,
234
246
// but the performance tradeoff is worthwhile for concurrent pathfinding).
235
247
let routing_graph = Arc :: new (
236
- populate_network_graph ( channels)
248
+ populate_network_graph ( channels, clock . clone ( ) )
237
249
. map_err ( |e| SimulationError :: SimulatedNetworkError ( format ! ( "{:?}" , e) ) ) ?,
238
250
) ;
239
251
@@ -246,7 +258,7 @@ pub async fn create_simulation_with_network(
246
258
cfg,
247
259
nodes,
248
260
tasks,
249
- Arc :: new ( SimulationClock :: new ( 1 ) ? ) ,
261
+ clock ,
250
262
shutdown_trigger,
251
263
shutdown_listener,
252
264
) ,
@@ -279,6 +291,8 @@ pub async fn create_simulation(
279
291
cfg,
280
292
clients,
281
293
tasks,
294
+ // When running on a real network, the underlying node may use wall time so we always use a clock with no
295
+ // speedup.
282
296
Arc :: new ( SimulationClock :: new ( 1 ) ?) ,
283
297
shutdown_trigger,
284
298
shutdown_listener,
0 commit comments