@lodestar/beacon-node 1.52.0-dev.6ab73fec0a → 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 (160) 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/blockInput/blockInput.d.ts.map +1 -1
  17. package/lib/chain/blocks/blockInput/blockInput.js +3 -1
  18. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  19. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  20. package/lib/chain/blocks/importExecutionPayload.js +17 -3
  21. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  22. package/lib/chain/blocks/index.d.ts.map +1 -1
  23. package/lib/chain/blocks/index.js +3 -16
  24. package/lib/chain/blocks/index.js.map +1 -1
  25. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  26. package/lib/chain/blocks/verifyBlock.js +21 -17
  27. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  28. package/lib/chain/blocks/verifyBlocksDataAvailability.d.ts +2 -2
  29. package/lib/chain/blocks/verifyBlocksDataAvailability.d.ts.map +1 -1
  30. package/lib/chain/blocks/verifyBlocksDataAvailability.js +3 -3
  31. package/lib/chain/blocks/verifyBlocksDataAvailability.js.map +1 -1
  32. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  33. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +7 -5
  34. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  35. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  36. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  37. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -1
  38. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  39. package/lib/chain/blocks/verifyPayloadsDataAvailability.d.ts +2 -2
  40. package/lib/chain/blocks/verifyPayloadsDataAvailability.d.ts.map +1 -1
  41. package/lib/chain/blocks/verifyPayloadsDataAvailability.js +3 -3
  42. package/lib/chain/blocks/verifyPayloadsDataAvailability.js.map +1 -1
  43. package/lib/chain/bls/utils.js +1 -1
  44. package/lib/chain/bls/utils.js.map +1 -1
  45. package/lib/chain/chain.d.ts +3 -3
  46. package/lib/chain/chain.d.ts.map +1 -1
  47. package/lib/chain/chain.js +53 -24
  48. package/lib/chain/chain.js.map +1 -1
  49. package/lib/chain/errors/executionPayloadBid.d.ts +3 -2
  50. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  51. package/lib/chain/errors/executionPayloadBid.js +1 -1
  52. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  53. package/lib/chain/forkChoice/index.d.ts +1 -4
  54. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  55. package/lib/chain/forkChoice/index.js +1 -4
  56. package/lib/chain/forkChoice/index.js.map +1 -1
  57. package/lib/chain/forkChoiceExecutionEngine.d.ts +5 -3
  58. package/lib/chain/forkChoiceExecutionEngine.d.ts.map +1 -1
  59. package/lib/chain/forkChoiceExecutionEngine.js +34 -11
  60. package/lib/chain/forkChoiceExecutionEngine.js.map +1 -1
  61. package/lib/chain/interface.d.ts +1 -1
  62. package/lib/chain/interface.d.ts.map +1 -1
  63. package/lib/chain/opPools/inclusionListStore.d.ts +4 -1
  64. package/lib/chain/opPools/inclusionListStore.d.ts.map +1 -1
  65. package/lib/chain/opPools/inclusionListStore.js +5 -2
  66. package/lib/chain/opPools/inclusionListStore.js.map +1 -1
  67. package/lib/chain/opPools/opPool.js +6 -6
  68. package/lib/chain/opPools/opPool.js.map +1 -1
  69. package/lib/chain/options.js +1 -1
  70. package/lib/chain/options.js.map +1 -1
  71. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +13 -4
  72. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
  73. package/lib/chain/seenCache/seenExecutionPayloadBids.js +13 -12
  74. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
  75. package/lib/chain/shufflingCache.d.ts +5 -0
  76. package/lib/chain/shufflingCache.d.ts.map +1 -1
  77. package/lib/chain/shufflingCache.js +39 -1
  78. package/lib/chain/shufflingCache.js.map +1 -1
  79. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
  80. package/lib/chain/validation/aggregateAndProof.js +13 -2
  81. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  82. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  83. package/lib/chain/validation/dataColumnSidecar.js +8 -1
  84. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  85. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  86. package/lib/chain/validation/executionPayloadBid.js +30 -40
  87. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  88. package/lib/chain/validation/payloadAttestationMessage.js +9 -0
  89. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  90. package/lib/metrics/metrics/beacon.d.ts +4 -0
  91. package/lib/metrics/metrics/beacon.d.ts.map +1 -1
  92. package/lib/metrics/metrics/beacon.js +11 -2
  93. package/lib/metrics/metrics/beacon.js.map +1 -1
  94. package/lib/metrics/metrics/lodestar.d.ts +2 -0
  95. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  96. package/lib/metrics/metrics/lodestar.js +37 -28
  97. package/lib/metrics/metrics/lodestar.js.map +1 -1
  98. package/lib/network/gossip/topic.d.ts +1 -7
  99. package/lib/network/gossip/topic.d.ts.map +1 -1
  100. package/lib/network/gossip/topic.js +0 -13
  101. package/lib/network/gossip/topic.js.map +1 -1
  102. package/lib/network/network.d.ts +1 -0
  103. package/lib/network/network.d.ts.map +1 -1
  104. package/lib/network/network.js +20 -11
  105. package/lib/network/network.js.map +1 -1
  106. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  107. package/lib/network/processor/gossipHandlers.js +8 -4
  108. package/lib/network/processor/gossipHandlers.js.map +1 -1
  109. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  110. package/lib/network/processor/gossipValidatorFn.js +4 -1
  111. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  112. package/lib/network/reqresp/utils/collect.d.ts +4 -4
  113. package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
  114. package/lib/network/reqresp/utils/collect.js +9 -8
  115. package/lib/network/reqresp/utils/collect.js.map +1 -1
  116. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +1 -1
  117. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
  118. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +2 -2
  119. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
  120. package/lib/sync/unknownBlock.d.ts.map +1 -1
  121. package/lib/sync/unknownBlock.js +2 -1
  122. package/lib/sync/unknownBlock.js.map +1 -1
  123. package/package.json +16 -16
  124. package/src/api/impl/beacon/blocks/index.ts +74 -47
  125. package/src/api/impl/beacon/pool/index.ts +9 -7
  126. package/src/api/impl/beacon/state/utils.ts +2 -1
  127. package/src/api/impl/debug/index.ts +6 -2
  128. package/src/api/impl/validator/index.ts +6 -3
  129. package/src/chain/blocks/blockInput/blockInput.ts +4 -1
  130. package/src/chain/blocks/importExecutionPayload.ts +21 -2
  131. package/src/chain/blocks/index.ts +3 -30
  132. package/src/chain/blocks/verifyBlock.ts +24 -17
  133. package/src/chain/blocks/verifyBlocksDataAvailability.ts +4 -4
  134. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +7 -4
  135. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -0
  136. package/src/chain/blocks/verifyPayloadsDataAvailability.ts +5 -4
  137. package/src/chain/bls/utils.ts +1 -1
  138. package/src/chain/chain.ts +81 -40
  139. package/src/chain/errors/executionPayloadBid.ts +3 -2
  140. package/src/chain/forkChoice/index.ts +1 -4
  141. package/src/chain/forkChoiceExecutionEngine.ts +48 -15
  142. package/src/chain/interface.ts +1 -1
  143. package/src/chain/opPools/inclusionListStore.ts +5 -2
  144. package/src/chain/opPools/opPool.ts +6 -6
  145. package/src/chain/options.ts +1 -1
  146. package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
  147. package/src/chain/shufflingCache.ts +40 -1
  148. package/src/chain/validation/aggregateAndProof.ts +19 -5
  149. package/src/chain/validation/dataColumnSidecar.ts +7 -1
  150. package/src/chain/validation/executionPayloadBid.ts +40 -42
  151. package/src/chain/validation/payloadAttestationMessage.ts +10 -0
  152. package/src/metrics/metrics/beacon.ts +11 -2
  153. package/src/metrics/metrics/lodestar.ts +37 -28
  154. package/src/network/gossip/topic.ts +1 -14
  155. package/src/network/network.ts +33 -11
  156. package/src/network/processor/gossipHandlers.ts +14 -10
  157. package/src/network/processor/gossipValidatorFn.ts +4 -0
  158. package/src/network/reqresp/utils/collect.ts +16 -8
  159. package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +3 -2
  160. package/src/sync/unknownBlock.ts +2 -1
