@lodestar/beacon-node 1.52.0-dev.77088eb712 → 1.52.0-dev.7dd7051260

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 (88) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +63 -39
  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 +3 -1
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.js +2 -1
  9. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  10. package/lib/api/impl/debug/index.d.ts.map +1 -1
  11. package/lib/api/impl/debug/index.js +6 -2
  12. package/lib/api/impl/debug/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 +6 -4
  15. package/lib/api/impl/validator/index.js.map +1 -1
  16. package/lib/chain/blocks/index.d.ts.map +1 -1
  17. package/lib/chain/blocks/index.js +3 -16
  18. package/lib/chain/blocks/index.js.map +1 -1
  19. package/lib/chain/chain.d.ts +3 -3
  20. package/lib/chain/chain.d.ts.map +1 -1
  21. package/lib/chain/chain.js +53 -24
  22. package/lib/chain/chain.js.map +1 -1
  23. package/lib/chain/errors/executionPayloadBid.d.ts +3 -2
  24. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  25. package/lib/chain/errors/executionPayloadBid.js +1 -1
  26. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  27. package/lib/chain/interface.d.ts +1 -1
  28. package/lib/chain/interface.d.ts.map +1 -1
  29. package/lib/chain/opPools/opPool.js +6 -6
  30. package/lib/chain/opPools/opPool.js.map +1 -1
  31. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +13 -4
  32. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
  33. package/lib/chain/seenCache/seenExecutionPayloadBids.js +13 -12
  34. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
  35. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  36. package/lib/chain/validation/executionPayloadBid.js +30 -40
  37. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  38. package/lib/chain/validation/payloadAttestationMessage.js +9 -0
  39. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  40. package/lib/chain/validatorMonitor.js +43 -43
  41. package/lib/chain/validatorMonitor.js.map +1 -1
  42. package/lib/network/gossip/topic.d.ts +1 -7
  43. package/lib/network/gossip/topic.d.ts.map +1 -1
  44. package/lib/network/gossip/topic.js +0 -13
  45. package/lib/network/gossip/topic.js.map +1 -1
  46. package/lib/network/network.d.ts +1 -0
  47. package/lib/network/network.d.ts.map +1 -1
  48. package/lib/network/network.js +20 -11
  49. package/lib/network/network.js.map +1 -1
  50. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  51. package/lib/network/processor/gossipHandlers.js +8 -4
  52. package/lib/network/processor/gossipHandlers.js.map +1 -1
  53. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  54. package/lib/network/processor/gossipValidatorFn.js +4 -1
  55. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  56. package/lib/network/reqresp/utils/collect.d.ts +4 -4
  57. package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
  58. package/lib/network/reqresp/utils/collect.js +9 -8
  59. package/lib/network/reqresp/utils/collect.js.map +1 -1
  60. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +1 -1
  61. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
  62. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +2 -2
  63. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
  64. package/lib/sync/unknownBlock.d.ts.map +1 -1
  65. package/lib/sync/unknownBlock.js +2 -1
  66. package/lib/sync/unknownBlock.js.map +1 -1
  67. package/package.json +16 -16
  68. package/src/api/impl/beacon/blocks/index.ts +74 -47
  69. package/src/api/impl/beacon/pool/index.ts +9 -7
  70. package/src/api/impl/beacon/state/utils.ts +2 -1
  71. package/src/api/impl/debug/index.ts +6 -2
  72. package/src/api/impl/validator/index.ts +6 -3
  73. package/src/chain/blocks/index.ts +3 -30
  74. package/src/chain/chain.ts +81 -40
  75. package/src/chain/errors/executionPayloadBid.ts +3 -2
  76. package/src/chain/interface.ts +1 -1
  77. package/src/chain/opPools/opPool.ts +6 -6
  78. package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
  79. package/src/chain/validation/executionPayloadBid.ts +40 -42
  80. package/src/chain/validation/payloadAttestationMessage.ts +10 -0
  81. package/src/chain/validatorMonitor.ts +43 -43
  82. package/src/network/gossip/topic.ts +1 -14
  83. package/src/network/network.ts +33 -11
  84. package/src/network/processor/gossipHandlers.ts +14 -10
  85. package/src/network/processor/gossipValidatorFn.ts +4 -0
  86. package/src/network/reqresp/utils/collect.ts +16 -8
  87. package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +3 -2
  88. package/src/sync/unknownBlock.ts +2 -1
@@ -25,6 +25,7 @@ import {
25
25
  } from "@lodestar/state-transition";
