xGodMode / godmode

Use GodMode to get full control of any Ethereum contract or account
http://godmode.work
MIT License
41 stars 15 forks source link

Handle Infura archive error #29

Open v-stickykeys opened 3 years ago

v-stickykeys commented 3 years ago

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,

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 commented 3 years ago

To flesh this out a bit more, what we want is:

This requires a few components:

  1. API endpoints to start and stop godmode ganache running
  2. An interface in the godmode library (or elsewhere?) to allow users to make requests to the endpoint above
  3. Documentation and examples on the proper start up/clean up usage and docs on how to handle the archive error (or do we watch for the archive error and reset for them? then include a response message that says state was reset?)