@lodestar/beacon-node 1.43.0-dev.1213f9c92d → 1.43.0-dev.12d35509c0

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 (146) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +10 -0
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/debug/index.d.ts.map +1 -1
  5. package/lib/api/impl/debug/index.js +0 -1
  6. package/lib/api/impl/debug/index.js.map +1 -1
  7. package/lib/api/impl/validator/index.d.ts.map +1 -1
  8. package/lib/api/impl/validator/index.js +2 -1
  9. package/lib/api/impl/validator/index.js.map +1 -1
  10. package/lib/chain/blocks/blockInput/blockInput.d.ts +3 -0
  11. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  12. package/lib/chain/blocks/blockInput/blockInput.js +4 -1
  13. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  14. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  15. package/lib/chain/blocks/importBlock.js +16 -29
  16. package/lib/chain/blocks/importBlock.js.map +1 -1
  17. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  18. package/lib/chain/blocks/importExecutionPayload.js +3 -5
  19. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  20. package/lib/chain/blocks/index.d.ts.map +1 -1
  21. package/lib/chain/blocks/index.js +30 -17
  22. package/lib/chain/blocks/index.js.map +1 -1
  23. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts +3 -0
  24. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -1
  25. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +5 -1
  26. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.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 +5 -2
  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 +10 -9
  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/prepareNextSlot.js +1 -1
  55. package/lib/chain/prepareNextSlot.js.map +1 -1
  56. package/lib/chain/produceBlock/produceBlockBody.d.ts +1 -0
  57. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  58. package/lib/chain/produceBlock/produceBlockBody.js +2 -7
  59. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  60. package/lib/chain/regen/queued.d.ts.map +1 -1
  61. package/lib/chain/regen/queued.js +1 -4
  62. package/lib/chain/regen/queued.js.map +1 -1
  63. package/lib/chain/regen/regen.d.ts.map +1 -1
  64. package/lib/chain/regen/regen.js +1 -4
  65. package/lib/chain/regen/regen.js.map +1 -1
  66. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +7 -4
  67. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  68. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +42 -14
  69. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  70. package/lib/chain/seenCache/seenProposerPreferences.d.ts +8 -7
  71. package/lib/chain/seenCache/seenProposerPreferences.d.ts.map +1 -1
  72. package/lib/chain/seenCache/seenProposerPreferences.js +11 -10
  73. package/lib/chain/seenCache/seenProposerPreferences.js.map +1 -1
  74. package/lib/chain/validation/executionPayloadBid.js +11 -8
  75. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  76. package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
  77. package/lib/chain/validation/proposerPreferences.js +39 -17
  78. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  79. package/lib/network/gossip/topic.d.ts +2 -0
  80. package/lib/network/gossip/topic.d.ts.map +1 -1
  81. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  82. package/lib/network/processor/gossipHandlers.js +24 -0
  83. package/lib/network/processor/gossipHandlers.js.map +1 -1
  84. package/lib/node/nodejs.js +2 -2
  85. package/lib/node/nodejs.js.map +1 -1
  86. package/lib/node/notifier.js +1 -7
  87. package/lib/node/notifier.js.map +1 -1
  88. package/lib/sync/constants.d.ts +3 -1
  89. package/lib/sync/constants.d.ts.map +1 -1
  90. package/lib/sync/constants.js +3 -4
  91. package/lib/sync/constants.js.map +1 -1
  92. package/lib/sync/range/batch.d.ts +5 -0
  93. package/lib/sync/range/batch.d.ts.map +1 -1
  94. package/lib/sync/range/batch.js +68 -17
  95. package/lib/sync/range/batch.js.map +1 -1
  96. package/lib/sync/range/chain.d.ts +6 -0
  97. package/lib/sync/range/chain.d.ts.map +1 -1
  98. package/lib/sync/range/chain.js +27 -2
  99. package/lib/sync/range/chain.js.map +1 -1
  100. package/lib/sync/unknownBlock.d.ts.map +1 -1
  101. package/lib/sync/unknownBlock.js +2 -0
  102. package/lib/sync/unknownBlock.js.map +1 -1
  103. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  104. package/lib/sync/utils/downloadByRange.js +36 -21
  105. package/lib/sync/utils/downloadByRange.js.map +1 -1
  106. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  107. package/lib/sync/utils/downloadByRoot.js +10 -0
  108. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  109. package/lib/util/sszBytes.d.ts.map +1 -1
  110. package/lib/util/sszBytes.js +8 -6
  111. package/lib/util/sszBytes.js.map +1 -1
  112. package/package.json +15 -15
  113. package/src/api/impl/beacon/blocks/index.ts +13 -0
  114. package/src/api/impl/debug/index.ts +0 -1
  115. package/src/api/impl/validator/index.ts +2 -1
  116. package/src/chain/blocks/blockInput/blockInput.ts +4 -1
  117. package/src/chain/blocks/importBlock.ts +16 -49
  118. package/src/chain/blocks/importExecutionPayload.ts +3 -5
  119. package/src/chain/blocks/index.ts +20 -9
  120. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +5 -1
  121. package/src/chain/blocks/types.ts +2 -1
  122. package/src/chain/blocks/utils/chainSegment.ts +8 -0
  123. package/src/chain/blocks/verifyBlock.ts +7 -5
  124. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +6 -4
  125. package/src/chain/blocks/verifyBlocksSanityChecks.ts +16 -6
  126. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +7 -2
  127. package/src/chain/chain.ts +12 -9
  128. package/src/chain/errors/proposerPreferences.ts +9 -1
  129. package/src/chain/prepareNextSlot.ts +1 -1
  130. package/src/chain/produceBlock/produceBlockBody.ts +3 -7
  131. package/src/chain/regen/queued.ts +2 -7
  132. package/src/chain/regen/regen.ts +2 -7
  133. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +55 -16
  134. package/src/chain/seenCache/seenProposerPreferences.ts +14 -11
  135. package/src/chain/validation/executionPayloadBid.ts +11 -8
  136. package/src/chain/validation/proposerPreferences.ts +37 -18
  137. package/src/network/processor/gossipHandlers.ts +30 -0
  138. package/src/node/nodejs.ts +2 -2
  139. package/src/node/notifier.ts +1 -8
  140. package/src/sync/constants.ts +4 -4
  141. package/src/sync/range/batch.ts +70 -19
  142. package/src/sync/range/chain.ts +32 -2
  143. package/src/sync/unknownBlock.ts +2 -0
  144. package/src/sync/utils/downloadByRange.ts +37 -21
  145. package/src/sync/utils/downloadByRoot.ts +12 -0
  146. package/src/util/sszBytes.ts +8 -6
