@lodestar/beacon-node 2.1.0-dev.7fecddd274 → 2.1.0-dev.861fc0baea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +1 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +8 -0
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/index.js +3 -2
  9. package/lib/api/impl/beacon/state/index.js.map +1 -1
  10. package/lib/api/impl/beacon/state/utils.js +1 -1
  11. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  12. package/lib/api/impl/validator/index.js +1 -1
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/api/rest/base.d.ts.map +1 -1
  15. package/lib/api/rest/base.js +1 -1
  16. package/lib/api/rest/base.js.map +1 -1
  17. package/lib/chain/ColumnReconstructionTracker.d.ts +3 -0
  18. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  19. package/lib/chain/ColumnReconstructionTracker.js +3 -1
  20. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  21. package/lib/chain/GetBlobsTracker.d.ts +3 -0
  22. package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
  23. package/lib/chain/GetBlobsTracker.js +3 -1
  24. package/lib/chain/GetBlobsTracker.js.map +1 -1
  25. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  26. package/lib/chain/blocks/importBlock.js +14 -5
  27. package/lib/chain/blocks/importBlock.js.map +1 -1
  28. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  29. package/lib/chain/blocks/importExecutionPayload.js +4 -2
  30. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  31. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
  32. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  33. package/lib/chain/chain.d.ts +2 -1
  34. package/lib/chain/chain.d.ts.map +1 -1
  35. package/lib/chain/chain.js +29 -6
  36. package/lib/chain/chain.js.map +1 -1
  37. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  38. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  39. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  40. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  41. package/lib/chain/forkChoice/index.d.ts +11 -2
  42. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  43. package/lib/chain/forkChoice/index.js +180 -13
  44. package/lib/chain/forkChoice/index.js.map +1 -1
  45. package/lib/chain/interface.d.ts +2 -1
  46. package/lib/chain/interface.d.ts.map +1 -1
  47. package/lib/chain/interface.js.map +1 -1
  48. package/lib/chain/opPools/opPool.d.ts +9 -3
  49. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  50. package/lib/chain/opPools/opPool.js +22 -16
  51. package/lib/chain/opPools/opPool.js.map +1 -1
  52. package/lib/chain/options.d.ts.map +1 -1
  53. package/lib/chain/options.js +1 -3
  54. package/lib/chain/options.js.map +1 -1
  55. package/lib/chain/seenCache/index.d.ts +1 -0
  56. package/lib/chain/seenCache/index.d.ts.map +1 -1
  57. package/lib/chain/seenCache/index.js +1 -0
  58. package/lib/chain/seenCache/index.js.map +1 -1
  59. package/lib/chain/seenCache/seenBlockProposers.d.ts +1 -0
  60. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  61. package/lib/chain/seenCache/seenBlockProposers.js +5 -1
  62. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  63. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts +16 -0
  64. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts.map +1 -0
  65. package/lib/chain/seenCache/seenDataColumnSidecars.js +56 -0
  66. package/lib/chain/seenCache/seenDataColumnSidecars.js.map +1 -0
  67. package/lib/chain/seenCache/seenGossipBlockInput.js +1 -1
  68. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  69. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +11 -2
  70. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  71. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +28 -2
  72. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  73. package/lib/chain/validation/attestation.d.ts.map +1 -1
  74. package/lib/chain/validation/attestation.js +4 -2
  75. package/lib/chain/validation/attestation.js.map +1 -1
  76. package/lib/chain/validation/block.d.ts.map +1 -1
  77. package/lib/chain/validation/block.js +20 -7
  78. package/lib/chain/validation/block.js.map +1 -1
  79. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  80. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  81. package/lib/chain/validation/proposerSlashing.js +5 -1
  82. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  83. package/lib/network/core/networkCore.d.ts +1 -3
  84. package/lib/network/core/networkCore.d.ts.map +1 -1
  85. package/lib/network/core/networkCore.js +1 -3
  86. package/lib/network/core/networkCore.js.map +1 -1
  87. package/lib/network/forks.d.ts +2 -2
  88. package/lib/network/forks.d.ts.map +1 -1
  89. package/lib/network/forks.js +3 -3
  90. package/lib/network/forks.js.map +1 -1
  91. package/lib/network/gossip/scoringParameters.js +19 -14
  92. package/lib/network/gossip/scoringParameters.js.map +1 -1
  93. package/lib/network/network.d.ts +1 -6
  94. package/lib/network/network.d.ts.map +1 -1
  95. package/lib/network/network.js +16 -40
  96. package/lib/network/network.js.map +1 -1
  97. package/lib/network/options.d.ts +0 -1
  98. package/lib/network/options.d.ts.map +1 -1
  99. package/lib/network/options.js +0 -1
  100. package/lib/network/options.js.map +1 -1
  101. package/lib/network/peers/discover.d.ts +1 -0
  102. package/lib/network/peers/discover.d.ts.map +1 -1
  103. package/lib/network/peers/discover.js +44 -48
  104. package/lib/network/peers/discover.js.map +1 -1
  105. package/lib/network/peers/score/store.d.ts.map +1 -1
  106. package/lib/network/peers/score/store.js +1 -2
  107. package/lib/network/peers/score/store.js.map +1 -1
  108. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  109. package/lib/network/processor/gossipHandlers.js +85 -17
  110. package/lib/network/processor/gossipHandlers.js.map +1 -1
  111. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  112. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -1
  113. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  114. package/lib/sync/range/chain.d.ts.map +1 -1
  115. package/lib/sync/range/chain.js +1 -0
  116. package/lib/sync/range/chain.js.map +1 -1
  117. package/lib/sync/range/range.d.ts.map +1 -1
  118. package/lib/sync/range/range.js +5 -1
  119. package/lib/sync/range/range.js.map +1 -1
  120. package/lib/sync/unknownBlock.d.ts.map +1 -1
  121. package/lib/sync/unknownBlock.js +14 -1
  122. package/lib/sync/unknownBlock.js.map +1 -1
  123. package/lib/sync/utils/downloadByRange.d.ts +6 -0
  124. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  125. package/lib/sync/utils/downloadByRange.js +17 -8
  126. package/lib/sync/utils/downloadByRange.js.map +1 -1
  127. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  128. package/lib/sync/utils/downloadByRoot.js +1 -1
  129. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  130. package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -1
  131. package/lib/sync/utils/pendingBlocksTree.js +6 -1
  132. package/lib/sync/utils/pendingBlocksTree.js.map +1 -1
  133. package/lib/util/dataColumns.d.ts +2 -1
  134. package/lib/util/dataColumns.d.ts.map +1 -1
  135. package/lib/util/dataColumns.js +7 -2
  136. package/lib/util/dataColumns.js.map +1 -1
  137. package/lib/util/execution.d.ts +2 -1
  138. package/lib/util/execution.d.ts.map +1 -1
  139. package/lib/util/execution.js +7 -2
  140. package/lib/util/execution.js.map +1 -1
  141. package/lib/util/sszBytes.d.ts.map +1 -1
  142. package/lib/util/sszBytes.js +6 -4
  143. package/lib/util/sszBytes.js.map +1 -1
  144. package/package.json +18 -21
  145. package/src/api/impl/beacon/blocks/index.ts +1 -5
  146. package/src/api/impl/beacon/pool/index.ts +11 -0
  147. package/src/api/impl/beacon/state/index.ts +3 -7
  148. package/src/api/impl/beacon/state/utils.ts +1 -1
  149. package/src/api/impl/validator/index.ts +1 -1
  150. package/src/api/rest/base.ts +5 -1
  151. package/src/chain/ColumnReconstructionTracker.ts +5 -1
  152. package/src/chain/GetBlobsTracker.ts +5 -0
  153. package/src/chain/blocks/importBlock.ts +14 -7
  154. package/src/chain/blocks/importExecutionPayload.ts +4 -2
  155. package/src/chain/blocks/payloadEnvelopeInput/types.ts +8 -1
  156. package/src/chain/chain.ts +34 -5
  157. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  158. package/src/chain/forkChoice/index.ts +233 -13
  159. package/src/chain/interface.ts +2 -0
  160. package/src/chain/opPools/opPool.ts +27 -16
  161. package/src/chain/options.ts +1 -3
  162. package/src/chain/seenCache/index.ts +1 -0
  163. package/src/chain/seenCache/seenBlockProposers.ts +11 -1
  164. package/src/chain/seenCache/seenDataColumnSidecars.ts +64 -0
  165. package/src/chain/seenCache/seenGossipBlockInput.ts +1 -1
  166. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +28 -2
  167. package/src/chain/validation/attestation.ts +4 -2
  168. package/src/chain/validation/block.ts +19 -7
  169. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  170. package/src/chain/validation/proposerSlashing.ts +5 -1
  171. package/src/network/core/networkCore.ts +1 -3
  172. package/src/network/forks.ts +7 -3
  173. package/src/network/gossip/scoringParameters.ts +23 -14
  174. package/src/network/network.ts +20 -44
  175. package/src/network/options.ts +0 -2
  176. package/src/network/peers/discover.ts +42 -52
  177. package/src/network/peers/score/store.ts +1 -2
  178. package/src/network/processor/gossipHandlers.ts +147 -25
  179. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
  180. package/src/sync/range/chain.ts +1 -0
  181. package/src/sync/range/range.ts +7 -1
  182. package/src/sync/unknownBlock.ts +20 -1
  183. package/src/sync/utils/downloadByRange.ts +30 -7
  184. package/src/sync/utils/downloadByRoot.ts +12 -9
  185. package/src/sync/utils/pendingBlocksTree.ts +6 -1
  186. package/src/util/dataColumns.ts +13 -1
  187. package/src/util/execution.ts +16 -1
  188. package/src/util/sszBytes.ts +7 -8
