Commit 82b07d46 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: fix deploy utils

It is possible for the backend to prune the chain db which
will cause `waitForTransaction` to hang forever if the contract
was not recently deployed. Only check for the transaction if
it was recently deployed and instead add a safety check that
looks at the on chain code. It is unlikely to deploy a contract that
leaves no code in the state, so this is safe. The state cannot
be pruned so this will be a more reliable check to ensure that
the deployment is sane and exists. We do not use selfdestruct
so this is safe.
parent 9ae0a566
...@@ -54,10 +54,16 @@ export const deploy = async ({ ...@@ -54,10 +54,16 @@ export const deploy = async ({
waitConfirmations: hre.deployConfig.numDeployConfirmations, waitConfirmations: hre.deployConfig.numDeployConfirmations,
}) })
console.log(`Deployed ${name} at ${result.address}`) console.log(`Deployed ${name} at ${result.address}`)
// Only wait for the transaction if it was recently deployed in case the
// result was deployed a long time ago and was pruned from the backend.
await hre.ethers.provider.waitForTransaction(result.transactionHash)
} }
// Always wait for the transaction to be mined, just in case. // Check to make sure there is code
await hre.ethers.provider.waitForTransaction(result.transactionHash) const code = await hre.ethers.provider.getCode(result.address)
if (code === '0x') {
throw new Error(`no code for ${result.address}`)
}
// Create the contract object to return. // Create the contract object to return.
const created = asAdvancedContract({ const created = asAdvancedContract({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment