@lodestar/beacon-node 1.52.0-dev.20cca3c9f1 → 1.52.0-dev.263ed9ded6

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 (128) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +4 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.js +1 -1
  5. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  6. package/lib/api/impl/validator/index.d.ts.map +1 -1
  7. package/lib/api/impl/validator/index.js +72 -40
  8. package/lib/api/impl/validator/index.js.map +1 -1
  9. package/lib/chain/archiveStore/utils/archiveBlocks.js +1 -1
  10. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  11. package/lib/chain/chain.d.ts +1 -1
  12. package/lib/chain/chain.d.ts.map +1 -1
  13. package/lib/chain/chain.js +9 -16
  14. package/lib/chain/chain.js.map +1 -1
  15. package/lib/chain/errors/executionPayloadBid.d.ts +5 -0
  16. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  17. package/lib/chain/errors/executionPayloadBid.js +1 -0
  18. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  19. package/lib/chain/produceBlock/produceBlockBody.d.ts +5 -2
  20. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  21. package/lib/chain/produceBlock/produceBlockBody.js +31 -49
  22. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  23. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  24. package/lib/chain/validation/attesterSlashing.js +4 -2
  25. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  26. package/lib/chain/validation/executionPayloadBid.js +11 -1
  27. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  28. package/lib/chain/validation/payloadAttestationMessage.js +2 -2
  29. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  30. package/lib/chain/validation/proposerSlashing.js +4 -2
  31. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  32. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  33. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  34. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  35. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  36. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  37. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  38. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  39. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  40. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
  41. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  42. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  43. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  44. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  45. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  46. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +2 -2
  47. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  48. package/lib/chain/validation/syncCommittee.d.ts +1 -1
  49. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  50. package/lib/chain/validation/syncCommittee.js +5 -5
  51. package/lib/chain/validation/syncCommittee.js.map +1 -1
  52. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  53. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  54. package/lib/network/core/events.d.ts +6 -2
  55. package/lib/network/core/events.d.ts.map +1 -1
  56. package/lib/network/core/events.js +9 -0
  57. package/lib/network/core/events.js.map +1 -1
  58. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  59. package/lib/network/core/networkCoreWorkerHandler.js +3 -2
  60. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  61. package/lib/network/network.js +6 -6
  62. package/lib/network/network.js.map +1 -1
  63. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -1
  64. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  65. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
  66. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  67. package/lib/sync/range/batch.d.ts +4 -0
  68. package/lib/sync/range/batch.d.ts.map +1 -1
  69. package/lib/sync/range/batch.js +12 -0
  70. package/lib/sync/range/batch.js.map +1 -1
  71. package/lib/sync/range/chain.d.ts +17 -2
  72. package/lib/sync/range/chain.d.ts.map +1 -1
  73. package/lib/sync/range/chain.js +52 -19
  74. package/lib/sync/range/chain.js.map +1 -1
  75. package/lib/sync/range/range.d.ts.map +1 -1
  76. package/lib/sync/range/range.js +1 -0
  77. package/lib/sync/range/range.js.map +1 -1
  78. package/lib/sync/range/utils/batches.d.ts +20 -4
  79. package/lib/sync/range/utils/batches.d.ts.map +1 -1
  80. package/lib/sync/range/utils/batches.js +31 -13
  81. package/lib/sync/range/utils/batches.js.map +1 -1
  82. package/lib/sync/range/utils/peerBalancer.d.ts +1 -1
  83. package/lib/sync/range/utils/peerBalancer.d.ts.map +1 -1
  84. package/lib/sync/range/utils/peerBalancer.js +5 -2
  85. package/lib/sync/range/utils/peerBalancer.js.map +1 -1
  86. package/lib/sync/utils/downloadByRange.d.ts +8 -0
  87. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  88. package/lib/sync/utils/downloadByRange.js +43 -23
  89. package/lib/sync/utils/downloadByRange.js.map +1 -1
  90. package/lib/util/asyncIterableToEvents.d.ts +20 -3
  91. package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
  92. package/lib/util/asyncIterableToEvents.js +76 -20
  93. package/lib/util/asyncIterableToEvents.js.map +1 -1
  94. package/lib/util/dataColumns.d.ts +1 -1
  95. package/lib/util/dataColumns.d.ts.map +1 -1
  96. package/lib/util/dataColumns.js +4 -1
  97. package/lib/util/dataColumns.js.map +1 -1
  98. package/package.json +16 -16
  99. package/src/api/impl/beacon/blocks/index.ts +4 -3
  100. package/src/api/impl/beacon/pool/index.ts +1 -1
  101. package/src/api/impl/validator/index.ts +105 -57
  102. package/src/chain/archiveStore/utils/archiveBlocks.ts +1 -1
  103. package/src/chain/chain.ts +8 -36
  104. package/src/chain/errors/executionPayloadBid.ts +6 -0
  105. package/src/chain/produceBlock/produceBlockBody.ts +44 -64
  106. package/src/chain/validation/attesterSlashing.ts +4 -2
  107. package/src/chain/validation/executionPayloadBid.ts +15 -6
  108. package/src/chain/validation/payloadAttestationMessage.ts +2 -2
  109. package/src/chain/validation/proposerSlashing.ts +4 -2
  110. package/src/chain/validation/signatureSets/contributionAndProof.ts +4 -6
  111. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -3
  112. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -3
  113. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -3
  114. package/src/chain/validation/syncCommittee.ts +3 -5
  115. package/src/chain/validation/syncCommitteeContributionAndProof.ts +3 -3
  116. package/src/network/core/events.ts +12 -0
  117. package/src/network/core/networkCoreWorkerHandler.ts +6 -2
  118. package/src/network/network.ts +6 -6
  119. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +1 -1
  120. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
  121. package/src/sync/range/batch.ts +13 -0
  122. package/src/sync/range/chain.ts +64 -17
  123. package/src/sync/range/range.ts +1 -0
  124. package/src/sync/range/utils/batches.ts +38 -13
  125. package/src/sync/range/utils/peerBalancer.ts +4 -1
  126. package/src/sync/utils/downloadByRange.ts +60 -26
  127. package/src/util/asyncIterableToEvents.ts +100 -21
  128. package/src/util/dataColumns.ts +4 -1
