Skip to content

feat(app): trim and refresh the validator cache each epoch#552

Open
emlautarom1-agent[bot] wants to merge 2 commits into
mainfrom
worktree-issue-529-valcache-refresh
Open

feat(app): trim and refresh the validator cache each epoch#552
emlautarom1-agent[bot] wants to merge 2 commits into
mainfrom
worktree-issue-529-valcache-refresh

Conversation

@emlautarom1-agent

@emlautarom1-agent emlautarom1-agent Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #529

Summary

The scheduler seeds a shared ValidatorCache at startup (shipped in #536) but nothing refreshes it, so the validator set is effectively frozen for the node's lifetime: validators that activate after startup never get duties scheduled, and exited validators keep being scheduled. This adds the missing per-epoch refresh — the Rust analog of Charon's inline validator-cache loop in wireCoreWorkflow.

A ValidatorCacheRefresher is registered as a scheduler slot subscriber. On each epoch's first slot — plus the first-ever tick, and any tick following a head fallback — it trims the shared cache and re-fetches the cluster validator set by slot. Because this is the single cache instance #536 installed into the scheduler, broadcaster, and validator-API clients, one refresh updates every consumer at once.

Differences from Charon

  1. Mutex instead of RWMutex. Charon guards the bookkeeping flags with a sync.RWMutex; a plain tokio::Mutex is used here since the read/write split makes no sense for this usage pattern (the subscriber runs sequentially, one refresh at a time).
  2. Errors surface through the subscriber framework. On a failed refresh Charon calls log.Error and returns the error; Pluto returns the error and lets the scheduler's slot-subscriber loop log it with the slot and subscriber label. Both leave the bookkeeping flags untouched on failure, so the next tick retries.

Add a scheduler slot subscriber that trims and refreshes the shared
ValidatorCache on each epoch's first slot, the Rust analog of Charon's
inline refresh loop (app/app.go:484-532).

Without it the validator set is frozen at startup: validators activating
later never get duties scheduled, and exited validators keep being
scheduled. The single shared cache means one refresh covers the
scheduler, broadcaster, and validator-API consumers.

The new ValidatorCacheRefresher mirrors Charon's firstValCacheRefresh /
refreshedBySlot bookkeeping: it skips mid-epoch slots once refreshed by
slot, forces a refresh on the first tick and after any head fallback,
and re-fetches the epoch's first slot (rather than the current slot)
when the previous fetch fell back to head.

Closes #529
- Reference Charon at the function level (`wireCoreWorkflow`,
  `shouldUpdateCache`, `GetBySlot`) instead of by line number.
- Rename bookkeeping fields to match Charon's names in Rust convention:
  first_refresh -> first_val_cache_refresh, refreshed_by_slot ->
  refresh_by_slot.
- Trim the over-explanatory subscriber comment and drop the test-module
  doc comment.

@emlautarom1-agent emlautarom1-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes on deliberate deviations from Charon for reviewers.

/// resolved.
struct ValidatorCacheRefresher {
cache: ValidatorCache,
bookkeeping: tokio::sync::Mutex<RefreshBookkeeping>,

@emlautarom1-agent emlautarom1-agent Bot Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutex instead of RWMutex. The read/write split makes no sense for this usage pattern — subscribe_slot drives the subscriber sequentially, one refresh at a time.


tracing::info!(
slot = %slot.slot,
first_refresh = bk.first_val_cache_refresh,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parity quirk. The struct field is first_val_cache_refresh, but the tracing key is intentionally kept as first_refresh to match Charon's log field (z.Bool("first_refresh", firstValCacheRefresh)), so log output stays consistent with Charon.

@emlautarom1
emlautarom1 marked this pull request as ready for review July 16, 2026 15:10

@emlautarom1 emlautarom1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually reviewed, LGTM.

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.

feat(app): trim and refresh the validator cache each epoch

1 participant