26
26
  import {
27
27
  ProducedBlockSource,
28
+ RootHex,
28
29
  SignedBeaconBlock,
29
30
  SignedBlindedBeaconBlock,
30
31
  SignedBlockContents,
@@ -190,28 +191,31 @@ export function getBeaconBlockApi(
190
191
 
191
192
  switch (broadcastValidation) {
192
193
  case routes.beacon.BroadcastValidation.gossip: {
193
- if (!blockLocallyProduced) {
194
- try {
194
+ try {
195
+ if (blockLocallyProduced) {
196
+ // Block production does not cover the proposer signature, the validator client signs the block
197
+ await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
198
+ } else {
195
199
  await validateGossipBlock(config, chain, signedBlock, fork);
196
- } catch (error) {
197
- if (error instanceof BlockGossipError) {
198
- switch (error.type.code) {
199
- case BlockErrorCode.ALREADY_KNOWN:
200
- // Block has already been seen, e.g. via gossip racing the publish API. Benign.
201
- chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
202
- return;
203
- }
200
+ }
201
+ } catch (error) {
202
+ if (error instanceof BlockGossipError) {
203
+ switch (error.type.code) {
204
+ case BlockErrorCode.ALREADY_KNOWN:
205
+ // Block has already been seen, e.g. via gossip racing the publish API. Benign.
206
+ chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
207
+ return;
204
208
  }
205
-
206
- chain.logger.error("Gossip validations failed while publishing the block", valLogMeta, error as Error);
207
- chain.persistInvalidSszValue(
208
- chain.config.getForkTypes(slot).SignedBeaconBlock,
209
- signedBlock,
210
- "api_reject_gossip_failure",
211
- blockRoot
212
- );
213
- throw error;
214
209
  }
210
+
211
+ chain.logger.error("Gossip validations failed while publishing the block", valLogMeta, error as Error);
212
+ chain.persistInvalidSszValue(
213
+ chain.config.getForkTypes(slot).SignedBeaconBlock,
214
+ signedBlock,
215
+ "api_reject_gossip_failure",
216
+ blockRoot
217
+ );
218
+ throw error;
215
219
  }
216
220
  chain.logger.debug("Gossip checks validated while publishing the block", valLogMeta);
217
221
  break;
@@ -507,26 +511,32 @@ export function getBeaconBlockApi(
507
511
 
508
512
  const result: routes.beacon.BlockHeaderResponse[] = [];
509
513
  if (parentRoot) {
514
+ let finalizedRoot: RootHex | null = null;
510
515
  const finalizedBlock = await db.blockArchive.getByParentRoot(fromHex(parentRoot));
511
516
  if (finalizedBlock) {
512
- result.push(toBeaconHeaderResponse(config, finalizedBlock, true));
517
+ const header = toBeaconHeaderResponse(config, finalizedBlock, true);
518
+ finalizedRoot = toRootHex(header.root);
519
+ result.push(header);
513
520
  }
514
521
  const nonFinalizedBlocks = chain.forkChoice.getBlockSummariesByParentRoot(parentRoot);
515
522
  await Promise.all(
516
523
  nonFinalizedBlocks.map(async (summary) => {
524
+ // The finalized block stays in fork choice as its anchor after it is archived
525
+ if (summary.blockRoot === finalizedRoot) {
526
+ return;
527
+ }
517
528
  const blockResult = await chain.getBlockByRoot(summary.blockRoot);
518
529
  if (blockResult) {
530
+ // There is no canonical block at the slot of a child that was reorged out by a later sibling
519
531
  const canonical = chain.forkChoice.getCanonicalBlockAtSlot(blockResult.block.message.slot);
520
- if (canonical) {
521
- result.push(
522
- toBeaconHeaderResponse(config, blockResult.block, canonical.blockRoot === summary.blockRoot)
523
- );
524
- if (isOptimisticBlock(canonical)) {
525
- executionOptimistic = true;
526
- }
527
- // Block from hot db which only contains unfinalized blocks
528
- finalized = false;
532
+ result.push(
533
+ toBeaconHeaderResponse(config, blockResult.block, canonical?.blockRoot === summary.blockRoot)
534
+ );
535
+ if (isOptimisticBlock(summary)) {
536
+ executionOptimistic = true;
529
537
  }
538
+ // Block from hot db which only contains unfinalized blocks
539
+ finalized = false;
530
540
  }
531
541
  })
532
542
  );
@@ -551,21 +561,18 @@ export function getBeaconBlockApi(
551
561
  return {data: [], meta: {executionOptimistic: false, finalized: false}};
552
562
  }
553
563
 
564
+ let canonicalRoot: RootHex | null = null;
554
565
  const canonicalBlock = await chain.getCanonicalBlockAtSlot(slot);
555
- // skip slot
556
- if (!canonicalBlock) {
557
- return {data: [], meta: {executionOptimistic: false, finalized: false}};
558
- }
559
- const canonicalRoot = config
560
- .getForkTypes(canonicalBlock.block.message.slot)
561
- .BeaconBlock.hashTreeRoot(canonicalBlock.block.message);
562
- result.push(toBeaconHeaderResponse(config, canonicalBlock.block, true));
563
- if (!canonicalBlock.finalized) {
564
- finalized = false;
566
+ if (canonicalBlock) {
567
+ const header = toBeaconHeaderResponse(config, canonicalBlock.block, true);
568
+ canonicalRoot = toRootHex(header.root);
569
+ result.push(header);
570
+ if (!canonicalBlock.finalized) {
571
+ finalized = false;
572
+ }
565
573
  }
566
574
 
567
- // fork blocks
568
- // TODO: What is this logic?
575
+ // Non-canonical blocks at the slot, also if the canonical chain skipped it
569
576
  await Promise.all(
570
577
  chain.forkChoice.getBlockSummariesAtSlot(slot).map(async (summary) => {
571
578
  if (isOptimisticBlock(summary)) {
@@ -573,7 +580,7 @@ export function getBeaconBlockApi(
573
580
  }
574
581
  finalized = false;
575
582
 
576
- if (summary.blockRoot !== toRootHex(canonicalRoot)) {
583
+ if (summary.blockRoot !== canonicalRoot) {
577
584
  const blockResult = await chain.getBlockByRoot(summary.blockRoot);
578
585
  if (blockResult) {
579
586
  result.push(toBeaconHeaderResponse(config, blockResult.block));
@@ -581,6 +588,11 @@ export function getBeaconBlockApi(
581
588
  }
582
589
  })
583
590
  );
591
+
592
+ // skip slot
593
+ if (result.length === 0) {
594
+ return {data: [], meta: {executionOptimistic: false, finalized: false}};
595
+ }
584
596
  }
585
597
 
586
598
  return {
@@ -646,11 +658,15 @@ export function getBeaconBlockApi(
646
658
  : parseInt(blockId, 10);
647
659
  if (!Number.isNaN(slot)) {
648
660
  const head = chain.forkChoice.getHead();
661
+ // The head can be the FULL variant, a block reports the status of the payload it builds on
662
+ const executionOptimistic = isOptimisticBlock(
663
+ chain.forkChoice.getBlockHexDefaultStatus(head.blockRoot) ?? head
664
+ );
649
665
 
650
666
  if (slot === head.slot) {
651
667
  return {
652
668
  data: {root: fromHex(head.blockRoot)},
653
- meta: {executionOptimistic: isOptimisticBlock(head), finalized: false},
669
+ meta: {executionOptimistic, finalized: false},
654
670
  };
655
671
  }
656
672
 
@@ -659,7 +675,7 @@ export function getBeaconBlockApi(
659
675
  return {
660
676
  data: {root: state.getBlockRootAtSlot(slot)},
661
677
  meta: {
662
- executionOptimistic: isOptimisticBlock(head),
678
+ executionOptimistic,
663
679
  finalized: computeEpochAtSlot(slot) <= chain.forkChoice.getFinalizedCheckpoint().epoch,
664
680
  },
665
681
  };
@@ -668,7 +684,10 @@ export function getBeaconBlockApi(
668
684
  const head = chain.forkChoice.getHead();
669
685
  return {
670
686
  data: {root: fromHex(head.blockRoot)},
671
- meta: {executionOptimistic: isOptimisticBlock(head), finalized: false},
687
+ meta: {
688
+ executionOptimistic: isOptimisticBlock(chain.forkChoice.getBlockHexDefaultStatus(head.blockRoot) ?? head),
689
+ finalized: false,
690
+ },
672
691
  };
673
692
  }
674
693
 
@@ -1183,10 +1202,14 @@ export function getBeaconBlockApi(
1183
1202
  data = [];
1184
1203
  }
1185
1204
 
1205
+ // Post-gloas sidecars belong to the block's own payload, its FULL variant only exists once imported
1206
+ const payload = finalized ? null : chain.forkChoice.getBlockHex(blockRootHex, PayloadStatus.FULL);
1186
1207
  return {
1187
1208
  data,
1188
1209
  meta: {
1189
- executionOptimistic,
1210
+ executionOptimistic: isForkPostGloas(fork)
1211
+ ? !finalized && (payload === null || isOptimisticBlock(payload))
1212
+ : executionOptimistic,
1190
1213
  finalized,
1191
1214
  version: config.getForkName(block.message.slot),
1192
1215
  },
@@ -1284,10 +1307,14 @@ export function getBeaconBlockApi(
1284
1307
  blobs = [];
1285
1308
  }
1286
1309
 
1310
+ // Post-gloas blobs belong to the block's own payload, its FULL variant only exists once imported
1311
+ const payload = finalized ? null : chain.forkChoice.getBlockHex(blockRootHex, PayloadStatus.FULL);
1287
1312
  return {
1288
1313
  data: blobs,
1289
1314
  meta: {
1290
- executionOptimistic,
1315
+ executionOptimistic: isForkPostGloas(fork)
1316
+ ? !finalized && (payload === null || isOptimisticBlock(payload))
1317
+ : executionOptimistic,
1291
1318
  finalized,
1292
1319
  },
1293
1320
  };
@@ -289,13 +289,15 @@ export function getBeaconPoolApi({
289
289
  );
290
290
  metrics?.opPool.payloadAttestationPool.apiInsertOutcome.inc({insertOutcome});
291
291
 
292
- chain.forkChoice.notifyPtcMessages(
293
- toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
294
- payloadAttestationMessage.data.slot,
295
- validatorCommitteeIndices,
296
- payloadAttestationMessage.data.payloadPresent,
297
- payloadAttestationMessage.data.blobDataAvailable
298
- );
292
+ if (slot === chain.clock.currentSlot) {
293
+ chain.forkChoice.notifyPtcMessages(
294
+ toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
295
+ payloadAttestationMessage.data.slot,
296
+ validatorCommitteeIndices,
297
+ payloadAttestationMessage.data.payloadPresent,
298
+ payloadAttestationMessage.data.blobDataAvailable
299
+ );
300
+ }
299
301
 
300
302
  chain.emitter.emit(routes.events.EventType.payloadAttestationMessage, {
301
303
  version: chain.config.getForkName(slot),
@@ -75,7 +75,8 @@ export async function getStateResponseWithRegen(
75
75
  const finalizedEpoch = chain.forkChoice.getFinalizedCheckpoint().epoch;
76
76
  return {
77
77
  state,
78
- executionOptimistic: isOptimisticBlock(head),
78
+ // The head can be the FULL variant, a state reports the status of the payload its block builds on
79
+ executionOptimistic: isOptimisticBlock(chain.forkChoice.getBlockHexDefaultStatus(head.blockRoot) ?? head),
79
80
  finalized: state.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
80
81
  };
81
82
  }
@@ -1,7 +1,7 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ApplicationMethods} from "@lodestar/api/server";
3
3
  import {ExecutionStatus, PayloadStatus} from "@lodestar/fork-choice";
4
- import {ForkPostDeneb, ZERO_HASH_HEX, isForkPostDeneb, isForkPostFulu} from "@lodestar/params";
4
+ import {ForkPostDeneb, ZERO_HASH_HEX, isForkPostDeneb, isForkPostFulu, isForkPostGloas} from "@lodestar/params";
5
5
  import {computeTimeAtSlot} from "@lodestar/state-transition";
6
6
  import {BeaconState, DataColumnSidecar, DataColumnSidecars, type SignedBeaconBlock, sszTypesFor} from "@lodestar/types";
7
7
  import {fromHex, toRootHex} from "@lodestar/utils";
@@ -190,12 +190,16 @@ export function getDebugApi({
190
190
  dataColumnSidecars = [];
191
191
  }
192
192
 
193
+ // Post-gloas sidecars belong to the block's own payload, its FULL variant only exists once imported
194
+ const payload = finalized ? null : chain.forkChoice.getBlockHex(toRootHex(blockRoot), PayloadStatus.FULL);
193
195
  return {
194
196
  data: (indices
195
197
  ? dataColumnSidecars.filter(({index}) => indices.includes(index))
196
198
  : dataColumnSidecars) as DataColumnSidecars,
197
199
  meta: {
198
- executionOptimistic,
200
+ executionOptimistic: isForkPostGloas(fork)
201
+ ? !finalized && (payload === null || isOptimisticBlock(payload))
202
+ : executionOptimistic,
199
203
  finalized,
200
204
  version: fork,
201
205
  },
@@ -9,6 +9,7 @@ import {
9
9
  ForkPreDeneb,
10
10
  ForkPreGloas,
11
11
  ForkSeq,
12
+ GENESIS_EPOCH,
12
13
  GENESIS_SLOT,
13
14
  SLOTS_PER_EPOCH,
14
15
  SLOTS_PER_HISTORICAL_ROOT,
@@ -1684,7 +1685,8 @@ export function getValidatorApi(
1684
1685
 
1685
1686
  // should not compare to headEpoch in order to handle skipped slots
1686
1687
  // Check if the epoch is in the future after waiting for requested slot
1687
- if (epoch > chain.clock.currentEpoch + 1) {
1688
+ // Before genesis the clock epoch is negative, treat it as GENESIS_EPOCH so the next epoch can be requested
1689
+ if (epoch > Math.max(chain.clock.currentEpoch, GENESIS_EPOCH) + 1) {
1688
1690
  throw new ApiError(400, "Cannot get duties for epoch more than one ahead");
1689
1691
  }
1690
1692
 
@@ -1747,7 +1749,7 @@ export function getValidatorApi(
1747
1749
 
1748
1750
  await waitForNextClosestEpoch();
1749
1751
 
1750
- if (epoch > chain.clock.currentEpoch + 1) {
1752
+ if (epoch > Math.max(chain.clock.currentEpoch, GENESIS_EPOCH) + 1) {
1751
1753
  throw new ApiError(400, "Cannot get PTC duties for epoch more than one ahead");
1752
1754
  }
1753
1755
 
@@ -2325,7 +2327,8 @@ export function getValidatorApi(
2325
2327
  metrics?.inclusionListsValidSize.inc(totalBytes);
2326
2328
 
2327
2329
  const isTimely =
2328
- secFromSlot >= 0 && secFromSlot * 1000 < chain.config.getInclusionListDueMs(chain.config.getForkName(slot));
2330
+ secFromSlot * 1000 >= -chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY &&
2331
+ secFromSlot * 1000 < chain.config.getInclusionListDueMs(chain.config.getForkName(slot));
2329
2332
  chain.inclusionListStore.process(signedInclusionList, committeeIndices, isTimely);
2330
2333
 
2331
2334
  chain.emitter.emit(routes.events.EventType.inclusionList, {
@@ -1,7 +1,7 @@
1
1
  import {PayloadStatus} from "@lodestar/fork-choice";
2
2
  import {computeEpochAtSlot} from "@lodestar/state-transition";
3
3
  import {SignedBeaconBlock, Slot} from "@lodestar/types";
4
- import {isErrorAborted, toRootHex} from "@lodestar/utils";
4
+ import {isErrorAborted} from "@lodestar/utils";
5
5
  import {Metrics} from "../../metrics/metrics.js";
6
6
  import {nextEventLoop} from "../../util/eventLoop.js";
7
7
  import {JobItemQueue, isQueueErrorAborted} from "../../util/queue/index.js";
@@ -208,36 +208,9 @@ export async function processBlocks(
208
208
  this.logger.debug("Block error", {slot: err.signedBlock.message.slot}, err);
209
209
 
210
210
  if (err.type.code === BlockErrorCode.INVALID_SIGNATURE) {
211
- const {signedBlock} = err;
212
- const blockSlot = signedBlock.message.slot;
213
- const {state} = err.type;
214
- const forkTypes = this.config.getForkTypes(blockSlot);
215
- const blockRootHex = toRootHex(forkTypes.BeaconBlock.hashTreeRoot(signedBlock.message));
216
- this.persistInvalidSszValue(
217
- forkTypes.SignedBeaconBlock,
218
- signedBlock,
219
- `${blockSlot}_invalid_signature`,
220
- blockRootHex
221
- );
222
- this.persistInvalidSszBytes(
223
- "BeaconState",
224
- state.serialize(),
225
- toRootHex(state.hashTreeRoot()),
226
- `${state.slot}_invalid_signature`
227
- );
211
+ void this.persistInvalidSignature(err.type.state, err.signedBlock);
228
212
  } else if (err.type.code === BlockErrorCode.INVALID_STATE_ROOT) {
229
- const {signedBlock} = err;
230
- const blockSlot = signedBlock.message.slot;
231
- const {preState, postState} = err.type;
232
- const preRoot = preState.hashTreeRoot();
233
- const postRoot = postState.hashTreeRoot();
234
- this.persistInvalidStateRoot(preState, postState, signedBlock).catch((e) => {
235
- this.logger.error(
236
- "Error persisting invalid state root objects",
237
- {slot: blockSlot, preStateRoot: toRootHex(preRoot), postStateRoot: toRootHex(postRoot)},
238
- e
239
- );
240
- });
213
+ void this.persistInvalidStateRoot(err.type.preState, err.type.postState, err.signedBlock);
241
214
  }
242
215
  }
243
216
 
@@ -7,6 +7,8 @@ import {
7
7
  AncestorStatus,
8
8
  CheckpointWithHex,
9
9
  EpochDifference,
10
+ ForkChoiceError,
11
+ ForkChoiceErrorCode,
10
12
  ForkChoiceStateGetter,
11
13
  IForkChoice,
12
14
  PayloadStatus,
@@ -699,7 +701,8 @@ export class BeaconChain implements IBeaconChain {
699
701
  const state = await this.regen.getBlockSlotState(block, slot, {dontTransferCache: true}, RegenCaller.restApi);
700
702
  return {
701
703
  state,
702
- executionOptimistic: isOptimisticBlock(block),
704
+ // The canonical variant can be FULL, a state reports the status of the payload its block builds on
705
+ executionOptimistic: isOptimisticBlock(this.forkChoice.getBlockHexDefaultStatus(block.blockRoot) ?? block),
703
706
  finalized: slot === finalizedBlock.slot && finalizedBlock.slot !== GENESIS_SLOT,
704
707
  };
705
708
  }
@@ -715,7 +718,7 @@ export class BeaconChain implements IBeaconChain {
715
718
  return (
716
719
  state && {
717
720
  state,
718
- executionOptimistic: isOptimisticBlock(block),
721
+ executionOptimistic: isOptimisticBlock(this.forkChoice.getBlockHexDefaultStatus(block.blockRoot) ?? block),
719
722
  finalized: slot === finalizedBlock.slot && finalizedBlock.slot !== GENESIS_SLOT,
720
723
  }
721
724
  );
@@ -863,7 +866,9 @@ export class BeaconChain implements IBeaconChain {
863
866
  const finalizedBlock = this.forkChoice.getFinalizedBlock();
864
867
  if (slot > finalizedBlock.slot) {
865
868
  // Unfinalized slot, attempt to find in fork-choice
866
- const block = this.forkChoice.getCanonicalBlockAtSlot(slot);
869
+ const canonicalBlock = this.forkChoice.getCanonicalBlockAtSlot(slot);
870
+ // The canonical variant can be FULL, a block reports the status of the payload it builds on
871
+ const block = canonicalBlock && this.forkChoice.getBlockHexDefaultStatus(canonicalBlock.blockRoot);
867
872
  if (block) {
868
873
  // Block found in fork-choice.
869
874
  // It may be in the block input cache, awaiting full DA reconstruction, check there first
@@ -1604,38 +1609,76 @@ export class BeaconChain implements IBeaconChain {
1604
1609
  }
1605
1610
 
1606
1611
  /**
1607
- * Invalid state root error is critical and it causes the node to stale most of the time so we want to always
1608
- * persist preState, postState and block for further investigation.
1612
+ * Invalid state root error is critical and it causes the node to stale most of the time so we want to persist
1613
+ * preState, postState and block for further investigation.
1609
1614
  */
1610
1615
  async persistInvalidStateRoot(
1611
1616
  preState: IBeaconStateView,
1612
1617
  postState: IBeaconStateView,
1613
1618
  block: SignedBeaconBlock
1614
1619
  ): Promise<void> {
1620
+ if (!this.opts.persistInvalidSszObjects) {
1621
+ return;
1622
+ }
1615
1623
  const blockSlot = block.message.slot;
1616
- const blockType = this.config.getForkTypes(blockSlot).SignedBeaconBlock;
1617
- const postStateRoot = postState.hashTreeRoot();
1618
- const logStr = `slot_${blockSlot}_invalid_state_root_${toRootHex(postStateRoot)}`;
1619
- await Promise.all([
1620
- this.persistSszObject(
1621
- `SignedBeaconBlock_slot_${blockSlot}`,
1622
- blockType.serialize(block),
1623
- toRootHex(this.config.getForkTypes(blockSlot).BeaconBlock.hashTreeRoot(block.message)),
1624
- `${logStr}_block`
1625
- ),
1626
- this.persistSszObject(
1627
- `preState_slot_${preState.slot}_BeaconState`,
1628
- preState.serialize(),
1629
- toRootHex(preState.hashTreeRoot()),
1630
- `${logStr}_pre_state`
1631
- ),
1632
- this.persistSszObject(
1633
- `postState_slot_${postState.slot}_BeaconState`,
1634
- postState.serialize(),
1635
- toRootHex(postStateRoot),
1636
- `${logStr}_post_state`
1637
- ),
1638
- ]);
1624
+ const forkTypes = this.config.getForkTypes(blockSlot);
1625
+ const preStateRoot = toRootHex(preState.hashTreeRoot());
1626
+ const postStateRoot = toRootHex(postState.hashTreeRoot());
1627
+ const logStr = `slot_${blockSlot}_invalid_state_root_${postStateRoot}`;
1628
+ try {
1629
+ await Promise.all([
1630
+ this.persistSszObject(
1631
+ `SignedBeaconBlock_slot_${blockSlot}`,
1632
+ forkTypes.SignedBeaconBlock.serialize(block),
1633
+ toRootHex(forkTypes.BeaconBlock.hashTreeRoot(block.message)),
1634
+ `${logStr}_block`
1635
+ ),
1636
+ this.persistSszObject(
1637
+ `preState_slot_${preState.slot}_BeaconState`,
1638
+ preState.serialize(),
1639
+ preStateRoot,
1640
+ `${logStr}_pre_state`
1641
+ ),
1642
+ this.persistSszObject(
1643
+ `postState_slot_${postState.slot}_BeaconState`,
1644
+ postState.serialize(),
1645
+ postStateRoot,
1646
+ `${logStr}_post_state`
1647
+ ),
1648
+ ]);
1649
+ } catch (e) {
1650
+ this.logger.error(
1651
+ "Error persisting invalid state root objects",
1652
+ {slot: blockSlot, preStateRoot, postStateRoot},
1653
+ e as Error
1654
+ );
1655
+ }
1656
+ }
1657
+
1658
+ async persistInvalidSignature(state: IBeaconStateView, block: SignedBeaconBlock): Promise<void> {
1659
+ if (!this.opts.persistInvalidSszObjects) {
1660
+ return;
1661
+ }
1662
+ const blockSlot = block.message.slot;
1663
+ const forkTypes = this.config.getForkTypes(blockSlot);
1664
+ try {
1665
+ await Promise.all([
1666
+ this.persistSszObject(
1667
+ forkTypes.SignedBeaconBlock.typeName,
1668
+ forkTypes.SignedBeaconBlock.serialize(block),
1669
+ toRootHex(forkTypes.BeaconBlock.hashTreeRoot(block.message)),
1670
+ `${blockSlot}_invalid_signature`
1671
+ ),
1672
+ this.persistSszObject(
1673
+ "BeaconState",
1674
+ state.serialize(),
1675
+ toRootHex(state.hashTreeRoot()),
1676
+ `${state.slot}_invalid_signature`
1677
+ ),
1678
+ ]);
1679
+ } catch (e) {
1680
+ this.logger.error("Error persisting invalid signature objects", {slot: blockSlot}, e as Error);
1681
+ }
1639
1682
  }
1640
1683
 
1641
1684
  persistInvalidSszValue<T>(type: Type<T>, sszObject: T, suffix?: string, rootHex?: RootHex): void {
@@ -1650,12 +1693,6 @@ export class BeaconChain implements IBeaconChain {
1650
1693
  }
1651
1694
  }
1652
1695
 
1653
- persistInvalidSszBytes(typeName: string, sszBytes: Uint8Array, rootHex: RootHex, suffix?: string): void {
1654
- if (this.opts.persistInvalidSszObjects) {
1655
- void this.persistSszObject(typeName, sszBytes, rootHex, suffix);
1656
- }
1657
- }
1658
-
1659
1696
  /**
1660
1697
  * Regenerate state for attestation verification, this does not happen with default chain option of maxSkipSlots = 32 .
1661
1698
  * However, need to handle just in case. Lodestar doesn't support multiple regen state requests for attestation verification
@@ -1855,14 +1892,18 @@ export class BeaconChain implements IBeaconChain {
1855
1892
  private onClockSlot(slot: Slot): void {
1856
1893
  this.logger.verbose("Clock slot", {slot});
1857
1894
 
1858
- // CRITICAL UPDATE
1859
- if (this.forkChoice.irrecoverableError) {
1860
- this.processShutdownCallback(this.forkChoice.irrecoverableError);
1861
- }
1862
-
1863
1895
  // updateTime() recomputes the head on epoch-boundary checkpoint pull-up and under fast confirmation
1864
1896
  const prevHead = this.forkChoice.getHead();
1865
- this.forkChoice.updateTime(slot);
1897
+ try {
1898
+ this.forkChoice.updateTime(slot);
1899
+ } catch (e) {
1900
+ // Per optimistic sync the node MAY exit once the justified checkpoint is INVALIDATED, fork choice has no head
1901
+ if (e instanceof ForkChoiceError && e.type.code === ForkChoiceErrorCode.INVALID_JUSTIFIED_EXECUTION_STATUS) {
1902
+ this.processShutdownCallback(e);
1903
+ return;
1904
+ }
1905
+ throw e;
1906
+ }
1866
1907
  this.emitHeadEvents(prevHead, this.forkChoice.getHead());
1867
1908
  this.metrics?.clockSlot.set(slot);
1868
1909
 
@@ -7,7 +7,7 @@ export enum ExecutionPayloadBidErrorCode {
7
7
  NON_ZERO_EXECUTION_PAYMENT = "EXECUTION_PAYLOAD_BID_ERROR_NON_ZERO_EXECUTION_PAYMENT",
8
8
  BLOCK_HASH_EQUALS_PARENT_BLOCK_HASH = "EXECUTION_PAYLOAD_BID_ERROR_BLOCK_HASH_EQUALS_PARENT_BLOCK_HASH",
9
9
  INCOMPATIBLE_WITH_HEAD = "EXECUTION_PAYLOAD_BID_ERROR_INCOMPATIBLE_WITH_HEAD",
10
- BID_ALREADY_KNOWN = "EXECUTION_PAYLOAD_BID_ERROR_BID_ALREADY_KNOWN",
10
+ BID_LIMIT_REACHED = "EXECUTION_PAYLOAD_BID_ERROR_BID_LIMIT_REACHED",
11
11
  BID_TOO_LOW = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_LOW",
12
12
  BID_TOO_HIGH = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_HIGH",
13
13
  BUILDER_MAY_EXIT = "EXECUTION_PAYLOAD_BID_ERROR_BUILDER_MAY_EXIT",
@@ -46,11 +46,12 @@ export type ExecutionPayloadBidErrorType =
46
46
  headBlockRoot: RootHex;
47
47
  }
48
48
  | {
49
- code: ExecutionPayloadBidErrorCode.BID_ALREADY_KNOWN;
49
+ code: ExecutionPayloadBidErrorCode.BID_LIMIT_REACHED;
50
50
  builderIndex: BuilderIndex;
51
51
  slot: Slot;
52
52
  parentBlockRoot: RootHex;
53
53
  parentBlockHash: RootHex;
54
+ bidLimit: number;
54
55
  }
55
56
  | {code: ExecutionPayloadBidErrorCode.BID_TOO_LOW; bidValue: number; currentHighestBid: number}
56
57
  | {code: ExecutionPayloadBidErrorCode.BID_TOO_HIGH; bidValue: number; builderBalance: number}
@@ -303,8 +303,8 @@ export interface IBeaconChain {
303
303
  postState: IBeaconStateView,
304
304
  block: SignedBeaconBlock
305
305
  ): Promise<void>;
306
+ persistInvalidSignature(state: IBeaconStateView, block: SignedBeaconBlock): Promise<void>;
306
307
  persistInvalidSszValue<T>(type: Type<T>, sszObject: T, suffix?: string, rootHex?: RootHex): void;
307
- persistInvalidSszBytes(type: string, sszBytes: Uint8Array, rootHex: RootHex, suffix?: string): void;
308
308
  regenStateForAttestationVerification(
309
309
  attEpoch: Epoch,
310
310
  shufflingDependentRoot: RootHex,
@@ -290,7 +290,7 @@ export class OpPool {
290
290
  const endAttesterSlashings = stepsMetrics?.startTimer();
291
291
  const attesterSlashings: AttesterSlashing[] = [];
292
292
  const maxAttesterSlashings = stateFork >= ForkSeq.electra ? MAX_ATTESTER_SLASHINGS_ELECTRA : MAX_ATTESTER_SLASHINGS;
293
- attesterSlashing: for (const [key, attesterSlashing] of this.attesterSlashings) {
293
+ for (const [key, attesterSlashing] of this.attesterSlashings) {
294
294
  const domains = getAttesterSlashingSignatureDomains(this.config, state.slot, attesterSlashing.attesterSlashing);
295
295
  if (!attesterSlashing.verifiedDomains.every((domain, i) => byteArrayEquals(domain, domains[i]))) {
296
296
  this.attesterSlashings.delete(key);
@@ -300,18 +300,15 @@ export class OpPool {
300
300
  const slashableIndices = new Set<ValidatorIndex>();
301
301
  for (let i = 0; i < attesterSlashing.intersectingIndices.length; i++) {
302
302
  const index = attesterSlashing.intersectingIndices[i];
303
- // If we already have a slashing for this index, we can continue on to the next slashing
303
+ // Covered by an earlier slashing in this block, the remaining indices may still be slashable
304
304
  if (toBeSlashedIndices.has(index)) {
305
- continue attesterSlashing;
305
+ continue;
306
306
  }
307
307
 
308
308
  const validator = state.getValidator(index);
309
309
  if (isSlashableAtEpoch(validator, stateEpoch)) {
310
310
  slashableIndices.add(index);
311
311
  }
312
- if (attesterSlashings.length >= maxAttesterSlashings) {
313
- break attesterSlashing;
314
- }
315
312
  }
316
313
 
317
314
  // If there were slashable indices in this slashing
@@ -321,6 +318,9 @@ export class OpPool {
321
318
  for (const index of slashableIndices) {
322
319
  toBeSlashedIndices.add(index);
323
320
  }
321
+ if (attesterSlashings.length >= maxAttesterSlashings) {
322
+ break;
323
+ }
324
324
  }
325
325
  }
326
326
  endAttesterSlashings?.({