@lodestar/beacon-node 2.1.0-dev.06e42737f0 → 2.1.0-dev.07a42946c1

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 (150) 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/chain/ColumnReconstructionTracker.d.ts +3 -0
  15. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  16. package/lib/chain/ColumnReconstructionTracker.js +3 -1
  17. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  18. package/lib/chain/GetBlobsTracker.d.ts +3 -0
  19. package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
  20. package/lib/chain/GetBlobsTracker.js +3 -1
  21. package/lib/chain/GetBlobsTracker.js.map +1 -1
  22. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  23. package/lib/chain/blocks/importBlock.js +14 -5
  24. package/lib/chain/blocks/importBlock.js.map +1 -1
  25. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  26. package/lib/chain/blocks/importExecutionPayload.js +4 -2
  27. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  28. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
  29. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  30. package/lib/chain/chain.d.ts +2 -1
  31. package/lib/chain/chain.d.ts.map +1 -1
  32. package/lib/chain/chain.js +29 -6
  33. package/lib/chain/chain.js.map +1 -1
  34. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  35. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  36. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  37. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  38. package/lib/chain/forkChoice/index.d.ts +11 -2
  39. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  40. package/lib/chain/forkChoice/index.js +181 -13
  41. package/lib/chain/forkChoice/index.js.map +1 -1
  42. package/lib/chain/interface.d.ts +2 -1
  43. package/lib/chain/interface.d.ts.map +1 -1
  44. package/lib/chain/interface.js.map +1 -1
  45. package/lib/chain/opPools/opPool.d.ts +9 -3
  46. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  47. package/lib/chain/opPools/opPool.js +22 -16
  48. package/lib/chain/opPools/opPool.js.map +1 -1
  49. package/lib/chain/options.d.ts.map +1 -1
  50. package/lib/chain/options.js +1 -0
  51. package/lib/chain/options.js.map +1 -1
  52. package/lib/chain/seenCache/index.d.ts +1 -0
  53. package/lib/chain/seenCache/index.d.ts.map +1 -1
  54. package/lib/chain/seenCache/index.js +1 -0
  55. package/lib/chain/seenCache/index.js.map +1 -1
  56. package/lib/chain/seenCache/seenBlockProposers.d.ts +1 -0
  57. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  58. package/lib/chain/seenCache/seenBlockProposers.js +5 -1
  59. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  60. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts +16 -0
  61. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts.map +1 -0
  62. package/lib/chain/seenCache/seenDataColumnSidecars.js +56 -0
  63. package/lib/chain/seenCache/seenDataColumnSidecars.js.map +1 -0
  64. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +11 -2
  65. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  66. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +28 -2
  67. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  68. package/lib/chain/validation/attestation.d.ts.map +1 -1
  69. package/lib/chain/validation/attestation.js +4 -2
  70. package/lib/chain/validation/attestation.js.map +1 -1
  71. package/lib/chain/validation/block.d.ts.map +1 -1
  72. package/lib/chain/validation/block.js +12 -2
  73. package/lib/chain/validation/block.js.map +1 -1
  74. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  75. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  76. package/lib/network/forks.d.ts +2 -2
  77. package/lib/network/forks.d.ts.map +1 -1
  78. package/lib/network/forks.js +3 -3
  79. package/lib/network/forks.js.map +1 -1
  80. package/lib/network/gossip/scoringParameters.js +19 -14
  81. package/lib/network/gossip/scoringParameters.js.map +1 -1
  82. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  83. package/lib/network/processor/gossipHandlers.js +75 -9
  84. package/lib/network/processor/gossipHandlers.js.map +1 -1
  85. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  86. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -1
  87. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  88. package/lib/sync/range/chain.d.ts.map +1 -1
  89. package/lib/sync/range/chain.js +1 -0
  90. package/lib/sync/range/chain.js.map +1 -1
  91. package/lib/sync/range/range.d.ts.map +1 -1
  92. package/lib/sync/range/range.js +5 -1
  93. package/lib/sync/range/range.js.map +1 -1
  94. package/lib/sync/unknownBlock.d.ts.map +1 -1
  95. package/lib/sync/unknownBlock.js +14 -1
  96. package/lib/sync/unknownBlock.js.map +1 -1
  97. package/lib/sync/utils/downloadByRange.d.ts +6 -0
  98. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  99. package/lib/sync/utils/downloadByRange.js +17 -8
  100. package/lib/sync/utils/downloadByRange.js.map +1 -1
  101. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  102. package/lib/sync/utils/downloadByRoot.js +1 -1
  103. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  104. package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -1
  105. package/lib/sync/utils/pendingBlocksTree.js +6 -1
  106. package/lib/sync/utils/pendingBlocksTree.js.map +1 -1
  107. package/lib/util/dataColumns.d.ts +2 -1
  108. package/lib/util/dataColumns.d.ts.map +1 -1
  109. package/lib/util/dataColumns.js +7 -2
  110. package/lib/util/dataColumns.js.map +1 -1
  111. package/lib/util/execution.d.ts +2 -1
  112. package/lib/util/execution.d.ts.map +1 -1
  113. package/lib/util/execution.js +7 -2
  114. package/lib/util/execution.js.map +1 -1
  115. package/package.json +16 -19
  116. package/src/api/impl/beacon/blocks/index.ts +1 -5
  117. package/src/api/impl/beacon/pool/index.ts +11 -0
  118. package/src/api/impl/beacon/state/index.ts +3 -7
  119. package/src/api/impl/beacon/state/utils.ts +1 -1
  120. package/src/api/impl/validator/index.ts +1 -1
  121. package/src/chain/ColumnReconstructionTracker.ts +5 -1
  122. package/src/chain/GetBlobsTracker.ts +5 -0
  123. package/src/chain/blocks/importBlock.ts +14 -7
  124. package/src/chain/blocks/importExecutionPayload.ts +4 -2
  125. package/src/chain/blocks/payloadEnvelopeInput/types.ts +8 -1
  126. package/src/chain/chain.ts +34 -5
  127. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  128. package/src/chain/forkChoice/index.ts +235 -13
  129. package/src/chain/interface.ts +2 -0
  130. package/src/chain/opPools/opPool.ts +27 -16
  131. package/src/chain/options.ts +1 -0
  132. package/src/chain/seenCache/index.ts +1 -0
  133. package/src/chain/seenCache/seenBlockProposers.ts +11 -1
  134. package/src/chain/seenCache/seenDataColumnSidecars.ts +64 -0
  135. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +28 -2
  136. package/src/chain/validation/attestation.ts +4 -2
  137. package/src/chain/validation/block.ts +11 -2
  138. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  139. package/src/network/forks.ts +7 -3
  140. package/src/network/gossip/scoringParameters.ts +23 -14
  141. package/src/network/processor/gossipHandlers.ts +134 -17
  142. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
  143. package/src/sync/range/chain.ts +1 -0
  144. package/src/sync/range/range.ts +7 -1
  145. package/src/sync/unknownBlock.ts +20 -1
  146. package/src/sync/utils/downloadByRange.ts +30 -7
  147. package/src/sync/utils/downloadByRoot.ts +12 -9
  148. package/src/sync/utils/pendingBlocksTree.ts +6 -1
  149. package/src/util/dataColumns.ts +13 -1
  150. package/src/util/execution.ts +16 -1
