Skip to content

Commit

Permalink
feat: add more metrics for gossip attestation verification
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed May 17, 2023
1 parent 87596ff commit bf74eae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Expand Up @@ -52,6 +52,11 @@ export async function validateGossipAggregateAndProof(
const attTarget = attData.target;
const targetEpoch = attTarget.epoch;

chain.metrics?.gossipAttestation.attestationSlotToClockSlot.observe(
{caller: RegenCaller.validateGossipAggregateAndProof},
chain.clock.currentSlot - attSlot
);

if (!cachedAttData) {
// [REJECT] The attestation's epoch matches its target -- i.e. attestation.data.target.epoch == compute_epoch_at_slot(attestation.data.slot)
if (targetEpoch !== attEpoch) {
Expand Down Expand Up @@ -101,6 +106,7 @@ export async function validateGossipAggregateAndProof(
attTarget.root,
attSlot,
attEpoch,
RegenCaller.validateGossipAggregateAndProof,
chain.opts.maxSkipSlots
);

Expand Down
12 changes: 11 additions & 1 deletion packages/beacon-node/src/chain/validation/attestation.ts
Expand Up @@ -91,6 +91,11 @@ export async function validateGossipAttestation(
const attTarget = attData.target;
const targetEpoch = attTarget.epoch;

chain.metrics?.gossipAttestation.attestationSlotToClockSlot.observe(
{caller: RegenCaller.validateGossipAttestation},
chain.clock.currentSlot - attSlot
);

if (!attestationOrCache.cache) {
// [REJECT] The attestation's epoch matches its target -- i.e. attestation.data.target.epoch == compute_epoch_at_slot(attestation.data.slot)
if (targetEpoch !== attEpoch) {
Expand Down Expand Up @@ -146,6 +151,7 @@ export async function validateGossipAttestation(
attestationOrCache.attestation.data.target.root,
attSlot,
attEpoch,
RegenCaller.validateGossipAttestation,
chain.opts.maxSkipSlots
);

Expand Down Expand Up @@ -337,14 +343,18 @@ export function verifyHeadBlockAndTargetRoot(
targetRoot: Root,
attestationSlot: Slot,
attestationEpoch: Epoch,
caller: string,
maxSkipSlots?: number
): ProtoBlock {
const headBlock = verifyHeadBlockIsKnown(chain, beaconBlockRoot);
// Lighthouse rejects the attestation, however Lodestar only ignores considering it's not against the spec
// it's more about a DOS protection to us
// With verifyPropagationSlotRange() and maxSkipSlots = 32, it's unlikely we have to regenerate states in queue
// to validate beacon_attestation and aggregate_and_proof
if (maxSkipSlots !== undefined && attestationSlot - headBlock.slot > maxSkipSlots) {
const slotDistance = attestationSlot - headBlock.slot;
chain.metrics?.gossipAttestation.headSlotToAttestationSlot.observe({caller}, slotDistance);

if (maxSkipSlots !== undefined && slotDistance > maxSkipSlots) {
throw new AttestationError(GossipAction.IGNORE, {
code: AttestationErrorCode.TOO_MANY_SKIPPED_SLOTS,
attestationSlot,
Expand Down
12 changes: 12 additions & 0 deletions packages/beacon-node/src/metrics/metrics/lodestar.ts
Expand Up @@ -530,6 +530,18 @@ export function createLodestarMetrics(
help: "Count of gossip attestation verification using head block state and dialed to target epoch",
labelNames: ["caller"],
}),
headSlotToAttestationSlot: register.histogram<"caller">({
name: "lodestar_gossip_attestation_head_slot_to_attestation_slot",
help: "Slot distance between attestation slot and head slot",
labelNames: ["caller"],
buckets: [0, 1, 2, 4, 8, 16, 32, 64],
}),
attestationSlotToClockSlot: register.histogram<"caller">({
name: "lodestar_gossip_attestation_attestation_slot_to_clock_slot",
help: "Slot distance between clock slot and attestation slot",
labelNames: ["caller"],
buckets: [0, 1, 2, 4, 8, 16, 32, 64],
}),
},

// Gossip block
Expand Down

0 comments on commit bf74eae

Please sign in to comment.