diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 658c86b905ff..3b21b4434f1d 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -1067,7 +1067,13 @@ export function getValidatorApi({ await waitForSlot(slot); // Must never request for a future slot > currentSlot - const aggregate = chain.attestationPool.getAggregate(slot, attestationDataRoot); + const dataRootHex = toHexString(attestationDataRoot); + const aggregate = chain.attestationPool.getAggregate(slot, dataRootHex); + + if (!aggregate) { + throw new ApiError(404, `No aggregated attestation for slot=${slot}, dataRoot=${dataRootHex}`); + } + metrics?.production.producedAggregateParticipants.observe(aggregate.aggregationBits.getTrueBitIndexes().length); return { diff --git a/packages/beacon-node/src/chain/opPools/attestationPool.ts b/packages/beacon-node/src/chain/opPools/attestationPool.ts index a04cd7592091..804d8798cbc2 100644 --- a/packages/beacon-node/src/chain/opPools/attestationPool.ts +++ b/packages/beacon-node/src/chain/opPools/attestationPool.ts @@ -1,7 +1,7 @@ import {PointFormat, Signature} from "@chainsafe/bls/types"; import bls from "@chainsafe/bls"; -import {BitArray, toHexString} from "@chainsafe/ssz"; -import {phase0, Slot, Root, RootHex} from "@lodestar/types"; +import {BitArray} from "@chainsafe/ssz"; +import {phase0, Slot, RootHex} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; import {IClock} from "../../util/clock.js"; import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js"; @@ -128,12 +128,11 @@ export class AttestationPool { /** * For validator API to get an aggregate */ - getAggregate(slot: Slot, dataRoot: Root): phase0.Attestation { - const dataRootHex = toHexString(dataRoot); + getAggregate(slot: Slot, dataRootHex: RootHex): phase0.Attestation | null { const aggregate = this.attestationByRootBySlot.get(slot)?.get(dataRootHex); if (!aggregate) { // TODO: Add metric for missing aggregates - throw Error(`No attestation for slot=${slot} dataRoot=${dataRootHex}`); + return null; } return fastToAttestation(aggregate);