Repository navigation
app/eth2wrap: derive epoch validators from cached records - #4874
KaloyanTanev wants to merge 1 commit into
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4874 +/- ##
==========================================
+ Coverage 70.47% 70.54% +0.06%
==========================================
Files 284 284
Lines 37308 37346 +38
==========================================
+ Hits 26293 26345 +52
+ Misses 11014 11000 -14
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical flaws in stale-head validity, concurrent epoch updates, and reorg handling can serve incorrect active validator sets or leave stale indices in use.
3 open issues
What changed in this PR
This PR reduces epoch-boundary blocking in Charon by deriving validator sets from cached activation and exit epochs.
Changes:
- Refreshes validator records late in eligible slots and limits cache validity after reorgs.
- Uses the validator cache only for
headrequests. - Adds cache lifecycle tests and consistent mock validator epochs.
| File | Description |
|---|---|
| testutil/random.go | Makes random validator epochs consistent. |
| testutil/beaconmock/options.go | Updates mock activation and exit epochs. |
| core/validatorapi/validatorapi.go | Bypasses the cache for non-head states. |
| core/validatorapi/validatorapi_test.go | Tests non-head request forwarding. |
| app/vmock.go | Supplies epoch timing and lookahead to the cache. |
| app/eth2wrap/utils.go | Adds network lookahead retrieval. |
| app/eth2wrap/utils_test.go | Tests lookahead retrieval and validation. |
| app/eth2wrap/cache.go | Derives validator sets and handles refreshes and reorgs. |
| app/eth2wrap/cache_test.go | Tests derivation, concurrency, refreshes, and invalidation. |
| app/app.go | Wires cache refresh and duties updates separately. |
| app/app_internal_test.go | Tests refresh scheduling and duties updates. |
Review effort: Balanced
| var updated atomic.Bool | ||
|
|
||
| return func(ctx context.Context, slot core.Slot) error { | ||
| if !slot.FirstInEpoch() && updated.Load() { | ||
| return nil |
| // The head state may still be in the previous epoch. | ||
| c.validThrough = epoch + c.maxSeedLookahead - 1 |
| missedCacheCount.WithLabelValues("validators").Inc() | ||
|
|
||
| refreshedBySlot := true | ||
| return c.store(fetched, epoch) |
OisinKyne
left a comment
There was a problem hiding this comment.
LGTM. I checked the lookahead argument against the spec (activation and exit epochs are always ≥ MAX_SEED_LOOKAHEAD + 1 ahead, electra exit queue and consolidations included), and the reorg bound of epoch + MAX_SEED_LOOKAHEAD is exactly right. Race tests pass locally. Small things, none blocking:
- A Refresh whose fetch starts before a reorg more than one epoch deep and stores after InvalidateCache restores the full window. Rare, but a counter bumped by InvalidateCache and checked in store would close it.
- Refresh increments the validators miss counter every epoch, so misses no longer mean a caller waited. Maybe a separate label?
- valCacheRefreshSlot never allows a refresh with fewer than 4 slots per epoch. That's only test configs, but worth a comment.




Stops the validator cache refresh from blocking the validator API and the scheduler at every epoch start. The cache now derives each epoch's active set and statuses from the activation and exit epochs of the validators it last fetched, which the chain assigns at least
MAX_SEED_LOOKAHEAD + 1epochs ahead, so no beacon node call is needed at the boundary.ValidatorCache.Refreshfetches the head state once an epoch, from the third slot on and late in the slot, without holding the lock. Fetched validators are trusted forMAX_SEED_LOOKAHEAD - 1epochs ahead, since the head state may be an epoch behind.headstate from the cache; other state ids go to the beacon node.testutilget consistent activation and exit epochs, as statuses are derived from them.category: bug
ticket: none