Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion crates/cli/src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloy::{
consensus::TxType,
network::AnyNetwork,
primitives::utils::{format_ether, parse_ether},
providers::{DynProvider, ProviderBuilder},
providers::{DynProvider, Provider, ProviderBuilder},
signers::local::PrivateKeySigner,
transports::http::reqwest::Url,
};
Expand Down Expand Up @@ -156,6 +156,38 @@ pub async fn setup(
.into());
}

// derive block time from last two blocks. if two blocks don't exist, assume block time is 1s
let block_num = rpc_client
.get_block_number()
.await
.map_err(|e| ContenderError::with_err(e, "failed to get block number"))?;

let block_time_secs = if block_num > 0 {
let mut timestamps = vec![];
for i in [0_u64, 1] {
let block = rpc_client
.get_block_by_number((block_num - i).into())
.await
.map_err(|e| ContenderError::with_err(e, "failed to get block"))?;
if let Some(block) = block {
timestamps.push(block.header.timestamp);
}
}
if timestamps.len() == 2 {
(timestamps[0] - timestamps[1]).max(1)
} else {
1
}
} else {
1
};

let timekeeper_handle = tokio::spawn(async move {
let timeout_blocks = 10;
let safe_time = (testconfig.create.iter().len() + timeout_blocks) as u64 * block_time_secs;
tokio::time::sleep(Duration::from_secs(safe_time)).await;
println!("Contract deployment has been waiting for more than {timeout_blocks} blocks... Press Ctrl+C to cancel.");
});
let done = AtomicBool::new(false);
let is_done = Arc::new(done);

Expand All @@ -181,6 +213,7 @@ pub async fn setup(
}

scenario.deploy_contracts().await?;
timekeeper_handle.abort();
println!("Finished deploying contracts. Running setup txs...");
scenario.run_setup().await?;
println!("Setup complete. To run the scenario, use the `spam` command.");
Expand Down
Loading