@@ -5,28 +5,33 @@ import {
5
5
  ForkChoice,
6
6
  ForkChoiceStateGetter,
7
7
  ForkChoiceStore,
8
+ IForkChoice,
8
9
  JustifiedBalancesGetter,
10
+ NativeForkChoice,
9
11
  PayloadStatus,
10
12
  ProtoArray,
11
13
  ProtoBlock,
12
14
  ForkChoiceOpts as RawForkChoiceOpts,
13
15
  } from "@lodestar/fork-choice";
14
- import {ZERO_HASH_HEX} from "@lodestar/params";
16
+ import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT, ZERO_HASH_HEX, isForkPostGloas} from "@lodestar/params";
15
17
  import {
16
18
  DataAvailabilityStatus,
17
19
  IBeaconStateView,
20
+ ZERO_HASH,
18
21
  computeEpochAtSlot,
19
22
  computeStartSlotAtEpoch,
20
23
  isStatePostBellatrix,
21
24
  isStatePostGloas,
22
25
  } from "@lodestar/state-transition";
23
- import {Slot, ssz} from "@lodestar/types";
24
- import {Logger, toRootHex} from "@lodestar/utils";
26
+ import {Slot, phase0, ssz} from "@lodestar/types";
27
+ import {Logger, fromHex, toRootHex} from "@lodestar/utils";
25
28
  import {GENESIS_SLOT} from "../../constants/index.js";
