@@ -31,6 +31,7 @@ import {
31
31
} from "@lodestar/state-transition" ;
32
32
import { IForkChoice , EpochDifference } from "@lodestar/fork-choice" ;
33
33
import { toHex , MapDef , assert } from "@lodestar/utils" ;
34
+ import { ChainForkConfig } from "@lodestar/config" ;
34
35
import { intersectUint8Arrays , IntersectResult } from "../../util/bitArray.js" ;
35
36
import { pruneBySlot , signatureFromBytesNoCheck } from "./utils.js" ;
36
37
import { InsertOutcome } from "./types.js" ;
@@ -102,6 +103,8 @@ export class AggregatedAttestationPool {
102
103
> ( ( ) => new Map < DataRootHex , Map < CommitteeIndex , MatchingDataAttestationGroup > > ( ) ) ;
103
104
private lowestPermissibleSlot = 0 ;
104
105
106
+ constructor ( private readonly config : ChainForkConfig ) { }
107
+
105
108
/** For metrics to track size of the pool */
106
109
getAttestationCount ( ) : { attestationCount : number ; attestationDataCount : number } {
107
110
let attestationCount = 0 ;
@@ -124,6 +127,7 @@ export class AggregatedAttestationPool {
124
127
committee : Uint32Array
125
128
) : InsertOutcome {
126
129
const slot = attestation . data . slot ;
130
+ const fork = this . config . getForkSeq ( slot ) ;
127
131
const lowestPermissibleSlot = this . lowestPermissibleSlot ;
128
132
129
133
// Reject any attestations that are too old.
@@ -137,10 +141,22 @@ export class AggregatedAttestationPool {
137
141
attestationGroupByIndex = new Map < CommitteeIndex , MatchingDataAttestationGroup > ( ) ;
138
142
attestationGroupByIndexByDataHash . set ( dataRootHex , attestationGroupByIndex ) ;
139
143
}
140
- const committeeIndex = isElectraAttestation ( attestation )
141
- ? // this attestation is added to pool after validation
142
- attestation . committeeBits . getSingleTrueBit ( )
143
- : attestation . data . index ;
144
+
145
+ let committeeIndex ;
146
+
147
+ if ( fork >= ForkSeq . electra ) {
148
+ if ( isElectraAttestation ( attestation ) ) {
149
+ committeeIndex = attestation . committeeBits . getSingleTrueBit ( ) ;
150
+ } else {
151
+ throw new Error ( "" ) ;
152
+ }
153
+ } else {
154
+ if ( ! isElectraAttestation ( attestation ) ) {
155
+ committeeIndex = attestation . data . index ;
156
+ } else {
157
+ throw new Error ( "" ) ;
158
+ }
159
+ }
144
160
// this should not happen because attestation should be validated before reaching this
145
161
assert . notNull ( committeeIndex , "Committee index should not be null in aggregated attestation pool" ) ;
146
162
let attestationGroup = attestationGroupByIndex . get ( committeeIndex ) ;
@@ -391,6 +407,10 @@ export class AggregatedAttestationPool {
391
407
392
408
/**
393
409
* Get all attestations optionally filtered by `attestation.data.slot`
410
+ * Note this function is not fork aware and can potentially return a mix
411
+ * of phase0.Attestations and electra.Attestations.
412
+ * Caller of this function is expected to filtered result if they desire
413
+ * a homogenous array.
394
414
* @param bySlot slot to filter, `bySlot === attestation.data.slot`
395
415
*/
396
416
getAll ( bySlot ?: Slot ) : Attestation [ ] {
@@ -506,7 +526,16 @@ export class MatchingDataAttestationGroup {
506
526
getAttestationsForBlock ( fork : ForkName , notSeenAttestingIndices : Set < number > ) : AttestationNonParticipant [ ] {
507
527
const attestations : AttestationNonParticipant [ ] = [ ] ;
508
528
const forkSeq = ForkSeq [ fork ] ;
529
+ const isAfterElectra = forkSeq >= ForkSeq . electra ;
509
530
for ( const { attestation} of this . attestations ) {
531
+ if (
532
+ ( isAfterElectra && ! isElectraAttestation ( attestation ) ) ||
533
+ ( ! isAfterElectra && isElectraAttestation ( attestation ) )
534
+ ) {
535
+ // TODO Electra: log warning
536
+ continue ;
537
+ }
538
+
510
539
let notSeenAttesterCount = 0 ;
511
540
const { aggregationBits} = attestation ;
512
541
for ( const notSeenIndex of notSeenAttestingIndices ) {
@@ -516,12 +545,12 @@ export class MatchingDataAttestationGroup {
516
545
}
517
546
518
547
// if fork >= electra, should return electra-only attestations
519
- if ( notSeenAttesterCount > 0 && ( forkSeq < ForkSeq . electra || isElectraAttestation ( attestation ) ) ) {
548
+ if ( notSeenAttesterCount > 0 ) {
520
549
attestations . push ( { attestation, notSeenAttesterCount} ) ;
521
550
}
522
551
}
523
552
524
- const maxAttestation = forkSeq >= ForkSeq . electra ? MAX_ATTESTATIONS_PER_GROUP_ELECTRA : MAX_ATTESTATIONS_PER_GROUP ;
553
+ const maxAttestation = isAfterElectra ? MAX_ATTESTATIONS_PER_GROUP_ELECTRA : MAX_ATTESTATIONS_PER_GROUP ;
525
554
if ( attestations . length <= maxAttestation ) {
526
555
return attestations ;
527
556
} else {
0 commit comments