@@ -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
  }
@@ -132,6 +132,7 @@ export const defaultChainOptions: IChainOptions = {
132
132
  // - it helps debug easier when network is unfinalized
133
133
  nHistoricalStatesFileDataStore: true,
134
134
  nativeStateTransition: true,
135
+ nativeForkChoice: false,
135
136
  maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
136
137
  maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
137
138
  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
+ }
@@ -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
@@ -76,8 +76,17 @@ export async function validateGossipBlock(
76
76
  const proposerIndex = block.proposerIndex;
77
77
  if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
78
78
  if (chain.seenBlockProposers.isRepeatProposal(blockSlot, proposerIndex, blockRoot)) {
79
- const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
80
- if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
79
+ if (chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot)) {
80
+ // The root is known with a verified signature, e.g. from the header of a data column sidecar, and a valid
81
+ // BLS signature of the same message by the same proposer is unique
82
+ if (!chain.seenBlockProposers.hasBlockSignature(blockSlot, proposerIndex, blockRoot, signedBlock.signature)) {
83
+ throw new BlockGossipError(GossipAction.REJECT, {
84
+ code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
85
+ slot: blockSlot,
86
+ root: blockRoot,
87
+ });
88
+ }
89
+ } else if (!chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
81
90
  await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
82
91
  chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
83
92
  }
@@ -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
@@ -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.
@@ -1650,3 +1706,64 @@ function getCutoffTimeMs(
1650
1706
  0
1651
1707
  );
1652
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: