Skip to content

Commit

Permalink
feat: add metric for slot of next scheduled attestation duty (#5954)
Browse files Browse the repository at this point in the history
* feat: add metric for slot of next scheduled attestation duty

* Remove .entries() when iterating over dutiesByIndexByEpoch

* Set duty slot to next slot if more than 64 validators

* Add comment to explain metric name and usage

* Remove validator count check

* Stop searching once a next duty slot is found
  • Loading branch information
nflaig authored Sep 15, 2023
1 parent 6d8b42c commit 37f404f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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",
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

0 comments on commit 37f404f

Please sign in to comment.