From 4f86d950e98d73b590a7dbf5225855c0bd0602cb Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 4 Nov 2024 09:46:25 +1100 Subject: [PATCH] Add error message for duration subtraction overflow in sim tests (#6558) * Add error message for duration subtraction overflow. --- testing/simulator/src/basic_sim.rs | 2 +- testing/simulator/src/fallback_sim.rs | 2 +- testing/simulator/src/local_network.rs | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/testing/simulator/src/basic_sim.rs b/testing/simulator/src/basic_sim.rs index e1cef95cd32..5c9baa2349b 100644 --- a/testing/simulator/src/basic_sim.rs +++ b/testing/simulator/src/basic_sim.rs @@ -206,7 +206,7 @@ pub fn run_basic_sim(matches: &ArgMatches) -> Result<(), String> { node.server.all_payloads_valid(); }); - let duration_to_genesis = network.duration_to_genesis().await; + let duration_to_genesis = network.duration_to_genesis().await?; println!("Duration to genesis: {}", duration_to_genesis.as_secs()); sleep(duration_to_genesis).await; diff --git a/testing/simulator/src/fallback_sim.rs b/testing/simulator/src/fallback_sim.rs index 3859257fb75..0690ab242c5 100644 --- a/testing/simulator/src/fallback_sim.rs +++ b/testing/simulator/src/fallback_sim.rs @@ -194,7 +194,7 @@ pub fn run_fallback_sim(matches: &ArgMatches) -> Result<(), String> { ); } - let duration_to_genesis = network.duration_to_genesis().await; + let duration_to_genesis = network.duration_to_genesis().await?; println!("Duration to genesis: {}", duration_to_genesis.as_secs()); sleep(duration_to_genesis).await; diff --git a/testing/simulator/src/local_network.rs b/testing/simulator/src/local_network.rs index 7b9327a7aaa..59efc09baa6 100644 --- a/testing/simulator/src/local_network.rs +++ b/testing/simulator/src/local_network.rs @@ -459,7 +459,7 @@ impl LocalNetwork { .map(|body| body.unwrap().data.finalized.epoch) } - pub async fn duration_to_genesis(&self) -> Duration { + pub async fn duration_to_genesis(&self) -> Result { let nodes = self.remote_nodes().expect("Failed to get remote nodes"); let bootnode = nodes.first().expect("Should contain bootnode"); let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); @@ -471,6 +471,9 @@ impl LocalNetwork { .data .genesis_time, ); - genesis_time - now + genesis_time.checked_sub(now).ok_or( + "The genesis time has already passed since all nodes started. The node startup time \ + may have regressed, and the current `GENESIS_DELAY` is no longer sufficient.", + ) } }