feat(app): trim and refresh the validator cache each epoch#552
Open
emlautarom1-agent[bot] wants to merge 2 commits into
Open
feat(app): trim and refresh the validator cache each epoch#552emlautarom1-agent[bot] wants to merge 2 commits into
emlautarom1-agent[bot] wants to merge 2 commits into
Conversation
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.
| /// resolved. | ||
| struct ValidatorCacheRefresher { | ||
| cache: ValidatorCache, | ||
| bookkeeping: tokio::sync::Mutex<RefreshBookkeeping>, |
Contributor
Author
There was a problem hiding this comment.
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, |
Contributor
Author
There was a problem hiding this comment.
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
marked this pull request as ready for review
July 16, 2026 15:10
emlautarom1
approved these changes
Jul 16, 2026
emlautarom1
left a comment
Collaborator
There was a problem hiding this comment.
Manually reviewed, LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #529
Summary
The scheduler seeds a shared
ValidatorCacheat 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 inwireCoreWorkflow.A
ValidatorCacheRefresheris 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
Mutexinstead ofRWMutex. Charon guards the bookkeeping flags with async.RWMutex; a plaintokio::Mutexis used here since the read/write split makes no sense for this usage pattern (the subscriber runs sequentially, one refresh at a time).log.Errorand 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.