Skip to content

Commit 5f55066

Browse files
authored
fix: return correct type from attestation validation when using cache (#7261)
* fix: return correct type from attestation validation when using cache * Remove type casts * Remove unused import * Use ternary operator instead of if-else * Fix aggregationBits type issue * Add comment
1 parent 957684f commit 5f55066

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
SingleAttestation,
3131
Slot,
3232
ValidatorIndex,
33-
electra,
3433
isElectraSingleAttestation,
3534
phase0,
3635
ssz,
@@ -514,27 +513,27 @@ async function validateAttestationNoSignatureCheck(
514513
}
515514

516515
// no signature check, leave that for step1
517-
const indexedAttestationContent = {
516+
const indexedAttestation: IndexedAttestation = {
518517
attestingIndices,
519518
data: attData,
520519
signature,
521520
};
522-
const indexedAttestation =
523-
ForkSeq[fork] >= ForkSeq.electra
524-
? (indexedAttestationContent as electra.IndexedAttestation)
525-
: (indexedAttestationContent as phase0.IndexedAttestation);
526521

527-
const attestationContent = attestationOrCache.attestation ?? {
528-
aggregationBits,
529-
data: attData,
530-
committeeIndex,
531-
signature,
532-
};
533-
534-
const attestation =
535-
ForkSeq[fork] >= ForkSeq.electra
536-
? (attestationContent as SingleAttestation<ForkPostElectra>)
537-
: (attestationContent as SingleAttestation<ForkPreElectra>);
522+
const attestation: SingleAttestation = attestationOrCache.attestation
523+
? attestationOrCache.attestation
524+
: !isForkPostElectra(fork)
525+
? {
526+
// Aggregation bits are already asserted above to not be null
527+
aggregationBits: aggregationBits as BitArray,
528+
data: attData,
529+
signature,
530+
}
531+
: {
532+
committeeIndex,
533+
attesterIndex: validatorIndex,
534+
data: attData,
535+
signature,
536+
};
538537

539538
return {
540539
attestation,

0 commit comments

Comments
 (0)