-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix(anvil
): set storage.best_number
correctly
#9215
Conversation
@yash-atreya I added a test here, basically dumping state locally from gh issue recreate and reloading / make sure balance properly retrieved, feel free to include in PR if OK |
@grandizzy thanks for this. I've added a more comprehensive test. ptal. |
anvil
): introduce account_at
in ForkedStorage
anvil
): set storage.best_number
correctly
@yash-atreya I suspect this is supposed to close #8493 too? If so, could you please update description to include it? thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Motivation
Closes #9053 + Closes #8493
This arises when
--fork-url
and--load-state
are used together.Solution
Introduceaccount_at
inForkedStorage
which stores the state of accounts at specific block numbers.Populateaccount_at
using the provided state file.Solution is a lot simpler.
We are correctly loading the data to the db:
foundry/crates/anvil/src/eth/backend/mem/mod.rs
Line 925 in 4012ade
However, the
storage.best_number
i.e head of the chain is not correctly set when--load-state
is used with--fork-url
. We continue to setstorage.best_number = state.block.number
which is incorrect as thebest_number
should befork_block_number
.This issue is observed when
fork_block_number
>state.block_number
. In this case while all state data has been correctly loaded to the db, we fetch via the provider due to this check.foundry/crates/anvil/src/eth/api.rs
Line 683 in 4012ade
Setting
storage.best_number = fork_block_number
fixes thisTest