@lodestar/beacon-node 1.50.0-dev.2e668c516f → 1.50.0-dev.335476095e

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 (184) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +6 -1
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/index.js +13 -0
  6. package/lib/api/impl/beacon/index.js.map +1 -1
  7. package/lib/api/impl/validator/index.d.ts +1 -0
  8. package/lib/api/impl/validator/index.d.ts.map +1 -1
  9. package/lib/api/impl/validator/index.js +17 -1
  10. package/lib/api/impl/validator/index.js.map +1 -1
  11. package/lib/chain/archiveStore/archiveStore.js +1 -1
  12. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  13. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +2 -2
  14. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  15. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -7
  16. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  17. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js +1 -1
  18. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js.map +1 -1
  19. package/lib/chain/archiveStore/historicalState/types.d.ts +2 -2
  20. package/lib/chain/archiveStore/historicalState/types.d.ts.map +1 -1
  21. package/lib/chain/archiveStore/historicalState/worker.js +1 -1
  22. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  23. package/lib/chain/archiveStore/interface.d.ts +1 -1
  24. package/lib/chain/archiveStore/interface.d.ts.map +1 -1
  25. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  26. package/lib/chain/blocks/importBlock.js +4 -0
  27. package/lib/chain/blocks/importBlock.js.map +1 -1
  28. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
  29. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  30. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  31. package/lib/chain/blocks/verifyBlock.js +1 -1
  32. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  33. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts +2 -1
  34. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  35. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +5 -4
  36. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  37. package/lib/chain/chain.d.ts +6 -4
  38. package/lib/chain/chain.d.ts.map +1 -1
  39. package/lib/chain/chain.js +40 -13
  40. package/lib/chain/chain.js.map +1 -1
  41. package/lib/chain/emitter.d.ts +7 -1
  42. package/lib/chain/emitter.d.ts.map +1 -1
  43. package/lib/chain/emitter.js +5 -0
  44. package/lib/chain/emitter.js.map +1 -1
  45. package/lib/chain/errors/envelopeReconstructionError.d.ts +5 -0
  46. package/lib/chain/errors/envelopeReconstructionError.d.ts.map +1 -1
  47. package/lib/chain/errors/envelopeReconstructionError.js +2 -0
  48. package/lib/chain/errors/envelopeReconstructionError.js.map +1 -1
  49. package/lib/chain/errors/gossipValidation.d.ts +3 -1
  50. package/lib/chain/errors/gossipValidation.d.ts.map +1 -1
  51. package/lib/chain/errors/gossipValidation.js +2 -0
  52. package/lib/chain/errors/gossipValidation.js.map +1 -1
  53. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  54. package/lib/chain/forkChoice/index.js +2 -0
  55. package/lib/chain/forkChoice/index.js.map +1 -1
  56. package/lib/chain/interface.d.ts +2 -2
  57. package/lib/chain/interface.d.ts.map +1 -1
  58. package/lib/chain/opPools/proposerPreferencesPool.d.ts +4 -4
  59. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
  60. package/lib/chain/opPools/proposerPreferencesPool.js +14 -11
  61. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
  62. package/lib/chain/options.d.ts +1 -1
  63. package/lib/chain/options.d.ts.map +1 -1
  64. package/lib/chain/options.js +1 -1
  65. package/lib/chain/options.js.map +1 -1
  66. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  67. package/lib/chain/prepareNextSlot.js +5 -2
  68. package/lib/chain/prepareNextSlot.js.map +1 -1
  69. package/lib/chain/produceBlock/computeNewStateRoot.js +1 -1
  70. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  71. package/lib/chain/produceBlock/produceBlockBody.d.ts +3 -1
  72. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  73. package/lib/chain/produceBlock/produceBlockBody.js +6 -2
  74. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  75. package/lib/chain/regen/regen.d.ts +2 -0
  76. package/lib/chain/regen/regen.d.ts.map +1 -1
  77. package/lib/chain/regen/regen.js +10 -4
  78. package/lib/chain/regen/regen.js.map +1 -1
  79. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +9 -2
  80. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  81. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +23 -13
  82. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  83. package/lib/chain/validatorMonitor.d.ts +5 -1
  84. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  85. package/lib/chain/validatorMonitor.js +64 -54
  86. package/lib/chain/validatorMonitor.js.map +1 -1
  87. package/lib/execution/engine/disabled.d.ts +0 -2
  88. package/lib/execution/engine/disabled.d.ts.map +1 -1
  89. package/lib/execution/engine/disabled.js +0 -6
  90. package/lib/execution/engine/disabled.js.map +1 -1
  91. package/lib/execution/engine/http.d.ts +1 -3
  92. package/lib/execution/engine/http.d.ts.map +1 -1
  93. package/lib/execution/engine/http.js +2 -17
  94. package/lib/execution/engine/http.js.map +1 -1
  95. package/lib/execution/engine/interface.d.ts +2 -4
  96. package/lib/execution/engine/interface.d.ts.map +1 -1
  97. package/lib/execution/engine/mock.d.ts +0 -2
  98. package/lib/execution/engine/mock.d.ts.map +1 -1
  99. package/lib/execution/engine/mock.js +0 -8
  100. package/lib/execution/engine/mock.js.map +1 -1
  101. package/lib/execution/engine/types.d.ts +0 -8
  102. package/lib/execution/engine/types.d.ts.map +1 -1
  103. package/lib/execution/engine/types.js.map +1 -1
  104. package/lib/metrics/metrics.d.ts +7 -3
  105. package/lib/metrics/metrics.d.ts.map +1 -1
  106. package/lib/metrics/metrics.js +4 -4
  107. package/lib/metrics/metrics.js.map +1 -1
  108. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  109. package/lib/network/processor/gossipHandlers.js +3 -0
  110. package/lib/network/processor/gossipHandlers.js.map +1 -1
  111. package/lib/network/processor/gossipValidatorFn.d.ts +7 -3
  112. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  113. package/lib/network/processor/gossipValidatorFn.js +7 -3
  114. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  115. package/lib/network/processor/index.d.ts +9 -0
  116. package/lib/network/processor/index.d.ts.map +1 -1
  117. package/lib/network/processor/index.js +77 -10
  118. package/lib/network/processor/index.js.map +1 -1
  119. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +1 -1
  120. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
  121. package/lib/node/nodejs.d.ts.map +1 -1
  122. package/lib/node/nodejs.js +25 -3
  123. package/lib/node/nodejs.js.map +1 -1
  124. package/lib/sync/range/batch.d.ts +6 -0
  125. package/lib/sync/range/batch.d.ts.map +1 -1
  126. package/lib/sync/range/batch.js +10 -0
  127. package/lib/sync/range/batch.js.map +1 -1
  128. package/lib/sync/range/chain.d.ts.map +1 -1
  129. package/lib/sync/range/chain.js +5 -1
  130. package/lib/sync/range/chain.js.map +1 -1
  131. package/lib/sync/range/range.d.ts.map +1 -1
  132. package/lib/sync/range/range.js +50 -18
  133. package/lib/sync/range/range.js.map +1 -1
  134. package/lib/sync/unknownBlock.d.ts.map +1 -1
  135. package/lib/sync/unknownBlock.js +5 -4
  136. package/lib/sync/unknownBlock.js.map +1 -1
  137. package/lib/util/execution.d.ts +9 -11
  138. package/lib/util/execution.d.ts.map +1 -1
  139. package/lib/util/execution.js +5 -1
  140. package/lib/util/execution.js.map +1 -1
  141. package/package.json +16 -16
  142. package/src/api/impl/beacon/blocks/index.ts +7 -4
  143. package/src/api/impl/beacon/index.ts +15 -0
  144. package/src/api/impl/validator/index.ts +16 -2
  145. package/src/chain/archiveStore/archiveStore.ts +1 -1
  146. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +5 -7
  147. package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +1 -1
  148. package/src/chain/archiveStore/historicalState/types.ts +2 -2
  149. package/src/chain/archiveStore/historicalState/worker.ts +1 -2
  150. package/src/chain/archiveStore/interface.ts +1 -1
  151. package/src/chain/blocks/importBlock.ts +4 -0
  152. package/src/chain/blocks/payloadEnvelopeInput/types.ts +2 -1
  153. package/src/chain/blocks/verifyBlock.ts +1 -0
  154. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +6 -3
  155. package/src/chain/chain.ts +47 -16
  156. package/src/chain/emitter.ts +7 -1
  157. package/src/chain/errors/envelopeReconstructionError.ts +3 -0
  158. package/src/chain/errors/gossipValidation.ts +2 -0
  159. package/src/chain/forkChoice/index.ts +2 -0
  160. package/src/chain/interface.ts +2 -2
  161. package/src/chain/opPools/proposerPreferencesPool.ts +14 -10
  162. package/src/chain/options.ts +2 -2
  163. package/src/chain/prepareNextSlot.ts +6 -3
  164. package/src/chain/produceBlock/computeNewStateRoot.ts +1 -1
  165. package/src/chain/produceBlock/produceBlockBody.ts +8 -1
  166. package/src/chain/regen/regen.ts +12 -4
  167. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +31 -13
  168. package/src/chain/validatorMonitor.ts +75 -57
  169. package/src/execution/engine/disabled.ts +0 -8
  170. package/src/execution/engine/http.ts +1 -30
  171. package/src/execution/engine/interface.ts +2 -6
  172. package/src/execution/engine/mock.ts +1 -19
  173. package/src/execution/engine/types.ts +0 -10
  174. package/src/metrics/metrics.ts +21 -6
  175. package/src/network/processor/gossipHandlers.ts +3 -0
  176. package/src/network/processor/gossipValidatorFn.ts +13 -3
  177. package/src/network/processor/index.ts +89 -10
  178. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +1 -1
  179. package/src/node/nodejs.ts +31 -3
  180. package/src/sync/range/batch.ts +11 -0
  181. package/src/sync/range/chain.ts +6 -1
  182. package/src/sync/range/range.ts +50 -18
  183. package/src/sync/unknownBlock.ts +5 -4
  184. package/src/util/execution.ts +16 -8
@@ -17,7 +17,7 @@ export async function getNearestState(
17
17
  slot: number,
18
18
  config: BeaconConfig,
19
19
  db: IBeaconDb,
20
- nativeStateView: boolean
20
+ nativeStateTransition: boolean
21
21
  ): Promise<IBeaconStateView> {
22
22
  const stateBytesArr = await db.stateArchive.binaries({limit: 1, lte: slot, reverse: true});
23
23
  if (!stateBytesArr.length) {
@@ -25,9 +25,7 @@ export async function getNearestState(
25
25
  }
26
26
 
27
27
  const stateBytes = stateBytesArr[0];
28
- return nativeStateView
29
- ? createBeaconStateViewForHistoricalRegen({useNative: true, stateBytes})
30
- : createBeaconStateViewForHistoricalRegen({useNative: false, config, stateBytes});
28
+ return createBeaconStateViewForHistoricalRegen({nativeStateTransition: nativeStateTransition, config, stateBytes});
31
29
  }
32
30
 
33
31
  /**
@@ -37,13 +35,13 @@ export async function getHistoricalState(
37
35
  slot: number,
38
36
  config: BeaconConfig,
39
37
  db: IBeaconDb,
40
- nativeStateView: boolean,
38
+ nativeStateTransition: boolean,
41
39
  metrics?: HistoricalStateRegenMetrics
42
40
  ): Promise<Uint8Array> {
43
41
  const regenTimer = metrics?.regenTime.startTimer();
44
42
 
45
43
  const loadStateTimer = metrics?.loadStateTime.startTimer();
46
- let state = await getNearestState(slot, config, db, nativeStateView).catch((e) => {
44
+ let state = await getNearestState(slot, config, db, nativeStateTransition).catch((e) => {
47
45
  metrics?.regenErrorCount.inc({reason: RegenErrorType.loadState});
48
46
  throw e;
49
47
  });
@@ -54,7 +52,7 @@ export async function getHistoricalState(
54
52
  for await (const block of db.blockArchive.valuesStream({gt: state.slot, lte: slot})) {
55
53
  try {
56
54
  state = state.stateTransition(
57
- block,
55
+ {block},
58
56
  {
59
57
  verifyProposer: false,
60
58
  verifySignatures: false,
@@ -36,7 +36,7 @@ export class HistoricalStateRegen implements HistoricalStateWorkerApi {
36
36
  dataColumnDir: modules.opts.dataColumnDir,
37
37
  metricsEnabled: Boolean(modules.metrics),
38
38
  loggerOpts: modules.logger.toOpts(),
39
- nativeStateView: modules.opts.nativeStateView,
39
+ nativeStateTransition: modules.opts.nativeStateTransition,
40
40
  };
41
41
 
42
42
  const worker = new Worker(path.join(WORKER_DIR, "worker.js"), {
@@ -8,7 +8,7 @@ export type HistoricalStateRegenInitModules = {
8
8
  genesisTime: number;
9
9
  dbLocation: string;
10
10
  dataColumnDir: string;
11
- nativeStateView: boolean;
11
+ nativeStateTransition: boolean;
12
12
  };
13
13
  config: BeaconConfig;
14
14
  logger: LoggerNode;
@@ -29,7 +29,7 @@ export type HistoricalStateWorkerData = {
29
29
  dataColumnDir: string;
30
30
  metricsEnabled: boolean;
31
31
  loggerOpts: LoggerNodeOpts;
32
- nativeStateView: boolean;
32
+ nativeStateTransition: boolean;
33
33
  };
34
34
 
35
35
  export type HistoricalStateWorkerApi = {
@@ -36,7 +36,6 @@ const abortController = new AbortController();
36
36
  const metricsRegister = workerData.metricsEnabled ? new RegistryMetricCreator() : null;
37
37
  let historicalStateRegenMetrics: HistoricalStateRegenMetrics | undefined;
38
38
  let queueMetrics: QueueMetrics | undefined;
39
-
40
39
  if (metricsRegister) {
41
40
  const closeMetrics = collectNodeJSMetrics(metricsRegister, "lodestar_historical_state_worker_");
42
41
  abortController.signal.addEventListener("abort", closeMetrics, {once: true});
@@ -65,7 +64,7 @@ const api: HistoricalStateWorkerApi = {
65
64
  historicalStateRegenMetrics?.regenRequestCount.inc();
66
65
 
67
66
  const stateBytes = await queue.push<Uint8Array>(() =>
68
- getHistoricalState(slot, config, db, workerData.nativeStateView, historicalStateRegenMetrics)
67
+ getHistoricalState(slot, config, db, workerData.nativeStateTransition, historicalStateRegenMetrics)
69
68
  );
70
69
  const result = Transfer(stateBytes, [stateBytes.buffer]) as unknown as Uint8Array;
71
70
 
@@ -25,7 +25,7 @@ export type ArchiveStoreOpts = StatesArchiveOpts & {
25
25
  archiveDataEpochs?: number;
26
26
  pruneHistory?: boolean;
27
27
  serveHistoricalState?: boolean;
28
- nativeStateView?: boolean;
28
+ nativeStateTransition?: boolean;
29
29
  };
30
30
 
31
31
  export type ProposalStats = {
@@ -538,6 +538,10 @@ export async function importBlock(
538
538
  block: blockRootHex,
539
539
  slot: blockSlot,
540
540
  executionOptimistic: blockSummary != null && isOptimisticBlock(blockSummary),
541
+ ...(isGloasBeaconBlock(block.message) && {
542
+ blockHash: toRootHex(block.message.body.signedExecutionPayloadBid.message.blockHash),
543
+ builderIndex: block.message.body.signedExecutionPayloadBid.message.builderIndex,
544
+ }),
541
545
  });
542
546
  }
543
547
  if (this.emitter.listenerCount(routes.events.EventType.voluntaryExit)) {
@@ -22,8 +22,9 @@ export enum PayloadEnvelopeInputSource {
22
22
  * - finalized: below the finalized slot
23
23
  * - prune: explicit prune by root
24
24
  * - cap: insertion-order backstop cap (MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE)
25
+ * - invalid: the cached envelope failed import with a definitive invalid verdict
25
26
  */
26
- export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "remove" | "cap";
27
+ export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "remove" | "cap" | "invalid";
27
28
 
28
29
  export type SourceMeta = {
29
30
  source: PayloadEnvelopeInputSource;
@@ -188,6 +188,7 @@ export async function verifyBlocksInEpoch(
188
188
  blockInputs,
189
189
  // hack availability for state transition eval as availability is separately determined
190
190
  blocks.map(() => DataAvailabilityStatus.Available),
191
+ this.serializedCache,
191
192
  this.logger,
192
193
  this.metrics,
193
194
  this.validatorMonitor,
@@ -7,6 +7,7 @@ import {
7
7
  import {ErrorAborted, Logger, byteArrayEquals} from "@lodestar/utils";
8
8
  import {Metrics} from "../../metrics/index.js";
9
9
  import {nextEventLoop} from "../../util/eventLoop.js";
10
+ import {SerializedCache} from "../../util/serializedCache.js";
10
11
  import {BlockError, BlockErrorCode} from "../errors/index.js";
11
12
  import {BlockProcessOpts} from "../options.js";
12
13
  import {ValidatorMonitor} from "../validatorMonitor.js";
@@ -25,6 +26,7 @@ export async function verifyBlocksStateTransitionOnly(
25
26
  preState0: IBeaconStateView,
26
27
  blocks: IBlockInput[],
27
28
  dataAvailabilityStatuses: DataAvailabilityStatus[],
29
+ serializedCache: SerializedCache,
28
30
  logger: Logger,
29
31
  metrics: Metrics | null,
30
32
  validatorMonitor: ValidatorMonitor | null,
@@ -37,7 +39,8 @@ export async function verifyBlocksStateTransitionOnly(
37
39
 
38
40
  for (let i = 0; i < blocks.length; i++) {
39
41
  const {validProposerSignature, validSignatures} = opts;
40
- const block = blocks[i].getBlock();
42
+ const blockInput = blocks[i];
43
+ const block = blockInput.getBlock();
41
44
  const preState = i === 0 ? preState0 : postStates[i - 1];
42
45
  const dataAvailabilityStatus = dataAvailabilityStatuses[i];
43
46
 
@@ -47,7 +50,7 @@ export async function verifyBlocksStateTransitionOnly(
47
50
  let postState: IBeaconStateView;
48
51
  try {
49
52
  postState = preState.stateTransition(
50
- block,
53
+ {block, ssz: serializedCache.get(block)},
51
54
  {
52
55
  // NOTE: Assume valid for now while sending payload to execution engine in parallel
53
56
  // Latter verifyBlocksInEpoch() will make sure that payload is indeed valid
@@ -60,7 +63,7 @@ export async function verifyBlocksStateTransitionOnly(
60
63
  verifySignatures: !useBlsBatchVerify && !validSignatures,
61
64
  dontTransferCache: false,
62
65
  },
63
- {metrics, validatorMonitor}
66
+ {metrics: metrics?.stateTransition, validatorMonitor}
64
67
  );
65
68
  } catch (e) {
66
69
  throw new BlockError(block, {
@@ -71,7 +71,7 @@ import {BufferPool} from "../util/bufferPool.js";
71
71
  import {Clock, ClockEvent, IClock} from "../util/clock.js";
72
72
  import {CustodyConfig, getValidatorsCustodyRequirement} from "../util/dataColumns.js";
73
73
  import {callInNextEventLoop} from "../util/eventLoop.js";
74
- import {ReconstructMismatchPolicy, isRebuildMiss, reconstructExecutionPayloadEnvelopes} from "../util/execution.js";
74
+ import {ReconstructMissPolicy, isRebuildMiss, reconstructExecutionPayloadEnvelopes} from "../util/execution.js";
75
75
  import {ensureDir, writeIfNotExist} from "../util/file.js";
76
76
  import {isOptimisticBlock} from "../util/forkChoice.js";
77
77
  import {JobItemQueue} from "../util/queue/itemQueue.js";
@@ -244,6 +244,7 @@ export class BeaconChain implements IBeaconChain {
244
244
  protected readonly blockProcessor: BlockProcessor;
245
245
  protected readonly payloadEnvelopeProcessor: PayloadEnvelopeProcessor;
246
246
  protected readonly db: IBeaconDb;
247
+ private genesisStateRoot?: RootHex | null;
247
248
  // this is only available if nHistoricalStates is enabled
248
249
  private readonly cpStateDatastore?: CPStateDatastore;
249
250
  private abortController = new AbortController();
@@ -432,6 +433,7 @@ export class BeaconChain implements IBeaconChain {
432
433
  blockStateCache,
433
434
  checkpointStateCache,
434
435
  seenBlockInputCache: this.seenBlockInputCache,
436
+ serializedCache: this.serializedCache,
435
437
  db,
436
438
  metrics,
437
439
  validatorMonitor,
@@ -702,6 +704,37 @@ export class BeaconChain implements IBeaconChain {
702
704
  stateRoot: RootHex,
703
705
  opts?: StateGetOpts
704
706
  ): Promise<{state: IBeaconStateView | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
707
+ const finalizedBlock = this.forkChoice.getFinalizedBlock();
708
+ const finalizedCheckpoint = this.forkChoice.getFinalizedCheckpoint();
709
+ // Checkpoint state only equals the block post-state if the block is at the epoch start slot
710
+ if (
711
+ finalizedBlock.stateRoot === stateRoot &&
712
+ finalizedBlock.slot === computeStartSlotAtEpoch(finalizedCheckpoint.epoch)
713
+ ) {
714
+ const state = this.regen.getCheckpointStateSync({
715
+ epoch: finalizedCheckpoint.epoch,
716
+ rootHex: finalizedCheckpoint.rootHex,
717
+ });
718
+ if (state) {
719
+ return {
720
+ state,
721
+ executionOptimistic: isOptimisticBlock(finalizedBlock),
722
+ finalized: finalizedCheckpoint.epoch !== GENESIS_EPOCH,
723
+ };
724
+ }
725
+ }
726
+
727
+ if (this.genesisStateRoot === undefined) {
728
+ const genesisBlock = await this.db.blockArchive.get(GENESIS_SLOT);
729
+ this.genesisStateRoot = genesisBlock ? toRootHex(genesisBlock.message.stateRoot) : null;
730
+ }
731
+ if (this.genesisStateRoot === stateRoot) {
732
+ const state = await this.db.stateArchive.getBinary(GENESIS_SLOT);
733
+ if (state) {
734
+ return {state, executionOptimistic: false, finalized: finalizedCheckpoint.epoch !== GENESIS_EPOCH};
735
+ }
736
+ }
737
+
705
738
  if (opts?.allowRegen) {
706
739
  const state = await this.regen.getState(stateRoot, RegenCaller.restApi);
707
740
  const block = this.forkChoice.getBlockDefaultStatus(
@@ -934,12 +967,13 @@ export class BeaconChain implements IBeaconChain {
934
967
 
935
968
  /**
936
969
  * Batch variant: archived header envelopes are rebuilt 32 per EL round-trip. Aligned with `requests`.
937
- * A body root mismatch is a local inconsistency: `"throw"` surfaces it, `"omit"` logs it and
938
- * returns null for that entry, for peer-facing paths where the spec allows omission.
970
+ * An archived envelope that cannot be rebuilt (EL-unavailable body or body root mismatch) is not the
971
+ * same as an unknown one: `"throw"` surfaces it, `"omit"` returns null for that entry, for
972
+ * peer-facing paths where the spec allows omission.
939
973
  */
940
974
  async getSerializedExecutionPayloadEnvelopes(
941
975
  requests: {blockSlot: Slot; blockRootHex: RootHex}[],
942
- onMismatch: ReconstructMismatchPolicy = "throw"
976
+ onMiss: ReconstructMissPolicy = "throw"
943
977
  ): Promise<(Uint8Array | null)[]> {
944
978
  const out: (Uint8Array | null)[] = new Array(requests.length).fill(null);
945
979
  const headerEnvelopes: gloas.SignedExecutionPayloadHeaderEnvelope[] = [];
@@ -978,14 +1012,14 @@ export class BeaconChain implements IBeaconChain {
978
1012
  for (let j = 0; j < rebuilt.length; j++) {
979
1013
  const result = rebuilt[j];
980
1014
  if (isRebuildMiss(result)) {
981
- if (result.reason === "mismatch") {
982
- if (onMismatch === "throw") throw result.error;
983
- this.logger.debug(
984
- "Archived envelope failed body root check against EL bodies",
985
- {slot: result.slot},
986
- result.error
987
- );
988
- }
1015
+ if (onMiss === "throw") throw result.error;
1016
+ this.logger.debug(
1017
+ result.reason === "mismatch"
1018
+ ? "Archived envelope failed body root check against EL bodies"
1019
+ : "EL cannot serve bodies for archived envelope, omitting",
1020
+ {slot: result.slot},
1021
+ result.error
1022
+ );
989
1023
  continue;
990
1024
  }
991
1025
  out[headerEnvelopeIdxs[j]] = ssz.gloas.SignedExecutionPayloadEnvelope.serialize(result);
@@ -1016,10 +1050,7 @@ export class BeaconChain implements IBeaconChain {
1016
1050
  const [result] = await reconstructExecutionPayloadEnvelopes(this.executionEngine, this.metrics, [
1017
1051
  archived.headerEnvelope,
1018
1052
  ]);
1019
- if (isRebuildMiss(result)) {
1020
- if (result.reason === "mismatch") throw result.error;
1021
- return null;
1022
- }
1053
+ if (isRebuildMiss(result)) throw result.error;
1023
1054
  return result;
1024
1055
  }
1025
1056
 
@@ -1,7 +1,7 @@
1
1
  import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {routes} from "@lodestar/api";
4
- import {CheckpointWithHex} from "@lodestar/fork-choice";
4
+ import {CheckpointWithHex, PtcQuorumEvent} from "@lodestar/fork-choice";
5
5
  import {IBeaconStateView} from "@lodestar/state-transition";
6
6
  import {DataColumnSidecar, RootHex, Slot, deneb, phase0} from "@lodestar/types";
7
7
  import {PeerIdStr} from "../util/peerId.js";
@@ -36,6 +36,11 @@ export enum ChainEvent {
36
36
  * This event is guaranteed to be triggered whenever the fork choice finalized checkpoint is updated. This is either in response to a newly processed block or a new clock tick.
37
37
  */
38
38
  forkChoiceFinalized = "forkChoice:finalized",
39
+ /**
40
+ * This event signals that the PTC verdict on a block was decided: a majority against payload presence or blob data
41
+ * availability, or a majority for both.
42
+ */
43
+ forkChoicePtcQuorum = "forkChoice:ptcQuorum",
39
44
  /**
40
45
  * This event signals that dependent services (e.g. custody sampling) should update to account for the new target group count.
41
46
  */
@@ -112,6 +117,7 @@ export type IChainEvents = ApiEvents & {
112
117
 
113
118
  [ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithHex) => void;
114
119
  [ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithHex) => void;
120
+ [ChainEvent.forkChoicePtcQuorum]: (data: PtcQuorumEvent) => void;
115
121
 
116
122
  [ChainEvent.updateTargetCustodyGroupCount]: (targetGroupCount: number) => void;
117
123
 
@@ -4,6 +4,8 @@ import {LodestarError} from "@lodestar/utils";
4
4
  export enum EnvelopeReconstructionErrorCode {
5
5
  /** The EL failed to answer engine_getPayloadBodiesByHashV2 (transport / EL down). Transient. */
6
6
  ENGINE_UNAVAILABLE = "ENVELOPE_RECONSTRUCTION_ERROR_ENGINE_UNAVAILABLE",
7
+ /** The EL does not have the block or its block access list (pruned, or not yet re-indexed after a restart). May recover. */
8
+ BODY_UNAVAILABLE = "ENVELOPE_RECONSTRUCTION_ERROR_BODY_UNAVAILABLE",
7
9
  /** A body returned by the EL does not hash to the root stored in the header envelope. Local DB/EL inconsistency. */
8
10
  BODY_ROOT_MISMATCH = "ENVELOPE_RECONSTRUCTION_ERROR_BODY_ROOT_MISMATCH",
9
11
  /** A by-range stream stopped short at a slot that cannot be served; the response so far is still valid */
@@ -12,6 +14,7 @@ export enum EnvelopeReconstructionErrorCode {
12
14
 
13
15
  export type EnvelopeReconstructionErrorType =
14
16
  | {code: EnvelopeReconstructionErrorCode.ENGINE_UNAVAILABLE}
17
+ | {code: EnvelopeReconstructionErrorCode.BODY_UNAVAILABLE; slot: Slot}
15
18
  | {
16
19
  code: EnvelopeReconstructionErrorCode.BODY_ROOT_MISMATCH;
17
20
  slot: Slot;
@@ -9,6 +9,8 @@ export enum GossipErrorCode {
9
9
  INVALID_SERIALIZED_BYTES_ERROR_CODE = "GOSSIP_ERROR_INVALID_SERIALIZED_BYTES",
10
10
  PAST_SLOT = "GOSSIP_ERROR_PAST_SLOT",
11
11
  FUTURE_SLOT = "GOSSIP_ERROR_FUTURE_SLOT",
12
+ FATAL_PEER = "GOSSIP_ERROR_FATAL_PEER",
13
+ INVALID_SLOT = "GOSSIP_ERROR_INVALID_SLOT",
12
14
  }
13
15
 
14
16
  export class GossipActionError<T extends {code: string}> extends LodestarError<T> {
@@ -124,6 +124,7 @@ export function initializeForkChoiceFromFinalizedState(
124
124
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
125
125
  onFastConfirmation: ({block, slot, currentSlot}) =>
126
126
  emitter.emit(routes.events.EventType.fastConfirmation, {block, slot, currentSlot}),
127
+ onPtcQuorum: (data) => emitter.emit(ChainEvent.forkChoicePtcQuorum, data),
127
128
  }
128
129
  ),
129
130
 
@@ -222,6 +223,7 @@ export function initializeForkChoiceFromUnfinalizedState(
222
223
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
223
224
  onFastConfirmation: ({block, slot, currentSlot}) =>
224
225
  emitter.emit(routes.events.EventType.fastConfirmation, {block, slot, currentSlot}),
226
+ onPtcQuorum: (data) => emitter.emit(ChainEvent.forkChoicePtcQuorum, data),
225
227
  }
226
228
  );
227
229
 
@@ -30,7 +30,7 @@ import {Metrics} from "../metrics/metrics.js";
30
30
  import {BufferPool} from "../util/bufferPool.js";
31
31
  import {IClock} from "../util/clock.js";
32
32
  import {CustodyConfig} from "../util/dataColumns.js";
33
- import {ReconstructMismatchPolicy} from "../util/execution.js";
33
+ import {ReconstructMissPolicy} from "../util/execution.js";
34
34
  import {SerializedCache} from "../util/serializedCache.js";
35
35
  import {IArchiveStore} from "./archiveStore/interface.js";
36
36
  import {CheckpointBalancesCache} from "./balancesCache.js";
@@ -239,7 +239,7 @@ export interface IBeaconChain {
239
239
  getSerializedExecutionPayloadEnvelope(blockSlot: Slot, blockRootHex: string): Promise<Uint8Array | null>;
240
240
  getSerializedExecutionPayloadEnvelopes(
241
241
  requests: {blockSlot: Slot; blockRootHex: RootHex}[],
242
- onMismatch?: ReconstructMismatchPolicy
242
+ onMiss?: ReconstructMissPolicy
243
243
  ): Promise<(Uint8Array | null)[]>;
244
244
  getExecutionPayloadEnvelope(
245
245
  blockSlot: Slot,
@@ -6,8 +6,8 @@ import {toRootHex} from "@lodestar/utils";
6
6
  *
7
7
  * The primary consumer is `validateExecutionPayloadBid`, which looks up the matching
8
8
  * preferences via `get(bid.slot, dependent_root)` to enforce the IGNORE-existence and
9
- * REJECT-equality rules from the gloas spec. The beacon API `/pool/proposer_preferences`
10
- * GET endpoint reads from the same pool via `getAll`.
9
+ * REJECT-equality rules from the gloas spec. The beacon API `getProposerPreferences`
10
+ * endpoint reads from the same pool via `getAll`.
11
11
  *
12
12
  * `validator_index` is intentionally not part of the key: gossip validation enforces
13
13
  * `proposers[proposalSlot % SLOTS_PER_EPOCH] === validatorIndex` against the shuffling
@@ -37,15 +37,19 @@ export class ProposerPreferencesPool {
37
37
  byRoot.set(rootHex, signed);
38
38
  }
39
39
 
40
- /** API read-out: flatten across branches, optionally filtered by slot. */
41
- getAll(slot?: Slot): gloas.SignedProposerPreferences[] {
42
- if (slot !== undefined) {
43
- const byRoot = this.bySlot.get(slot);
44
- return byRoot ? Array.from(byRoot.values()) : [];
45
- }
40
+ /** API read-out: flatten across branches, optionally filtered by slot and dependent root. */
41
+ getAll(slot?: Slot, dependentRootHex?: RootHex): gloas.SignedProposerPreferences[] {
46
42
  const out: gloas.SignedProposerPreferences[] = [];
47
- for (const byRoot of this.bySlot.values()) {
48
- for (const v of byRoot.values()) out.push(v);
43
+ for (const [s, byRoot] of this.bySlot) {
44
+ if (slot !== undefined && s !== slot) {
45
+ continue;
46
+ }
47
+ for (const [root, signed] of byRoot) {
48
+ if (dependentRootHex !== undefined && root !== dependentRootHex) {
49
+ continue;
50
+ }
51
+ out.push(signed);
52
+ }
49
53
  }
50
54
  return out;
51
55
  }
@@ -52,7 +52,7 @@ export type IChainOptions = BlockProcessOpts &
52
52
  minSameMessageSignatureSetsToBatch: number;
53
53
  archiveDateEpochs?: number;
54
54
  nHistoricalStatesFileDataStore?: boolean;
55
- nativeStateView?: boolean;
55
+ nativeStateTransition?: boolean;
56
56
  /** Builder circuit breaker fault inspection window in slots */
57
57
  faultInspectionWindow?: number;
58
58
  /** Canonical EMPTY blocks allowed per `faultInspectionWindow` observed blocks */
@@ -131,7 +131,7 @@ export const defaultChainOptions: IChainOptions = {
131
131
  // - users can prune the persisted checkpoint state files manually to save disc space
132
132
  // - it helps debug easier when network is unfinalized
133
133
  nHistoricalStatesFileDataStore: true,
134
- nativeStateView: false,
134
+ nativeStateTransition: false,
135
135
  maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
136
136
  maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
137
137
  maxCPStateEpochsOnDisk: DEFAULT_MAX_CP_STATE_ON_DISK,
@@ -244,6 +244,10 @@ export class PrepareNextSlotScheduler {
244
244
  parentBlockHash = preparedState.latestExecutionPayloadHeader.blockHash;
245
245
  }
246
246
 
247
+ // The payload_attributes event must carry the same hashes we send to the EL
248
+ const safeBlockHash = getSafeExecutionBlockHash(this.chain.forkChoice, this.logger);
249
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice);
250
+
247
251
  let payloadAttributes: PayloadAttributes | undefined;
248
252
  // If emitPayloadAttributes is true emit a SSE payloadAttributes event for
249
253
  // every slot. Without the flag, only emit the event if we are proposing in the next slot.
@@ -256,6 +260,8 @@ export class PrepareNextSlotScheduler {
256
260
  prepareSlot,
257
261
  parentBlockRoot: fromHex(updatedHead.blockRoot),
258
262
  parentBlockHash,
263
+ safeBlockHash,
264
+ finalizedBlockHash,
259
265
  feeRecipient: feeRecipient ?? "0x0000000000000000000000000000000000000000",
260
266
  });
261
267
  this.chain.emitter.emit(routes.events.EventType.payloadAttributes, {data, version: fork});
@@ -267,9 +273,6 @@ export class PrepareNextSlotScheduler {
267
273
  computeTimeAtSlot(this.config, prepareSlot, this.chain.genesisTime) - Date.now() / 1000;
268
274
  this.metrics?.blockPayload.payloadAdvancePrepTime.observe(preparationTime);
269
275
 
270
- const safeBlockHash = getSafeExecutionBlockHash(this.chain.forkChoice, this.logger);
271
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice);
272
-
273
276
  // awaiting here instead of throwing an async call because there is no other task
274
277
  // left for scheduler and this gives nice semantics to catch and log errors in the
275
278
  // try/catch wrapper here.
@@ -16,7 +16,7 @@ export function computeNewStateRoot(
16
16
  const signedBlock = {message: block, signature: EMPTY_SIGNATURE};
17
17
  const {newStateRoot, proposerReward, postState, hashTreeRootTime} = state.computeNewStateRoot(
18
18
  {block: signedBlock},
19
- {metrics}
19
+ {metrics: metrics?.stateTransition}
20
20
  );
21
21
 
22
22
  metrics?.stateHashTreeRootTime.observe({source: StateHashTreeRootSource.computeNewStateRoot}, hashTreeRootTime);
@@ -845,6 +845,8 @@ export function getPayloadAttributesForSSE(
845
845
  prepareSlot,
846
846
  parentBlockRoot,
847
847
  parentBlockHash,
848
+ safeBlockHash,
849
+ finalizedBlockHash,
848
850
  feeRecipient,
849
851
  }: {
850
852
  /**
@@ -855,6 +857,8 @@ export function getPayloadAttributesForSSE(
855
857
  prepareSlot: Slot;
856
858
  parentBlockRoot: Root;
857
859
  parentBlockHash: Bytes32;
860
+ safeBlockHash: RootHex;
861
+ finalizedBlockHash: RootHex;
858
862
  feeRecipient: string;
859
863
  }
860
864
  ): SSEPayloadAttributes {
@@ -874,7 +878,10 @@ export function getPayloadAttributesForSSE(
874
878
  payloadAttributes,
875
879
  } as SSEPayloadAttributes;
876
880
 
877
- if (!isForkPostGloas(fork)) {
881
+ if (isForkPostGloas(fork)) {
882
+ (ssePayloadAttributes as gloas.SSEPayloadAttributes).safeBlockHash = fromHex(safeBlockHash);
883
+ (ssePayloadAttributes as gloas.SSEPayloadAttributes).finalizedBlockHash = fromHex(finalizedBlockHash);
884
+ } else {
878
885
  // Removed in Gloas, builders can get the block number from the EL via the block hash if required
879
886
  (ssePayloadAttributes as bellatrix.SSEPayloadAttributes).parentBlockNumber = prepareState.payloadBlockNumber;
880
887
  }
@@ -14,6 +14,7 @@ import {Logger, fromHex, toRootHex} from "@lodestar/utils";
14
14
  import {IBeaconDb} from "../../db/index.js";
15
15
  import {Metrics} from "../../metrics/index.js";
16
16
  import {nextEventLoop} from "../../util/eventLoop.js";
17
+ import {SerializedCache} from "../../util/serializedCache.js";
17
18
  import {getCheckpointFromState} from "../blocks/utils/checkpoint.js";
18
19
  import {ChainEvent, ChainEventEmitter} from "../emitter.js";
19
20
  import {SeenBlockInput} from "../seenCache/seenGossipBlockInput.js";
@@ -28,6 +29,7 @@ export type RegenModules = {
28
29
  blockStateCache: BlockStateCache;
29
30
  checkpointStateCache: CheckpointStateCache;
30
31
  seenBlockInputCache: SeenBlockInput;
32
+ serializedCache: SerializedCache;
31
33
  config: ChainForkConfig;
32
34
  emitter: ChainEventEmitter;
33
35
  logger: Logger;
@@ -235,7 +237,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
235
237
  // We are only running the state transition to get a specific state's data.
236
238
  // stateTransition() does the clone() inside, transfer cache to make the regen faster
237
239
  state = state.stateTransition(
238
- block,
240
+ {block, ssz: this.modules.serializedCache.get(block)},
239
241
  {
240
242
  // Replay previously imported blocks, assume valid and available
241
243
  executionPayloadStatus: ExecutionPayloadStatus.valid,
@@ -245,7 +247,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
245
247
  verifySignatures: false,
246
248
  dontTransferCache: false,
247
249
  },
248
- this.modules
250
+ {metrics: this.modules.metrics?.stateTransition, validatorMonitor: this.modules.validatorMonitor}
249
251
  );
250
252
 
251
253
  const hashTreeRootTimer = this.modules.metrics?.stateHashTreeRootTime.startTimer({
@@ -316,7 +318,10 @@ async function processSlotsByCheckpoint(
316
318
  ): Promise<IBeaconStateView> {
317
319
  let postState = await processSlotsToNearestCheckpoint(modules, preState, slot, regenCaller, opts);
318
320
  if (postState.slot < slot) {
319
- postState = postState.processSlots(slot, opts, modules);
321
+ postState = postState.processSlots(slot, opts, {
322
+ metrics: modules.metrics?.stateTransition,
323
+ validatorMonitor: modules.validatorMonitor,
324
+ });
320
325
  }
321
326
  return postState;
322
327
  }
@@ -361,7 +366,10 @@ export async function processSlotsToNearestCheckpoint(
361
366
  caller: regenCaller,
362
367
  });
363
368
  // processSlots calls .clone() before mutating
364
- postState = postState.processSlots(nextEpochSlot, opts, modules);
369
+ postState = postState.processSlots(nextEpochSlot, opts, {
370
+ metrics: metrics?.stateTransition,
371
+ validatorMonitor: modules.validatorMonitor,
372
+ });
365
373
  metrics?.epochTransitionByCaller.inc({caller: regenCaller});
366
374
 
367
375
  // this is usually added when we prepare for next slot or validate gossip block
@@ -47,8 +47,9 @@ export type SeenPayloadEnvelopeInputModules = {
47
47
  * Created whenever we have a block because it needs block bid.
48
48
  * Steady state (linear chain, healthy progression): the cache holds ~2 entries — the head
49
49
  * (parent for next-slot production) and its parent (proposer-boost-reorg fallback). It can
50
- * transiently hold more during forks, range-sync bursts, or when `prepareNextSlot` skips
51
- * ticks; subsequent ticks settle it back.
50
+ * hold more during forks and range sync, or while an entry's payload is not FULL on the head's
51
+ * branch or its columns are still being gathered. Such entries are evicted on a later block
52
+ * import, on finalization or by the size cap.
52
53
  */
53
54
  export class SeenPayloadEnvelopeInput {
54
55
  private readonly config: ChainForkConfig;
@@ -264,18 +265,35 @@ export class SeenPayloadEnvelopeInput {
264
265
  }
265
266
  }
266
267
 
268
+ /**
269
+ * Removes a PayloadEnvelopeInput whose envelope failed import with a definitive invalid verdict. The envelope
270
+ * cannot be replaced in place, sync recreates the entry via `getOrReload()` or `add()` to fetch another one.
271
+ * No-op if the cached entry is a different object, it may already be the recreated one.
272
+ */
273
+ removeInvalid(payloadInput: PayloadEnvelopeInput): void {
274
+ if (this.payloadInputs.get(payloadInput.blockRootHex) === payloadInput) {
275
+ this.evictPayloadInput(payloadInput, "invalid");
276
+ }
277
+ }
278
+
267
279
  pruneBelowParent(parentBlock: ProtoBlock): void {
268
- for (const block of this.forkChoice.getAllAncestorBlocks(parentBlock.blockRoot, parentBlock.payloadStatus)) {
269
- // Only evict once the payload is FULL (revealed/imported) — on an EMPTY/PENDING branch we may
270
- // still need to download the FULL envelope (see #9475), and evicting would make payload-by-root
271
- // sync throw "Missing PayloadEnvelopeInput for known block".
272
- if (block.slot < parentBlock.slot && block.payloadStatus === PayloadStatus.FULL) {
273
- const input = this.payloadInputs.get(block.blockRoot);
274
- // ...and don't evict while columns are still being gathered: writeDataColumnsToDb awaits the
275
- // same hasComputedAllData() before persisting. Such entries are pruned by a later call.
276
- if (input?.hasComputedAllData()) {
277
- this.evictPayloadInput(input, "belowParent");
278
- }
280
+ for (const input of this.payloadInputs.values()) {
281
+ if (
282
+ input.slot < parentBlock.slot &&
283
+ // Don't evict while columns are still being gathered: writeDataColumnsToDb awaits the same
284
+ // hasComputedAllData() before persisting. Such entries are pruned by a later call.
285
+ input.hasComputedAllData() &&
286
+ // Only evict once the payload is FULL (revealed/imported) on the parent's branch. On an EMPTY/PENDING
287
+ // branch we may still need to download the FULL envelope (see #9475), and without the entry gossip
288
+ // for the block is ignored until by-root sync reloads it.
289
+ this.forkChoice.isDescendant(
290
+ input.blockRootHex,
291
+ PayloadStatus.FULL,
292
+ parentBlock.blockRoot,
293
+ parentBlock.payloadStatus
294
+ )
295
+ ) {
296
+ this.evictPayloadInput(input, "belowParent");
279
297
  }
280
298
  }
281
299
  }