Skip to content

Commit

Permalink
fix: return 404 error if no aggregated attestation is available (#6648)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Apr 8, 2024
1 parent d79bc49 commit 65927c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/beacon-node/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions packages/beacon-node/src/chain/opPools/attestationPool.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 65927c6

Please sign in to comment.