@lodestar/beacon-node 2.1.0-dev.52f6c9664e → 2.1.0-dev.5aa241fdf6

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 (164) 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 +181 -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 -0
  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/forks.d.ts +2 -2
  84. package/lib/network/forks.d.ts.map +1 -1
  85. package/lib/network/forks.js +3 -3
  86. package/lib/network/forks.js.map +1 -1
  87. package/lib/network/gossip/scoringParameters.js +19 -14
  88. package/lib/network/gossip/scoringParameters.js.map +1 -1
  89. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  90. package/lib/network/processor/gossipHandlers.js +84 -16
  91. package/lib/network/processor/gossipHandlers.js.map +1 -1
  92. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  93. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -1
  94. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  95. package/lib/sync/range/chain.d.ts.map +1 -1
  96. package/lib/sync/range/chain.js +1 -0
  97. package/lib/sync/range/chain.js.map +1 -1
  98. package/lib/sync/range/range.d.ts.map +1 -1
  99. package/lib/sync/range/range.js +5 -1
  100. package/lib/sync/range/range.js.map +1 -1
  101. package/lib/sync/unknownBlock.d.ts.map +1 -1
  102. package/lib/sync/unknownBlock.js +14 -1
  103. package/lib/sync/unknownBlock.js.map +1 -1
  104. package/lib/sync/utils/downloadByRange.d.ts +6 -0
  105. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  106. package/lib/sync/utils/downloadByRange.js +17 -8
  107. package/lib/sync/utils/downloadByRange.js.map +1 -1
  108. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  109. package/lib/sync/utils/downloadByRoot.js +1 -1
  110. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  111. package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -1
  112. package/lib/sync/utils/pendingBlocksTree.js +6 -1
  113. package/lib/sync/utils/pendingBlocksTree.js.map +1 -1
  114. package/lib/util/dataColumns.d.ts +2 -1
  115. package/lib/util/dataColumns.d.ts.map +1 -1
  116. package/lib/util/dataColumns.js +7 -2
  117. package/lib/util/dataColumns.js.map +1 -1
  118. package/lib/util/execution.d.ts +2 -1
  119. package/lib/util/execution.d.ts.map +1 -1
  120. package/lib/util/execution.js +7 -2
  121. package/lib/util/execution.js.map +1 -1
  122. package/lib/util/sszBytes.d.ts.map +1 -1
  123. package/lib/util/sszBytes.js +6 -4
  124. package/lib/util/sszBytes.js.map +1 -1
  125. package/package.json +17 -20
  126. package/src/api/impl/beacon/blocks/index.ts +1 -5
  127. package/src/api/impl/beacon/pool/index.ts +11 -0
  128. package/src/api/impl/beacon/state/index.ts +3 -7
  129. package/src/api/impl/beacon/state/utils.ts +1 -1
  130. package/src/api/impl/validator/index.ts +1 -1
  131. package/src/api/rest/base.ts +5 -1
  132. package/src/chain/ColumnReconstructionTracker.ts +5 -1
  133. package/src/chain/GetBlobsTracker.ts +5 -0
  134. package/src/chain/blocks/importBlock.ts +14 -7
  135. package/src/chain/blocks/importExecutionPayload.ts +4 -2
  136. package/src/chain/blocks/payloadEnvelopeInput/types.ts +8 -1
  137. package/src/chain/chain.ts +34 -5
  138. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  139. package/src/chain/forkChoice/index.ts +235 -13
  140. package/src/chain/interface.ts +2 -0
  141. package/src/chain/opPools/opPool.ts +27 -16
  142. package/src/chain/options.ts +1 -0
  143. package/src/chain/seenCache/index.ts +1 -0
  144. package/src/chain/seenCache/seenBlockProposers.ts +11 -1
  145. package/src/chain/seenCache/seenDataColumnSidecars.ts +64 -0
  146. package/src/chain/seenCache/seenGossipBlockInput.ts +1 -1
  147. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +28 -2
  148. package/src/chain/validation/attestation.ts +4 -2
  149. package/src/chain/validation/block.ts +19 -7
  150. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  151. package/src/chain/validation/proposerSlashing.ts +5 -1
  152. package/src/network/forks.ts +7 -3
  153. package/src/network/gossip/scoringParameters.ts +23 -14
  154. package/src/network/processor/gossipHandlers.ts +146 -24
  155. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
  156. package/src/sync/range/chain.ts +1 -0
  157. package/src/sync/range/range.ts +7 -1
  158. package/src/sync/unknownBlock.ts +20 -1
  159. package/src/sync/utils/downloadByRange.ts +30 -7
  160. package/src/sync/utils/downloadByRoot.ts +12 -9
  161. package/src/sync/utils/pendingBlocksTree.ts +6 -1
  162. package/src/util/dataColumns.ts +13 -1
  163. package/src/util/execution.ts +16 -1
  164. package/src/util/sszBytes.ts +7 -8
