Skip to content

Commit

Permalink
Build cache for implementations (#42)
Browse files Browse the repository at this point in the history
* added build cache for implementations

* fmt + clippy

* updated readme

---------

Co-authored-by: Stefan Effenberger <[email protected]>
  • Loading branch information
stiefn and Stefan Effenberger authored Sep 5, 2024
1 parent e8480c4 commit b0d9fac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ If the Hardhat project does not store its compilation artifacts in the default d
dv init --project <PROJECT_PATH> --address <ADDRESS> --contractname <NAME> --implementation <IMPL_NAME> --implementationproject <IMPL_PROJECT_PATH> --implementationenv hardhat --implementationartifacts <IMPL_ARTIFACTS> new.dvf.json
```

If you have to use an external build-info (i.e., you don't want `dv` to build the implementation project), you can specify the path to the implementation project's build-info directory with `--implementationbuildcache`:

```
dv init --project <PROJECT_PATH> --address <ADDRESS> --contractname <NAME> --implementation <IMPL_NAME> --implementationproject <IMPL_PROJECT_PATH> --implementationbuildcache <IMPL_BUILD_CACHE> new.dvf.json
```

Please note that this does not validate the implementation contract itself. If there are any security risks associated with the implementation contracts, you should create another DVF for it and then create a reference (see [References](#references)) from the original DVF to the implementation contract's DVF.

### Factories
Expand Down
20 changes: 16 additions & 4 deletions src/dvf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,13 @@ fn main() {
.arg(
Arg::with_name("buildcache")
.long("buildcache")
.help("Folder containing buildcache previously. Use with care")
.help("Folder containing build-info files")
.action(ArgAction::Set)
)
.arg(
Arg::with_name("implementationbuildcache")
.long("implementationbuildcache")
.help("Folder containing build-info files of the implementation contract")
.action(ArgAction::Set)
)
.arg(
Expand Down Expand Up @@ -627,7 +633,7 @@ fn main() {
.arg(
Arg::with_name("buildcache")
.long("buildcache")
.help("Folder containing buildcache previously. Use with care")
.help("Folder containing build-info files")
.action(ArgAction::Set)
)
)
Expand Down Expand Up @@ -740,6 +746,7 @@ fn process(matches: ArgMatches) -> Result<(), ValidationError> {

let mut imp_env = *sub_m.get_one::<Environment>("implementationenv").unwrap();
let imp_project = sub_m.value_of("implementationproject");
let mut imp_build_cache = sub_m.value_of("implementationbuildcache");
let imp_artifacts = sub_m.value_of("implementationartifacts").unwrap();
let imp_path: PathBuf;
let imp_artifacts_path: PathBuf;
Expand All @@ -748,6 +755,7 @@ fn process(matches: ArgMatches) -> Result<(), ValidationError> {
} else {
imp_path = path.clone();
imp_artifacts_path = artifacts_path.clone();
imp_build_cache = build_cache;
imp_env = env
}

Expand Down Expand Up @@ -800,7 +808,11 @@ fn process(matches: ArgMatches) -> Result<(), ValidationError> {
let init_code = web3::get_init_code(&config, &dumped.deployment_tx, &dumped.address)?;

debug!("Fetching forge output");
print_progress("Compiling local code.", &mut pc, &progress_mode);
let compile_output = match build_cache {
None => "Compiling local code.",
Some(_) => "Loading build cache.",
};
print_progress(compile_output, &mut pc, &progress_mode);
let mut project_info = ProjectInfo::new(
&dumped.contract_name,
&path,
Expand Down Expand Up @@ -889,7 +901,7 @@ fn process(matches: ArgMatches) -> Result<(), ValidationError> {
&imp_path,
imp_env,
&imp_artifacts_path,
None,
imp_build_cache,
)?;

print_progress(
Expand Down

0 comments on commit b0d9fac

Please sign in to comment.