26
29
  import {Metrics} from "../../metrics/index.js";
27
30
  import {ChainEvent, ChainEventEmitter} from "../emitter.js";
28
31
 
29
32
  export type ForkChoiceOpts = RawForkChoiceOpts & {
33
+ /** Use the native (Zig) fork choice store instead of the proto-array */
34
+ nativeForkChoice?: boolean;
30
35
  // for testing only
31
36
  forkchoiceConstructor?: typeof ForkChoice;
32
37
  };
@@ -58,7 +63,22 @@ export function initializeForkChoice(
58
63
  stateGetter: ForkChoiceStateGetter,
59
64
  metrics: Metrics | null,
60
65
  logger?: Logger
61
- ): ForkChoice {
66
+ ): IForkChoice {
67
+ if (opts.nativeForkChoice) {
68
+ return initializeNativeForkChoice(
69
+ config,
70
+ emitter,
71
+ currentSlot,
72
+ state,
73
+ isFinalizedState,
74
+ opts,
75
+ justifiedBalancesGetter,
76
+ stateGetter,
77
+ metrics,
78
+ logger
79
+ );
80
+ }
81
+
62
82
  return isFinalizedState
63
83
  ? initializeForkChoiceFromFinalizedState(
64
84
  config,
@@ -115,7 +135,7 @@ export function initializeForkChoiceFromFinalizedState(
115
135
  // production code use ForkChoice constructor directly
116
136
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
117
137
 
118
- const isForkPostGloas = computeEpochAtSlot(state.slot) >= config.GLOAS_FORK_EPOCH;
138
+ const isPostGloasAnchor = isStatePostGloas(state) && isForkPostGloas(config.getForkName(blockHeader.slot));
119
139
 
120
140
  return new forkchoiceConstructor(
121
141
  config,
@@ -164,15 +184,20 @@ export function initializeForkChoiceFromFinalizedState(
164
184
  // TODO GLOAS: executionPayloadNumber/GasLimit are not tracked in BeaconState post-gloas
165
185
  // (EIP-7732 removed latestExecutionPayloadHeader). Using 0 as unavailable fallback —
166
186
  // see initializeForkChoiceFromUnfinalizedState for the same caveat on validation.
187
+ // A pre-Gloas anchor's gas limit is kept in the state's bid by the upgrade.
167
188
  executionPayloadNumber: isStatePostGloas(state) ? 0 : state.payloadBlockNumber,
168
- executionPayloadGasLimit: isStatePostGloas(state) ? 0 : state.latestExecutionPayloadHeader.gasLimit,
189
+ executionPayloadGasLimit: isPostGloasAnchor
190
+ ? 0
191
+ : isStatePostGloas(state)
192
+ ? Number(state.latestExecutionPayloadBid.gasLimit)
193
+ : state.latestExecutionPayloadHeader.gasLimit,
169
194
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
170
195
  }
171
196
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
172
197
 
173
198
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
174
- payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL,
175
- parentBlockHash: isStatePostGloas(state) ? toRootHex(state.latestBlockHash) : null,
199
+ payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
200
+ parentBlockHash: isPostGloasAnchor ? toRootHex(state.latestBlockHash) : null,
176
201
  },
177
202
  currentSlot
178
203
  ),
@@ -183,6 +208,198 @@ export function initializeForkChoiceFromFinalizedState(
183
208
  );
184
209
  }
185
210
 
211
+ /**
212
+ * Initialize the native fork choice. A finalized anchor is both the justified and the finalized
213
+ * checkpoint, as in the spec's `get_forkchoice_store`. An unfinalized one keeps its state's
214
+ * checkpoints, with stand-ins for the ancestors that connect it to them: nothing is reported as
215
+ * finalized that the chain has not finalized.
216
+ */
217
+ export function initializeNativeForkChoice(
218
+ config: ChainForkConfig,
219
+ emitter: ChainEventEmitter,
220
+ currentSlot: Slot,
221
+ state: IBeaconStateView,
222
+ isFinalizedState: boolean,
223
+ opts: ForkChoiceOpts,
224
+ justifiedBalancesGetter: JustifiedBalancesGetter,
225
+ stateGetter: ForkChoiceStateGetter,
226
+ metrics: Metrics | null,
227
+ logger?: Logger
228
+ ): NativeForkChoice {
229
+ const {blockHeader, checkpoint} = state.computeAnchorCheckpoint();
230
+ const anchorRoot = toRootHex(checkpoint.root);
231
+ const isPostGloas = isStatePostGloas(state);
232
+ // A state upgraded to Gloas through skipped slots still holds a pre-Gloas block, which carried its own payload
233
+ const isPostGloasAnchor = isPostGloas && config.getForkSeq(blockHeader.slot) >= ForkSeq.gloas;
234
+ const bid = isPostGloasAnchor ? state.latestExecutionPayloadBid : null;
235
+ const hasPayload = isStatePostBellatrix(state) && state.isExecutionStateType && state.isMergeTransitionComplete;
236
+ // The state caches the bid of its latest block, except at genesis: the genesis block carries no bid
237
+ const anchorBid = blockHeader.slot === GENESIS_SLOT ? null : bid;
238
+
239
+ // The store aliases no root to genesis, so a checkpoint the chain never moved off genesis is
240
+ // given the genesis block root. Only possible while that root is still in the state's history.
241
+ const withGenesisRoot = (cp: phase0.Checkpoint): phase0.Checkpoint => {
242
+ if (!ssz.Root.equals(cp.root, ZERO_HASH)) return cp;
243
+ if (state.slot > GENESIS_SLOT + SLOTS_PER_HISTORICAL_ROOT) {
244
+ throw Error(
245
+ `The native fork choice cannot start from an unfinalized state at slot ${state.slot} of a chain that never justified a checkpoint: the genesis block root has left the state's block roots. Start without --chain.nativeForkChoice`
246
+ );
247
+ }
248
+ return {epoch: cp.epoch, root: state.getBlockRootAtSlot(GENESIS_SLOT)};
249
+ };
250
+ const justifiedCheckpoint = isFinalizedState ? checkpoint : withGenesisRoot(state.currentJustifiedCheckpoint);
251
+ const finalizedCheckpoint = isFinalizedState ? checkpoint : withGenesisRoot(state.finalizedCheckpoint);
252
+ const justifiedRoot = toRootHex(justifiedCheckpoint.root);
253
+ const finalizedRoot = toRootHex(finalizedCheckpoint.root);
254
+
255
+ if (!isFinalizedState) {
256
+ logger?.warn("Initializing fork choice from unfinalized state", {
257
+ currentSlot,
258
+ stateSlot: state.slot,
259
+ headSlot: blockHeader.slot,
260
+ headRoot: anchorRoot,
261
+ finalizedEpoch: finalizedCheckpoint.epoch,
262
+ finalizedRoot,
263
+ justifiedEpoch: justifiedCheckpoint.epoch,
264
+ justifiedRoot,
265
+ });
266
+ }
267
+
268
+ const store = new ForkChoiceStore(
269
+ currentSlot,
270
+ justifiedCheckpoint,
271
+ finalizedCheckpoint,
272
+ // For an unfinalized anchor this is not the justified state, but no other state is at hand
273
+ state.getEffectiveBalanceIncrementsZeroInactive(),
274
+ justifiedBalancesGetter,
275
+ stateGetter,
276
+ {
277
+ onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
278
+ onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
279
+ onFastConfirmation: ({block, slot, currentSlot}) =>
280
+ emitter.emit(routes.events.EventType.fastConfirmation, {block, slot, currentSlot}),
281
+ onPtcQuorum: (data) => emitter.emit(ChainEvent.forkChoicePtcQuorum, data),
282
+ }
283
+ );
284
+
285
+ const checkpoints = {
286
+ justifiedEpoch: justifiedCheckpoint.epoch,
287
+ justifiedRoot,
288
+ finalizedEpoch: finalizedCheckpoint.epoch,
289
+ finalizedRoot,
290
+ unrealizedJustifiedEpoch: justifiedCheckpoint.epoch,
291
+ unrealizedJustifiedRoot: justifiedRoot,
292
+ unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
293
+ unrealizedFinalizedRoot: finalizedRoot,
294
+ };
295
+
296
+ const block: ProtoBlock = {
297
+ slot: blockHeader.slot,
298
+ parentRoot: toRootHex(blockHeader.parentRoot),
299
+ stateRoot: toRootHex(blockHeader.stateRoot),
300
+ blockRoot: anchorRoot,
301
+ targetRoot: anchorRoot,
302
+ timeliness: true,
303
+ ptcTimeliness: true,
304
+ importedTimely: true,
305
+ proposerIndex: blockHeader.proposerIndex,
306
+ ...checkpoints,
307
+
308
+ ...(hasPayload
309
+ ? {
310
+ executionPayloadBlockHash: isPostGloas
311
+ ? toRootHex(state.latestBlockHash)
312
+ : toRootHex(state.latestExecutionPayloadHeader.blockHash),
313
+ // TODO GLOAS: not tracked in BeaconState post-gloas, see initializeForkChoiceFromFinalizedState
314
+ executionPayloadNumber: isPostGloas ? 0 : state.payloadBlockNumber,
315
+ // The upgrade to Gloas keeps a pre-Gloas block's payload gas limit in the state's bid
316
+ executionPayloadGasLimit: isPostGloasAnchor
317
+ ? 0
318
+ : isPostGloas
319
+ ? Number(state.latestExecutionPayloadBid.gasLimit)
320
+ : state.latestExecutionPayloadHeader.gasLimit,
321
+ executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
322
+ }
323
+ : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
324
+
325
+ dataAvailabilityStatus: DataAvailabilityStatus.PreData,
326
+ payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
327
+ parentBlockHash: bid === null ? null : toRootHex(bid.parentBlockHash),
328
+ };
329
+
330
+ // Ancestors of the anchor known by root only: the finalized block, the justified block, the
331
+ // anchor's parent, and for the anchor's epoch and the one before the checkpoint block, which the
332
+ // chain can still justify and which current votes target, and the block before it, the
333
+ // dependent root of the next epoch's duties. Their slots are upper bounds and their payloads
334
+ // unknown, so they carry none.
335
+ const unfinalizedAncestors: ProtoBlock[] = [];
336
+ if (!isFinalizedState) {
337
+ const finalizedSlot = computeStartSlotAtEpoch(finalizedCheckpoint.epoch);
338
+ const candidates: [string, Slot][] = [
339
+ [finalizedRoot, finalizedSlot],
340
+ [justifiedRoot, computeStartSlotAtEpoch(justifiedCheckpoint.epoch)],
341
+ [block.parentRoot, blockHeader.slot - 1],
342
+ ];
343
+ const anchorEpoch = computeEpochAtSlot(state.slot);
344
+ for (const epoch of [anchorEpoch - 1, anchorEpoch]) {
345
+ const checkpointSlot = computeStartSlotAtEpoch(epoch);
346
+ for (const slot of [checkpointSlot - 1, checkpointSlot]) {
347
+ if (slot > finalizedSlot && slot < blockHeader.slot) {
348
+ candidates.push([toRootHex(state.getBlockRootAtSlot(slot)), slot]);
349
+ }
350
+ }
351
+ }
352
+ // Roots repeat over skipped slots: a block keeps the lowest slot it is known at
353
+ candidates.sort((a, b) => a[1] - b[1]);
354
+ for (const [blockRoot, slot] of candidates) {
355
+ const isKnown = blockRoot === anchorRoot || unfinalizedAncestors.some((b) => b.blockRoot === blockRoot);
356
+ if (isKnown || blockRoot === ZERO_HASH_HEX) continue;
357
+ const isGloas = config.getForkSeq(slot) >= ForkSeq.gloas;
358
+ const targetSlot = computeStartSlotAtEpoch(computeEpochAtSlot(slot));
359
+ unfinalizedAncestors.push({
360
+ slot,
361
+ blockRoot,
362
+ parentRoot: unfinalizedAncestors.at(-1)?.blockRoot ?? ZERO_HASH_HEX,
363
+ stateRoot: ZERO_HASH_HEX,
364
+ targetRoot: targetSlot === slot ? blockRoot : toRootHex(state.getBlockRootAtSlot(targetSlot)),
365
+ timeliness: false,
366
+ ptcTimeliness: false,
367
+ importedTimely: false,
368
+ proposerIndex: 0,
369
+ ...checkpoints,
370
+ executionPayloadBlockHash: null,
371
+ executionStatus: ExecutionStatus.PreMerge,
372
+ dataAvailabilityStatus: DataAvailabilityStatus.PreData,
373
+ payloadStatus: isGloas ? PayloadStatus.PENDING : PayloadStatus.FULL,
374
+ parentBlockHash: isGloas ? ZERO_HASH_HEX : null,
375
+ });
376
+ }
377
+ }
378
+
379
+ return new NativeForkChoice(
380
+ config,
381
+ store,
382
+ {
383
+ block,
384
+ stateSlot: state.slot,
385
+ genesisTime: state.genesisTime,
386
+ genesisValidatorsRoot: state.genesisValidatorsRoot,
387
+ justifiedCheckpoint: isFinalizedState ? state.currentJustifiedCheckpoint : justifiedCheckpoint,
388
+ finalizedCheckpoint: isFinalizedState ? state.finalizedCheckpoint : finalizedCheckpoint,
389
+ unfinalizedAncestors: isFinalizedState ? undefined : unfinalizedAncestors,
390
+ payloadBlockHash: isPostGloasAnchor
391
+ ? (anchorBid?.blockHash ?? null)
392
+ : block.executionPayloadBlockHash === null
393
+ ? null
394
+ : fromHex(block.executionPayloadBlockHash),
395
+ bidParentBlockHash: anchorBid?.parentBlockHash ?? null,
396
+ },
397
+ metrics,
398
+ opts,
399
+ logger
400
+ );
401
+ }
402
+
186
403
  /**
187
404
  * Initialize forkchoice from an unfinalized state.
188
405
  */
@@ -217,7 +434,7 @@ export function initializeForkChoiceFromUnfinalizedState(
217
434
  // this is not the justified state, but there is no other ways to get justified balances
218
435
  const justifiedBalances = unfinalizedState.getEffectiveBalanceIncrementsZeroInactive();
219
436
 
220
- const isForkPostGloas = computeEpochAtSlot(unfinalizedState.slot) >= config.GLOAS_FORK_EPOCH;
437
+ const isPostGloasAnchor = isStatePostGloas(unfinalizedState) && isForkPostGloas(config.getForkName(blockHeader.slot));
221
438
 
222
439
  const store = new ForkChoiceStore(
223
440
  currentSlot,
@@ -270,17 +487,20 @@ export function initializeForkChoiceFromUnfinalizedState(
270
487
  // PENDING/EMPTY convention), so gossip bids that reference the head's *own* payload
271
488
  // hash won't match this variant anyway and will IGNORE until `onExecutionPayload`
272
489
  // upgrades the head to FULL with real values.
490
+ // A pre-Gloas anchor's gas limit is kept in the state's bid by the upgrade.
273
491
  executionPayloadNumber: isStatePostGloas(unfinalizedState) ? 0 : unfinalizedState.payloadBlockNumber,
274
- executionPayloadGasLimit: isStatePostGloas(unfinalizedState)
492
+ executionPayloadGasLimit: isPostGloasAnchor
275
493
  ? 0
276
- : unfinalizedState.latestExecutionPayloadHeader.gasLimit,
494
+ : isStatePostGloas(unfinalizedState)
495
+ ? Number(unfinalizedState.latestExecutionPayloadBid.gasLimit)
496
+ : unfinalizedState.latestExecutionPayloadHeader.gasLimit,
277
497
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
278
498
  }
279
499
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
280
500
 
281
501
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
282
- payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL,
283
- parentBlockHash: isStatePostGloas(unfinalizedState) ? toRootHex(unfinalizedState.latestBlockHash) : null,
502
+ payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
503
+ parentBlockHash: isPostGloasAnchor ? toRootHex(unfinalizedState.latestBlockHash) : null,
284
504
  };
285
505
 
286
506
  const parentSlot = blockHeader.slot - 1;
@@ -68,6 +68,7 @@ import {
68
68
  SeenAttesters,
69
69
  SeenBlockProposers,
70
70
  SeenContributionAndProof,
71
+ SeenDataColumnSidecars,
71
72
  SeenExecutionPayloadBids,
72
73
  SeenPayloadAttesters,
73
74
  SeenSyncCommitteeMessages,
@@ -147,6 +148,7 @@ export interface IBeaconChain {
147
148
  readonly seenAggregatedAttestations: SeenAggregatedAttestations;
148
149
  readonly seenExecutionPayloadBids: SeenExecutionPayloadBids;
149
150
  readonly seenBlockProposers: SeenBlockProposers;
151
+ readonly seenDataColumnSidecars: SeenDataColumnSidecars;
150
152
  readonly seenSyncCommitteeMessages: SeenSyncCommitteeMessages;
151
153
  readonly seenContributionAndProof: SeenContributionAndProof;
152
154
  readonly seenAttestationDatas: SeenAttestationDatas;
@@ -1,6 +1,7 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {
3
3
  BLS_WITHDRAWAL_PREFIX,
4
+ FAR_FUTURE_EPOCH,
4
5
  ForkName,
5
6
  ForkSeq,
6
7
  MAX_ATTESTER_SLASHINGS,
@@ -17,6 +18,7 @@ import {
17
18
  getAttesterSlashableIndices,
18
19
  getAttesterSlashingSignatureSets,
19
20
  getProposerSlashingSignatureSets,
21
+ getValidatorFromStateBytes,
20
22
  } from "@lodestar/state-transition";
21
23
  import {
22
24
  AttesterSlashing,
@@ -389,12 +391,19 @@ export class OpPool {
389
391
  }
390
392
 
391
393
  /**
392
- * Prune all types of transactions given the latest head state
394
+ * Prune all types of transactions given the latest head state and the finalized checkpoint state.
395
+ * `finalizedState` is only needed to prune voluntary exits, and may be null when there are none.
393
396
  */
394
- pruneAll(headBlock: SignedBeaconBlock, headState: IBeaconStateView): void {
397
+ pruneAll(
398
+ headBlock: SignedBeaconBlock,
399
+ headState: IBeaconStateView,
400
+ finalizedState: IBeaconStateView | Uint8Array | null
401
+ ): void {
395
402
  this.pruneAttesterSlashings(headState);
396
403
  this.pruneProposerSlashings(headState);
397
- this.pruneVoluntaryExits(headState);
404
+ if (finalizedState !== null) {
405
+ this.pruneVoluntaryExits(finalizedState);
406
+ }
398
407
  this.pruneBlsToExecutionChanges(headBlock, headState);
399
408
  }
400
409
 
@@ -438,21 +447,23 @@ export class OpPool {
438
447
 
439
448
  /**
440
449
  * Call after finalizing
441
- * Prune if validator has already exited at or before the finalized checkpoint of the head.
450
+ * Prune if validator has already exited in the finalized state, so an exit included only in a block that is later
451
+ * orphaned stays in the pool. The finalized state may be serialized bytes if it is not in memory.
452
+ *
453
+ * Exits are not pruned by fork: from Deneb the signature domain is fixed to Capella (EIP-7044), so a fork transition
454
+ * cannot invalidate an exit verified at a Deneb+ state. Exits verified with a pre-Capella domain before crossing into
455
+ * Deneb are not handled, as only chains that cross the Deneb fork are affected.
442
456
  */
443
- private pruneVoluntaryExits(headState: IBeaconStateView): void {
444
- const headStateFork = this.config.getForkSeq(headState.slot);
445
- const finalizedEpoch = headState.finalizedCheckpoint.epoch;
446
-
457
+ private pruneVoluntaryExits(finalizedState: IBeaconStateView | Uint8Array): void {
447
458
  for (const [key, voluntaryExit] of this.voluntaryExits.entries()) {
448
- // VoluntaryExit messages signed in the previous fork become invalid and can never be included in any future
449
- // block, so just drop as the head state advances into the next fork.
450
- if (this.config.getForkSeq(computeStartSlotAtEpoch(voluntaryExit.message.epoch)) < headStateFork) {
451
- this.voluntaryExits.delete(key);
452
- }
453
-
454
- // TODO: Improve this simplistic condition
455
- if (voluntaryExit.message.epoch <= finalizedEpoch) {
459
+ const {validatorIndex} = voluntaryExit.message;
460
+ const finalizedValidator =
461
+ finalizedState instanceof Uint8Array
462
+ ? getValidatorFromStateBytes(this.config, finalizedState, validatorIndex)
463
+ : validatorIndex < finalizedState.validatorCount
464
+ ? finalizedState.getValidator(validatorIndex)
465
+ : null;
466
+ if (finalizedValidator !== null && finalizedValidator.exitEpoch !== FAR_FUTURE_EPOCH) {
456
467
  this.voluntaryExits.delete(key);
457
468
  }
458
469
  }
@@ -110,7 +110,6 @@ export const defaultChainOptions: IChainOptions = {
110
110
  proposerBoost: true,
111
111
  proposerBoostReorg: true,
112
112
  dedupePayloads: true,
113
- computeUnrealized: true,
114
113
  fastConfirmation: false,
115
114
  suggestedFeeRecipient: defaultValidatorOptions.suggestedFeeRecipient,
116
115
  graffitiAppend: true,
@@ -124,8 +123,6 @@ export const defaultChainOptions: IChainOptions = {
124
123
  maxSkipSlots: 32,
125
124
  disableProposerSlashings: false,
126
125
  // should be less than or equal to MIN_SIGNATURE_SETS_TO_BATCH_VERIFY
127
- // batching too much may block the I/O thread so if useWorker=false, suggest this value to be 32
128
- // since this batch attestation work is designed to work with useWorker=true, make this the lowest value
129
126
  minSameMessageSignatureSetsToBatch: 2,
130
127
  // as of Feb 2025, this option turned out to be very useful:
131
128
  // - it allows to share a persisted checkpoint state to other nodes
@@ -133,6 +130,7 @@ export const defaultChainOptions: IChainOptions = {
133
130
  // - it helps debug easier when network is unfinalized
134
131
  nHistoricalStatesFileDataStore: true,
135
132
  nativeStateTransition: true,
133
+ nativeForkChoice: false,
136
134
  maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
137
135
  maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
138
136
  maxCPStateEpochsOnDisk: DEFAULT_MAX_CP_STATE_ON_DISK,
@@ -2,6 +2,7 @@ export {SeenAggregators, SeenAttesters, SeenPayloadAttesters} from "./seenAttest
2
2
  export {SeenBlockProposers} from "./seenBlockProposers.js";
3
3
  export {SeenSyncCommitteeMessages} from "./seenCommittee.js";
4
4
  export {SeenContributionAndProof} from "./seenCommitteeContribution.js";
5
+ export {SeenDataColumnSidecars} from "./seenDataColumnSidecars.js";
5
6
  export {SeenExecutionPayloadBids} from "./seenExecutionPayloadBids.js";
6
7
  export {SeenBlockInput} from "./seenGossipBlockInput.js";
7
8
  export {PayloadEnvelopeInput, SeenPayloadEnvelopeInput} from "./seenPayloadEnvelopeInput.js";
@@ -1,6 +1,6 @@
1
1
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
2
2
  import {Epoch, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
3
- import {MapDef} from "@lodestar/utils";
3
+ import {MapDef, byteArrayEquals} from "@lodestar/utils";
4
4
 
5
5
  /** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
6
6
  const MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL = 2;
@@ -44,6 +44,16 @@ export class SeenBlockProposers {
44
44
  return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
45
45
  }
46
46
 
47
+ hasBlockSignature(
48
+ blockSlot: Slot,
49
+ proposerIndex: ValidatorIndex,
50
+ blockRoot: RootHex,
51
+ signature: Uint8Array
52
+ ): boolean {
53
+ const signedBlockHeader = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.get(blockRoot);
54
+ return signedBlockHeader !== undefined && byteArrayEquals(signedBlockHeader.signature, signature);
55
+ }
56
+
47
57
  isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
48
58
  return (
49
59
  (this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >=
@@ -0,0 +1,64 @@
1
+ import {ColumnIndex, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
2
+ import {MapDef} from "@lodestar/utils";
3
+
4
+ /**
5
+ * Tracks the column indices of valid gossip data column sidecars per slot, proposer and block root,
6
+ * to ignore sidecars of a repeated proposal. Pruned on finalization.
7
+ */
8
+ export class SeenDataColumnSidecars {
9
+ private readonly columnIndicesBySlot = new MapDef<Slot, MapDef<ValidatorIndex, MapDef<RootHex, Set<ColumnIndex>>>>(
10
+ () => new MapDef(() => new MapDef(() => new Set()))
11
+ );
12
+ private readonly evidenceChecksBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set());
13
+ private finalizedSlot: Slot = 0;
14
+
15
+ isRepeatProposal(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
16
+ const columnIndicesByRoot = this.columnIndicesBySlot.get(slot)?.get(proposerIndex);
17
+ if (columnIndicesByRoot === undefined) {
18
+ return false;
19
+ }
20
+ for (const [root, columnIndices] of columnIndicesByRoot) {
21
+ if (root !== blockRoot && columnIndices.has(columnIndex)) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ }
27
+
28
+ isKnown(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
29
+ return this.columnIndicesBySlot.get(slot)?.get(proposerIndex)?.get(blockRoot)?.has(columnIndex) === true;
30
+ }
31
+
32
+ add(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): void {
33
+ if (slot < this.finalizedSlot || this.isRepeatProposal(slot, proposerIndex, columnIndex, blockRoot)) {
34
+ return;
35
+ }
36
+ this.columnIndicesBySlot.getOrDefault(slot).getOrDefault(proposerIndex).getOrDefault(blockRoot).add(columnIndex);
37
+ }
38
+
39
+ markEvidenceCheck(slot: Slot, proposerIndex: ValidatorIndex): boolean {
40
+ if (slot < this.finalizedSlot) {
41
+ return false;
42
+ }
43
+ const proposers = this.evidenceChecksBySlot.getOrDefault(slot);
44
+ if (proposers.has(proposerIndex)) {
45
+ return false;
46
+ }
47
+ proposers.add(proposerIndex);
48
+ return true;
49
+ }
50
+
51
+ prune(finalizedSlot: Slot): void {
52
+ this.finalizedSlot = finalizedSlot;
53
+ for (const slot of this.columnIndicesBySlot.keys()) {
54
+ if (slot < finalizedSlot) {
55
+ this.columnIndicesBySlot.delete(slot);
56
+ }
57
+ }
58
+ for (const slot of this.evidenceChecksBySlot.keys()) {
59
+ if (slot < finalizedSlot) {
60
+ this.evidenceChecksBySlot.delete(slot);
61
+ }
62
+ }
63
+ }
64
+ }
@@ -378,7 +378,7 @@ export class SeenBlockInput {
378
378
  for (const [, blockInput] of sorted) {
379
379
  this.evictBlockInput(blockInput);
380
380
  itemsToDelete--;
381
- if (itemsToDelete <= 0) return;
381
+ if (itemsToDelete <= 0) break;
382
382
  }
383
383
  }
384
384
  pruneSetToMax(this.verifiedProposerSignatures, MAX_BLOCK_INPUT_CACHE_SIZE);
@@ -64,6 +64,7 @@ export class SeenPayloadEnvelopeInput {
64
64
  private readonly metrics: Metrics | null;
65
65
  private readonly logger?: Logger;
66
66
  private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
67
+ private readonly unvalidatedRoots = new Set<RootHex>();
67
68
  // Dedup concurrent DB reloads of the same root so callers share one reconstructed object.
68
69
  private readonly reloading = new Map<RootHex, Promise<PayloadEnvelopeInput | undefined>>();
69
70
 
@@ -127,9 +128,17 @@ export class SeenPayloadEnvelopeInput {
127
128
  });
128
129
  };
129
130
 
130
- add(props: Omit<CreateFromBlockProps, "daOutOfRange">): PayloadEnvelopeInput {
131
+ /**
132
+ * Set `unvalidated` for a block of which only the proposer signature is verified, e.g. one retained for unknown
133
+ * parent sync. Such entries are evicted first when the cache is over its max size, until the block passes gossip
134
+ * validation or is imported. Adding an existing entry without `unvalidated` promotes it without replacing it.
135
+ */
136
+ add(props: Omit<CreateFromBlockProps, "daOutOfRange">, opts?: {unvalidated?: boolean}): PayloadEnvelopeInput {
131
137
  const existing = this.payloadInputs.get(props.blockRootHex);
132
138
  if (existing !== undefined) {
139
+ if (!opts?.unvalidated) {
140
+ this.unvalidatedRoots.delete(props.blockRootHex);
141
+ }
133
142
  this.logger?.verbose("SeenPayloadEnvelopeInput.add reused existing entry", {
134
143
  slot: existing.slot,
135
144
  root: props.blockRootHex,
@@ -139,6 +148,9 @@ export class SeenPayloadEnvelopeInput {
139
148
  const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
140
149
  const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
141
150
  this.payloadInputs.set(props.blockRootHex, input);
151
+ if (opts?.unvalidated) {
152
+ this.unvalidatedRoots.add(props.blockRootHex);
153
+ }
142
154
  this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: props.source});
143
155
  this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
144
156
  slot: input.slot,
@@ -300,12 +312,25 @@ export class SeenPayloadEnvelopeInput {
300
312
 
301
313
  /**
302
314
  * Bound this cache to have at most MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE items.
303
- * Evicts by insertion order so a just-reloaded old-slot entry is not evicted right after.
315
+ * Evicts entries of unvalidated blocks that are not imported yet first, then the rest by insertion order so a
316
+ * just-reloaded old-slot entry is not evicted right after.
304
317
  * On unstable network, we may need to query an evicted item, UnknownBlockInput will recover
305
318
  * it from db via getOrReload() api. Runs after every single insert, so it evicts ~1 per call.
306
319
  */
307
320
  private pruneToMaxSize(): void {
308
321
  let evicted = 0;
322
+ for (const blockRootHex of this.unvalidatedRoots) {
323
+ if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
324
+ break;
325
+ }
326
+ const input = this.payloadInputs.get(blockRootHex);
327
+ if (input === undefined || this.forkChoice.hasBlockHex(blockRootHex)) {
328
+ this.unvalidatedRoots.delete(blockRootHex);
329
+ continue;
330
+ }
331
+ this.evictPayloadInput(input, "capUnvalidated");
332
+ evicted++;
333
+ }
309
334
  for (const input of this.payloadInputs.values()) {
310
335
  if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
311
336
  break;
@@ -331,5 +356,6 @@ export class SeenPayloadEnvelopeInput {
331
356
  });
332
357
  this.serializedCache.delete(payloadInput.getSerializedCacheKeys());
333
358
  this.payloadInputs.delete(payloadInput.blockRootHex);
359
+ this.unvalidatedRoots.delete(payloadInput.blockRootHex);
334
360
  }
335
361
  }
@@ -261,10 +261,12 @@ async function validateAttestationNoSignatureCheck(
261
261
  const attSlot = attestationOrBytes.attSlot;
262
262
  attDataKey = getSeenAttDataKeyFromGossipAttestation(attestationOrBytes);
263
263
  const committeeIndexForLookup = isForkPostElectra(fork)
264
- ? (getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes) ?? 0)
264
+ ? getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes)
265
265
  : PRE_ELECTRA_SINGLE_ATTESTATION_COMMITTEE_INDEX;
266
266
  const cachedAttData =
267
- attDataKey !== null ? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey) : null;
267
+ attDataKey !== null && committeeIndexForLookup !== null
268
+ ? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey)
269
+ : null;
268
270
  if (cachedAttData === null) {
269
271
  const attestation = sszDeserializeSingleAttestation(fork, attestationOrBytes.serializedData);
270
272
  // only deserialize on the first AttestationData that's not cached