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

Cache does not contain all artifacts when multiple versions exist #1995

Open
0xalpharush opened this issue Dec 31, 2022 · 3 comments
Open

Cache does not contain all artifacts when multiple versions exist #1995

0xalpharush opened this issue Dec 31, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@0xalpharush
Copy link
Contributor

0xalpharush commented Dec 31, 2022

Version
This exists on master and can be reproduced on recent versions of foundry: forge 0.2.0 (848bb44 2022-12-28T00:13:43.163127Z).

Platform
Darwin macbook arm64

Description
In the following example, lib/forge-std/src/Test.sol is compiled using 0.8.10 and 0.8.17 and both artifacts are written to out/. However, if you run forge build && cat cache/solidity-files-cache.json | jq '.files["lib/forge-std/src/Test.sol"].artifacts' repeatedly it seems to cause unnecessary compilation due to the artifacts not being stored for multiple versions.

This issue seems related to these changes e.g. delete this snippet and forge build will include both artifacts. This doesn't totally address the issue because if forge build is run again the cache won't always include both artifacts or the names are inconsistent due to (#1491). There needs to be some notion that a file is not obsolete but is not currently being written either.

Fixing this should probably be unified with #1964 or done as a prerequisite.

I tried this code:

git clone https://github.com/ScopeLift/flexible-voting
cd flexible-voting
forge build

The artifacts exist

$ ls out/test.sol
DSTest.0.8.10.json      Test.0.8.10.json        TestBase.0.8.10.json
DSTest.0.8.17.json      Test.0.8.17.json        TestBase.0.8.17.json

But not all of them are cached

$ cat cache/solidity-files-cache.json | jq '.files["lib/forge-std/src/Test.sol"].artifacts'
{
  "Test": {
    "0.8.17+commit.8df45f5f.Darwin.appleclang": "Test.sol/Test.0.8.17.json"
  },
  "TestBase": {
    "0.8.17+commit.8df45f5f.Darwin.appleclang": "Test.sol/TestBase.0.8.17.json"
  }
}

If I run forge build again, it will contain the artifacts for0.8.10 but not 0.8.17 or vice versa.

I expected to see this happen:

{
  "Test": {
    "0.8.17+commit.8df45f5f.Darwin.appleclang": "Test.sol/Test.0.8.17.json",
     "0.8.10+commit.fc410830.Darwin.appleclang": "Test.sol/Test.json"

  },
  "TestBase": {
    "0.8.17+commit.8df45f5f.Darwin.appleclang": "Test.sol/TestBase.0.8.17.json",
     "0.8.10+commit.fc410830.Darwin.appleclang": "Test.sol/TestBase.json"

  }
}
@wbj-goldfinch
Copy link

wbj-goldfinch commented Feb 8, 2023

Hey @gakonst I'd be willing to take this. I working based off of @0xalpharush's #1964 that currently resolves this issue but in a hamfisted way that needs refinement. I'd be happy to keep working on this to get it into main 😄

@gakonst
Copy link
Owner

gakonst commented Feb 9, 2023

Yeah we'd love to get this over the line on top of @0xalpharush's work, and happy to help

@0xalpharush
Copy link
Contributor Author

0xalpharush commented Jul 16, 2024

@klkvr can this also be migrated to foundry-compilers. This more likely has been fixed but it may be helpful as a regression test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants