Skip to content

Commit

Permalink
Update logs to include total validator availability count (#4785)
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Feb 22, 2023
1 parent fe09b0d commit b4eac94
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
28 changes: 20 additions & 8 deletions packages/validator/src/services/indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand All @@ -101,22 +101,34 @@ export class IndicesService {
ApiError.assert(res, "Can not fetch state validators from beacon node");

const newIndices = [];

const allValidators = new Map<ValidatorStatus, ValidatorResponse[]>();

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;
}
}
19 changes: 13 additions & 6 deletions packages/validator/src/services/prepareBeaconProposer.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b4eac94

Please sign in to comment.