@lodestar/beacon-node 1.44.0-dev.9d8b487a59 → 1.44.0-dev.a879adb124

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 (126) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +13 -5
  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 +1 -1
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/config/constants.d.ts +1 -0
  8. package/lib/api/impl/config/constants.d.ts.map +1 -1
  9. package/lib/api/impl/config/constants.js +2 -1
  10. package/lib/api/impl/config/constants.js.map +1 -1
  11. package/lib/api/impl/debug/index.d.ts.map +1 -1
  12. package/lib/api/impl/debug/index.js +69 -12
  13. package/lib/api/impl/debug/index.js.map +1 -1
  14. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  15. package/lib/api/impl/lodestar/index.js +28 -0
  16. package/lib/api/impl/lodestar/index.js.map +1 -1
  17. package/lib/api/impl/validator/index.d.ts.map +1 -1
  18. package/lib/api/impl/validator/index.js +21 -9
  19. package/lib/api/impl/validator/index.js.map +1 -1
  20. package/lib/chain/archiveStore/archiveStore.d.ts +0 -1
  21. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  22. package/lib/chain/archiveStore/archiveStore.js +0 -4
  23. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  24. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  25. package/lib/chain/blocks/importBlock.js +1 -1
  26. package/lib/chain/blocks/importBlock.js.map +1 -1
  27. package/lib/chain/chain.d.ts.map +1 -1
  28. package/lib/chain/chain.js +8 -1
  29. package/lib/chain/chain.js.map +1 -1
  30. package/lib/chain/errors/payloadAttestation.d.ts +6 -0
  31. package/lib/chain/errors/payloadAttestation.d.ts.map +1 -1
  32. package/lib/chain/errors/payloadAttestation.js +1 -0
  33. package/lib/chain/errors/payloadAttestation.js.map +1 -1
  34. package/lib/chain/forkChoice/index.d.ts +4 -4
  35. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  36. package/lib/chain/forkChoice/index.js +7 -7
  37. package/lib/chain/forkChoice/index.js.map +1 -1
  38. package/lib/chain/options.d.ts.map +1 -1
  39. package/lib/chain/options.js +1 -0
  40. package/lib/chain/options.js.map +1 -1
  41. package/lib/chain/prepareNextSlot.js +1 -1
  42. package/lib/chain/prepareNextSlot.js.map +1 -1
  43. package/lib/chain/produceBlock/produceBlockBody.js +3 -3
  44. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  45. package/lib/chain/regen/interface.d.ts +1 -1
  46. package/lib/chain/regen/interface.d.ts.map +1 -1
  47. package/lib/chain/regen/interface.js +1 -0
  48. package/lib/chain/regen/interface.js.map +1 -1
  49. package/lib/chain/regen/queued.d.ts +0 -1
  50. package/lib/chain/regen/queued.d.ts.map +1 -1
  51. package/lib/chain/regen/queued.js +0 -4
  52. package/lib/chain/regen/queued.js.map +1 -1
  53. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +0 -5
  54. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  55. package/lib/chain/stateCache/fifoBlockStateCache.js +0 -5
  56. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  57. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +1 -4
  58. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  59. package/lib/chain/stateCache/persistentCheckpointsCache.js +5 -2
  60. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  61. package/lib/chain/stateCache/types.d.ts +0 -2
  62. package/lib/chain/stateCache/types.d.ts.map +1 -1
  63. package/lib/chain/stateCache/types.js.map +1 -1
  64. package/lib/chain/validation/executionPayloadBid.js +22 -5
  65. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  66. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  67. package/lib/chain/validation/payloadAttestationMessage.js +24 -4
  68. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  69. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  70. package/lib/network/processor/gossipHandlers.js +1 -1
  71. package/lib/network/processor/gossipHandlers.js.map +1 -1
  72. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  73. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +9 -5
  74. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  75. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  76. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +13 -3
  77. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  78. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
  79. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  80. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts +2 -1
  81. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -1
  82. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +16 -6
  83. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -1
  84. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts +2 -1
  85. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -1
  86. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +15 -1
  87. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
  88. package/lib/network/reqresp/handlers/index.js +4 -4
  89. package/lib/network/reqresp/handlers/index.js.map +1 -1
  90. package/lib/network/reqresp/utils/dataColumnResponseValidation.d.ts.map +1 -1
  91. package/lib/network/reqresp/utils/dataColumnResponseValidation.js +22 -3
  92. package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
  93. package/lib/util/dataColumns.d.ts.map +1 -1
  94. package/lib/util/dataColumns.js +16 -11
  95. package/lib/util/dataColumns.js.map +1 -1
  96. package/package.json +14 -16
  97. package/src/api/impl/beacon/blocks/index.ts +13 -5
  98. package/src/api/impl/beacon/pool/index.ts +1 -0
  99. package/src/api/impl/config/constants.ts +2 -0
  100. package/src/api/impl/debug/index.ts +73 -12
  101. package/src/api/impl/lodestar/index.ts +30 -0
  102. package/src/api/impl/validator/index.ts +23 -14
  103. package/src/chain/archiveStore/archiveStore.ts +0 -5
  104. package/src/chain/blocks/importBlock.ts +1 -0
  105. package/src/chain/chain.ts +10 -1
  106. package/src/chain/errors/payloadAttestation.ts +2 -0
  107. package/src/chain/forkChoice/index.ts +8 -0
  108. package/src/chain/options.ts +1 -0
  109. package/src/chain/prepareNextSlot.ts +1 -1
  110. package/src/chain/produceBlock/produceBlockBody.ts +3 -3
  111. package/src/chain/regen/interface.ts +1 -1
  112. package/src/chain/regen/queued.ts +0 -5
  113. package/src/chain/stateCache/fifoBlockStateCache.ts +0 -6
  114. package/src/chain/stateCache/persistentCheckpointsCache.ts +6 -2
  115. package/src/chain/stateCache/types.ts +0 -2
  116. package/src/chain/validation/executionPayloadBid.ts +23 -5
  117. package/src/chain/validation/payloadAttestationMessage.ts +26 -4
  118. package/src/network/processor/gossipHandlers.ts +1 -0
  119. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +12 -5
  120. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +17 -3
  121. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
  122. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +22 -6
  123. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +20 -1
  124. package/src/network/reqresp/handlers/index.ts +4 -4
  125. package/src/network/reqresp/utils/dataColumnResponseValidation.ts +21 -3
  126. package/src/util/dataColumns.ts +17 -12
@@ -2,6 +2,7 @@ import {ChainForkConfig} from "@lodestar/config";
2
2
  import {
3
3
  ExecutionStatus,
4
4
  ForkChoice,
5
+ ForkChoiceStateGetter,
5
6
  ForkChoiceStore,
6
7
  JustifiedBalancesGetter,
7
8
  PayloadStatus,
@@ -45,6 +46,7 @@ export function initializeForkChoice(
45
46
  isFinalizedState: boolean,
46
47
  opts: ForkChoiceOpts,
47
48
  justifiedBalancesGetter: JustifiedBalancesGetter,
49
+ stateGetter: ForkChoiceStateGetter,
48
50
  metrics: Metrics | null,
49
51
  logger?: Logger
50
52
  ): ForkChoice {
@@ -56,6 +58,7 @@ export function initializeForkChoice(
56
58
  state,
57
59
  opts,
58
60
  justifiedBalancesGetter,
61
+ stateGetter,
59
62
  metrics,
60
63
  logger
61
64
  )
@@ -66,6 +69,7 @@ export function initializeForkChoice(
66
69
  state,
67
70
  opts,
68
71
  justifiedBalancesGetter,
72
+ stateGetter,
69
73
  metrics,
70
74
  logger
71
75
  );
@@ -81,6 +85,7 @@ export function initializeForkChoiceFromFinalizedState(
81
85
  state: IBeaconStateView,
82
86
  opts: ForkChoiceOpts,
83
87
  justifiedBalancesGetter: JustifiedBalancesGetter,
88
+ stateGetter: ForkChoiceStateGetter,
84
89
  metrics: Metrics | null,
85
90
  logger?: Logger
86
91
  ): ForkChoice {
@@ -112,6 +117,7 @@ export function initializeForkChoiceFromFinalizedState(
112
117
  finalizedCheckpoint,
113
118
  justifiedBalances,
114
119
  justifiedBalancesGetter,
120
+ stateGetter,
115
121
  {
116
122
  onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
117
123
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
@@ -172,6 +178,7 @@ export function initializeForkChoiceFromUnfinalizedState(
172
178
  unfinalizedState: IBeaconStateView,
173
179
  opts: ForkChoiceOpts,
174
180
  justifiedBalancesGetter: JustifiedBalancesGetter,
181
+ stateGetter: ForkChoiceStateGetter,
175
182
  metrics: Metrics | null,
176
183
  logger?: Logger
177
184
  ): ForkChoice {
@@ -203,6 +210,7 @@ export function initializeForkChoiceFromUnfinalizedState(
203
210
  finalizedCheckpoint,
204
211
  justifiedBalances,
205
212
  justifiedBalancesGetter,
213
+ stateGetter,
206
214
  {
207
215
  onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
208
216
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
@@ -105,6 +105,7 @@ export const defaultChainOptions: IChainOptions = {
105
105
  proposerBoost: true,
106
106
  proposerBoostReorg: true,
107
107
  computeUnrealized: true,
108
+ fastConfirmation: false,
108
109
  suggestedFeeRecipient: defaultValidatorOptions.suggestedFeeRecipient,
109
110
  serveHistoricalState: false,
110
111
  assertCorrectProgressiveBalances: false,
@@ -170,7 +170,7 @@ export class PrepareNextSlotScheduler {
170
170
  let stateAfterParentPayload: IBeaconStateViewBellatrix = updatedPrepareState;
171
171
  if (isStatePostGloas(updatedPrepareState)) {
172
172
  // Spec: should_build_on_full(store, head) — see produceBlockBody.ts for context.
173
- if (this.chain.forkChoice.shouldBuildOnFull(updatedHead)) {
173
+ if (this.chain.forkChoice.shouldBuildOnFull(updatedHead, prepareSlot)) {
174
174
  parentBlockHash = updatedPrepareState.latestExecutionPayloadBid.blockHash;
175
175
  // Skip applying parent payload unless we're proposing the next slot or have to emit payload_attributes events
176
176
  if (feeRecipient !== undefined || this.chain.opts.emitPayloadAttributes === true) {
@@ -276,9 +276,9 @@ export async function produceBlockBody<T extends BlockType>(
276
276
  // Apply parent payload once here as it's reused by EL prep and voluntary exit filtering below
277
277
  let stateAfterParentPayload: IBeaconStateViewBellatrix = currentState;
278
278
  // Spec: should_build_on_full(store, head). `parentBlock` is the proposer's head
279
- // (set by chain.getProposerHead(slot)). Returns false when the PTC majority
280
- // signalled the blob data is not available, forcing a build on EMPTY (reorg).
281
- const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock);
279
+ // (set by chain.getProposerHead(slot)). Returns false when the PTC majority signalled
280
+ // the blob data is not available or the payload was not timely, forcing a build on EMPTY (reorg).
281
+ const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock, blockSlot);
282
282
  if (isBuildingOnFull) {
283
283
  parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;
284
284
  parentExecutionRequests = await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot);
@@ -22,6 +22,7 @@ export enum RegenCaller {
22
22
  validateGossipAttestation = "validateGossipAttestation",
23
23
  validateGossipVoluntaryExit = "validateGossipVoluntaryExit",
24
24
  validateGossipExecutionPayloadBid = "validateGossipExecutionPayloadBid",
25
+ validateGossipPayloadAttestationMessage = "validateGossipPayloadAttestationMessage",
25
26
  validateGossipProposerPreferences = "validateGossipProposerPreferences",
26
27
  onForkChoiceFinalized = "onForkChoiceFinalized",
27
28
  restApi = "restApi",
@@ -46,7 +47,6 @@ export interface IStateRegenerator extends IStateRegeneratorInternal {
46
47
  getCheckpointStateSync(cp: CheckpointHex): IBeaconStateView | null;
47
48
  getClosestHeadState(head: ProtoBlock): IBeaconStateView | null;
48
49
  pruneOnCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void;
49
- pruneOnFinalized(finalizedEpoch: Epoch): void;
50
50
  processState(blockRootHex: RootHex, postState: IBeaconStateView): void;
51
51
  addCheckpointState(cp: phase0.Checkpoint, item: IBeaconStateView): void;
52
52
  updateHeadState(newHead: ProtoBlock, maybeHeadState: IBeaconStateView): void;
@@ -143,11 +143,6 @@ export class QueuedStateRegenerator implements IStateRegenerator {
143
143
  this.blockStateCache.prune(headStateRoot);
144
144
  }
145
145
 
146
- pruneOnFinalized(finalizedEpoch: number): void {
147
- this.checkpointStateCache.pruneFinalized(finalizedEpoch);
148
- this.blockStateCache.deleteAllBeforeEpoch(finalizedEpoch);
149
- }
150
-
151
146
  processState(blockRootHex: RootHex, postState: IBeaconStateView): void {
152
147
  this.blockStateCache.add(postState);
153
148
  this.checkpointStateCache.processState(blockRootHex, postState).catch((e) => {
@@ -167,12 +167,6 @@ export class FIFOBlockStateCache implements BlockStateCache {
167
167
  }
168
168
  }
169
169
 
170
- /**
171
- * No need for this implementation
172
- * This is only to conform to the old api
173
- */
174
- deleteAllBeforeEpoch(): void {}
175
-
176
170
  /**
177
171
  * ONLY FOR DEBUGGING PURPOSES. For lodestar debug API.
178
172
  */
@@ -414,11 +414,12 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
414
414
 
415
415
  /**
416
416
  * Prune all checkpoint states before the provided finalized epoch.
417
+ * Driven sequentially from processState() so it never interleaves with persist.
417
418
  */
418
- pruneFinalized(finalizedEpoch: Epoch): void {
419
+ private async pruneFinalized(finalizedEpoch: Epoch): Promise<void> {
419
420
  for (const epoch of this.epochIndex.keys()) {
420
421
  if (epoch < finalizedEpoch) {
421
- this.deleteAllEpochItems(epoch).catch((e) =>
422
+ await this.deleteAllEpochItems(epoch).catch((e) =>
422
423
  this.logger.debug("Error delete all epoch items", {epoch, finalizedEpoch}, e as Error)
423
424
  );
424
425
  }
@@ -476,6 +477,9 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
476
477
  * As of Mar 2024, it takes <=350ms to persist a holesky state on fast server
477
478
  */
478
479
  async processState(blockRootHex: RootHex, state: IBeaconStateView): Promise<number> {
480
+ // prune finalized in the same flow so a finalized cp state is pruned, never persisted
481
+ await this.pruneFinalized(state.finalizedCheckpoint.epoch);
482
+
479
483
  let persistCount = 0;
480
484
  // it's important to sort the epochs in ascending order, in case of big reorg we always want to keep the most recent checkpoint states
481
485
  const sortedEpochs = Array.from(this.epochIndex.keys()).sort((a, b) => a - b);
@@ -30,7 +30,6 @@ export interface BlockStateCache {
30
30
  clear(): void;
31
31
  size: number;
32
32
  prune(headStateRootHex: RootHex): void;
33
- deleteAllBeforeEpoch(finalizedEpoch: Epoch): void;
34
33
  dumpSummary(): routes.lodestar.StateCacheItem[];
35
34
  /** Expose beacon states stored in cache. Use with caution */
36
35
  getStates(): IterableIterator<IBeaconStateView>;
@@ -67,7 +66,6 @@ export interface CheckpointStateCache {
67
66
  getOrReloadLatest(rootHex: RootHex, maxEpoch: Epoch): Promise<IBeaconStateView | null>;
68
67
  updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null;
69
68
  prune(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void;
70
- pruneFinalized(finalizedEpoch: Epoch): void;
71
69
  processState(blockRootHex: RootHex, state: IBeaconStateView): Promise<number>;
72
70
  clear(): void;
73
71
  dumpSummary(): routes.lodestar.StateCacheItem[];
@@ -35,10 +35,6 @@ async function validateExecutionPayloadBid(
35
35
  const bid = signedExecutionPayloadBid.message;
36
36
  const parentBlockRootHex = toRootHex(bid.parentBlockRoot);
37
37
  const parentBlockHashHex = toRootHex(bid.parentBlockHash);
38
- const state = await chain.getHeadStateAtCurrentEpoch(RegenCaller.validateGossipExecutionPayloadBid);
39
- if (!isStatePostGloas(state)) {
40
- throw new Error(`Expected gloas+ state for execution payload bid validation, got fork=${state.forkName}`);
41
- }
42
38
 
43
39
  // [IGNORE] `bid.slot` is the current slot or the next slot.
44
40
  const currentSlot = chain.clock.currentSlot;
@@ -111,9 +107,31 @@ async function validateExecutionPayloadBid(
111
107
  });
112
108
  }
113
109
 
110
+ // Use the bid's parent branch state for builder checks
111
+ const state = await chain.regen
112
+ .getBlockSlotState(parentBlock, bid.slot, {dontTransferCache: true}, RegenCaller.validateGossipExecutionPayloadBid)
113
+ .catch(() => {
114
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
115
+ code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT,
116
+ parentBlockRoot: parentBlockRootHex,
117
+ });
118
+ });
119
+
120
+ if (!isStatePostGloas(state)) {
121
+ throw new Error(`Expected gloas+ state for execution payload bid validation, got fork=${state.forkName}`);
122
+ }
123
+
114
124
  // [REJECT] `bid.builder_index` is a valid/active builder index -- i.e.
115
125
  // `is_active_builder(state, bid.builder_index)` returns `True`.
116
- const builder = state.getBuilder(bid.builderIndex);
126
+ let builder: gloas.Builder;
127
+ try {
128
+ builder = state.getBuilder(bid.builderIndex);
129
+ } catch {
130
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
131
+ code: ExecutionPayloadBidErrorCode.BUILDER_NOT_ELIGIBLE,
132
+ builderIndex: bid.builderIndex,
133
+ });
134
+ }
117
135
  if (!isActiveBuilder(builder, state.finalizedCheckpoint.epoch)) {
118
136
  throw new ExecutionPayloadBidError(GossipAction.REJECT, {
119
137
  code: ExecutionPayloadBidErrorCode.BUILDER_NOT_ELIGIBLE,
@@ -8,6 +8,7 @@ import {RootHex, gloas, ssz} from "@lodestar/types";
8
8
  import {toRootHex} from "@lodestar/utils";
9
9
  import {GossipAction, PayloadAttestationError, PayloadAttestationErrorCode} from "../errors/index.js";
10
10
  import {IBeaconChain} from "../index.js";
11
+ import {RegenCaller} from "../regen/index.js";
11
12
 
12
13
  export type PayloadAttestationValidationResult = {
13
14
  attDataRootHex: RootHex;
@@ -61,22 +62,43 @@ async function validatePayloadAttestationMessage(
61
62
  // [IGNORE] The message's block `data.beacon_block_root` has been seen (via
62
63
  // gossip or non-gossip sources) (a client MAY queue attestation for processing
63
64
  // once the block is retrieved. Note a client might want to request payload after).
64
- if (!chain.forkChoice.hasBlock(data.beaconBlockRoot)) {
65
+ const block = chain.forkChoice.getBlockDefaultStatus(data.beaconBlockRoot);
66
+ if (!block) {
65
67
  throw new PayloadAttestationError(GossipAction.IGNORE, {
66
68
  code: PayloadAttestationErrorCode.UNKNOWN_BLOCK_ROOT,
67
69
  blockRoot: toRootHex(data.beaconBlockRoot),
68
70
  });
69
71
  }
70
72
 
71
- const state = chain.getHeadState();
72
- if (!isStatePostGloas(state)) {
73
- throw new Error(`Expected gloas+ state for payload attestation validation, got fork=${state.forkName}`);
73
+ // [IGNORE] The block referenced by `data.beacon_block_root` is at slot `data.slot`,
74
+ // i.e. the block has `block.slot == data.slot`.
75
+ if (block.slot !== data.slot) {
76
+ throw new PayloadAttestationError(GossipAction.IGNORE, {
77
+ code: PayloadAttestationErrorCode.INVALID_BLOCK_SLOT,
78
+ blockRoot: toRootHex(data.beaconBlockRoot),
79
+ blockSlot: block.slot,
80
+ slot: data.slot,
81
+ });
74
82
  }
75
83
 
76
84
  // [REJECT] The message's block `data.beacon_block_root` passes validation.
77
85
  // TODO GLOAS: implement this. Technically if we cannot get proto block from fork choice,
78
86
  // it is possible that the block didn't pass the validation
79
87
 
88
+ // Use the referenced block's branch state for the PTC committee check
89
+ const state = await chain.regen
90
+ .getBlockSlotState(block, data.slot, {dontTransferCache: true}, RegenCaller.validateGossipPayloadAttestationMessage)
91
+ .catch(() => {
92
+ throw new PayloadAttestationError(GossipAction.IGNORE, {
93
+ code: PayloadAttestationErrorCode.UNKNOWN_BLOCK_ROOT,
94
+ blockRoot: toRootHex(data.beaconBlockRoot),
95
+ });
96
+ });
97
+
98
+ if (!isStatePostGloas(state)) {
99
+ throw new Error(`Expected gloas+ state for payload attestation validation, got fork=${state.forkName}`);
100
+ }
101
+
80
102
  // [REJECT] The message's validator index is within the payload committee in
81
103
  // `get_ptc(state, data.slot)`. The `state` is the head state corresponding to
82
104
  // processing the block up to the current slot as determined by the fork choice.
@@ -1214,6 +1214,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
1214
1214
  }
1215
1215
  chain.forkChoice.notifyPtcMessages(
1216
1216
  toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
1217
+ payloadAttestationMessage.data.slot,
1217
1218
  validationResult.validatorCommitteeIndices,
1218
1219
  payloadAttestationMessage.data.payloadPresent,
1219
1220
  payloadAttestationMessage.data.blobDataAvailable
@@ -1,6 +1,6 @@
1
1
  import {PeerId} from "@libp2p/interface";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
- import {GENESIS_SLOT, isForkPostDeneb, isForkPostFulu} from "@lodestar/params";
3
+ import {GENESIS_SLOT, isForkPostDeneb} from "@lodestar/params";
4
4
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
5
5
  import {computeEpochAtSlot} from "@lodestar/state-transition";
6
6
  import {deneb, phase0} from "@lodestar/types";
@@ -29,13 +29,20 @@ export async function* onBeaconBlocksByRange(
29
29
  // starts above it to avoid duplicate yields. See archiveBlocks.ts for the migration logic.
30
30
  const archiveMaxSlot = finalizedSlot;
31
31
 
32
- const forkName = chain.config.getForkName(startSlot);
33
- if (isForkPostFulu(forkName) && startSlot < chain.earliestAvailableSlot) {
34
- chain.logger.verbose("Peer did not respect earliestAvailableSlot for BeaconBlocksByRange", {
32
+ // endSlot is exclusive, so highest served slot is endSlot - 1.
33
+ // Throw only when the entire requested range is below earliestAvailableSlot.
34
+ if (endSlot - 1 < chain.earliestAvailableSlot) {
35
+ chain.logger.verbose("Peer requested range before earliestAvailableSlot for BeaconBlocksByRange", {
35
36
  peer: prettyPrintPeerId(peerId),
36
37
  client: peerClient,
38
+ startSlot,
39
+ count,
40
+ earliestAvailableSlot: chain.earliestAvailableSlot,
37
41
  });
38
- return;
42
+ throw new ResponseError(
43
+ RespStatus.RESOURCE_UNAVAILABLE,
44
+ `Requested range is before earliestAvailableSlot startSlot=${startSlot} count=${count} earliestAvailableSlot=${chain.earliestAvailableSlot}`
45
+ );
39
46
  }
40
47
 
41
48
  // Finalized range of blocks
@@ -1,5 +1,6 @@
1
1
  import {PeerId} from "@libp2p/interface";
2
2
  import {ChainConfig} from "@lodestar/config";
3
+ import {PayloadStatus} from "@lodestar/fork-choice";
3
4
  import {ForkSeq, GENESIS_SLOT} from "@lodestar/params";
4
5
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
5
6
  import {computeEpochAtSlot} from "@lodestar/state-transition";
@@ -33,12 +34,20 @@ export async function* onDataColumnSidecarsByRange(
33
34
  return;
34
35
  }
35
36
 
36
- if (startSlot < chain.earliestAvailableSlot) {
37
- chain.logger.verbose("Peer did not respect earliestAvailableSlot for DataColumnSidecarsByRange", {
37
+ // endSlot is exclusive, so highest served slot is endSlot - 1.
38
+ // Throw only when the entire requested range is below earliestAvailableSlot.
39
+ if (endSlot - 1 < chain.earliestAvailableSlot) {
40
+ chain.logger.verbose("Peer requested range before earliestAvailableSlot for DataColumnSidecarsByRange", {
38
41
  peer: prettyPrintPeerId(peerId),
39
42
  client: peerClient,
43
+ startSlot,
44
+ count,
45
+ earliestAvailableSlot: chain.earliestAvailableSlot,
40
46
  });
41
- return;
47
+ throw new ResponseError(
48
+ RespStatus.RESOURCE_UNAVAILABLE,
49
+ `Requested range is before earliestAvailableSlot startSlot=${startSlot} count=${count} earliestAvailableSlot=${chain.earliestAvailableSlot}`
50
+ );
42
51
  }
43
52
 
44
53
  const finalized = db.dataColumnSidecarArchive;
@@ -104,6 +113,11 @@ export async function* onDataColumnSidecarsByRange(
104
113
 
105
114
  // Must include only columns in the range requested
106
115
  if (block.slot > archiveMaxSlot && block.slot >= startSlot && block.slot < endSlot) {
116
+ // Post-gloas, columns exist only for FULL blocks (pre-gloas blocks are always FULL)
117
+ if (block.payloadStatus !== PayloadStatus.FULL) {
118
+ continue;
119
+ }
120
+
107
121
  // Note: Here the forkChoice head may change due to a re-org, so the headChain reflects the canonical chain
108
122
  // at the time of the start of the request. Spec is clear the chain of columns must be consistent, but on
109
123
  // re-org there's no need to abort the request
@@ -30,7 +30,7 @@ export async function* onDataColumnSidecarsByRoot(
30
30
  const {blockRoot, columns: requestedColumns} = dataColumnsByRootIdentifier;
31
31
  const availableColumns = validateRequestedDataColumns(chain, requestedColumns);
32
32
  if (availableColumns.length === 0) {
33
- return;
33
+ continue;
34
34
  }
35
35
 
36
36
  const blockRootHex = toRootHex(blockRoot);
@@ -1,3 +1,4 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {ChainConfig} from "@lodestar/config";
2
3
  import {PayloadStatus} from "@lodestar/fork-choice";
3
4
  import {GENESIS_SLOT} from "@lodestar/params";
@@ -6,23 +7,38 @@ import {computeEpochAtSlot} from "@lodestar/state-transition";
6
7
  import {gloas} from "@lodestar/types";
7
8
  import {IBeaconChain} from "../../../chain/index.js";
8
9
  import {IBeaconDb} from "../../../db/index.js";
10
+ import {prettyPrintPeerId} from "../../util.js";
9
11
 
10
12
  export async function* onExecutionPayloadEnvelopesByRange(
11
13
  request: gloas.ExecutionPayloadEnvelopesByRangeRequest,
12
14
  chain: IBeaconChain,
13
- db: IBeaconDb
15
+ db: IBeaconDb,
16
+ peerId: PeerId,
17
+ peerClient: string
14
18
  ): AsyncIterable<ResponseOutgoing> {
15
19
  const {startSlot, count} = validateExecutionPayloadEnvelopesByRangeRequest(chain.config, request);
16
20
  const endSlot = startSlot + count;
17
21
 
18
- if (startSlot < chain.earliestAvailableSlot) {
19
- return;
22
+ // endSlot is exclusive, so highest served slot is endSlot - 1.
23
+ // Throw only when the entire requested range is below earliestAvailableSlot.
24
+ if (endSlot - 1 < chain.earliestAvailableSlot) {
25
+ chain.logger.verbose("Peer requested range before earliestAvailableSlot for ExecutionPayloadEnvelopesByRange", {
26
+ peer: prettyPrintPeerId(peerId),
27
+ client: peerClient,
28
+ startSlot,
29
+ count,
30
+ earliestAvailableSlot: chain.earliestAvailableSlot,
31
+ });
32
+ throw new ResponseError(
33
+ RespStatus.RESOURCE_UNAVAILABLE,
34
+ `Requested range is before earliestAvailableSlot startSlot=${startSlot} count=${count} earliestAvailableSlot=${chain.earliestAvailableSlot}`
35
+ );
20
36
  }
21
37
 
22
38
  const finalized = db.executionPayloadEnvelopeArchive;
23
- const finalizedSlot = chain.forkChoice.getFinalizedCheckpointSlot();
24
- // The current finalized block's envelope is still in the hot db; archive migration happens
25
- // in the next finalization run (see migrateExecutionPayloadEnvelopesFromHotToColdDb).
39
+ // Use the finalized block's actual slot as the checkpoint epoch-boundary slot may be skipped
40
+ const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
41
+ // The finalized block's envelope stays in the hot db until the next finalization run
26
42
  const archiveMaxSlot = finalizedSlot - 1;
27
43
 
28
44
  // Finalized range of envelopes
@@ -1,14 +1,18 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {ResponseOutgoing} from "@lodestar/reqresp";
2
3
  import {computeEpochAtSlot} from "@lodestar/state-transition";
3
4
  import {toRootHex} from "@lodestar/utils";
4
5
  import {IBeaconChain} from "../../../chain/index.js";
5
6
  import {IBeaconDb} from "../../../db/index.js";
6
7
  import {ExecutionPayloadEnvelopesByRootRequest} from "../../../util/types.js";
8
+ import {prettyPrintPeerId} from "../../util.js";
7
9
 
8
10
  export async function* onExecutionPayloadEnvelopesByRoot(
9
11
  requestBody: ExecutionPayloadEnvelopesByRootRequest,
10
12
  chain: IBeaconChain,
11
- db: IBeaconDb
13
+ db: IBeaconDb,
14
+ peerId: PeerId,
15
+ peerClient: string
12
16
  ): AsyncIterable<ResponseOutgoing> {
13
17
  // The gloas req/resp spec uses MIN_EPOCHS_FOR_BLOCK_REQUESTS to define the minimum range peers MUST serve.
14
18
  // Archival nodes may still serve older retained payloads to allow genesis sync.
@@ -20,6 +24,14 @@ export async function* onExecutionPayloadEnvelopesByRoot(
20
24
  const slot = block ? block.slot : await db.blockArchive.getSlotByRoot(root);
21
25
 
22
26
  if (slot === null) {
27
+ chain.logger.debug(
28
+ "Cannot serve ExecutionPayloadEnvelopesByRoot: block root not in fork choice or block archive",
29
+ {
30
+ root: rootHex,
31
+ peer: prettyPrintPeerId(peerId),
32
+ client: peerClient,
33
+ }
34
+ );
23
35
  continue;
24
36
  }
25
37
 
@@ -29,6 +41,13 @@ export async function* onExecutionPayloadEnvelopesByRoot(
29
41
  data: envelopeBytes,
30
42
  boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(slot)),
31
43
  };
44
+ } else {
45
+ chain.logger.debug("Cannot serve ExecutionPayloadEnvelopesByRoot: envelope not found", {
46
+ slot,
47
+ root: rootHex,
48
+ peer: prettyPrintPeerId(peerId),
49
+ client: peerClient,
50
+ });
32
51
  }
33
52
  }
34
53
  }
@@ -70,13 +70,13 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
70
70
  return onDataColumnSidecarsByRoot(body, chain, db, peerId, peerClient);
71
71
  },
72
72
 
73
- [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: (req) => {
73
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: (req, peerId, peerClient) => {
74
74
  const body = ExecutionPayloadEnvelopesByRootRequestType(chain.config).deserialize(req.data);
75
- return onExecutionPayloadEnvelopesByRoot(body, chain, db);
75
+ return onExecutionPayloadEnvelopesByRoot(body, chain, db, peerId, peerClient);
76
76
  },
77
- [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: (req) => {
77
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: (req, peerId, peerClient) => {
78
78
  const body = ssz.gloas.ExecutionPayloadEnvelopesByRangeRequest.deserialize(req.data);
79
- return onExecutionPayloadEnvelopesByRange(body, chain, db);
79
+ return onExecutionPayloadEnvelopesByRange(body, chain, db, peerId, peerClient);
80
80
  },
81
81
 
82
82
  [ReqRespMethod.LightClientBootstrap]: (req) => {
@@ -1,4 +1,5 @@
1
1
  import {LogData} from "@lodestar/logger";
2
+ import {ForkSeq} from "@lodestar/params";
2
3
  import {RespStatus, ResponseError} from "@lodestar/reqresp";
3
4
  import {ColumnIndex, Slot} from "@lodestar/types";
4
5
  import {prettyBytes, prettyPrintIndices, toRootHex} from "@lodestar/utils";
@@ -38,6 +39,13 @@ export async function handleColumnSidecarUnavailability({
38
39
 
39
40
  chain.logger.debug("dataColumnSidecar requested unavailable", logData);
40
41
 
42
+ // Post-gloas, columns exist only for FULL blocks; a finalized block is FULL if its envelope was
43
+ // archived. Bid blobsCount is unreliable here since an EMPTY block's bid may still commit to blobs
44
+ if (blockRoot === undefined && chain.config.getForkSeq(slot) >= ForkSeq.gloas) {
45
+ const envelopeBytes = await db.executionPayloadEnvelopeArchive.getBinary(slot);
46
+ if (!envelopeBytes) return;
47
+ }
48
+
41
49
  const blockBytes = blockRoot ? await db.block.getBinary(blockRoot) : await db.blockArchive.getBinary(slot);
42
50
  if (!blockBytes) {
43
51
  chain.logger.verbose(
@@ -71,9 +79,19 @@ export function validateRequestedDataColumns(chain: IBeaconChain, requestedColum
71
79
  throw new ResponseError(RespStatus.INVALID_REQUEST, "dataColumnSidecar requested without column indices");
72
80
  }
73
81
 
74
- const custodyColumns = chain.custodyConfig.custodyColumns;
75
- const availableColumns = requestedColumns.filter((c) => custodyColumns.includes(c));
76
- const missingColumns = requestedColumns.filter((c) => !custodyColumns.includes(c));
82
+ const {custodyColumns, custodyColumnsIndex} = chain.custodyConfig;
83
+ const availableColumns: ColumnIndex[] = [];
84
+ const missingColumns: ColumnIndex[] = [];
85
+ for (const c of requestedColumns) {
86
+ // `c` is peer-controlled and SSZ-deserialized as `uint64`, so it may exceed
87
+ // `NUMBER_OF_COLUMNS - 1`; `Uint8Array` returns `undefined` for OOB reads,
88
+ // and `undefined !== 0` would silently classify OOB indices as custodied.
89
+ if ((custodyColumnsIndex[c] ?? 0) !== 0) {
90
+ availableColumns.push(c);
91
+ } else {
92
+ missingColumns.push(c);
93
+ }
94
+ }
77
95
 
78
96
  if (missingColumns.length > 0) {
79
97
  chain.logger.verbose("Requested dataColumnSidecar for non-custody columns", {
@@ -470,15 +470,17 @@ export async function recoverDataColumnSidecars(
470
470
  return DataColumnReconstructionCode.SuccessLate;
471
471
  }
472
472
 
473
- // Once the node obtains a column through reconstruction,
474
- // the node MUST expose the new column as if it had received it over the network.
475
- // If the node is subscribed to the subnet corresponding to the column,
476
- // it MUST send the reconstructed DataColumnSidecar to its topic mesh neighbors.
477
- // If instead the node is not subscribed to the corresponding subnet,
478
- // it SHOULD still expose the availability of the DataColumnSidecar as part of the gossip emission process.
479
- // After exposing the reconstructed DataColumnSidecar to the network,
480
- // the node MAY delete the DataColumnSidecar if it is not part of the node's custody requirement.
481
- const sidecarsToPublish = [];
473
+ // Per consensus-specs PR #4657, only publish reconstructed columns the node is
474
+ // subscribed to (custody + sampling). Eagerly cross-seeding non-subscribed
475
+ // columns floods the network with duplicates because the sender has no
476
+ // visibility into which peers already saw the message via the topic mesh.
477
+ // This matches the getBlobsV2 path in `getDataColumnSidecarsFromExecution` and
478
+ // aligns with Lighthouse/Prysm. Capture missing sampled indices before adding
479
+ // any reconstructed columns so they are not filtered out by the subsequent
480
+ // `addColumn` calls.
481
+ const missingSampledColumns = new Set(input.getMissingSampledColumnMeta().missing);
482
+ const sidecarsReconstructed: DataColumnSidecar[] = [];
483
+ const sidecarsToPublish: DataColumnSidecar[] = [];
482
484
  for (const columnSidecar of fullSidecars) {
483
485
  if (!input.hasColumn(columnSidecar.index)) {
484
486
  if (input instanceof PayloadEnvelopeInput) {
@@ -501,11 +503,14 @@ export async function recoverDataColumnSidecars(
501
503
  source: BlockInputSource.recovery,
502
504
  });
503
505
  }
504
- sidecarsToPublish.push(columnSidecar);
506
+ sidecarsReconstructed.push(columnSidecar);
507
+ if (missingSampledColumns.has(columnSidecar.index)) {
508
+ sidecarsToPublish.push(columnSidecar);
509
+ }
505
510
  }
506
511
  }
507
- metrics?.peerDas.reconstructedColumns.inc(sidecarsToPublish.length);
508
- metrics?.dataColumns.bySource.inc({source: BlockInputSource.recovery}, sidecarsToPublish.length);
512
+ metrics?.peerDas.reconstructedColumns.inc(sidecarsReconstructed.length);
513
+ metrics?.dataColumns.bySource.inc({source: BlockInputSource.recovery}, sidecarsReconstructed.length);
509
514
  emitter.emit(ChainEvent.publishDataColumns, sidecarsToPublish);
510
515
  // TODO: Can we record dataColumns.sentPeersPerSubnet metric somehow
511
516
  return DataColumnReconstructionCode.SuccessResolved;