deployProxy() using `truffle migrate --reset` errors with requested contract was not found

In my migraton I am using the same artifact that works with await deployer.deploy() than deployProxy().

But with deployProxy() when I run truffle migrate --reset` I get the following error:

`Error: The requested contract was not found. Make sure the source code is available for compilation
at getContractNameAndRunValidation (…/node_modules/@openzeppelin/upgrades-core/src/
validate.ts:159:11)

$ truffle version
Truffle v5.1.60 (core: 5.1.60)
Solidity - 0.5.11 (solc-js)
Node v10.23.1
Web3.js v1.2.9
1 Like

Hi @ccolorado,

Are you able to share the full output from truffle migrate?

What commands had you previously run, e.g. truffle migrate?
What network are you deploying to? Were you doing a dry run?

I wasn’t able to reproduce unfortunately. I did the following:

  1. $ npx truffle migrate --network rinkeby
  2. $ npx truffle migrate --network rinkeby --reset
$ npx truffle migrate --network rinkeby --reset

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'rinkeby'
> Network id:      4
> Block gas limit: 10000000 (0x989680)


1_initial_migration.js
======================

   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0xaa96fe2dadeaf19f4196fe08c8df771f6b7925fab9ab9de4796d970d67b84fcb
   > Blocks: 1            Seconds: 9
   > contract address:    0xDc4A551e0AfBA493246149B1B7ea6Aaa1F9fC7BC
   > block number:        7874819
   > block timestamp:     1610349951
   > account:             0xEce6999C6c5BDA71d673090144b6d3bCD21d13d4
   > balance:             7.283331938
   > gas used:            186951 (0x2da47)
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.00186951 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00186951 ETH


2_deploy_box.js
===============

   Deploying 'AdminUpgradeabilityProxy'
   ------------------------------------
   > transaction hash:    0xf24339e64957244386ed57191b44733402234094161cdb601eb2c644e9ec72d1
   > Blocks: 1            Seconds: 9
   > contract address:    0xD13cA5dc87820844e6f34f84E590B62153AB8A95
   > block number:        7874823
   > block timestamp:     1610350011
   > account:             0xEce6999C6c5BDA71d673090144b6d3bCD21d13d4
   > balance:             7.276701938
   > gas used:            620665 (0x97879)
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.00620665 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00620665 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0.00807616 ETH

I am running on WSL2 on Windows 10

$ npx truffle version
Truffle v5.1.61 (core: 5.1.61)
Solidity - 0.7.5 (solc-js)
Node v10.22.1
Web3.js v1.2.9
1 Like

Hi @abcoathup. Thanks for taking the time to check my question.

So I dug into the openzeppelin’s upgrades-core && truffle-upgrades.

Found out that there are some scenarios that can cause a contract source to be discarded from the migration candidates. (In hindsight It would be useful to have these scenarios produce some kind of error)

After doing some tweaking on my contract I was able to get past that error. but ended up seeing errors like these.

Now I have already deployed contracts with @openzeppelin/cli. Which does not enforce validations (or at least it didn’t at the time I used it).

Have you guys published the risks of not moving to @openzeppelin/truffle-upgrades?

UPDATE:,
There seems to be a bug on how the input and output objects are populated checkForImportIdConsistency. Submitted the following issue.

1 Like

Hi @ccolorado,

OpenZeppelin CLI included upgrade safety checks.

Now that CLI support has ended (see: Building for interoperability: why we’re focusing on Upgrades Plugins), I would recommend migrating to the Upgrades Plugins. Primarily to benefit from the tooling for test and deployment, including the upgrade safety checks. Also to avoid using a project that is no longer supported.


I wasn't able to reproduce the error in https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/279 (yet) but we can continue that discussion in the issue.

1 Like

Hi @ccolorado,

An issue has been created to allow skipping specific upgrade safety checks.

1 Like

Hi there,

I’m also experiencing a similar issue (but using the truffle-upgrades) and would really appreciate some assistance on what the issue is and how to resolve. In my case, my contract code in my original local environment successfully migrates (to ganache-cli) and executes fine. The code is in my GitHub repo: https://github.com/msuscens/Kitty-Masters

However, when I (or someone else) git clones my repo, and then follows the install steps:

    $ npm i
    $ npm install @truffle/hdwallet-provider --save

    Creates a file: 'secrets.json' (required by my truffle-config.js), containing:
    {
        "projectId": "a78925685d7246ef89300dd57aee7c14",
        "mnemonic": "<Insert your MetaMask seed phrase here>"
    }

   $ ganache-cli -h 127.0.0.1 -p 8545 -m "<your chosen mneumonic seed phrase>"
   $ truffle migrate --reset --network development

The following error is thrown:

3_market_migration.js
=====================
***DEBUG : About to deployProxy

