Skip to content

Commit

Permalink
Add error message for duration subtraction overflow in sim tests (#6558)
Browse files Browse the repository at this point in the history
* Add error message for duration subtraction overflow.
  • Loading branch information
jimmygchen authored Nov 3, 2024
1 parent 16693b0 commit 4f86d95
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion testing/simulator/src/basic_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion testing/simulator/src/fallback_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions testing/simulator/src/local_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.",
)
}
}

0 comments on commit 4f86d95

Please sign in to comment.