@@ -65,7 +65,7 @@ export async function processBlocks(
65
65
  }
66
66
 
67
67
  try {
68
- const {relevantBlocks, parentSlots, parentBlock} = verifyBlocksSanityChecks(this, blocks, opts);
68
+ const {relevantBlocks, parentSlots, parentBlock} = verifyBlocksSanityChecks(this, blocks, payloadEnvelopes, opts);
69
69
 
70
70
  // No relevant blocks, skip verifyBlocksInEpoch()
71
71
  if (relevantBlocks.length === 0 || parentBlock === null) {
@@ -109,8 +109,10 @@ export async function processBlocks(
109
109
  }
110
110
 
111
111
  const {executionStatuses} = segmentExecStatus;
112
- const fullyVerifiedBlocks = relevantBlocks.map(
113
- (block, i): FullyVerifiedBlock => ({
112
+ const verifiedBlocksBySlot = new Map<Slot, FullyVerifiedBlock>();
113
+ for (let i = 0; i < relevantBlocks.length; i++) {
114
+ const block = relevantBlocks[i];
115
+ verifiedBlocksBySlot.set(block.getBlock().message.slot, {
114
116
  blockInput: block,
115
117
  postState: postStates[i],
116
118
  parentBlockSlot: parentSlots[i],
@@ -121,14 +123,23 @@ export async function processBlocks(
121
123
  indexedAttestations: indexedAttestationsByBlock[i],
122
124
  // TODO: Make this param mandatory and capture in gossip
123
125
  seenTimestampSec: opts.seenTimestampSec ?? Math.floor(Date.now() / 1000),
124
- })
125
- );
126
+ });
127
+ }
126
128
 
127
- for (const fullyVerifiedBlock of fullyVerifiedBlocks) {
128
- // TODO: Consider batching importBlock too if it takes significant time
129
- await importBlock.call(this, fullyVerifiedBlock, opts);
129
+ // Iterate slots from the original `blocks` input (which spans the entire batch including
130
+ // slots filtered out of `relevantBlocks`). The first batch of a checkpoint sync may contain
131
+ // a payload at the anchor slot whose block is already in fork-choice (added by
132
+ // initializeForkChoice as PENDING+EMPTY) and therefore not in verifiedBlocksBySlot — the
133
+ // payload still needs to be imported here to populate the anchor's FULL variant so
134
+ // subsequent slots can find their parent payload.
135
+ const slots = Array.from(new Set(blocks.map((b) => b.getBlock().message.slot)));
136
+ for (const slot of slots) {
137
+ const fullyVerifiedBlock = verifiedBlocksBySlot.get(slot);
138
+ if (fullyVerifiedBlock !== undefined) {
139
+ // TODO: Consider batching importBlock too if it takes significant time
140
+ await importBlock.call(this, fullyVerifiedBlock, opts);
141
+ }
130
142
 
131
- const slot = fullyVerifiedBlock.blockInput.getBlock().message.slot;
132
143
  const payloadInput = payloadEnvelopes?.get(slot);
133
144
  if (payloadInput?.hasPayloadEnvelope()) {
134
145
  if (!payloadInput.isComplete()) {
@@ -156,6 +156,7 @@ export class PayloadEnvelopeInput {
156
156
  throw new Error("Payload envelope beacon_block_root mismatch");
157
157
  }
158
158
 
159
+ // TODO GLOAS: track source by metrics, maybe inside the seen cache
159
160
  const source: SourceMeta = {
160
161
  source: props.source,
161
162
  seenTimestampSec: props.seenTimestampSec,
@@ -310,8 +311,11 @@ export class PayloadEnvelopeInput {
310
311
  return this.state.hasAllData;
311
312
  }
312
313
 
314
+ /**
315
+ * Strictly checks missing sampled columns. Does NOT short-circuit on `state.hasAllData`.
316
+ */
313
317
  getMissingSampledColumnMeta(): MissingColumnMeta {
314
- if (this.state.hasAllData) {
318
+ if (this.state.hasComputedAllData) {
315
319
  return {missing: [], versionedHashes: this.versionedHashes};
316
320
  }
317
321
 
@@ -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;
@@ -108,7 +113,7 @@ export function verifyExecutionPayloadEnvelope(
108
113
  /**
109
114
  * Verify the BLS signature of an execution payload envelope.
110
115
  *
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
116
+ * 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
117
  */
113
118
  export async function verifyExecutionPayloadEnvelopeSignature(
114
119
  config: BeaconConfig,
@@ -335,15 +335,6 @@ export class BeaconChain implements IBeaconChain {
335
335
  metrics,
336
336
  logger,
337
337
  });
338
- this.seenPayloadEnvelopeInputCache = new SeenPayloadEnvelopeInput({
339
- config,
340
- clock,
341
- chainEvents: emitter,
342
- signal,
343
- serializedCache: this.serializedCache,
344
- metrics,
345
- logger,
346
- });
347
338
 
348
339
  this._earliestAvailableSlot = anchorState.slot;
349
340
 
@@ -423,6 +414,18 @@ export class BeaconChain implements IBeaconChain {
423
414
  this.payloadEnvelopeProcessor = new PayloadEnvelopeProcessor(this, metrics, signal);
424
415
 
425
416
  this.forkChoice = forkChoice;
417
+
418
+ this.seenPayloadEnvelopeInputCache = new SeenPayloadEnvelopeInput({
419
+ config,
420
+ clock,
421
+ forkChoice,
422
+ chainEvents: emitter,
423
+ signal,
424
+ serializedCache: this.serializedCache,
425
+ metrics,
426
+ logger,
427
+ });
428
+
426
429
  this.clock = clock;
427
430
  this.regen = regen;
428
431
  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;
@@ -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,7 +1,7 @@
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";
@@ -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;
@@ -39,6 +40,7 @@ export type SeenPayloadEnvelopeInputModules = {
39
40
  export class SeenPayloadEnvelopeInput {
40
41
  private readonly config: ChainForkConfig;
41
42
  private readonly clock: IClock;
43
+ private readonly forkChoice: IForkChoice;
42
44
  private readonly chainEvents: ChainEventEmitter;
43
45
  private readonly signal: AbortSignal;
44
46
  private readonly serializedCache: SerializedCache;
@@ -46,9 +48,19 @@ export class SeenPayloadEnvelopeInput {
46
48
  private readonly logger?: Logger;
47
49
  private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
48
50
 
49
- constructor({config, clock, chainEvents, signal, serializedCache, metrics, logger}: SeenPayloadEnvelopeInputModules) {
51
+ constructor({
52
+ config,
53
+ clock,
54
+ forkChoice,
55
+ chainEvents,
56
+ signal,
57
+ serializedCache,
58
+ metrics,
59
+ logger,
60
+ }: SeenPayloadEnvelopeInputModules) {
50
61
  this.config = config;
51
62
  this.clock = clock;
63
+ this.forkChoice = forkChoice;
52
64
  this.chainEvents = chainEvents;
53
65
  this.signal = signal;
54
66
  this.serializedCache = serializedCache;
@@ -67,24 +79,47 @@ export class SeenPayloadEnvelopeInput {
67
79
  });
68
80
  }
69
81
 
70
- this.chainEvents.on(ChainEvent.forkChoiceFinalized, this.onFinalized);
82
+ this.chainEvents.on(ChainEvent.forkChoiceFinalized, this.pruneFinalized);
71
83
  this.signal.addEventListener("abort", () => {
72
- this.chainEvents.off(ChainEvent.forkChoiceFinalized, this.onFinalized);
84
+ this.chainEvents.off(ChainEvent.forkChoiceFinalized, this.pruneFinalized);
73
85
  });
74
86
  }
75
87
 
76
- private onFinalized = (checkpoint: CheckpointWithHex): void => {
77
- this.pruneBelow(computeStartSlotAtEpoch(checkpoint.epoch));
88
+ private pruneFinalized = (checkpoint: CheckpointWithHex): void => {
89
+ const finalizedSlot = computeStartSlotAtEpoch(checkpoint.epoch);
90
+ let deletedCount = 0;
91
+ for (const [, input] of this.payloadInputs) {
92
+ if (input.slot < finalizedSlot) {
93
+ this.evictPayloadInput(input);
94
+ deletedCount++;
95
+ }
96
+ }
97
+
98
+ this.logger?.debug("SeenPayloadEnvelopeInput.pruneFinalized deleted entries", {
99
+ finalizedSlot,
100
+ finalizedRoot: checkpoint.rootHex,
101
+ deletedCount,
102
+ });
78
103
  };
79
104
 
80
105
  add(props: Omit<CreateFromBlockProps, "daOutOfRange">): PayloadEnvelopeInput {
81
- if (this.payloadInputs.has(props.blockRootHex)) {
82
- throw new Error(`PayloadEnvelopeInput already exists for block ${props.blockRootHex}`);
106
+ const existing = this.payloadInputs.get(props.blockRootHex);
107
+ if (existing !== undefined) {
108
+ this.logger?.verbose("SeenPayloadEnvelopeInput.add reused existing entry", {
109
+ slot: existing.slot,
110
+ root: props.blockRootHex,
111
+ });
112
+ return existing;
83
113
  }
84
114
  const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
85
115
  const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
86
116
  this.payloadInputs.set(props.blockRootHex, input);
87
117
  this.metrics?.seenCache.payloadEnvelopeInput.created.inc();
118
+ this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
119
+ slot: input.slot,
120
+ root: props.blockRootHex,
121
+ daOutOfRange,
122
+ });
88
123
  return input;
89
124
  }
90
125
 
@@ -100,15 +135,19 @@ export class SeenPayloadEnvelopeInput {
100
135
  return this.payloadInputs.size;
101
136
  }
102
137
 
103
- pruneBelow(slot: Slot): void {
104
- let deletedCount = 0;
105
- for (const [, input] of this.payloadInputs) {
106
- if (input.slot < slot) {
107
- this.evictPayloadInput(input);
108
- deletedCount++;
138
+ pruneBelowParent(parentBlock: ProtoBlock): void {
139
+ for (const block of this.forkChoice.getAllAncestorBlocks(parentBlock.blockRoot, parentBlock.payloadStatus)) {
140
+ if (block.slot < parentBlock.slot) {
141
+ const input = this.payloadInputs.get(block.blockRoot);
142
+ if (input) {
143
+ this.evictPayloadInput(input);
144
+ this.logger?.verbose("SeenPayloadEnvelopeInput.pruneBelowParent deleted", {
145
+ slot: block.slot,
146
+ root: block.blockRoot,
147
+ });
148
+ }
109
149
  }
110
150
  }
111
- this.logger?.debug("SeenPayloadEnvelopeInput.pruneBelow deleted entries", {slot, deletedCount});
112
151
  }
113
152
 
114
153
  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