godmode icon indicating copy to clipboard operation
godmode copied to clipboard

Handle Infura archive error

Open v-stickykeys opened this issue 3 years ago • 1 comments

Problem

When using the default Infura mainnet endpoint, you get the latest 128 blocks of Ethereum state. Given a block production rate of about 13 seconds, that is about 27 minutes of full mainnet state. This means when you run ganache and fork off of mainnet you will get an error when trying to retrieve block state created 27 minutes prior to when you started.

As an example,

  • Alex is running ganache-cli with the -f flag set to an Infura mainnet websocket url
  • Alex runs tests against ganache-cli deploying a contract in block 1
  • 13 seconds later the block height is 2
  • 30 minutes later the block height is 138
  • When Alex attempts to run a test accessing the full state from block 1 an error to the tune of project ID does not have access to archive state will be thrown by Infura

Based on the Infura docs on archive data:

Because of the way account and contract storage works in Ethereum, this means that only an archive node can serve API request for certain RPC methods older than 128 blocks.

Solutions

So far I see 2 ways to handle this:

  1. Keep your testing within 128 blocks (and restart ganache-cli after 128 blocks so you don't accidentally exceed this when testing)
  2. Spin up another ganache with shared state before the first expires and switch to it (basically, keep the state around in ganache that would otherwise get pruned and make the request for state use this cache instead of making the json rpc request to infura)
  3. Require users to design tests such that they don't retrieve state after 128 blocks (not sure that this would exactly solve it, probably more nuance here)

Proposal

I propose we start with solution 1 and explore 2 in the future because it is very reasonable for testing to exceed 27 minutes

v-stickykeys avatar Jun 15 '21 20:06 v-stickykeys