From 604019da218bf50acb51e280adabd68452c6133e Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Fri, 9 Feb 2024 16:47:45 -0500 Subject: [PATCH] multi: pass shutdown trigger into simulation To allow us to use a universal shutdown trigger, pass it into the simulation. --- Cargo.lock | 1 + sim-cli/Cargo.toml | 1 + sim-cli/src/main.rs | 2 ++ sim-lib/src/lib.rs | 6 +++--- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95199b79..639f722c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1697,6 +1697,7 @@ dependencies = [ "sim-lib", "simple_logger", "tokio", + "triggered", ] [[package]] diff --git a/sim-cli/Cargo.toml b/sim-cli/Cargo.toml index 67a6f41b..0dce023b 100644 --- a/sim-cli/Cargo.toml +++ b/sim-cli/Cargo.toml @@ -20,3 +20,4 @@ sim-lib = { path = "../sim-lib" } tokio = { version = "1.26.0", features = ["full"] } bitcoin = { version = "0.30.1" } ctrlc = "3.4.0" +triggered = "0.1.2" diff --git a/sim-cli/src/main.rs b/sim-cli/src/main.rs index 545a5104..a4c06771 100644 --- a/sim-cli/src/main.rs +++ b/sim-cli/src/main.rs @@ -199,6 +199,7 @@ async fn main() -> anyhow::Result<()> { None }; + let (shutdown_trigger, shutdown_listener) = triggered::trigger(); let sim = Simulation::new( clients, validated_activities, @@ -206,6 +207,7 @@ async fn main() -> anyhow::Result<()> { cli.expected_pmt_amt, cli.capacity_multiplier, write_results, + (shutdown_trigger, shutdown_listener), ); let sim2 = sim.clone(); diff --git a/sim-lib/src/lib.rs b/sim-lib/src/lib.rs index a64e8ba8..336a8dcb 100644 --- a/sim-lib/src/lib.rs +++ b/sim-lib/src/lib.rs @@ -368,13 +368,13 @@ impl Simulation { expected_payment_msat: u64, activity_multiplier: f64, write_results: Option, + shutdown: (Trigger, Listener), ) -> Self { - let (shutdown_trigger, shutdown_listener) = triggered::trigger(); Self { nodes, activity, - shutdown_trigger, - shutdown_listener, + shutdown_trigger: shutdown.0, + shutdown_listener: shutdown.1, total_time: total_time.map(|x| Duration::from_secs(x as u64)), expected_payment_msat, activity_multiplier,