@lodestar/beacon-node 1.52.0-dev.b76fc9b708 → 1.52.0-dev.c90a21c764

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 (65) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +17 -13
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/validator/index.d.ts.map +1 -1
  5. package/lib/api/impl/validator/index.js +4 -3
  6. package/lib/api/impl/validator/index.js.map +1 -1
  7. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  8. package/lib/chain/blocks/importExecutionPayload.js +17 -3
  9. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  10. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  11. package/lib/chain/blocks/verifyBlock.js +12 -11
  12. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  13. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  14. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +7 -5
  15. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  16. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  17. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  18. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -1
  19. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  20. package/lib/chain/bls/utils.js +1 -1
  21. package/lib/chain/bls/utils.js.map +1 -1
  22. package/lib/chain/chain.d.ts.map +1 -1
  23. package/lib/chain/chain.js +12 -6
  24. package/lib/chain/chain.js.map +1 -1
  25. package/lib/chain/forkChoice/index.d.ts +1 -4
  26. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  27. package/lib/chain/forkChoice/index.js +1 -4
  28. package/lib/chain/forkChoice/index.js.map +1 -1
  29. package/lib/chain/forkChoiceExecutionEngine.d.ts +5 -3
  30. package/lib/chain/forkChoiceExecutionEngine.d.ts.map +1 -1
  31. package/lib/chain/forkChoiceExecutionEngine.js +34 -11
  32. package/lib/chain/forkChoiceExecutionEngine.js.map +1 -1
  33. package/lib/chain/opPools/inclusionListStore.d.ts +4 -1
  34. package/lib/chain/opPools/inclusionListStore.d.ts.map +1 -1
  35. package/lib/chain/opPools/inclusionListStore.js +5 -2
  36. package/lib/chain/opPools/inclusionListStore.js.map +1 -1
  37. package/lib/chain/options.js +1 -1
  38. package/lib/chain/options.js.map +1 -1
  39. package/lib/chain/shufflingCache.d.ts +5 -0
  40. package/lib/chain/shufflingCache.d.ts.map +1 -1
  41. package/lib/chain/shufflingCache.js +39 -1
  42. package/lib/chain/shufflingCache.js.map +1 -1
  43. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
  44. package/lib/chain/validation/aggregateAndProof.js +13 -2
  45. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  46. package/lib/metrics/metrics/lodestar.d.ts +2 -0
  47. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  48. package/lib/metrics/metrics/lodestar.js +9 -0
  49. package/lib/metrics/metrics/lodestar.js.map +1 -1
  50. package/package.json +16 -16
  51. package/src/api/impl/beacon/blocks/index.ts +22 -19
  52. package/src/api/impl/validator/index.ts +4 -2
  53. package/src/chain/blocks/importExecutionPayload.ts +21 -2
  54. package/src/chain/blocks/verifyBlock.ts +14 -10
  55. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +7 -4
  56. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -0
  57. package/src/chain/bls/utils.ts +1 -1
  58. package/src/chain/chain.ts +12 -6
  59. package/src/chain/forkChoice/index.ts +1 -4
  60. package/src/chain/forkChoiceExecutionEngine.ts +48 -15
  61. package/src/chain/opPools/inclusionListStore.ts +5 -2
  62. package/src/chain/options.ts +1 -1
  63. package/src/chain/shufflingCache.ts +40 -1
  64. package/src/chain/validation/aggregateAndProof.ts +19 -5
  65. package/src/metrics/metrics/lodestar.ts +9 -0
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.52.0-dev.b76fc9b708",
14
+ "version": "1.52.0-dev.c90a21c764",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -126,18 +126,18 @@
126
126
  "@libp2p/prometheus-metrics": "^5.0.31",
127
127
  "@libp2p/tcp": "^11.0.30",
128
128
  "@libp2p/utils": "^7.4.3",
