OpenZeppelin / openzeppelin-upgrades

Plugins for Hardhat and Foundry to deploy and manage upgradeable contracts on Ethereum.
MIT License
611 stars 261 forks source link

Add support for Truffle dry run fork #241

Open abcoathup opened 3 years ago

abcoathup commented 3 years ago

Truffle has a dry run option on migration that forks the network to check the migration.

When deploying a contract with dry run skipped, and then attempting to do an upgrade with dry run, the upgrade fails with:

Error: Proxy admin is not the one registered in the network manifest
    at upgradeProxy

Using Box.sol and BoxV2.sol from https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-truffle/3579 and the deploy and upgrade migrations below:

2_deploy_box.js

// migrations/2_deploy_box.js
const Box = artifacts.require('Box');

const { deployProxy } = require('@openzeppelin/truffle-upgrades');

module.exports = async function (deployer) {
  await deployProxy(Box, [42], { deployer, initializer: 'store' });
};

3_upgrade_box.js

// migrations/3_upgrade_box.js
const Box = artifacts.require('Box');
const BoxV2 = artifacts.require('BoxV2');

const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');

module.exports = async function (deployer) {
  const box = await Box.deployed();
  await upgradeProxy(box.address, BoxV2, { deployer });
};
$ npx truffle migrate --network rinkeby --to 2 --skip-dry-run
...
Starting migrations...
======================
> Network name:    'rinkeby'
> Network id:      4
> Block gas limit: 10000000 (0x989680)

1_initial_migration.js
...
2_deploy_box.js
===============

   Deploying 'Box'
   ---------------
   > transaction hash:    0x55fe331e1997c5ee4233fb9db21eb63bb12c0d9aac02ba21750cca487364e903
   > Blocks: 2            Seconds: 21
   > contract address:    0xE1a1b97E43362F8FE6F08Bc3A6EC250C35146E0F
...
   Deploying 'ProxyAdmin'
   ----------------------
   > transaction hash:    0x725e4486c35d4b6c812513a5705e9c04ea3b0ed19ebb6cedd443dc5c371709c6
   > Blocks: 1            Seconds: 17
   > contract address:    0xe34E320E784D56728aC0247005De168bdDA17beE
...
   Deploying 'AdminUpgradeabilityProxy'
   ------------------------------------
   > transaction hash:    0xc1210bfcb6381dd24ac590b3e93820ba49700207affcb6cea0550eb94318698a
   > Blocks: 1            Seconds: 17
   > contract address:    0xe2e88690f2F3CAC2534412AaA5C93e8b6368Ad98
...
$ npx truffle migrate --network rinkeby

Compiling your contracts...
===========================
...

Migrations dry-run (simulation)
===============================
> Network name:    'rinkeby-fork'
> Network id:      4
> Block gas limit: 10000000 (0x989680)

3_upgrade_box.js
================

Error: Proxy admin is not the one registered in the network manifest
    at upgradeProxy (/home/abcoathup/projects/forum/truffledryrun/node_modules/@openzeppelin/truffle-upgrades/src/upgrade-proxy.ts:76:11)
Truffle v5.1.54 (core: 5.1.54)
Node v10.22.1
0xByteLeon commented 2 years ago

Any update? I also face this issue

frangio commented 2 years ago

We need someone to help us understand what the dry run does exactly and what is going wrong that it breaks the Upgrades Plugin.

In the meantime, please use --skip-dry-run.

NeoXtreem commented 2 years ago

This has just cost me a considerable amount of time to figure out where the problem was (see here). When will this be fixed?

hodlbe commented 2 years ago

We need someone to help us understand what the dry run does exactly and what is going wrong that it breaks the Upgrades Plugin.

In the meantime, please use --skip-dry-run.

What to do if the chain.js file in the .openzeppelin directory has been deleted??? Using hardhat.

Error: Proxy admin is not the one registered in the network manifest

webgurucan commented 2 years ago

@NeoXtreem @0xByteLeon I have same issues, but I solved the issue. At your project root directory, you can find .openzeppelin directory. There should be the files that contains proxy addresses for the smart contracts you deployed. In case that file is old (not latest) or missed, then you will get that error message.

In my case, that file is old one which is overwritten by git pull. So I restored the latest unknown-43113.json file at .openzeppelin. (I deployed to fuji Avalanche testnet). It solved the problem.

treygrainger commented 2 years ago

@frangio I burned some time on this issue as well. You asked for someone to help you "understand what the dry run does exactly and what is going wrong that it breaks the Upgrades Plugin".

Here's what appears to be going on to me:

Let's say I want to deploy to mainnet. when I run truffle migrate, it forks mainnet and creates a .openzeppelin/unknown_1337.json . It then saves the dry-run information (impls, admin, etc.) in there.

Then, once the dry-run is finished, it creates the .openzeppelin/mainnet.json, and the same values get placed in there after the mainnet migration is complete.


So the issue becomes that general instructions are to commit the mainnet.json (and testnet) network files, but to NOT commit the unknown_*.json files.

The issue comes later, the next time someone wants to do a mainnet deploy. Say someone clones the git repository - they now have the mainnet.json, but NOT the unknown_*.json file. Thus when the fork is made for the dry-run, the network file used before for the dry run during the initial deployment (with the admin and impls) is not there, so the upgrades plugin is throwing the "Error: Proxy admin is not the one registered in the network manifest at upgradeProxy" error.

After figuring this out, I was able to just copy my mainnet.json to unknown_1337.json and rerun the dry-run and everything worked.

It might be cleaner to implement the dry-run plugin to use a temporary network file (like mainnet_dry-run.json) instead, and if it doesn't exist to just copy the mainnet.json if it exists into that file before the dry-run.

Hope this helps. Seems plenty of people have burned considerable time on this issue due to lack of clarity about what's going on under the covers. In my case, I didn't feel comfortable pushing out to mainnet until the dry-run had completed successfully, so took the time to figure out.

Shout out to @webgurucan, whose comment above led me down this path.


*Note for anyone looking for a workaround for this:

  1. The actual filename is unknown_{networkId}. In my case it was unknown_1337.json, since the default ganache network id is 1337. Possible there's a different network id for your file depending on what you're doing.
sicadev commented 1 year ago

Just had the same issue, i was working on rinkeby testnet then i did a test using ganache and from there it was impossible to deploy any more migrations on rinkeby.

I was always getting "previous deployment is not registered", I indeed had a new unknown-1337.json file near my rinkeby.json one. Deleting it didn't help so i added it back and added the content of my rinkeby.json (after seeing your message @treygrainger) into the unknown-1337.json and it work again now.

This definitely had me lost lot of time, might worth a fix.