Partial Deploy For Upgradeable Contract

Hey!

I deployed an OZ ERC1155 upgradeable contract using Truffle. The Migration and ERC1155 contracts deployed successfully, but the last two (ProxyAdmin and I can’t remember the other one…) didn’t deploy due to insufficient funds. Can I recover this process to avoid re-deploying the ERC1155 contract? It was quite expensive. Re-running truffle migrate shows that it is attempting to re-deploy the ERC1155 contract.

If there’s any other helpful information I can provide please let me know!

Here are some versions of things if it helps (I started out using hardhat for testing and deployments but ended up switching to truffle in the end):

"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-truffle5": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/contracts-upgradeable": "^3.3.0",
"@openzeppelin/hardhat-upgrades": "^1.4.3",
"@openzeppelin/test-environment": "^0.1.9",
"@openzeppelin/test-helpers": "^0.5.10",
"@openzeppelin/truffle-upgrades": "^1.4.0",
"@truffle/hdwallet-provider": "^1.2.1",
"chai": "^4.2.0",
"dotenv": "^8.2.0",
"ethereum-waffle": "^3.2.1",
"ethers": "^5.0.25",
"hardhat": "^2.0.7",
"web3": "^1.3.1"

Thanks in advance! I’m still relatively new to all of this but you guys have done an awesome job with the documentation, walkthroughs, and making it easy to get started.

1 Like

Hi @devdev,

Welcome to the community :wave:

OpenZeppelin Upgrades Plugin should detect the partial deployment and deploy the remaining contracts.

The following contracts need to be deployed:

  1. Implementation contract
  2. ProxyAdmin
  3. proxy

Using Truffle there is also a Migrations contract to be deployed.

I have created an issue to document the retry/continue behavior: https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/284

Hi @abcoathup,

Thank you! That will be very helpful.

I was able to figure some things out and I shared the details below. For right now, is there any way I can run the migration script and get debug output from proxyDeploy?

I did some digging today and found the JSON files that contain the migration/deployment data to keep track of the state of things. In my case the important files are:

  • build/contracts/Migrations.json (contains an entry for each network with the txn hash and address)
  • build/contracts/ERC1155PresetMinterPauserUpgradeable.json (contains an entry for each network with events of some kind and the txn hash and address)
  • .openzeppelin/mainnet.json (contains an entry for the implementation contract describing the layout)

So the ERC1155Preset contract is the implementation one and the Migration one is from truffle. Those two have already been successfully deployed to mainnet but proxyDeploy is attempting to redeploy the implementation contract.

Based on other successful deployments to Ropsten, I see that I’m missing the JSON mainnet network entry in ERC1155PresetMinterPauserUpgradeable.json and the “admin” JSON entry in .openzeppelin/mainnet.json.

I used a local test network and was able to reproduce the exact same state of my mainnet deployment. The JSON entries between the test network and mainnet all match up in those files listed above (except hashes and addresses). What’s interesting is that the test network does not try to redeploy the ERC1155 contract but the mainnet deployment process does. I can’t see any difference between the migration state of the two deployments. I’m actually going to try reproducing it on Ropsten because that will be more realistic. If the results differ I’ll post back here.

1 Like

Hi @devdev,

The implementation address and the ProxyAdmin address should be found in openzeppelin/mainnet; See: https://docs.openzeppelin.com/upgrades-plugins/1.x/network-files

OpenZeppelin Upgrades Plugins should only deploy the implementation contract once.

You’re right!

What was concerning me is that the dry-run was saying it needs to redeploy the implementation contract and factored that into the check for sufficient funds. But when it actually got to the deploy phase it skipped deploying the implementation contract which was good.

It successfully deployed the ProxyAdmin contract but then it threw an error with this message Error: Invalid deployment and stopped the deployment process. It’s trying to redeploy the ProxyAdmin contract again.

1 Like

Could you check in your package-lock.json what version of @openzeppelin/upgrades-core you have? The Invalid deployment error may be the same error we fixed in the latest release of the core (1.4.4), and it was caused in some cases when deploying against Infura.

If your .openzeppelin/mainnet.json file does not contain the admin and it was deployed successfully, you can fill it in manually. It should look like the following:

{
  ...
  "admin": {
    "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
    "txHash": "0xa75f2c81e45bfb92e0e15049dd38f3881a4316715b41e0451783d58ddef5a83c"
  }
}

Sorry for the inconvenience!

1 Like

Hi @frangio,

