trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.62k stars 678 forks source link

ganache-core 'header not found' error when forking on node 14 #1497

Closed moda20 closed 2 years ago

moda20 commented 2 years ago

I am having an error when forking using the programmable version of ganache (ganache-core version 2.13.2). the error is 'header not found' :

Error: Returned error: header not found
    at Object.ErrorResponse (/node_modules/ganache-core/node_modules/web3-core-helpers/src/errors.js:30:19)
    at onJsonrpcResult (node_modules/ganache-core/node_modules/web3-core-requestmanager/src/index.js:172:36)
    at node_modules/ganache-core/lib/forking/forked_blockchain.js:136:11
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

this is a very recurrent issue and breaks the usage of ganache forking.

my node version is v14.15.2.

davidmurdoch commented 2 years ago

Can you try starting ganache with an explicit fork block number that is at least a few blocks old and let me know if it works.

Are you using infura for the fork url?

Example:

ganache-cli --fork {FORK URL}@13551770

moda20 commented 2 years ago

Hi, i am doing the forking programmatically, but I'll try the explicit block number. for forking i am using moralis nodes, it's free archival nodes. it always worked before so I have faith in it.

davidmurdoch commented 2 years ago

I've seen this issue occur when ganache requests the latest block number, then uses that block number to get the block data, but the node hasn't yet processed it, and instead returns a "header not found" error.

moda20 commented 2 years ago

Well, that did it. it fixed a lot of the issues I had with the forking, it's weird that it requests block data before having the blocknumber.

davidmurdoch commented 2 years ago

It doesn't request the block data before the block number, it's just that the external node we interact with knows the block number of the block it is currently processing, but because it hasn't finished processing it yet when we request the block itself the node response like it doesn't know about it. It's very frustrating behavior, as you've seen!

An alternative approach for ganache is for us to automatically set the default fork block number to "latest" - n, where n is ~5 blocks. That way we can:

Another alternative, and the one I prefer, but haven't figured out how to fully implement, is to attempt a time-based approach, where we just want to make sure the blocks are at least t seconds old. But this get complicated because the user's clock isn't always reliable! We'd need to sync with an authoritative time server, like pool.ntp.org, which requires an always-on internet connection. Additionally, block times themselves are permitted to be inaccurate to a certain degree (15 minutes!).

I'm going to close this issue, as it's really an issue with the node (though we are working on ways of minimizing the occurrence on start up)