@lodestar/beacon-node 1.43.0-rc.5 → 1.44.0-dev.055b83cb3d

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 (128) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +30 -0
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +46 -5
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/validator/index.d.ts.map +1 -1
  8. package/lib/api/impl/validator/index.js +103 -49
  9. package/lib/api/impl/validator/index.js.map +1 -1
  10. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  11. package/lib/chain/blocks/importBlock.js +5 -2
  12. package/lib/chain/blocks/importBlock.js.map +1 -1
  13. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  14. package/lib/chain/blocks/importExecutionPayload.js +4 -2
  15. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  16. package/lib/chain/chain.d.ts +3 -2
  17. package/lib/chain/chain.d.ts.map +1 -1
  18. package/lib/chain/chain.js +5 -2
  19. package/lib/chain/chain.js.map +1 -1
  20. package/lib/chain/errors/executionPayloadBid.d.ts +24 -1
  21. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  22. package/lib/chain/errors/executionPayloadBid.js +4 -0
  23. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  24. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  25. package/lib/chain/forkChoice/index.js +14 -4
  26. package/lib/chain/forkChoice/index.js.map +1 -1
  27. package/lib/chain/interface.d.ts +2 -1
  28. package/lib/chain/interface.d.ts.map +1 -1
  29. package/lib/chain/interface.js.map +1 -1
  30. package/lib/chain/lightClient/index.d.ts.map +1 -1
  31. package/lib/chain/lightClient/index.js +1 -1
  32. package/lib/chain/lightClient/index.js.map +1 -1
  33. package/lib/chain/opPools/executionPayloadBidPool.d.ts +4 -4
  34. package/lib/chain/opPools/executionPayloadBidPool.d.ts.map +1 -1
  35. package/lib/chain/opPools/executionPayloadBidPool.js +6 -4
  36. package/lib/chain/opPools/executionPayloadBidPool.js.map +1 -1
  37. package/lib/chain/opPools/index.d.ts +1 -0
  38. package/lib/chain/opPools/index.d.ts.map +1 -1
  39. package/lib/chain/opPools/index.js +1 -0
  40. package/lib/chain/opPools/index.js.map +1 -1
  41. package/lib/chain/opPools/payloadAttestationPool.d.ts +1 -1
  42. package/lib/chain/opPools/payloadAttestationPool.d.ts.map +1 -1
  43. package/lib/chain/opPools/payloadAttestationPool.js +30 -10
  44. package/lib/chain/opPools/payloadAttestationPool.js.map +1 -1
  45. package/lib/chain/opPools/proposerPreferencesPool.d.ts +29 -0
  46. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -0
  47. package/lib/chain/opPools/proposerPreferencesPool.js +56 -0
  48. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -0
  49. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  50. package/lib/chain/prepareNextSlot.js +2 -1
  51. package/lib/chain/prepareNextSlot.js.map +1 -1
  52. package/lib/chain/produceBlock/produceBlockBody.d.ts +7 -1
  53. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  54. package/lib/chain/produceBlock/produceBlockBody.js +107 -18
  55. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  56. package/lib/chain/validation/executionPayloadBid.d.ts +7 -3
  57. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  58. package/lib/chain/validation/executionPayloadBid.js +87 -23
  59. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  60. package/lib/chain/validation/payloadAttestationMessage.d.ts +1 -1
  61. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  62. package/lib/chain/validation/payloadAttestationMessage.js +5 -3
  63. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  64. package/lib/chain/validatorMonitor.d.ts +1 -0
  65. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  66. package/lib/chain/validatorMonitor.js +16 -0
  67. package/lib/chain/validatorMonitor.js.map +1 -1
  68. package/lib/execution/builder/index.d.ts +1 -2
  69. package/lib/execution/builder/index.d.ts.map +1 -1
  70. package/lib/execution/builder/index.js +0 -1
  71. package/lib/execution/builder/index.js.map +1 -1
  72. package/lib/execution/engine/interface.d.ts +1 -0
  73. package/lib/execution/engine/interface.d.ts.map +1 -1
  74. package/lib/execution/engine/types.d.ts +2 -0
  75. package/lib/execution/engine/types.d.ts.map +1 -1
  76. package/lib/execution/engine/types.js +2 -0
  77. package/lib/execution/engine/types.js.map +1 -1
  78. package/lib/metrics/metrics/lodestar.d.ts +1 -1
  79. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  80. package/lib/metrics/metrics/lodestar.js +4 -3
  81. package/lib/metrics/metrics/lodestar.js.map +1 -1
  82. package/lib/network/gossip/topic.d.ts +1 -1
  83. package/lib/network/interface.d.ts +2 -0
  84. package/lib/network/interface.d.ts.map +1 -1
  85. package/lib/network/network.d.ts +2 -0
  86. package/lib/network/network.d.ts.map +1 -1
  87. package/lib/network/network.js +10 -0
  88. package/lib/network/network.js.map +1 -1
  89. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  90. package/lib/network/processor/gossipHandlers.js +19 -6
  91. package/lib/network/processor/gossipHandlers.js.map +1 -1
  92. package/lib/util/dependentRoot.d.ts +6 -2
  93. package/lib/util/dependentRoot.d.ts.map +1 -1
  94. package/lib/util/dependentRoot.js +20 -16
  95. package/lib/util/dependentRoot.js.map +1 -1
  96. package/package.json +14 -15
  97. package/src/api/impl/beacon/blocks/index.ts +36 -0
  98. package/src/api/impl/beacon/pool/index.ts +58 -4
  99. package/src/api/impl/validator/index.ts +118 -50
  100. package/src/chain/blocks/importBlock.ts +9 -2
  101. package/src/chain/blocks/importExecutionPayload.ts +7 -1
  102. package/src/chain/chain.ts +5 -0
  103. package/src/chain/errors/executionPayloadBid.ts +25 -1
  104. package/src/chain/forkChoice/index.ts +14 -4
  105. package/src/chain/interface.ts +2 -0
  106. package/src/chain/lightClient/index.ts +6 -6
  107. package/src/chain/opPools/executionPayloadBidPool.ts +10 -9
  108. package/src/chain/opPools/index.ts +1 -0
  109. package/src/chain/opPools/payloadAttestationPool.ts +34 -10
  110. package/src/chain/opPools/proposerPreferencesPool.ts +59 -0
  111. package/src/chain/prepareNextSlot.ts +2 -1
  112. package/src/chain/produceBlock/produceBlockBody.ts +158 -25
  113. package/src/chain/validation/executionPayloadBid.ts +96 -28
  114. package/src/chain/validation/payloadAttestationMessage.ts +6 -4
  115. package/src/chain/validatorMonitor.ts +18 -0
  116. package/src/execution/builder/index.ts +1 -4
  117. package/src/execution/engine/interface.ts +1 -0
  118. package/src/execution/engine/types.ts +4 -0
  119. package/src/metrics/metrics/lodestar.ts +4 -3
  120. package/src/network/interface.ts +2 -0
  121. package/src/network/network.ts +22 -0
  122. package/src/network/processor/gossipHandlers.ts +24 -6
  123. package/src/util/dependentRoot.ts +22 -18
  124. package/lib/execution/builder/utils.d.ts +0 -5
  125. package/lib/execution/builder/utils.d.ts.map +0 -1
  126. package/lib/execution/builder/utils.js +0 -17
  127. package/lib/execution/builder/utils.js.map +0 -1
  128. package/src/execution/builder/utils.ts +0 -19