@@ -225,7 +225,7 @@ export async function validateGossipFuluDataColumnSidecar(
225
225
 
226
226
  // 12) [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index,
227
227
  // sidecar.index) with valid header signature, sidecar inclusion proof, and kzg proof
228
- // -- Handled in seenGossipBlockInput
228
+ // -- Handled in gossip handler with seenDataColumnSidecars
229
229
  }
230
230
 
231
231
  // SPEC FUNCTION
@@ -36,7 +36,11 @@ async function validateProposerSlashing(
36
36
 
37
37
  // [REJECT] All of the conditions within process_proposer_slashing pass validation.
38
38
  try {
39
- const proposer = state.getValidator(proposerSlashing.signedHeader1.message.proposerIndex);
39
+ const {proposerIndex} = proposerSlashing.signedHeader1.message;
40
+ if (proposerIndex >= state.validatorCount) {
41
+ throw Error(`Unknown proposer index ${proposerIndex}`);
42
+ }
43
+ const proposer = state.getValidator(proposerIndex);
40
44
  // verifySignature = false, verified in batch below
41
45
  assertValidProposerSlashing(chain.config, state.slot, proposerSlashing, proposer, false);
42
46
  } catch (e) {
@@ -29,10 +29,14 @@ import {Epoch} from "@lodestar/types";
29
29
  export const FORK_EPOCH_LOOKAHEAD = 2;
30
30
 
31
31
  /**
32
- * Return the list of `ForkBoundary`s meant to be active at `epoch`
32
+ * Return the fork boundaries active at any epoch in the inclusive range.
33
33
  * @see FORK_EPOCH_LOOKAHEAD for details on when fork boundaries are considered 'active'
34
34
  */
35
- export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch): ForkBoundary[] {
35
+ export function getActiveForkBoundaries(
36
+ config: ChainForkConfig,
37
+ fromEpoch: Epoch,
38
+ toEpoch = fromEpoch
39
+ ): ForkBoundary[] {
36
40
  const activeBoundaries: ForkBoundary[] = [];
37
41
  const {forkBoundariesAscendingEpochOrder} = config;
38
42
 
@@ -48,7 +52,7 @@ export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch):
48
52
  continue;
49
53
  }
50
54
 
51
- if (epoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && epoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
55
+ if (toEpoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && fromEpoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
52
56
  activeBoundaries.push(currentForkBoundary);
53
57
  }
54
58
  }
@@ -6,8 +6,8 @@ import {
6
6
  } from "@libp2p/gossipsub/score";
7
7
  import {BeaconConfig} from "@lodestar/config";
8
8
  import {ATTESTATION_SUBNET_COUNT, PTC_SIZE, SLOTS_PER_EPOCH, TARGET_AGGREGATORS_PER_COMMITTEE} from "@lodestar/params";
9
- import {computeCommitteeCount} from "@lodestar/state-transition";
10
- import {getActiveForkBoundaries} from "../forks.js";
9
+ import {computeCommitteeCount, computeStartSlotAtEpoch} from "@lodestar/state-transition";
10
+ import {FORK_EPOCH_LOOKAHEAD, getActiveForkBoundaries} from "../forks.js";
11
11
  import {Eth2Context} from "./gossipsub.js";
12
12
  import {GossipType} from "./interface.js";
13
13
  import {stringifyGossipTopic} from "./topic.js";
@@ -132,11 +132,20 @@ function getAllTopicsScoreParams(
132
132
  precomputedParams: PreComputedParams
133
133
  ): Record<string, TopicScoreParams> {
134
134
  const {epochDurationMs, slotDurationMs} = precomputedParams;
135
- const epoch = eth2Context.currentEpoch;
136
135
  const topicsParams: Record<string, TopicScoreParams> = {};
137
- const boundaries = getActiveForkBoundaries(config, epoch);
136
+ // Gossipsub copies the score parameters at construction, including those for future subscriptions.
137
+ const boundaries = getActiveForkBoundaries(config, eth2Context.currentEpoch, Infinity);
138
138
  const beaconAttestationSubnetWeight = 1 / ATTESTATION_SUBNET_COUNT;
139
139
  for (const boundary of boundaries) {
140
+ const currentSlot = Math.max(
141
+ eth2Context.currentSlot,
142
+ computeStartSlotAtEpoch(boundary.epoch - FORK_EPOCH_LOOKAHEAD)
143
+ );
144
+ // The node subscribes to a boundary's topics FORK_EPOCH_LOOKAHEAD epochs early, but peers only publish on
145
+ // them from the boundary epoch. Hold back the mesh delivery penalty until then, otherwise every mesh peer
146
+ // is penalized for an empty topic.
147
+ const subscribeEpoch = Math.max(eth2Context.currentEpoch, boundary.epoch - FORK_EPOCH_LOOKAHEAD);
148
+ const activationDelayMs = Math.max(0, boundary.epoch - subscribeEpoch) * epochDurationMs;
140
149
  //first all fixed topics
141
150
  topicsParams[
142
151
  stringifyGossipTopic(config, {
@@ -225,8 +234,8 @@ function getAllTopicsScoreParams(
225
234
  meshMessageInfo: {
226
235
  decaySlots: SLOTS_PER_EPOCH * 5,
227
236
  capFactor: 3,
228
- activationWindow: epochDurationMs,
229
- currentSlot: eth2Context.currentSlot,
237
+ activationWindow: activationDelayMs + epochDurationMs,
238
+ currentSlot,
230
239
  },
231
240
  });
232
241
  topicsParams[
@@ -241,8 +250,8 @@ function getAllTopicsScoreParams(
241
250
  meshMessageInfo: {
242
251
  decaySlots: SLOTS_PER_EPOCH * 5,
243
252
  capFactor: 3,
244
- activationWindow: epochDurationMs,
245
- currentSlot: eth2Context.currentSlot,
253
+ activationWindow: activationDelayMs + epochDurationMs,
254
+ currentSlot,
246
255
  },
247
256
  });
248
257
 
@@ -268,8 +277,8 @@ function getAllTopicsScoreParams(
268
277
  meshMessageInfo: {
269
278
  decaySlots: SLOTS_PER_EPOCH * 2,
270
279
  capFactor: 4,
271
- activationWindow: epochDurationMs,
272
- currentSlot: eth2Context.currentSlot,
280
+ activationWindow: activationDelayMs + epochDurationMs,
281
+ currentSlot,
273
282
  },
274
283
  });
275
284
 
@@ -280,10 +289,10 @@ function getAllTopicsScoreParams(
280
289
  meshMessageInfo: {
281
290
  decaySlots: multipleBurstsPerSubnetPerEpoch ? SLOTS_PER_EPOCH * 4 : SLOTS_PER_EPOCH * 16,
282
291
  capFactor: 16,
283
- activationWindow: multipleBurstsPerSubnetPerEpoch
284
- ? slotDurationMs * (SLOTS_PER_EPOCH / 2 + 1)
285
- : epochDurationMs,
286
- currentSlot: eth2Context.currentSlot,
292
+ activationWindow:
293
+ activationDelayMs +
294
+ (multipleBurstsPerSubnetPerEpoch ? slotDurationMs * (SLOTS_PER_EPOCH / 2 + 1) : epochDurationMs),
295
+ currentSlot,
287
296
  },
288
297
  });
289
298
  for (let subnet = 0; subnet < ATTESTATION_SUBNET_COUNT; subnet++) {
@@ -12,7 +12,11 @@ import {
12
12
  isForkPostElectra,
13
13
  isForkPostGloas,
14
14
  } from "@lodestar/params";
15
- import {computeTimeAtSlot, signedBlockToSignedHeader} from "@lodestar/state-transition";
15
+ import {
16
+ computeTimeAtSlot,
17
+ getBlockHeaderProposerSignatureSetByHeaderSlot,
18
+ signedBlockToSignedHeader,
19
+ } from "@lodestar/state-transition";
16
20
  import {
17
21
  Root,
18
22
  RootHex,
@@ -25,6 +29,7 @@ import {
25
29
  gloas,
26
30
  isGloasBeaconBlock,
27
31
  isGloasDataColumnSidecar,
32
+ phase0,
28
33
  ssz,
29
34
  sszTypesFor,
30
35
  } from "@lodestar/types";
@@ -183,7 +188,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
183
188
  blockRootHex: RootHex,
184
189
  fork: ForkName,
185
190
  peerIdStr: string,
186
- seenTimestampSec: number
191
+ seenTimestampSec: number,
192
+ opts?: {unvalidated?: boolean}
187
193
  ): BlockInput {
188
194
  const blockInput = chain.seenBlockInputCache.getByBlock({
189
195
  block: signedBlock,
@@ -196,15 +202,18 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
196
202
  // Also seed the payload-envelope cache, so we have PayloadEnvelopeInput even through "PARENT_BLOCK_UNKNOWN" error
197
203
  // see https://github.com/ChainSafe/lodestar/issues/9475
198
204
  if (isForkPostGloas(fork)) {
199
- chain.seenPayloadEnvelopeInputCache.add({
200
- blockRootHex,
201
- block: signedBlock as SignedBeaconBlock<ForkPostGloas>,
202
- forkName: fork,
203
- sampledColumns: chain.custodyConfig.sampledColumns,
204
- custodyColumns: chain.custodyConfig.custodyColumns,
205
- seenTimestampSec,
206
- source: PayloadEnvelopeInputSource.gossip,
207
- });
205
+ chain.seenPayloadEnvelopeInputCache.add(
206
+ {
207
+ blockRootHex,
208
+ block: signedBlock as SignedBeaconBlock<ForkPostGloas>,
209
+ forkName: fork,
210
+ sampledColumns: chain.custodyConfig.sampledColumns,
211
+ custodyColumns: chain.custodyConfig.custodyColumns,
212
+ seenTimestampSec,
213
+ source: PayloadEnvelopeInputSource.gossip,
214
+ },
215
+ opts
216
+ );
208
217
  }
209
218
 
210
219
  return blockInput;
@@ -300,7 +309,9 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
300
309
  }
301
310
  chain.seenBlockProposers.add(slot, proposerIndex, blockRootHex);
302
311
 
303
- const blockInput = cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec);
312
+ const blockInput = cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec, {
313
+ unvalidated: true,
314
+ });
304
315
  chain.emitter.emit(ChainEvent.blockUnknownParent, {
305
316
  blockInput,
306
317
  peer: peerIdStr,
@@ -374,6 +385,28 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
374
385
  }
375
386
  }
376
387
 
388
+ // The block input may have been pruned before the block was imported
389
+ if (
390
+ chain.seenDataColumnSidecars.isKnown(
391
+ slot,
392
+ dataColumnBlockHeader.proposerIndex,
393
+ dataColumnSidecar.index,
394
+ blockRootHex
395
+ )
396
+ ) {
397
+ metrics?.peerDas.dataColumnSidecarProcessingSkip.inc();
398
+ throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
399
+ code: DataColumnSidecarErrorCode.ALREADY_KNOWN,
400
+ columnIndex: dataColumnSidecar.index,
401
+ slot,
402
+ });
403
+ }
404
+
405
+ if (isRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex)) {
406
+ await observeRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex);
407
+ throw repeatColumnProposalError(dataColumnSidecar, blockRootHex);
408
+ }
409
+
377
410
  const verificationTimer = metrics?.peerDas.dataColumnSidecarGossipVerificationTime.startTimer();
