From 37cfb6e77c35f27cc7b170bc95c490ee80fa7e85 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Fri, 18 Aug 2023 19:36:50 +0700 Subject: [PATCH] fix: address attDataBase64 for both linear & indexed queues --- .../src/chain/errors/attestationError.ts | 5 +---- .../beacon-node/src/chain/validation/attestation.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/beacon-node/src/chain/errors/attestationError.ts b/packages/beacon-node/src/chain/errors/attestationError.ts index 913827d4ca38..a93f5b42e439 100644 --- a/packages/beacon-node/src/chain/errors/attestationError.ts +++ b/packages/beacon-node/src/chain/errors/attestationError.ts @@ -132,8 +132,6 @@ export enum AttestationErrorCode { INVALID_SERIALIZED_BYTES = "ATTESTATION_ERROR_INVALID_SERIALIZED_BYTES", /** Too many skipped slots. */ TOO_MANY_SKIPPED_SLOTS = "ATTESTATION_ERROR_TOO_MANY_SKIPPED_SLOTS", - /** attDataBase64 is not available */ - NO_INDEXED_DATA = "ATTESTATION_ERROR_NO_INDEXED_DATA", } export type AttestationErrorType = @@ -168,8 +166,7 @@ export type AttestationErrorType = | {code: AttestationErrorCode.INVALID_AGGREGATOR} | {code: AttestationErrorCode.INVALID_INDEXED_ATTESTATION} | {code: AttestationErrorCode.INVALID_SERIALIZED_BYTES} - | {code: AttestationErrorCode.TOO_MANY_SKIPPED_SLOTS; headBlockSlot: Slot; attestationSlot: Slot} - | {code: AttestationErrorCode.NO_INDEXED_DATA}; + | {code: AttestationErrorCode.TOO_MANY_SKIPPED_SLOTS; headBlockSlot: Slot; attestationSlot: Slot}; export class AttestationError extends GossipActionError { getMetadata(): Record { diff --git a/packages/beacon-node/src/chain/validation/attestation.ts b/packages/beacon-node/src/chain/validation/attestation.ts index 573bfa5c227c..e47c795f0243 100644 --- a/packages/beacon-node/src/chain/validation/attestation.ts +++ b/packages/beacon-node/src/chain/validation/attestation.ts @@ -15,6 +15,7 @@ import {RegenCaller} from "../regen/index.js"; import { AttDataBase64, getAggregationBitsFromAttestationSerialized, + getAttDataBase64FromAttestationSerialized, getSignatureFromAttestationSerialized, } from "../../util/sszBytes.js"; import {AttestationDataCacheEntry} from "../seenCache/seenAttestationData.js"; @@ -233,16 +234,14 @@ async function validateGossipAttestationNoSignatureCheck( let attestationOrCache: | {attestation: phase0.Attestation; cache: null} | {attestation: null; cache: AttestationDataCacheEntry; serializedData: Uint8Array}; - let attDataBase64: AttDataBase64 | null; + let attDataBase64: AttDataBase64 | null = null; if (attestationOrBytes.serializedData) { // gossip const attSlot = attestationOrBytes.attSlot; - if (!attestationOrBytes.attDataBase64) { - throw new AttestationError(GossipAction.IGNORE, { - code: AttestationErrorCode.NO_INDEXED_DATA, - }); - } - attDataBase64 = attestationOrBytes.attDataBase64; + // for old LIFO linear gossip queue we don't have attDataBase64 + // for indexed gossip queue we have attDataBase64 + attDataBase64 = + attestationOrBytes.attDataBase64 ?? getAttDataBase64FromAttestationSerialized(attestationOrBytes.serializedData); const cachedAttData = attDataBase64 !== null ? chain.seenAttestationDatas.get(attSlot, attDataBase64) : null; if (cachedAttData === null) { const attestation = sszDeserializeAttestation(attestationOrBytes.serializedData);