@lodestar/beacon-node 1.47.0 → 1.48.0-dev.0dbea0de1b

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 (96) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +4 -0
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/validator/index.d.ts.map +1 -1
  5. package/lib/api/impl/validator/index.js +5 -0
  6. package/lib/api/impl/validator/index.js.map +1 -1
  7. package/lib/chain/blocks/index.js +7 -7
  8. package/lib/chain/blocks/index.js.map +1 -1
  9. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  10. package/lib/chain/blocks/verifyBlock.js +5 -2
  11. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  12. package/lib/chain/chain.d.ts +1 -1
  13. package/lib/chain/chain.d.ts.map +1 -1
  14. package/lib/chain/chain.js +2 -1
  15. package/lib/chain/chain.js.map +1 -1
  16. package/lib/chain/errors/executionPayloadBid.d.ts +5 -0
  17. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  18. package/lib/chain/errors/executionPayloadBid.js +1 -0
  19. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  20. package/lib/chain/interface.d.ts +2 -2
  21. package/lib/chain/interface.d.ts.map +1 -1
  22. package/lib/chain/lightClient/index.d.ts +3 -3
  23. package/lib/chain/lightClient/index.d.ts.map +1 -1
  24. package/lib/chain/lightClient/index.js +21 -23
  25. package/lib/chain/lightClient/index.js.map +1 -1
  26. package/lib/chain/lightClient/proofs.d.ts +2 -1
  27. package/lib/chain/lightClient/proofs.d.ts.map +1 -1
  28. package/lib/chain/lightClient/proofs.js +5 -1
  29. package/lib/chain/lightClient/proofs.js.map +1 -1
  30. package/lib/chain/prepareNextSlot.d.ts +5 -0
  31. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  32. package/lib/chain/prepareNextSlot.js +24 -1
  33. package/lib/chain/prepareNextSlot.js.map +1 -1
  34. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  35. package/lib/chain/produceBlock/computeNewStateRoot.js +3 -25
  36. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  37. package/lib/chain/regen/interface.d.ts +1 -0
  38. package/lib/chain/regen/interface.d.ts.map +1 -1
  39. package/lib/chain/regen/interface.js +1 -0
  40. package/lib/chain/regen/interface.js.map +1 -1
  41. package/lib/chain/validation/block.d.ts.map +1 -1
  42. package/lib/chain/validation/block.js +40 -10
  43. package/lib/chain/validation/block.js.map +1 -1
  44. package/lib/chain/validation/executionPayloadBid.d.ts +15 -3
  45. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  46. package/lib/chain/validation/executionPayloadBid.js +183 -28
  47. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  48. package/lib/execution/builder/apiClient.d.ts +6 -0
  49. package/lib/execution/builder/apiClient.d.ts.map +1 -1
  50. package/lib/execution/builder/apiClient.js +19 -1
  51. package/lib/execution/builder/apiClient.js.map +1 -1
  52. package/lib/execution/builder/validateBid.d.ts +1 -0
  53. package/lib/execution/builder/validateBid.d.ts.map +1 -1
  54. package/lib/execution/builder/validateBid.js +14 -6
  55. package/lib/execution/builder/validateBid.js.map +1 -1
  56. package/lib/metrics/metrics/lodestar.d.ts +10 -1
  57. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  58. package/lib/metrics/metrics/lodestar.js +19 -3
  59. package/lib/metrics/metrics/lodestar.js.map +1 -1
  60. package/lib/network/network.d.ts.map +1 -1
  61. package/lib/network/network.js +7 -6
  62. package/lib/network/network.js.map +1 -1
  63. package/lib/network/processor/gossipQueues/indexed.d.ts.map +1 -1
  64. package/lib/network/processor/gossipQueues/indexed.js +0 -1
  65. package/lib/network/processor/gossipQueues/indexed.js.map +1 -1
  66. package/lib/network/processor/index.d.ts.map +1 -1
  67. package/lib/network/processor/index.js +16 -8
  68. package/lib/network/processor/index.js.map +1 -1
  69. package/lib/sync/range/chain.d.ts.map +1 -1
  70. package/lib/sync/range/chain.js +9 -2
  71. package/lib/sync/range/chain.js.map +1 -1
  72. package/lib/sync/range/range.js +1 -1
  73. package/lib/sync/range/range.js.map +1 -1
  74. package/package.json +15 -15
  75. package/src/api/impl/beacon/blocks/index.ts +4 -0
  76. package/src/api/impl/validator/index.ts +5 -0
  77. package/src/chain/blocks/index.ts +7 -7
  78. package/src/chain/blocks/verifyBlock.ts +5 -2
  79. package/src/chain/chain.ts +2 -1
  80. package/src/chain/errors/executionPayloadBid.ts +6 -0
  81. package/src/chain/interface.ts +2 -2
  82. package/src/chain/lightClient/index.ts +32 -36
  83. package/src/chain/lightClient/proofs.ts +10 -0
  84. package/src/chain/prepareNextSlot.ts +26 -1
  85. package/src/chain/produceBlock/computeNewStateRoot.ts +3 -38
  86. package/src/chain/regen/interface.ts +1 -0
  87. package/src/chain/validation/block.ts +43 -10
  88. package/src/chain/validation/executionPayloadBid.ts +212 -32
  89. package/src/execution/builder/apiClient.ts +21 -1
  90. package/src/execution/builder/validateBid.ts +22 -7
  91. package/src/metrics/metrics/lodestar.ts +21 -4
  92. package/src/network/network.ts +9 -6
  93. package/src/network/processor/gossipQueues/indexed.ts +0 -1
  94. package/src/network/processor/index.ts +25 -11
  95. package/src/sync/range/chain.ts +9 -2
  96. package/src/sync/range/range.ts +1 -1
@@ -1327,9 +1327,10 @@ export class BeaconChain implements IBeaconChain {
1327
1327
  }
1328
1328
  }
1329
1329
 
1330
- predictProposerHead(slot: Slot): ProtoBlock {
1330
+ predictProposerHead(): ProtoBlock {
1331
1331
  this.metrics?.forkChoice.requests.inc();
1332
1332
  const timer = this.metrics?.forkChoice.findHead.startTimer({caller: FindHeadFnName.predictProposerHead});
1333
+ const slot = this.clock.currentSlot;
1333
1334
  const secFromSlot = this.clock.secFromSlot(slot);
1334
1335
 
1335
1336
  try {
@@ -9,6 +9,7 @@ export enum ExecutionPayloadBidErrorCode {
9
9
  BID_ALREADY_KNOWN = "EXECUTION_PAYLOAD_BID_ERROR_BID_ALREADY_KNOWN",
10
10
  BID_TOO_LOW = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_LOW",
11
11
  BID_TOO_HIGH = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_HIGH",
12
+ BUILDER_MAY_EXIT = "EXECUTION_PAYLOAD_BID_ERROR_BUILDER_MAY_EXIT",
12
13
  TOO_MANY_KZG_COMMITMENTS = "EXECUTION_PAYLOAD_BID_ERROR_TOO_MANY_KZG_COMMITMENTS",
13
14
  UNKNOWN_BLOCK_ROOT = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_BLOCK_ROOT",
14
15
  UNKNOWN_PARENT_BLOCK_HASH = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_PARENT_BLOCK_HASH",
@@ -50,6 +51,11 @@ export type ExecutionPayloadBidErrorType =
50
51
  }
51
52
  | {code: ExecutionPayloadBidErrorCode.BID_TOO_LOW; bidValue: number; currentHighestBid: number}
52
53
  | {code: ExecutionPayloadBidErrorCode.BID_TOO_HIGH; bidValue: number; builderBalance: number}
54
+ | {
55
+ code: ExecutionPayloadBidErrorCode.BUILDER_MAY_EXIT;
56
+ builderIndex: BuilderIndex;
57
+ parentBlockRoot: RootHex;
58
+ }
53
59
  | {
54
60
  code: ExecutionPayloadBidErrorCode.TOO_MANY_KZG_COMMITMENTS;
55
61
  blobKzgCommitmentsLen: number;
@@ -274,8 +274,8 @@ export interface IBeaconChain {
274
274
 
275
275
  recomputeForkChoiceHead(caller: ForkchoiceCaller): ProtoBlock;
276
276
 
277
- /** When proposerBoostReorg is enabled, this is called at slot n-1 to predict the head block to build on if we are proposing at slot n */
278
- predictProposerHead(slot: Slot): ProtoBlock;
277
+ /** When proposerBoostReorg is enabled, predict (as of the current slot) the head block a proposer would build on next slot */
278
+ predictProposerHead(): ProtoBlock;
279
279
 
280
280
  /** When proposerBoostReorg is enabled and we are proposing a block, this is called to determine which head block to build on */
281
281
  getProposerHead(slot: Slot): ProtoBlock;
@@ -5,6 +5,7 @@ import {
5
5
  ForkName,
6
6
  ForkPostAltair,
7
7
  ForkPostBellatrix,
8
+ ForkPostGloas,
8
9
  ForkPreGloas,
9
10
  ForkSeq,
10
11
  MIN_SYNC_COMMITTEE_PARTICIPANTS,
@@ -40,7 +41,6 @@ import {
40
41
  Slot,
41
42
  SyncPeriod,
42
43
  altair,
43
- electra,
44
44
  phase0,
45
45
  ssz,
46
46
  } from "@lodestar/types";
@@ -52,7 +52,12 @@ import {Metrics} from "../../metrics/index.js";
52
52
  import {IClock} from "../../util/clock.js";
53
53
  import {ChainEventEmitter} from "../emitter.js";
54
54
  import {LightClientServerError, LightClientServerErrorCode} from "../errors/lightClientError.js";
55
- import {getBlockBodyExecutionHeaderProof, getCurrentSyncCommitteeBranch, getNextSyncCommitteeBranch} from "./proofs.js";
55
+ import {
56
+ getBlockBodyExecutionBlockHashProof,
57
+ getBlockBodyExecutionHeaderProof,
58
+ getCurrentSyncCommitteeBranch,
59
+ getNextSyncCommitteeBranch,
60
+ } from "./proofs.js";
56
61
 
57
62
  export type LightClientServerOpts = {
58
63
  disableLightClientServerOnImportBlockHead?: boolean;
@@ -61,6 +66,7 @@ export type LightClientServerOpts = {
61
66
 
62
67
  type DependentRootHex = RootHex;
63
68
  type BlockRooHex = RootHex;
69
+ type LightClientZeroFinality = Pick<LightClientUpdate, "finalityBranch" | "finalizedHeader">;
64
70
 
65
71
  export type SyncAttestedData = {
66
72
  attestedHeader: LightClientHeader;
@@ -199,6 +205,7 @@ export class LightClientServer {
199
205
  private readonly clock: IClock;
200
206
  private readonly signal: AbortSignal;
201
207
  private readonly knownSyncCommittee = new MapDef<SyncPeriod, Set<DependentRootHex>>(() => new Set());
208
+ private readonly zeroFinalityByFork = new Map<ForkName, LightClientZeroFinality>();
202
209
  private storedCurrentSyncCommittee = false;
203
210
 
204
211
  /**
@@ -208,10 +215,6 @@ export class LightClientServer {
208
215
  private checkpointHeaders = new Map<BlockRooHex, LightClientHeader>();
209
216
  private latestHeadUpdate: LightClientOptimisticUpdate | null = null;
210
217
 
211
- private readonly zero: Pick<
212
- altair.LightClientUpdate | electra.LightClientUpdate,
213
- "finalityBranch" | "finalizedHeader"
214
- >;
215
218
  private finalized: LightClientFinalityUpdate | null = null;
216
219
 
217
220
  constructor(
@@ -227,14 +230,6 @@ export class LightClientServer {
227
230
  this.logger = logger;
228
231
  this.signal = signal;
229
232
 
230
- this.zero = {
231
- // Assign the highest pre-Gloas light-client header because post-Gloas light-client updates are skipped for now.
232
- finalizedHeader: ssz.electra.LightClientHeader.defaultValue(),
233
- // Electra finalityBranch has fixed length of 5 whereas altair has 4. The fifth element will be ignored
234
- // when serializing as altair LightClientUpdate
235
- finalityBranch: ssz.electra.LightClientUpdate.fields.finalityBranch.defaultValue(),
236
- };
237
-
238
233
  if (metrics) {
239
234
  metrics.lightclientServer.highestSlot.addCollect(() => {
240
235
  if (this.latestHeadUpdate) {
@@ -270,14 +265,6 @@ export class LightClientServer {
270
265
  return;
271
266
  }
272
267
 
273
- // TODO GLOAS: Light client updates for gloas are not yet updated in the spec.
274
- // The block body no longer contains execution payload, so `blockToLightClientHeader`
275
- // cannot construct a header from a gloas block. Skip all light client processing
276
- // for post-gloas blocks, revisit once there is a spec for it.
277
- if (this.config.getForkSeq(block.slot) >= ForkSeq.gloas) {
278
- return;
279
- }
280
-
281
268
  // What is the syncAggregate signing?
282
269
  // From the state-transition
283
270
  // ```
@@ -695,9 +682,16 @@ export class LightClientServer {
695
682
  }
696
683
  } else {
697
684
  isFinalized = false;
698
- finalityBranch = this.zero.finalityBranch;
699
- // No need to upgrade finalizedHeader because its anyway set to zero of highest fork
700
- finalizedHeader = this.zero.finalizedHeader;
685
+ let zeroFinality = this.zeroFinalityByFork.get(attestedFork);
686
+ if (!zeroFinality) {
687
+ const {finalityBranch, finalizedHeader} = this.config
688
+ .getPostAltairForkTypes(attestedHeader.beacon.slot)
689
+ .LightClientUpdate.defaultValue();
690
+ zeroFinality = {finalityBranch, finalizedHeader};
691
+ this.zeroFinalityByFork.set(attestedFork, zeroFinality);
692
+ }
693
+ finalityBranch = zeroFinality.finalityBranch;
694
+ finalizedHeader = zeroFinality.finalizedHeader;
701
695
  }
702
696
 
703
697
  const newUpdate = {
@@ -769,22 +763,24 @@ export function sumBits(bits: BitArray): number {
769
763
  return bits.getTrueBitIndexes().length;
770
764
  }
771
765
 
772
- // TODO GLOAS: Pending light-client spec but this function probably won't be used
773
- // in Gloas. So we can assume any types here are pre-gloas
774
- export function blockToLightClientHeader(
775
- fork: ForkName,
776
- block: BeaconBlock<ForkPostAltair & ForkPreGloas>
777
- ): LightClientHeader {
778
- const blockSlot = block.slot;
766
+ export function blockToLightClientHeader(fork: ForkName, block: BeaconBlock<ForkPostAltair>): LightClientHeader {
779
767
  const beacon: phase0.BeaconBlockHeader = {
780
- slot: blockSlot,
768
+ slot: block.slot,
781
769
  proposerIndex: block.proposerIndex,
782
770
  parentRoot: block.parentRoot,
783
771
  stateRoot: block.stateRoot,
784
- bodyRoot: (ssz[fork].BeaconBlockBody as SSZTypesFor<ForkPostAltair & ForkPreGloas, "BeaconBlockBody">).hashTreeRoot(
785
- block.body
786
- ),
772
+ bodyRoot: (ssz[fork].BeaconBlockBody as SSZTypesFor<ForkPostAltair, "BeaconBlockBody">).hashTreeRoot(block.body),
787
773
  };
774
+
775
+ if (isForkPostGloas(fork)) {
776
+ const blockBody = block.body as BeaconBlockBody<ForkPostGloas>;
777
+ return {
778
+ beacon,
779
+ executionBlockHash: blockBody.signedExecutionPayloadBid.message.parentBlockHash,
780
+ executionBranch: getBlockBodyExecutionBlockHashProof(fork, blockBody),
781
+ };
782
+ }
783
+
788
784
  if (ForkSeq[fork] >= ForkSeq.capella) {
789
785
  const blockBody = block.body as BeaconBlockBody<ForkPostBellatrix & ForkPreGloas>;
790
786
  const execution = executionPayloadToPayloadHeader(ForkSeq[fork], blockBody.executionPayload);
@@ -2,11 +2,13 @@ import {Tree} from "@chainsafe/persistent-merkle-tree";
2
2
  import {
3
3
  BLOCK_BODY_EXECUTION_PAYLOAD_GINDEX,
4
4
  CURRENT_SYNC_COMMITTEE_GINDEX_GLOAS,
5
+ EXECUTION_BLOCK_HASH_GINDEX_GLOAS,
5
6
  FINALIZED_ROOT_GINDEX,
6
7
  FINALIZED_ROOT_GINDEX_ELECTRA,
7
8
  FINALIZED_ROOT_GINDEX_GLOAS,
8
9
  ForkName,
9
10
  ForkPostBellatrix,
11
+ ForkPostGloas,
10
12
  NEXT_SYNC_COMMITTEE_GINDEX_GLOAS,
11
13
  isForkPostElectra,
12
14
  isForkPostGloas,
@@ -116,3 +118,11 @@ export function getBlockBodyExecutionHeaderProof(
116
118
  const bodyView = (ssz[fork].BeaconBlockBody as SSZTypesFor<ForkPostBellatrix, "BeaconBlockBody">).toView(body);
117
119
  return new Tree(bodyView.node).getSingleProof(BigInt(BLOCK_BODY_EXECUTION_PAYLOAD_GINDEX));
118
120
  }
121
+
122
+ export function getBlockBodyExecutionBlockHashProof(
123
+ fork: ForkPostGloas,
124
+ body: BeaconBlockBody<ForkPostGloas>
125
+ ): Uint8Array[] {
126
+ const bodyView = (ssz[fork].BeaconBlockBody as SSZTypesFor<ForkPostGloas, "BeaconBlockBody">).toView(body);
127
+ return new Tree(bodyView.node).getSingleProof(BigInt(EXECUTION_BLOCK_HASH_GINDEX_GLOAS));
128
+ }
@@ -45,6 +45,14 @@ const PREPARE_EPOCH_LIMIT = 1;
45
45
  * Expressed in bps so it scales with slot duration (mainnet vs minimal/devnet). */
46
46
  const BUILDER_PREVERIFY_LIMIT_BPS = 2000;
47
47
 
48
+ /**
49
+ * How far before the next slot builder connections are pre-established, see `checkBuilderStatusBeforeSlot`.
50
+ *
51
+ * 1667 = 16.67% of slot (2s on mainnet). Must stay under the few seconds an idle connection survives,
52
+ * while leaving room for a round trip to a distant builder to complete before the slot begins.
53
+ */
54
+ const BUILDER_STATUS_CHECK_BEFORE_SLOT_BPS = 1667;
55
+
48
56
  /**
49
57
  * At Bellatrix, if we are responsible for proposing in next slot, we want to prepare payload
50
58
  * 4s before the start of next slot at PREPARE_NEXT_SLOT_BPS of the current slot.
@@ -157,7 +165,7 @@ export class PrepareNextSlotScheduler {
157
165
  // last-block-of-epoch and build slot 0 on the strong parent (epoch-boundary reorg),
158
166
  // so we should dial the strong parent through the boundary instead of the weak head.
159
167
  if (feeRecipient || isEpochTransition) {
160
- const proposerHead = this.chain.predictProposerHead(clockSlot);
168
+ const proposerHead = this.chain.predictProposerHead();
161
169
  const {slot: proposerHeadSlot, blockRoot: proposerHeadRoot} = proposerHead;
162
170
 
163
171
  // If we predict a reorg, we build the epoch transition on the proposer head (parent) instead
@@ -185,6 +193,7 @@ export class PrepareNextSlotScheduler {
185
193
  if (feeRecipient) {
186
194
  if (isForkPostGloas(fork)) {
187
195
  this.chain.builderCircuitBreaker.update(clockSlot, updatedHead);
196
+ this.checkBuilderStatusBeforeSlot(prepareSlot);
188
197
  } else {
189
198
  // Update the builder status, if enabled shoot an api call to check status
190
199
  this.chain.updateBuilderStatus(clockSlot);
@@ -390,6 +399,22 @@ export class PrepareNextSlotScheduler {
390
399
  }
391
400
  };
392
401
 
402
+ /**
403
+ * Pre-establish the builder connections so the handshake lands outside the bid deadline. Scheduled
404
+ * later in the slot, connecting at PREPARE_NEXT_SLOT_BPS would go cold before bids are requested.
405
+ */
406
+ private checkBuilderStatusBeforeSlot(prepareSlot: Slot): void {
407
+ const msBeforeSlot = this.config.getSlotComponentDurationMs(BUILDER_STATUS_CHECK_BEFORE_SLOT_BPS);
408
+ const msUntilCheck = -this.chain.clock.msFromSlot(prepareSlot) - msBeforeSlot;
409
+ sleep(Math.max(0, msUntilCheck), this.signal)
410
+ .then(() => this.chain.builderApiClient.checkStatus())
411
+ .catch((e) => {
412
+ if (!isErrorAborted(e)) {
413
+ this.logger.debug("Failed to check builder status", {prepareSlot}, e as Error);
414
+ }
415
+ });
416
+ }
417
+
393
418
  computeStateHashTreeRoot(state: IBeaconStateView, isEpochTransition: boolean): void {
394
419
  // cache HashObjects for faster hashTreeRoot() later, especially for computeNewStateRoot() if we need to produce a block at slot 0 of epoch
395
420
  // see https://github.com/ChainSafe/lodestar/issues/6194
@@ -1,11 +1,5 @@
1
- import {
2
- DataAvailabilityStatus,
3
- ExecutionPayloadStatus,
4
- IBeaconStateView,
5
- StateHashTreeRootSource,
6
- } from "@lodestar/state-transition";
1
+ import {EMPTY_SIGNATURE, IBeaconStateView} from "@lodestar/state-transition";
7
2
  import {BeaconBlock, BlindedBeaconBlock, Gwei, Root} from "@lodestar/types";
8
- import {ZERO_HASH} from "../../constants/index.js";
9
3
  import {Metrics} from "../../metrics/index.js";
10
4
 
11
5
  /**
@@ -19,35 +13,6 @@ export function computeNewStateRoot(
19
13
  block: BeaconBlock | BlindedBeaconBlock
20
14
  ): {newStateRoot: Root; proposerReward: Gwei; postState: IBeaconStateView} {
21
15
  // Set signature to zero to re-use stateTransition() function which requires the SignedBeaconBlock type
22
- const blockEmptySig = {message: block, signature: ZERO_HASH};
23
-
24
- const postState = state.stateTransition(
25
- blockEmptySig,
26
- {
27
- // ExecutionPayloadStatus.valid: Assume payload valid, it has been produced by a trusted EL
28
- executionPayloadStatus: ExecutionPayloadStatus.valid,
29
- // DataAvailabilityStatus.available: Assume the blobs to be available, have just been produced by trusted EL
30
- dataAvailabilityStatus: DataAvailabilityStatus.Available,
31
- // verifyStateRoot: false | the root in the block is zero-ed, it's being computed here
32
- verifyStateRoot: false,
33
- // verifyProposer: false | as the block signature is zero-ed
34
- verifyProposer: false,
35
- // verifySignatures: false | since the data to assemble the block is trusted
36
- verifySignatures: false,
37
- // Preserve cache in source state, since the resulting state is not added to the state cache
38
- dontTransferCache: true,
39
- },
40
- {metrics}
41
- );
42
-
43
- const {attestations, syncAggregate, slashing} = postState.proposerRewards;
44
- const proposerReward = BigInt(attestations + syncAggregate + slashing);
45
-
46
- const hashTreeRootTimer = metrics?.stateHashTreeRootTime.startTimer({
47
- source: StateHashTreeRootSource.computeNewStateRoot,
48
- });
49
- const newStateRoot = postState.hashTreeRoot();
50
- hashTreeRootTimer?.();
51
-
52
- return {newStateRoot, proposerReward, postState};
16
+ const signedBlock = {message: block, signature: EMPTY_SIGNATURE};
17
+ return state.computeNewStateRoot({block: signedBlock}, {metrics});
53
18
  }
@@ -24,6 +24,7 @@ export enum RegenCaller {
24
24
  validateApiVoluntaryExit = "validateApiVoluntaryExit",
25
25
  publishDeferredVoluntaryExits = "publishDeferredVoluntaryExits",
26
26
  validateGossipExecutionPayloadBid = "validateGossipExecutionPayloadBid",
27
+ validateApiExecutionPayloadBid = "validateApiExecutionPayloadBid",
27
28
  validateGossipPayloadAttestationMessage = "validateGossipPayloadAttestationMessage",
28
29
  validateGossipProposerPreferences = "validateGossipProposerPreferences",
29
30
  onForkChoiceFinalized = "onForkChoiceFinalized",
@@ -12,6 +12,7 @@ import {
12
12
  MAX_PROPOSER_SLASHINGS,
13
13
  MAX_VOLUNTARY_EXITS,
14
14
  MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD,
15
+ MIN_SEED_LOOKAHEAD,
15
16
  isForkPostBellatrix,
16
17
  isForkPostDeneb,
17
18
  isForkPostGloas,
@@ -249,26 +250,58 @@ export async function validateGossipBlock(
249
250
  // This requires execution engine integration to verify the parent block hash
250
251
  }
251
252
 
252
- // use getPreState to reload state if needed. It also checks for whether the current finalized checkpoint is an ancestor of the block.
253
- // As a result, we throw an IGNORE (whereas the spec says we should REJECT for this scenario).
253
+ // For gossip forwarding we only need the state to check the block's proposer index.
254
+ // If the state cannot be regenerated we throw an IGNORE (whereas the spec says we should REJECT for the
255
+ // finalized-ancestor scenario, which is already guarded by the parentBlock lookup above).
254
256
  // this is something we should change this in the future to make the code airtight to the spec.
255
257
  // [IGNORE] The block's parent (defined by block.parent_root) has been seen (via both gossip and non-gossip sources) (a client MAY queue blocks for processing once the parent block is retrieved).
256
258
  // [REJECT] The block's parent (defined by block.parent_root) passes validation.
257
- const blockState = await chain.regen
258
- .getPreState(block, {dontTransferCache: true}, RegenCaller.validateGossipBlock)
259
- .catch(() => {
260
- throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.PARENT_BLOCK_UNKNOWN, parentRoot});
259
+ const canUseParentState = blockEpoch - computeEpochAtSlot(parentBlock.slot) <= MIN_SEED_LOOKAHEAD;
260
+
261
+ const getValidationState = async () => {
262
+ const getPreState = () =>
263
+ chain.regen.getPreState(block, {dontTransferCache: true}, RegenCaller.validateGossipBlock);
264
+ if (canUseParentState) {
265
+ try {
266
+ const parentState = await chain.regen.getState(parentBlock.stateRoot, RegenCaller.validateGossipBlock);
267
+ chain.metrics?.gossipBlock.preStateSource.inc({source: "parentState"});
268
+ return parentState;
269
+ } catch {
270
+ // if parent state is not in memory, we fall back to disk reload / dial-forward
271
+ chain.metrics?.gossipBlock.preStateSource.inc({source: "fallbackPreState"});
272
+ chain.logger.debug("Parent state not in memory, falling back to getPreState for gossip block validation", {
273
+ slot: blockSlot,
274
+ root: blockRoot,
275
+ parentSlot: parentBlock.slot,
276
+ parentRoot,
277
+ });
278
+ return getPreState();
279
+ }
280
+ }
281
+ // parent is >1 epoch behind (deep skip) → beyond proposer-lookahead range, must dial forward
282
+ chain.metrics?.gossipBlock.preStateSource.inc({source: "preState"});
283
+ chain.logger.debug("Cannot use parent state for gossip block validation, dialing forward via getPreState", {
284
+ slot: blockSlot,
285
+ root: blockRoot,
286
+ parentSlot: parentBlock.slot,
287
+ parentRoot,
261
288
  });
289
+ return getPreState();
290
+ };
291
+
292
+ const state = await getValidationState().catch(() => {
293
+ throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.PARENT_BLOCK_UNKNOWN, parentRoot});
294
+ });
262
295
 
263
296
  // in forky condition, make sure to populate ShufflingCache with regened state
264
- chain.shufflingCache.processState(blockState);
297
+ chain.shufflingCache.processState(state);
265
298
 
266
299
  // [REJECT] The block's execution payload timestamp is correct with respect to the slot
267
300
  // -- i.e. execution_payload.timestamp == compute_timestamp_at_slot(state, block.slot).
268
301
  if (isForkPostBellatrix(fork) && !isForkPostGloas(fork)) {
269
302
  if (!isExecutionBlockBodyType(block.body)) throw Error("Not execution block body type");
270
303
  const executionPayload = block.body.executionPayload;
271
- if (isStatePostBellatrix(blockState) && blockState.isExecutionStateType && blockState.isExecutionEnabled(block)) {
304
+ if (isStatePostBellatrix(state) && state.isExecutionStateType && state.isExecutionEnabled(block)) {
272
305
  const expectedTimestamp = computeTimeAtSlot(config, blockSlot, chain.genesisTime);
273
306
  if (executionPayload.timestamp !== computeTimeAtSlot(config, blockSlot, chain.genesisTime)) {
274
307
  throw new BlockGossipError(GossipAction.REJECT, {
@@ -281,7 +314,7 @@ export async function validateGossipBlock(
281
314
  }
282
315
 
283
316
  // [REJECT] The proposer index is a valid validator index
284
- if (proposerIndex >= blockState.validatorCount) {
317
+ if (proposerIndex >= state.validatorCount) {
285
318
  throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.UNKNOWN_PROPOSER, proposerIndex});
286
319
  }
287
320
 
@@ -293,7 +326,7 @@ export async function validateGossipBlock(
293
326
  // shuffling (defined by parent_root/slot). If the proposer_index cannot immediately be verified against the expected
294
327
  // shuffling, the block MAY be queued for later processing while proposers for the block's branch are calculated --
295
328
  // in such a case do not REJECT, instead IGNORE this message.
296
- if (blockState.getBeaconProposer(blockSlot) !== proposerIndex) {
329
+ if (state.getBeaconProposer(blockSlot) !== proposerIndex) {
297
330
  throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.INCORRECT_PROPOSER, proposerIndex});
298
331
  }
299
332