HH108 'Cannot connect to the network' when Hardhat Network forks mainnet after pinning an old blockNumber
0 reputation · 12 Jan 2020, 08:17 UTC
I am setting up local mainnet forking with the Hardhat Network using the networks.hardhat.forking config, with a url and a blockNumber pinned for reproducibility. Intermittently, startup fails with the documented connection error HH108 ("Cannot connect to the network"), and I cannot tell whether the failure is the endpoint being unreachable, the pinned block being older than what the node retains, or stale fork cache from an earlier run.
My constraints: the upstream endpoint may be a non-archive node, the pinned block is several months old, and tests are also run unpinned in CI, where results drift as the upstream chain advances. I have seen references to hardhat_reset as a way to re-initialize the fork at runtime, but its interaction with the local cache and an unreachable endpoint is unclear to me.
How can I distinguish, from the HH108 failure alone, between a connectivity problem and a request for state the upstream node no longer serves? Does hardhat_reset clear the cached fork state, or must the cache be invalidated separately? Is pinning a blockNumber the recommended way to get deterministic fork behavior across runs?