-
-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Log validator index, status and pubkey each epoch #5161
Changes from all commits
01b32cb
a7a778d
fe09b0d
b4eac94
2a9b72f
1014495
f1f0e36
aa79941
26e35d0
ba679cc
9250c53
f1f54aa
31a3879
cd71135
6e27d85
50825d1
07e9d07
7a2110a
d8094a4
700b062
5eb7541
335ebbc
b01b460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||||||||
import {ValidatorIndex} from "@lodestar/types"; | ||||||||||||
import {Logger} from "@lodestar/utils"; | ||||||||||||
import {Logger, MapDef} from "@lodestar/utils"; | ||||||||||||
import {toHexString} from "@chainsafe/ssz"; | ||||||||||||
import {Api, ApiError} from "@lodestar/api"; | ||||||||||||
import {Api, ApiError, routes} from "@lodestar/api"; | ||||||||||||
import {batchItems} from "../util/index.js"; | ||||||||||||
import {Metrics} from "../metrics.js"; | ||||||||||||
|
||||||||||||
|
@@ -14,6 +14,31 @@ const PUBKEYS_PER_REQUEST = 10; | |||||||||||
// To assist with readability | ||||||||||||
type PubkeyHex = string; | ||||||||||||
|
||||||||||||
// To assist with logging statuses, we only log the statuses that are not active_exiting or withdrawal_possible | ||||||||||||
type SimpleValidatorStatus = "pending" | "active" | "exited" | "withdrawn"; | ||||||||||||
|
||||||||||||
const statusToSimpleStatusMapping = (status: routes.beacon.ValidatorStatus): SimpleValidatorStatus => { | ||||||||||||
switch (status) { | ||||||||||||
case "active": | ||||||||||||
case "active_exiting": | ||||||||||||
case "active_slashed": | ||||||||||||
case "active_ongoing": | ||||||||||||
return "active"; | ||||||||||||
|
||||||||||||
case "withdrawal_possible": | ||||||||||||
case "exited_slashed": | ||||||||||||
case "exited_unslashed": | ||||||||||||
return "exited"; | ||||||||||||
|
||||||||||||
case "pending_initialized": | ||||||||||||
case "pending_queued": | ||||||||||||
return "pending"; | ||||||||||||
|
||||||||||||
case "withdrawal_done": | ||||||||||||
return "withdrawn"; | ||||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
export class IndicesService { | ||||||||||||
readonly index2pubkey = new Map<ValidatorIndex, PubkeyHex>(); | ||||||||||||
/** Indexed by pubkey in hex 0x prefixed */ | ||||||||||||
|
@@ -90,7 +115,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,15 +125,39 @@ export class IndicesService { | |||||||||||
ApiError.assert(res, "Can not fetch state validators from beacon node"); | ||||||||||||
|
||||||||||||
const newIndices = []; | ||||||||||||
|
||||||||||||
const allValidatorStatuses = new MapDef<SimpleValidatorStatus, number>(() => 0); | ||||||||||||
|
||||||||||||
for (const validatorState of res.response.data) { | ||||||||||||
// Group all validators by status | ||||||||||||
const status = statusToSimpleStatusMapping(validatorState.status); | ||||||||||||
allValidatorStatuses.set(status, allValidatorStatuses.getOrDefault(status) + 1); | ||||||||||||
|
||||||||||||
const pubkeyHex = toHexString(validatorState.validator.pubkey); | ||||||||||||
if (!this.pubkey2index.has(pubkeyHex)) { | ||||||||||||
this.logger.debug("Discovered validator", {pubkey: pubkeyHex, index: validatorState.index}); | ||||||||||||
this.logger.info("Validator exists in beacon chain", { | ||||||||||||
validatorIndex: validatorState.index, | ||||||||||||
pubKey: pubkeyHex, | ||||||||||||
}); | ||||||||||||
this.pubkey2index.set(pubkeyHex, validatorState.index); | ||||||||||||
this.index2pubkey.set(validatorState.index, pubkeyHex); | ||||||||||||
newIndices.push(validatorState.index); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
// The number of validators that are not in the beacon chain | ||||||||||||
const pendingCount = pubkeysHex.length - res.response.data.length; | ||||||||||||
|
||||||||||||
allValidatorStatuses.set("pending", allValidatorStatuses.getOrDefault("pending") + pendingCount); | ||||||||||||
|
||||||||||||
// Retrieve the number of validators for each status | ||||||||||||
const statuses = Object.fromEntries(Array.from(allValidatorStatuses.entries()).filter((entry) => entry[1] > 0)); | ||||||||||||
|
||||||||||||
// The total number of validators | ||||||||||||
const total = pubkeysHex.length; | ||||||||||||
|
||||||||||||
this.logger.info("Validator statuses", {...statuses, total}); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maschad wondering here, wasn't this intended to be logged every epoch? Once we discovered all pubkey we are not calling this due to this check lodestar/packages/validator/src/services/indices.ts Lines 102 to 106 in ddc58ce
I guess this should be fixed by the other PR #5239 |
||||||||||||
|
||||||||||||
return newIndices; | ||||||||||||
} | ||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maschad running this on goerli with quite a lot of validators and this inital log is quite noisy in my opinion, we are printing out
Validator exists in beacon chain
for each validator which seems bit redundant because these logs all happen after each other.I think we should reconsider this and maybe only print out
Validator exists in beacon chain
once and then just list all the validators, with index, pubkey and ideally also fee recipient (if possible)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've included that change in be5a7e4