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 #447

Open
MarcBickel opened this issue May 9, 2024 · 14 comments
Open

No known hardfork for execution on historical block #447

MarcBickel opened this issue May 9, 2024 · 14 comments
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

5 participants