@lodestar/beacon-node 1.43.0 → 1.44.0-dev.0e1ac44567

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 (133) 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 +5 -3
  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 +29 -1
  21. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  22. package/lib/chain/errors/executionPayloadBid.js +5 -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/regen/interface.d.ts +1 -0
  57. package/lib/chain/regen/interface.d.ts.map +1 -1
  58. package/lib/chain/regen/interface.js +1 -0
  59. package/lib/chain/regen/interface.js.map +1 -1
  60. package/lib/chain/validation/executionPayloadBid.d.ts +7 -3
  61. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  62. package/lib/chain/validation/executionPayloadBid.js +97 -23
  63. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  64. package/lib/chain/validation/payloadAttestationMessage.d.ts +1 -1
  65. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  66. package/lib/chain/validation/payloadAttestationMessage.js +5 -3
  67. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  68. package/lib/chain/validatorMonitor.d.ts +1 -0
  69. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  70. package/lib/chain/validatorMonitor.js +16 -0
  71. package/lib/chain/validatorMonitor.js.map +1 -1
  72. package/lib/execution/builder/index.d.ts +1 -2
  73. package/lib/execution/builder/index.d.ts.map +1 -1
  74. package/lib/execution/builder/index.js +0 -1
  75. package/lib/execution/builder/index.js.map +1 -1
  76. package/lib/execution/engine/interface.d.ts +1 -0
  77. package/lib/execution/engine/interface.d.ts.map +1 -1
  78. package/lib/execution/engine/types.d.ts +2 -0
  79. package/lib/execution/engine/types.d.ts.map +1 -1
  80. package/lib/execution/engine/types.js +2 -0
  81. package/lib/execution/engine/types.js.map +1 -1
  82. package/lib/metrics/metrics/lodestar.d.ts +1 -1
  83. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  84. package/lib/metrics/metrics/lodestar.js +4 -3
  85. package/lib/metrics/metrics/lodestar.js.map +1 -1
  86. package/lib/network/gossip/topic.d.ts +1 -1
  87. package/lib/network/interface.d.ts +2 -0
  88. package/lib/network/interface.d.ts.map +1 -1
  89. package/lib/network/network.d.ts +2 -0
  90. package/lib/network/network.d.ts.map +1 -1
  91. package/lib/network/network.js +10 -0
  92. package/lib/network/network.js.map +1 -1
  93. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  94. package/lib/network/processor/gossipHandlers.js +19 -6
  95. package/lib/network/processor/gossipHandlers.js.map +1 -1
  96. package/lib/util/dependentRoot.d.ts +6 -2
  97. package/lib/util/dependentRoot.d.ts.map +1 -1
  98. package/lib/util/dependentRoot.js +20 -16
  99. package/lib/util/dependentRoot.js.map +1 -1
  100. package/package.json +14 -15
  101. package/src/api/impl/beacon/blocks/index.ts +36 -0
  102. package/src/api/impl/beacon/pool/index.ts +59 -4
  103. package/src/api/impl/validator/index.ts +118 -50
  104. package/src/chain/blocks/importBlock.ts +10 -2
  105. package/src/chain/blocks/importExecutionPayload.ts +8 -2
  106. package/src/chain/chain.ts +5 -0
  107. package/src/chain/errors/executionPayloadBid.ts +27 -1
  108. package/src/chain/forkChoice/index.ts +14 -4
  109. package/src/chain/interface.ts +2 -0
  110. package/src/chain/lightClient/index.ts +6 -6
  111. package/src/chain/opPools/executionPayloadBidPool.ts +10 -9
  112. package/src/chain/opPools/index.ts +1 -0
  113. package/src/chain/opPools/payloadAttestationPool.ts +34 -10
  114. package/src/chain/opPools/proposerPreferencesPool.ts +59 -0
  115. package/src/chain/prepareNextSlot.ts +2 -1
  116. package/src/chain/produceBlock/produceBlockBody.ts +158 -25
  117. package/src/chain/regen/interface.ts +1 -0
  118. package/src/chain/validation/executionPayloadBid.ts +107 -28
  119. package/src/chain/validation/payloadAttestationMessage.ts +6 -4
  120. package/src/chain/validatorMonitor.ts +18 -0
  121. package/src/execution/builder/index.ts +1 -4
  122. package/src/execution/engine/interface.ts +1 -0
  123. package/src/execution/engine/types.ts +4 -0
  124. package/src/metrics/metrics/lodestar.ts +4 -3
  125. package/src/network/interface.ts +2 -0
  126. package/src/network/network.ts +22 -0
  127. package/src/network/processor/gossipHandlers.ts +25 -6
  128. package/src/util/dependentRoot.ts +22 -18
  129. package/lib/execution/builder/utils.d.ts +0 -5
  130. package/lib/execution/builder/utils.d.ts.map +0 -1
  131. package/lib/execution/builder/utils.js +0 -17
  132. package/lib/execution/builder/utils.js.map +0 -1
  133. package/src/execution/builder/utils.ts +0 -19
