From 45c4d95b67fb276740e148ff0733a40cfa94889f Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Mon, 25 Sep 2023 13:28:19 -0400 Subject: [PATCH] multi: allow empty activity description and validate random activity Allow parsing of empty activity descriptions to facilitate default run with random activity generation. We still use a vector in the Simulation struct to allow a path where we have a combination of random and specific activity. This commit also adds validation that we have at least two nodes when running random activity. This is required because destination nodes are chosen from within the nodes that we have execution on (to prevent liquidity draining and eventual death spirals). --- sim-lib/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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.