129
- "@lodestar/api": "^1.52.0-dev.b76fc9b708",
130
- "@lodestar/config": "^1.52.0-dev.b76fc9b708",
131
- "@lodestar/db": "^1.52.0-dev.b76fc9b708",
132
- "@lodestar/fork-choice": "^1.52.0-dev.b76fc9b708",
133
- "@lodestar/logger": "^1.52.0-dev.b76fc9b708",
134
- "@lodestar/native": "^1.52.0-dev.b76fc9b708",
135
- "@lodestar/params": "^1.52.0-dev.b76fc9b708",
136
- "@lodestar/reqresp": "^1.52.0-dev.b76fc9b708",
137
- "@lodestar/state-transition": "^1.52.0-dev.b76fc9b708",
138
- "@lodestar/types": "^1.52.0-dev.b76fc9b708",
139
- "@lodestar/utils": "^1.52.0-dev.b76fc9b708",
140
- "@lodestar/validator": "^1.52.0-dev.b76fc9b708",
129
+ "@lodestar/api": "^1.52.0-dev.c90a21c764",
130
+ "@lodestar/config": "^1.52.0-dev.c90a21c764",
131
+ "@lodestar/db": "^1.52.0-dev.c90a21c764",
132
+ "@lodestar/fork-choice": "^1.52.0-dev.c90a21c764",
133
+ "@lodestar/logger": "^1.52.0-dev.c90a21c764",
134
+ "@lodestar/native": "^1.52.0-dev.c90a21c764",
135
+ "@lodestar/params": "^1.52.0-dev.c90a21c764",
136
+ "@lodestar/reqresp": "^1.52.0-dev.c90a21c764",
137
+ "@lodestar/state-transition": "^1.52.0-dev.c90a21c764",
138
+ "@lodestar/types": "^1.52.0-dev.c90a21c764",
139
+ "@lodestar/utils": "^1.52.0-dev.c90a21c764",
140
+ "@lodestar/validator": "^1.52.0-dev.c90a21c764",
141
141
  "@multiformats/multiaddr": "^13.0.1",
142
142
  "datastore-core": "^12.0.1",
143
143
  "datastore-level": "^13.0.1",
@@ -159,8 +159,8 @@
159
159
  "@ethereumjs/rlp": "^4.0.1",
160
160
  "@libp2p/interface-internal": "^3.2.0",
161
161
  "@libp2p/logger": "^6.2.15",
162
- "@lodestar/spec-test-util": "^1.52.0-dev.b76fc9b708",
163
- "@lodestar/test-utils": "^1.52.0-dev.b76fc9b708",
162
+ "@lodestar/spec-test-util": "^1.52.0-dev.c90a21c764",
163
+ "@lodestar/test-utils": "^1.52.0-dev.c90a21c764",
164
164
  "@types/js-yaml": "^4.0.5",
165
165
  "@types/qs": "^6.9.7",
166
166
  "@types/tmp": "^0.2.3",
@@ -174,5 +174,5 @@
174
174
  "beacon",
175
175
  "blockchain"
176
176
  ],
177
- "gitHead": "7c6dacac80876857efe61b16333b3414bc5725ad"
177
+ "gitHead": "2fa0492e8af233db9acb5f04187fb2fb71f950ab"
178
178
  }