@@ -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
@@ -257,8 +263,10 @@ export async function importBlock(
257
263
  if (ptcIndices.length > 0) {
258
264
  this.forkChoice.notifyPtcMessages(
259
265
  toRootHex(payloadAttestation.data.beaconBlockRoot),
266
+ payloadAttestation.data.slot,
260
267
  ptcIndices,
261
- payloadAttestation.data.payloadPresent
268
+ payloadAttestation.data.payloadPresent,
269
+ payloadAttestation.data.blobDataAvailable
262
270
  );
263
271
  }
264
272
  } catch (e) {
@@ -129,7 +129,7 @@ export async function importExecutionPayload(
129
129
 
130
130
  // 3. Regenerate state for envelope verification
131
131
  const blockState = await this.regen
132
- .getBlockSlotState(protoBlock, protoBlock.slot, {dontTransferCache: true}, RegenCaller.processBlock)
132
+ .getBlockSlotState(protoBlock, protoBlock.slot, {dontTransferCache: true}, RegenCaller.importExecutionPayload)
133
133
  .catch(() =>
134
134
  // only happen at the 1st batch of skipped slot checkpoint sync
135
135
  this.regen.getClosestHeadState(protoBlock)
@@ -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,13 @@ 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",
14
+ NOT_LATER_THAN_PARENT = "EXECUTION_PAYLOAD_BID_ERROR_NOT_LATER_THAN_PARENT",
13
15
  INVALID_SIGNATURE = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_SIGNATURE",
16
+ NO_MATCHING_PROPOSER_PREFERENCES = "EXECUTION_PAYLOAD_BID_ERROR_NO_MATCHING_PROPOSER_PREFERENCES",
17
+ PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH",
18
+ PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH",
14
19
  }
15
20
 
16
21
  export type ExecutionPayloadBidErrorType =
@@ -35,7 +40,28 @@ export type ExecutionPayloadBidErrorType =
35
40
  commitmentLimit: number;
36
41
  }
37
42
  | {code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT; parentBlockRoot: RootHex}
43
+ | {code: ExecutionPayloadBidErrorCode.UNKNOWN_PARENT_BLOCK_HASH; parentBlockHash: RootHex}
38
44
  | {code: ExecutionPayloadBidErrorCode.INVALID_SLOT; builderIndex: BuilderIndex; slot: Slot}
39
- | {code: ExecutionPayloadBidErrorCode.INVALID_SIGNATURE; builderIndex: BuilderIndex; slot: Slot};
45
+ | {code: ExecutionPayloadBidErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
46
+ | {code: ExecutionPayloadBidErrorCode.INVALID_SIGNATURE; builderIndex: BuilderIndex; slot: Slot}
47
+ | {
48
+ code: ExecutionPayloadBidErrorCode.NO_MATCHING_PROPOSER_PREFERENCES;
49
+ slot: Slot;
50
+ parentBlockRoot: RootHex;
51
+ dependentRoot: RootHex;
52
+ }
53
+ | {
54
+ code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH;
55
+ builderIndex: BuilderIndex;
56
+ bidFeeRecipient: string;
57
+ expectedFeeRecipient: string;
58
+ }
59
+ | {
60
+ code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH;
61
+ builderIndex: BuilderIndex;
62
+ bidGasLimit: number;
63
+ parentGasLimit: number;
64
+ targetGasLimit: number;
65
+ };
40
66
 
41
67
  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";
@@ -57,7 +57,7 @@ export class PayloadAttestationPool {
57
57
  add(
58
58
  message: gloas.PayloadAttestationMessage,
59
59
  payloadAttDataRootHex: RootHex,
60
- validatorCommitteeIndex: number
60
+ validatorCommitteeIndices: number[]
61
61
  ): InsertOutcome {
62
62
  const slot = message.data.slot;
63
63
  const lowestPermissibleSlot = this.lowestPermissibleSlot;
@@ -85,10 +85,10 @@ export class PayloadAttestationPool {
85
85
  const aggregate = aggregateByDataRoot.get(payloadAttDataRootHex);
86
86
  if (aggregate) {
87
87
  // Aggregate msg into aggregate
88
- return aggregateMessageInto(message, validatorCommitteeIndex, aggregate);
88
+ return aggregateMessageInto(message, validatorCommitteeIndices, aggregate);
89
89
  }
90
90
  // Create a new aggregate with data
91
- aggregateByDataRoot.set(payloadAttDataRootHex, messageToAggregate(message, validatorCommitteeIndex));
91
+ aggregateByDataRoot.set(payloadAttDataRootHex, messageToAggregate(message, validatorCommitteeIndices));
92
92
 
93
93
  return InsertOutcome.NewData;
94
94
  }
@@ -150,25 +150,49 @@ export class PayloadAttestationPool {
150
150
  }
151
151
  }
152
152
 
153
- function messageToAggregate(message: gloas.PayloadAttestationMessage, validatorCommitteeIndex: number): AggregateFast {
153
+ function messageToAggregate(
154
+ message: gloas.PayloadAttestationMessage,
155
+ validatorCommitteeIndices: number[]
156
+ ): AggregateFast {
157
+ const aggregationBits = BitArray.fromBitLen(PTC_SIZE);
158
+ for (const index of validatorCommitteeIndices) {
159
+ aggregationBits.set(index, true);
160
+ }
161
+ const sig = signatureFromBytesNoCheck(message.signature);
162
+ // The validator signed once but occupies `validatorCommitteeIndices.length` PTC positions.
163
+ // Verification aggregates the pubkey once per set bit, so the signature must be aggregated
164
+ // the same number of times for the BLS check to balance — same pattern as sync committee.
165
+ const signature =
166
+ validatorCommitteeIndices.length === 1
167
+ ? sig
168
+ : aggregateSignatures(new Array(validatorCommitteeIndices.length).fill(sig));
154
169
  return {
155
- aggregationBits: BitArray.fromSingleBit(PTC_SIZE, validatorCommitteeIndex),
170
+ aggregationBits,
156
171
  data: message.data,
157
- signature: signatureFromBytesNoCheck(message.signature),
172
+ signature,
158
173
  };
159
174
  }
160
175
 
161
176
  function aggregateMessageInto(
162
177
  message: gloas.PayloadAttestationMessage,
163
- validatorCommitteeIndex: number,
178
+ validatorCommitteeIndices: number[],
164
179
  aggregate: AggregateFast
165
180
  ): InsertOutcome {
166
- if (aggregate.aggregationBits.get(validatorCommitteeIndex) === true) {
181
+ // Gossip dedup via `seenPayloadAttesters` is keyed by (epoch, validatorIndex), so the same
182
+ // validator's message is never processed twice — all of its bits are set together or none.
183
+ // Checking the first index is sufficient.
184
+ if (aggregate.aggregationBits.get(validatorCommitteeIndices[0]) === true) {
167
185
  return InsertOutcome.AlreadyKnown;
168
186
  }
169
187
 
170
- aggregate.aggregationBits.set(validatorCommitteeIndex, true);
171
- aggregate.signature = aggregateSignatures([aggregate.signature, signatureFromBytesNoCheck(message.signature)]);
188
+ for (const index of validatorCommitteeIndices) {
189
+ aggregate.aggregationBits.set(index, true);
190
+ }
191
+ const sig = signatureFromBytesNoCheck(message.signature);
192
+ aggregate.signature = aggregateSignatures([
193
+ aggregate.signature,
194
+ ...new Array(validatorCommitteeIndices.length).fill(sig),
195
+ ]);
172
196
 
173
197
  return InsertOutcome.Aggregated;
174
198
  }