@lodestar/beacon-node 1.43.0-dev.1629c3a59e → 1.43.0-dev.1a52372103

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 (122) 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/importBlock.d.ts.map +1 -1
  11. package/lib/chain/blocks/importBlock.js +23 -20
  12. package/lib/chain/blocks/importBlock.js.map +1 -1
  13. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  14. package/lib/chain/blocks/importExecutionPayload.js +3 -5
  15. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  16. package/lib/chain/blocks/index.d.ts.map +1 -1
  17. package/lib/chain/blocks/index.js +30 -17
  18. package/lib/chain/blocks/index.js.map +1 -1
  19. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -1
  20. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +1 -0
  21. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.map +1 -1
  22. package/lib/chain/blocks/types.d.ts +2 -1
  23. package/lib/chain/blocks/types.d.ts.map +1 -1
  24. package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
  25. package/lib/chain/blocks/utils/chainSegment.js +8 -0
  26. package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
  27. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  28. package/lib/chain/blocks/verifyBlock.js +5 -6
  29. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  30. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +0 -4
  31. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  32. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +5 -2
  33. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  34. package/lib/chain/blocks/verifyBlocksSanityChecks.d.ts +2 -1
  35. package/lib/chain/blocks/verifyBlocksSanityChecks.d.ts.map +1 -1
  36. package/lib/chain/blocks/verifyBlocksSanityChecks.js +16 -7
  37. package/lib/chain/blocks/verifyBlocksSanityChecks.js.map +1 -1
  38. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts +2 -2
  39. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts.map +1 -1
  40. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js +5 -2
  41. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js.map +1 -1
  42. package/lib/chain/errors/proposerPreferences.d.ts +8 -1
  43. package/lib/chain/errors/proposerPreferences.d.ts.map +1 -1
  44. package/lib/chain/errors/proposerPreferences.js +1 -0
  45. package/lib/chain/errors/proposerPreferences.js.map +1 -1
  46. package/lib/chain/produceBlock/produceBlockBody.d.ts +1 -0
  47. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  48. package/lib/chain/produceBlock/produceBlockBody.js +2 -7
  49. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  50. package/lib/chain/regen/queued.d.ts.map +1 -1
  51. package/lib/chain/regen/queued.js +1 -4
  52. package/lib/chain/regen/queued.js.map +1 -1
  53. package/lib/chain/regen/regen.d.ts.map +1 -1
  54. package/lib/chain/regen/regen.js +1 -4
  55. package/lib/chain/regen/regen.js.map +1 -1
  56. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  57. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +12 -2
  58. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  59. package/lib/chain/seenCache/seenProposerPreferences.d.ts +8 -7
  60. package/lib/chain/seenCache/seenProposerPreferences.d.ts.map +1 -1
  61. package/lib/chain/seenCache/seenProposerPreferences.js +17 -11
  62. package/lib/chain/seenCache/seenProposerPreferences.js.map +1 -1
  63. package/lib/chain/validation/executionPayloadBid.js +11 -8
  64. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  65. package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
  66. package/lib/chain/validation/proposerPreferences.js +39 -17
  67. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  68. package/lib/network/gossip/topic.d.ts +2 -0
  69. package/lib/network/gossip/topic.d.ts.map +1 -1
  70. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  71. package/lib/network/processor/gossipHandlers.js +10 -0
  72. package/lib/network/processor/gossipHandlers.js.map +1 -1
  73. package/lib/node/nodejs.js +2 -2
  74. package/lib/node/nodejs.js.map +1 -1
  75. package/lib/node/notifier.js +1 -7
  76. package/lib/node/notifier.js.map +1 -1
  77. package/lib/sync/range/batch.d.ts +11 -0
  78. package/lib/sync/range/batch.d.ts.map +1 -1
  79. package/lib/sync/range/batch.js +29 -4
  80. package/lib/sync/range/batch.js.map +1 -1
  81. package/lib/sync/range/chain.d.ts.map +1 -1
  82. package/lib/sync/range/chain.js +23 -5
  83. package/lib/sync/range/chain.js.map +1 -1
  84. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  85. package/lib/sync/utils/downloadByRange.js +36 -19
  86. package/lib/sync/utils/downloadByRange.js.map +1 -1
  87. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  88. package/lib/sync/utils/downloadByRoot.js +10 -0
  89. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  90. package/lib/util/sszBytes.d.ts.map +1 -1
  91. package/lib/util/sszBytes.js +8 -6
  92. package/lib/util/sszBytes.js.map +1 -1
  93. package/package.json +15 -15
  94. package/src/api/impl/beacon/blocks/index.ts +13 -0
  95. package/src/api/impl/debug/index.ts +0 -1
  96. package/src/api/impl/validator/index.ts +2 -1
  97. package/src/chain/blocks/importBlock.ts +23 -38
  98. package/src/chain/blocks/importExecutionPayload.ts +3 -5
  99. package/src/chain/blocks/index.ts +20 -9
  100. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +1 -0
  101. package/src/chain/blocks/types.ts +2 -1
  102. package/src/chain/blocks/utils/chainSegment.ts +8 -0
  103. package/src/chain/blocks/verifyBlock.ts +7 -5
  104. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +6 -4
  105. package/src/chain/blocks/verifyBlocksSanityChecks.ts +16 -6
  106. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +7 -2
  107. package/src/chain/errors/proposerPreferences.ts +9 -1
  108. package/src/chain/produceBlock/produceBlockBody.ts +3 -7
  109. package/src/chain/regen/queued.ts +2 -7
  110. package/src/chain/regen/regen.ts +2 -7
  111. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +12 -2
  112. package/src/chain/seenCache/seenProposerPreferences.ts +20 -12
  113. package/src/chain/validation/executionPayloadBid.ts +11 -8
  114. package/src/chain/validation/proposerPreferences.ts +37 -18
  115. package/src/network/processor/gossipHandlers.ts +12 -0
  116. package/src/node/nodejs.ts +2 -2
  117. package/src/node/notifier.ts +1 -8
  118. package/src/sync/range/batch.ts +54 -5
  119. package/src/sync/range/chain.ts +25 -5
  120. package/src/sync/utils/downloadByRange.ts +36 -18
  121. package/src/sync/utils/downloadByRoot.ts +12 -0
  122. 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,