@@ -3,6 +3,7 @@ import {
3
3
  BlockExecutionStatus,
4
4
  ExecutionStatus,
5
5
  IForkChoice,
6
+ LVHInvalidJudged,
6
7
  LVHInvalidResponse,
7
8
  LVHValidResponse,
8
9
  ProtoBlock,
@@ -200,8 +201,9 @@ export async function verifyBlockExecutionPayload(
200
201
  const lvhResponse = {
201
202
  executionStatus,
202
203
  latestValidExecHash: execResult.latestValidHash,
203
- invalidateFromParentBlockRoot: blockInput.parentRootHex,
204
- invalidateFromParentBlockHash: toRootHex(executionPayloadEnabled.parentHash),
204
+ invalidateFromBlockRoot: blockInput.parentRootHex,
205
+ invalidateFromBlockHash: toRootHex(executionPayloadEnabled.parentHash),
206
+ judged: LVHInvalidJudged.ChildPayload,
205
207
  };
206
208
  const execError = new BlockError(block, {
207
209
  code: BlockErrorCode.EXECUTION_ENGINE_INVALID,
@@ -284,8 +286,9 @@ function getSegmentErrorResponse(
284
286
  invalidSegmentLVH = {
285
287
  executionStatus: ExecutionStatus.Invalid,
286
288
  latestValidExecHash: lvhResponse.latestValidExecHash,
287
- invalidateFromParentBlockRoot: parentBlock.blockRoot,
288
- invalidateFromParentBlockHash: parentBlock.executionPayloadBlockHash,
289
+ invalidateFromBlockRoot: parentBlock.blockRoot,
290
+ invalidateFromBlockHash: parentBlock.executionPayloadBlockHash,
291
+ judged: LVHInvalidJudged.ChildPayload,
289
292
  };
290
293
  }
291
294
  }
@@ -1,5 +1,6 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {
3
+ EpochShuffling,
3
4
  IBeaconStateView,
4
5
  SyncCommitteeCacheEmpty,
5
6
  getBlockSignatureSets,
@@ -28,6 +29,7 @@ export async function verifyBlocksSignatures(
28
29
  preState0: IBeaconStateView,
29
30
  blocks: SignedBeaconBlock[],
30
31
  indexedAttestationsByBlock: IndexedAttestation[][],
32
+ attestationShufflingsByBlock: EpochShuffling[][],
31
33
  opts: ImportBlockOpts
32
34
  ): Promise<{verifySignaturesTime: number}> {
33
35
  const isValidPromises: Promise<boolean>[] = [];
@@ -49,6 +51,7 @@ export async function verifyBlocksSignatures(
49
51
  bls.verifySignatureSets(
50
52
  getBlockSignatureSets(config, currentSyncCommitteeIndexed, preState0, block, indexedAttestationsByBlock[i], {
51
53
  skipProposerSignature: opts.validProposerSignature,
54
+ attestationShufflings: attestationShufflingsByBlock[i],
52
55
  }),
53
56
  // Prioritize block verification over attestations, since
54
57
  // attestations already buffer up to `MAX_BUFFER_WAIT_MS`
@@ -8,7 +8,7 @@ import {PayloadError, PayloadErrorCode} from "./importExecutionPayload.js";
8
8
  /**
9
9
  * Verifies that all payload envelope inputs have their data columns available.
10
10
  * - Waits a max of one slot duration of the payload's fork for all data to be available
11
- * - Returns the time at which all data was available
11
+ * - Returns the time at which all data was available, in Unix milliseconds
12
12
  * - Returns the data availability status for each payload input
13
13
  */
14
14
  export async function verifyPayloadsDataAvailability(
@@ -17,7 +17,7 @@ export async function verifyPayloadsDataAvailability(
17
17
  signal: AbortSignal
18
18
  ): Promise<{
19
19
  dataAvailabilityStatuses: DataAvailabilityStatus[];
20
- availableTime: number;
20
+ availableTimeMs: number;
21
21
  }> {
22
22
  const promises: Promise<gloas.DataColumnSidecar[]>[] = [];
23
23
  for (const payloadInput of payloadInputs) {
@@ -35,7 +35,8 @@ export async function verifyPayloadsDataAvailability(
35
35
  }
36
36
  await Promise.all(promises);
37
37
 
38
- const availableTime = Math.max(0, Math.max(...payloadInputs.map((payloadInput) => payloadInput.getTimeComplete())));
38
+ const availableTimeMs =
39
+ Math.max(0, Math.max(...payloadInputs.map((payloadInput) => payloadInput.getTimeComplete()))) * 1000;
39
40
  const dataAvailabilityStatuses: DataAvailabilityStatus[] = payloadInputs.map((payloadInput) => {
40
41
  if (payloadInput.daOutOfRange) {
41
42
  return DataAvailabilityStatus.OutOfRange;
@@ -45,5 +46,5 @@ export async function verifyPayloadsDataAvailability(
45
46
  : DataAvailabilityStatus.Available;
46
47
  });
47
48
 
48
- return {dataAvailabilityStatuses, availableTime};
49
+ return {dataAvailabilityStatuses, availableTimeMs};
49
50
  }
@@ -32,7 +32,7 @@ export function chunkSameMessageSignatureSets(sets: SameMessageSignatureSet[]):
32
32
  export function getAggregatedPubkeysCount(signatureSets: ISignatureSet[]): number {
33
33
  let pubkeysCount = 0;
34
34
  for (const set of signatureSets) {
35
- if (set.type === SignatureSetType.aggregate) {
35
+ if (set.type === SignatureSetType.aggregate || set.type === SignatureSetType.committee) {
36
36
  pubkeysCount += set.indices.length;
37
37
  }
38
38
  }
@@ -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}
@@ -37,10 +37,7 @@ export enum ForkchoiceCaller {
37
37
  executionInvalid = "execution_invalid",
38
38
  }
39
39
 
40
- /**
41
- * Where an execution engine INVALID verdict comes from. Only `blockSegment` verdicts are about the payload the engine
42
- * just processed and keep the consensus failure semantics in fork choice, the others are applied leniently.
43
- */
40
+ /** Where an execution engine INVALID verdict comes from, a label for logs and metrics */
44
41
  export enum ExecutionInvalidSource {
45
42
  forkchoiceUpdated = "forkchoice_updated",
46
43
  newPayload = "new_payload",
@@ -1,8 +1,15 @@
1
- import {ExecutionStatus, IForkChoice, LVHInvalidResponse} from "@lodestar/fork-choice";
1
+ import {
2
+ ExecutionStatus,
3
+ IForkChoice,
4
+ LVHInvalidJudged,
5
+ LVHInvalidResponse,
6
+ LVHNotAppliedReason,
7
+ LVHVerdictResult,
8
+ } from "@lodestar/fork-choice";
2
9
  import {ForkName, ForkPostFulu} from "@lodestar/params";
3
10
  import {RootHex, bellatrix} from "@lodestar/types";
4
11
  import {BlobAndProofV2} from "@lodestar/types/fulu";
5
- import {Logger} from "@lodestar/utils";
12
+ import {LogDataBasic, Logger} from "@lodestar/utils";
6
13
  import {ExecutionPayloadBodyV2} from "../execution/engine/types.js";
7
14
  import {DATA} from "../execution/engine/utils.js";
8
15
  import {
@@ -119,18 +126,25 @@ export class ForkChoiceExecutionEngine {
119
126
  }
120
127
 
121
128
  /**
122
- * Apply an execution engine INVALID verdict to fork choice and move the chain head off the invalid chain
129
+ * Apply an execution engine INVALID verdict to fork choice and move the chain head off the invalid chain.
130
+ * `judgedLogCtx` identifies the judged payload in logs when it is not the from node.
123
131
  */
124
- invalidateExecutionPayloads(lvh: LVHInvalidResponse, source: ExecutionInvalidSource): void {
132
+ invalidateExecutionPayloads(
133
+ lvh: LVHInvalidResponse,
134
+ source: ExecutionInvalidSource,
135
+ judgedLogCtx?: Record<string, LogDataBasic>
136
+ ): void {
125
137
  const logCtx = {
138
+ ...judgedLogCtx,
126
139
  source,
127
- blockRoot: lvh.invalidateFromParentBlockRoot,
128
- blockHash: lvh.invalidateFromParentBlockHash,
140
+ judged: lvh.judged,
141
+ fromBlockRoot: lvh.invalidateFromBlockRoot,
142
+ fromBlockHash: lvh.invalidateFromBlockHash,
129
143
  latestValidHash: lvh.latestValidExecHash ?? "null",
130
144
  };
131
- const applied = this.forkChoice.validateLatestHash(lvh, {strict: source === ExecutionInvalidSource.blockSegment});
132
- if (!applied) {
133
- this.logger.warn("Execution engine INVALID verdict not applied to fork choice", logCtx);
145
+ const result = this.forkChoice.validateLatestHash(lvh);
146
+ if (!result.applied) {
147
+ this.logNotApplied(result, logCtx);
134
148
  return;
135
149
  }
136
150
  this.metrics?.forkChoice.executionInvalidations.inc({source});
@@ -143,6 +157,20 @@ export class ForkChoiceExecutionEngine {
143
157
  }
144
158
  }
145
159
 
160
+ private logNotApplied(
161
+ result: Exclude<LVHVerdictResult, {applied: true}>,
162
+ logCtx: Record<string, LogDataBasic>
163
+ ): void {
164
+ const message = "Execution engine verdict not applied to fork choice";
165
+ if (result.reason === LVHNotAppliedReason.Error) {
166
+ this.logger.error(message, {...logCtx, reason: result.reason}, result.error);
167
+ } else if (result.reason === LVHNotAppliedReason.AlreadyApplied) {
168
+ this.logger.debug(message, {...logCtx, reason: result.reason});
169
+ } else {
170
+ this.logger.warn(message, {...logCtx, reason: result.reason});
171
+ }
172
+ }
173
+
146
174
  private applyForkchoiceUpdatedResult(
147
175
  headBlockRoot: RootHex,
148
176
  headBlockHash: RootHex,
@@ -165,16 +193,21 @@ export class ForkChoiceExecutionEngine {
165
193
  {
166
194
  executionStatus: ExecutionStatus.Invalid,
167
195
  latestValidExecHash: latestValidHash,
168
- invalidateFromParentBlockRoot: headBlockRoot,
169
- invalidateFromParentBlockHash: headBlockHash,
196
+ invalidateFromBlockRoot: headBlockRoot,
197
+ invalidateFromBlockHash: headBlockHash,
198
+ judged: LVHInvalidJudged.FromBlock,
170
199
  },
171
200
  ExecutionInvalidSource.forkchoiceUpdated
172
201
  );
173
202
  } else if (status === ExecutionPayloadStatus.VALID && executionStatus === ExecutionStatus.Syncing) {
174
- this.forkChoice.validateLatestHash(
175
- {executionStatus: ExecutionStatus.Valid, latestValidExecHash: headBlockHash, blockRoot: headBlockRoot},
176
- {strict: false}
177
- );
203
+ const result = this.forkChoice.validateLatestHash({
204
+ executionStatus: ExecutionStatus.Valid,
205
+ latestValidExecHash: headBlockHash,
206
+ blockRoot: headBlockRoot,
207
+ });
208
+ if (!result.applied) {
209
+ this.logNotApplied(result, {source: ExecutionInvalidSource.forkchoiceUpdated, headBlockRoot, headBlockHash});
210
+ }
178
211
  }
179
212
  } catch (e) {
180
213
  this.logger.error("Error applying forkchoice update result", {headBlockRoot, headBlockHash, status}, e as Error);
@@ -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,
@@ -164,9 +164,12 @@ export class InclusionListStore {
164
164
  return out;
165
165
  }
166
166
 
167
- /** Lists are retained for MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS slots so InclusionListsByIndices can serve them */
167
+ /**
168
+ * Lists are kept one slot past the MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS serving window, the lists of slot N are
169
+ * read when the payload of slot N + 1 is processed, which may happen during slot N + 2
170
+ */
168
171
  prune(clockSlot: Slot): void {
169
- const horizon = clockSlot - this.config.MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS;
172
+ const horizon = clockSlot - this.config.MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS - 1;
170
173
 
171
174
  for (const slot of this.inclusionLists.keys()) {
172
175
  if (slot < horizon) {
@@ -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?.({
@@ -132,7 +132,7 @@ export const defaultChainOptions: IChainOptions = {
132
132
  // - users can prune the persisted checkpoint state files manually to save disc space
133
133
  // - it helps debug easier when network is unfinalized
134
134
  nHistoricalStatesFileDataStore: true,
135
- nativeStateTransition: false,
135
+ nativeStateTransition: true,
136
136
  maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
137
137
  maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
138
138
  maxCPStateEpochsOnDisk: DEFAULT_MAX_CP_STATE_ON_DISK,
@@ -6,38 +6,58 @@ import {MapDef} from "@lodestar/utils";
6
6
  */
7
7
  const SLOTS_RETAINED = 2;
8
8
 
9
+ export type SeenBuilderBids = {
10
+ /** Number of valid bids seen */
11
+ count: number;
12
+ /**
13
+ * The builder's bid limit. Bids for the same slot and parent root are validated against the same state,
14
+ * so it is known without the state once a bid was valid
15
+ */
16
+ limit: number;
17
+ };
18
+
9
19
  /**
10
- * Tracks execution payload bids we've already seen per
20
+ * Counts the valid execution payload bids seen per
11
21
  * (slot, builder, parent block hash, parent block root).
12
22
  */
13
23
  export class SeenExecutionPayloadBids {
14
- private readonly branchesByBuilderBySlot = new MapDef<Slot, MapDef<BuilderIndex, Set<string>>>(
15
- () => new MapDef<BuilderIndex, Set<string>>(() => new Set<string>())
24
+ private readonly bidsByBranchByBuilderBySlot = new MapDef<Slot, MapDef<BuilderIndex, Map<string, SeenBuilderBids>>>(
25
+ () => new MapDef<BuilderIndex, Map<string, SeenBuilderBids>>(() => new Map<string, SeenBuilderBids>())
16
26
  );
17
27
  private lowestPermissibleSlot: Slot = 0;
18
28
 
19
- isKnown(slot: Slot, builderIndex: BuilderIndex, parentBlockHash: RootHex, parentBlockRoot: RootHex): boolean {
20
- return (
21
- this.branchesByBuilderBySlot.get(slot)?.get(builderIndex)?.has(branchKey(parentBlockHash, parentBlockRoot)) ===
22
- true
23
- );
29
+ get(
30
+ slot: Slot,
31
+ builderIndex: BuilderIndex,
32
+ parentBlockHash: RootHex,
33
+ parentBlockRoot: RootHex
34
+ ): SeenBuilderBids | undefined {
35
+ return this.bidsByBranchByBuilderBySlot
36
+ .get(slot)
37
+ ?.get(builderIndex)
38
+ ?.get(branchKey(parentBlockHash, parentBlockRoot));
24
39
  }
25
40
 
26
- add(slot: Slot, builderIndex: BuilderIndex, parentBlockHash: RootHex, parentBlockRoot: RootHex): void {
41
+ add(
42
+ slot: Slot,
43
+ builderIndex: BuilderIndex,
44
+ parentBlockHash: RootHex,
45
+ parentBlockRoot: RootHex,
46
+ bidLimit: number
47
+ ): void {
27
48
  if (slot < this.lowestPermissibleSlot) {
28
49
  throw Error(`slot ${slot} < lowestPermissibleSlot ${this.lowestPermissibleSlot}`);
29
50
  }
30
- this.branchesByBuilderBySlot
31
- .getOrDefault(slot)
32
- .getOrDefault(builderIndex)
33
- .add(branchKey(parentBlockHash, parentBlockRoot));
51
+ const bidsByBranch = this.bidsByBranchByBuilderBySlot.getOrDefault(slot).getOrDefault(builderIndex);
52
+ const key = branchKey(parentBlockHash, parentBlockRoot);
53
+ bidsByBranch.set(key, {count: (bidsByBranch.get(key)?.count ?? 0) + 1, limit: bidLimit});
34
54
  }
35
55
 
36
56
  prune(currentSlot: Slot): void {
37
57
  this.lowestPermissibleSlot = Math.max(currentSlot - SLOTS_RETAINED, 0);
38
- for (const slot of this.branchesByBuilderBySlot.keys()) {
58
+ for (const slot of this.bidsByBranchByBuilderBySlot.keys()) {
39
59
  if (slot < this.lowestPermissibleSlot) {
40
- this.branchesByBuilderBySlot.delete(slot);
60
+ this.bidsByBranchByBuilderBySlot.delete(slot);
41
61
  }
42
62
  }
43
63
  }
@@ -1,4 +1,5 @@
1
- import {ForkSeq, GENESIS_EPOCH} from "@lodestar/params";
1
+ import {computeCommitteePubkeys, releaseCommitteePubkeys} from "@lodestar/native/committee-pubkeys";
2
+ import {ForkSeq, GENESIS_EPOCH, SLOTS_PER_EPOCH} from "@lodestar/params";
2
3
  import {
3
4
  EpochShuffling,
4
5
  IBeaconStateView,
@@ -272,6 +273,40 @@ export class ShufflingCache {
272
273
  // set the shuffling
273
274
  shufflingAtEpoch.set(decisionRoot, {type: CacheItemType.shuffling, shuffling});
274
275
  this.prune();
276
+ if (this.has(shuffling.epoch, decisionRoot)) {
277
+ this.computeCommitteePubkeys(shuffling, decisionRoot);
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Committee pubkeys make attestation signature sets cheaper to verify. Until they resolve, and if computing them
283
+ * fails, sets aggregate the participants instead.
284
+ */
285
+ private computeCommitteePubkeys(shuffling: EpochShuffling, decisionRoot: RootHex): void {
286
+ const timer = this.metrics?.shufflingCache.committeePubkeysComputeTime.startTimer();
287
+ const onError = (e: unknown): void => {
288
+ this.metrics?.shufflingCache.committeePubkeysErrors.inc();
289
+ this.logger?.debug("Error computing committee pubkeys", {epoch: shuffling.epoch, decisionRoot}, e as Error);
290
+ };
291
+
292
+ let promise: Promise<number>;
293
+ try {
294
+ promise = computeCommitteePubkeys(shuffling.shuffling, SLOTS_PER_EPOCH, shuffling.committeesPerSlot);
295
+ } catch (e) {
296
+ onError(e);
297
+ return;
298
+ }
299
+
300
+ promise.then((id) => {
301
+ timer?.();
302
+ const cacheItem = this.itemsByDecisionRootByEpoch.get(shuffling.epoch)?.get(decisionRoot);
303
+ if (cacheItem !== undefined && isShufflingCacheItem(cacheItem) && cacheItem.shuffling === shuffling) {
304
+ shuffling.committeePubkeysId = id;
305
+ } else {
306
+ // Pruned while computing
307
+ releaseCommitteePubkeys(id);
308
+ }
309
+ }, onError);
275
310
  }
276
311
 
277
312
  /**
@@ -294,6 +329,10 @@ export class ShufflingCache {
294
329
  this.metrics?.shufflingCache.cancelledPromises.inc({reason: ShufflingPromiseCancelReason.pruned});
295
330
  } else {
296
331
  prunedShufflings++;
332
+ if (cacheItem.shuffling.committeePubkeysId !== undefined) {
333
+ releaseCommitteePubkeys(cacheItem.shuffling.committeePubkeysId);
334
+ cacheItem.shuffling.committeePubkeysId = undefined;
335
+ }
297
336
  }
298
337
  }
299
338
  this.itemsByDecisionRootByEpoch.delete(epoch);
@@ -1,5 +1,7 @@
1
1
  import {ForkName, ForkSeq} from "@lodestar/params";
2
2
  import {
3
+ ISignatureSet,
4
+ SignatureSetType,
3
5
  computeEpochAtSlot,
4
6
  createAggregateSignatureSetFromComponents,
5
7
  isAggregatorFromCommitteeLength,
@@ -259,11 +261,23 @@ async function validateAggregateAndProof(
259
261
  // [REJECT] The aggregator signature, signed_aggregate_and_proof.signature, is valid.
260
262
  // [REJECT] The signature of aggregate is valid.
261
263
  const signingRoot = cachedAttData ? cachedAttData.signingRoot : getAttestationDataSigningRoot(chain.config, attData);
262
- const indexedAttestationSignatureSet = createAggregateSignatureSetFromComponents(
263
- indexedAttestation.attestingIndices,
264
- signingRoot,
265
- indexedAttestation.signature
266
- );
264
+ const indexedAttestationSignatureSet: ISignatureSet =
265
+ shuffling.committeePubkeysId === undefined
266
+ ? createAggregateSignatureSetFromComponents(
267
+ indexedAttestation.attestingIndices,
268
+ signingRoot,
269
+ indexedAttestation.signature
270
+ )
271
+ : {
272
+ type: SignatureSetType.committee,
273
+ indices: indexedAttestation.attestingIndices,
274
+ committeePubkeysId: shuffling.committeePubkeysId,
275
+ slot: attSlot,
276
+ committeeIndices: [committeeIndex],
277
+ aggregationBits: aggregate.aggregationBits,
278
+ signingRoot,
279
+ signature: indexedAttestation.signature,
280
+ };
267
281
  const signatureSets = [
268
282
  getSelectionProofSignatureSet(chain.config, attSlot, aggregatorIndex, signedAggregateAndProof),
269
283
  getAggregateAndProofSignatureSet(chain.config, attEpoch, aggregatorIndex, signedAggregateAndProof),