-
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
fix(anvil): reset cache path during anvil_reset without fork url #9729
base: master
Are you sure you want to change the base?
Conversation
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.
makes sense, thank you! left couple of nits
@@ -542,6 +542,27 @@ impl Backend { | |||
*self.fork.write() = Some(fork); | |||
*self.env.write() = env; | |||
} else { | |||
// If rpc url is unspecified, then update the fork with the new block number and |
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.
this makes sense, can you please externalize this code (which is done also in the case of rpc url specified) in a helper fn / closure and reuse?
foundry/crates/anvil/src/eth/backend/mem/mod.rs
Lines 531 to 534 in f399820
if let Some(fork_url) = forking.json_rpc_url { | |
// Set the fork block number | |
let mut node_config = self.node_config.write().await; | |
node_config.fork_choice = Some(ForkChoice::Block(fork_block_number)); |
async fn get_block_from_cache_path(api: &mut EthApi) -> u64 { | ||
let db = api.backend.get_db().read().await; | ||
let cache_debug = format!("{:?}", db.maybe_inner().unwrap().cache()); | ||
let re = regex::Regex::new(r#"JsonBlockCacheDB \{ cache_path: Some\("([^"]+)"\)"#).unwrap(); |
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.
can we simplify this by starting node with cache_path
config?
foundry/crates/anvil/src/config.rs
Lines 967 to 972 in 9f11e6d
/// Sets the path where states are cached | |
#[must_use] | |
pub fn with_cache_path(mut self, cache_path: Option<PathBuf>) -> Self { | |
self.cache_path = cache_path; | |
self | |
} |
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.
The test actually verifies that the cache path is updated upon reset, the regex exists because cache_path
is currently private (so only obtainable via fmt::Debug
). If we expose that property we can get rid of the regex and check it straight away
Motivation
The test
test_reset_dev_account_nonce
would fail on subsequent runs becauseanvil_reset
when run without afork_url
would not update the cache path inSharedBackend
andBlockchainDb
. As such, after reset, the rpc calls would write to the initial block's cache file.Solution
Reset the
ForkedDatabase
correctly even when the fork url is missing.Note
Unsure why this doesn't fail on the CI, but it would consistently fail locally on Ubuntu 24.04