Background
We are using keep-network/keep-core dependency in several projects:
The keep-network/keep-core package contains a KEEP-related contract called TokenStaking which is the same name that we use for staking contract for T token. We wanted to deploy both contracts in the same deployments, so we hit a contract name conflict (see issue wighawag/hardhat-deploy#241). That's why we created a prepare-dependencies.sh script that gets executed as a last step of installation of threshold-network/solidity-contracts project and renames the keep-core's TokenStaking artifact to KeepTokenStaking.
The issue(s)
The script is used as a postinstall script and uses the INIT_CWD variable as a parameter:
|
"postinstall": "./scripts/prepare-dependencies.sh $INIT_CWD", |
The INIT_CWD isn't set by us, it's a variable created by Yarn that should hold the full path of the localization where
yarn run/
yarn install was executed from. Unfortunately, sometimes it does not get configured correctly (it happens seemingly randomly) and causes the failures of the script.
Another issue is that in the script we're copying the files from the following location:
|
SOURCE_DIR="$ROOT_DIR/node_modules/@keep-network/keep-core/artifacts" |
This location sometimes may not be available - this is due to the fact that Yarn flattens the structure of dependencies. For example, when
threshold-network/solidity-contracts is a dependency of some project, Yarn may not include
@keep-network/keep-core in
threshold-network/solidity-contracts's
node_modules if
@keep-network/keep-core is already included in
node_modules of another dependency.
Examples:
https://github.com/keep-network/tbtc-v2/actions/runs/4969553945/jobs/8912960954:
error /home/runner/work/tbtc-v2/tbtc-v2/solidity/node_modules/@threshold-network/solidity-contracts: Command failed.
Exit code: 1
Command: ./scripts/prepare-dependencies.sh $INIT_CWD
Arguments:
Directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity/node_modules/@threshold-network/solidity-contracts
Output:
Preparing dependencies artifacts
Root directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity
Source directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity/node_modules/@keep-network/keep-core/artifacts
Destination directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core
mv: cannot stat '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TokenStaking.json': No such file or directory
https://github.com/keep-network/tbtc-v2/actions/runs/4969553945/jobs/8892795133
error /home/runner/work/tbtc-v2/tbtc-v2/solidity/node_modules/@keep-network/ecdsa/node_modules/@keep-network/random-beacon/node_modules/@threshold-network/solidity-contracts: Command failed.
Exit code: 1
Command: ./scripts/prepare-dependencies.sh $INIT_CWD
Arguments:
Directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity/node_modules/@keep-network/ecdsa/node_modules/@keep-network/random-beacon/node_modules/@threshold-network/solidity-contracts
Output:
Preparing dependencies artifacts
Root directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity
Source directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity/node_modules/@keep-network/keep-core/artifacts
Destination directory: /home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestArrayUtils.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestCurveRewards.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestModUtils.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestSimpleBeneficiary.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestSimpleReceiver.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestSimpleStakerRewards.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TestToken.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TokenDistributor.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TokenGeyser.json': File exists
cp: cannot create regular file '/home/runner/work/tbtc-v2/tbtc-v2/solidity/external/npm/@keep-network/keep-core/artifacts/TokenGrant.json': File exists
https://github.com/keep-network/keep-core/actions/runs/4969527266/jobs/8892744375:
error /home/runner/work/keep-core/keep-core/solidity/ecdsa/node_modules/@keep-network/random-beacon/node_modules/@threshold-network/solidity-contracts: Command failed.
Exit code: 1
Command: ./scripts/prepare-dependencies.sh $INIT_CWD
Arguments:
Directory: /home/runner/work/keep-core/keep-core/solidity/ecdsa/node_modules/@keep-network/random-beacon/node_modules/@threshold-network/solidity-contracts
Output:
Preparing dependencies artifacts
Root directory: /home/runner/work/keep-core/keep-core/solidity/ecdsa
Source directory: /home/runner/work/keep-core/keep-core/solidity/ecdsa/node_modules/@keep-network/keep-core/artifacts
Destination directory: /home/runner/work/keep-core/keep-core/solidity/ecdsa/external/npm/@keep-network/keep-core
cp: cannot create directory '/home/runner/work/keep-core/keep-core/solidity/ecdsa/external/npm/@keep-network/keep-core/artifacts': File exists
Solutions
There are several approaches we could take to tackle this:
- Try to fix each problem directly (change the script to not rely on the INIT_CWD variable, figure out how to work with flattened
node_modules structure)
- Try to get rid of the problem with the name conflict by publishing new NPM packages with
keep-core contracts that would be the exact copies of the current ones that are in use, with the only difference being the name of the TokenStaking contract (it could be renamed to KeepTokenStaking). This way we would no longer have a name conflict and could get rid of the prepare-dependencies.sh script.
- Deal with all those dependencies by just hardcoding ABI and addresses. v1
TokenStaking or KeepToken addresses are not going to change. This may be even quicker time-wise than figuring out what is happening with environment variables. And we'll make build times shorter. Double win.
Background
We are using
keep-network/keep-coredependency in several projects:solidity-contractstoken-dashboardcoverage-poolsThe
keep-network/keep-corepackage contains a KEEP-related contract calledTokenStakingwhich is the same name that we use for staking contract for T token. We wanted to deploy both contracts in the same deployments, so we hit a contract name conflict (see issue wighawag/hardhat-deploy#241). That's why we created aprepare-dependencies.shscript that gets executed as a last step of installation ofthreshold-network/solidity-contractsproject and renames thekeep-core'sTokenStakingartifact toKeepTokenStaking.The issue(s)
The script is used as a
postinstallscript and uses theINIT_CWDvariable as a parameter:solidity-contracts/package.json
Line 29 in f468a7d
The INIT_CWD isn't set by us, it's a variable created by Yarn that should hold the full path of the localization where
yarn run/yarn installwas executed from. Unfortunately, sometimes it does not get configured correctly (it happens seemingly randomly) and causes the failures of the script.Another issue is that in the script we're copying the files from the following location:
solidity-contracts/scripts/prepare-dependencies.sh
Line 20 in f468a7d
This location sometimes may not be available - this is due to the fact that Yarn flattens the structure of dependencies. For example, when
threshold-network/solidity-contractsis a dependency of some project, Yarn may not include@keep-network/keep-coreinthreshold-network/solidity-contracts'snode_modulesif@keep-network/keep-coreis already included innode_modulesof another dependency.Examples:
https://github.com/keep-network/tbtc-v2/actions/runs/4969553945/jobs/8912960954:
https://github.com/keep-network/tbtc-v2/actions/runs/4969553945/jobs/8892795133
https://github.com/keep-network/keep-core/actions/runs/4969527266/jobs/8892744375:
Solutions
There are several approaches we could take to tackle this:
node_modulesstructure)keep-corecontracts that would be the exact copies of the current ones that are in use, with the only difference being the name of the TokenStaking contract (it could be renamed to KeepTokenStaking). This way we would no longer have a name conflict and could get rid of the prepare-dependencies.sh script.TokenStakingorKeepTokenaddresses are not going to change. This may be even quicker time-wise than figuring out what is happening with environment variables. And we'll make build times shorter. Double win.