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.
Re-exportsยง
use super::Fork;๐use alloy_network::Network;๐use alloy_primitives::Address;๐use alloy_primitives::U256;๐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ยง
- 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.
Functionsยง
- keys ๐
- Returns the accounts first, then the slots, up to
MAX_KEYS. - 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.