@@ -190,28 +190,31 @@ export function getBeaconBlockApi(
190
190
 
191
191
  switch (broadcastValidation) {
192
192
  case routes.beacon.BroadcastValidation.gossip: {
193
- if (!blockLocallyProduced) {
194
- try {
193
+ try {
194
+ if (blockLocallyProduced) {
195
+ // Block production does not cover the proposer signature, the validator client signs the block
196
+ await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
197
+ } else {
195
198
  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
- }
199
+ }
200
+ } catch (error) {
201
+ if (error instanceof BlockGossipError) {
202
+ switch (error.type.code) {
203
+ case BlockErrorCode.ALREADY_KNOWN:
204
+ // Block has already been seen, e.g. via gossip racing the publish API. Benign.
205
+ chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
206
+ return;
204
207
  }
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
208
  }
209
+
210
+ chain.logger.error("Gossip validations failed while publishing the block", valLogMeta, error as Error);
211
+ chain.persistInvalidSszValue(
212
+ chain.config.getForkTypes(slot).SignedBeaconBlock,
213
+ signedBlock,
214
+ "api_reject_gossip_failure",
215
+ blockRoot
216
+ );
217
+ throw error;
215
218
  }
216
219
  chain.logger.debug("Gossip checks validated while publishing the block", valLogMeta);
217
220
  break;
@@ -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
 
@@ -5,6 +5,7 @@ import {
5
5
  ForkChoiceError,
6
6
  ForkChoiceErrorCode,
7
7
  InvalidBlockCode,
8
+ LVHInvalidJudged,
8
9
  PayloadExecutionStatus,
9
10
  getFinalizedExecutionBlockHash,
10
11
  getSafeExecutionBlockHash,
@@ -16,11 +17,12 @@ import {
16
17
  isStatePostHeze,
17
18
  } from "@lodestar/state-transition";
18
19
  import {RootHex, bellatrix} from "@lodestar/types";
19
- import {isErrorAborted} from "@lodestar/utils";
20
+ import {isErrorAborted, toRootHex} from "@lodestar/utils";
20
21
  import {ExecutionPayloadStatus} from "../../execution/index.js";
21
22
  import {getShufflingDependentRoot} from "../../util/dependentRoot.js";
22
23
  import {isQueueErrorAborted} from "../../util/queue/index.js";
23
24
  import {BeaconChain} from "../chain.js";
25
+ import {ExecutionInvalidSource} from "../forkChoice/index.js";
24
26
  import {RegenCaller} from "../regen/interface.js";
25
27
  import {PayloadEnvelopeInput} from "../seenCache/seenPayloadEnvelopeInput.js";
26
28
  import {PayloadEnvelopeInputSource} from "./payloadEnvelopeInput/index.js";
@@ -267,12 +269,29 @@ export async function importExecutionPayload(
267
269
  case ExecutionPayloadStatus.VALID:
268
270
  break;
269
271
 
270
- case ExecutionPayloadStatus.INVALID:
272
+ case ExecutionPayloadStatus.INVALID: {
273
+ // An LVH above the parent means the payload chain this block builds on is invalid too. The rejected payload
274
+ // itself never enters fork choice, so an LVH equal to the parent hash changes nothing
275
+ const parentHashHex = toRootHex(envelope.payload.parentHash);
276
+ if (execResult.latestValidHash !== null && execResult.latestValidHash !== parentHashHex) {
277
+ this.executionEngine.invalidateExecutionPayloads(
278
+ {
279
+ executionStatus: ExecutionStatus.Invalid,
280
+ latestValidExecHash: execResult.latestValidHash,
281
+ invalidateFromBlockRoot: protoBlock.parentRoot,
282
+ invalidateFromBlockHash: parentHashHex,
283
+ judged: LVHInvalidJudged.ChildPayload,
284
+ },
285
+ ExecutionInvalidSource.newPayload,
286
+ {slot, root: blockRootHex, payloadBlockHash: blockHashHex}
287
+ );
288
+ }
271
289
  throw new PayloadError(payloadInput, {
272
290
  code: PayloadErrorCode.EXECUTION_ENGINE_INVALID,
273
291
  execStatus: execResult.status,
274
292
  errorMessage: execResult.validationError ?? "",
275
293
  });
294
+ }
276
295
 
277
296
  case ExecutionPayloadStatus.ACCEPTED:
278
297
  case ExecutionPayloadStatus.SYNCING:
@@ -2,6 +2,7 @@ import {ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice";
2
2
  import {ForkName, ForkSeq, isForkPostFulu} from "@lodestar/params";
3
3
  import {
4
4
  DataAvailabilityStatus,
5
+ EpochShuffling,
5
6
  IBeaconStateView,
6
7
  computeEpochAtSlot,
7
8
  getAttestingIndices,
@@ -111,22 +112,24 @@ export async function verifyBlocksInEpoch(
111
112
 
112
113
  // Store indexed attestations for each block to avoid recomputing them during import
113
114
  const indexedAttestationsByBlock: IndexedAttestation[][] = [];
115
+ const attestationShufflingsByBlock: EpochShuffling[][] = [];
114
116
  for (const [i, block] of blocks.entries()) {
115
- indexedAttestationsByBlock[i] = block.message.body.attestations.map((attestation) => {
117
+ attestationShufflingsByBlock[i] = block.message.body.attestations.map((attestation) => {
116
118
  const attEpoch = computeEpochAtSlot(attestation.data.slot);
117
119
  // calling getShufflingAtEpoch may take some time for NativeBeaconStateView
118
120
  // we should have the shuffling inside ShufflingCache most of the time
119
- const shuffling =
121
+ return (
120
122
  this.shufflingCache.getSync(attEpoch, preState0.getShufflingDecisionRoot(attEpoch)) ??
121
- preState0.getShufflingAtEpoch(attEpoch);
122
- // Unlike getIndexedAttestation, keep attestingIndices in committee order: sorting them dominates building
123
- // these on mainnet blocks. See FullyVerifiedBlock.indexedAttestations.
124
- return {
125
- attestingIndices: getAttestingIndices(shuffling, fork, attestation),
126
- data: attestation.data,
127
- signature: attestation.signature,
128
- };
123
+ preState0.getShufflingAtEpoch(attEpoch)
124
+ );
129
125
  });
126
+ // Unlike getIndexedAttestation, keep attestingIndices in committee order: sorting them dominates building
127
+ // these on mainnet blocks. See FullyVerifiedBlock.indexedAttestations.
128
+ indexedAttestationsByBlock[i] = block.message.body.attestations.map((attestation, j) => ({
129
+ attestingIndices: getAttestingIndices(attestationShufflingsByBlock[i][j], fork, attestation),
130
+ data: attestation.data,
131
+ signature: attestation.signature,
132
+ }));
130
133
  }
131
134
 
132
135
  // Pick the data-availability source by fork:
@@ -200,6 +203,7 @@ export async function verifyBlocksInEpoch(
200
203
  preState0,
201
204
  blocks,
202
205
  indexedAttestationsByBlock,
206
+ attestationShufflingsByBlock,
203
207
  opts
204
208
  ),
205
209
 
@@ -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`
@@ -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,
@@ -1855,14 +1857,18 @@ export class BeaconChain implements IBeaconChain {
1855
1857
  private onClockSlot(slot: Slot): void {
1856
1858
  this.logger.verbose("Clock slot", {slot});
1857
1859
 
1858
- // CRITICAL UPDATE
1859
- if (this.forkChoice.irrecoverableError) {
1860
- this.processShutdownCallback(this.forkChoice.irrecoverableError);
1861
- }
1862
-
1863
1860
  // updateTime() recomputes the head on epoch-boundary checkpoint pull-up and under fast confirmation
1864
1861
  const prevHead = this.forkChoice.getHead();
1865
- this.forkChoice.updateTime(slot);
1862
+ try {
1863
+ this.forkChoice.updateTime(slot);
1864
+ } catch (e) {
1865
+ // Per optimistic sync the node MAY exit once the justified checkpoint is INVALIDATED, fork choice has no head
1866
+ if (e instanceof ForkChoiceError && e.type.code === ForkChoiceErrorCode.INVALID_JUSTIFIED_EXECUTION_STATUS) {
1867
+ this.processShutdownCallback(e);
1868
+ return;
1869
+ }
1870
+ throw e;
1871
+ }
1866
1872
  this.emitHeadEvents(prevHead, this.forkChoice.getHead());
1867
1873
  this.metrics?.clockSlot.set(slot);
1868
1874
 
@@ -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);
@@ -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) {
@@ -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,
@@ -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),
@@ -1784,6 +1784,15 @@ export function createLodestarMetrics(
1784
1784
  help: "Time from promise insertion until promise resolution when shuffling was ready in seconds",
1785
1785
  buckets: [0.5, 1, 1.5, 2],
1786
1786
  }),
1787
+ committeePubkeysComputeTime: register.histogram({
1788
+ name: "lodestar_shuffling_cache_committee_pubkeys_compute_seconds",
1789
+ help: "Time to aggregate the committee pubkeys of a shuffling off the main thread in seconds",
1790
+ buckets: [0.1, 0.25, 0.5, 1, 2, 5],
1791
+ }),
1792
+ committeePubkeysErrors: register.counter({
1793
+ name: "lodestar_shuffling_cache_committee_pubkeys_errors_total",
1794
+ help: "Total number of shufflings whose committee pubkeys could not be computed",
1795
+ }),
1787
1796
  },
1788
1797
 
1789
1798
  seenCache: {