-
Notifications
You must be signed in to change notification settings - Fork 2k
Where does anvil
store fork's state?
#3837
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
Comments
@mattsse polite reminder. |
Okay, I just realized that However, if I disconnect my internet connection and run the
Obviously, any operation on storage.json
next issue is returning a
which we can check for Final issue is, I then realized that only a few of the fields are different:
if we somehow match or skip that, then our node spins up and we can interact with it. Note that I only checked for ETH balance so far. We can read the json file separately and substitute the values in Thoughts? |
thanks for writing this down, however, I'm having a hard time parsing what the actual issue(s) are here. I looked at the corresponding PR, but having trouble understanding the exact motivation here and how this relates to this issue. rpc storage is flushed to disk on exit |
I'm testing contracts inside an isolated network which provides increased security. There is no route to public internet to begin with, so the only way to test against a fork is to move/commit state files of a certain block to a repository and test against that. Moving the state file (storage.json) alone is not enough because of the issues mentioned in the PR, and if merged, it wouldn't affect anything related to normal operations of a fork. Does this make sense? |
kinda but I'm still slow to understand this completely.
I really don't understand this, because the matching cache file to the block-number will be picked up if it exists, no?
why is |
Yes, but not before making two http(s) requests to remote endpoint, which will panic when not connected to internet:
to give you a code example:
you don't want to create a default |
okay, thanks for clearing this up. I believe I get it now. Supportive of an offline feature, wdyt about adding an |
I already had added a
|
I see, that makes sense if you want to use the cache file of chain x but override with y, right? but, correct me, isn't |
Not sure what you mean. Chain number is overridden by the cache file and we only need the chain id in order to know which folder to look for config.json in the first place.
Yes. let's call
becomes
|
gotcha, thanks for guiding me through this. I'll have a closer look at the PR in a bit but this should be a reasonable addon. thanks |
@xphoniex Did you have to do anything special (edit the storage.json file?) to get anvil to load the state? I can get Anvil to save the state by starting with:
I see the storage file in ~/.foundry/cache/rpc/dev/16328288/storage.json But when I restart it with:
.. the state isn't there, shows blockhash 0x0...0 Did you do anything different to restore the state? Thanks |
can you please elaborate on this? |
Anvil startup shows this in logs:
Block hash shows an actual value when starting w/o --fork-chain-id option |
The state is there, only blockhash is missing (read the whole issue and adjacent pr to know why). Try running a command which retrieves actual state, e.g. |
Yes you're right, the state is there, at least in part. I think there's another issue going on as well as me not understanding things properly. I just now realized that storage.json only stores the state from upstream. If I change the state in Anvil after forking, those changes are not going to be stored in storage.json. That was my first mistaken assumption. Having said that, contract calls don't work for some reason against the loaded storage.json state. cast balance X works, but if I try to read an ERC20 balance, it fails with I wish --dump-state and --load-state would work when using a fork :/ Anyways, thanks for the tip! |
I was not able to run anvil offline yet because of this issue. I'll revisit what you said once I can get it working, and hopefully fix contract calls as well. |
I'm running
anvil --fork-url <rpc>
and first thing I noticed is that the logs don't show interactions with rpc, e.g:whereas I expect it to show something like:
regardless, I don't know where the state is stored. It seems like
anvil
retrieves bare minimum for the task and keeps it in-memory (?), inBlockchainDb
(?).I'm also seeing a file in
.foundry/cache/rpc/goerli/8077534
which is the chain/block I'm interacting with but it's not growing in size, so I'm assuming the state has to be kept in-memory.If it is in-memory, then I suggest we add a flag so that state data can be stored on disk. This would enable further offline state retrieval which can be useful for CI purposes (e.g. committed to repo), as well as secure isolated environments.
I'd be interested to implement it myself as well, if given some pointers on how the internals work.
P.S. please consider creating a discord server.
The text was updated successfully, but these errors were encountered: