Skip to content

Commit

Permalink
fix: queued attestations metric (#7158)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths authored Oct 14, 2024
1 parent 2a7f7e6 commit b5c6043
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/beacon-node/src/metrics/metrics/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function createBeaconMetrics(register: RegistryMetricCreator) {
}),
queuedAttestations: register.gauge({
name: "beacon_fork_choice_queued_attestations_count",
help: "Current count of queued_attestations in fork choice data structures",
help: "Count of queued_attestations in fork choice per slot",
}),
validatedAttestationDatas: register.gauge({
name: "beacon_fork_choice_validated_attestation_datas_count",
Expand Down
17 changes: 12 additions & 5 deletions packages/fork-choice/src/forkChoice/forkChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export class ForkChoice implements IForkChoice {
() => new MapDef(() => new Set())
);

/**
* It's inconsistent to count number of queued attestations at different intervals of slot.
* Instead of that, we count number of queued attestations at the previous slot.
*/
private queuedAttestationsPreviousSlot = 0;

// Note: as of Jun 2022 Lodestar metrics show that 100% of the times updateHead() is called, synced = false.
// Because we are processing attestations from gossip, recomputing scores is always necessary
// /** Avoid having to compute deltas all the times. */
Expand Down Expand Up @@ -129,13 +135,9 @@ export class ForkChoice implements IForkChoice {
}

getMetrics(): ForkChoiceMetrics {
let numAttestations = 0;
for (const indicesByRoot of this.queuedAttestations.values()) {
numAttestations += Array.from(indicesByRoot.values()).reduce((acc, indices) => acc + indices.size, 0);
}
return {
votes: this.votes.length,
queuedAttestations: numAttestations,
queuedAttestations: this.queuedAttestationsPreviousSlot,
validatedAttestationDatas: this.validatedAttestationDatas.size,
balancesLength: this.balances.length,
nodes: this.protoArray.nodes.length,
Expand Down Expand Up @@ -771,6 +773,7 @@ export class ForkChoice implements IForkChoice {
this.onTick(previousSlot + 1);
}

this.queuedAttestationsPreviousSlot = 0;
// Process any attestations that might now be eligible.
this.processAttestationQueue();
this.validatedAttestationDatas = new Set();
Expand Down Expand Up @@ -1373,6 +1376,10 @@ export class ForkChoice implements IForkChoice {
// equivocatingIndices was checked in onAttestation
this.addLatestMessage(validatorIndex, targetEpoch, blockRootHex);
}

if (slot === currentSlot - 1) {
this.queuedAttestationsPreviousSlot += validatorIndices.size;
}
}
} else {
break;
Expand Down

0 comments on commit b5c6043

Please sign in to comment.