@lodestar/beacon-node 1.41.0-dev.9fa839a030 → 1.41.0-dev.aeb5a213ee

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 (175) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +121 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/state/utils.js +1 -20
  6. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  7. package/lib/api/impl/debug/index.d.ts.map +1 -1
  8. package/lib/api/impl/debug/index.js +5 -2
  9. package/lib/api/impl/debug/index.js.map +1 -1
  10. package/lib/api/impl/lightclient/index.d.ts.map +1 -1
  11. package/lib/api/impl/lightclient/index.js +19 -2
  12. package/lib/api/impl/lightclient/index.js.map +1 -1
  13. package/lib/api/impl/validator/index.d.ts.map +1 -1
  14. package/lib/api/impl/validator/index.js +101 -1
  15. package/lib/api/impl/validator/index.js.map +1 -1
  16. package/lib/chain/archiveStore/archiveStore.d.ts +1 -0
  17. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  18. package/lib/chain/archiveStore/archiveStore.js +9 -0
  19. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  20. package/lib/chain/archiveStore/utils/archivePayloads.d.ts +7 -0
  21. package/lib/chain/archiveStore/utils/archivePayloads.d.ts.map +1 -0
  22. package/lib/chain/archiveStore/utils/archivePayloads.js +10 -0
  23. package/lib/chain/archiveStore/utils/archivePayloads.js.map +1 -0
  24. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  25. package/lib/chain/blocks/importBlock.js +0 -2
  26. package/lib/chain/blocks/importBlock.js.map +1 -1
  27. package/lib/chain/blocks/index.d.ts.map +1 -1
  28. package/lib/chain/blocks/index.js +2 -1
  29. package/lib/chain/blocks/index.js.map +1 -1
  30. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
  31. package/lib/chain/blocks/writeBlockInputToDb.js +3 -0
  32. package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
  33. package/lib/chain/chain.d.ts +2 -2
  34. package/lib/chain/chain.d.ts.map +1 -1
  35. package/lib/chain/chain.js +24 -6
  36. package/lib/chain/chain.js.map +1 -1
  37. package/lib/chain/emitter.d.ts +2 -2
  38. package/lib/chain/emitter.d.ts.map +1 -1
  39. package/lib/chain/interface.d.ts +2 -2
  40. package/lib/chain/interface.d.ts.map +1 -1
  41. package/lib/chain/lightClient/index.d.ts.map +1 -1
  42. package/lib/chain/lightClient/index.js +1 -1
  43. package/lib/chain/lightClient/index.js.map +1 -1
  44. package/lib/chain/options.d.ts.map +1 -1
  45. package/lib/chain/options.js.map +1 -1
  46. package/lib/chain/prepareNextSlot.js +3 -3
  47. package/lib/chain/prepareNextSlot.js.map +1 -1
  48. package/lib/chain/produceBlock/computeNewStateRoot.d.ts +10 -2
  49. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  50. package/lib/chain/produceBlock/computeNewStateRoot.js +24 -2
  51. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  52. package/lib/chain/produceBlock/produceBlockBody.d.ts +22 -7
  53. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  54. package/lib/chain/produceBlock/produceBlockBody.js +110 -10
  55. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  56. package/lib/chain/validation/dataColumnSidecar.d.ts +2 -2
  57. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  58. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  59. package/lib/db/beacon.d.ts +3 -1
  60. package/lib/db/beacon.d.ts.map +1 -1
  61. package/lib/db/beacon.js +5 -1
  62. package/lib/db/beacon.js.map +1 -1
  63. package/lib/db/buckets.d.ts +3 -1
  64. package/lib/db/buckets.d.ts.map +1 -1
  65. package/lib/db/buckets.js +2 -0
  66. package/lib/db/buckets.js.map +1 -1
  67. package/lib/db/interface.d.ts +3 -1
  68. package/lib/db/interface.d.ts.map +1 -1
  69. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  70. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  71. package/lib/db/repositories/dataColumnSidecar.d.ts +5 -3
  72. package/lib/db/repositories/dataColumnSidecar.d.ts.map +1 -1
  73. package/lib/db/repositories/dataColumnSidecar.js +14 -1
  74. package/lib/db/repositories/dataColumnSidecar.js.map +1 -1
  75. package/lib/db/repositories/dataColumnSidecarArchive.d.ts +5 -3
  76. package/lib/db/repositories/dataColumnSidecarArchive.d.ts.map +1 -1
  77. package/lib/db/repositories/dataColumnSidecarArchive.js +14 -1
  78. package/lib/db/repositories/dataColumnSidecarArchive.js.map +1 -1
  79. package/lib/db/repositories/executionPayloadEnvelope.d.ts +19 -0
  80. package/lib/db/repositories/executionPayloadEnvelope.d.ts.map +1 -0
  81. package/lib/db/repositories/executionPayloadEnvelope.js +22 -0
  82. package/lib/db/repositories/executionPayloadEnvelope.js.map +1 -0
  83. package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts +18 -0
  84. package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts.map +1 -0
  85. package/lib/db/repositories/executionPayloadEnvelopeArchive.js +28 -0
  86. package/lib/db/repositories/executionPayloadEnvelopeArchive.js.map +1 -0
  87. package/lib/db/repositories/index.d.ts +2 -0
  88. package/lib/db/repositories/index.d.ts.map +1 -1
  89. package/lib/db/repositories/index.js +2 -0
  90. package/lib/db/repositories/index.js.map +1 -1
  91. package/lib/metrics/metrics/beacon.d.ts +1 -0
  92. package/lib/metrics/metrics/beacon.d.ts.map +1 -1
  93. package/lib/metrics/metrics/beacon.js +5 -0
  94. package/lib/metrics/metrics/beacon.js.map +1 -1
  95. package/lib/metrics/metrics/lodestar.d.ts +5 -0
  96. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  97. package/lib/metrics/metrics/lodestar.js +9 -0
  98. package/lib/metrics/metrics/lodestar.js.map +1 -1
  99. package/lib/metrics/metrics.d.ts.map +1 -1
  100. package/lib/metrics/metrics.js +8 -3
  101. package/lib/metrics/metrics.js.map +1 -1
  102. package/lib/network/gossip/interface.d.ts +3 -3
  103. package/lib/network/gossip/interface.d.ts.map +1 -1
  104. package/lib/network/gossip/topic.d.ts +113 -63
  105. package/lib/network/gossip/topic.d.ts.map +1 -1
  106. package/lib/network/gossip/topic.js +2 -2
  107. package/lib/network/gossip/topic.js.map +1 -1
  108. package/lib/network/interface.d.ts +3 -2
  109. package/lib/network/interface.d.ts.map +1 -1
  110. package/lib/network/network.d.ts +3 -2
  111. package/lib/network/network.d.ts.map +1 -1
  112. package/lib/network/network.js +10 -1
  113. package/lib/network/network.js.map +1 -1
  114. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  115. package/lib/network/processor/gossipHandlers.js +5 -1
  116. package/lib/network/processor/gossipHandlers.js.map +1 -1
  117. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.d.ts.map +1 -1
  118. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js +7 -1
  119. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js.map +1 -1
  120. package/lib/util/blobs.d.ts +2 -2
  121. package/lib/util/blobs.d.ts.map +1 -1
  122. package/lib/util/blobs.js.map +1 -1
  123. package/lib/util/dataColumns.d.ts +11 -3
  124. package/lib/util/dataColumns.d.ts.map +1 -1
  125. package/lib/util/dataColumns.js +27 -0
  126. package/lib/util/dataColumns.js.map +1 -1
  127. package/lib/util/multifork.d.ts +8 -0
  128. package/lib/util/multifork.d.ts.map +1 -1
  129. package/lib/util/multifork.js +37 -0
  130. package/lib/util/multifork.js.map +1 -1
  131. package/lib/util/serializedCache.d.ts +5 -0
  132. package/lib/util/serializedCache.d.ts.map +1 -1
  133. package/lib/util/serializedCache.js +5 -0
  134. package/lib/util/serializedCache.js.map +1 -1
  135. package/package.json +15 -15
  136. package/src/api/impl/beacon/blocks/index.ts +145 -2
  137. package/src/api/impl/beacon/state/utils.ts +10 -23
  138. package/src/api/impl/debug/index.ts +8 -5
  139. package/src/api/impl/lightclient/index.ts +19 -2
  140. package/src/api/impl/validator/index.ts +124 -1
  141. package/src/chain/archiveStore/archiveStore.ts +10 -0
  142. package/src/chain/archiveStore/utils/archivePayloads.ts +15 -0
  143. package/src/chain/blocks/importBlock.ts +0 -3
  144. package/src/chain/blocks/index.ts +2 -1
  145. package/src/chain/blocks/writeBlockInputToDb.ts +3 -0
  146. package/src/chain/chain.ts +41 -11
  147. package/src/chain/emitter.ts +2 -2
  148. package/src/chain/interface.ts +2 -2
  149. package/src/chain/lightClient/index.ts +4 -1
  150. package/src/chain/options.ts +1 -0
  151. package/src/chain/prepareNextSlot.ts +5 -5
  152. package/src/chain/produceBlock/computeNewStateRoot.ts +35 -3
  153. package/src/chain/produceBlock/produceBlockBody.ts +163 -13
  154. package/src/chain/validation/dataColumnSidecar.ts +2 -5
  155. package/src/db/beacon.ts +8 -0
  156. package/src/db/buckets.ts +3 -0
  157. package/src/db/interface.ts +5 -0
  158. package/src/db/repositories/dataColumnSidecar.ts +18 -3
  159. package/src/db/repositories/dataColumnSidecarArchive.ts +18 -3
  160. package/src/db/repositories/executionPayloadEnvelope.ts +26 -0
  161. package/src/db/repositories/executionPayloadEnvelopeArchive.ts +32 -0
  162. package/src/db/repositories/index.ts +2 -0
  163. package/src/metrics/metrics/beacon.ts +5 -0
  164. package/src/metrics/metrics/lodestar.ts +9 -0
  165. package/src/metrics/metrics.ts +8 -3
  166. package/src/network/gossip/interface.ts +3 -3
  167. package/src/network/gossip/topic.ts +2 -1
  168. package/src/network/interface.ts +4 -1
  169. package/src/network/network.ts +21 -3
  170. package/src/network/processor/gossipHandlers.ts +7 -1
  171. package/src/network/reqresp/handlers/lightClientUpdatesByRange.ts +6 -1
  172. package/src/util/blobs.ts +3 -3
  173. package/src/util/dataColumns.ts +37 -1
  174. package/src/util/multifork.ts +45 -0
  175. package/src/util/serializedCache.ts +5 -0
