@lodestar/beacon-node 1.43.0-dev.549a5b8115 → 1.43.0-dev.657dd16e61

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 (160) 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/emitter.d.ts +0 -11
  51. package/lib/chain/emitter.d.ts.map +1 -1
  52. package/lib/chain/emitter.js +0 -4
  53. package/lib/chain/emitter.js.map +1 -1
  54. package/lib/chain/errors/proposerPreferences.d.ts +8 -1
  55. package/lib/chain/errors/proposerPreferences.d.ts.map +1 -1
  56. package/lib/chain/errors/proposerPreferences.js +1 -0
  57. package/lib/chain/errors/proposerPreferences.js.map +1 -1
  58. package/lib/chain/initState.d.ts.map +1 -1
  59. package/lib/chain/initState.js +6 -1
  60. package/lib/chain/initState.js.map +1 -1
  61. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  62. package/lib/chain/prepareNextSlot.js +16 -18
  63. package/lib/chain/prepareNextSlot.js.map +1 -1
  64. package/lib/chain/produceBlock/produceBlockBody.d.ts +12 -3
  65. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  66. package/lib/chain/produceBlock/produceBlockBody.js +33 -20
  67. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  68. package/lib/chain/regen/queued.d.ts.map +1 -1
  69. package/lib/chain/regen/queued.js +1 -4
  70. package/lib/chain/regen/queued.js.map +1 -1
  71. package/lib/chain/regen/regen.d.ts.map +1 -1
  72. package/lib/chain/regen/regen.js +1 -4
  73. package/lib/chain/regen/regen.js.map +1 -1
  74. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +7 -4
  75. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  76. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +42 -14
  77. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  78. package/lib/chain/seenCache/seenProposerPreferences.d.ts +8 -7
  79. package/lib/chain/seenCache/seenProposerPreferences.d.ts.map +1 -1
  80. package/lib/chain/seenCache/seenProposerPreferences.js +11 -10
  81. package/lib/chain/seenCache/seenProposerPreferences.js.map +1 -1
  82. package/lib/chain/validation/executionPayloadBid.js +11 -8
  83. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  84. package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
  85. package/lib/chain/validation/proposerPreferences.js +39 -17
  86. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  87. package/lib/network/gossip/topic.d.ts +2 -0
  88. package/lib/network/gossip/topic.d.ts.map +1 -1
  89. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  90. package/lib/network/processor/gossipHandlers.js +24 -7
  91. package/lib/network/processor/gossipHandlers.js.map +1 -1
  92. package/lib/network/processor/index.js +5 -5
  93. package/lib/network/processor/index.js.map +1 -1
  94. package/lib/node/nodejs.js +2 -2
  95. package/lib/node/nodejs.js.map +1 -1
  96. package/lib/node/notifier.js +1 -7
  97. package/lib/node/notifier.js.map +1 -1
  98. package/lib/sync/constants.d.ts +3 -1
  99. package/lib/sync/constants.d.ts.map +1 -1
  100. package/lib/sync/constants.js +3 -4
  101. package/lib/sync/constants.js.map +1 -1
  102. package/lib/sync/range/batch.d.ts +16 -0
  103. package/lib/sync/range/batch.d.ts.map +1 -1
  104. package/lib/sync/range/batch.js +97 -21
  105. package/lib/sync/range/batch.js.map +1 -1
  106. package/lib/sync/range/chain.d.ts +6 -0
  107. package/lib/sync/range/chain.d.ts.map +1 -1
  108. package/lib/sync/range/chain.js +50 -7
  109. package/lib/sync/range/chain.js.map +1 -1
  110. package/lib/sync/unknownBlock.d.ts +0 -2
  111. package/lib/sync/unknownBlock.d.ts.map +1 -1
  112. package/lib/sync/unknownBlock.js +2 -47
  113. package/lib/sync/unknownBlock.js.map +1 -1
  114. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  115. package/lib/sync/utils/downloadByRange.js +36 -21
  116. package/lib/sync/utils/downloadByRange.js.map +1 -1
  117. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  118. package/lib/sync/utils/downloadByRoot.js +10 -0
  119. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  120. package/lib/util/sszBytes.d.ts.map +1 -1
  121. package/lib/util/sszBytes.js +8 -6
  122. package/lib/util/sszBytes.js.map +1 -1
  123. package/package.json +15 -15
  124. package/src/api/impl/beacon/blocks/index.ts +13 -0
  125. package/src/api/impl/debug/index.ts +0 -1
  126. package/src/api/impl/validator/index.ts +2 -1
  127. package/src/chain/blocks/blockInput/blockInput.ts +4 -1
  128. package/src/chain/blocks/importBlock.ts +16 -49
  129. package/src/chain/blocks/importExecutionPayload.ts +3 -5
  130. package/src/chain/blocks/index.ts +20 -9
  131. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +5 -1
  132. package/src/chain/blocks/types.ts +2 -1
  133. package/src/chain/blocks/utils/chainSegment.ts +8 -0
  134. package/src/chain/blocks/verifyBlock.ts +7 -5
  135. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +6 -4
  136. package/src/chain/blocks/verifyBlocksSanityChecks.ts +16 -6
  137. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +7 -2
  138. package/src/chain/chain.ts +12 -9
  139. package/src/chain/emitter.ts +0 -11
  140. package/src/chain/errors/proposerPreferences.ts +9 -1
  141. package/src/chain/initState.ts +9 -1
  142. package/src/chain/prepareNextSlot.ts +21 -29
  143. package/src/chain/produceBlock/produceBlockBody.ts +41 -25
  144. package/src/chain/regen/queued.ts +2 -7
  145. package/src/chain/regen/regen.ts +2 -7
  146. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +55 -16
  147. package/src/chain/seenCache/seenProposerPreferences.ts +14 -11
  148. package/src/chain/validation/executionPayloadBid.ts +11 -8
  149. package/src/chain/validation/proposerPreferences.ts +37 -18
  150. package/src/network/processor/gossipHandlers.ts +30 -7
  151. package/src/network/processor/index.ts +5 -5
  152. package/src/node/nodejs.ts +2 -2
  153. package/src/node/notifier.ts +1 -8
  154. package/src/sync/constants.ts +4 -4
  155. package/src/sync/range/batch.ts +124 -24
  156. package/src/sync/range/chain.ts +57 -7
  157. package/src/sync/unknownBlock.ts +2 -50
  158. package/src/sync/utils/downloadByRange.ts +37 -21
  159. package/src/sync/utils/downloadByRoot.ts +12 -0
  160. package/src/util/sszBytes.ts +8 -6
