Hey everyone,
I often have this error while deploying an upgradeable contract via Infura:
Invalid deployment with address 0x... and 0x...
Environment
hardhat 2.0.6:
@nomiclabs /hardhat-ethers 2.0.1
@openzeppelin /contracts-upgradeable@ 3.3.0
@openzeppelin /hardhat-upgrades 1.4.3
Details
The tx is actually sent and mined correctly but when the waitAndValidateDeployment
function of the @openzeppelin/upgrades-core
package checks the tx with getTransactionByHash
, the provider returns null
.
If I put an await sleep(5000)
before that, I don’t have problems, so I guess the infura node I’m hitting doesn’t know about that tx yet.
I guess in that while
loop we could retry N
times even in this case, but I’m asking because I’m not sure it would be the right place to do it.
Does this happen to someone else?
Code to reproduce
const myContract = await ethers.getContractFactory("MyContract", signer);
const proxy = await upgrades.deployProxy(myContract, [args]);
await proxy.deployed();
2 Likes
Hi @gravityblast ,
Welcome to the community
I am sorry that you are having this issue.
What network are you deploying to? Have you tried using a different provider (e.g. Alchemy: https://docs.openzeppelin.com/learn/connecting-to-public-test-networks )
I just tried OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat using Infura to Rinkeby with no issues.
$ npx hardhat run --network rinkeby scripts/deploy.js
Compiling 1 file with 0.7.3
Compilation finished successfully
Deploying Box...
Box deployed to: 0xfD1dafA50bC4362a792531285b047C14D75c5D5b
deploy.js
// scripts/deploy.js
async function main() {
const Box = await ethers.getContractFactory("Box");
console.log("Deploying Box...");
const box = await upgrades.deployProxy(Box, [42], { initializer: 'store' });
console.log("Box deployed to:", box.address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
1 Like
thank you @abcoathup ! It’s both with kovan and mainnet.
Yes with alchemy it seems to always work, but with infura it’s always the same so I was wondering if that change could be good to manage this problem.
If that makes sense I could open a PR.
2 Likes
HI @gravityblast ,
After a few tries I managed to reproduce on Kovan using Infura.
I’ll check with the development team what would be the best work around.
Cleanup
$ rm -rf artifacts/
$ rm -rf .openzeppelin/
Deploy
$ npx hardhat run --network kovan scripts/deploy.js
Compiling 1 file with 0.7.3
Compilation finished successfully
Deploying Box...
{ Error: Invalid deployment with address 0x03EB1e2956AA03a086a3511BCDaeFAcB1e438086 and txHash 0x0d18b824ea4137fce5386fb50307732987d39bdd870ecf0e836f5012be22d512
at Object.waitAndValidateDeployment (/home/abcoathup/projects/forum/gravityblast/node_modules/@openzeppelin/upgrades-core/src/deployment.ts:66:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
deployment:
{ address: '0x03EB1e2956AA03a086a3511BCDaeFAcB1e438086',
txHash:
'0x0d18b824ea4137fce5386fb50307732987d39bdd870ecf0e836f5012be22d512',
layout: { storage: [Array], types: [Object] } } }
2 Likes
frangio
January 13, 2021, 10:28pm
5
Hi @gravityblast .
Yes, this is very likely the reason.
I think we can safely remove the exception we raise, and continue retrying until we see something or time out.
If you would like to provide a PR, if I'm not mistaken we have to replace the following
with something like
if (tx === null) {
continue;
}
3 Likes
frangio
January 14, 2021, 11:28pm
6
3 Likes
great!! thank you @frangio !
1 Like
HI @frangio & @gravityblast ,
It looks resolved; I haven’t been able to reproduce since upgrading to the latest version.
1 Like