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 all 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
8 changes: 8 additions & 0 deletions packages/validator/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ export function getMetrics(register: MetricsRegister, gitData: LodestarGitData)
help: "Total count of instances the attester duties dependant root changed",
}),

attesterDutiesNextSlot: register.gauge({
// Metric is used by Rocket Pool dashboard (18391) to determine seconds until next attestation.
// It works without requiring any modification to the dashboard as the metric name is the
// same as Lighthouse uses for this.
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
15 changes: 14 additions & 1 deletion packages/validator/src/services/attestationDuties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ 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;

// Epochs are sorted, stop searching once a next duty slot is found
if (epoch < this.clock.currentEpoch || nextDutySlot !== null) 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