pub struct EvmCacheBuilder<P> { /* private fields */ }Expand description
Fluent builder for EvmCache.
A readable alternative to the positional EvmCache::with_cache
constructor. Defaults: latest block, no disk cache, SpecId::CANCUN.
let provider = ProviderBuilder::new()
.network::<AnyNetwork>()
.connect_http("https://example-rpc.invalid".parse()?);
let cache = EvmCache::builder(Arc::new(provider))
.latest_block()
.spec(SpecId::CANCUN)
.build()
.await;Implementations§
Source§impl<P> EvmCacheBuilder<P>where
P: Provider<AnyNetwork> + 'static,
impl<P> EvmCacheBuilder<P>where
P: Provider<AnyNetwork> + 'static,
Sourcepub fn max_concurrent_proofs(self, cap: usize) -> Self
pub fn max_concurrent_proofs(self, cap: usize) -> Self
Cap the default account-proof fetcher’s concurrent eth_getProof
fan-out (default 8, name-symmetric with
BulkCallConfig::max_concurrent_calls).
eth_getProof is single-address at the RPC level, so when the root
gate or an account resync probes N tracked accounts in one seam call,
concurrency is the only wall-clock lever: N × RTT serial becomes
~ceil(N / cap) × RTT. Values are clamped to at least 1. Custom
fetchers installed via
set_account_proof_fetcher
ignore this knob.
Sourcepub fn block(self, block: BlockId) -> Self
pub fn block(self, block: BlockId) -> Self
Pin simulations and RPC fetches to a specific block.
Use this to fork at a fixed height for reproducible simulation. Without
a call to block or latest_block
the builder defaults to the latest block at build time.
Sourcepub fn latest_block(self) -> Self
pub fn latest_block(self) -> Self
Sourcepub fn spec(self, spec_id: SpecId) -> Self
pub fn spec(self, spec_id: SpecId) -> Self
Set the EVM hardfork spec (must match the chain’s execution layer).
Sourcepub fn chain_id(self, chain_id: u64) -> Self
pub fn chain_id(self, chain_id: u64) -> Self
Set the chain ID reported to simulations via the CHAINID opcode.
Recommended. This is the explicit, authoritative way to set the chain
ID. If left unset, build infers it from the provider
(eth_chainId), falling back to 1 (Ethereum mainnet) only if that query
fails. A disk cache_config also carries a
chain_id (which additionally namespaces the on-disk cache directory);
when both are set, the value passed here wins for the CHAINID opcode, so
keep them consistent.
Sourcepub fn cache_config(self, cache_config: CacheConfig) -> Self
pub fn cache_config(self, cache_config: CacheConfig) -> Self
Enable disk-backed caching with the given configuration.
Supplying a CacheConfig turns on persistence of EVM state, bytecodes,
and immutable data under the configured chain directory; the cache is
loaded on build and flushed on drop. Omit it for a
purely in-memory cache backed solely by RPC.
Set how much EVM shared memory to pre-allocate per simulation context.
Defaults to SharedMemoryCapacity::Fixed with 64 * 1024 bytes
(65,536 bytes).
Use Fixed(n) to pin a size, or SharedMemoryCapacity::Auto to size it
from the chain state loaded at build time (e.g. a bincode
state file supplied via cache_config). See
SharedMemoryCapacity for the trade-offs.
Sourcepub fn storage_batch_config(self, config: impl Into<StorageBatchConfig>) -> Self
pub fn storage_batch_config(self, config: impl Into<StorageBatchConfig>) -> Self
Set the concrete storage batch-fetch configuration for this cache instance.
The config controls the batch size and concurrency used by the
provider-backed StorageBatchFetchFn. Defaults to
StorageBatchConfig::default (the CacheSpeedMode::Slow preset).
Different cache instances can use different values in the same process.
Zero values are normalized to one.
Sourcepub fn speed_mode(self, mode: CacheSpeedMode) -> Self
pub fn speed_mode(self, mode: CacheSpeedMode) -> Self
Set the storage batch-fetch profile from a preset.
Shorthand for storage_batch_config with
mode.into().
Sourcepub fn storage_fetch_strategy(self, strategy: StorageFetchStrategy) -> Self
pub fn storage_fetch_strategy(self, strategy: StorageFetchStrategy) -> Self
Choose how the cache’s batch storage fetcher loads slots.
Defaults to StorageFetchStrategy::BulkCall with
BulkCallConfig::default:
bulk eth_call state-override extraction, repaired by (and degrading
to) the point-read fetcher that storage_batch_config
tunes. Use StorageFetchStrategy::PointRead to restore the classic
per-slot behavior.
Sourcepub fn bulk_call_config(self, config: BulkCallConfig) -> Self
pub fn bulk_call_config(self, config: BulkCallConfig) -> Self
Tune the bulk eth_call extraction path.
Shorthand for storage_fetch_strategy
with StorageFetchStrategy::BulkCall(config) — e.g. raising
max_slots_per_call on a provider with a generous gas cap, or
selecting CallDispatch::CallMany
on Erigon-lineage endpoints.
Sourcepub fn block_context_requirements(self, reqs: BlockContextRequirements) -> Self
pub fn block_context_requirements(self, reqs: BlockContextRequirements) -> Self
Set which block-context header fields the cache requires.
See BlockContextRequirements. Defaults to
lenient. Only try_build
enforces non-lenient requirements at construction; the infallible
build always stays lenient.
Sourcepub fn strict_block_context(self, strict: bool) -> Self
pub fn strict_block_context(self, strict: bool) -> Self
Convenience toggle: require every block-context field (true) or none
(false).
Equivalent to
block_context_requirements with
strict /
lenient. Enforced only by
try_build.
Sourcepub async fn build(self) -> EvmCache
pub async fn build(self) -> EvmCache
Build the EvmCache, fetching the pinned block’s header for context.
If a chain ID was not set via chain_id, it is inferred
from the provider (eth_chainId); see chain_id for the
full resolution order.
This constructor is infallible and always uses
lenient enforcement (a missing
block-context field is silently defaulted). To enforce
BlockContextRequirements at construction, use
try_build instead.
Sourcepub async fn try_build(self) -> Result<EvmCache, BlockContextError>
pub async fn try_build(self) -> Result<EvmCache, BlockContextError>
Build the EvmCache, enforcing the configured
BlockContextRequirements against the fetched block header.
Builds the cache the same way build does, then, if the
requirements are non-lenient, validates the pinned block’s header:
- if the header could not be fetched (the provider errored or returned no
block), returns
BlockContextError::FetchFailed; - otherwise validates the fetched header via
BlockContextRequirements::validate_headerand propagates anyBlockContextError::MissingField.
A lenient build never errors (it
does not fetch a header solely to validate). On success the requirements
are stored on the returned cache so a later
advance_block enforces them too.
Auto Trait Implementations§
impl<P> Freeze for EvmCacheBuilder<P>
impl<P> RefUnwindSafe for EvmCacheBuilder<P>where
P: RefUnwindSafe,
impl<P> Send for EvmCacheBuilder<P>
impl<P> Sync for EvmCacheBuilder<P>
impl<P> Unpin for EvmCacheBuilder<P>
impl<P> UnsafeUnpin for EvmCacheBuilder<P>
impl<P> UnwindSafe for EvmCacheBuilder<P>where
P: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.