@@ -3,6 +3,7 @@ import {routes} from "@lodestar/api";
3
3
  import {ApplicationMethods} from "@lodestar/api/server";
4
4
  import {ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice";
5
5
  import {
6
+ BUILDER_INDEX_SELF_BUILD,
6
7
  ForkName,
7
8
  ForkPostBellatrix,
8
9
  ForkPreGloas,
@@ -14,6 +15,7 @@ import {
14
15
  isForkPostBellatrix,
15
16
  isForkPostDeneb,
16
17
  isForkPostElectra,
18
+ isForkPostGloas,
17
19
  } from "@lodestar/params";
18
20
  import {
19
21
  CachedBeaconStateAllForks,
@@ -45,6 +47,7 @@ import {
45
47
  Wei,
46
48
  bellatrix,
47
49
  getValidatorStatus,
50
+ gloas,
48
51
  phase0,
49
52
  ssz,
50
53
  } from "@lodestar/types";
@@ -69,7 +72,7 @@ import {
69
72
  } from "../../../chain/errors/index.js";
70
73
  import {ChainEvent, CommonBlockBody} from "../../../chain/index.js";
71
74
  import {PREPARE_NEXT_SLOT_BPS} from "../../../chain/prepareNextSlot.js";
72
- import {BlockType, ProduceFullDeneb} from "../../../chain/produceBlock/index.js";
75
+ import {BlockType, ProduceFullDeneb, ProduceFullGloas} from "../../../chain/produceBlock/index.js";
73
76
  import {RegenCaller} from "../../../chain/regen/index.js";
74
77
  import {CheckpointHex} from "../../../chain/stateCache/types.js";
75
78
  import {validateApiAggregateAndProof} from "../../../chain/validation/index.js";
@@ -901,6 +904,77 @@ export function getValidatorApi(
901
904
  return {data, meta};
902
905
  },
903
906
 
907
+ async produceBlockV4({slot, randaoReveal, graffiti, feeRecipient}) {
908
+ const fork = config.getForkName(slot);
909
+
910
+ if (!isForkPostGloas(fork)) {
911
+ throw new ApiError(400, `produceBlockV4 not supported for pre-gloas fork=${fork}`);
912
+ }
913
+
914
+ notWhileSyncing();
915
+ await waitForSlot(slot);
916
+
917
+ // TODO GLOAS: support producing blocks from builder bids
918
+ const source = ProducedBlockSource.engine;
919
+
920
+ // TODO GLOAS: needs to be updated after fork choice changes are merged
921
+ const parentBlock = chain.getProposerHead(slot);
922
+ const {blockRoot: parentBlockRootHex, slot: parentSlot} = parentBlock;
923
+ const parentBlockRoot = fromHex(parentBlockRootHex);
924
+ notOnOutOfRangeData(parentBlockRoot);
925
+ metrics?.blockProductionSlotDelta.set(slot - parentSlot);
926
+ metrics?.blockProductionRequests.inc({source});
927
+
928
+ const graffitiBytes = toGraffitiBytes(
929
+ graffiti ?? getDefaultGraffiti(getLodestarClientVersion(), chain.executionEngine.clientVersion, {})
930
+ );
931
+ const commonBlockBodyPromise = chain.produceCommonBlockBody({
932
+ slot,
933
+ parentBlock,
934
+ randaoReveal,
935
+ graffiti: graffitiBytes,
936
+ });
937
+
938
+ let timer: undefined | ((opts: {source: ProducedBlockSource}) => number);
939
+ try {
940
+ timer = metrics?.blockProductionTime.startTimer();
941
+ const {block, executionPayloadValue, consensusBlockValue} = await chain.produceBlock({
942
+ slot,
943
+ parentBlock,
944
+ randaoReveal,
945
+ graffiti: graffitiBytes,
946
+ feeRecipient,
947
+ commonBlockBodyPromise,
948
+ });
949
+
950
+ metrics?.blockProductionSuccess.inc({source});
951
+ metrics?.blockProductionNumAggregated.observe({source}, block.body.attestations.length);
952
+ metrics?.blockProductionConsensusBlockValue.observe({source}, Number(formatWeiToEth(consensusBlockValue)));
953
+ metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(formatWeiToEth(executionPayloadValue)));
954
+
955
+ const blockRoot = toRootHex(config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block));
956
+ logger.verbose("Produced block", {
957
+ slot,
958
+ executionPayloadValue,
959
+ consensusBlockValue,
960
+ root: blockRoot,
961
+ });
962
+ if (chain.opts.persistProducedBlocks) {
963
+ void chain.persistBlock(block, "produced_engine_block");
964
+ }
965
+
966
+ return {
967
+ data: block as gloas.BeaconBlock,
968
+ meta: {
969
+ version: fork,
970
+ consensusBlockValue,
971
+ },
972
+ };
973
+ } finally {
974
+ timer?.({source});
975
+ }
976
+ },
977
+
904
978
  async produceAttestationData({committeeIndex, slot}) {
905
979
  notWhileSyncing();
906
980
 
@@ -1532,5 +1606,54 @@ export function getValidatorApi(
1532
1606
  count: filteredRegistrations.length,
1533
1607
  });
1534
1608
  },
