Skip to content
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

feat: add metric for slot of next scheduled attestation duty #5954

Merged
merged 6 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/validator/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export function getMetrics(register: MetricsRegister, gitData: LodestarGitData)
help: "Total count of instances the attester duties dependant root changed",
}),

attesterDutiesNextSlot: register.gauge({
name: "vc_attestation_duty_slot",
nflaig marked this conversation as resolved.
Show resolved Hide resolved
help: "Slot of next scheduled attestation duty",
}),

// BlockProposingService

blocksProduced: register.gauge({
Expand Down
22 changes: 21 additions & 1 deletion packages/validator/src/services/attestationDuties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,32 @@ export class AttestationDutiesService {

if (metrics) {
metrics.attesterDutiesCount.addCollect(() => {
const currentSlot = this.clock.getCurrentSlot();
let duties = 0;
for (const attDutiesAtEpoch of this.dutiesByIndexByEpoch.values()) {
let nextDutySlot = null;
for (const [epoch, attDutiesAtEpoch] of this.dutiesByIndexByEpoch) {
duties += attDutiesAtEpoch.dutiesByIndex.size;

// Historical epochs can be skipped when determining next duty slot
if (epoch < this.clock.currentEpoch) continue;
nflaig marked this conversation as resolved.
Show resolved Hide resolved

// There is no need to check every single duty at a certain amount
twoeths marked this conversation as resolved.
Show resolved Hide resolved
// of validators, next duty slot will almost always be the next slot
if (attDutiesAtEpoch.dutiesByIndex.size >= 64) {
nextDutySlot = currentSlot + 1;
continue;
}

for (const {duty} of attDutiesAtEpoch.dutiesByIndex.values()) {
// Set next duty slot to the closest future slot found in all duties
if (duty.slot > currentSlot && (nextDutySlot === null || duty.slot < nextDutySlot)) {
nextDutySlot = duty.slot;
}
}
}
metrics.attesterDutiesCount.set(duties);
metrics.attesterDutiesEpochCount.set(this.dutiesByIndexByEpoch.size);
if (nextDutySlot !== null) metrics.attesterDutiesNextSlot.set(nextDutySlot);
});
}
}
Expand Down
Loading