Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(script): use try_join_all in build_runners #7508

Merged
merged 1 commit into from
Mar 27, 2024
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
22 changes: 9 additions & 13 deletions crates/script/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use foundry_common::{
get_contract_name, provider::ethers::RpcUrl, shell, types::ToAlloy, ContractsByArtifact,
};
use foundry_evm::traces::render_trace_arena;
use futures::future::join_all;
use futures::future::{join_all, try_join_all};
use parking_lot::RwLock;
use std::{
collections::{BTreeMap, HashMap, VecDeque},
Expand Down Expand Up @@ -207,25 +207,21 @@ impl PreSimulationState {
}

/// Build [ScriptRunner] forking given RPC for each RPC used in the script.
async fn build_runners(&self) -> Result<HashMap<RpcUrl, ScriptRunner>> {
async fn build_runners(&self) -> Result<Vec<(RpcUrl, ScriptRunner)>> {
let rpcs = self.execution_artifacts.rpc_data.total_rpcs.clone();
if !shell::verbosity().is_silent() {
let n = rpcs.len();
let s = if n != 1 { "s" } else { "" };
println!("\n## Setting up {n} EVM{s}.");
}

let futs = rpcs
.into_iter()
.map(|rpc| async move {
let mut script_config = self.script_config.clone();
script_config.evm_opts.fork_url = Some(rpc.clone());
let runner = script_config.get_runner().await?;
Ok((rpc.clone(), runner))
})
.collect::<Vec<_>>();

join_all(futs).await.into_iter().collect()
let futs = rpcs.into_iter().map(|rpc| async move {
let mut script_config = self.script_config.clone();
script_config.evm_opts.fork_url = Some(rpc.clone());
let runner = script_config.get_runner().await?;
Ok((rpc.clone(), runner))
});
try_join_all(futs).await
}

/// If simulation is disabled, converts transactions into [TransactionWithMetadata] type
Expand Down
Loading