Skip to content

Add iter_validators_by_ids - #834

Merged
evgeny-stakewise merged 2 commits into
masterfrom
iter-validators-by-ids
Sep 3, 2026
Merged

Add iter_validators_by_ids#834
evgeny-stakewise merged 2 commits into
masterfrom
iter-validators-by-ids

Conversation

@evgeny-stakewise

@evgeny-stakewise evgeny-stakewise commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds iter_validators_by_ids in src/validators/consensus.py — an async generator that fetches beacon validators in chunks of settings.validators_fetch_chunk_size and yields flat ConsensusValidator instances. Callers no longer deal with batching or with the raw beacon dict.

async def iter_validators_by_ids(
    validator_ids: Sequence[str] | Sequence[HexStr],
    state_id: str = 'head',
    consensus_client: ExtendedAsyncBeacon | None = None,
) -> AsyncIterator[ConsensusValidator]

consensus_client defaults to the shared singleton, imported as default_consensus_client. It is overridable because node-status deliberately builds its own non-retry, 10s-timeout client to fail fast.

Changes

  • src/validators/consensus.py — new iter_validators_by_ids; fetch_consensus_validators becomes a one-line async comprehension over it.
  • src/exits/consensus.py — replaces manual range() slicing; int(beacon_validator['index']) and the raw pubkey lookup become validator.index / validator.public_key.
  • src/commands/recover.py — replaces manual range() slicing; the pubkey/status normalization collapses to validator_statuses[validator.public_key] = validator.status.
  • src/nodewise/status.py_get_number_of_active_validators now iterates instead of issuing one unbatched request for every keystore public key, passing its own fail-fast client.

Normalization (0x-prefixing the pubkey, int() on the index, ValidatorStatus(...) on the status) now happens in one place: ConsensusValidator.from_consensus_data.

Behavior notes

  • get_validator_public_keys in src/exits/consensus.py now returns 0x-prefixed public keys, consistent with the rest of the codebase.
  • nodewise validator activity stats are now batched. Previously all keystore public keys went out in a single request, which could exceed request-size limits on a large keystore directory.

Tests

  • New patch_consensus_client helper in src/common/tests/utils.py replaces 11 copies of the same patch('src.validators.consensus...') string across three test files.
  • @contextmanager functions annotated -> Iterator[...] are deprecated in typeshed; switched to Generator[..., None, None] in the touched test files.

@evgeny-stakewise
evgeny-stakewise merged commit e718c51 into master Sep 3, 2026
10 checks passed
@evgeny-stakewise
evgeny-stakewise deleted the iter-validators-by-ids branch September 3, 2026 07:28
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.

2 participants