378
411
 
379
412
  const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
@@ -382,6 +415,17 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
382
415
 
383
416
  try {
384
417
  await validateGossipFuluDataColumnSidecar(chain, dataColumnSidecar, gossipSubnet, metrics);
418
+ observeColumnBlockHeader(chain, dataColumnSidecar.signedBlockHeader, blockRootHex);
419
+ // Another block root may have been seen for the same tuple while validating
420
+ if (isRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex)) {
421
+ throw repeatColumnProposalError(dataColumnSidecar, blockRootHex);
422
+ }
423
+ chain.seenDataColumnSidecars.add(
424
+ slot,
425
+ dataColumnBlockHeader.proposerIndex,
426
+ dataColumnSidecar.index,
427
+ blockRootHex
428
+ );
385
429
  const blockInput = chain.seenBlockInputCache.getByColumn({
386
430
  blockRootHex,
387
431
  columnSidecar: dataColumnSidecar,
@@ -575,7 +619,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
575
619
  const delaySec = seenTimestampSec - computeTimeAtSlot(config, slot, chain.genesisTime);
576
620
  metrics?.gossipBlock.elapsedTimeTillReceived.observe({source: OpSource.gossip}, delaySec);
577
621
  chain.validatorMonitor?.registerBeaconBlock(OpSource.gossip, delaySec, signedBlock.message);
578
- if (!blockInput.hasBlockAndAllData()) {
622
+ const missingData = !blockInput.hasBlockAndAllData();
623
+ if (missingData) {
579
624
  chain.logger.debug("Received gossip block, attempting fetch of unavailable data", blockInput.getLogMeta());
580
625
  // The data is not yet fully available, immediately trigger an aggressive pull via unknown block sync
581
626
  chain.emitter.emit(ChainEvent.incompleteBlockInput, {
@@ -668,8 +713,13 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
668
713
  }
669
714
  metrics?.gossipBlock.processBlockErrors.inc({error: e instanceof BlockError ? e.type.code : "NOT_BLOCK_ERROR"});
670
715
  logger[logLevel]("Error processing block", {slot, root: blockInput.blockRootHex, peer: peerIdStr}, e as Error);
671
- // TODO(fulu): Revisit when we prune block inputs
672
- chain.seenBlockInputCache.prune(blockInput.blockRootHex);
716
+ // BlockInputSync retries the import of a block with missing data from this same BlockInput, pruning it here
717
+ // would put later gossip columns into a new BlockInput that is never imported. The entry is released once the
718
+ // block is persisted, BlockInputSync removes it, on finalization or by the cache size limit
719
+ if (!missingData) {
720
+ // TODO(fulu): Revisit when we prune block inputs
721
+ chain.seenBlockInputCache.prune(blockInput.blockRootHex);
722
+ }
673
723
  });
674
724
  }
675
725
 
@@ -707,7 +757,12 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
707
757
  e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
708
758
  // Only a signature-verified sibling recorded in the seen cache is imported. The cache holds at most two
709
759
  // roots per proposer and slot, which bounds full imports over gossip to one alternate
710
- chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root) &&
760
+ chain.seenBlockProposers.hasBlockSignature(
761
+ signedBlock.message.slot,
762
+ e.type.proposerIndex,
763
+ e.type.root,
764
+ signedBlock.signature
765
+ ) &&
711
766
  // A sibling with an unknown parent cannot be imported, sync fetches it if its branch becomes relevant
712
767
  chain.forkChoice.getBlockHexDefaultStatus(toRootHex(signedBlock.message.parentRoot)) !== null &&
713
768
  (!isGloasBeaconBlock(signedBlock.message) ||
@@ -721,7 +776,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
721
776
  e.type.root,
722
777
  topic.boundary.fork,
723
778
  peerIdStr,
724
- seenTimestampSec
779
+ seenTimestampSec,
780
+ {unvalidated: false}
725
781
  );
726
782
  // We're returning IGNORE (thrown below), so this block is not forwarded to peers. Unlike the
727
783
  // happy path there is no rush to forward, so we don't need to wrap in callInNextEventLoop.
@@ -1295,20 +1351,25 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
1295
1351
  try {
1296
1352
  const delaySec = chain.clock.secFromSlot(payloadAttestationMessage.data.slot, seenTimestampSec);
1297
1353
  metrics?.gossipPayloadAttestationMessage.elapsedTimeTillReceived.observe({source: OpSource.gossip}, delaySec);
1298
- const nextSlotProposer = chain.getHeadState().getBeaconProposer(payloadAttestationMessage.data.slot + 1);
1299
- const isNextSlotProposer = chain.beaconProposerCache.has(nextSlotProposer);
1300
-
1301
- if (isNextSlotProposer) {
1302
- try {
1354
+ try {
1355
+ const nextSlotProposer = chain.getHeadState().getBeaconProposer(payloadAttestationMessage.data.slot + 1);
1356
+ if (chain.beaconProposerCache.has(nextSlotProposer)) {
1303
1357
  const insertOutcome = chain.payloadAttestationPool.add(
1304
1358
  payloadAttestationMessage,
1305
1359
  validationResult.attDataRootHex,
1306
1360
  validationResult.validatorCommitteeIndices
1307
1361
  );
1308
1362
  metrics?.opPool.payloadAttestationPool.gossipInsertOutcome.inc({insertOutcome});
1309
- } catch (e) {
1310
- logger.debug("Error adding to payloadAttestation pool", {}, e as Error);
1311
1363
  }
1364
+ } catch (e) {
1365
+ logger.debug(
1366
+ "Error adding to payloadAttestation pool",
1367
+ {
1368
+ slot: payloadAttestationMessage.data.slot,
1369
+ root: toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
1370
+ },
1371
+ e as Error
1372
+ );
1312
1373
  }
1313
1374
 
1314
1375
  // Gossip accepts adjacent slots within the clock disparity but fork choice only counts the current slot
@@ -1645,3 +1706,64 @@ function getCutoffTimeMs(
1645
1706
  0
1646
1707
  );
1647
1708
  }
1709
+
1710
+ /**
1711
+ * [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index, sidecar.index)
1712
+ * with valid header signature, sidecar inclusion proof, and kzg proof
1713
+ */
1714
+ function isRepeatColumnProposal(
1715
+ chain: IBeaconChain,
1716
+ dataColumnSidecar: fulu.DataColumnSidecar,
1717
+ blockRootHex: RootHex
1718
+ ): boolean {
1719
+ const {slot, proposerIndex} = dataColumnSidecar.signedBlockHeader.message;
1720
+ return chain.seenDataColumnSidecars.isRepeatProposal(slot, proposerIndex, dataColumnSidecar.index, blockRootHex);
1721
+ }
1722
+
1723
+ function repeatColumnProposalError(
1724
+ dataColumnSidecar: fulu.DataColumnSidecar,
1725
+ blockRootHex: RootHex
1726
+ ): DataColumnSidecarGossipError {
1727
+ const {slot, proposerIndex} = dataColumnSidecar.signedBlockHeader.message;
1728
+ return new DataColumnSidecarGossipError(GossipAction.IGNORE, {
1729
+ code: DataColumnSidecarErrorCode.REPEAT_PROPOSAL,
1730
+ slot,
1731
+ proposerIndex,
1732
+ columnIndex: dataColumnSidecar.index,
1733
+ root: blockRootHex,
1734
+ });
1735
+ }
1736
+
1737
+ function observeColumnBlockHeader(
1738
+ chain: IBeaconChain,
1739
+ signedBlockHeader: phase0.SignedBeaconBlockHeader,
1740
+ blockRootHex: RootHex
1741
+ ): void {
1742
+ const {slot, proposerIndex} = signedBlockHeader.message;
1743
+ chain.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRootHex, signedBlockHeader);
1744
+ if (chain.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
1745
+ chain.processProposerEquivocation(slot, proposerIndex);
1746
+ }
1747
+ }
1748
+
1749
+ async function observeRepeatColumnProposal(
1750
+ chain: IBeaconChain,
1751
+ dataColumnSidecar: fulu.DataColumnSidecar,
1752
+ blockRootHex: RootHex
1753
+ ): Promise<void> {
1754
+ const {signedBlockHeader} = dataColumnSidecar;
1755
+ const {slot, proposerIndex} = signedBlockHeader.message;
1756
+ // Only needed as slashing evidence, so verify at most one conflicting header per slot and proposer
1757
+ if (
1758
+ chain.seenBlockProposers.hasBlockRoot(slot, proposerIndex, blockRootHex) ||
1759
+ chain.seenBlockProposers.isEquivocating(slot, proposerIndex) ||
1760
+ !chain.seenDataColumnSidecars.markEvidenceCheck(slot, proposerIndex)
1761
+ ) {
1762
+ return;
1763
+ }
1764
+
1765
+ const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(chain.config, signedBlockHeader);
1766
+ if (await chain.bls.verifySignatureSets([signatureSet])) {
1767
+ observeColumnBlockHeader(chain, signedBlockHeader, blockRootHex);
1768
+ }
1769
+ }
@@ -226,5 +226,8 @@ export function validateDataColumnSidecarsByRangeRequest(
226
226
  count = config.MAX_REQUEST_BLOCKS_DENEB;
227
227
  }
228
228
 
229
- return {startSlot, count, columns};
229
+ // Spec: sidecars MUST be sent in (slot, column_index) order, so serve each requested column once, ascending
230
+ const sortedColumns = Array.from(new Set(columns)).sort((a, b) => a - b);
231
+
232
+ return {startSlot, count, columns: sortedColumns};
230
233
  }
@@ -627,6 +627,7 @@ export class SyncChain {
627
627
  case DownloadByRangeErrorCode.INVALID_ENVELOPE_BLOCK_HASH:
628
628
  case DownloadByRangeErrorCode.INVALID_ENVELOPE_SLOT:
629
629
  case DownloadByRangeErrorCode.INVALID_CHAIN_SEGMENT:
630
+ case DownloadByRangeErrorCode.TOO_MANY_KZG_COMMITMENTS:
630
631
  case DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT:
631
632
  case DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT:
632
633
  case DataColumnSidecarErrorCode.INVALID_KZG_PROOF_BATCH:
@@ -1,6 +1,7 @@
1
1
  import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {BeaconConfig} from "@lodestar/config";
4
+ import {isForkPostGloas} from "@lodestar/params";
4
5
  import {IBeaconStateViewGloas, computeStartSlotAtEpoch, isStatePostGloas} from "@lodestar/state-transition";
5
6
  import {Epoch, Status, fulu, ssz} from "@lodestar/types";
6
7
  import {Logger, byteArrayEquals, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
@@ -434,7 +435,12 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
434
435
  // the batch then downloads the head's payload as dangling parent and validates it against the bid
435
436
  const headState = this.chain.getHeadState();
436
437
  let parentPayload: ParentPayload | undefined;
437
- if (isStatePostGloas(headState) && headState.latestBlockHeader.slot > 0) {
438
+ // A pre-Gloas head block in a state upgraded to Gloas carried its own payload, no envelope follows it
439
+ if (
440
+ isStatePostGloas(headState) &&
441
+ headState.latestBlockHeader.slot > 0 &&
442
+ isForkPostGloas(this.config.getForkName(headState.latestBlockHeader.slot))
443
+ ) {
438
444
  const header = ssz.phase0.BeaconBlockHeader.clone(headState.latestBlockHeader);
439
445
  if (byteArrayEquals(header.stateRoot, ssz.Root.defaultValue())) {
440
446
  header.stateRoot = headState.hashTreeRoot();
@@ -928,6 +928,19 @@ export class BlockInputSync {
928
928
  const connectedPeers = this.network.getConnectedPeers();
929
929
  const hasConnectedPeers = connectedPeers.length > 0;
930
930
 
931
+ // Gossip, getBlobs or column reconstruction can complete a pending block's data through the shared BlockInput.
932
+ // With only half the columns the block stays pending, its fetch asks a peer for the rest before reconstructing
933
+ for (const block of this.pendingBlocks.values()) {
934
+ if (
935
+ isPendingBlockInput(block) &&
936
+ block.status === PendingBlockInputStatus.pending &&
937
+ block.blockInput.hasBlockAndAllData() &&
938
+ (!isBlockInputColumns(block.blockInput) || block.blockInput.hasComputedAllData())
939
+ ) {
940
+ block.status = PendingBlockInputStatus.downloaded;
941
+ }
942
+ }
943
+
931
944
  const {unknowns, ancestors} = getUnknownAndAncestorBlocks(this.pendingBlocks);
932
945
  let processedBlocks = 0;
933
946
  let shouldRerunBlockSearch = false;
@@ -2201,7 +2214,13 @@ export class BlockInputSync {
2201
2214
  const cacheItemRootHex = getBlockInputSyncCacheItemRootHex(cacheItem);
2202
2215
  // pruning may have dropped it mid-fetch
2203
2216
  if (this.pendingBlocks.has(cacheItemRootHex)) {
2204
- this.pendingBlocks.set(cacheItemRootHex, cacheItem);
2217
+ // A partial download stays fetching while the next peer is asked, a pending entry would be fetched again
2218
+ this.pendingBlocks.set(
2219
+ cacheItemRootHex,
2220
+ cacheItem.status === PendingBlockInputStatus.pending
2221
+ ? {...cacheItem, status: PendingBlockInputStatus.fetching}
2222
+ : cacheItem
2223
+ );
2205
2224
  }
2206
2225
 
2207
2226
  if (cacheItem.status === PendingBlockInputStatus.downloaded) {
@@ -1,5 +1,14 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {ForkName, ForkPostFulu, ForkPostGloas, isForkPostFulu, isForkPostGloas} from "@lodestar/params";
2
+ import {
3
+ ForkName,
4
+ ForkPostDeneb,
5
+ ForkPostFulu,
6
+ ForkPostGloas,
7
+ isForkPostDeneb,
8
+ isForkPostFulu,
9
+ isForkPostGloas,
10
+ } from "@lodestar/params";
11
+ import {computeEpochAtSlot} from "@lodestar/state-transition";
3
12
  import {
4
13
  ColumnIndex,
5
14
  DataColumnSidecar,
@@ -28,6 +37,7 @@ import {INetwork} from "../../network/index.js";
28
37
  import {CustodyConfig, getBlobKzgCommitments} from "../../util/dataColumns.js";
29
38
  import {PeerIdStr} from "../../util/peerId.js";
30
39
  import {WarnResult} from "../../util/wrapError.js";
40
+ import {getRateLimitedUntilMs} from "./rateLimit.js";
31
41
 
32
42
  export type DownloadByRangeRequests = {
33
43
  blocksRequest?: phase0.BeaconBlocksByRangeRequest;
@@ -327,6 +337,8 @@ export async function downloadByRange({
327
337
  parentPayloadRequest,
328
338
  });
329
339
  } catch (err) {
340
+ // Rethrow rate limit errors as is, so range sync can back off from the peer instead of counting a failed download
341
+ if (getRateLimitedUntilMs(err) !== null) throw err;
330
342
  throw new DownloadByRangeError({
331
343
  code: DownloadByRangeErrorCode.REQ_RESP_ERROR,
332
344
  reason: (err as Error).message,
@@ -697,6 +709,15 @@ export function validateBlockByRangeResponse(
697
709
 
698
710
  for (let i = 0; i < blocks.length; i++) {
699
711
  const block = blocks[i];
712
+ const slot = block.message.slot;
713
+ const fork = config.getForkName(slot);
714
+ if (isForkPostDeneb(fork)) {
715
+ const count = getBlobKzgCommitments(fork, block as SignedBeaconBlock<ForkPostDeneb>).length;
716
+ const limit = config.getMaxBlobsPerBlock(computeEpochAtSlot(slot));
717
+ if (count > limit) {
718
+ throw new DownloadByRangeError({code: DownloadByRangeErrorCode.TOO_MANY_KZG_COMMITMENTS, slot, count, limit});
719
+ }
720
+ }
700
721
  const blockRoot = type.hashTreeRoot(block.message);
701
722
  response.push({block, blockRoot});
702
723
 
@@ -825,12 +846,7 @@ export async function validateColumnsByRangeResponse(
825
846
  }
826
847
 
827
848
  seenSlotColumns.set(columnSidecar.index, columnSidecar);
828
- if (currentSlot !== slot) {
829
- // a new slot has started, reset index
830
- currentIndex = -1;
831
- } else {
832
- currentIndex = columnSidecar.index;
833
- }
849
+ currentIndex = columnSidecar.index;
834
850
  currentSlot = slot;
835
851
  }
836
852
 
@@ -1030,6 +1046,7 @@ export enum DownloadByRangeErrorCode {
1030
1046
 
1031
1047
  PARENT_ROOT_MISMATCH = "DOWNLOAD_BY_RANGE_ERROR_PARENT_ROOT_MISMATCH",
1032
1048
  EXTRA_BLOCKS = "DOWNLOAD_BY_RANGE_ERROR_EXTRA_BLOCKS",
1049
+ TOO_MANY_KZG_COMMITMENTS = "DOWNLOAD_BY_RANGE_ERROR_TOO_MANY_KZG_COMMITMENTS",
1033
1050
  OUT_OF_RANGE_BLOCKS = "DOWNLOAD_BY_RANGE_OUT_OF_RANGE_BLOCKS",
1034
1051
  OUT_OF_ORDER_BLOCKS = "DOWNLOAD_BY_RANGE_OUT_OF_ORDER_BLOCKS",
1035
1052
 
@@ -1072,6 +1089,12 @@ export type DownloadByRangeErrorType =
1072
1089
  columnSidecarCount: number;
1073
1090
  payloadEnvelopeCount: number;
1074
1091
  }
1092
+ | {
1093
+ code: DownloadByRangeErrorCode.TOO_MANY_KZG_COMMITMENTS;
1094
+ slot: Slot;
1095
+ count: number;
1096
+ limit: number;
1097
+ }
1075
1098
  | {
1076
1099
  code: DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS;
1077
1100
  slot: number;
@@ -104,15 +104,18 @@ export async function downloadByRoot({
104
104
  }
105
105
 
106
106
  if (isForkPostGloas(blockInput.forkName)) {
107
- chain.seenPayloadEnvelopeInputCache.add({
108
- blockRootHex: rootHex,
109
- block: blockInput.getBlock() as SignedBeaconBlock<ForkPostGloas>,
110
- forkName: blockInput.forkName,
111
- sampledColumns: chain.custodyConfig.sampledColumns,
112
- custodyColumns: chain.custodyConfig.custodyColumns,
113
- seenTimestampSec: Date.now() / 1000,
114
- source: PayloadEnvelopeInputSource.byRoot,
115
- });
107
+ chain.seenPayloadEnvelopeInputCache.add(
108
+ {
109
+ blockRootHex: rootHex,
110
+ block: blockInput.getBlock() as SignedBeaconBlock<ForkPostGloas>,
111
+ forkName: blockInput.forkName,
112
+ sampledColumns: chain.custodyConfig.sampledColumns,
113
+ custodyColumns: chain.custodyConfig.custodyColumns,
114
+ seenTimestampSec: Date.now() / 1000,
115
+ source: PayloadEnvelopeInputSource.byRoot,
116
+ },
117
+ {unvalidated: true}
118
+ );
116
119
  }
117
120
 
118
121
  // Like range sync, download every sampled column, half of them only counts as available for reconstruction
@@ -1,5 +1,6 @@
1
1
  import {RootHex} from "@lodestar/types";
2
2
  import {MapDef} from "@lodestar/utils";
3
+ import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
3
4
  import {
4
5
  BlockInputSyncCacheItem,
5
6
  PendingBlockInput,
@@ -61,9 +62,13 @@ export function getUnknownAndAncestorBlocks(blocks: Map<RootHex, BlockInputSyncC
61
62
  const ancestors = new Map<RootHex, PendingBlockInput>();
62
63
 
63
64
  for (const block of blocks.values()) {
65
+ // Half the columns counts as all data, but a pending block is only complete with all sampled columns
64
66
  if (
65
67
  block.status === PendingBlockInputStatus.pending &&
66
- (isPendingBlockInput(block) ? !block.blockInput.hasBlockAndAllData() : true)
68
+ (isPendingBlockInput(block)
69
+ ? !block.blockInput.hasBlockAndAllData() ||
70
+ (isBlockInputColumns(block.blockInput) && !block.blockInput.hasComputedAllData())
71
+ : true)
67
72
  ) {
68
73
  unknowns.set(getBlockInputSyncCacheItemRootHex(block), block);
69
74
  } else if (
@@ -33,6 +33,7 @@ import {BlockInputColumns} from "../chain/blocks/blockInput/blockInput.js";
33
33
  import {BlockInputSource} from "../chain/blocks/blockInput/types.js";
34
34
  import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/payloadEnvelopeInput/index.js";
35
35
  import {ChainEvent, ChainEventEmitter} from "../chain/emitter.js";
36
+ import {SeenDataColumnSidecars} from "../chain/seenCache/seenDataColumnSidecars.js";
36
37
  import {Metrics} from "../metrics/metrics.js";
37
38
  import {NodeId} from "../network/subnets/index.js";
38
39
  import {dataColumnMatrixRecovery} from "./blobs.js";
@@ -434,6 +435,7 @@ export function getGloasDataColumnSidecars(
434
435
  export async function recoverDataColumnSidecars(
435
436
  input: BlockInputColumns | PayloadEnvelopeInput,
436
437
  emitter: ChainEventEmitter,
438
+ seenDataColumnSidecars: SeenDataColumnSidecars,
437
439
  metrics: Metrics | null
438
440
  ): Promise<DataColumnReconstructionCode> {
439
441
  const existingColumns = input.getAllColumns();
@@ -486,6 +488,7 @@ export async function recoverDataColumnSidecars(
486
488
  const sidecarsToPublish: DataColumnSidecar[] = [];
487
489
  for (const columnSidecar of fullSidecars) {
488
490
  if (!input.hasColumn(columnSidecar.index)) {
491
+ let isRepeatProposal = false;
489
492
  if (input instanceof PayloadEnvelopeInput) {
490
493
  if (!isGloasDataColumnSidecar(columnSidecar)) {
491
494
  throw new Error(`Expected gloas DataColumnSidecar for block ${input.blockRootHex}`);
@@ -505,9 +508,18 @@ export async function recoverDataColumnSidecars(
505
508
  seenTimestampSec: Date.now() / 1000,
506
509
  source: BlockInputSource.recovery,
507
510
  });
511
+ // Reconstructed columns count as received via gossip for the repeat proposal check
512
+ const {slot, proposerIndex} = columnSidecar.signedBlockHeader.message;
513
+ isRepeatProposal = seenDataColumnSidecars.isRepeatProposal(
514
+ slot,
515
+ proposerIndex,
516
+ columnSidecar.index,
517
+ input.blockRootHex
518
+ );
519
+ seenDataColumnSidecars.add(slot, proposerIndex, columnSidecar.index, input.blockRootHex);
508
520
  }
509
521
  sidecarsReconstructed.push(columnSidecar);
510
- if (missingSampledColumns.has(columnSidecar.index)) {
522
+ if (missingSampledColumns.has(columnSidecar.index) && !isRepeatProposal) {
511
523
  sidecarsToPublish.push(columnSidecar);
512
524
  }
513
525
  }