Skip to content

Add protocol-neutral cold-start sync (reactive feature) - #12

Merged
KaiCode2 merged 2 commits into
codex/reactive-reorg-recoveryfrom
cold-start-sync
Jun 23, 2026
Merged

Add protocol-neutral cold-start sync (reactive feature)#12
KaiCode2 merged 2 commits into
codex/reactive-reorg-recoveryfrom
cold-start-sync

Conversation

@KaiCode2

Copy link
Copy Markdown
Owner

Summary

Adds a protocol-neutral cold-start sync mechanism to evm-fork-cache, gated under the existing reactive feature. A consumer declares the storage it needs warmed on startup and drives a bounded multi-round loop via a pure ColdStartPlanner — the driver owns all fetch/call IO, the planner owns all protocol decisions.

The headline win is a per-slot SlotFetch (Value / Zero / FetchFailed / NotAttempted) that closes the archive-miss gap: a fetch failure is now distinct from a genuine on-chain zero, which verify_slots could not express (it dropped per-slot Errs and kept only an aggregate count).

Base: this PR stacks on codex/reactive-reorg-recovery (the rev evm-amm-state pins). Motivating consumer: the AMM cold-start work in evm-amm-state (V3 slot0, V2 reserves, Balancer getPoolTokens access-list discovery) — adoption is a separate follow-up in that repo.

What's in it

A ColdStartPlan declares four independent, optional phases run in fixed order accounts → verify → probe → discover:

  • verify — authoritative pinned re-fetch + dual-layer injection (inject_storage_batch_fresh), with a per-slot outcome.
  • probe — classify at the pinned block without injecting (archive-miss check for slots you don't want to warm).
  • accountsensure_account pre-seeding before discovery.
  • discover — view-call access-list capture via call_raw_with_access_list, with an optional restrict_to filter.

A Done | Continue(next_plan) continuation drives data-dependent multi-round cold starts; ColdStartPin::Hash { require_canonical } pins a whole run to a hash and restores the prior block on every exit path.

New / changed

  • src/cold_start/ (new, gated): ColdStartPlan/Call/Results/CallResult/RoundOutcome, ColdStartPlanner/Step, ColdStartConfig/Pin/RunReport/RoundSummary, ColdStartError, and EvmCache::{execute_cold_start_round, run_cold_start}.
  • src/freshness.rs: SlotOutcome / SlotFetch (ungated, beside SlotChange).
  • src/cache/mod.rs: verify_slots_core extraction (verify_slots / reconcile_slots behaviour unchanged), verify_slots_with_outcomes, ensure_account_blocking; classify + block_in_place_handle widened to pub(crate).
  • tests/cold_start.rs (new): 19 offline acceptance tests; setup_cache_with_asserter added to tests/common.

Design notes

  • Composition, not reinvention — every phase composes an existing primitive (verify_slots_inner, inject_storage_batch_fresh, call_raw_with_access_list, ensure_account, StorageBatchFetchFn); SlotChange and StorageAccessList are reused verbatim.
  • No AMM concepts enter evm-fork-cache.
  • Mid-round honestyexecute_cold_start_round returns RoundOutcome { results, error }, carrying partial results in the return type; on an accounts-phase hard error every unreached verify/probe slot is marked NotAttempted, the round is absorbed into the report, and on_results is skipped.
  • Cold-start stays an EvmCache-level mechanism (no ReactiveRuntime coupling); require_canonical: true hash-pinning is its standalone reorg defense.

Validation (full release gate, all green)

cargo test · cargo test --no-default-features · cargo fmt --all --check · cargo clippy --all-targets --no-deps -- -D warnings · RUSTDOCFLAGS="-D warnings" cargo doc --no-deps (default + --no-default-features) · cargo +1.88.0 check --lib --locked · git diff --check. 19/19 cold-start tests pass; existing suite unaffected.

Not in scope (follow-up)

Consumer adoption in evm-amm-state (V2/V3/Balancer ColdStartPlanner impls, migrating its cold_start tests, bumping the pinned rev) — handoff doc to follow.

🤖 Generated with Claude Code

KaiCode2 and others added 2 commits June 23, 2026 14:59
Adds a cold-start sync mechanism gated under the existing `reactive` feature:
a consumer declares the storage to warm on startup (verify / probe / accounts /
discover) and drives a bounded multi-round loop via a pure `ColdStartPlanner`.
Surfaces a per-slot `SlotFetch` (Value / Zero / FetchFailed / NotAttempted)
that closes the archive-miss gap — distinguishing a genuine on-chain zero from
a fetch failure, which `verify_slots` could not express.

- src/cold_start/: ColdStartPlan/Call/Results/CallResult/RoundOutcome,
  ColdStartPlanner/Step, ColdStartConfig/Pin/RunReport, ColdStartError, and the
  driver methods EvmCache::{execute_cold_start_round, run_cold_start}.
- src/freshness.rs: SlotOutcome / SlotFetch (ungated, beside SlotChange).
- src/cache/mod.rs: verify_slots_core extraction (verify_slots / reconcile_slots
  behaviour unchanged), verify_slots_with_outcomes, ensure_account_blocking;
  classify and block_in_place_handle widened to pub(crate).
- 19 offline acceptance tests (tests/cold_start.rs) + setup_cache_with_asserter.

Composes existing primitives (verify_slots_inner, inject_storage_batch_fresh,
call_raw_with_access_list, ensure_account, StorageBatchFetchFn). No AMM concepts
enter evm-fork-cache. `cargo test --no-default-features` stays green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- ColdStartRunReport / run_cold_start: clarify the report is returned only on
  the Ok path; on error it is dropped (use execute_cold_start_round to observe a
  failed round's partial outcomes).
- discovered_accounts / discovered_slots: drop "distinct" — they are sums across
  calls and rounds, not de-duplicated.
- ColdStartResults: document that fetched/probed order is unspecified (look up
  by (address, slot)).

Doc-only; no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@KaiCode2
KaiCode2 merged commit 9762ed7 into codex/reactive-reorg-recovery Jun 23, 2026
2 checks passed
@KaiCode2
KaiCode2 deleted the cold-start-sync branch June 30, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant