@lodestar/beacon-node 1.43.0-dev.a45ba75824 → 1.43.0-dev.a58ad80359

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 (156) hide show
  1. package/lib/api/impl/debug/index.d.ts.map +1 -1
  2. package/lib/api/impl/debug/index.js +0 -1
  3. package/lib/api/impl/debug/index.js.map +1 -1
  4. package/lib/api/impl/validator/index.d.ts.map +1 -1
  5. package/lib/api/impl/validator/index.js +2 -1
  6. package/lib/api/impl/validator/index.js.map +1 -1
  7. package/lib/chain/blocks/blockInput/blockInput.d.ts +3 -0
  8. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  9. package/lib/chain/blocks/blockInput/blockInput.js +4 -1
  10. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  11. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  12. package/lib/chain/blocks/importBlock.js +14 -18
  13. package/lib/chain/blocks/importBlock.js.map +1 -1
  14. package/lib/chain/blocks/importExecutionPayload.d.ts +4 -0
  15. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  16. package/lib/chain/blocks/importExecutionPayload.js +15 -6
  17. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  18. package/lib/chain/blocks/index.d.ts.map +1 -1
  19. package/lib/chain/blocks/index.js +29 -17
  20. package/lib/chain/blocks/index.js.map +1 -1
  21. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts +11 -1
  22. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -1
  23. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +23 -1
  24. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.map +1 -1
  25. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +16 -0
  26. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  27. package/lib/chain/blocks/types.d.ts +2 -1
  28. package/lib/chain/blocks/types.d.ts.map +1 -1
  29. package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
  30. package/lib/chain/blocks/utils/chainSegment.js +8 -0
  31. package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
  32. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  33. package/lib/chain/blocks/verifyBlock.js +5 -6
  34. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  35. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +0 -4
  36. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  37. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +5 -2
  38. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  39. package/lib/chain/blocks/verifyBlocksSanityChecks.d.ts +2 -1
  40. package/lib/chain/blocks/verifyBlocksSanityChecks.d.ts.map +1 -1
  41. package/lib/chain/blocks/verifyBlocksSanityChecks.js +16 -7
  42. package/lib/chain/blocks/verifyBlocksSanityChecks.js.map +1 -1
  43. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts +2 -2
  44. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts.map +1 -1
  45. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js +10 -6
  46. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js.map +1 -1
  47. package/lib/chain/chain.d.ts.map +1 -1
  48. package/lib/chain/chain.js +25 -10
  49. package/lib/chain/chain.js.map +1 -1
  50. package/lib/chain/errors/proposerPreferences.d.ts +8 -1
  51. package/lib/chain/errors/proposerPreferences.d.ts.map +1 -1
  52. package/lib/chain/errors/proposerPreferences.js +1 -0
  53. package/lib/chain/errors/proposerPreferences.js.map +1 -1
  54. package/lib/chain/initState.d.ts.map +1 -1
  55. package/lib/chain/initState.js +6 -1
  56. package/lib/chain/initState.js.map +1 -1
  57. package/lib/chain/prepareNextSlot.js +1 -1
  58. package/lib/chain/prepareNextSlot.js.map +1 -1
  59. package/lib/chain/produceBlock/produceBlockBody.d.ts +1 -0
  60. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  61. package/lib/chain/produceBlock/produceBlockBody.js +2 -7
  62. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  63. package/lib/chain/regen/queued.d.ts.map +1 -1
  64. package/lib/chain/regen/queued.js +1 -4
  65. package/lib/chain/regen/queued.js.map +1 -1
  66. package/lib/chain/regen/regen.d.ts.map +1 -1
  67. package/lib/chain/regen/regen.js +1 -4
  68. package/lib/chain/regen/regen.js.map +1 -1
  69. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +14 -10
  70. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  71. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +51 -17
  72. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  73. package/lib/chain/seenCache/seenProposerPreferences.d.ts +8 -7
  74. package/lib/chain/seenCache/seenProposerPreferences.d.ts.map +1 -1
  75. package/lib/chain/seenCache/seenProposerPreferences.js +11 -10
  76. package/lib/chain/seenCache/seenProposerPreferences.js.map +1 -1
  77. package/lib/chain/validation/executionPayloadBid.js +11 -8
  78. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  79. package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
  80. package/lib/chain/validation/proposerPreferences.js +39 -17
  81. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  82. package/lib/network/gossip/topic.d.ts +2 -0
  83. package/lib/network/gossip/topic.d.ts.map +1 -1
  84. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  85. package/lib/network/processor/gossipHandlers.js +14 -0
  86. package/lib/network/processor/gossipHandlers.js.map +1 -1
  87. package/lib/node/nodejs.js +2 -2
  88. package/lib/node/nodejs.js.map +1 -1
  89. package/lib/node/notifier.js +1 -7
  90. package/lib/node/notifier.js.map +1 -1
  91. package/lib/sync/constants.d.ts +3 -1
  92. package/lib/sync/constants.d.ts.map +1 -1
  93. package/lib/sync/constants.js +3 -4
  94. package/lib/sync/constants.js.map +1 -1
  95. package/lib/sync/range/batch.d.ts +12 -3
  96. package/lib/sync/range/batch.d.ts.map +1 -1
  97. package/lib/sync/range/batch.js +163 -33
  98. package/lib/sync/range/batch.js.map +1 -1
  99. package/lib/sync/range/chain.d.ts +13 -2
  100. package/lib/sync/range/chain.d.ts.map +1 -1
  101. package/lib/sync/range/chain.js +38 -4
  102. package/lib/sync/range/chain.js.map +1 -1
  103. package/lib/sync/range/range.d.ts.map +1 -1
  104. package/lib/sync/range/range.js +14 -3
  105. package/lib/sync/range/range.js.map +1 -1
  106. package/lib/sync/sync.d.ts.map +1 -1
  107. package/lib/sync/sync.js +13 -0
  108. package/lib/sync/sync.js.map +1 -1
  109. package/lib/sync/unknownBlock.d.ts +7 -0
  110. package/lib/sync/unknownBlock.d.ts.map +1 -1
  111. package/lib/sync/unknownBlock.js +138 -10
  112. package/lib/sync/unknownBlock.js.map +1 -1
  113. package/lib/sync/utils/downloadByRange.d.ts +29 -8
  114. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  115. package/lib/sync/utils/downloadByRange.js +87 -31
  116. package/lib/sync/utils/downloadByRange.js.map +1 -1
  117. package/lib/util/sszBytes.d.ts.map +1 -1
  118. package/lib/util/sszBytes.js +8 -6
  119. package/lib/util/sszBytes.js.map +1 -1
  120. package/package.json +16 -16
  121. package/src/api/impl/debug/index.ts +0 -1
  122. package/src/api/impl/validator/index.ts +2 -1
  123. package/src/chain/blocks/blockInput/blockInput.ts +4 -1
  124. package/src/chain/blocks/importBlock.ts +14 -21
  125. package/src/chain/blocks/importExecutionPayload.ts +21 -11
  126. package/src/chain/blocks/index.ts +18 -9
  127. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +31 -2
  128. package/src/chain/blocks/payloadEnvelopeInput/types.ts +17 -0
  129. package/src/chain/blocks/types.ts +2 -1
  130. package/src/chain/blocks/utils/chainSegment.ts +8 -0
  131. package/src/chain/blocks/verifyBlock.ts +7 -5
  132. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +6 -4
  133. package/src/chain/blocks/verifyBlocksSanityChecks.ts +16 -6
  134. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +14 -6
  135. package/src/chain/chain.ts +29 -9
  136. package/src/chain/errors/proposerPreferences.ts +9 -1
  137. package/src/chain/initState.ts +9 -1
  138. package/src/chain/prepareNextSlot.ts +1 -1
  139. package/src/chain/produceBlock/produceBlockBody.ts +3 -7
  140. package/src/chain/regen/queued.ts +2 -7
  141. package/src/chain/regen/regen.ts +2 -7
  142. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +66 -20
  143. package/src/chain/seenCache/seenProposerPreferences.ts +14 -11
  144. package/src/chain/validation/executionPayloadBid.ts +11 -8
  145. package/src/chain/validation/proposerPreferences.ts +37 -18
  146. package/src/network/processor/gossipHandlers.ts +18 -0
  147. package/src/node/nodejs.ts +2 -2
  148. package/src/node/notifier.ts +1 -8
  149. package/src/sync/constants.ts +4 -4
  150. package/src/sync/range/batch.ts +187 -38
  151. package/src/sync/range/chain.ts +52 -5
  152. package/src/sync/range/range.ts +16 -3
  153. package/src/sync/sync.ts +13 -1
  154. package/src/sync/unknownBlock.ts +170 -10
  155. package/src/sync/utils/downloadByRange.ts +149 -33
  156. package/src/util/sszBytes.ts +8 -6
