Expand description
Prefetches a new fork blockβs remote cache from the keys of an older cached block.
A fork of latest gets an empty cache on each new head, and every cold account or storage read
then blocks the EVM for one RPC round trip. Earlier runs on the same chain read mostly the same
accounts and slots, so the keys of the newest older cache file predict the reads. The keys are
read again at the new block through the fork backend, so the cache stays exact for that block.
The cache file keeps only the keys the EVM then reads, so a wrong prediction only costs an RPC
request and does not carry over to the next block.
A call is predicted more precisely by simulating it on the endpoint, see prefetch_call.
Re-exportsΒ§
use super::Fork;πuse crate::constants::CHEATCODE_ADDRESS;πuse crate::constants::HARDHAT_CONSOLE_ADDRESS;πuse crate::precompiles::P256_VERIFY;πuse alloy_network::Network;πuse alloy_primitives::Address;πuse alloy_primitives::B256;πuse alloy_primitives::Bytes;πuse alloy_primitives::KECCAK256_EMPTY;πuse alloy_primitives::U256;πuse alloy_rpc_types::TransactionRequest;πuse alloy_rpc_types::state::StateOverride;πuse evm2::bytecode::Bytecode;πuse evm2::evm::Cache;πuse foundry_config::Config;πuse foundry_fork_db::ForkBlockEnv;πuse foundry_fork_db::backend::BlockingMode;πuse foundry_fork_db::cache::JsonBlockCacheDB;πuse foundry_fork_db::cache::MemDb;πuse parking_lot::Mutex;πuse std::path::Path;πuse std::path::PathBuf;πuse std::sync::Arc;πuse std::sync::atomic::AtomicBool;πuse std::sync::atomic::Ordering;πuse std::sync::mpsc;π
StructsΒ§
- Prefetch π
- Background prefetch workers of one fork backend.
EnumsΒ§
- Key π
ConstantsΒ§
- CHEATCODE_
STUB π - Runtime code that returns one zero word, standing in for the cheatcode contract in a
simulation on the forkβs endpoint:
PUSH1 0x20 PUSH1 0x00 RETURN. - MAX_
CONCURRENT_ πREQUESTS - Prefetch requests in flight at once. The fork backend sends its own cold reads without a limit; this bound keeps a large key set from flooding a public endpoint.
- MAX_
KEYS π - Largest number of accounts and slots to prefetch. Older cache files can hold the union of many runs; past this size, a prefetch can cost more requests than it saves.
- MAX_
OVERRIDE_ πBYTES - Largest local state, in bytes of code and storage, sent as overrides with a simulated call.
FunctionsΒ§
- keys π
- Returns the accounts first, then the slots, up to
MAX_KEYS. - prefetch_
call π - Simulates a call on the forkβs endpoint and prefetches the state it touches, see
SharedBackend::prefetch_access_list. Withoverrides, thelocalstate over the fork goes along as overrides. - previous_
cache_ πfile - Returns the cache file of the newest block below
numberin a chain cache directory. - spawn π
- Starts a background prefetch through
backendif its cache is empty. - state_
override π - Returns the local state of a fork context that differs from
remote, the state the fork loaded from its endpoint, as overrides for a simulation there, with a stub for the cheatcode contract. Such state is the test contract and balances set with cheatcodes.