Add error message for duration subtraction overflow in sim tests (#6558)

* Add error message for duration subtraction overflow.
This commit is contained in:
Jimmy Chen
2024-11-04 09:46:25 +11:00
committed by GitHub
parent 16693b0bd7
commit 4f86d950e9
3 changed files with 7 additions and 4 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -459,7 +459,7 @@ impl<E: EthSpec> LocalNetwork<E> {
.map(|body| body.unwrap().data.finalized.epoch)
}
pub async fn duration_to_genesis(&self) -> Duration {
pub async fn duration_to_genesis(&self) -> Result<Duration, &'static str> {
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<E: EthSpec> LocalNetwork<E> {
.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.",
)
}
}