1609
+
1610
+ async getExecutionPayloadEnvelope({slot, beaconBlockRoot}) {
1611
+ const fork = config.getForkName(slot);
1612
+
1613
+ if (!isForkPostGloas(fork)) {
1614
+ throw new ApiError(400, `getExecutionPayloadEnvelope not supported for pre-gloas fork=${fork}`);
1615
+ }
1616
+
1617
+ notWhileSyncing();
1618
+ await waitForSlot(slot);
1619
+
1620
+ const blockRootHex = toRootHex(beaconBlockRoot);
1621
+ const produceResult = chain.blockProductionCache.get(blockRootHex);
1622
+
1623
+ if (produceResult === undefined) {
1624
+ throw new ApiError(404, `No cached block production result found for block root ${blockRootHex}`);
1625
+ }
1626
+ if (!isForkPostGloas(produceResult.fork)) {
1627
+ throw Error(`Cached block production result is for pre-gloas fork=${produceResult.fork}`);
1628
+ }
1629
+ if (produceResult.type !== BlockType.Full) {
1630
+ throw Error("Cached block production result is not full block");
1631
+ }
1632
+
1633
+ const {executionPayload, executionRequests, envelopeStateRoot} = produceResult as ProduceFullGloas;
1634
+
1635
+ const envelope: gloas.ExecutionPayloadEnvelope = {
1636
+ payload: executionPayload,
1637
+ executionRequests: executionRequests,
1638
+ builderIndex: BUILDER_INDEX_SELF_BUILD,
1639
+ beaconBlockRoot,
1640
+ slot,
1641
+ stateRoot: envelopeStateRoot,
1642
+ };
1643
+
1644
+ logger.info("Produced execution payload envelope", {
1645
+ slot,
1646
+ blockRoot: blockRootHex,
1647
+ transactions: executionPayload.transactions.length,
1648
+ blockHash: toRootHex(executionPayload.blockHash),
1649
+ });
1650
+
1651
+ return {
1652
+ data: envelope,
1653
+ meta: {
1654
+ version: fork,
1655
+ },
1656
+ };
1657
+ },
1535
1658
  };
1536
1659
  }
@@ -1,5 +1,6 @@
1
1
  import {CheckpointWithHex} from "@lodestar/fork-choice";
2
2
  import {LoggerNode} from "@lodestar/logger/node";
3
+ import {ForkSeq} from "@lodestar/params";
3
4
  import {Checkpoint} from "@lodestar/types/phase0";
4
5
  import {callFnWhenAwait} from "@lodestar/utils";
5
6
  import {IBeaconDb} from "../../db/index.js";
@@ -13,6 +14,7 @@ import {HistoricalStateRegen} from "./historicalState/historicalStateRegen.js";
13
14
  import {ArchiveMode, ArchiveStoreOpts, StateArchiveStrategy} from "./interface.js";
14
15
  import {FrequencyStateArchiveStrategy} from "./strategies/frequencyStateArchiveStrategy.js";
15
16
  import {archiveBlocks} from "./utils/archiveBlocks.js";
17
+ import {archiveExecutionPayloadEnvelopes} from "./utils/archivePayloads.js";
16
18
  import {pruneHistory} from "./utils/pruneHistory.js";
17
19
  import {updateBackfillRange} from "./utils/updateBackfillRange.js";
18
20
 
@@ -27,6 +29,7 @@ type ArchiveStoreInitOpts = ArchiveStoreOpts & {dbName: string; anchorState: {fi
27
29
 
28
30
  export enum ArchiveStoreTask {
29
31
  ArchiveBlocks = "archive_blocks",
32
+ ArchivePayloads = "archive_payloads",
30
33
  PruneHistory = "prune_history",
31
34
  OnFinalizedCheckpoint = "on_finalized_checkpoint",
32
35
  MaybeArchiveState = "maybe_archive_state",
@@ -189,6 +192,7 @@ export class ArchiveStore {
189
192
  private processFinalizedCheckpoint = async (finalized: CheckpointWithHex): Promise<void> => {
190
193
  try {
191
194
  const finalizedEpoch = finalized.epoch;
195
+ const finalizedFork = this.chain.config.getForkSeqAtEpoch(finalizedEpoch);
192
196
  this.logger.verbose("Start processing finalized checkpoint", {epoch: finalizedEpoch, rootHex: finalized.rootHex});
193
197
 
194
198
  let timer = this.metrics?.processFinalizedCheckpoint.durationByTask.startTimer();
@@ -206,6 +210,12 @@ export class ArchiveStore {
206
210
  );
207
211
  timer?.({source: ArchiveStoreTask.ArchiveBlocks});
208
212
 
213
+ if (finalizedFork >= ForkSeq.gloas) {
214
+ timer = this.metrics?.processFinalizedCheckpoint.durationByTask.startTimer();
215
+ await archiveExecutionPayloadEnvelopes(this.chain, finalized);
216
+ timer?.({source: ArchiveStoreTask.ArchivePayloads});
217
+ }
218
+
209
219
  if (this.opts.pruneHistory) {
210
220
  timer = this.metrics?.processFinalizedCheckpoint.durationByTask.startTimer();
211
221
  await pruneHistory(
@@ -0,0 +1,15 @@
1
+ import {CheckpointWithHex} from "@lodestar/fork-choice";
2
+ import {IBeaconChain} from "../../interface.js";
3
+
4
+ /**
5
+ * Archives execution payload envelopes from hot DB to archive DB after finalization.
6
+ */
7
+ export async function archiveExecutionPayloadEnvelopes(
8
+ chain: IBeaconChain,
9
+ _finalized: CheckpointWithHex
10
+ ): Promise<void> {
11
+ const finalizedBlock = chain.forkChoice.getFinalizedBlock();
12
+ if (!finalizedBlock) return;
13
+
14
+ // TODO GLOAS: Implement payload envelope archival after epbs fork choice changes are merged
15
+ }
@@ -101,9 +101,6 @@ export async function importBlock(
101
101
  }
102
102
  });
103
103
 
104
- // Without forcefully clearing this cache, we would rely on WeakMap to evict memory which is not reliable
105
- this.serializedCache.clear();
106
-
107
104
  // 2. Import block to fork choice
108
105
 
109
106
  // Should compute checkpoint balances before forkchoice.onBlock
@@ -1,6 +1,7 @@
1
1
  import {SignedBeaconBlock} from "@lodestar/types";
2
2
  import {isErrorAborted, toRootHex} from "@lodestar/utils";
3
3
  import {Metrics} from "../../metrics/metrics.js";
4
+ import {nextEventLoop} from "../../util/eventLoop.js";
4
5
  import {JobItemQueue, isQueueErrorAborted} from "../../util/queue/index.js";
5
6
  import type {BeaconChain} from "../chain.js";
6
7
  import {BlockError, BlockErrorCode, isBlockErrorAborted} from "../errors/index.js";
@@ -100,9 +101,9 @@ export async function processBlocks(
100
101
  );
101
102
 
102
103
  for (const fullyVerifiedBlock of fullyVerifiedBlocks) {
103
- // No need to sleep(0) here since `importBlock` includes a disk write
104
104
  // TODO: Consider batching importBlock too if it takes significant time
105
105
  await importBlock.call(this, fullyVerifiedBlock, opts);
106
+ await nextEventLoop();
106
107
  }
107
108
  } catch (e) {
108
109
  if (isErrorAborted(e) || isQueueErrorAborted(e) || isBlockErrorAborted(e)) {
@@ -125,6 +125,9 @@ export async function persistBlockInputs(this: BeaconChain, blockInputs: IBlockI
125
125
  for (const blockInput of blockInputs) {
126
126
  this.seenBlockInputCache.prune(blockInput.blockRootHex);
127
127
  }
128
+ // Without forcefully clearing this cache, we would rely on WeakMap to evict memory which is not reliable.
129
+ // Clear here (after the DB write) so that writeBlockInputToDb can still use the cached serialized bytes.
130
+ this.serializedCache.clear();
128
131
  if (blockInputs.length === 1) {
129
132
  this.logger.debug("Pruned block input", {
130
133
  slot: blockInputs[0].slot,
@@ -5,11 +5,20 @@ import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
5
5
  import {BeaconConfig} from "@lodestar/config";
6
6
  import {CheckpointWithHex, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice";
7
7
  import {LoggerNode} from "@lodestar/logger/node";
8
- import {EFFECTIVE_BALANCE_INCREMENT, GENESIS_SLOT, SLOTS_PER_EPOCH, isForkPostElectra} from "@lodestar/params";
8
+ import {
9
+ BUILDER_INDEX_SELF_BUILD,
10
+ EFFECTIVE_BALANCE_INCREMENT,
11
+ ForkPostFulu,
12
+ GENESIS_SLOT,
13
+ SLOTS_PER_EPOCH,
14
+ isForkPostElectra,
15
+ isForkPostGloas,
16
+ } from "@lodestar/params";
9
17
  import {
10
18
  BeaconStateAllForks,
11
19
  BeaconStateElectra,
12
20
  CachedBeaconStateAllForks,
21
+ CachedBeaconStateGloas,
13
22
  EffectiveBalanceIncrements,
14
23
  EpochShuffling,
15
24
  Index2PubkeyCache,
@@ -28,6 +37,7 @@ import {
28
37
  BeaconBlock,
29
38
  BlindedBeaconBlock,
30
39
  BlindedBeaconBlockBody,
40
+ DataColumnSidecars,
31
41
  Epoch,
32
42
  Root,
33
43
  RootHex,
@@ -38,7 +48,7 @@ import {
38
48
  ValidatorIndex,
39
49
  Wei,
40
50
  deneb,
41
- fulu,
51
+ gloas,
42
52
  isBlindedBeaconBlock,
43
53
  phase0,
44
54
  rewards,
@@ -87,8 +97,8 @@ import {
87
97
  } from "./opPools/index.js";
88
98
  import {IChainOptions} from "./options.js";
89
99
  import {PrepareNextSlotScheduler} from "./prepareNextSlot.js";
90
- import {computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js";
91
- import {AssembledBlockType, BlockType, ProduceResult} from "./produceBlock/index.js";
100
+ import {computeEnvelopeStateRoot, computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js";
101
+ import {AssembledBlockType, BlockType, ProduceFullGloas, ProduceResult} from "./produceBlock/index.js";
92
102
  import {BlockAttributes, produceBlockBody, produceCommonBlockBody} from "./produceBlock/produceBlockBody.js";
93
103
  import {QueuedStateRegenerator, RegenCaller} from "./regen/index.js";
94
104
  import {ReprocessController} from "./reprocess.js";
@@ -808,7 +818,7 @@ export class BeaconChain implements IBeaconChain {
808
818
  return null;
809
819
  }
810
820
 
811
- async getDataColumnSidecars(blockSlot: Slot, blockRootHex: string): Promise<fulu.DataColumnSidecars> {
821
+ async getDataColumnSidecars(blockSlot: Slot, blockRootHex: string): Promise<DataColumnSidecars> {
812
822
  const blockInput = this.seenBlockInputCache.get(blockRootHex);
813
823
  if (blockInput) {
814
824
  if (!isBlockInputColumns(blockInput)) {
@@ -818,10 +828,10 @@ export class BeaconChain implements IBeaconChain {
818
828
  }
819
829
  const sidecarsUnfinalized = await this.db.dataColumnSidecar.values(fromHex(blockRootHex));
820
830
  if (sidecarsUnfinalized.length > 0) {
821
- return sidecarsUnfinalized;
831
+ return sidecarsUnfinalized as DataColumnSidecars;
822
832
  }
823
833
  const sidecarsFinalized = await this.db.dataColumnSidecarArchive.values(blockSlot);
824
- return sidecarsFinalized;
834
+ return sidecarsFinalized as DataColumnSidecars;
825
835
  }
826
836
 
827
837
  async getSerializedDataColumnSidecars(
@@ -843,7 +853,7 @@ export class BeaconChain implements IBeaconChain {
843
853
  if (serialized) {
844
854
  return serialized;
845
855
  }
846
- return ssz.fulu.DataColumnSidecar.serialize(sidecar);
856
+ return sszTypesFor(blockInput.forkName as ForkPostFulu).DataColumnSidecar.serialize(sidecar);
847
857
  });
848
858
  }
849
859
  const sidecarsUnfinalized = await this.db.dataColumnSidecar.getManyBinary(fromHex(blockRootHex), indices);
@@ -902,6 +912,7 @@ export class BeaconChain implements IBeaconChain {
902
912
  consensusBlockValue: Wei;
903
913
  shouldOverrideBuilder?: boolean;
904
914
  }> {
915
+ const fork = this.config.getForkName(slot);
905
916
  const state = await this.regen.getBlockSlotState(
906
917
  parentBlock,
907
918
  slot,
@@ -930,7 +941,7 @@ export class BeaconChain implements IBeaconChain {
930
941
  // The hashtree root computed here for debug log will get cached and hence won't introduce additional delays
931
942
  const bodyRoot =
932
943
  produceResult.type === BlockType.Full
933
- ? this.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(body)
944
+ ? sszTypesFor(fork).BeaconBlockBody.hashTreeRoot(body)
934
945
  : this.config
935
946
  .getPostBellatrixForkTypes(slot)
936
947
  .BlindedBeaconBlockBody.hashTreeRoot(body as BlindedBeaconBlockBody);
@@ -948,14 +959,33 @@ export class BeaconChain implements IBeaconChain {
948
959
  body,
949
960
  } as AssembledBlockType<T>;
950
961
 
951
- const {newStateRoot, proposerReward} = computeNewStateRoot(this.metrics, state, block);
962
+ const {newStateRoot, proposerReward, postState} = computeNewStateRoot(this.metrics, state, block);
952
963
  block.stateRoot = newStateRoot;
953
964
  const blockRoot =
954
965
  produceResult.type === BlockType.Full
955
- ? this.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block)
966
+ ? sszTypesFor(fork).BeaconBlock.hashTreeRoot(block)
956
967
  : this.config.getPostBellatrixForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block as BlindedBeaconBlock);
957
968
  const blockRootHex = toRootHex(blockRoot);
958
969
 
970
+ if (isForkPostGloas(fork)) {
971
+ // TODO GLOAS: we should retire BlockType post-gloas, may need a new enum for self vs non-self built
972
+ if (produceResult.type !== BlockType.Full) {
973
+ throw Error(`Unexpected block type=${produceResult.type} for post-gloas fork=${fork}`);
974
+ }
975
+
976
+ const gloasResult = produceResult as ProduceFullGloas;
977
+ const envelope: gloas.ExecutionPayloadEnvelope = {
978
+ payload: gloasResult.executionPayload,
979
+ executionRequests: gloasResult.executionRequests,
980
+ builderIndex: BUILDER_INDEX_SELF_BUILD,
981
+ beaconBlockRoot: blockRoot,
982
+ slot,
983
+ stateRoot: ZERO_HASH,
984
+ };
985
+ const envelopeStateRoot = computeEnvelopeStateRoot(this.metrics, postState as CachedBeaconStateGloas, envelope);
986
+ gloasResult.envelopeStateRoot = envelopeStateRoot;
987
+ }
988
+
959
989
  // Track the produced block for consensus broadcast validations, later validation, etc.
960
990
  this.blockProductionCache.set(blockRootHex, produceResult);
961
991
  this.metrics?.blockProductionCacheSize.set(this.blockProductionCache.size);
@@ -3,7 +3,7 @@ import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {routes} from "@lodestar/api";
4
4
  import {CheckpointWithHex} from "@lodestar/fork-choice";
5
5
  import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
6
- import {RootHex, deneb, fulu, phase0} from "@lodestar/types";
6
+ import {DataColumnSidecars, RootHex, deneb, phase0} from "@lodestar/types";
7
7
  import {PeerIdStr} from "../util/peerId.js";
8
8
  import {BlockInputSource, IBlockInput} from "./blocks/blockInput/types.js";
9
9
 
@@ -88,7 +88,7 @@ export type IChainEvents = ApiEvents & {
88
88
 
89
89
  [ChainEvent.updateTargetCustodyGroupCount]: (targetGroupCount: number) => void;
90
90
 
91
- [ChainEvent.publishDataColumns]: (sidecars: fulu.DataColumnSidecar[]) => void;
91
+ [ChainEvent.publishDataColumns]: (sidecars: DataColumnSidecars) => void;
92
92
 
93
93
  [ChainEvent.publishBlobSidecars]: (sidecars: deneb.BlobSidecar[]) => void;
94
94
 
@@ -11,6 +11,7 @@ import {
11
11
  import {
12
12
  BeaconBlock,
13
13
  BlindedBeaconBlock,
14
+ DataColumnSidecars,
14
15
  Epoch,
15
16
  Root,
16
17
  RootHex,
@@ -23,7 +24,6 @@ import {
23
24
  altair,
24
25
  capella,
25
26
  deneb,
26
- fulu,
27
27
  phase0,
28
28
  rewards,
29
29
  } from "@lodestar/types";
@@ -224,7 +224,7 @@ export interface IBeaconChain {
224
224
  ): Promise<{block: SignedBeaconBlock; executionOptimistic: boolean; finalized: boolean} | null>;
225
225
  getBlobSidecars(blockSlot: Slot, blockRootHex: string): Promise<deneb.BlobSidecars | null>;
226
226
  getSerializedBlobSidecars(blockSlot: Slot, blockRootHex: string): Promise<Uint8Array | null>;
227
- getDataColumnSidecars(blockSlot: Slot, blockRootHex: string): Promise<fulu.DataColumnSidecars>;
227
+ getDataColumnSidecars(blockSlot: Slot, blockRootHex: string): Promise<DataColumnSidecars>;
228
228
  getSerializedDataColumnSidecars(
229
229
  blockSlot: Slot,
230
230
  blockRootHex: string,
@@ -355,7 +355,10 @@ export class LightClientServer {
355
355
  // Signature data
356
356
  const update = await this.db.bestLightClientUpdate.get(period);
357
357
  if (!update) {
358
- throw Error(`No partialUpdate available for period ${period}`);
358
+ throw new LightClientServerError(
359
+ {code: LightClientServerErrorCode.RESOURCE_UNAVAILABLE},
360
+ `No partialUpdate available for period ${period}`
361
+ );
359
362
  }
360
363
  return update;
361
364
  }
@@ -27,6 +27,7 @@ export type IChainOptions = BlockProcessOpts &
27
27
  blsVerifyAllMainThread?: boolean;
28
28
  blsVerifyAllMultiThread?: boolean;
29
29
  blacklistedBlocks?: string[];
30
+ // TODO GLOAS: add similar option for execution payload envelopes?
30
31
  persistProducedBlocks?: boolean;
31
32
  persistInvalidSszObjects?: boolean;
32
33
  persistInvalidSszObjectsDir?: string;
@@ -1,14 +1,14 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {getSafeExecutionBlockHash} from "@lodestar/fork-choice";
4
- import {ForkPostBellatrix, ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
4
+ import {ForkPostBellatrix, ForkSeq, SLOTS_PER_EPOCH, isForkPostBellatrix} from "@lodestar/params";
5
5
  import {
6
6
  CachedBeaconStateAllForks,
7
7
  CachedBeaconStateExecutions,
8
+ CachedBeaconStateGloas,
8
9
  StateHashTreeRootSource,
9
10
  computeEpochAtSlot,
10
11
  computeTimeAtSlot,
11
- isExecutionStateType,
12
12
  } from "@lodestar/state-transition";
13
13
  import {Slot} from "@lodestar/types";
14
14
  import {Logger, fromHex, isErrorAborted, sleep} from "@lodestar/utils";
@@ -120,10 +120,10 @@ export class PrepareNextSlotScheduler {
120
120
  RegenCaller.precomputeEpoch
121
121
  );
122
122
 
123
- if (isExecutionStateType(prepareState)) {
123
+ if (isForkPostBellatrix(fork)) {
124
124
  const proposerIndex = prepareState.epochCtx.getBeaconProposer(prepareSlot);
125
125
  const feeRecipient = this.chain.beaconProposerCache.get(proposerIndex);
126
- let updatedPrepareState = prepareState;
126
+ let updatedPrepareState = prepareState as CachedBeaconStateExecutions | CachedBeaconStateGloas;
127
127
  let updatedHeadRoot = headRoot;
128
128
 
129
129
  if (feeRecipient) {
@@ -146,7 +146,7 @@ export class PrepareNextSlotScheduler {
146
146
  // only transfer cache if epoch transition because that's the state we will use to stateTransition() the 1st block of epoch
147
147
  {dontTransferCache: !isEpochTransition},
148
148
  RegenCaller.predictProposerHead
149
- )) as CachedBeaconStateExecutions;
149
+ )) as CachedBeaconStateExecutions | CachedBeaconStateGloas;
150
150
  updatedHeadRoot = proposerHeadRoot;
151
151
  }
152
152
 
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  CachedBeaconStateAllForks,
3
+ CachedBeaconStateGloas,
3
4
  DataAvailabilityStatus,
4
5
  ExecutionPayloadStatus,
6
+ G2_POINT_AT_INFINITY,
5
7
  StateHashTreeRootSource,
6
8
  stateTransition,
7
9
  } from "@lodestar/state-transition";
8
- import {BeaconBlock, BlindedBeaconBlock, Gwei, Root} from "@lodestar/types";
10
+ import {processExecutionPayloadEnvelope} from "@lodestar/state-transition/block";
11
+ import {BeaconBlock, BlindedBeaconBlock, Gwei, Root, gloas} from "@lodestar/types";
9
12
  import {ZERO_HASH} from "../../constants/index.js";
10
13
  import {Metrics} from "../../metrics/index.js";
11
14
 
@@ -18,7 +21,7 @@ export function computeNewStateRoot(
18
21
  metrics: Metrics | null,
19
22
  state: CachedBeaconStateAllForks,
20
23
  block: BeaconBlock | BlindedBeaconBlock
21
- ): {newStateRoot: Root; proposerReward: Gwei} {
24
+ ): {newStateRoot: Root; proposerReward: Gwei; postState: CachedBeaconStateAllForks} {
22
25
  // Set signature to zero to re-use stateTransition() function which requires the SignedBeaconBlock type
23
26
  const blockEmptySig = {message: block, signature: ZERO_HASH};
24
27
 
@@ -51,5 +54,34 @@ export function computeNewStateRoot(
51
54
  const newStateRoot = postState.hashTreeRoot();
52
55
  hashTreeRootTimer?.();
53
56
 
54
- return {newStateRoot, proposerReward};
57
+ return {newStateRoot, proposerReward, postState};
58
+ }
59
+
60
+ /**
61
+ * Compute the state root after processing an execution payload envelope.
62
+ * Similar to `computeNewStateRoot` but for payload envelope processing.
63
+ *
64
+ * The `postBlockState` is mutated in place, callers must ensure it is not needed afterward.
65
+ */
66
+ export function computeEnvelopeStateRoot(
67
+ metrics: Metrics | null,
68
+ postBlockState: CachedBeaconStateGloas,
69
+ envelope: gloas.ExecutionPayloadEnvelope
70
+ ): Root {
71
+ const signedEnvelope: gloas.SignedExecutionPayloadEnvelope = {
72
+ message: envelope,
73
+ signature: G2_POINT_AT_INFINITY,
74
+ };
75
+
76
+ const processEnvelopeTimer = metrics?.blockPayload.executionPayloadEnvelopeProcessingTime.startTimer();
77
+ processExecutionPayloadEnvelope(postBlockState, signedEnvelope, false);
78
+ processEnvelopeTimer?.();
79
+
80
+ const hashTreeRootTimer = metrics?.stateHashTreeRootTime.startTimer({
81
+ source: StateHashTreeRootSource.computeEnvelopeStateRoot,
82
+ });
83
+ const stateRoot = postBlockState.hashTreeRoot();
84
+ hashTreeRootTimer?.();
85
+
86
+ return stateRoot;
55
87
  }