Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No known hardfork for execution on historical block #5511

Closed
MarcBickel opened this issue May 9, 2024 · 21 comments · Fixed by #5394
Closed

No known hardfork for execution on historical block #5511

MarcBickel opened this issue May 9, 2024 · 21 comments · Fixed by #5394
Assignees

Comments

@MarcBickel
Copy link

Version of Hardhat

2.22.3

What happened?

Forked arbitrum sepolia with npx hardhat node, when trying to run a typescript script that calls any function on-chain (even simple view function), I get the error
ProviderError: No known hardfork for execution on historical block 42324641 (relative to fork block number 42324641). The node was not configured with a hardfork activation history.

The block number is the block at which the chain has been forked I believe (didn't specify so should be latest).

Minimal reproduction steps

Fork arbitrum sepolia with npx hardhat node with an alchemy endpoint.

Search terms

No response

@6xiaowu9
Copy link

I also encountered it, it should be a problem with v2.22.3, I downgraded the version to v2.22.2 and it ran normally.

@MarcBickel
Copy link
Author

I still get it with v2.22.2, forking the same network as above.

@6xiaowu9
Copy link

I still get it with v2.22.2, forking the same network as above.

Sorry I saw it wrong, I reverted to v2.19.4

@MarcBickel
Copy link
Author

Can confirm this error goes away with v2.19.4, but I am relying on features introduced later (and get other errors), so can't really use that version. Thanks for the input though!

@MarcBickel
Copy link
Author

As additional input: my script works with anvil running the local fork, so error should be on the node task side

@6xiaowu9
Copy link

6xiaowu9 commented May 13, 2024

You can try to roll back to the previous version from v2.22.3

@kanej kanej transferred this issue from NomicFoundation/hardhat May 13, 2024
@fvictorio
Copy link
Member

Hi, I can't reproduce this. I'm forking sepolia and running a call with some random ERC-20:

const blockNumber = await ethers.provider.getBlockNumber()
const mockDai = await ethers.getContractAt(["function totalSupply() public view returns(uint256)"], "0xd6a17186e7bde277ad70e5d5c99d042acf30990c")
console.log(await mockDai.totalSupply())
console.log(await mockDai.totalSupply({blockTag: blockNumber - 10}))

Could someone give us a minimal reproducible example?

@MarcBickel
Copy link
Author

Steps to reproduce:

  1. Have a hardhat config file
defaultNetwork: "arbitrumSepolia",
  solidity: {
    version: "0.8.25",
    settings: {
      viaIR: true,
      optimizer: {
        enabled: true,
        runs: 10,
        details: {
          yulDetails: {
            optimizerSteps: "u",
          },
        },
      },
      evmVersion: "cancun",
    },
  }
networks: {
    hardhat: {
      forking: {
        enabled: true,
        url: `https://arb-sepolia.g.alchemy.com/v2/<APIKEY>`,
      },
    }
  1. Run npx hardhat node --fork https://arb-sepolia.g.alchemy.com/v2/<APIKEY>
  2. Run npx hardhat run --network localhost scripts/testMultiContract.ts (or any script).
    The first lines of the script are (after getting the accounts) as follows. Most likely hangs with any eth_call though.
const currencyContract = "0xB28bbA1a16eB2aB0B0E4396f90BFbC04B6e344dC";
  const USDT = await ethers.getContractAt("TestnetERC20", currencyContract);
  const currencyDecimals = Number(await USDT.decimals());
  1. Get an error
Screenshot 2024-05-15 at 12 19 28
ProviderError: No known hardfork for execution on historical block 44273914 (relative to fork block number 44273914). The node was not configured with a hardfork activation history.
    at HttpProvider.request (/Users/marc/Documents/Fume-Protocol/node_modules/hardhat/src/internal/core/providers/http.ts:90:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async staticCallResult (/Users/marc/Documents/Fume-Protocol/node_modules/ethers/src.ts/contract/contract.ts:337:22)
    at async staticCall (/Users/marc/Documents/Fume-Protocol/node_modules/ethers/src.ts/contract/contract.ts:303:24)
    at async Proxy.decimals (/Users/marc/Documents/Fume-Protocol/node_modules/ethers/src.ts/contract/contract.ts:351:41)
    at async main (/Users/marc/Documents/Fume-Protocol/scripts/testMultiContract.ts:19:39)

@noodlespan
Copy link

noodlespan commented May 20, 2024

I downgraded the version to v2.20.1 and it worked on optimistic network

"devDependencies": {
    "@nomicfoundation/hardhat-toolbox": "^4.0.0",
    "hardhat": "^2.20.1"
  }

Testcase code :

import hre from "hardhat";
//USDC 合约地址
const USDC_ADDRESS = "0x0b2c639c533813f4aa9d7837caf62653d097ff85";
//USDC ABI 
const USDC_ABI = ["function totalSupply() public view returns (uint)"];

describe("Optimistic USDC", function () {
  describe("Balance", function () {
    it("Get usdc balance by address", async function () {
      const usdcToken = await hre.ethers.getContractAt(USDC_ABI, USDC_ADDRESS);
      const block = await hre.ethers.provider.getBlockNumber();
      console.log("Optimistic Block Number", block);
      //获取 USDT 总发行量
      const totalSupply = await usdcToken.totalSupply();
      console.log("Optimistic USDC totalSupply", hre.ethers.formatUnits(totalSupply, 6));
    });
  });
});

Run command:

fork:
npx hardhat node --fork https://opt-mainnet.g.alchemy.com/v2/...
run:
npx hardhat test --network localhost

Result:

  Optimistic USDC
    Balance
Optimistic Block Number 120288014
Optimistic USDC totalSupply 169377140.604314
      ✔ Get usdc balance by address (3721ms)


  1 passing (4s)

@MarcBickel
Copy link
Author

@noodlespan I can confirm this fixes the error as well with v2.20.1. I get strange other errors in my script afterwards, but that's most likely on me (reverts for unkown reason, works with anvil). Most likely bug in the rust rework then

@MarcBickel
Copy link
Author

@fvictorio Is that enough or do you need more info?

@fvictorio
Copy link
Member

Confirmed and important, thanks!

@fvictorio
Copy link
Member

I hope we can fix this soon, but in the meantime: a workaround seems to be to immediately mine a block after starting the node. For example, adding this at the beginning of the script:

import * as helpers from "@nomicfoundation/hardhat-network-helpers";

await helpers.mine()
// rest of the script

@fvictorio fvictorio self-assigned this May 22, 2024
@MarcBickel
Copy link
Author

@fvictorio Thanks for the workaround, can confirm this does fix the problem, at least temporally 👍
(I put the await helpers.mine() in main() if someone else also needs the workaround)

@SrikanthAlva
Copy link

I hope we can fix this soon, but in the meantime: a workaround seems to be to immediately mine a block after starting the node. For example, adding this at the beginning of the script:

import * as helpers from "@nomicfoundation/hardhat-network-helpers";

await helpers.mine()
// rest of the script

I am using 2.22.5.

Didnt downgrade.

used the code shared above. It resolved my issue.

@Wodann Wodann transferred this issue from NomicFoundation/edr Jul 11, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Jul 11, 2024
@Wodann Wodann moved this from Backlog to Done in Hardhat Jul 11, 2024
@fvictorio fvictorio removed this from EDR Jul 12, 2024
@bytes0xcr6
Copy link

I am still getting this error on the latest version. Is it supposed to be solved?

Hardhat version: "^2.22.8"

@fvictorio
Copy link
Member

@bytes0xcr6 we fixed it for some chains (Optimism and Arbitrum mainnets and testnets). This will continue to be an issue for "unknown" chains. The workarounds are:

  1. Add a hardfork history for that chain (docs)
  2. Mine a block before making any calls (an ugly workaround but it works)

We are going to fix the underlying issue so that these workarounds are not necessary, but I don't have an estimation of when that will happen.

@laptrinhbockchain
Copy link

I still get it with v2.22.2, forking the same network as above.

Sorry I saw it wrong, I reverted to v2.19.4

I had the same problem. When I reverted hardhat to v2.19.4, everything worked. Thank you!

@Quazia
Copy link

Quazia commented Sep 13, 2024

Still getting this issue on "^2.22.5" mine() worked great thank you @fvictorio

Quazia added a commit to boostxyz/boost-protocol that referenced this issue Sep 13, 2024
@fvictorio
Copy link
Member

@Quazia which chain are you using? Zora?

Quazia added a commit to boostxyz/boost-protocol that referenced this issue Sep 18, 2024
Quazia added a commit to boostxyz/boost-protocol that referenced this issue Sep 18, 2024
@farau
Copy link

farau commented Sep 27, 2024

@bytes0xcr6 we fixed it for some chains (Optimism and Arbitrum mainnets and testnets). This will continue to be an issue for "unknown" chains. The workarounds are:

  1. Add a hardfork history for that chain (docs)
  2. Mine a block before making any calls (an ugly workaround but it works)

We are going to fix the underlying issue so that these workarounds are not necessary, but I don't have an estimation of when that will happen.

I got the same issue with Blast chain. I added the hardForkHistory in my hardhat.config.js file :

hardhat: {
            forking: {
                url: `https://rpc.blast.io`,  
                blockNumber: 9192511
            },
            chainId: 0x13e31, 
            chains: {
                0x13e31: {
                  hardforkHistory: {
                    berlin: 1000000,
                    london: 2000000,
                  },
                }
              }
        },

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.