EDIT (quick question):
Is there any way I can run the migration and have it skip the sufficient funds check? It’s still factoring in the implementation contract cost into the total but all that I have left to deploy is the final Proxy contract which is very small. And I have more than enough funds to cover that. I tried using --skip-dry-run but it still errors out saying insufficient funds.


No worries, I appreciate the help!

I don’t see package-lock.json but I do see package.json and this is what’s in there:

{
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.1",
    "@nomiclabs/hardhat-truffle5": "^2.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.1",
    "@nomiclabs/hardhat-web3": "^2.0.0",
    "@openzeppelin/contracts-upgradeable": "^3.3.0",
    "@openzeppelin/hardhat-upgrades": "^1.4.3",
    "@openzeppelin/test-environment": "^0.1.9",
    "@openzeppelin/test-helpers": "^0.5.10",
    "@openzeppelin/truffle-upgrades": "^1.4.0",
    "@truffle/hdwallet-provider": "^1.2.1",
    "chai": "^4.2.0",
    "dotenv": "^8.2.0",
    "ethereum-waffle": "^3.2.1",
    "ethers": "^5.0.25",
    "hardhat": "^2.0.7",
    "web3": "^1.3.1"
  }
}

I don’t see @openzeppelin/upgrades-core, could it be any of those above or is there something I’m missing? I just started working with OZ contracts about a week ago, when was 1.4.4 released?

I am actually deploying against Infura for both Ropsten and mainnet but the Ropsten tests all worked successfully. But it also seems that mainnet is an entirely different beast.

I’ll add that admin entry in and give it a try and let you know how it goes.

1 Like

Hi @devdev,

I am not sure where the sufficient funds check is done, I assume in Truffle but I didn’t see any option to disable.

Upgrades Core 1.4.4 was released 3 days ago: https://github.com/OpenZeppelin/openzeppelin-upgrades/releases/tag/%40openzeppelin%2Fupgrades-core%401.4.4

You should be able to get the latest version of Upgrades Core using:

npm install @openzeppelin/truffle-upgrades@latest

So I was at the point where 3/4 of the contracts had been deployed: Migration contract, implementation contract, and the ProxyAdmin contract. So the only remaining one is the AdminUpgradeabilityProxy. I finally got that one deployed but as soon as the transaction completed I received this error message:

Starting migrations...
======================
> Network name:    'mainnet'
> Network id:      1
> Block gas limit: 12493846 (0xbea416)


2_truffle_deploy_my_token.js
============================

Warning: Potentially unsafe deployment of ERC1155PresetMinterPauserUpgradeable

    You are using the `unsafeAllowCustomTypes` flag to skip storage checks for structs and enums.
    Make sure you have manually checked the storage layout for incompatibilities.


   Deploying 'AdminUpgradeabilityProxy'
   ------------------------------------
   > transaction hash:    [txn_hash]
   > Blocks: 5            Seconds: 92
   > contract address:    [contract_addr]
   > block number:        11688332
   > block timestamp:     1611093467
   > account:             [account_address]
   > balance:             0.395879715752187639
   > gas used:            966898 (0xec0f2)
   > gas price:           60 gwei
   > value sent:          0 ETH
   > total cost:          0.05801388 ETH


   ⠼ Saving migration to chain.

insufficient funds for gas * price + value
Truffle v5.1.62 (core: 5.1.62)
Node v15.5.1
npm ERR! code 1

I didn’t think there was anything left to do after this one was deployed so I’m not sure why I received the insufficient funds error. Is there anything I’m missing or is that all that was left to do?

I noticed that in build/contracts/ERC1155PresetMinterPauserUpgradeable.json there were network entries in there to save the address of the main Proxy contract and some “events”, but mainnet didn’t have an entry. I saw that the local test network and Ropsten had the same JSON data except for their contract addresses so I manually added a mainnet entry with the address from the recently deployed AdminUpgradeabilityProxy. When I run the truffle console it correctly parses the mainnet Proxy address but I can’t initialize the contract or make any calls. They all throw an insufficient funds error.

Any thoughts or advice? I’m going to keep troubleshooting tonight so if I figure something out I’ll post back here.

1 Like

Hi @devdev,

Did the transaction deploying the proxy complete, you can check on Etherscan.

When using Truffle, there will also be a transaction to update the Migrations contract to track that the migration (number) has completed.

If you can interact with your token contract using the ABI of the implementation and the address of the proxy then your upgradeable contract is deployed.

Upgrades Plugins updates the Truffle contract artifact with the address of the proxy. This may not have happened, so you may need to do this manually if you want to use MyContract.deployed().