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

perf: don't clone artifacts when building multi runner #7116

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn print_storage(layout: StorageLayout, values: Vec<StorageValue>, pretty: bool)
storage_type.map_or("?", |t| &t.label),
&slot.slot,
&slot.offset.to_string(),
&storage_type.map_or("?", |t| &t.number_of_bytes),
storage_type.map_or("?", |t| &t.number_of_bytes),
&converted_value.to_string(),
&value.to_string(),
&slot.contract,
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn print_storage_layout(storage_layout: Option<&StorageLayout>, pretty: bool
storage_type.map_or("?", |t| &t.label),
&slot.slot,
&slot.offset.to_string(),
&storage_type.map_or("?", |t| &t.number_of_bytes),
storage_type.map_or("?", |t| &t.number_of_bytes),
&slot.contract,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ mod tests {

// <https://github.com/foundry-rs/foundry/issues/5913>
#[test]
fn issue_5913() {
fn fuzz_seed_exists() {
let args: TestArgs =
TestArgs::parse_from(["foundry-cli", "-vvv", "--gas-report", "--fuzz-seed", "0x10"]);
assert!(args.fuzz_seed.is_some());
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Linker {
/// Root of the project, used to determine whether artifact/library path can be stripped.
pub root: PathBuf,
/// Compilation artifacts.
contracts: ArtifactContracts,
pub contracts: ArtifactContracts,
}

/// Output of the `link_with_nonce_or_address`
Expand Down
18 changes: 8 additions & 10 deletions crates/forge/src/multi_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use alloy_primitives::{Address, Bytes, U256};
use eyre::{OptionExt, Result};
use foundry_common::{ContractsByArtifact, TestFunctionExt};
use foundry_compilers::{
artifacts::CompactContractBytecode, Artifact, ArtifactId, ArtifactOutput, ProjectCompileOutput,
contracts::ArtifactContracts, Artifact, ArtifactId, ArtifactOutput, ProjectCompileOutput,
};
use foundry_evm::{
backend::Backend,
Expand Down Expand Up @@ -267,31 +267,29 @@ impl MultiContractRunnerBuilder {
{
let output = output.with_stripped_file_prefixes(&root);
// This is just the contracts compiled, but we need to merge this with the read cached
// artifacts
// artifacts.
let contracts = output
.into_artifacts()
.map(|(i, c)| (i, c.into_contract_bytecode()))
.collect::<Vec<(ArtifactId, CompactContractBytecode)>>();
.collect::<ArtifactContracts>();

let mut known_contracts = ContractsByArtifact::default();
let source_paths = contracts
.iter()
.map(|(i, _)| (i.identifier(), root.as_ref().join(&i.source).to_string_lossy().into()))
.collect::<BTreeMap<String, String>>();
// create a mapping of name => (abi, deployment code, Vec<library deployment code>)
let mut deployable_contracts = DeployableContracts::default();

let artifact_contracts = contracts.iter().cloned().collect();

let linker = Linker::new(root.as_ref(), artifact_contracts);
let linker = Linker::new(root.as_ref(), contracts);

for (id, contract) in contracts {
let mut known_contracts = ContractsByArtifact::default();
for (id, contract) in &linker.contracts.0 {
let abi = contract.abi.as_ref().ok_or_eyre("we should have an abi by now")?;

let LinkOutput { libs_to_deploy, libraries } =
linker.link_with_nonce_or_address(Default::default(), evm_opts.sender, 1, &id)?;
linker.link_with_nonce_or_address(Default::default(), evm_opts.sender, 1, id)?;

let linked_contract = linker.link(&id, &libraries)?;
let linked_contract = linker.link(id, &libraries)?;

// get bytes if deployable, else add to known contracts and continue.
// interfaces and abstract contracts should be known to enable fuzzing of their ABI
Expand Down
Loading