@@ -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,
@@ -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;
@@ -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,
@@ -78,13 +78,23 @@ export class SeenPayloadEnvelopeInput {
78
78
  };
79
79
 
80
80
  add(props: Omit<CreateFromBlockProps, "daOutOfRange">): PayloadEnvelopeInput {
81
- if (this.payloadInputs.has(props.blockRootHex)) {
82
- throw new Error(`PayloadEnvelopeInput already exists for block ${props.blockRootHex}`);
81
+ const existing = this.payloadInputs.get(props.blockRootHex);
82
+ if (existing !== undefined) {
83
+ this.logger?.verbose("SeenPayloadEnvelopeInput.add reused existing entry", {
84
+ slot: existing.slot,
85
+ root: props.blockRootHex,
86
+ });
87
+ return existing;
83
88
  }
84
89
  const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
85
90
  const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
86
91
  this.payloadInputs.set(props.blockRootHex, input);
87
92
  this.metrics?.seenCache.payloadEnvelopeInput.created.inc();
93
+ this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
94
+ slot: input.slot,
95
+ root: props.blockRootHex,
96
+ daOutOfRange,
97
+ });
88
98
  return input;
89
99
  }
90
100
 
@@ -1,28 +1,36 @@
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 validatorBySlotByDependentRoot = new MapDef<RootHex, Map<Slot, ValidatorIndex>>(
9
+ () => new Map<Slot, 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.validatorBySlotByDependentRoot.get(dependentRoot)?.get(proposalSlot) === 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.validatorBySlotByDependentRoot.getOrDefault(dependentRoot).set(proposalSlot, 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()) {
24
- if (slot < currentSlot) {
25
- this.validatorIndexesBySlot.delete(slot);
26
+ for (const [dependentRoot, slotMap] of this.validatorBySlotByDependentRoot.entries()) {
27
+ for (const slot of slotMap.keys()) {
28
+ if (slot < currentSlot) {
29
+ slotMap.delete(slot);
30
+ }
31
+ }
32
+ if (slotMap.size === 0) {
33
+ this.validatorBySlotByDependentRoot.delete(dependentRoot);
26
34
  }
27
35
  }
28
36
  }
@@ -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
@@ -3,12 +3,11 @@ import {
3
3
  computeEpochAtSlot,
4
4
  createSingleSignatureSetFromComponents,
5
5
  getProposerPreferencesSigningRoot,
6
- isStatePostGloas,
7
6
  } from "@lodestar/state-transition";
8
- import {gloas} from "@lodestar/types";
7
+ import {ValidatorIndex, gloas} from "@lodestar/types";
8
+ import {toRootHex} from "@lodestar/utils";
9
9
  import {GossipAction, ProposerPreferencesError, ProposerPreferencesErrorCode} from "../errors/index.js";
10
10
  import {IBeaconChain} from "../index.js";
11
- import {RegenCaller} from "../regen/index.js";
12
11
 
13
12
  /**
14
13
  * Validates a gossiped `SignedProposerPreferences` per
@@ -19,7 +18,8 @@ export async function validateGossipProposerPreferences(
19
18
  signedProposerPreferences: gloas.SignedProposerPreferences
20
19
  ): Promise<void> {
21
20
  const preferences = signedProposerPreferences.message;
22
- const {proposalSlot, validatorIndex} = preferences;
21
+ const {proposalSlot, validatorIndex, dependentRoot} = preferences;
22
+ const dependentRootHex = toRootHex(dependentRoot);
23
23
  const proposalEpoch = computeEpochAtSlot(proposalSlot);
24
24
 
25
25
  // [IGNORE] `preferences.proposal_slot` is in the current or next epoch.
@@ -42,32 +42,51 @@ export async function validateGossipProposerPreferences(
42
42
  });
43
43
  }
44
44
 
45
- const state = await chain.getHeadStateAtCurrentEpoch(RegenCaller.validateGossipProposerPreferences);
46
- if (!isStatePostGloas(state)) {
47
- throw new Error(`Expected gloas+ state for proposer preferences validation, got fork=${state.forkName}`);
45
+ // [IGNORE] The block with root `dependent_root` has been seen by the node.
46
+ // Resolve the proposer lookahead for the message's branch via head state (fast path) or
47
+ // the previous-root checkpoint state (populated by `processSlotsToNearestCheckpoint` for
48
+ // any imported branch crossing into `proposalEpoch - 1`). The head-state path also handles
49
+ // narrow timing windows where the checkpoint state isn't yet populated.
50
+ const headState = chain.getHeadState();
51
+ let proposers: ValidatorIndex[] | null = null;
52
+ if (headState.epoch === proposalEpoch && headState.currentDecisionRoot === dependentRootHex) {
53
+ proposers = headState.currentProposers;
54
+ } else if (headState.epoch === proposalEpoch - 1 && headState.nextDecisionRoot === dependentRootHex) {
55
+ proposers = headState.nextProposers;
56
+ } else {
57
+ // Sync lookup only to not trigger disk reload from gossip input.
58
+ const checkpointState = chain.regen.getCheckpointStateSync({epoch: proposalEpoch - 1, rootHex: dependentRootHex});
59
+ if (checkpointState !== null) {
60
+ // State is at `proposalEpoch - 1`, so proposers for `proposalSlot` (next epoch from
61
+ // the state's perspective) live in `nextProposers`.
62
+ proposers = checkpointState.nextProposers;
63
+ }
64
+ }
65
+ if (proposers === null) {
66
+ throw new ProposerPreferencesError(GossipAction.IGNORE, {
67
+ code: ProposerPreferencesErrorCode.UNKNOWN_DEPENDENT_ROOT,
68
+ proposalSlot,
69
+ dependentRoot: dependentRootHex,
70
+ });
48
71
  }
49
72
 
50
- // [REJECT] `preferences.validator_index` is present at the correct slot in the current or next
51
- // epoch's portion of `state.proposer_lookahead` i.e. `is_valid_proposal_slot(state, preferences)`
52
- // returns True.
53
- const epochOffset = proposalEpoch - state.epoch;
54
- const proposers = epochOffset === 0 ? state.currentProposers : state.nextProposers;
55
- const expectedProposer = proposers[proposalSlot % SLOTS_PER_EPOCH];
56
- if (epochOffset < 0 || epochOffset > 1 || expectedProposer !== validatorIndex) {
73
+ // [REJECT] `is_valid_proposal_slot(state, preferences)` returns True.
74
+ if (proposers[proposalSlot % SLOTS_PER_EPOCH] !== validatorIndex) {
57
75
  throw new ProposerPreferencesError(GossipAction.REJECT, {
58
76
  code: ProposerPreferencesErrorCode.INVALID_PROPOSER,
59
77
  proposalSlot,
60
78
  validatorIndex,
79
+ dependentRoot: dependentRootHex,
61
80
  });
62
81
  }
63
82
 
64
- // [IGNORE] The `signed_proposer_preferences` is the first valid message received from the validator
65
- // with index `preferences.validator_index` and the given slot `preferences.proposal_slot`.
66
- if (chain.seenProposerPreferences.isKnown(proposalSlot, validatorIndex)) {
83
+ // [IGNORE] First valid message for (dependent_root, proposal_slot, validator_index).
84
+ if (chain.seenProposerPreferences.isKnown(dependentRootHex, proposalSlot, validatorIndex)) {
67
85
  throw new ProposerPreferencesError(GossipAction.IGNORE, {
68
86
  code: ProposerPreferencesErrorCode.ALREADY_KNOWN,
69
87
  proposalSlot,
70
88
  validatorIndex,
89
+ dependentRoot: dependentRootHex,
71
90
  });
72
91
  }
73
92
 
@@ -87,5 +106,5 @@ export async function validateGossipProposerPreferences(
87
106
  }
88
107
 
89
108
  // Valid
90
- chain.seenProposerPreferences.add(proposalSlot, validatorIndex);
109
+ chain.seenProposerPreferences.add(dependentRootHex, proposalSlot, validatorIndex);
91
110
  }
@@ -185,6 +185,18 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
185
185
  });
186
186
  try {
187
187
  await validateGossipBlock(config, chain, signedBlock, fork);
188
+
189
+ if (isForkPostGloas(fork)) {
190
+ chain.seenPayloadEnvelopeInputCache.add({
191
+ blockRootHex,
192
+ block: signedBlock as SignedBeaconBlock<ForkPostGloas>,
193
+ forkName: fork,
194
+ sampledColumns: chain.custodyConfig.sampledColumns,
195
+ custodyColumns: chain.custodyConfig.custodyColumns,
196
+ timeCreatedSec: seenTimestampSec,
197
+ });
198
+ }
199
+
188
200
  const blockInputMeta = blockInput.getLogMeta();
189
201
 
190
202
  const recvToValidation = Date.now() / 1000 - seenTimestampSec;
@@ -221,7 +221,7 @@ export class BeaconNode {
221
221
 
222
222
  let executionEngineOpts = opts.executionEngine;
223
223
  if (opts.executionEngine.mode === "mock") {
224
- const eth1BlockHash =
224
+ const latestEth1BlockHash =
225
225
  isStatePostBellatrix(anchorState) && anchorState.isExecutionStateType
226
226
  ? isStatePostGloas(anchorState)
227
227
  ? toRootHex(anchorState.latestBlockHash)
@@ -230,7 +230,7 @@ export class BeaconNode {
230
230
  executionEngineOpts = {
231
231
  ...opts.executionEngine,
232
232
  genesisBlockHash: ZERO_HASH_HEX,
233
- eth1BlockHash,
233
+ eth1BlockHash: opts.executionEngine.eth1BlockHash ?? latestEth1BlockHash,
234
234
  genesisTime: anchorState.genesisTime,
235
235
  config,
236
236
  };
@@ -167,14 +167,7 @@ function getHeadExecutionInfo(
167
167
  return [];
168
168
  }
169
169
 
170
- // A PayloadSeparated head is a gloas beacon block imported before its payload envelope
171
- // arrives, in that case the exec-block row surfaces the inherited parent anchor (from the
172
- // bid), which is already validated. Normalize to "valid" to avoid leaking internal
173
- // fork-choice bookkeeping into the log. Once the payload envelope arrives and the FULL
174
- // variant becomes head, executionStatus is Valid/Syncing naturally.
175
- // TODO GLOAS: revisit once optimistic sync is implemented
176
- const executionStatusStr =
177
- headInfo.executionStatus === ExecutionStatus.PayloadSeparated ? "valid" : headInfo.executionStatus.toLowerCase();
170
+ const executionStatusStr = headInfo.executionStatus.toLowerCase();
178
171
 
179
172
  // Add execution status to notifier only if head is on/post bellatrix
180
173
  if (isStatePostBellatrix(headState) && headState.isExecutionStateType) {