-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(anvil
): support state caching for forked historical blocks
#1759
Comments
currently we only store the state of the forked block, and cache is blockwise. if the block predates the fork we simply delegate the eth_call. which would be doable but would require some work. I'm not sure how hardhat/ganache store that eth_call, are they storing state map or eth_call/response pairs? |
I am not familiar with hardhat implementation, but looking into the cache folder, it seems they are creating a "request-{transaction-hash}.json" file, with the contents of the response inside. I don't see any block number reference, so I can only guess that part of the hash contains the block number, something like sha(blockNumber + transaction-data). |
I looked into hardhat's caching approach a little while back (see #698 (comment)). The answer is yes, they store call/response pairs:
Most (all?) of their implementation can be found here: https://github.com/nomiclabs/hardhat/blob/4f108b51fc7f87bcf7f173a4301b5973918b4903/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts#L224-L475 |
Needing to implement chain specific logic for safe depth could be implemented in a more generic way if the corresponding blockhash is stored locally and always checked against the remote before using the cache. If they don't match, then flush the cache. That adds an extra http request but it can be amortized over many possible state lookups |
Ah yes good point, did not mean to imply we should use hardhat's approach of a chain-specific reorg threshold—I agree the blockhash approach is better and forgot to mention it |
Is this still the case? If so, is this expected/is it fixable? cc @mattsse |
Is it still considered to have a call cache that can be dumped into a file? That would be an awesome feature. |
anvil
): support state caching for forked historical blocks
we now have --dump-state <PATH>
Dump the state and block environment of chain on exit to the given file.
If the value is a directory, the state will be written to `<VALUE>/state.json`.
--load-state <PATH>
Initialize the chain from a previously saved state snapshot flags which could be used (we're fixing the issue reported in #8493 though) Would these new options work for mentioned scenario? thank you |
OK |
ping @julien-devatom @asafyish could you pls check comment above? thanks! |
Component
Anvil
Describe the feature you would like
I am running anvil in fork mode (connected to archive node), like so:
anvil --fork-url "https://eth-mainnet.alchemyapi.io/v2/XXXXXXXX" --fork-block-number 14577209
Then I am trying to read historical blocks data, which works, but only caches block 14577209, even though I am reading from the other blocks. The same scenario does create cache in hardhat and ganache. Since anvil is so much faster in the initial reading, I prefer using it.
This is how I am reading historical data:
Running
returns:
-️ mainnet (2.1 kB)
-️ Block 14577209 (2.1 kB)
Additional context
forge 0.2.0 (6ca977f 2022-05-29T02:10:50.584077Z)
The text was updated successfully, but these errors were encountered: