Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix(solc): invalid cached artifacts #783

Merged
merged 5 commits into from
Jan 11, 2022
Merged

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Jan 11, 2022

Motivation

foundry-rs/foundry#316

the way we checked if we need to recompile a contract was too optimistic and didn't check for their usage properly so in foundry-rs/foundry#316 we only recompiled the base contract and not the contract that inherits.
This was fixed but should be improved, generally the whole compile <-> cache pipeline is ripe for a v2 rewrite that uses the new dependency path.

I also discovered and fixed the issue that's likely related to #727, we used different keys for the into_artifacts iterator, while for cached artifacts we used <file>:<name> we only used the name for recompiled assets. but #727 needs an additional test as follow-up.

Solution

resolve all imports and check if they were changed.

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@mattsse mattsse changed the title fix(solc): invalid cached and missing artifacts fix(solc): invalid cached artifacts Jan 11, 2022
Comment on lines +144 to +145
let src = project
.add_source(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this technique makes test building so much easier

Comment on lines +873 to +875
T::contract_name(&path).map(|name| {
(format!("{}:{}", path.file_name().unwrap().to_string_lossy(), name), art)
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a bug here and you do to_string_lossy? I guess the issue would be that due to the {:?} the key becomes a quoted string, which ends up having a different key from {}:{}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this added quotes for the file path like \"file\":name

Comment on lines +878 to +888
let artifacts: Box<dyn Iterator<Item = (String, T::Artifact)>> = if let Some(output) =
self.compiler_output.take()
{
Box::new(artifacts.chain(T::output_to_artifacts(output).into_values().flatten().map(
|(name, artifact)| {
(format!("{}:{}", T::output_file_name(&name).display(), name), artifact)
},
)))
} else {
Box::new(artifacts)
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch

we used different keys for the into_artifacts iterator, while for cached artifacts we used : we only used the name for recompiled assets

Comment on lines +215 to +221
// ensure change is detected
assert!(!compiled.is_unchanged());
// and all recompiled artifacts are different
for (p, artifact) in compiled.into_artifacts() {
let other = artifacts.remove(&p).unwrap();
assert_ne!(artifact, other);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ethers-solc/src/cache.rs Show resolved Hide resolved
@gakonst gakonst merged commit 4d2cd83 into gakonst:master Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants