Skip to content

refactor(eth2api): make ValidatorCache immutable in BeaconNodeClient - #667

Open
varex83agent wants to merge 1 commit into
mainfrom
feat/fix-482
Open

refactor(eth2api): make ValidatorCache immutable in BeaconNodeClient#667
varex83agent wants to merge 1 commit into
mainfrom
feat/fix-482

Conversation

@varex83agent

Copy link
Copy Markdown
Collaborator

Summary

BeaconNodeClient held its ValidatorCache as Arc<RwLock<Option<ValidatorCache>>>, initialized to None and populated later via set_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 ValidatorCache once in node::run and threads it into both the scheduler and submission BeaconNodeClients at construction.

Changes

  • BeaconNodeClient::new now takes the ValidatorCache and stores it as a plain field (ValidatorCache is already Arc-backed, so clones seeded into each client share state — a single per-epoch refresh still updates every consumer).
  • Removed the Arc<RwLock<Option<..>>> wrapping, the set_validator_cache setter, and the NoActiveValidatorCache error variant.
  • validator_cache() returns &ValidatorCache; dropped the .expect/TODO at the scheduler read site.
  • Updated wiring (node::run / wire_core_workflow) to construct-and-seed the shared cache up front instead of set_validator_cache after the fact, and all tests to the new constructor.

Testing

  • cargo +nightly fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — clean
  • cargo test -p pluto-eth2api -p pluto-core -p pluto-app — all pass (eth2api 133, core 605, app 141)

Closes #482

🤖 Generated with Claude Code

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>
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.

Make ValidatorCache in BeaconNodeClient immutable

1 participant