refactor(eth2api): make ValidatorCache immutable in BeaconNodeClient - #667
Open
varex83agent wants to merge 1 commit into
Open
refactor(eth2api): make ValidatorCache immutable in BeaconNodeClient#667varex83agent wants to merge 1 commit into
varex83agent wants to merge 1 commit into
Conversation
The validator set is known at node construction (from the cluster validators), so the cache no longer needs to be optional, mutable, or shared behind a lock. Build a single `ValidatorCache` in `node::run` and thread it into both the scheduler and submission `BeaconNodeClient`s at construction. - `BeaconNodeClient::new` now takes the `ValidatorCache` and stores it as a plain field (the type is already `Arc`-backed, so clones share state). - Remove the `Arc<RwLock<Option<..>>>` wrapping, the `set_validator_cache` setter, and the `NoActiveValidatorCache` error variant. - `validator_cache()` returns `&ValidatorCache`; drops the `.expect`/TODO at the scheduler read site. Closes #482 Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
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.
Summary
BeaconNodeClientheld itsValidatorCacheasArc<RwLock<Option<ValidatorCache>>>, initialized toNoneand populated later viaset_validator_cache, so every read had to handle a "not yet set" case that leaked into callers (the scheduler's.expect("validator cache is available")).The validator set is actually known at node construction (from the cluster's validators), so this optionality was never needed. This PR builds a single
ValidatorCacheonce innode::runand threads it into both the scheduler and submissionBeaconNodeClients at construction.Changes
BeaconNodeClient::newnow takes theValidatorCacheand stores it as a plain field (ValidatorCacheis alreadyArc-backed, so clones seeded into each client share state — a single per-epoch refresh still updates every consumer).Arc<RwLock<Option<..>>>wrapping, theset_validator_cachesetter, and theNoActiveValidatorCacheerror variant.validator_cache()returns&ValidatorCache; dropped the.expect/TODO at the scheduler read site.node::run/wire_core_workflow) to construct-and-seed the shared cache up front instead ofset_validator_cacheafter the fact, and all tests to the new constructor.Testing
cargo +nightly fmt --all --checkcargo clippy --workspace --all-targets --all-features -- -D warnings— cleancargo test -p pluto-eth2api -p pluto-core -p pluto-app— all pass (eth2api 133, core 605, app 141)Closes #482
🤖 Generated with Claude Code