diff --git a/sim-lib/src/lib.rs b/sim-lib/src/lib.rs index fe1a36bf..35e38f9c 100644 --- a/sim-lib/src/lib.rs +++ b/sim-lib/src/lib.rs @@ -63,7 +63,7 @@ pub struct ClnConnection { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Config { pub nodes: Vec, - pub activity: Vec, + pub activity: Option>, } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] @@ -259,14 +259,14 @@ const DEFAULT_PRINT_BATCH_SIZE: u32 = 500; impl Simulation { pub fn new( nodes: HashMap>>, - activity: Vec, + activity: Option>, total_time: Option, print_batch_size: Option, ) -> Self { let (shutdown_trigger, shutdown_listener) = triggered::trigger(); Self { nodes, - activity, + activity: activity.unwrap_or_default(), shutdown_trigger, shutdown_listener, total_time: total_time.map(|x| Duration::from_secs(x as u64)), @@ -277,8 +277,19 @@ impl Simulation { } /// validate_activity validates that the user-provided activity description is achievable for the network that - /// we're working with. + /// we're working with. If no activity description is provided, then it ensures that we have configured a network + /// that is suitable for random activity generation. async fn validate_activity(&self) -> Result<(), LightningError> { + if self.activity.is_empty() { + return if self.nodes.len() <= 1 { + Err(LightningError::ValidationError( + "At least two nodes required for random activity generation.".to_string(), + )) + } else { + Ok(()) + }; + } + for payment_flow in self.activity.iter() { // We need every source node that is configured to execute some activity to be included in our set of // nodes so that we can execute events on it.