wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 292 forks source link

hardhat-deploy can't be used together with regular hardchat smartcontact calls, it uses same nonce #336

Open lebed2045 opened 2 years ago

lebed2045 commented 2 years ago

Describe the bug hardhat-deploy can't be used together with regular hardchat smartcontact calls, it uses same nonce

To Reproduce

  await deployments.deploy("MockOracle", deployOptions);
  const mockOracle = await ethers.getContract("MockOracle") as MockOracle;
  await allContracts.suOracleAggregator.setOracleImplementation(mockOracleId, mockOracle.address);
  const mockWBTC = await deployments.deploy("MockWBTC", deployOptions);

deploying "MockWBTC"nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="sendTransaction", transaction=undefined, code=NONCE_EXPIRED, version=providers/5.6.2) {"reason":"nonce has already been used","code":"NONCE_EXPIRED","error":{"name":"ProviderError","code":-32000,"_isProviderError":true},"method":"sendTransaction"} Error: nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="sendTransaction", transaction=undefined, code=NONCE_EXPIRED, version=providers/5.6.2) at Logger.makeError (/Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/logger/src.ts/index.ts:261:28) at Logger.throwError (/Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/logger/src.ts/index.ts:273:20) at checkError (/Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:88:16) at /Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:243:24 at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) { reason: 'nonce has already been used', code: 'NONCE_EXPIRED', error: ProviderError: nonce too low at HttpProvider.request (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat/src/internal/core/providers/http.ts:49:19) at LocalAccountsProvider.request (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat/src/internal/core/providers/accounts.ts:182:36) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5), method: 'sendTransaction', transaction: undefined } An unexpected error occurred: Error: ERROR processing /Users/dmitry/stableunit-poc-v2/deploy/2_MockContracts.ts: Error: nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="sendTransaction", transaction=undefined, code=NONCE_EXPIRED, version=providers/5.6.2) at Logger.makeError (/Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/logger/src.ts/index.ts:261:28) at Logger.throwError (/Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/logger/src.ts/index.ts:273:20) at checkError (/Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:88:16) at /Users/dmitry/stableunit-poc-v2/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:243:24 at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at DeploymentsManager.executeDeployScripts (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at async DeploymentsManager.runDeploy (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5) at async SimpleTaskDefinition.action (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat-deploy/src/index.ts:422:5) at async Environment._runTaskDefinition (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14) at async Environment.run (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14) at async SimpleTaskDefinition.action (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat-deploy/src/index.ts:568:32) at async Environment._runTaskDefinition (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14) at async Environment.run (/Users/dmitry/stableunit-poc-v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14) npm notice npm notice New minor version of npm available! 8.5.5 -> 8.12.1 npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.12.1 npm notice Run npm install -g npm@8.12.1 to update! npm notice

Expected behavior it should be able to deploy and call function without problems.

versions

  "dependencies": {
    "@chainlink/contracts": "^0.4.0",
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-truffle5": "^2.0.5",
    "@nomiclabs/hardhat-waffle": "^2.0.0",
    "@nomiclabs/hardhat-web3": "^2.0.0",
    "@openzeppelin/contracts": "4.5.0",
    "@openzeppelin/contracts-upgradeable": "^4.5.2",
    "@openzeppelin/test-helpers": "^0.5.15",
    "@remix-project/remixd": "^0.5.6",
    "@typechain/ethers-v5": "^7.0.1",
    "@typechain/hardhat": "^2.3.0",
    "@types/chai": "^4.2.21",
    "@types/mocha": "^9.0.0",
    "@types/node": "^12.20.47",
    "@typescript-eslint/eslint-plugin": "^5.16.0",
    "@typescript-eslint/parser": "^5.16.0",
    "@uniswap/v3-core": "^1.0.1",
    "@uniswap/v3-periphery": "^1.4.0",
    "chai": "^4.2.0",
    "dotenv": "^10.0.0",
    "eslint": "^8.11.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-config-airbnb-typescript": "^16.1.4",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-promise": "^5.1.0",
    "ethereum-waffle": "^3.0.0",
    "ethereumjs-wallet": "^1.0.2",
    "ethers": "5.6.1",
    "hardhat": "^2.8.4",
    "hardhat-deploy": "^0.11.2",
    "hardhat-deploy-ethers": "^0.3.0-beta.13",
    "hardhat-gas-reporter": "^1.0.4",
    "prettier": "^2.3.2",
    "prettier-plugin-solidity": "^1.0.0-beta.13",
    "solhint": "^3.3.6",
    "solidity-coverage": "^0.7.16",
    "ts-node": "^10.1.0",
    "typechain": "^5.1.2",
    "typescript": "^4.5.2"
  },

Additional context it works extremely inconsistent, add sleep(30 seconds) after hardhat-deploy and regular call and vice-versa sometimes help, but if you have lots of cases - one eventually fails.

wighawag commented 2 years ago

you can provide nonce: "pending" to the deploy option

But the way hardhat-deploy works to remain idempotent (if the script are designed for it) is to wait for the previous tx first and use latest nonce

this line: await allContracts.suOracleAggregator.setOracleImplementation(mockOracleId, mockOracle.address); is not waiting for the tx to be mined, it just wait for the tx to be broadcasted

Smajser12 commented 2 years ago

Any update on how we can solve this error when calling contracts ? It seems really unpractical to code script with it right now ?

wighawag commented 2 years ago

@Smajser12 what do you mean ?

I replied, you either have to wait for the tx to be mined with tx.wait() or use nonce:pending` (but the latter will break hardhat-deploy replayability