From b4eac94e6851c2f87a320c884f3ea7bcd6b51824 Mon Sep 17 00:00:00 2001 From: chad Date: Tue, 21 Feb 2023 20:47:22 -0500 Subject: [PATCH] Update logs to include total validator availability count (#4785) --- packages/validator/src/services/indices.ts | 28 +++++++++++++------ .../src/services/prepareBeaconProposer.ts | 19 +++++++++---- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/validator/src/services/indices.ts b/packages/validator/src/services/indices.ts index 512cdb370872..216ebbedcfde 100644 --- a/packages/validator/src/services/indices.ts +++ b/packages/validator/src/services/indices.ts @@ -2,6 +2,7 @@ import {ValidatorIndex} from "@lodestar/types"; import {ILogger} from "@lodestar/utils"; import {toHexString} from "@chainsafe/ssz"; import {Api, ApiError} from "@lodestar/api"; +import {ValidatorResponse, ValidatorStatus} from "@lodestar/api/lib/beacon/routes/beacon/state.js"; import {batchItems} from "../util/index.js"; import {Metrics} from "../metrics.js"; @@ -90,7 +91,6 @@ export class IndicesService { newIndices.push(...validatorIndicesArr); } - this.logger.info("Discovered new validators", {count: newIndices.length}); this.metrics?.discoveredIndices.inc(newIndices.length); return newIndices; @@ -101,22 +101,34 @@ export class IndicesService { ApiError.assert(res, "Can not fetch state validators from beacon node"); const newIndices = []; + + const allValidators = new Map(); + for (const validatorState of res.response.data) { + // Group all validators by status + allValidators.set(validatorState.status, [validatorState]); + const pubkeyHex = toHexString(validatorState.validator.pubkey); if (!this.pubkey2index.has(pubkeyHex)) { this.logger.debug("Discovered validator", {pubkey: pubkeyHex, index: validatorState.index}); this.pubkey2index.set(pubkeyHex, validatorState.index); this.index2pubkey.set(validatorState.index, pubkeyHex); newIndices.push(validatorState.index); - } else { - this.logger.info( - `Validator: - status=${validatorState.status || "unknown"} - index=${this.pubkey2index.get(pubkeyHex)} - pubkey=${pubkeyHex}` - ); } } + + allValidators.get("active")?.forEach((validatorState: ValidatorResponse) => { + this.logger.info("Validator activated", { + pubkey: toHexString(validatorState.validator.pubkey), + index: validatorState.index, + }); + }); + + this.logger.info("Initialized Validators: ", { + total: allValidators.size, + available: allValidators.get("active")?.length, + }); + return newIndices; } } diff --git a/packages/validator/src/services/prepareBeaconProposer.ts b/packages/validator/src/services/prepareBeaconProposer.ts index dcc9eff29f4e..7179c00a4534 100644 --- a/packages/validator/src/services/prepareBeaconProposer.ts +++ b/packages/validator/src/services/prepareBeaconProposer.ts @@ -1,8 +1,9 @@ import {Epoch, bellatrix} from "@lodestar/types"; -import {Api, ApiError, routes} from "@lodestar/api"; +import {Api, ApiError} from "@lodestar/api"; import {IBeaconConfig} from "@lodestar/config"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {ProposerPreparationData} from "@lodestar/api/lib/beacon/routes/validator.js"; import {IClock, ILoggerVc, batchItems} from "../util/index.js"; import {Metrics} from "../metrics.js"; import {ValidatorStore} from "./validatorStore.js"; @@ -37,13 +38,19 @@ export function pollPrepareBeaconProposer( const indicesChunks = batchItems(validatorStore.getAllLocalIndices(), {batchSize: REGISTRATION_CHUNK_SIZE}); for (const indices of indicesChunks) { + const proposers: ProposerPreparationData[] = []; try { - const proposers = indices.map( - (index): routes.validator.ProposerPreparationData => ({ + indices.forEach((index) => { + const feeRecipient = validatorStore.getFeeRecipientByIndex(index); + const pubKey = validatorStore.getPubkeyOfIndex(index); + + proposers.push({ validatorIndex: String(index as number), - feeRecipient: validatorStore.getFeeRecipientByIndex(index), - }) - ); + feeRecipient, + }); + + logger.info("Validator exists in Beacon Chain", {validatorIndex: index, feeRecipient, pubKey}); + }); ApiError.assert(await api.validator.prepareBeaconProposer(proposers)); } catch (e) { logger.error("Failed to register proposers with beacon", {epoch}, e as Error);