Skip to content

Commit 59b3b1e

Browse files
committed
fix: cache attester index during attestation validation
1 parent cfe6c89 commit 59b3b1e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/beacon-node/src/chain/seenCache/seenAttestationData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {BitArray} from "@chainsafe/ssz";
2-
import {CommitteeIndex, RootHex, Slot, phase0} from "@lodestar/types";
2+
import {CommitteeIndex, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
33
import {MapDef} from "@lodestar/utils";
44
import {Metrics} from "../../metrics/metrics.js";
55
import {InsertOutcome} from "../opPools/types.js";
@@ -11,8 +11,8 @@ type AttDataBase64 = string;
1111
export type AttestationDataCacheEntry = {
1212
// part of shuffling data, so this does not take memory
1313
committeeValidatorIndices: Uint32Array;
14-
// TODO: remove this? this is available in SingleAttestation
1514
committeeIndex: CommitteeIndex;
15+
attesterIndex: ValidatorIndex;
1616
// IndexedAttestationData signing root, 32 bytes
1717
signingRoot: Uint8Array;
1818
// to be consumed by forkchoice and oppool

packages/beacon-node/src/chain/validation/attestation.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,16 @@ async function validateAttestationNoSignatureCheck(
407407
if (!isForkPostElectra(fork)) {
408408
// The validity of aggregation bits are already checked above
409409
assert.notNull(aggregationBits);
410-
const bitIndex = aggregationBits.getSingleTrueBit();
411-
assert.notNull(bitIndex);
412410

413-
validatorIndex = committeeValidatorIndices[bitIndex];
411+
if (attestationOrCache.attestation) {
412+
const bitIndex = aggregationBits.getSingleTrueBit();
413+
assert.notNull(bitIndex);
414+
415+
validatorIndex = committeeValidatorIndices[bitIndex];
416+
} else {
417+
validatorIndex = attestationOrCache.cache.attesterIndex;
418+
}
419+
414420
// [REJECT] The number of aggregation bits matches the committee size
415421
// -- i.e. len(attestation.aggregation_bits) == len(get_beacon_committee(state, data.slot, data.index)).
416422
// > TODO: Is this necessary? Lighthouse does not do this check.
@@ -420,7 +426,10 @@ async function validateAttestationNoSignatureCheck(
420426
});
421427
}
422428
} else {
423-
validatorIndex = (attestationOrCache.attestation as SingleAttestation<ForkPostElectra>).attesterIndex;
429+
validatorIndex = attestationOrCache.attestation
430+
? (attestationOrCache.attestation as SingleAttestation<ForkPostElectra>).attesterIndex
431+
: attestationOrCache.cache.attesterIndex;
432+
424433
// [REJECT] The attester is a member of the committee -- i.e.
425434
// `attestation.attester_index in get_beacon_committee(state, attestation.data.slot, index)`.
426435
// If `aggregationBitsElectra` exists, that means we have already cached it. No need to check again
@@ -498,6 +507,7 @@ async function validateAttestationNoSignatureCheck(
498507
chain.seenAttestationDatas.add(attSlot, committeeIndex, attDataKey, {
499508
committeeValidatorIndices,
500509
committeeIndex,
510+
attesterIndex: validatorIndex,
501511
signingRoot: signatureSet.signingRoot,
502512
subnet: expectedSubnet,
503513
// precompute this to be used in forkchoice

0 commit comments

Comments
 (0)