@@ -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;
@@ -214,19 +215,19 @@ export async function produceBlockBody<T extends BlockType>(
214
215
  });
215
216
 
216
217
  // Get execution payload from EL
218
+ let parentBlockHash: Bytes32;
219
+ let parentExecutionRequests: electra.ExecutionRequests;
220
+ // Apply parent payload once here as it's reused by EL prep and voluntary exit filtering below
221
+ let stateAfterParentPayload: IBeaconStateViewBellatrix = currentState;
217
222
  const isExtendingPayload = this.forkChoice.shouldExtendPayload(toRootHex(parentBlockRoot));
218
- let parentBlockHash = isExtendingPayload
219
- ? currentState.latestExecutionPayloadBid.blockHash
220
- : currentState.latestExecutionPayloadBid.parentBlockHash;
221
- // At gloas genesis the committed bid has no prior EL block to reference
222
- // (`bid.parentBlockHash` is zero). Fall back to `bid.blockHash` (= eth1 genesis hash) so the
223
- // FCU to the EL carries a valid head. Post-genesis bids always reference a non-zero parent.
224
- if (isStatePostGloas(currentState) && byteArrayEquals(parentBlockHash, ZERO_HASH)) {
223
+ if (isExtendingPayload) {
225
224
  parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;
225
+ parentExecutionRequests = await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot);
226
+ stateAfterParentPayload = currentState.withParentPayloadApplied(parentExecutionRequests);
227
+ } else {
228
+ parentBlockHash = currentState.latestExecutionPayloadBid.parentBlockHash;
229
+ parentExecutionRequests = ssz.electra.ExecutionRequests.defaultValue();
226
230
  }