@@ -94,7 +94,8 @@ export type ImportBlockOpts = {
94
94
  *
95
95
  * `executionStatus` reflects the outcome of execution payload verification at block-import time:
96
96
  * - pre-gloas: Valid | Syncing | PreMerge (from EL notifyNewPayload against the in-block payload)
97
- * - post-gloas: PayloadSeparated (payload arrives separately as an envelope and is imported later)
97
+ * - post-gloas: inherited from parent's chain (Valid/Syncing) by importBlock; payload arrives
98
+ * separately as an envelope and creates the FULL variant later via onExecutionPayload
98
99
  */
99
100
  export type FullyVerifiedBlock = {
100
101
  blockInput: IBlockInput;
@@ -41,6 +41,14 @@ export function assertLinearChainSegment(
41
41
  // - EMPTY variant (no envelope for slot): execution hash is unchanged
42
42
  // null only for pre-merge parents, which cannot precede gloas blocks.
43
43
  let currentExecHash: string | null = parentBlock.executionPayloadBlockHash;
44
+ // Checkpoint sync first batch: parent is the anchor PENDING whose executionPayloadBlockHash
45
+ // is the inherited parentBlockHash semantic (= grandparent's payload), not its own payload.
46
+ // If parent's own payload envelope arrives in this batch, advance currentExecHash to that
47
+ // payload's blockHash so the segment validation sees the true EL chain head.
48
+ const parentPayloadInput = payloadEnvelopes?.get(parentBlock.slot);
49
+ if (parentPayloadInput?.hasPayloadEnvelope()) {
50
+ currentExecHash = parentPayloadInput.getBlockHashHex();
51
+ }
44
52
  // Track the execution hash before the last FULL advancement so we can recover
45
53
  // if the next block reveals that envelope was orphaned.
46
54
  let prevExecHash: string | null = currentExecHash;
@@ -125,15 +125,17 @@ export async function verifyBlocksInEpoch(
125
125
  }> =
126
126
  fork >= ForkSeq.gloas
127
127
  ? (async () => {
128
- const payloadInputsForDa: PayloadEnvelopeInput[] = [];
129
- for (const input of blockInputs) {
130
- const pi = payloadEnvelopes?.get(input.slot);
131
- if (pi !== undefined) payloadInputsForDa.push(pi);
132
- }
128
+ // Validate DA for ALL payloads in the Map, not just those paired with blockInputs.
129
+ // A checkpoint-sync batch may include a payload for a slot whose block was filtered
130
+ // out of relevantBlocks (e.g., the anchor at the finalized slot); that payload still
131
+ // needs DA validation so it can be imported in processBlocks.
132
+ const payloadInputsForDa: PayloadEnvelopeInput[] =
133
+ payloadEnvelopes !== null ? Array.from(payloadEnvelopes.values()) : [];
133
134
  const {dataAvailabilityStatuses, availableTime} = await verifyPayloadsDataAvailability(
134
135
  payloadInputsForDa,
135
136
  abortController.signal
136
137
  );
138
+
137
139
  const payloadDAStatuses = new Map<Slot, DataAvailabilityStatus>();
138
140
  for (let i = 0; i < payloadInputsForDa.length; i++) {
139
141
  payloadDAStatuses.set(payloadInputsForDa[i].slot, dataAvailabilityStatuses[i]);
@@ -46,8 +46,7 @@ type VerifyBlockExecutionResponse =
46
46
  | VerifyExecutionErrorResponse
47
47
  | {executionStatus: ExecutionStatus.Valid; lvhResponse: LVHValidResponse; execError: null}
48
48
  | {executionStatus: ExecutionStatus.Syncing; lvhResponse?: LVHValidResponse; execError: null}
49
- | {executionStatus: ExecutionStatus.PreMerge; lvhResponse: undefined; execError: null}
50
- | {executionStatus: ExecutionStatus.PayloadSeparated; lvhResponse: undefined; execError: null};
49
+ | {executionStatus: ExecutionStatus.PreMerge; lvhResponse: undefined; execError: null};
51
50
 
52
51
  /**
53
52
  * Verifies 1 or more execution payloads from a linear sequence of blocks.
@@ -145,9 +144,10 @@ export async function verifyBlockExecutionPayload(
145
144
  ): Promise<VerifyBlockExecutionResponse> {
146
145
  const block = blockInput.getBlock();
147
146
 
148
- // Gloas block doesn't have execution payload. Return right away
147
+ // Gloas block doesn't have execution payload. Return Syncing as a placeholder; the actual
148
+ // status for gloas PENDING/EMPTY is derived from parent's chain in importBlock.
149
149
  if (isBlockInputNoData(blockInput)) {
150
- return {executionStatus: ExecutionStatus.PayloadSeparated, lvhResponse: undefined, execError: null};
150
+ return {executionStatus: ExecutionStatus.Syncing, lvhResponse: undefined, execError: null};
151
151
  }
152
152
 
153
153
  /** Not null if execution is enabled */
@@ -198,6 +198,7 @@ export async function verifyBlockExecutionPayload(
198
198
  executionStatus,
199
199
  latestValidExecHash: execResult.latestValidHash,
200
200
  invalidateFromParentBlockRoot: blockInput.parentRootHex,
201
+ invalidateFromParentBlockHash: toRootHex(executionPayloadEnabled.parentHash),
201
202
  };
202
203
  const execError = new BlockError(block, {
203
204
  code: BlockErrorCode.EXECUTION_ENGINE_ERROR,
@@ -281,6 +282,7 @@ function getSegmentErrorResponse(
281
282
  executionStatus: ExecutionStatus.Invalid,
282
283
  latestValidExecHash: lvhResponse.latestValidExecHash,
283
284
  invalidateFromParentBlockRoot: parentBlock.blockRoot,
285
+ invalidateFromParentBlockHash: parentBlock.executionPayloadBlockHash,
284
286
  };
285
287
  }
286
288
  }
@@ -7,6 +7,7 @@ import {IClock} from "../../util/clock.js";
7
7
  import {BlockError, BlockErrorCode} from "../errors/index.js";
8
8
  import {IChainOptions} from "../options.js";
9
9
  import {IBlockInput} from "./blockInput/types.js";
10
+ import {PayloadEnvelopeInput} from "./payloadEnvelopeInput/payloadEnvelopeInput.js";
10
11
  import {ImportBlockOpts} from "./types.js";
11
12
 
12
13
  /**
@@ -30,6 +31,7 @@ export function verifyBlocksSanityChecks(
30
31
  blacklistedBlocks: Map<RootHex, Slot | null>;
31
32
  },
32
33
  blocks: IBlockInput[],
34
+ payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null,
33
35
  opts: ImportBlockOpts
34
36
  ): {
35
37
  relevantBlocks: IBlockInput[];
@@ -100,13 +102,21 @@ export function verifyBlocksSanityChecks(
100
102
  const parentBlockHash = toRootHex(block.message.body.signedExecutionPayloadBid.message.parentBlockHash);
101
103
  const parentBlockWithPayload = chain.forkChoice.getBlockHexAndBlockHash(parentRoot, parentBlockHash);
102
104
  if (!parentBlockWithPayload) {
103
- throw new BlockError(block, {
104
- code: BlockErrorCode.PARENT_PAYLOAD_UNKNOWN,
105
- parentRoot,
106
- parentBlockHash,
107
- });
105
+ // Checkpoint sync: parent's FULL variant may not be in fork-choice yet because the
106
+ // anchor block is initialized with PENDING+EMPTY only. The parent's payload arrives
107
+ // in the same batch via payloadEnvelopes and will be imported by processBlocks. If
108
+ // a matching payload is in the Map, accept the parent as known.
109
+ const parentPayloadInput = payloadEnvelopes?.get(parentBlockDefaultStatus.slot);
110
+ if (parentPayloadInput?.getBlockHashHex() !== parentBlockHash) {
111
+ throw new BlockError(block, {
112
+ code: BlockErrorCode.PARENT_PAYLOAD_UNKNOWN,
113
+ parentRoot,
114
+ parentBlockHash,
115
+ });
116
+ }
117
+ } else {
118
+ parentBlock = parentBlockWithPayload;
108
119
  }
109
- parentBlock = parentBlockWithPayload;
110
120
  }
111
121
  // Parent is known to the fork-choice
112
122
  parentBlockSlot = parentBlock.slot;
@@ -20,7 +20,7 @@ export type VerifyExecutionPayloadEnvelopeOpts = {
20
20
  * performed outside this function, see `verifyExecutionPayloadEnvelopeSignature` and
21
21
  * `importExecutionPayload` which run both in parallel with this check.
22
22
  *
23
- * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.5/specs/gloas/fork-choice.md#new-verify_execution_payload_envelope
23
+ * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.6/specs/gloas/fork-choice.md#new-verify_execution_payload_envelope
24
24
  */
25
25
  export function verifyExecutionPayloadEnvelope(
26
26
  config: BeaconConfig,
@@ -43,6 +43,11 @@ export function verifyExecutionPayloadEnvelope(
43
43
  `Envelope's block is not the latest block header envelope=${toRootHex(envelope.beaconBlockRoot)} latestBlockHeader=${toRootHex(headerRoot)}`
44
44
  );
45
45
  }
46
+ if (!byteArrayEquals(envelope.parentBeaconBlockRoot, state.latestBlockHeader.parentRoot)) {
47
+ throw new Error(
48
+ `Envelope's parent_beacon_block_root mismatch envelope=${toRootHex(envelope.parentBeaconBlockRoot)} state=${toRootHex(state.latestBlockHeader.parentRoot)}`
49
+ );
50
+ }
46
51
 
47
52
  // Verify consistency with the committed bid
48
53
  const bid = state.latestExecutionPayloadBid;
@@ -77,16 +82,19 @@ export function verifyExecutionPayloadEnvelope(
77
82
  }
78
83
  }
79
84
 
80
- // Verify the execution payload is valid
81
- if (payload.slotNumber !== state.slot) {
82
- throw new Error(`Slot mismatch between payload and state payload=${payload.slotNumber} state=${state.slot}`);
85
+ // should not use state.slot, it does not work for skipped slot checkpoint sync
86
+ const blockSlot = state.latestBlockHeader.slot;
87
+ if (payload.slotNumber !== blockSlot) {
88
+ throw new Error(
89
+ `Slot mismatch between payload and latest block header payload=${payload.slotNumber} latestBlockHeader=${blockSlot}`
90
+ );
83
91
  }
84
92
  if (!byteArrayEquals(payload.parentHash, state.latestBlockHash)) {
85
93
  throw new Error(
86
94
  `Parent hash mismatch between payload and state payload=${toRootHex(payload.parentHash)} state=${toRootHex(state.latestBlockHash)}`
87
95
  );
88
96
  }
89
- const expectedTimestamp = computeTimeAtSlot(config, state.slot, state.genesisTime);
97
+ const expectedTimestamp = computeTimeAtSlot(config, blockSlot, state.genesisTime);
90
98
  if (payload.timestamp !== expectedTimestamp) {
91
99
  throw new Error(
92
100
  `Timestamp mismatch between payload and state payload=${payload.timestamp} state=${expectedTimestamp}`
@@ -108,7 +116,7 @@ export function verifyExecutionPayloadEnvelope(
108
116
  /**
109
117
  * Verify the BLS signature of an execution payload envelope.
110
118
  *
111
- * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.5/specs/gloas/fork-choice.md#new-verify_execution_payload_envelope_signature
119
+ * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.6/specs/gloas/fork-choice.md#new-verify_execution_payload_envelope_signature
112
120
  */
113
121
  export async function verifyExecutionPayloadEnvelopeSignature(
114
122
  config: BeaconConfig,
@@ -23,6 +23,7 @@ import {
23
23
  getEffectiveBalancesFromStateBytes,
24
24
  isStatePostAltair,
25
25
  isStatePostElectra,
26
+ isStatePostGloas,
26
27
  } from "@lodestar/state-transition";
27
28
  import {
28
29
  BeaconBlock,
@@ -335,15 +336,6 @@ export class BeaconChain implements IBeaconChain {
335
336
  metrics,
336
337
  logger,
337
338
  });
338
- this.seenPayloadEnvelopeInputCache = new SeenPayloadEnvelopeInput({
339
- config,
340
- clock,
341
- chainEvents: emitter,
342
- signal,
343
- serializedCache: this.serializedCache,
344
- metrics,
345
- logger,
346
- });
347
339
 
348
340
  this._earliestAvailableSlot = anchorState.slot;
349
341
 
@@ -399,6 +391,7 @@ export class BeaconChain implements IBeaconChain {
399
391
  metrics,
400
392
  logger
401
393
  );
394
+
402
395
  const regen = new QueuedStateRegenerator({
403
396
  config,
404
397
  forkChoice,
@@ -423,6 +416,33 @@ export class BeaconChain implements IBeaconChain {
423
416
  this.payloadEnvelopeProcessor = new PayloadEnvelopeProcessor(this, metrics, signal);
424
417
 
425
418
  this.forkChoice = forkChoice;
419
+
420
+ this.seenPayloadEnvelopeInputCache = new SeenPayloadEnvelopeInput({
421
+ config,
422
+ clock,
423
+ forkChoice,
424
+ chainEvents: emitter,
425
+ signal,
426
+ serializedCache: this.serializedCache,
427
+ metrics,
428
+ logger,
429
+ });
430
+
431
+ const anchorBlockSlot = anchorState.latestBlockHeader.slot;
432
+ if (isStatePostGloas(anchorState) && anchorBlockSlot > 0) {
433
+ const anchorBid = anchorState.latestExecutionPayloadBid;
434
+ this.seenPayloadEnvelopeInputCache.addFromBid({
435
+ blockRootHex: toRootHex(checkpoint.root),
436
+ slot: anchorBlockSlot,
437
+ forkName: anchorState.forkName,
438
+ proposerIndex: anchorState.latestBlockHeader.proposerIndex,
439
+ bid: anchorBid,
440
+ sampledColumns: this.custodyConfig.sampledColumns,
441
+ custodyColumns: this.custodyConfig.custodyColumns,
442
+ timeCreatedSec: Math.floor(Date.now() / 1000),
443
+ });
444
+ }
445
+
426
446
  this.clock = clock;
427
447
  this.regen = regen;
428
448
  this.bls = bls;
@@ -1,9 +1,10 @@
1
- import {Slot, ValidatorIndex} from "@lodestar/types";
1
+ import {RootHex, Slot, ValidatorIndex} from "@lodestar/types";
2
2
  import {GossipActionError} from "./gossipValidation.js";
3
3
 
4
4
  export enum ProposerPreferencesErrorCode {
5
5
  INVALID_EPOCH = "PROPOSER_PREFERENCES_ERROR_INVALID_EPOCH",
6
6
  PROPOSAL_SLOT_PASSED = "PROPOSER_PREFERENCES_ERROR_PROPOSAL_SLOT_PASSED",
7
+ UNKNOWN_DEPENDENT_ROOT = "PROPOSER_PREFERENCES_ERROR_UNKNOWN_DEPENDENT_ROOT",
7
8
  INVALID_PROPOSER = "PROPOSER_PREFERENCES_ERROR_INVALID_PROPOSER",
8
9
  ALREADY_KNOWN = "PROPOSER_PREFERENCES_ERROR_ALREADY_KNOWN",
9
10
  INVALID_SIGNATURE = "PROPOSER_PREFERENCES_ERROR_INVALID_SIGNATURE",
@@ -20,15 +21,22 @@ export type ProposerPreferencesErrorType =
20
21
  proposalSlot: Slot;
21
22
  currentSlot: Slot;
22
23
  }
24
+ | {
25
+ code: ProposerPreferencesErrorCode.UNKNOWN_DEPENDENT_ROOT;
26
+ proposalSlot: Slot;
27
+ dependentRoot: RootHex;
28
+ }
23
29
  | {
24
30
  code: ProposerPreferencesErrorCode.INVALID_PROPOSER;
25
31
  proposalSlot: Slot;
26
32
  validatorIndex: ValidatorIndex;
33
+ dependentRoot: RootHex;
27
34
  }
28
35
  | {
29
36
  code: ProposerPreferencesErrorCode.ALREADY_KNOWN;
30
37
  proposalSlot: Slot;
31
38
  validatorIndex: ValidatorIndex;
39
+ dependentRoot: RootHex;
32
40
  }
33
41
  | {
34
42
  code: ProposerPreferencesErrorCode.INVALID_SIGNATURE;
@@ -1,7 +1,8 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {ZERO_HASH} from "@lodestar/params";
2
+ import {ForkPostGloas, ForkSeq, ZERO_HASH} from "@lodestar/params";
3
3
  import {
4
4
  BeaconStateAllForks,
5
+ BeaconStateGloas,
5
6
  IBeaconStateView,
6
7
  computeEpochAtSlot,
7
8
  computeStartSlotAtEpoch,
@@ -52,6 +53,13 @@ export function createGenesisBlock(config: ChainForkConfig, genesisState: Beacon
52
53
  const genesisBlock = types.SignedBeaconBlock.defaultValue();
53
54
  const stateRoot = genesisState.hashTreeRoot();
54
55
  genesisBlock.message.stateRoot = stateRoot;
56
+
57
+ if (config.getForkSeq(GENESIS_SLOT) >= ForkSeq.gloas) {
58
+ const gloasBlock = genesisBlock as SignedBeaconBlock<ForkPostGloas>;
59
+ const gloasState = genesisState as BeaconStateGloas;
60
+ gloasBlock.message.body.signedExecutionPayloadBid.message = gloasState.latestExecutionPayloadBid.toValue();
61
+ }
62
+
55
63
  return genesisBlock;
56
64
  }
57
65
 
@@ -222,7 +222,7 @@ export class PrepareNextSlotScheduler {
222
222
  // and head.parent (proposer-boost-reorg fallback). Anything older is evicted.
223
223
  const updatedHeadParent = this.chain.forkChoice.getBlockHexDefaultStatus(updatedHead.parentRoot);
224
224
  if (updatedHeadParent) {
225
- this.chain.seenPayloadEnvelopeInputCache.pruneBelow(updatedHeadParent.slot);
225
+ this.chain.seenPayloadEnvelopeInputCache.pruneBelowParent(updatedHeadParent);
226
226
  }
227
227
  }
228
228
 
@@ -49,7 +49,7 @@ import {
49
49
  ssz,
50
50
  } from "@lodestar/types";
51
51
  import {Logger, byteArrayEquals, fromHex, sleep, toHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
52
- import {ZERO_HASH, ZERO_HASH_HEX} from "../../constants/index.js";
52
+ import {ZERO_HASH_HEX} from "../../constants/index.js";
53
53
  import {numToQuantity} from "../../execution/engine/utils.js";
54
54
  import {
55
55
  IExecutionBuilder,
@@ -111,6 +111,7 @@ export type ProduceFullGloas = {
111
111
  executionRequests: electra.ExecutionRequests;
112
112
  blobsBundle: BlobsBundle<ForkPostGloas>;
113
113
  cells: fulu.Cell[][];
114
+ parentBlockRoot: Root;
114
115
  };
115
116
  export type ProduceFullFulu = {
116
117
  type: BlockType.Full;
@@ -225,12 +226,6 @@ export async function produceBlockBody<T extends BlockType>(
225
226
  stateAfterParentPayload = currentState.withParentPayloadApplied(parentExecutionRequests);
226
227
  } else {
227
228
  parentBlockHash = currentState.latestExecutionPayloadBid.parentBlockHash;
228
- // At gloas genesis the committed bid has no prior EL block to reference
229
- // (`bid.parentBlockHash` is zero). Fall back to `bid.blockHash` (= eth1 genesis hash) so the
230
- // FCU to the EL carries a valid head. Post-genesis bids always reference a non-zero parent.
231
- if (byteArrayEquals(parentBlockHash, ZERO_HASH)) {
232
- parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;
233
- }
234
229
  parentExecutionRequests = ssz.electra.ExecutionRequests.defaultValue();
235
230
  }
236
231
  const prepareRes = await prepareExecutionPayload(
@@ -317,6 +312,7 @@ export async function produceBlockBody<T extends BlockType>(
317
312
  gloasResult.executionRequests = executionRequests;
318
313
  gloasResult.blobsBundle = blobsBundle;
319
314
  gloasResult.cells = cells;
315
+ gloasResult.parentBlockRoot = fromHex(parentBlock.blockRoot);
320
316
 
321
317
  const fetchedTime = Date.now() / 1000 - computeTimeAtSlot(this.config, blockSlot, this.genesisTime);
322
318
  this.metrics?.blockPayload.payloadFetchedTime.observe({prepType}, fetchedTime);
@@ -1,7 +1,7 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
3
3
  import {IBeaconStateView, computeEpochAtSlot} from "@lodestar/state-transition";
4
- import {BeaconBlock, Epoch, RootHex, Slot, isGloasBeaconBlock, phase0} from "@lodestar/types";
4
+ import {BeaconBlock, Epoch, RootHex, Slot, phase0} from "@lodestar/types";
5
5
  import {Logger, toRootHex} from "@lodestar/utils";
6
6
  import {Metrics} from "../../metrics/index.js";
7
7
  import {JobItemQueue} from "../../util/queue/index.js";
@@ -88,12 +88,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
88
88
  */
89
89
  getPreStateSync(block: BeaconBlock): IBeaconStateView | null {
90
90
  const parentRoot = toRootHex(block.parentRoot);
91
- const parentBlock = isGloasBeaconBlock(block)
92
- ? this.forkChoice.getBlockHexAndBlockHash(
93
- parentRoot,
94
- toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash)
95
- )
96
- : this.forkChoice.getBlockHexDefaultStatus(parentRoot);
91
+ const parentBlock = this.forkChoice.getBlockHexDefaultStatus(parentRoot);
97
92
  if (!parentBlock) {
98
93
  throw new RegenError({
99
94
  code: RegenErrorCode.BLOCK_NOT_IN_FORKCHOICE,
@@ -9,7 +9,7 @@ import {
9
9
  computeEpochAtSlot,
10
10
  computeStartSlotAtEpoch,
11
11
  } from "@lodestar/state-transition";
12
- import {BeaconBlock, RootHex, SignedBeaconBlock, Slot, isGloasBeaconBlock} from "@lodestar/types";
12
+ import {BeaconBlock, RootHex, SignedBeaconBlock, Slot} from "@lodestar/types";
13
13
  import {Logger, fromHex, toRootHex} from "@lodestar/utils";
14
14
  import {IBeaconDb} from "../../db/index.js";
15
15
  import {Metrics} from "../../metrics/index.js";
@@ -57,12 +57,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
57
57
  regenCaller: RegenCaller
58
58
  ): Promise<IBeaconStateView> {
59
59
  const parentRoot = toRootHex(block.parentRoot);
60
- const parentBlock = isGloasBeaconBlock(block)
61
- ? this.modules.forkChoice.getBlockHexAndBlockHash(
62
- parentRoot,
63
- toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash)
64
- )
65
- : this.modules.forkChoice.getBlockHexDefaultStatus(parentRoot);
60
+ const parentBlock = this.modules.forkChoice.getBlockHexDefaultStatus(parentRoot);
66
61
  if (!parentBlock) {
67
62
  throw new RegenError({
68
63
  code: RegenErrorCode.BLOCK_NOT_IN_FORKCHOICE,
@@ -1,13 +1,13 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {CheckpointWithHex} from "@lodestar/fork-choice";
2
+ import {CheckpointWithHex, IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
3
3
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
4
- import {RootHex, Slot} from "@lodestar/types";
4
+ import {RootHex} from "@lodestar/types";
5
5
  import {Logger} from "@lodestar/utils";
6
6
  import {Metrics} from "../../metrics/metrics.js";
7
7
  import {IClock} from "../../util/clock.js";
8
8
  import {SerializedCache} from "../../util/serializedCache.js";
9
9
  import {isDaOutOfRange} from "../blocks/blockInput/index.js";
10
- import {CreateFromBlockProps, PayloadEnvelopeInput} from "../blocks/payloadEnvelopeInput/index.js";
10
+ import {CreateFromBidProps, CreateFromBlockProps, PayloadEnvelopeInput} from "../blocks/payloadEnvelopeInput/index.js";
11
11
  import {ChainEvent, ChainEventEmitter} from "../emitter.js";
12
12
 
13
13
  export type {PayloadEnvelopeInputState} from "../blocks/payloadEnvelopeInput/index.js";
@@ -16,6 +16,7 @@ export {PayloadEnvelopeInput} from "../blocks/payloadEnvelopeInput/index.js";
16
16
  export type SeenPayloadEnvelopeInputModules = {
17
17
  config: ChainForkConfig;
18
18
  clock: IClock;
19
+ forkChoice: IForkChoice;
19
20
  chainEvents: ChainEventEmitter;
20
21
  signal: AbortSignal;
21
22
  serializedCache: SerializedCache;
@@ -26,11 +27,7 @@ export type SeenPayloadEnvelopeInputModules = {
26
27
  /**
27
28
  * Cache for tracking PayloadEnvelopeInput instances, keyed by beacon block root.
28
29
  *
29
- * Created during block import when a block is processed. Two pruning paths:
30
- * - `prepareNextSlot` calls `pruneBelow(headParentSlot)` every slot once the head we'll build
31
- * on is known.
32
- * - `onFinalized` calls `pruneBelow(finalizedSlot)` on every finalization for bulk cleanup.
33
- *
30
+ * Created whenever we have a block because it needs block bid.
34
31
  * Steady state (linear chain, healthy progression): the cache holds ~2 entries — the head
35
32
  * (parent for next-slot production) and its parent (proposer-boost-reorg fallback). It can
36
33
  * transiently hold more during forks, range-sync bursts, or when `prepareNextSlot` skips
@@ -39,6 +36,7 @@ export type SeenPayloadEnvelopeInputModules = {
39
36
  export class SeenPayloadEnvelopeInput {
40
37
  private readonly config: ChainForkConfig;
41
38
  private readonly clock: IClock;
39
+ private readonly forkChoice: IForkChoice;
42
40
  private readonly chainEvents: ChainEventEmitter;
43
41
  private readonly signal: AbortSignal;
44
42
  private readonly serializedCache: SerializedCache;
@@ -46,9 +44,19 @@ export class SeenPayloadEnvelopeInput {
46
44
  private readonly logger?: Logger;
47
45
  private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
48
46
 
49
- constructor({config, clock, chainEvents, signal, serializedCache, metrics, logger}: SeenPayloadEnvelopeInputModules) {
47
+ constructor({
48
+ config,
49
+ clock,
50
+ forkChoice,
51
+ chainEvents,
52
+ signal,
53
+ serializedCache,
54
+ metrics,
55
+ logger,
56
+ }: SeenPayloadEnvelopeInputModules) {
50
57
  this.config = config;
51
58
  this.clock = clock;
59
+ this.forkChoice = forkChoice;
52
60
  this.chainEvents = chainEvents;
53
61
  this.signal = signal;
54
62
  this.serializedCache = serializedCache;
@@ -67,14 +75,27 @@ export class SeenPayloadEnvelopeInput {
67
75
  });
68
76
  }
69
77
 
70
- this.chainEvents.on(ChainEvent.forkChoiceFinalized, this.onFinalized);
78
+ this.chainEvents.on(ChainEvent.forkChoiceFinalized, this.pruneFinalized);
71
79
  this.signal.addEventListener("abort", () => {
72
- this.chainEvents.off(ChainEvent.forkChoiceFinalized, this.onFinalized);
80
+ this.chainEvents.off(ChainEvent.forkChoiceFinalized, this.pruneFinalized);
73
81
  });
74
82
  }
75
83
 
76
- private onFinalized = (checkpoint: CheckpointWithHex): void => {
77
- this.pruneBelow(computeStartSlotAtEpoch(checkpoint.epoch));
84
+ private pruneFinalized = (checkpoint: CheckpointWithHex): void => {
85
+ const finalizedSlot = computeStartSlotAtEpoch(checkpoint.epoch);
86
+ let deletedCount = 0;
87
+ for (const [, input] of this.payloadInputs) {
88
+ if (input.slot < finalizedSlot) {
89
+ this.evictPayloadInput(input);
90
+ deletedCount++;
91
+ }
92
+ }
93
+
94
+ this.logger?.debug("SeenPayloadEnvelopeInput.pruneFinalized deleted entries", {
95
+ finalizedSlot,
96
+ finalizedRoot: checkpoint.rootHex,
97
+ deletedCount,
98
+ });
78
99
  };
79
100
 
80
101
  add(props: Omit<CreateFromBlockProps, "daOutOfRange">): PayloadEnvelopeInput {
@@ -98,6 +119,27 @@ export class SeenPayloadEnvelopeInput {
98
119
  return input;
99
120
  }
100
121
 
122
+ /**
123
+ * Used at chain initialization to seed the anchor block's PayloadEnvelopeInput from
124
+ * `state.latestExecutionPayloadBid`.
125
+ */
126
+ addFromBid(props: Omit<CreateFromBidProps, "daOutOfRange">): PayloadEnvelopeInput {
127
+ const existing = this.payloadInputs.get(props.blockRootHex);
128
+ if (existing !== undefined) {
129
+ return existing;
130
+ }
131
+ const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.slot, this.clock.currentEpoch);
132
+ const input = PayloadEnvelopeInput.createFromBid({...props, daOutOfRange});
133
+ this.payloadInputs.set(props.blockRootHex, input);
134
+ this.metrics?.seenCache.payloadEnvelopeInput.created.inc();
135
+ this.logger?.verbose("SeenPayloadEnvelopeInput.addFromBid created new entry", {
136
+ slot: input.slot,
137
+ root: props.blockRootHex,
138
+ daOutOfRange,
139
+ });
140
+ return input;
141
+ }
142
+
101
143
  get(blockRootHex: RootHex): PayloadEnvelopeInput | undefined {
102
144
  return this.payloadInputs.get(blockRootHex);
103
145
  }
@@ -110,15 +152,19 @@ export class SeenPayloadEnvelopeInput {
110
152
  return this.payloadInputs.size;
111
153
  }
112
154
 
113
- pruneBelow(slot: Slot): void {
114
- let deletedCount = 0;
115
- for (const [, input] of this.payloadInputs) {
116
- if (input.slot < slot) {
117
- this.evictPayloadInput(input);
118
- deletedCount++;
155
+ pruneBelowParent(parentBlock: ProtoBlock): void {
156
+ for (const block of this.forkChoice.getAllAncestorBlocks(parentBlock.blockRoot, parentBlock.payloadStatus)) {
157
+ if (block.slot < parentBlock.slot) {
158
+ const input = this.payloadInputs.get(block.blockRoot);
159
+ if (input) {
160
+ this.evictPayloadInput(input);
161
+ this.logger?.verbose("SeenPayloadEnvelopeInput.pruneBelowParent deleted", {
162
+ slot: block.slot,
163
+ root: block.blockRoot,
164
+ });
165
+ }
119
166
  }
120
167
  }
121
- this.logger?.debug("SeenPayloadEnvelopeInput.pruneBelow deleted entries", {slot, deletedCount});
122
168
  }
123
169
 
124
170
  private evictPayloadInput(payloadInput: PayloadEnvelopeInput): void {
@@ -1,28 +1,31 @@
1
- import {Slot, ValidatorIndex} from "@lodestar/types";
1
+ import {RootHex, Slot, ValidatorIndex} from "@lodestar/types";
2
2
  import {MapDef} from "@lodestar/utils";
3
3
 
4
4
  /**
5
- * Tracks signed proposer preferences we've already seen per (proposal_slot, validator_index).
5
+ * Tracks signed proposer preferences we've already seen per (dependent_root, proposal_slot, validator_index).
6
6
  */
7
7
  export class SeenProposerPreferences {
8
- private readonly validatorIndexesBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set<ValidatorIndex>());
8
+ private readonly validatorByDependentRootBySlot = new MapDef<Slot, Map<RootHex, ValidatorIndex>>(
9
+ () => new Map<RootHex, ValidatorIndex>()
10
+ );
9
11
 
10
- isKnown(proposalSlot: Slot, validatorIndex: ValidatorIndex): boolean {
11
- return this.validatorIndexesBySlot.get(proposalSlot)?.has(validatorIndex) === true;
12
+ isKnown(dependentRoot: RootHex, proposalSlot: Slot, validatorIndex: ValidatorIndex): boolean {
13
+ return this.validatorByDependentRootBySlot.get(proposalSlot)?.get(dependentRoot) === validatorIndex;
12
14
  }
13
15
 
14
- add(proposalSlot: Slot, validatorIndex: ValidatorIndex): void {
15
- this.validatorIndexesBySlot.getOrDefault(proposalSlot).add(validatorIndex);
16
+ add(dependentRoot: RootHex, proposalSlot: Slot, validatorIndex: ValidatorIndex): void {
17
+ this.validatorByDependentRootBySlot.getOrDefault(proposalSlot).set(dependentRoot, validatorIndex);
16
18
  }
17
19
 
18
20
  /**
19
- * Entries are only load-bearing while `proposal_slot > state.slot`. Once the slot has passed the
20
- * `[IGNORE] proposal_slot > state.slot` gossip rule takes over, so drop them on each slot tick.
21
+ * Entries are only load-bearing while `proposal_slot > current_slot`. Once the slot has
22
+ * passed the `[IGNORE] proposal_slot > current_slot` gossip rule takes over, so drop them
23
+ * on each slot tick.
21
24
  */
22
25
  prune(currentSlot: Slot): void {
23
- for (const slot of this.validatorIndexesBySlot.keys()) {
26
+ for (const slot of this.validatorByDependentRootBySlot.keys()) {
24
27
  if (slot < currentSlot) {
25
- this.validatorIndexesBySlot.delete(slot);
28
+ this.validatorByDependentRootBySlot.delete(slot);
26
29
  }
27
30
  }
28
31
  }
@@ -48,9 +48,12 @@ async function validateExecutionPayloadBid(
48
48
  });
49
49
  }
50
50
 
51
- // [IGNORE] the `SignedProposerPreferences` where `preferences.proposal_slot`
52
- // is equal to `bid.slot` has been seen.
53
- // TODO GLOAS: Implement this along with proposer preference
51
+ // [IGNORE] A `SignedProposerPreferences` matching `bid.slot` and the bid's branch has been
52
+ // seen i.e. `proposal_slot == bid.slot` AND `dependent_root ==
53
+ // get_proposer_dependent_root(parent_state, compute_epoch_at_slot(bid.slot))`,
54
+ // where `parent_state` is the post-state of `bid.parent_block_root`.
55
+ // This is the message referenced as `proposer_preferences` in the following REJECT rules.
56
+ // TODO GLOAS: Implement once a ProposerPreferencesPool exists.
54
57
 
55
58
  // [REJECT] `bid.builder_index` is a valid/active builder index -- i.e.
56
59
  // `is_active_builder(state, bid.builder_index)` returns `True`.
@@ -71,11 +74,11 @@ async function validateExecutionPayloadBid(
71
74
  });
72
75
  }
73
76
 
74
- // [REJECT] `bid.fee_recipient` matches the `fee_recipient` from the proposer's
75
- // `SignedProposerPreferences` associated with `bid.slot`.
76
- // [REJECT] `bid.gas_limit` matches the `gas_limit` from the proposer's
77
- // `SignedProposerPreferences` associated with `bid.slot`.
78
- // TODO GLOAS: Implement this along with proposer preference
77
+ // [REJECT] `bid.fee_recipient == proposer_preferences.fee_recipient`.
78
+ // [REJECT] `bid.gas_limit == proposer_preferences.gas_limit`.
79
+ // Both compared against the matching `proposer_preferences` defined above (same branch
80
+ // via dependent_root, same proposal_slot).
81
+ // TODO GLOAS: Implement once a ProposerPreferencesPool exists.
79
82
 
80
83
  // [REJECT] The length of KZG commitments is less than or equal to the limitation defined in the
81
84
  // consensus layer -- i.e. validate that