@@ -24,6 +24,7 @@ import {
24
24
  G2_POINT_AT_INFINITY,
25
25
  IBeaconStateView,
26
26
  type IBeaconStateViewBellatrix,
27
+ type IBeaconStateViewGloas,
27
28
  computeEpochAtSlot,
28
29
  computeTimeAtSlot,
29
30
  getExpectedGasLimit,
@@ -111,6 +112,12 @@ export type BlockAttributes = {
111
112
  graffiti: Bytes32;
112
113
  slot: Slot;
113
114
  parentBlock: ProtoBlock;
115
+ // the state of parentBlock processed to slot
116
+ parentState: IBeaconStateView;
117
+ // parentStateWithPayload is the same as parentState for pre-gloas or if building on EMPTY
118
+ parentStateWithPayload: IBeaconStateView;
119
+ // Parent's execution requests, undefined pre-gloas.
120
+ parentExecutionRequests?: gloas.ExecutionRequests;
114
121
  feeRecipient?: string;
115
122
  /** Verify that a locally produced execution payload uses `feeRecipient`. */
116
123
  strictFeeRecipientCheck?: boolean;
@@ -175,32 +182,9 @@ export type ProduceResult =
175
182
  | ProduceFullPhase0
176
183
  | ProduceBlinded;
177
184
 
178
- /**
179
- * Drop voluntary exits that `parent_execution_requests` have invalidated (e.g. a withdrawal
180
- * request initiating an exit on the same validator). Op pool selected against the unapplied
181
- * state, so re-validate against the post-apply state to avoid producing an invalid block.
182
- *
183
- * `getStateAfterParentPayload` is a thunk so the post-apply state is only materialized when
184
- * actually needed (i.e. when extending the parent payload and there are exits to filter).
185
- */
186
- function maybeFilterInvalidatedVoluntaryExits(
187
- commonBlockBody: CommonBlockBody,
188
- isExtendingPayload: boolean,
189
- getStateAfterParentPayload: () => IBeaconStateViewBellatrix
190
- ): CommonBlockBody["voluntaryExits"] {
191
- if (!isExtendingPayload || commonBlockBody.voluntaryExits.length === 0) {
192
- return commonBlockBody.voluntaryExits;
193
- }
194
- const state = getStateAfterParentPayload();
195
- return commonBlockBody.voluntaryExits.filter((signedVoluntaryExit) =>
196
- state.isValidVoluntaryExit(signedVoluntaryExit, false)
197
- );
198
- }
199
-
200
185
  export async function produceBlockBody<T extends BlockType>(
201
186
  this: BeaconChain,
202
187
  blockType: T,
203
- currentState: IBeaconStateView,
204
188
  blockAttr: BlockAttributes & {
205
189
  proposerIndex: ValidatorIndex;
206
190
  proposerPubKey: BLSPubkey;
@@ -221,6 +205,9 @@ export async function produceBlockBody<T extends BlockType>(
221
205
  proposerPubKey,
222
206
  commonBlockBodyPromise,
223
207
  builderBid,
208
+ parentState,
209
+ parentStateWithPayload,
210
+ parentExecutionRequests,
224
211
  } = blockAttr;
225
212
  let executionPayloadValue: Wei;
226
213
  let blockBody: AssembledBodyType<T>;
@@ -242,17 +229,17 @@ export async function produceBlockBody<T extends BlockType>(
242
229
  this.logger.verbose("Producing beacon block body", logMeta);
243
230
 
244
231
  if (builderBid !== undefined) {
245
- if (!isStatePostGloas(currentState)) {
246
- throw new Error("Expected Gloas state for builder bid block production");
232
+ if (!isStatePostGloas(parentState)) {
233
+ throw new Error(`Expected Gloas state for builder bid block production slot=${blockSlot}`);
234
+ }
235
+ if (parentExecutionRequests === undefined) {
236
+ throw new Error(`Expected parentExecutionRequests for gloas block production slot=${blockSlot}`);
247
237
  }
248
238
 
249
239
  const isExtendingPayload = byteArrayEquals(
250
240
  builderBid.message.parentBlockHash,
251
- currentState.latestExecutionPayloadBid.blockHash
241
+ parentState.latestExecutionPayloadBid.blockHash
252
242
  );
253
- const parentExecutionRequests = isExtendingPayload
254
- ? await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot)
255
- : ssz.gloas.ExecutionRequests.defaultValue();
256
243
  executionPayloadValue = (BigInt(builderBid.message.value) + builderBid.message.executionPayment) * GWEI_TO_WEI;
257
244
 
258
245
  const commonBlockBody = await commonBlockBodyPromise;
@@ -262,10 +249,9 @@ export async function produceBlockBody<T extends BlockType>(
262
249
  parentBlock.blockRoot,
263
250
  blockSlot - 1
264
251
  );
252
+ // parentExecutionRequests fetched once by the entrypoint (isExtendingPayload aligns with the
253
+ // build-on-full decision used to select this bid; default value when building on an empty parent)
265
254
  gloasBody.parentExecutionRequests = parentExecutionRequests;
266
- gloasBody.voluntaryExits = maybeFilterInvalidatedVoluntaryExits(commonBlockBody, isExtendingPayload, () =>
267
- currentState.withParentPayloadApplied(parentExecutionRequests)
268
- );
269
255
  blockBody = gloasBody as AssembledBodyType<T>;
270
256
 
271
257
  this.logger.verbose("Produced block with builder bid", {
@@ -278,8 +264,11 @@ export async function produceBlockBody<T extends BlockType>(
278
264
  isExtendingPayload,
279
265
  });
280
266
  } else if (isForkPostGloas(fork)) {
281
- if (!isStatePostGloas(currentState)) {
282
- throw new Error("Expected Gloas state for Gloas block production");
267
+ if (!isStatePostGloas(parentState)) {
268
+ throw new Error(`Expected Gloas state for Gloas block production slot=${blockSlot}`);
269
+ }
270
+ if (parentExecutionRequests === undefined) {
271
+ throw new Error(`Expected parentExecutionRequests for gloas block production slot=${blockSlot}`);
283
272
  }
284
273
 
285
274
  // TODO GLOAS: support non self-building here, the block type differentiation between
@@ -299,20 +288,16 @@ export async function produceBlockBody<T extends BlockType>(
299
288
 
300
289
  // Get execution payload from EL
301
290
  let parentBlockHash: Bytes32;
302
- let parentExecutionRequests: gloas.ExecutionRequests;
303
- // Apply parent payload once here as it's reused by EL prep and voluntary exit filtering below
304
- let stateAfterParentPayload: IBeaconStateViewBellatrix = currentState;
305
- // Spec: should_build_on_full(store, head, slot). `parentBlock` is the proposer's head
306
- // (set by chain.getProposerHead(slot)). Returns false when the PTC majority signalled
307
- // the blob data is not available or the payload was not timely, forcing a build on EMPTY (reorg).
308
- const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock, blockSlot);
291
+ const stateAfterParentPayload = parentStateWithPayload as IBeaconStateViewGloas;
292
+ // Spec: should_build_on_full(store, head, slot), decided by the caller when applying the parent payload
293
+ const isBuildingOnFull = byteArrayEquals(
294
+ stateAfterParentPayload.latestBlockHash,
295
+ parentState.latestExecutionPayloadBid.blockHash
296
+ );
309
297
  if (isBuildingOnFull) {
310
- parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;
311
- parentExecutionRequests = await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot);
312
- stateAfterParentPayload = currentState.withParentPayloadApplied(parentExecutionRequests);
298
+ parentBlockHash = parentState.latestExecutionPayloadBid.blockHash;
313
299
  } else {
314
- parentBlockHash = currentState.latestExecutionPayloadBid.parentBlockHash;
315
- parentExecutionRequests = ssz.gloas.ExecutionRequests.defaultValue();
300
+ parentBlockHash = parentState.latestExecutionPayloadBid.parentBlockHash;
316
301
  }
317
302
  const prepareRes = await prepareExecutionPayload(
318
303
  this,
@@ -377,7 +362,7 @@ export async function produceBlockBody<T extends BlockType>(
377
362
  parentBlockHash,
378
363
  parentBlockRoot,
379
364
  blockHash: executionPayload.blockHash,
380
- prevRandao: currentState.getRandaoMix(currentState.epoch),
365
+ prevRandao: parentState.getRandaoMix(parentState.epoch),
381
366
  feeRecipient: executionPayload.feeRecipient,
382
367
  gasLimit: BigInt(executionPayload.gasLimit),
383
368
  builderIndex: BUILDER_INDEX_SELF_BUILD,
@@ -414,12 +399,8 @@ export async function produceBlockBody<T extends BlockType>(
414
399
  parentBlock.blockRoot,
415
400
  blockSlot - 1
416
401
  );
402
+ // parentExecutionRequests fetched once by the entrypoint (default value when building on an empty parent)
417
403
  gloasBody.parentExecutionRequests = parentExecutionRequests;
418
- gloasBody.voluntaryExits = maybeFilterInvalidatedVoluntaryExits(
419
- commonBlockBody,
420
- isBuildingOnFull,
421
- () => stateAfterParentPayload
422
- );
423
404
  blockBody = gloasBody as AssembledBodyType<T>;
424
405
 
425
406
  // Store execution payload data required to construct execution payload envelope later
@@ -449,7 +430,7 @@ export async function produceBlockBody<T extends BlockType>(
449
430
  shouldOverrideBuilder,
450
431
  });
451
432
  } else if (isForkPostBellatrix(fork)) {
452
- if (!isStatePostBellatrix(currentState)) {
433
+ if (!isStatePostBellatrix(parentState)) {
453
434
  throw new Error("Expected Bellatrix state for execution block production");
454
435
  }
455
436
 
@@ -478,10 +459,10 @@ export async function produceBlockBody<T extends BlockType>(
478
459
  this.logger,
479
460
  fork,
480
461
  parentBlockRoot,
481
- currentState.latestExecutionPayloadHeader.blockHash,
462
+ parentState.latestExecutionPayloadHeader.blockHash,
482
463
  safeBlockHash,
483
464
  finalizedBlockHash ?? ZERO_HASH_HEX,
484
- currentState,
465
+ parentState,
485
466
  executionBuilder.issueLocalFcUWithFeeRecipient
486
467
  );
487
468
  }
@@ -493,7 +474,7 @@ export async function produceBlockBody<T extends BlockType>(
493
474
  slot: blockSlot,
494
475
  proposerPubKey: toHex(proposerPubKey),
495
476
  });
496
- const headerRes = await prepareExecutionPayloadHeader(this, fork, currentState, proposerPubKey);
477
+ const headerRes = await prepareExecutionPayloadHeader(this, fork, parentState, proposerPubKey);
497
478
 
498
479
  endExecutionPayloadHeader?.({
499
480
  step: BlockProductionStep.executionPayload,
@@ -528,7 +509,7 @@ export async function produceBlockBody<T extends BlockType>(
528
509
  });
529
510
  } else {
530
511
  const headerGasLimit = builderRes.header.gasLimit;
531
- const parentGasLimit = currentState.latestExecutionPayloadHeader.gasLimit;
512
+ const parentGasLimit = parentState.latestExecutionPayloadHeader.gasLimit;
532
513
  const expectedGasLimit = getExpectedGasLimit(parentGasLimit, targetGasLimit);
533
514
 
534
515
  const lowerBound = Math.min(parentGasLimit, expectedGasLimit);
@@ -582,10 +563,10 @@ export async function produceBlockBody<T extends BlockType>(
582
563
  this.logger,
583
564
  fork,
584
565
  parentBlockRoot,
585
- currentState.latestExecutionPayloadHeader.blockHash,
566
+ parentState.latestExecutionPayloadHeader.blockHash,
586
567
  safeBlockHash,
587
568
  finalizedBlockHash ?? ZERO_HASH_HEX,
588
- currentState,
569
+ parentState,
589
570
  feeRecipient
590
571
  );
591
572
 
@@ -1111,8 +1092,7 @@ export function getPooledProposerPreferences(
1111
1092
  export async function produceCommonBlockBody<T extends BlockType>(
1112
1093
  this: BeaconChain,
1113
1094
  blockType: T,
1114
- currentState: IBeaconStateView,
1115
- {randaoReveal, graffiti, slot, parentBlock}: BlockAttributes
1095
+ {randaoReveal, graffiti, slot, parentBlock, parentStateWithPayload}: BlockAttributes
1116
1096
  ): Promise<CommonBlockBody> {
1117
1097
  const stepsMetrics =
1118
1098
  blockType === BlockType.Full
@@ -1133,7 +1113,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
1133
1113
  // }
1134
1114
  // }
1135
1115
  const [attesterSlashings, proposerSlashings, voluntaryExits, blsToExecutionChanges] =
1136
- this.opPool.getSlashingsAndExits(currentState, blockType, this.metrics);
1116
+ this.opPool.getSlashingsAndExits(parentStateWithPayload, blockType, this.metrics);
1137
1117
 
1138
1118
  const endAttestations = stepsMetrics?.startTimer();
1139
1119
  // TODO: extract to a separate BeaconChain method to coordinate the 2 op-pools
@@ -1141,7 +1121,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
1141
1121
  fork,
1142
1122
  this.forkChoice,
1143
1123
  this.shufflingCache,
1144
- currentState,
1124
+ parentStateWithPayload,
1145
1125
  this.singleAttestationPool
1146
1126
  );
1147
1127
  endAttestations?.({
@@ -1172,7 +1152,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
1172
1152
  };
1173
1153
 
1174
1154
  if (!isForkPostHeze(fork)) {
1175
- commonBlockBody.eth1Data = currentState.eth1Data;
1155
+ commonBlockBody.eth1Data = parentStateWithPayload.eth1Data;
1176
1156
  commonBlockBody.deposits = [];
1177
1157
  }
1178
1158
 
@@ -61,8 +61,10 @@ export async function validateAttesterSlashing(
61
61
  });
62
62
  }
63
63
 
64
- const signatureSets = getAttesterSlashingSignatureSets(chain.config, state.slot, attesterSlashing);
65
- const verifiedDomains = getAttesterSlashingSignatureDomains(chain.config, state.slot, attesterSlashing);
64
+ // Head state may lag behind a fork transition, verify against the fork of the clock slot
65
+ const currentSlot = chain.clock.currentSlot;
66
+ const signatureSets = getAttesterSlashingSignatureSets(chain.config, currentSlot, attesterSlashing);
67
+ const verifiedDomains = getAttesterSlashingSignatureDomains(chain.config, currentSlot, attesterSlashing);
66
68
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
67
69
  throw new AttesterSlashingError(GossipAction.REJECT, {
68
70
  code: AttesterSlashingErrorCode.INVALID_SIGNATURE,
@@ -214,12 +214,21 @@ async function validateExecutionPayloadBid(
214
214
  if (isForkPostHeze(chain.config.getForkName(bid.slot))) {
215
215
  const {inclusionListBits} = bid as heze.ExecutionPayloadBid;
216
216
  const inclusionListSlot = bid.slot - 1;
217
- const inclusionListDependentRoot = getShufflingDependentRoot(
218
- chain.forkChoice,
219
- computeEpochAtSlot(inclusionListSlot),
220
- computeEpochAtSlot(parentBlock.slot),
221
- parentBlock
222
- );
217
+ let inclusionListDependentRoot: RootHex;
218
+ try {
219
+ inclusionListDependentRoot = getShufflingDependentRoot(
220
+ chain.forkChoice,
221
+ computeEpochAtSlot(inclusionListSlot),
222
+ computeEpochAtSlot(parentBlock.slot),
223
+ parentBlock
224
+ );
225
+ } catch {
226
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
227
+ code: ExecutionPayloadBidErrorCode.UNKNOWN_INCLUSION_LIST_DEPENDENT_ROOT,
228
+ slot: bid.slot,
229
+ parentBlockRoot: bidParentBlockRoot,
230
+ });
231
+ }
223
232
  if (
224
233
  !chain.inclusionListStore.isInclusionListBitsInclusive(
225
234
  inclusionListSlot,
@@ -105,8 +105,8 @@ async function validatePayloadAttestationMessage(
105
105
  }
106
106
 
107
107
  // [REJECT] The message's validator index is within the payload committee in
108
- // `get_ptc(state, data.slot)`. The `state` is the head state corresponding to
109
- // processing the block up to the current slot as determined by the fork choice.
108
+ // `get_ptc(state, data.slot)`. The `state` is the post-state of the attested block,
109
+ // so the committee is the one of the block's branch, as in fork choice.
110
110
  // The validator may occupy multiple PTC positions because `compute_ptc` samples
111
111
  // by effective balance — collect all of them so duplicate votes are counted.
112
112
  const validatorCommitteeIndices = state.getIndicesInPayloadTimelinessCommittee(validatorIndex, data.slot);
@@ -46,8 +46,10 @@ async function validateProposerSlashing(
46
46
  });
47
47
  }
48
48
 
49
- const signatureSets = getProposerSlashingSignatureSets(chain.config, state.slot, proposerSlashing);
50
- const verifiedDomain = getProposerSlashingSignatureDomain(chain.config, state.slot, proposerSlashing);
49
+ // Head state may lag behind a fork transition, verify against the fork of the clock slot
50
+ const currentSlot = chain.clock.currentSlot;
51
+ const signatureSets = getProposerSlashingSignatureSets(chain.config, currentSlot, proposerSlashing);
52
+ const verifiedDomain = getProposerSlashingSignatureDomain(chain.config, currentSlot, proposerSlashing);
51
53
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
52
54
  throw new ProposerSlashingError(GossipAction.REJECT, {
53
55
  code: ProposerSlashingErrorCode.INVALID_SIGNATURE,
@@ -1,17 +1,15 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_CONTRIBUTION_AND_PROOF} from "@lodestar/params";
3
- import {IBeaconStateView, ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
3
+ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
4
4
  import {altair, ssz} from "@lodestar/types";
5
5
 
6
6
  export function getContributionAndProofSignatureSet(
7
7
  config: BeaconConfig,
8
- state: IBeaconStateView,
9
8
  signedContributionAndProof: altair.SignedContributionAndProof
10
9
  ): ISignatureSet {
11
- const domain = config.getDomain(
12
- state.slot,
13
- DOMAIN_CONTRIBUTION_AND_PROOF,
14
- signedContributionAndProof.message.contribution.slot
10
+ const domain = config.getDomainAtFork(
11
+ config.getForkName(signedContributionAndProof.message.contribution.slot),
12
+ DOMAIN_CONTRIBUTION_AND_PROOF
15
13
  );
16
14
  const signingData = signedContributionAndProof.message;
17
15
  return {
@@ -1,14 +1,13 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_SYNC_COMMITTEE} from "@lodestar/params";
3
- import {IBeaconStateView, ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
3
+ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
4
4
  import {altair, ssz} from "@lodestar/types";
5
5
 
6
6
  export function getSyncCommitteeSignatureSet(
7
7
  config: BeaconConfig,
8
- state: IBeaconStateView,
9
8
  syncCommittee: altair.SyncCommitteeMessage
10
9
  ): ISignatureSet {
11
- const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, syncCommittee.slot);
10
+ const domain = config.getDomainAtFork(config.getForkName(syncCommittee.slot), DOMAIN_SYNC_COMMITTEE);
12
11
 
13
12
  return {
14
13
  type: SignatureSetType.indexed,
@@ -1,15 +1,14 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_SYNC_COMMITTEE} from "@lodestar/params";
3
- import {IBeaconStateView, ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
3
+ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
4
4
  import {altair, ssz} from "@lodestar/types";
5
5
 
6
6
  export function getSyncCommitteeContributionSignatureSet(
7
7
  config: BeaconConfig,
8
- state: IBeaconStateView,
9
8
  contribution: altair.SyncCommitteeContribution,
10
9
  participantIndices: number[]
11
10
  ): ISignatureSet {
12
- const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, contribution.slot);
11
+ const domain = config.getDomainAtFork(config.getForkName(contribution.slot), DOMAIN_SYNC_COMMITTEE);
13
12
  return {
14
13
  type: SignatureSetType.aggregate,
15
14
  indices: participantIndices,
@@ -1,15 +1,14 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF} from "@lodestar/params";
3
- import {IBeaconStateView, ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
3
+ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
4
4
  import {altair, ssz} from "@lodestar/types";
5
5
 
6
6
  export function getSyncCommitteeSelectionProofSignatureSet(
7
7
  config: BeaconConfig,
8
- state: IBeaconStateView,
9
8
  contributionAndProof: altair.ContributionAndProof
10
9
  ): ISignatureSet {
11
10
  const slot = contributionAndProof.contribution.slot;
12
- const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF, slot);
11
+ const domain = config.getDomainAtFork(config.getForkName(slot), DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF);
13
12
  const signingData: altair.SyncAggregatorSelectionData = {
14
13
  slot,
15
14
  subcommitteeIndex: contributionAndProof.contribution.subcommitteeIndex,
@@ -40,7 +40,7 @@ export async function validateGossipSyncCommittee(
40
40
  // > Checked in validateGossipSyncCommitteeExceptSig()
41
41
 
42
42
  // [REJECT] The signature is valid for the message beacon_block_root for the validator referenced by validator_index.
43
- await validateSyncCommitteeSigOnly(chain, headState, syncCommittee);
43
+ await validateSyncCommitteeSigOnly(chain, syncCommittee);
44
44
 
45
45
  // Re-check after the await: concurrent messages from the same validator all pass the check above.
46
46
  // Metrics were already counted by the first check.
@@ -89,11 +89,10 @@ function assertSyncCommitteeMessageNotKnown(
89
89
 
90
90
  export async function validateApiSyncCommittee(
91
91
  chain: IBeaconChain,
92
- headState: IBeaconStateView,
93
92
  syncCommittee: altair.SyncCommitteeMessage
94
93
  ): Promise<void> {
95
94
  const prioritizeBls = true;
96
- return validateSyncCommitteeSigOnly(chain, headState, syncCommittee, prioritizeBls);
95
+ return validateSyncCommitteeSigOnly(chain, syncCommittee, prioritizeBls);
97
96
  }
98
97
 
99
98
  /**
@@ -101,11 +100,10 @@ export async function validateApiSyncCommittee(
101
100
  */
102
101
  async function validateSyncCommitteeSigOnly(
103
102
  chain: IBeaconChain,
104
- headState: IBeaconStateView,
105
103
  syncCommittee: altair.SyncCommitteeMessage,
106
104
  prioritizeBls = false
107
105
  ): Promise<void> {
108
- const signatureSet = getSyncCommitteeSignatureSet(chain.config, headState, syncCommittee);
106
+ const signatureSet = getSyncCommitteeSignatureSet(chain.config, syncCommittee);
109
107
  if (!(await chain.bls.verifySignatureSets([signatureSet], {batchable: true, priority: prioritizeBls}))) {
110
108
  throw new SyncCommitteeError(GossipAction.REJECT, {
111
109
  code: SyncCommitteeErrorCode.INVALID_SIGNATURE,
@@ -76,14 +76,14 @@ export async function validateSyncCommitteeGossipContributionAndProof(
76
76
  const signatureSets = [
77
77
  // [REJECT] The contribution_and_proof.selection_proof is a valid signature of the SyncAggregatorSelectionData
78
78
  // derived from the contribution by the validator with index contribution_and_proof.aggregator_index.
79
- getSyncCommitteeSelectionProofSignatureSet(chain.config, headState, contributionAndProof),
79
+ getSyncCommitteeSelectionProofSignatureSet(chain.config, contributionAndProof),
80
80
 
81
81
  // [REJECT] The aggregator signature, signed_contribution_and_proof.signature, is valid.
82
- getContributionAndProofSignatureSet(chain.config, headState, signedContributionAndProof),
82
+ getContributionAndProofSignatureSet(chain.config, signedContributionAndProof),
83
83
 
84
84
  // [REJECT] The aggregate signature is valid for the message beacon_block_root and aggregate pubkey derived from
85
85
  // the participation info in aggregation_bits for the subcommittee specified by the contribution.subcommittee_index.
86
- getSyncCommitteeContributionSignatureSet(chain.config, headState, contribution, syncCommitteeParticipantIndices),
86
+ getSyncCommitteeContributionSignatureSet(chain.config, contribution, syncCommitteeParticipantIndices),
87
87
  ];
88
88
 
89
89
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true}))) {
@@ -5,6 +5,7 @@ import {
5
5
  IteratorEvent,
6
6
  RequestCancelEvent,
7
7
  RequestEvent,
8
+ ResponsePullEvent,
8
9
  } from "../../util/asyncIterableToEvents.js";
9
10
  import {StrictEventEmitterSingleArg} from "../../util/strictEvents.js";
10
11
  import {EventDirection} from "../events.js";
@@ -14,18 +15,22 @@ export enum ReqRespBridgeEvent {
14
15
  outgoingRequest = "reqresp.outgoingRequest",
15
16
  outgoingRequestCancel = "reqresp.outgoingRequestCancel",
16
17
  outgoingResponse = "reqresp.outgoingResponse",
18
+ outgoingResponsePull = "reqresp.outgoingResponsePull",
17
19
  incomingRequest = "reqresp.incomingRequest",
18
20
  incomingRequestCancel = "reqresp.incomingRequestCancel",
19
21
  incomingResponse = "reqresp.incomingResponse",
22
+ incomingResponsePull = "reqresp.incomingResponsePull",
20
23
  }
21
24
 
22
25
  export type ReqRespBridgeEventData = {
23
26
  [ReqRespBridgeEvent.outgoingRequest]: RequestEvent<OutgoingRequestArgs>;
24
27
  [ReqRespBridgeEvent.outgoingRequestCancel]: RequestCancelEvent;
25
28
  [ReqRespBridgeEvent.outgoingResponse]: IteratorEvent<ResponseOutgoing>;
29
+ [ReqRespBridgeEvent.outgoingResponsePull]: ResponsePullEvent;
26
30
  [ReqRespBridgeEvent.incomingRequest]: RequestEvent<IncomingRequestArgs>;
27
31
  [ReqRespBridgeEvent.incomingRequestCancel]: RequestCancelEvent;
28
32
  [ReqRespBridgeEvent.incomingResponse]: IteratorEvent<ResponseIncoming>;
33
+ [ReqRespBridgeEvent.incomingResponsePull]: ResponsePullEvent;
29
34
  };
30
35
 
31
36
  type IReqRespBridgeEventBus = StrictEventEmitterSingleArg<ReqRespBridgeEventData>;
@@ -37,9 +42,12 @@ export const reqRespBridgeEventDirection: Record<ReqRespBridgeEvent, EventDirect
37
42
  [ReqRespBridgeEvent.outgoingRequest]: EventDirection.mainToWorker,
38
43
  [ReqRespBridgeEvent.outgoingRequestCancel]: EventDirection.mainToWorker,
39
44
  [ReqRespBridgeEvent.outgoingResponse]: EventDirection.mainToWorker,
45
+ // Credit flows from the consumer back to the producer, opposite the response it paces
46
+ [ReqRespBridgeEvent.outgoingResponsePull]: EventDirection.workerToMain,
40
47
  [ReqRespBridgeEvent.incomingRequest]: EventDirection.workerToMain,
41
48
  [ReqRespBridgeEvent.incomingRequestCancel]: EventDirection.workerToMain,
42
49
  [ReqRespBridgeEvent.incomingResponse]: EventDirection.workerToMain,
50
+ [ReqRespBridgeEvent.incomingResponsePull]: EventDirection.mainToWorker,
43
51
  };
44
52
 
45
53
  export function getReqRespBridgeReqEvents(
@@ -49,9 +57,11 @@ export function getReqRespBridgeReqEvents(
49
57
  emitRequest: (data) => events.emit(ReqRespBridgeEvent.outgoingRequest, data),
50
58
  emitRequestCancel: (data) => events.emit(ReqRespBridgeEvent.outgoingRequestCancel, data),
51
59
  emitResponse: (data) => events.emit(ReqRespBridgeEvent.incomingResponse, data),
60
+ emitResponsePull: (data) => events.emit(ReqRespBridgeEvent.incomingResponsePull, data),
52
61
  onRequest: (cb) => events.on(ReqRespBridgeEvent.outgoingRequest, cb),
53
62
  onRequestCancel: (cb) => events.on(ReqRespBridgeEvent.outgoingRequestCancel, cb),
54
63
  onResponse: (cb) => events.on(ReqRespBridgeEvent.incomingResponse, cb),
64
+ onResponsePull: (cb) => events.on(ReqRespBridgeEvent.incomingResponsePull, cb),
55
65
  };
56
66
  }
57
67
 
@@ -62,9 +72,11 @@ export function getReqRespBridgeRespEvents(
62
72
  emitRequest: (data) => events.emit(ReqRespBridgeEvent.incomingRequest, data),
63
73
  emitRequestCancel: (data) => events.emit(ReqRespBridgeEvent.incomingRequestCancel, data),
64
74
  emitResponse: (data) => events.emit(ReqRespBridgeEvent.outgoingResponse, data),
75
+ emitResponsePull: (data) => events.emit(ReqRespBridgeEvent.outgoingResponsePull, data),
65
76
  onRequest: (cb) => events.on(ReqRespBridgeEvent.incomingRequest, cb),
66
77
  onRequestCancel: (cb) => events.on(ReqRespBridgeEvent.incomingRequestCancel, cb),
67
78
  onResponse: (cb) => events.on(ReqRespBridgeEvent.outgoingResponse, cb),
79
+ onResponsePull: (cb) => events.on(ReqRespBridgeEvent.outgoingResponsePull, cb),
68
80
  };
69
81
  }
70
82
 
@@ -74,8 +74,12 @@ export class WorkerNetworkCore implements INetworkCore {
74
74
  private readonly reqRespBridgeEventBus = new ReqRespBridgeEventBus();
75
75
 
76
76
  constructor(private readonly modules: WorkerNetworkCoreModules) {
77
- // Get called from main thread to issue a ReqResp request, and emits event to worker
78
- this.reqRespBridgeReqCaller = new AsyncIterableBridgeCaller(getReqRespBridgeReqEvents(this.reqRespBridgeEventBus));
77
+ // Get called from main thread to issue a ReqResp request, and emits event to worker. Unbounded: we
78
+ // buffer the whole response into an array anyway, so pacing the worker only risks a read buffer overflow
79
+ this.reqRespBridgeReqCaller = new AsyncIterableBridgeCaller(
80
+ getReqRespBridgeReqEvents(this.reqRespBridgeEventBus),
81
+ Infinity
82
+ );
79
83
  // Handles ReqResp response from worker and calls async generator in main thread
80
84
  this.reqRespBridgeRespHandler = new AsyncIterableBridgeHandler(
81
85
  getReqRespBridgeRespEvents(this.reqRespBridgeEventBus),
@@ -424,8 +424,8 @@ export class Network implements INetwork {
424
424
  }
425
425
 
426
426
  async publishVoluntaryExit(voluntaryExit: phase0.SignedVoluntaryExit): Promise<number> {
427
- const epoch = voluntaryExit.message.epoch;
428
- const boundary = this.config.getForkBoundaryAtEpoch(epoch);
427
+ // An exit stays valid indefinitely but peers unsubscribe from the topics of previous forks
428
+ const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
429
429
 
430
430
  return this.publishGossip<GossipType.voluntary_exit>({type: GossipType.voluntary_exit, boundary}, voluntaryExit);
431
431
  }
@@ -455,8 +455,8 @@ export class Network implements INetwork {
455
455
  }
456
456
 
457
457
  async publishProposerSlashing(proposerSlashing: phase0.ProposerSlashing): Promise<number> {
458
- const epoch = computeEpochAtSlot(Number(proposerSlashing.signedHeader1.message.slot as bigint));
459
- const boundary = this.config.getForkBoundaryAtEpoch(epoch);
458
+ // The slashed headers can be from a previous fork but peers unsubscribe from the topics of previous forks
459
+ const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
460
460
 
461
461
  return this.publishGossip<GossipType.proposer_slashing>(
462
462
  {type: GossipType.proposer_slashing, boundary},
@@ -465,8 +465,8 @@ export class Network implements INetwork {
465
465
  }
466
466
 
467
467
  async publishAttesterSlashing(attesterSlashing: AttesterSlashing): Promise<number> {
468
- const epoch = computeEpochAtSlot(Number(attesterSlashing.attestation1.data.slot as bigint));
469
- const boundary = this.config.getForkBoundaryAtEpoch(epoch);
468
+ // The slashed attestations can be from a previous fork but peers unsubscribe from the topics of previous forks
469
+ const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
470
470
 
471
471
  return this.publishGossip<GossipType.attester_slashing>(
472
472
  {type: GossipType.attester_slashing, boundary},
@@ -216,7 +216,7 @@ export function validateDataColumnSidecarsByRangeRequest(
216
216
  throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis");
217
217
  }
218
218
 
219
- // Spec: [max(compute_blob_data_retention_start_epoch(current_epoch), FULU_FORK_EPOCH), current_epoch]
219
+ // Spec: [max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH), current_epoch]
220
220
  const minimumRequestEpoch = Math.max(getBlobDataRetentionStartEpoch(config, currentEpoch), config.FULU_FORK_EPOCH);
221
221
  if (computeEpochAtSlot(startSlot) < minimumRequestEpoch) {
222
222
  throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, "startSlot is before the blob data retention window");
@@ -19,7 +19,7 @@ export async function* onDataColumnSidecarsByRoot(
19
19
  peerId: PeerId,
20
20
  peerClient: string
21
21
  ): AsyncIterable<ResponseOutgoing> {
22
- // SPEC: minimum_request_epoch = max(compute_blob_data_retention_start_epoch(current_epoch), FULU_FORK_EPOCH)
22
+ // SPEC: minimum_request_epoch = max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH)
23
23
  const currentEpoch = chain.clock.currentEpoch;
24
24
  const minimumRequestEpoch = Math.max(
25
25
  getBlobDataRetentionStartEpoch(chain.config, currentEpoch),
@@ -430,6 +430,19 @@ export class Batch {
430
430
  return [...this.failedProcessingAttempts, ...this.executionErrorAttempts].filter((a) => a.peerAttributable);
431
431
  }
432
432
 
433
+ /**
434
+ * How many failed processing/execution attempts each peer took part in, peer-attributable or not
435
+ */
436
+ getTriedPeerCounts(): Map<PeerIdStr, number> {
437
+ const counts = new Map<PeerIdStr, number>();
438
+ for (const attempt of [...this.failedProcessingAttempts, ...this.executionErrorAttempts]) {
439
+ for (const peer of attempt.peers) {
440
+ counts.set(peer, (counts.get(peer) ?? 0) + 1);
441
+ }
442
+ }
443
+ return counts;
444
+ }
445
+
433
446
  /**
434
447
  * True only if the peer has already returned a successful response for the current request.
435
448
  * A by_range success may update `this.requests` to parent_payload, and the same peer is then