227
- const parentExecutionRequests = isExtendingPayload
228
- ? await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot)
229
- : ssz.electra.ExecutionRequests.defaultValue();
230
231
  const prepareRes = await prepareExecutionPayload(
231
232
  this,
232
233
  this.logger,
@@ -235,9 +236,8 @@ export async function produceBlockBody<T extends BlockType>(
235
236
  parentBlockHash,
236
237
  safeBlockHash,
237
238
  finalizedBlockHash ?? ZERO_HASH_HEX,
238
- currentState,
239
- feeRecipient,
240
- parentExecutionRequests
239
+ stateAfterParentPayload,
240
+ feeRecipient
241
241
  );
242
242
 
243
243
  const {prepType, payloadId} = prepareRes;
@@ -296,6 +296,14 @@ export async function produceBlockBody<T extends BlockType>(
296
296
  blockSlot - 1
297
297
  );
298
298
  gloasBody.parentExecutionRequests = parentExecutionRequests;
299
+ // Drop voluntary exits that parent_execution_requests have invalidated (e.g. a withdrawal
300
+ // request initiating an exit on the same validator). Op pool selected against the unapplied
301
+ // state, so re-validate against the post-apply state to avoid producing an invalid block.
302
+ if (isExtendingPayload && commonBlockBody.voluntaryExits.length > 0) {
303
+ gloasBody.voluntaryExits = commonBlockBody.voluntaryExits.filter((signedVoluntaryExit) =>
304
+ stateAfterParentPayload.isValidVoluntaryExit(signedVoluntaryExit, false)
305
+ );
306
+ }
299
307
  blockBody = gloasBody as AssembledBodyType<T>;
300
308
 
301
309
  // Store execution payload data required to construct execution payload envelope later
@@ -304,6 +312,7 @@ export async function produceBlockBody<T extends BlockType>(
304
312
  gloasResult.executionRequests = executionRequests;
305
313
  gloasResult.blobsBundle = blobsBundle;
306
314
  gloasResult.cells = cells;
315
+ gloasResult.parentBlockRoot = fromHex(parentBlock.blockRoot);
307
316
 
308
317
  const fetchedTime = Date.now() / 1000 - computeTimeAtSlot(this.config, blockSlot, this.genesisTime);
309
318
  this.metrics?.blockPayload.payloadFetchedTime.observe({prepType}, fetchedTime);
@@ -631,9 +640,12 @@ export async function prepareExecutionPayload(
631
640
  parentBlockHash: Bytes32,
632
641
  safeBlockHash: RootHex,
633
642
  finalizedBlockHash: RootHex,
643
+ /**
644
+ * Post-gloas, when extending a full parent, callers must apply
645
+ * parent execution payload first (see `withParentPayloadApplied`).
646
+ */
634
647
  state: IBeaconStateViewBellatrix,
635
- suggestedFeeRecipient: string,
636
- parentExecutionRequests?: electra.ExecutionRequests
648
+ suggestedFeeRecipient: string
637
649
  ): Promise<{prepType: PayloadPreparationType; payloadId: PayloadId}> {
638
650
  const timestamp = computeTimeAtSlot(chain.config, state.slot, state.genesisTime);
639
651
  const prevRandao = state.getRandaoMix(state.epoch);
@@ -670,7 +682,6 @@ export async function prepareExecutionPayload(
670
682
  parentBlockRoot,
671
683
  parentBlockHash,
672
684
  feeRecipient: suggestedFeeRecipient,
673
- parentExecutionRequests,
674
685
  });
675
686
 
676
687
  payloadId = await chain.executionEngine.notifyForkchoiceUpdate(
@@ -729,14 +740,16 @@ export function getPayloadAttributesForSSE(
729
740
  parentBlockRoot,
730
741
  parentBlockHash,
731
742
  feeRecipient,
732
- parentExecutionRequests,
733
743
  }: {
744
+ /**
745
+ * Post-gloas, when extending a full parent, callers must apply
746
+ * parent execution payload first (see `withParentPayloadApplied`).
747
+ */
734
748
  prepareState: IBeaconStateViewBellatrix;
735
749
  prepareSlot: Slot;
736
750
  parentBlockRoot: Root;
737
751
  parentBlockHash: Bytes32;
738
752
  feeRecipient: string;
739
- parentExecutionRequests?: electra.ExecutionRequests;
740
753
  }
741
754
  ): SSEPayloadAttributes {
742
755
  const payloadAttributes = preparePayloadAttributes(fork, chain, {
@@ -745,7 +758,6 @@ export function getPayloadAttributesForSSE(
745
758
  parentBlockRoot,
746
759
  parentBlockHash,
747
760
  feeRecipient,
748
- parentExecutionRequests,
749
761
  });
750
762
 
751
763
  let parentBlockNumber: number;
@@ -784,14 +796,16 @@ function preparePayloadAttributes(
784
796
  parentBlockRoot,
785
797
  parentBlockHash,
786
798
  feeRecipient,
787
- parentExecutionRequests,
788
799
  }: {
800
+ /**
801
+ * Post-gloas, when extending a full parent, callers must apply
802
+ * parent execution payload first (see `withParentPayloadApplied`).
803
+ */
789
804
  prepareState: IBeaconStateViewBellatrix;
790
805
  prepareSlot: Slot;
791
806
  parentBlockRoot: Root;
792
807
  parentBlockHash: Bytes32;
793
808
  feeRecipient: string;
794
- parentExecutionRequests?: electra.ExecutionRequests;
795
809
  }
796
810
  ): SSEPayloadAttributes["payloadAttributes"] {
797
811
  const timestamp = computeTimeAtSlot(chain.config, prepareSlot, prepareState.genesisTime);
@@ -810,11 +824,13 @@ function preparePayloadAttributes(
810
824
  if (isStatePostGloas(prepareState)) {
811
825
  const isExtendingPayload = byteArrayEquals(parentBlockHash, prepareState.latestExecutionPayloadBid.blockHash);
812
826
  if (isExtendingPayload) {
813
- if (parentExecutionRequests === undefined) {
814
- throw new Error("parentExecutionRequests required when extending full parent");
827
+ // applyParentExecutionPayload sets latestBlockHash = parentBid.blockHash, so a mismatch
828
+ // here means the caller did not apply parent payload to prepareState
829
+ if (!byteArrayEquals(prepareState.latestBlockHash, prepareState.latestExecutionPayloadBid.blockHash)) {
830
+ throw new Error("Expected state with parent execution payload applied for withdrawals");
815
831
  }
816
832
  (payloadAttributes as capella.SSEPayloadAttributes["payloadAttributes"]).withdrawals =
817
- prepareState.getExpectedWithdrawalsForFullParent(parentExecutionRequests);
833
+ prepareState.getExpectedWithdrawals().expectedWithdrawals;
818
834
  } else {
819
835
  // When the parent block is empty, state.payloadExpectedWithdrawals holds a batch
820
836
  // already deducted from CL balances but never credited on the EL (the envelope
@@ -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
@@ -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;
@@ -595,6 +607,24 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
595
607
  // Returns the delay between the start of `block.slot` and `current time`
596
608
  const delaySec = chain.clock.secFromSlot(slot);
597
609
  metrics?.gossipBlock.elapsedTimeTillProcessed.observe(delaySec);
610
+
611
+ if (isForkPostGloas(blockInput.forkName)) {
612
+ const payloadInput = chain.seenPayloadEnvelopeInputCache.get(blockInput.blockRootHex);
613
+ // This payloadInput should have been created just after gossip validation
614
+ if (!payloadInput) {
615
+ throw Error(
616
+ `PayloadEnvelopeInput not seeded for block ${blockInput.blockRootHex} during gossip processing`
617
+ );
618
+ }
619
+
620
+ // Immediately attempt fetch of data columns from execution engine as the bid contains kzg commitments
621
+ // which is all the information we need so there is no reason to delay until execution payload arrives
622
+ // TODO GLOAS: If we want EL retries after this initial attempt, add an explicit retry policy here
623
+ // (for example later in the slot). Do not couple retries to incoming gossip columns.
624
+ // Columns fetched here feed payloadInput.addColumn, which resolves waitForAllData for any
625
+ // in-flight importExecutionPayload. No processExecutionPayload trigger needed from this path.
626
+ chain.getBlobsTracker.triggerGetBlobs(payloadInput);
627
+ }
598
628
  })
599
629
  .catch((e) => {
600
630
  // Adjust verbosity based on error type
@@ -1072,13 +1102,6 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
1072
1102
  const {beaconBlockRoot} = signedEnvelope.message;
1073
1103
  const slot = signedEnvelope.message.payload.slotNumber;
1074
1104
  logger.debug("Gossip envelope has error", {slot, root: toRootHex(beaconBlockRoot), code: e.type.code});
1075
- if (e.type.code === ExecutionPayloadEnvelopeErrorCode.BLOCK_ROOT_UNKNOWN) {
1076
- chain.emitter.emit(ChainEvent.envelopeUnknownBlock, {
1077
- envelope: signedEnvelope,
1078
- peer: peerIdStr,
1079
- source: BlockInputSource.gossip,
1080
- });
1081
- }
1082
1105
 
1083
1106
  if (e.action === GossipAction.REJECT) {
1084
1107
  chain.persistInvalidSszValue(
@@ -76,6 +76,7 @@ type WorkOpts = {
76
76
  */
77
77
  const executeGossipWorkOrderObj: Record<GossipType, WorkOpts> = {
78
78
  [GossipType.beacon_block]: {bypassQueue: true},
79
+ [GossipType.execution_payload]: {bypassQueue: true},
79
80
  [GossipType.blob_sidecar]: {bypassQueue: true},
80
81
  [GossipType.data_column_sidecar]: {bypassQueue: true},
81
82
  [GossipType.beacon_aggregate_and_proof]: {},
@@ -88,7 +89,6 @@ const executeGossipWorkOrderObj: Record<GossipType, WorkOpts> = {
88
89
  [GossipType.sync_committee]: {},
89
90
  [GossipType.light_client_finality_update]: {},
90
91
  [GossipType.light_client_optimistic_update]: {},
91
- [GossipType.execution_payload]: {bypassQueue: true},
92
92
  [GossipType.payload_attestation_message]: {},
93
93
  [GossipType.execution_payload_bid]: {},
94
94
  [GossipType.proposer_preferences]: {},
@@ -444,8 +444,7 @@ export class NetworkProcessor {
444
444
  }
445
445
  case GossipType.execution_payload: {
446
446
  // extractBlockSlotRootFn does not return a root for this topic.
447
- // Extract beacon_block_root directly and proactively trigger block sync if missing.
448
- // Do NOT await the block — the handler runs immediately; BlockInputSync handles recovery.
447
+ // Extract beacon_block_root directly
449
448
  const blockRoot = getBeaconBlockRootFromExecutionPayloadEnvelopeSerialized(message.msg.data);
450
449
  if (blockRoot && !this.chain.forkChoice.hasBlockHexUnsafe(blockRoot)) {
451
450
  this.searchUnknownBlock(
@@ -453,9 +452,10 @@ export class NetworkProcessor {
453
452
  BlockInputSource.network_processor,
454
453
  message.propagationSource.toString()
455
454
  );
455
+ // We always want to await the block
456
+ // This allows us to properly forward the payload envelope
457
+ preprocessResult = {action: PreprocessAction.AwaitBlock, root: blockRoot};
456
458
  }
457
- // do not await the block, we want UnknownBlockSync to handle it.
458
- preprocessResult = {action: PreprocessAction.PushToQueue};
459
459
  break;
460
460
  }
461
461
  case GossipType.execution_payload_bid: {
@@ -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) {