Skip to main content

evm_fork_cache/cold_start/
planner.rs

1//! The pure planner that drives a bounded multi-round cold start.
2//!
3//! A [`ColdStartPlanner`] performs no IO: the driver performs every fetch and
4//! call and hands the planner only a [`StateView`] and the round's
5//! [`ColdStartResults`]. The planner decides the next plan (or stops).
6
7use crate::cold_start::plan::ColdStartPlan;
8use crate::cold_start::results::ColdStartResults;
9use crate::events::StateView;
10
11/// The planner's decision after a round completes.
12#[derive(Clone, Debug)]
13pub enum ColdStartStep {
14    /// Stop the cold-start loop; the run succeeds.
15    Done,
16    /// Execute the carried plan as the next round.
17    Continue(ColdStartPlan),
18}
19
20/// Drives a bounded multi-round cold start.
21///
22/// The driver calls [`initial_plan`](Self::initial_plan) once, executes it, then
23/// repeatedly calls [`on_results`](Self::on_results) with the round's results and
24/// the post-injection [`StateView`]; a returned [`ColdStartStep::Continue`] is run
25/// as the next round and [`ColdStartStep::Done`] ends the run. The loop is bounded
26/// by [`ColdStartConfig::max_rounds`](crate::cold_start::ColdStartConfig::max_rounds).
27///
28/// Implementations perform **no IO** — the trait hands them only borrowed,
29/// read-only state, so all fetching is the driver's responsibility.
30pub trait ColdStartPlanner {
31    /// The first plan to execute, derived from the current cached state.
32    fn initial_plan(&mut self, state: &dyn StateView) -> ColdStartPlan;
33    /// Decide whether to continue (with a next plan) or finish, given the just-
34    /// completed round's results and the post-injection state view.
35    fn on_results(&mut self, results: &ColdStartResults, state: &dyn StateView) -> ColdStartStep;
36}