Error: The requested contract was not found. Make sure the source code is available for compilation
    at getContractNameAndRunValidation (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Bootcamp/Test-Repo-Pull/Kitty-Masters/node_modules/@openzeppelin/upgrades-core/src/validate/query.ts:46:11)
    at Object.getStorageLayout (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Bootcamp/Test-Repo-Pull/Kitty-Masters/node_modules/@openzeppelin/upgrades-core/src/validate/query.ts:54:41)
    at Object.deployImpl (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Bootcamp/Test-Repo-Pull/Kitty-Masters/node_modules/@openzeppelin/truffle-upgrades/src/utils/deploy-impl.ts:32:18)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at deployProxy (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Bootcamp/Test-Repo-Pull/Kitty-Masters/node_modules/@openzeppelin/truffle-upgrades/src/deploy-proxy.ts:46:16)
    at module.exports (/Users/Mark/Documents/BlockChain/IvanOnTechAcademy/Bootcamp/Test-Repo-Pull/Kitty-Masters/migrations/3_market_migration.js:11:20)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:80:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:218:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.runAll (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:147:1)
Truffle v5.3.9 (core: 5.3.9)
Node v14.15.5

[ Note: I added a console.log("***DEBUG: About to deployProxy") to the repo pulled migration script in order to confirm that the error is thrown upon executing the deployProxy() function ]

Interesting I/they also get a preceding compile warning (that doesn’t occur in my original local environment upon compile or migrate) of:

> Compiled successfully using:
   - solc: 0.8.6+commit.11564f7e.Emscripten.clang

> Duplicate contract names found for KittyContract.
> This can cause errors and unknown behavior. Please rename one of your contracts.

3_market_migration.js file

const { deployProxy } = require('@openzeppelin/truffle-upgrades')
const KittyContract = artifacts.require("KittyContract")
const Marketplace = artifacts.require("KittyMarketplace")

let marketInstance

module.exports = async function (deployer, network, accounts) {

  console.log("***DEBUG : About to deployProxy")
  // Deploy the Logic contract and initialize (with associated proxy)
  marketInstance = await deployProxy(
    Marketplace, 
    [KittyContract.address], 
    { deployer, initializer: 'init_KittyMarketplace', from: accounts[0]}
  )
  console.log("***DEBUG:Done deployProxy")

}

My preceding migration script for the referenced KittyContract, executes successfully:
2_token_migration.js file

const { deployProxy } = require('@openzeppelin/truffle-upgrades')
const KittyContract = artifacts.require("KittyContract")

const tokenName = "Mark-Crypto-Kitty"
const tokenSymbol = "MCK"
let kittyInstance

module.exports = async function (deployer, network, accounts) {

  // Deploy the Logic contract and initialize (with associated proxy)
  kittyInstance = await deployProxy(
    KittyContract, 
    [tokenName, tokenSymbol], 
    { deployer, initializer: 'init_KittyContract', from: accounts[0]}
  )
  
}

Both in my original local version and in the new directory with the pulled repo from gitHub, I have the following:
Truffle v5.3.9 (core: 5.3.9)
Solidity - 0.8.6 (solc-js)
Node v14.15.5
Web3.js v1.3.6

Ganache CLI v6.12.2 (ganache-core: 2.13.2)

Note: I originally hit this issue using Solidity 0.8.5. I updated the code to use 0.8.6 thinking that the compiler version my be an issue. However, I get the same migration error with 0.8.6.

Hey - just to say I’ve now fixed this issue.

It wasn’t to do with deployProxy() function after all but rather I had an inconsistency between my local KittyContract.sol filename and the filename held by git/GitHub. The clue was in the compiler warning of a duplicate contract after a git clone of the repository (pulling it backdown from gitHub and doing a truffle migrate).

My local ‘KittyContract.sol’ file was being stored in git/GitHub as ‘Kittycontract.sol’ (with lowercase ‘c’ but the same contract name inside KittyContract). I recall that I renamed my Kittycontract.sol file early in developing this project (to KittyContract.sol) but for some reason git/GitHub although committing subsequent changes to my KittyContract.sol file kept the old filename as ‘Kittycontract.sol’.

I don’t understand exactly why this happened or why it was causing the issue I was experiencing (ie. truffle migrate worked locally but when committed to git/gitHub and the repository pulled back down from gitHub with a git clone - it found a duplicate contract and migration failed). However, after correcting this filename in git/GitHub this has resolved the issue (both the duplicate contract warning and the migration)!

2 Likes

Going through the same issue right here, but cannot find out how to fix it. getting this error:

Error: The requested contract was not found. Make sure the source code is available for compilation
    at getContractNameAndRunValidation (D:\solidity\MOTDV1\node_modules\@openzeppelin\upgrades-core\src\validate\query.ts:46:11)
    at Object.getStorageLayout (D:\solidity\MOTDV1\node_modules\@openzeppelin\upgrades-core\src\validate\query.ts:54:41)
    at Object.deployImpl (D:\solidity\MOTDV1\node_modules\@openzeppelin\truffle-upgrades\src\utils\deploy-impl.ts:32:18)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at deployProxy (D:\solidity\MOTDV1\node_modules\@openzeppelin\truffle-upgrades\src\deploy-proxy.ts:46:16)
    at module.exports (D:\solidity\MOTDV1\migrations\2_MOTD_V1_Proxy_Deployment.js:36:19)
    at Migration._deploy (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:80:1)
    at Migration._load (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:61:1)
    at Migration.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:218:1)
    at Object.runMigrations (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
    at Object.runFrom (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.runAll (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
    at Object.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
    at runMigrations (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:258:1)
    at Object.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:223:1)
    at Command.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:167:1)

It all worked find 6 weeks ago. Now coming back to the project, I face issue after issue.

1 Like