@@ -1,6 +1,7 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ApplicationMethods} from "@lodestar/api/server";
3
3
  import {
4
+ ForkName,
4
5
  ForkPostElectra,
5
6
  ForkPreElectra,
6
7
  SYNC_COMMITTEE_SUBNET_SIZE,
@@ -16,12 +17,15 @@ import {
16
17
  GossipAction,
17
18
  PayloadAttestationError,
18
19
  PayloadAttestationErrorCode,
20
+ ProposerPreferencesError,
21
+ ProposerPreferencesErrorCode,
19
22
  SyncCommitteeError,
20
23
  } from "../../../../chain/errors/index.js";
21
24
  import {validateApiAttesterSlashing} from "../../../../chain/validation/attesterSlashing.js";
22
25
  import {validateApiBlsToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js";
23
26
  import {toElectraSingleAttestation, validateApiAttestation} from "../../../../chain/validation/index.js";
24
27
  import {validateApiPayloadAttestationMessage} from "../../../../chain/validation/payloadAttestationMessage.js";
28
+ import {validateGossipProposerPreferences} from "../../../../chain/validation/proposerPreferences.js";
25
29
  import {validateApiProposerSlashing} from "../../../../chain/validation/proposerSlashing.js";
26
30
  import {validateApiSyncCommittee} from "../../../../chain/validation/syncCommittee.js";
27
31
  import {validateApiVoluntaryExit} from "../../../../chain/validation/voluntaryExit.js";
@@ -81,6 +85,55 @@ export function getBeaconPoolApi({
81
85
  return {data: chain.payloadAttestationPool.getAll(slot), meta: {version: fork}};
82
86
  },
83
87
 
88
+ async getPoolProposerPreferences({slot}) {
89
+ const fork = chain.config.getForkName(slot ?? chain.clock.currentSlot);
90
+ if (!isForkPostGloas(fork)) {
91
+ throw new ApiError(400, `Proposer preferences pool is not supported before Gloas fork=${fork}`);
92
+ }
93
+
94
+ return {data: chain.proposerPreferencesPool.getAll(slot), meta: {version: fork}};
95
+ },
96
+
97
+ async submitSignedProposerPreferences({signedProposerPreferences}) {
98
+ const failures: FailureList = [];
99
+
100
+ await Promise.all(
101
+ signedProposerPreferences.map(async (signed, i) => {
102
+ try {
103
+ await validateGossipProposerPreferences(chain, signed);
104
+
105
+ chain.proposerPreferencesPool.add(signed);
106
+ await network.publishProposerPreferences(signed);
107
+ chain.emitter.emit(routes.events.EventType.proposerPreferences, {
108
+ version: ForkName.gloas,
109
+ data: signed,
110
+ });
111
+ } catch (e) {
112
+ const logCtx = {
113
+ slot: signed.message.proposalSlot,
114
+ validatorIndex: signed.message.validatorIndex,
115
+ dependentRoot: toRootHex(signed.message.dependentRoot),
116
+ };
117
+
118
+ if (e instanceof ProposerPreferencesError && e.type.code === ProposerPreferencesErrorCode.ALREADY_KNOWN) {
119
+ logger.debug("Ignoring known signed proposer preferences", logCtx);
120
+ return;
121
+ }
122
+
123
+ failures.push({index: i, message: (e as Error).message});
124
+ logger.verbose(`Error on submitSignedProposerPreferences [${i}]`, logCtx, e as Error);
125
+ if (e instanceof ProposerPreferencesError && e.action === GossipAction.REJECT) {
126
+ chain.persistInvalidSszValue(ssz.gloas.SignedProposerPreferences, signed, "api_reject");
127
+ }
128
+ }
129
+ })
130
+ );
131
+
132
+ if (failures.length > 0) {
133
+ throw new IndexedError("Error processing signed proposer preferences", failures);
134
+ }
135
+ },
136
+
84
137
  async getPoolAttesterSlashings() {
85
138
  const fork = chain.config.getForkName(chain.clock.currentSlot);
86
139
 
@@ -258,7 +311,7 @@ export function getBeaconPoolApi({
258
311
  try {
259
312
  const validateFn = () => validateApiPayloadAttestationMessage(chain, payloadAttestationMessage);
260
313
  const {slot, beaconBlockRoot} = payloadAttestationMessage.data;
261
- const {attDataRootHex, validatorCommitteeIndex} = await validateGossipFnRetryUnknownRoot(
314
+ const {attDataRootHex, validatorCommitteeIndices} = await validateGossipFnRetryUnknownRoot(
262
315
  validateFn,
263
316
  network,
264
317
  chain,
@@ -269,14 +322,15 @@ export function getBeaconPoolApi({
269
322
  const insertOutcome = chain.payloadAttestationPool.add(
270
323
  payloadAttestationMessage,
271
324
  attDataRootHex,
272
- validatorCommitteeIndex
325
+ validatorCommitteeIndices
273
326
  );
274
327
  metrics?.opPool.payloadAttestationPool.apiInsertOutcome.inc({insertOutcome});
275
328
 
276
329
  chain.forkChoice.notifyPtcMessages(
277
330
  toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
278
- [validatorCommitteeIndex],
279
- payloadAttestationMessage.data.payloadPresent
331
+ validatorCommitteeIndices,
332
+ payloadAttestationMessage.data.payloadPresent,
333
+ payloadAttestationMessage.data.blobDataAvailable
280
334
  );
281
335
 
282
336
  await network.publishPayloadAttestationMessage(payloadAttestationMessage);
@@ -14,6 +14,7 @@ import {
14
14
  isForkPostBellatrix,
15
15
  isForkPostDeneb,
16
16
  isForkPostElectra,
17
+ isForkPostFulu,
17
18
  isForkPostGloas,
18
19
  } from "@lodestar/params";
19
20
  import {
@@ -913,20 +914,40 @@ export function getValidatorApi(
913
914
  notWhileSyncing();
914
915
  await waitForSlot(slot);
915
916
 
916
- // TODO GLOAS: support producing blocks from builder bids
917
- const source = ProducedBlockSource.engine;
918
-
919
- // TODO GLOAS: needs to be updated after fork choice changes are merged
920
917
  const parentBlock = chain.getProposerHead(slot);
921
918
  const {blockRoot: parentBlockRootHex, slot: parentSlot} = parentBlock;
922
919
  const parentBlockRoot = fromHex(parentBlockRootHex);
923
920
  notOnOutOfRangeData(parentBlockRoot);
924
921
  metrics?.blockProductionSlotDelta.set(slot - parentSlot);
925
- metrics?.blockProductionRequests.inc({source});
926
922
 
927
923
  const graffitiBytes = toGraffitiBytes(
928
- graffiti ?? getDefaultGraffiti(getLodestarClientVersion(), chain.executionEngine.clientVersion, {})
924
+ graffiti ?? getDefaultGraffiti(getLodestarClientVersion(opts), chain.executionEngine.clientVersion, opts)
925
+ );
926
+
927
+ // TODO GLOAS: respect builderSelection (MaxProfit, BuilderAlways, ExecutionAlways, etc.) to let
928
+ // the user control bid source preferences and value comparison. Also add external builder api
929
+ // support when it is implemented.
930
+ const builderBid = chain.executionPayloadBidPool.getBestBid(
931
+ slot,
932
+ parentBlock.executionPayloadBlockHash,
933
+ parentBlockRootHex
929
934
  );
935
+
936
+ const logCtx = {
937
+ slot,
938
+ parentSlot,
939
+ parentBlockRoot: parentBlockRootHex,
940
+ parentBlockHash: parentBlock.executionPayloadBlockHash,
941
+ fork,
942
+ ...(builderBid !== null
943
+ ? {
944
+ bidValue: builderBid.message.value,
945
+ builderIndex: builderBid.message.builderIndex,
946
+ bidBlockHash: toRootHex(builderBid.message.blockHash),
947
+ }
948
+ : {}),
949
+ };
950
+
930
951
  const commonBlockBodyPromise = chain.produceCommonBlockBody({
931
952
  slot,
932
953
  parentBlock,
@@ -934,44 +955,76 @@ export function getValidatorApi(
934
955
  graffiti: graffitiBytes,
935
956
  });
936
957
 
937
- let timer: undefined | ((opts: {source: ProducedBlockSource}) => number);
938
- try {
939
- timer = metrics?.blockProductionTime.startTimer();
940
- const {block, executionPayloadValue, consensusBlockValue} = await chain.produceBlock({
941
- slot,
942
- parentBlock,
943
- randaoReveal,
944
- graffiti: graffitiBytes,
945
- feeRecipient,
946
- commonBlockBodyPromise,
947
- });
958
+ const baseAttrs = {
959
+ slot,
960
+ parentBlock,
961
+ randaoReveal,
962
+ graffiti: graffitiBytes,
963
+ feeRecipient,
964
+ commonBlockBodyPromise,
965
+ };
948
966
 
949
- metrics?.blockProductionSuccess.inc({source});
950
- metrics?.blockProductionNumAggregated.observe({source}, block.body.attestations.length);
951
- metrics?.blockProductionConsensusBlockValue.observe({source}, Number(formatWeiToEth(consensusBlockValue)));
952
- metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(formatWeiToEth(executionPayloadValue)));
967
+ metrics?.blockProductionRequests.inc({source: ProducedBlockSource.engine});
968
+ if (builderBid !== null) {
969
+ metrics?.blockProductionRequests.inc({source: ProducedBlockSource.builder});
970
+ }
953
971
 
954
- const blockRoot = toRootHex(config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block));
955
- logger.verbose("Produced block", {
956
- slot,
957
- executionPayloadValue,
958
- consensusBlockValue,
959
- root: blockRoot,
960
- });
961
- if (chain.opts.persistProducedBlocks) {
962
- void chain.persistBlock(block, "produced_engine_block");
972
+ const timed = <T>(source: ProducedBlockSource, fn: () => Promise<T>): Promise<T> => {
973
+ const t = metrics?.blockProductionTime.startTimer();
974
+ return fn().finally(() => t?.({source}));
975
+ };
976
+
977
+ // Always build local block. If builder bid available, also build with it in parallel and prefer it.
978
+ const [engineResult, bidResult] = await Promise.allSettled([
979
+ timed(ProducedBlockSource.engine, () => chain.produceBlock(baseAttrs)),
980
+ builderBid !== null
981
+ ? timed(ProducedBlockSource.builder, () => chain.produceBlock({...baseAttrs, builderBid}))
982
+ : Promise.reject(),
983
+ ]);
984
+
985
+ let bestResult: typeof engineResult | null = null;
986
+ let source: ProducedBlockSource = ProducedBlockSource.engine;
987
+ if (builderBid !== null && bidResult.status === "fulfilled") {
988
+ source = ProducedBlockSource.builder;
989
+ bestResult = bidResult;
990
+ logger.info("Selected builder bid block", logCtx);
991
+ } else if (engineResult.status === "fulfilled") {
992
+ source = ProducedBlockSource.engine;
993
+ bestResult = engineResult;
994
+ if (builderBid !== null) {
995
+ logger.warn("Builder bid block production failed, using local block", logCtx);
963
996
  }
997
+ }
964
998
 
965
- return {
966
- data: block as gloas.BeaconBlock,
967
- meta: {
968
- version: fork,
969
- consensusBlockValue,
970
- },
971
- };
972
- } finally {
973
- timer?.({source});
999
+ if (bestResult === null || bestResult.status !== "fulfilled") {
1000
+ const engineReason = engineResult.status === "rejected" ? engineResult.reason : undefined;
1001
+ const bidReason = builderBid !== null && bidResult.status === "rejected" ? bidResult.reason : undefined;
1002
+ logger.error("Block production failed", {...logCtx, engineReason, bidReason});
1003
+ throw Error(`Block production failed: engine=${engineReason ?? "n/a"} builder=${bidReason ?? "n/a"}`);
1004
+ }
1005
+
1006
+ const {block, executionPayloadValue, consensusBlockValue} = bestResult.value;
1007
+
1008
+ metrics?.blockProductionSuccess.inc({source});
1009
+ metrics?.blockProductionNumAggregated.observe({source}, block.body.attestations.length);
1010
+ metrics?.blockProductionConsensusBlockValue.observe({source}, Number(formatWeiToEth(consensusBlockValue)));
1011
+ metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(formatWeiToEth(executionPayloadValue)));
1012
+
1013
+ const blockRoot = toRootHex(config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block));
1014
+ logger.verbose("Produced block", {
1015
+ ...logCtx,
1016
+ executionPayloadValue,
1017
+ consensusBlockValue,
1018
+ root: blockRoot,
1019
+ });
1020
+ if (chain.opts.persistProducedBlocks) {
1021
+ void chain.persistBlock(block, "produced_engine_block");
974
1022
  }
1023
+
1024
+ return {
1025
+ data: block as gloas.BeaconBlock,
1026
+ meta: {version: fork, consensusBlockValue},
1027
+ };
975
1028
  },
976
1029
 
977
1030
  async produceAttestationData({committeeIndex, slot}) {
@@ -1066,7 +1119,15 @@ export function getValidatorApi(
1066
1119
 
1067
1120
  const blockIsForSlot = block.slot === slot;
1068
1121
  const payloadInput = chain.seenPayloadEnvelopeInputCache.get(block.blockRoot);
1069
- const payloadPresent = blockIsForSlot && (payloadInput?.hasPayloadEnvelope() ?? false);
1122
+ // Spec: set payload_present only if the envelope was seen before get_payload_due_ms()
1123
+ // into the slot. Use the envelope's own arrival time (getPayloadEnvelopeSource), not
1124
+ // the input's creation time.
1125
+ const payloadDueSec = config.getPayloadDueMs() / 1000;
1126
+ const payloadPresent =
1127
+ blockIsForSlot &&
1128
+ payloadInput !== undefined &&
1129
+ payloadInput.hasPayloadEnvelope() &&
1130
+ chain.clock.secFromSlot(slot, payloadInput.getPayloadEnvelopeSource().seenTimestampSec) < payloadDueSec;
1070
1131
  const blobDataAvailable = blockIsForSlot && (payloadInput?.hasAllData() ?? false);
1071
1132
 
1072
1133
  return {
@@ -1124,26 +1185,33 @@ export function getValidatorApi(
1124
1185
  async getProposerDuties({epoch}, _context, opts?: {v2?: boolean}) {
1125
1186
  notWhileSyncing();
1126
1187
 
1127
- // Early check that epoch is no more than current_epoch + 1, or allow for pre-genesis
1128
1188
  const currentEpoch = currentEpochWithDisparity();
1129
1189
  const nextEpoch = currentEpoch + 1;
1130
- if (currentEpoch >= 0 && epoch > nextEpoch) {
1190
+ const startSlot = computeStartSlotAtEpoch(epoch);
1191
+ const prepareNextSlotLookAheadMs =
1192
+ config.SLOT_DURATION_MS - config.getSlotComponentDurationMs(PREPARE_NEXT_SLOT_BPS);
1193
+ const toNextEpochMs = msToNextEpoch();
1194
+ const nearNextEpoch = toNextEpochMs < prepareNextSlotLookAheadMs;
1195
+ // Post-Fulu the proposer lookahead is deterministic and known a full epoch ahead, so
1196
+ // close to the boundary `currentEpoch + 2` is serveable from the upcoming-epoch
1197
+ // checkpoint state (its `nextProposers`). Pre-Fulu / mid-epoch: `currentEpoch + 1` max.
1198
+ const isPostFulu = isForkPostFulu(config.getForkName(startSlot));
1199
+ const maxFutureEpoch = isPostFulu && nearNextEpoch && opts?.v2 ? nextEpoch + 1 : nextEpoch;
1200
+ if (currentEpoch >= 0 && epoch > maxFutureEpoch) {
1131
1201
  throw new ApiError(400, `Requested epoch ${epoch} must not be more than one epoch in the future`);
1132
1202
  }
1133
1203
 
1134
1204
  const head = chain.forkChoice.getHead();
1135
1205
  let state: IBeaconStateView | undefined = undefined;
1136
- const startSlot = computeStartSlotAtEpoch(epoch);
1137
- const prepareNextSlotLookAheadMs =
1138
- config.SLOT_DURATION_MS - config.getSlotComponentDurationMs(PREPARE_NEXT_SLOT_BPS);
1139
- const toNextEpochMs = msToNextEpoch();
1140
1206
  // validators may request next epoch's duties when it's close to next epoch
1141
- // this is to avoid missed block proposal due to 0 epoch look ahead
1142
- if (epoch === nextEpoch && toNextEpochMs < prepareNextSlotLookAheadMs) {
1207
+ // this is to avoid missed block proposal due to 0 epoch look ahead.
1208
+ // Post-Fulu, `nextEpoch + 1` is served from the same upcoming-epoch (`nextEpoch`)
1209
+ // checkpoint state via its `nextProposers` (deterministic proposer lookahead).
1210
+ if (nearNextEpoch && (epoch === nextEpoch || (isPostFulu && epoch === nextEpoch + 1))) {
1143
1211
  // wait for maximum 1 slot for cp state which is the timeout of validator api
1144
1212
  const cpState = await waitForCheckpointState({
1145
1213
  rootHex: head.blockRoot,
1146
- epoch,
1214
+ epoch: nextEpoch,
1147
1215
  });
1148
1216
  if (cpState) {
1149
1217
  state = cpState;
@@ -1218,7 +1286,7 @@ export function getValidatorApi(
1218
1286
  // It should be set to the latest block applied to `self` or the genesis block root.
1219
1287
  const dependentRoot =
1220
1288
  // In v2 the dependent root is different after fulu due to deterministic proposer lookahead
1221
- proposerShufflingDecisionRoot(opts?.v2 ? config.getForkName(startSlot) : ForkName.phase0, state) ||
1289
+ proposerShufflingDecisionRoot(opts?.v2 ? config.getForkName(startSlot) : ForkName.phase0, state, epoch) ||
1222
1290
  (await getGenesisBlockRoot(state));
1223
1291
 
1224
1292
  return {
@@ -116,13 +116,19 @@ export async function importBlock(
116
116
  }
117
117
  executionStatus = parentBlock.executionStatus;
118
118
  }
119
+
120
+ // getBeaconProposerOrNull will return null if head state is more than one epoch away
121
+ // from block slot. We skip proposer boost canonical check as we cannot determine the canonical proposer
122
+ const expectedProposerIndex: number | null = this.getHeadState().getBeaconProposerOrNull(blockSlot);
123
+
119
124
  const blockSummary = this.forkChoice.onBlock(
120
125
  block.message,
121
126
  postState,
122
127
  blockDelaySec,
123
128
  currentSlot,
124
129
  executionStatus,
125
- dataAvailabilityStatus
130
+ dataAvailabilityStatus,
131
+ expectedProposerIndex
126
132
  );
127
133
 
128
134
  // This adds the state necessary to process the next block
@@ -258,7 +264,8 @@ export async function importBlock(
258
264
  this.forkChoice.notifyPtcMessages(
259
265
  toRootHex(payloadAttestation.data.beaconBlockRoot),
260
266
  ptcIndices,
261
- payloadAttestation.data.payloadPresent
267
+ payloadAttestation.data.payloadPresent,
268
+ payloadAttestation.data.blobDataAvailable
262
269
  );
263
270
  }
264
271
  } catch (e) {
@@ -237,6 +237,7 @@ export async function importExecutionPayload(
237
237
  blockRootHex,
238
238
  blockHashHex,
239
239
  envelope.payload.blockNumber,
240
+ envelope.payload.gasLimit,
240
241
  execStatus,
241
242
  dataAvailabilityStatus
242
243
  );
@@ -254,7 +255,11 @@ export async function importExecutionPayload(
254
255
  }
255
256
 
256
257
  // 8. Record metrics for payload envelope and column sources
257
- this.metrics?.importPayload.bySource.inc({source: payloadInput.getPayloadEnvelopeSource().source});
258
+ const delaySec = this.clock.secFromSlot(slot);
259
+ this.metrics?.importPayload.elapsedTimeTillImported.observe(
260
+ {source: payloadInput.getPayloadEnvelopeSource().source},
261
+ delaySec
262
+ );
258
263
  for (const {source} of payloadInput.getSampledColumnsWithSource()) {
259
264
  this.metrics?.importPayload.columnsBySource.inc({source});
260
265
  }
@@ -275,6 +280,7 @@ export async function importExecutionPayload(
275
280
  builderIndex: envelope.builderIndex,
276
281
  blockRoot: blockRootHex,
277
282
  blockHash: blockHashHex,
283
+ delaySec,
278
284
  });
279
285
  }
280
286
 
@@ -88,6 +88,7 @@ import {
88
88
  ExecutionPayloadBidPool,
89
89
  OpPool,
90
90
  PayloadAttestationPool,
91
+ ProposerPreferencesPool,
91
92
  SyncCommitteeMessagePool,
92
93
  SyncContributionAndProofPool,
93
94
  } from "./opPools/index.js";
@@ -180,6 +181,7 @@ export class BeaconChain implements IBeaconChain {
180
181
  readonly syncContributionAndProofPool;
181
182
  readonly executionPayloadBidPool: ExecutionPayloadBidPool;
182
183
  readonly payloadAttestationPool: PayloadAttestationPool;
184
+ readonly proposerPreferencesPool = new ProposerPreferencesPool();
183
185
  readonly opPool: OpPool;
184
186
 
185
187
  // Gossip seen cache
@@ -1047,6 +1049,7 @@ export class BeaconChain implements IBeaconChain {
1047
1049
  feeRecipient,
1048
1050
  commonBlockBodyPromise,
1049
1051
  parentBlock,
1052
+ builderBid,
1050
1053
  }: BlockAttributes & {commonBlockBodyPromise: Promise<CommonBlockBody>}
1051
1054
  ): Promise<{
1052
1055
  block: AssembledBlockType<T>;
@@ -1076,6 +1079,7 @@ export class BeaconChain implements IBeaconChain {
1076
1079
  proposerIndex,
1077
1080
  proposerPubKey,
1078
1081
  commonBlockBodyPromise,
1082
+ builderBid,
1079
1083
  }
1080
1084
  );
1081
1085
 
@@ -1462,6 +1466,7 @@ export class BeaconChain implements IBeaconChain {
1462
1466
  this.executionPayloadBidPool.prune(slot);
1463
1467
  this.seenExecutionPayloadBids.prune(slot);
1464
1468
  this.seenProposerPreferences.prune(slot);
1469
+ this.proposerPreferencesPool.prune(slot);
1465
1470
  this.seenAttestationDatas.onSlot(slot);
1466
1471
  this.reprocessController.onSlot(slot);
1467
1472
 
@@ -9,8 +9,12 @@ export enum ExecutionPayloadBidErrorCode {
9
9
  BID_TOO_HIGH = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_HIGH",
10
10
  TOO_MANY_KZG_COMMITMENTS = "EXECUTION_PAYLOAD_BID_ERROR_TOO_MANY_KZG_COMMITMENTS",
11
11
  UNKNOWN_BLOCK_ROOT = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_BLOCK_ROOT",
12
+ UNKNOWN_PARENT_BLOCK_HASH = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_PARENT_BLOCK_HASH",
12
13
  INVALID_SLOT = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_SLOT",
13
14
  INVALID_SIGNATURE = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_SIGNATURE",
15
+ NO_MATCHING_PROPOSER_PREFERENCES = "EXECUTION_PAYLOAD_BID_ERROR_NO_MATCHING_PROPOSER_PREFERENCES",
16
+ PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH",
17
+ PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH",
14
18
  }
15
19
 
16
20
  export type ExecutionPayloadBidErrorType =
@@ -35,7 +39,27 @@ export type ExecutionPayloadBidErrorType =
35
39
  commitmentLimit: number;
36
40
  }
37
41
  | {code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT; parentBlockRoot: RootHex}
42
+ | {code: ExecutionPayloadBidErrorCode.UNKNOWN_PARENT_BLOCK_HASH; parentBlockHash: RootHex}
38
43
  | {code: ExecutionPayloadBidErrorCode.INVALID_SLOT; builderIndex: BuilderIndex; slot: Slot}
39
- | {code: ExecutionPayloadBidErrorCode.INVALID_SIGNATURE; builderIndex: BuilderIndex; slot: Slot};
44
+ | {code: ExecutionPayloadBidErrorCode.INVALID_SIGNATURE; builderIndex: BuilderIndex; slot: Slot}
45
+ | {
46
+ code: ExecutionPayloadBidErrorCode.NO_MATCHING_PROPOSER_PREFERENCES;
47
+ slot: Slot;
48
+ parentBlockRoot: RootHex;
49
+ dependentRoot: RootHex;
50
+ }
51
+ | {
52
+ code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH;
53
+ builderIndex: BuilderIndex;
54
+ bidFeeRecipient: string;
55
+ expectedFeeRecipient: string;
56
+ }
57
+ | {
58
+ code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH;
59
+ builderIndex: BuilderIndex;
60
+ bidGasLimit: number;
61
+ parentGasLimit: number;
62
+ targetGasLimit: number;
63
+ };
40
64
 
41
65
  export class ExecutionPayloadBidError extends GossipActionError<ExecutionPayloadBidErrorType> {}
@@ -140,9 +140,11 @@ export function initializeForkChoiceFromFinalizedState(
140
140
  executionPayloadBlockHash: isStatePostGloas(state)
141
141
  ? toRootHex(state.latestBlockHash)
142
142
  : toRootHex(state.latestExecutionPayloadHeader.blockHash),
143
- // TODO GLOAS: executionPayloadNumber is not tracked in BeaconState post-gloas (EIP-7732 removed
144
- // latestExecutionPayloadHeader). Using 0 as unavailable fallback until a solution is found.
143
+ // TODO GLOAS: executionPayloadNumber/GasLimit are not tracked in BeaconState post-gloas
144
+ // (EIP-7732 removed latestExecutionPayloadHeader). Using 0 as unavailable fallback
145
+ // see initializeForkChoiceFromUnfinalizedState for the same caveat on validation.
145
146
  executionPayloadNumber: isStatePostGloas(state) ? 0 : state.payloadBlockNumber,
147
+ executionPayloadGasLimit: isStatePostGloas(state) ? 0 : state.latestExecutionPayloadHeader.gasLimit,
146
148
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
147
149
  }
148
150
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
@@ -232,9 +234,17 @@ export function initializeForkChoiceFromUnfinalizedState(
232
234
  executionPayloadBlockHash: isStatePostGloas(unfinalizedState)
233
235
  ? toRootHex(unfinalizedState.latestBlockHash)
234
236
  : toRootHex(unfinalizedState.latestExecutionPayloadHeader.blockHash),
235
- // TODO GLOAS: executionPayloadNumber is not tracked in BeaconState post-gloas (EIP-7732 removed
236
- // latestExecutionPayloadHeader). Using 0 as unavailable fallback until a solution is found.
237
+ // TODO GLOAS: executionPayloadNumber/GasLimit are not tracked in BeaconState post-gloas
238
+ // (EIP-7732 removed latestExecutionPayloadHeader). Using 0 as unavailable fallback until
239
+ // a solution is found. The 0 doesn't gate validation in practice: at boot the head's
240
+ // PENDING variant's `executionPayloadBlockHash` is the *parent's* payload hash (per the
241
+ // PENDING/EMPTY convention), so gossip bids that reference the head's *own* payload
242
+ // hash won't match this variant anyway and will IGNORE until `onExecutionPayload`
243
+ // upgrades the head to FULL with real values.
237
244
  executionPayloadNumber: isStatePostGloas(unfinalizedState) ? 0 : unfinalizedState.payloadBlockNumber,
245
+ executionPayloadGasLimit: isStatePostGloas(unfinalizedState)
246
+ ? 0
247
+ : unfinalizedState.latestExecutionPayloadHeader.gasLimit,
238
248
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
239
249
  }
240
250
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
@@ -47,6 +47,7 @@ import {
47
47
  ExecutionPayloadBidPool,
48
48
  OpPool,
49
49
  PayloadAttestationPool,
50
+ ProposerPreferencesPool,
50
51
  SyncCommitteeMessagePool,
51
52
  SyncContributionAndProofPool,
52
53
  } from "./opPools/index.js";
@@ -124,6 +125,7 @@ export interface IBeaconChain {
124
125
  readonly syncContributionAndProofPool: SyncContributionAndProofPool;
125
126
  readonly executionPayloadBidPool: ExecutionPayloadBidPool;
126
127
  readonly payloadAttestationPool: PayloadAttestationPool;
128
+ readonly proposerPreferencesPool: ProposerPreferencesPool;
127
129
  readonly opPool: OpPool;
128
130
 
129
131
  // Gossip seen cache
@@ -1,12 +1,6 @@
1
1
  import {BitArray} from "@chainsafe/ssz";
2
2
  import {routes} from "@lodestar/api";
3
3
  import {ChainForkConfig} from "@lodestar/config";
4
- import {
5
- LightClientUpdateSummary,
6
- isBetterUpdate,
7
- toLightClientUpdateSummary,
8
- upgradeLightClientHeader,
9
- } from "@lodestar/light-client/spec";
10
4
  import {
11
5
  ForkName,
12
6
  ForkPostAltair,
@@ -27,6 +21,12 @@ import {
27
21
  computeSyncPeriodAtSlot,
28
22
  executionPayloadToPayloadHeader,
29
23
  } from "@lodestar/state-transition";
24
+ import {
25
+ LightClientUpdateSummary,
26
+ isBetterUpdate,
27
+ toLightClientUpdateSummary,
28
+ upgradeLightClientHeader,
29
+ } from "@lodestar/state-transition/light-client";
30
30
  import {
31
31
  BeaconBlock,
32
32
  BeaconBlockBody,
@@ -12,13 +12,13 @@ type BlockRootHex = string;
12
12
  type BlockHashHex = string;
13
13
 
14
14
  /**
15
- * Store the best execution payload bid per slot / (parent block root, parent block hash).
15
+ * Store the best signed execution payload bid per slot / (parent block root, parent block hash).
16
16
  */
17
17
  export class ExecutionPayloadBidPool {
18
18
  private readonly bidByParentHashByParentRootBySlot = new MapDef<
19
19
  Slot,
20
- MapDef<BlockRootHex, Map<BlockHashHex, gloas.ExecutionPayloadBid>>
21
- >(() => new MapDef<BlockRootHex, Map<BlockHashHex, gloas.ExecutionPayloadBid>>(() => new Map()));
20
+ MapDef<BlockRootHex, Map<BlockHashHex, gloas.SignedExecutionPayloadBid>>
21
+ >(() => new MapDef<BlockRootHex, Map<BlockHashHex, gloas.SignedExecutionPayloadBid>>(() => new Map()));
22
22
  private lowestPermissibleSlot = 0;
23
23
 
24
24
  get size(): number {
@@ -31,8 +31,8 @@ export class ExecutionPayloadBidPool {
31
31
  return count;
32
32
  }
33
33
 
34
- add(bid: gloas.ExecutionPayloadBid): InsertOutcome {
35
- const {slot, parentBlockRoot, parentBlockHash, value} = bid;
34
+ add(bid: gloas.SignedExecutionPayloadBid): InsertOutcome {
35
+ const {slot, parentBlockRoot, parentBlockHash, value} = bid.message;
36
36
  const lowestPermissibleSlot = this.lowestPermissibleSlot;
37
37
 
38
38
  if (slot < lowestPermissibleSlot) {
@@ -45,7 +45,7 @@ export class ExecutionPayloadBidPool {
45
45
  const existing = bidByParentHash.get(parentHashHex);
46
46
 
47
47
  if (existing) {
48
- const existingValue = existing.value;
48
+ const existingValue = existing.message.value;
49
49
  const newValue = value;
50
50
  if (newValue > existingValue) {
51
51
  bidByParentHash.set(parentHashHex, bid);
@@ -59,14 +59,15 @@ export class ExecutionPayloadBidPool {
59
59
  }
60
60
 
61
61
  /**
62
- * Return the highest-value bid matching slot, parent block hash, and parent block root.
62
+ * Return the highest-value signed bid matching slot, parent block hash, and parent block root.
63
63
  * Used for gossip validation and block production.
64
64
  */
65
65
  getBestBid(
66
66
  slot: Slot,
67
- parentBlockHash: BlockHashHex,
67
+ parentBlockHash: BlockHashHex | null,
68
68
  parentBlockRoot: BlockRootHex
69
- ): gloas.ExecutionPayloadBid | null {
69
+ ): gloas.SignedExecutionPayloadBid | null {
70
+ if (parentBlockHash === null) return null;
70
71
  const bidByParentHash = this.bidByParentHashByParentRootBySlot.get(slot)?.get(parentBlockRoot);
71
72
  return bidByParentHash?.get(parentBlockHash) ?? null;
72
73
  }
@@ -3,5 +3,6 @@ export {AttestationPool} from "./attestationPool.js";
3
3
  export {ExecutionPayloadBidPool} from "./executionPayloadBidPool.js";
4
4
  export {OpPool} from "./opPool.js";
5
5
  export {PayloadAttestationPool} from "./payloadAttestationPool.js";
6
+ export {ProposerPreferencesPool} from "./proposerPreferencesPool.js";
6
7
  export {SyncCommitteeMessagePool} from "./syncCommitteeMessagePool.js";
7
8
  export {SyncContributionAndProofPool} from "./syncContributionAndProofPool.js";