pub struct FreshnessController<P: FreshnessPolicy, C: FreshnessClock> { /* private fields */ }Expand description
Drives the optimistic verify-and-rerun loop over an EvmCache.
Holds the freshness FreshnessRegistry, the shared
SlotObservationTracker, a FreshnessPolicy, a FreshnessClock, and
the pending-corrections queue. The tracker and the pending queue are
Arc<Mutex<…>> so the background validator can update them without touching
the !Send cache. Adaptive thresholds (FreshnessParams) live on the
policy that uses them (ObservationDriven), not on the controller.
§Runtime requirement
run spawns a background task and the (synchronous) fetcher uses
block_in_place internally, so a multi-thread tokio runtime is required
(#[tokio::main(flavor = "multi_thread")] or
Builder::new_multi_thread()), mirroring the EvmCache constructor note.
Implementations§
Source§impl<P: FreshnessPolicy> FreshnessController<P, BlockClock>
impl<P: FreshnessPolicy> FreshnessController<P, BlockClock>
Sourcepub fn new(registry: FreshnessRegistry, policy: P) -> Self
pub fn new(registry: FreshnessRegistry, policy: P) -> Self
Build a controller with the default BlockClock (starting at block 0).
Starts with a fresh, empty SlotObservationTracker and an empty
pending-corrections queue. Use with_tracker to share
a persisted tracker, or with_clock for a non-default
clock such as WallClock.
Source§impl<P: FreshnessPolicy, C: FreshnessClock> FreshnessController<P, C>
impl<P: FreshnessPolicy, C: FreshnessClock> FreshnessController<P, C>
Sourcepub fn with_clock(registry: FreshnessRegistry, policy: P, clock: C) -> Self
pub fn with_clock(registry: FreshnessRegistry, policy: P, clock: C) -> Self
Build a controller with an explicit clock.
Starts with a fresh, empty SlotObservationTracker and an empty
pending-corrections queue. The clock’s units must match those the
policy’s FreshnessParams were tuned for (block numbers for
BlockClock, unix seconds for WallClock).
Sourcepub fn with_tracker(self, tracker: Arc<Mutex<SlotObservationTracker>>) -> Self
pub fn with_tracker(self, tracker: Arc<Mutex<SlotObservationTracker>>) -> Self
Use an existing shared observation tracker (e.g. a persisted one).
Builder-style override that replaces the fresh tracker installed by
new / with_clock with the given shared
handle, so change-frequency history survives across runs or is shared with
other components. The background validator updates this same tracker under
its Mutex.
Sourcepub fn registry(&self) -> &FreshnessRegistry
pub fn registry(&self) -> &FreshnessRegistry
The freshness registry.
Sourcepub fn registry_mut(&mut self) -> &mut FreshnessRegistry
pub fn registry_mut(&mut self) -> &mut FreshnessRegistry
Mutable access to the freshness registry.
Sourcepub fn pending_len(&self) -> usize
pub fn pending_len(&self) -> usize
Number of corrections waiting to be drained into the cache on the next
run.
Sourcepub fn rerun_count(&self) -> usize
pub fn rerun_count(&self) -> usize
Cumulative number of background re-runs performed by the validator across
all run calls so far.
Incremented once per sim that the reconcile step actually re-executes
(i.e. whose read set intersected a changed slot). A Corrected verdict
over n requests where only one slot changed advances this by the number
of affected sims, not by n — making the selective-re-run behavior
directly observable.
Sourcepub fn on_new_block(&mut self, block: u64)
pub fn on_new_block(&mut self, block: u64)
Advance to a new block.
Advances the clock to block (a no-op for WallClock, a set_block
for BlockClock) and then notifies the policy. Advancing the clock is
what ages Validity::ValidThrough slots into Validity::Volatile and
progresses the observation-tracker reuse window through the natural API.
Sourcepub fn run(
&mut self,
cache: &mut EvmCache,
requests: Vec<SimRequest>,
) -> Result<SpeculativeSim>
pub fn run( &mut self, cache: &mut EvmCache, requests: Vec<SimRequest>, ) -> Result<SpeculativeSim>
Run the optimistic loop for a batch of requests.
- Drain queued corrections from prior cycles into the cache.
- Snapshot the cache and grab the batch fetcher.
- Run each request optimistically against the snapshot, capturing its actual volatile read set.
- Compute the predicted volatile candidates and ask the policy which to verify.
- Spawn the background validator (Send data only) and return a
SpeculativeSimimmediately.
§Panics
Must be called from within a tokio runtime: it calls tokio::spawn to
launch the background validator, which panics (there is no reactor running) if no runtime is active. The spawned (synchronous) fetcher
additionally uses tokio::task::block_in_place internally, so the runtime
must be multi-thread (#[tokio::main(flavor = "multi_thread")] or
Builder::new_multi_thread()); on a current-thread runtime block_in_place
panics, mirroring the EvmCache constructor note.
§Errors
Returns an error if any optimistic simulation fails to execute against the
freshly-created snapshot (propagated from
EvmOverlay::call_raw_with_access_list).
Auto Trait Implementations§
impl<P, C> Freeze for FreshnessController<P, C>
impl<P, C> RefUnwindSafe for FreshnessController<P, C>where
P: RefUnwindSafe,
C: RefUnwindSafe,
impl<P, C> Send for FreshnessController<P, C>
impl<P, C> Sync for FreshnessController<P, C>where
P: Sync,
impl<P, C> Unpin for FreshnessController<P, C>
impl<P, C> UnsafeUnpin for FreshnessController<P, C>where
P: UnsafeUnpin,
C: UnsafeUnpin,
impl<P, C> UnwindSafe for FreshnessController<P, C>where
P: UnwindSafe,
C: UnwindSafe,
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.