@lodestar/beacon-node 1.39.0-dev.2fe8de2346 → 1.39.0-dev.3932675174

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 (182) hide show
  1. package/README.md +1 -1
  2. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  3. package/lib/chain/blocks/importBlock.js +6 -0
  4. package/lib/chain/blocks/importBlock.js.map +1 -1
  5. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  6. package/lib/chain/blocks/verifyBlock.js +1 -1
  7. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  8. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  9. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +4 -2
  10. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  11. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -1
  12. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  13. package/lib/chain/blocks/verifyBlocksSignatures.js +3 -2
  14. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  15. package/lib/chain/chain.d.ts +9 -9
  16. package/lib/chain/chain.d.ts.map +1 -1
  17. package/lib/chain/chain.js +33 -38
  18. package/lib/chain/chain.js.map +1 -1
  19. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  20. package/lib/chain/forkChoice/index.js +3 -3
  21. package/lib/chain/forkChoice/index.js.map +1 -1
  22. package/lib/chain/interface.d.ts +4 -7
  23. package/lib/chain/interface.d.ts.map +1 -1
  24. package/lib/chain/interface.js.map +1 -1
  25. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +6 -7
  26. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  27. package/lib/chain/opPools/aggregatedAttestationPool.js +8 -133
  28. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  29. package/lib/chain/opPools/opPool.d.ts +3 -0
  30. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  31. package/lib/chain/opPools/opPool.js +9 -8
  32. package/lib/chain/opPools/opPool.js.map +1 -1
  33. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  34. package/lib/chain/prepareNextSlot.js +1 -6
  35. package/lib/chain/prepareNextSlot.js.map +1 -1
  36. package/lib/chain/produceBlock/produceBlockBody.js +3 -3
  37. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  38. package/lib/chain/regen/interface.d.ts +0 -4
  39. package/lib/chain/regen/interface.d.ts.map +1 -1
  40. package/lib/chain/shufflingCache.d.ts +5 -12
  41. package/lib/chain/shufflingCache.d.ts.map +1 -1
  42. package/lib/chain/shufflingCache.js +12 -50
  43. package/lib/chain/shufflingCache.js.map +1 -1
  44. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +4 -1
  45. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  46. package/lib/chain/stateCache/persistentCheckpointsCache.js +4 -2
  47. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  48. package/lib/chain/validation/aggregateAndProof.js +9 -0
  49. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  50. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  51. package/lib/chain/validation/attesterSlashing.js +2 -2
  52. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  53. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  54. package/lib/chain/validation/blobSidecar.js +2 -3
  55. package/lib/chain/validation/blobSidecar.js.map +1 -1
  56. package/lib/chain/validation/block.d.ts.map +1 -1
  57. package/lib/chain/validation/block.js +3 -3
  58. package/lib/chain/validation/block.js.map +1 -1
  59. package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -1
  60. package/lib/chain/validation/blsToExecutionChange.js +10 -3
  61. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  62. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  63. package/lib/chain/validation/dataColumnSidecar.js +2 -3
  64. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  65. package/lib/chain/validation/proposerSlashing.js +3 -2
  66. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  67. package/lib/chain/validation/signatureSets/aggregateAndProof.js +1 -1
  68. package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
  69. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -1
  70. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  71. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  72. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  73. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -1
  74. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  75. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  76. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  77. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -1
  78. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  79. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  80. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  81. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -1
  82. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  83. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -2
  84. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  85. package/lib/chain/validation/syncCommittee.js +1 -1
  86. package/lib/chain/validation/syncCommittee.js.map +1 -1
  87. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  88. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  89. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  90. package/lib/chain/validation/voluntaryExit.js +1 -1
  91. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  92. package/lib/db/beacon.d.ts +2 -0
  93. package/lib/db/beacon.d.ts.map +1 -1
  94. package/lib/db/beacon.js +32 -0
  95. package/lib/db/beacon.js.map +1 -1
  96. package/lib/db/buckets.d.ts +12 -0
  97. package/lib/db/buckets.d.ts.map +1 -1
  98. package/lib/db/buckets.js +12 -6
  99. package/lib/db/buckets.js.map +1 -1
  100. package/lib/db/interface.d.ts +1 -0
  101. package/lib/db/interface.d.ts.map +1 -1
  102. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  103. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  104. package/lib/execution/engine/mock.d.ts +9 -6
  105. package/lib/execution/engine/mock.d.ts.map +1 -1
  106. package/lib/execution/engine/mock.js +34 -7
  107. package/lib/execution/engine/mock.js.map +1 -1
  108. package/lib/metrics/metrics/lodestar.d.ts +1 -6
  109. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  110. package/lib/metrics/metrics/lodestar.js +3 -17
  111. package/lib/metrics/metrics/lodestar.js.map +1 -1
  112. package/lib/network/peers/discover.d.ts.map +1 -1
  113. package/lib/network/peers/discover.js.map +1 -1
  114. package/lib/node/nodejs.d.ts +6 -3
  115. package/lib/node/nodejs.d.ts.map +1 -1
  116. package/lib/node/nodejs.js +30 -3
  117. package/lib/node/nodejs.js.map +1 -1
  118. package/lib/node/notifier.d.ts.map +1 -1
  119. package/lib/node/notifier.js +9 -6
  120. package/lib/node/notifier.js.map +1 -1
  121. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  122. package/lib/sync/backfill/backfill.js +2 -4
  123. package/lib/sync/backfill/backfill.js.map +1 -1
  124. package/lib/sync/backfill/verify.d.ts +2 -2
  125. package/lib/sync/backfill/verify.d.ts.map +1 -1
  126. package/lib/sync/backfill/verify.js +3 -3
  127. package/lib/sync/backfill/verify.js.map +1 -1
  128. package/package.json +28 -20
  129. package/src/chain/blocks/importBlock.ts +7 -0
  130. package/src/chain/blocks/verifyBlock.ts +1 -0
  131. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -2
  132. package/src/chain/blocks/verifyBlocksSignatures.ts +13 -3
  133. package/src/chain/chain.ts +45 -44
  134. package/src/chain/forkChoice/index.ts +3 -2
  135. package/src/chain/interface.ts +4 -6
  136. package/src/chain/opPools/aggregatedAttestationPool.ts +12 -187
  137. package/src/chain/opPools/opPool.ts +8 -8
  138. package/src/chain/prepareNextSlot.ts +1 -6
  139. package/src/chain/produceBlock/produceBlockBody.ts +3 -3
  140. package/src/chain/regen/interface.ts +0 -4
  141. package/src/chain/shufflingCache.ts +15 -61
  142. package/src/chain/stateCache/persistentCheckpointsCache.ts +15 -2
  143. package/src/chain/validation/aggregateAndProof.ts +12 -0
  144. package/src/chain/validation/attesterSlashing.ts +14 -2
  145. package/src/chain/validation/blobSidecar.ts +3 -3
  146. package/src/chain/validation/block.ts +3 -2
  147. package/src/chain/validation/blsToExecutionChange.ts +10 -8
  148. package/src/chain/validation/dataColumnSidecar.ts +3 -3
  149. package/src/chain/validation/proposerSlashing.ts +8 -2
  150. package/src/chain/validation/signatureSets/aggregateAndProof.ts +1 -1
  151. package/src/chain/validation/signatureSets/contributionAndProof.ts +3 -1
  152. package/src/chain/validation/signatureSets/syncCommittee.ts +3 -1
  153. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +3 -1
  154. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -1
  155. package/src/chain/validation/syncCommittee.ts +1 -1
  156. package/src/chain/validation/syncCommitteeContributionAndProof.ts +8 -3
  157. package/src/chain/validation/voluntaryExit.ts +1 -1
  158. package/src/db/beacon.ts +38 -1
  159. package/src/db/buckets.ts +12 -6
  160. package/src/db/interface.ts +2 -0
  161. package/src/execution/engine/mock.ts +40 -13
  162. package/src/metrics/metrics/lodestar.ts +3 -17
  163. package/src/network/peers/discover.ts +3 -3
  164. package/src/node/nodejs.ts +37 -4
  165. package/src/node/notifier.ts +13 -7
  166. package/src/sync/backfill/backfill.ts +2 -9
  167. package/src/sync/backfill/verify.ts +3 -8
  168. package/lib/chain/rewards/attestationsRewards.d.ts +0 -7
  169. package/lib/chain/rewards/attestationsRewards.d.ts.map +0 -1
  170. package/lib/chain/rewards/attestationsRewards.js +0 -112
  171. package/lib/chain/rewards/attestationsRewards.js.map +0 -1
  172. package/lib/chain/rewards/blockRewards.d.ts +0 -14
  173. package/lib/chain/rewards/blockRewards.d.ts.map +0 -1
  174. package/lib/chain/rewards/blockRewards.js +0 -94
  175. package/lib/chain/rewards/blockRewards.js.map +0 -1
  176. package/lib/chain/rewards/syncCommitteeRewards.d.ts +0 -6
  177. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +0 -1
  178. package/lib/chain/rewards/syncCommitteeRewards.js +0 -36
  179. package/lib/chain/rewards/syncCommitteeRewards.js.map +0 -1
  180. package/src/chain/rewards/attestationsRewards.ts +0 -197
  181. package/src/chain/rewards/blockRewards.ts +0 -150
  182. package/src/chain/rewards/syncCommitteeRewards.ts +0 -58
@@ -165,7 +165,7 @@ export async function produceBlockBody<T extends BlockType>(
165
165
  // even though shouldOverrideBuilder is relevant for the engine response, for simplicity of typing
166
166
  // we just return it undefined for the builder which anyway doesn't get consumed downstream
167
167
  let shouldOverrideBuilder: boolean | undefined;
168
- const fork = currentState.config.getForkName(blockSlot);
168
+ const fork = this.config.getForkName(blockSlot);
169
169
  const produceResult = {
170
170
  type: blockType,
171
171
  fork,
@@ -623,7 +623,7 @@ function preparePayloadAttributes(
623
623
  (payloadAttributes as capella.SSEPayloadAttributes["payloadAttributes"]).withdrawals = getExpectedWithdrawals(
624
624
  ForkSeq[fork],
625
625
  prepareState as CachedBeaconStateCapella
626
- ).withdrawals;
626
+ ).expectedWithdrawals;
627
627
  }
628
628
 
629
629
  if (ForkSeq[fork] >= ForkSeq.deneb) {
@@ -644,7 +644,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
644
644
  ? this.metrics?.executionBlockProductionTimeSteps
645
645
  : this.metrics?.builderBlockProductionTimeSteps;
646
646
 
647
- const fork = currentState.config.getForkName(slot);
647
+ const fork = this.config.getForkName(slot);
648
648
 
649
649
  // TODO:
650
650
  // Iterate through the naive aggregation pool and ensure all the attestations from there
@@ -31,10 +31,6 @@ export enum RegenFnName {
31
31
 
32
32
  export type StateRegenerationOpts = {
33
33
  dontTransferCache: boolean;
34
- /**
35
- * Do not queue shuffling calculation async. Forces sync JIT calculation in afterProcessEpoch if not passed as `true`
36
- */
37
- asyncShufflingCalculation?: boolean;
38
34
  };
39
35
 
40
36
  export interface IStateRegenerator extends IStateRegeneratorInternal {
@@ -1,11 +1,4 @@
1
- import {
2
- BeaconStateAllForks,
3
- EpochShuffling,
4
- IShufflingCache,
5
- ShufflingBuildProps,
6
- computeEpochShuffling,
7
- computeEpochShufflingAsync,
8
- } from "@lodestar/state-transition";
1
+ import {CachedBeaconStateAllForks, EpochShuffling} from "@lodestar/state-transition";
9
2
  import {Epoch, RootHex} from "@lodestar/types";
10
3
  import {LodestarError, Logger, MapDef, pruneSetToMax} from "@lodestar/utils";
11
4
  import {Metrics} from "../metrics/metrics.js";
@@ -53,7 +46,7 @@ export type ShufflingCacheOpts = {
53
46
  * - if a shuffling is not available (which does not happen with default chain option of maxSkipSlots = 32), track a promise to make sure we don't compute the same shuffling twice
54
47
  * - skip computing shuffling when loading state bytes from disk
55
48
  */
56
- export class ShufflingCache implements IShufflingCache {
49
+ export class ShufflingCache {
57
50
  /** LRU cache implemented as a map, pruned every time we add an item */
58
51
  private readonly itemsByDecisionRootByEpoch: MapDef<Epoch, Map<RootHex, CacheItem>> = new MapDef(
59
52
  () => new Map<RootHex, CacheItem>()
@@ -136,60 +129,20 @@ export class ShufflingCache implements IShufflingCache {
136
129
  }
137
130
 
138
131
  /**
139
- * Gets a cached shuffling via the epoch and decision root. If the shuffling is not
140
- * available it will build it synchronously and return the shuffling.
141
- *
142
- * NOTE: If a shuffling is already queued and not calculated it will build and resolve
143
- * the promise but the already queued build will happen at some later time
132
+ * Process a state to extract and cache all shufflings (previous, current, next).
133
+ * Uses the stored decision roots from epochCtx.
144
134
  */
145
- getSync<T extends ShufflingBuildProps | undefined>(
146
- epoch: Epoch,
147
- decisionRoot: RootHex,
148
- buildProps?: T
149
- ): T extends ShufflingBuildProps ? EpochShuffling : EpochShuffling | null {
150
- const cacheItem = this.itemsByDecisionRootByEpoch.getOrDefault(epoch).get(decisionRoot);
151
- if (!cacheItem) {
152
- this.metrics?.shufflingCache.miss.inc();
153
- } else if (isShufflingCacheItem(cacheItem)) {
154
- this.metrics?.shufflingCache.hit.inc();
155
- return cacheItem.shuffling;
156
- } else if (buildProps) {
157
- // TODO: (@matthewkeil) This should possible log a warning??
158
- this.metrics?.shufflingCache.shufflingPromiseNotResolvedAndThrownAway.inc();
159
- } else {
160
- this.metrics?.shufflingCache.shufflingPromiseNotResolved.inc();
161
- }
135
+ processState(state: CachedBeaconStateAllForks): void {
136
+ const {epochCtx} = state;
162
137
 
163
- let shuffling: EpochShuffling | null = null;
164
- if (buildProps) {
165
- const timer = this.metrics?.shufflingCache.shufflingCalculationTime.startTimer({source: "getSync"});
166
- shuffling = computeEpochShuffling(buildProps.state, buildProps.activeIndices, epoch);
167
- timer?.();
168
- this.set(shuffling, decisionRoot);
169
- }
170
- return shuffling as T extends ShufflingBuildProps ? EpochShuffling : EpochShuffling | null;
171
- }
138
+ // Cache previous shuffling
139
+ this.set(epochCtx.previousShuffling, epochCtx.previousDecisionRoot);
172
140
 
173
- /**
174
- * Queue asynchronous build for an EpochShuffling, triggered from state-transition
175
- */
176
- build(epoch: number, decisionRoot: string, state: BeaconStateAllForks, activeIndices: Uint32Array): void {
177
- this.insertPromise(epoch, decisionRoot);
178
- /**
179
- * TODO: (@matthewkeil) This will get replaced by a proper build queue and a worker to do calculations
180
- * on a NICE thread
181
- */
182
- const timer = this.metrics?.shufflingCache.shufflingCalculationTime.startTimer({source: "build"});
183
- computeEpochShufflingAsync(state, activeIndices, epoch)
184
- .then((shuffling) => {
185
- this.set(shuffling, decisionRoot);
186
- })
187
- .catch((err) =>
188
- this.logger?.error(`error building shuffling for epoch ${epoch} at decisionRoot ${decisionRoot}`, {}, err)
189
- )
190
- .finally(() => {
191
- timer?.();
192
- });
141
+ // Cache current shuffling
142
+ this.set(epochCtx.currentShuffling, epochCtx.currentDecisionRoot);
143
+
144
+ // Cache next shuffling
145
+ this.set(epochCtx.nextShuffling, epochCtx.nextDecisionRoot);
193
146
  }
194
147
 
195
148
  /**
@@ -207,7 +160,8 @@ export class ShufflingCache implements IShufflingCache {
207
160
  (Date.now() - cacheItem.timeInsertedMs) / 1000
208
161
  );
209
162
  } else {
210
- this.metrics?.shufflingCache.shufflingBuiltMultipleTimes.inc();
163
+ this.metrics?.shufflingCache.shufflingSetMultipleTimes.inc();
164
+ return;
211
165
  }
212
166
  }
213
167
  // set the shuffling
@@ -1,4 +1,5 @@
1
1
  import {routes} from "@lodestar/api";
2
+ import {BeaconConfig} from "@lodestar/config";
2
3
  import {
3
4
  CachedBeaconStateAllForks,
4
5
  computeStartSlotAtEpoch,
@@ -24,6 +25,7 @@ export type PersistentCheckpointStateCacheOpts = {
24
25
  };
25
26
 
26
27
  type PersistentCheckpointStateCacheModules = {
28
+ config: BeaconConfig;
27
29
  metrics?: Metrics | null;
28
30
  logger: Logger;
29
31
  clock?: IClock | null;
@@ -107,6 +109,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
107
109
  private readonly cache: MapTracker<CacheKey, CacheItem>;
108
110
  /** Epoch -> Set<blockRoot> */
109
111
  private readonly epochIndex = new MapDef<Epoch, Set<RootHex>>(() => new Set<string>());
112
+ private readonly config: BeaconConfig;
110
113
  private readonly metrics: Metrics | null | undefined;
111
114
  private readonly logger: Logger;
112
115
  private readonly clock: IClock | null | undefined;
@@ -120,10 +123,20 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
120
123
  private readonly bufferPool?: BufferPool | null;
121
124
 
122
125
  constructor(
123
- {metrics, logger, clock, signal, datastore, blockStateCache, bufferPool}: PersistentCheckpointStateCacheModules,
126
+ {
127
+ config,
128
+ metrics,
129
+ logger,
130
+ clock,
131
+ signal,
132
+ datastore,
133
+ blockStateCache,
134
+ bufferPool,
135
+ }: PersistentCheckpointStateCacheModules,
124
136
  opts: PersistentCheckpointStateCacheOpts
125
137
  ) {
126
138
  this.cache = new MapTracker(metrics?.cpStateCache);
139
+ this.config = config;
127
140
  if (metrics) {
128
141
  this.metrics = metrics;
129
142
  metrics.cpStateCache.size.addCollect(() => {
@@ -484,7 +497,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
484
497
  }
485
498
 
486
499
  const blockSlot = state.slot;
487
- const processCPStatesTimeMs = state.config.getSlotComponentDurationMs(PROCESS_CHECKPOINT_STATES_BPS);
500
+ const processCPStatesTimeMs = this.config.getSlotComponentDurationMs(PROCESS_CHECKPOINT_STATES_BPS);
488
501
  // we always have clock in production, fallback value is only for test
489
502
  const msFromSlot = this.clock?.msFromSlot(blockSlot) ?? processCPStatesTimeMs;
490
503
  const msToProcessCPStates = processCPStatesTimeMs - msFromSlot;
@@ -245,6 +245,18 @@ async function validateAggregateAndProof(
245
245
  });
246
246
  }
247
247
 
248
+ // Same race-condition check as above for seen aggregators
249
+ if (
250
+ !skipValidationKnownAttesters &&
251
+ chain.seenAggregatedAttestations.isKnown(targetEpoch, attIndex, attDataRootHex, aggregationBits)
252
+ ) {
253
+ throw new AttestationError(GossipAction.IGNORE, {
254
+ code: AttestationErrorCode.ATTESTERS_ALREADY_KNOWN,
255
+ targetEpoch,
256
+ aggregateRoot: attDataRootHex,
257
+ });
258
+ }
259
+
248
260
  chain.seenAggregators.add(targetEpoch, aggregatorIndex);
249
261
  chain.seenAggregatedAttestations.add(
250
262
  targetEpoch,
@@ -43,7 +43,14 @@ export async function validateAttesterSlashing(
43
43
  // [REJECT] All of the conditions within process_attester_slashing pass validation.
44
44
  try {
45
45
  // verifySignature = false, verified in batch below
46
- assertValidAttesterSlashing(chain.index2pubkey, state, attesterSlashing, false);
46
+ assertValidAttesterSlashing(
47
+ chain.config,
48
+ chain.index2pubkey,
49
+ state.slot,
50
+ state.validators.length,
51
+ attesterSlashing,
52
+ false
53
+ );
47
54
  } catch (e) {
48
55
  throw new AttesterSlashingError(GossipAction.REJECT, {
49
56
  code: AttesterSlashingErrorCode.INVALID,
@@ -51,7 +58,12 @@ export async function validateAttesterSlashing(
51
58
  });
52
59
  }
53
60
 
54
- const signatureSets = getAttesterSlashingSignatureSets(chain.index2pubkey, state, attesterSlashing);
61
+ const signatureSets = getAttesterSlashingSignatureSets(
62
+ chain.config,
63
+ chain.index2pubkey,
64
+ state.slot,
65
+ attesterSlashing
66
+ );
55
67
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
56
68
  throw new AttesterSlashingError(GossipAction.REJECT, {
57
69
  code: AttesterSlashingErrorCode.INVALID,
@@ -138,8 +138,9 @@ export async function validateGossipBlobSidecar(
138
138
  const signature = blobSidecar.signedBlockHeader.signature;
139
139
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blobSlot, blockHex, signature)) {
140
140
  const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(
141
+ chain.config,
141
142
  chain.index2pubkey,
142
- blockState,
143
+ blockState.slot,
143
144
  blobSidecar.signedBlockHeader
144
145
  );
145
146
  // Don't batch so verification is not delayed
@@ -243,10 +244,9 @@ export async function validateBlockBlobSidecars(
243
244
  const blockRootHex = toRootHex(blockRoot);
244
245
  const signature = firstSidecarSignedBlockHeader.signature;
245
246
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRootHex, signature)) {
246
- const headState = await chain.getHeadState();
247
247
  const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(
248
+ chain.config,
248
249
  chain.index2pubkey,
249
- headState,
250
250
  firstSidecarSignedBlockHeader
251
251
  );
252
252
 
@@ -6,6 +6,7 @@ import {
6
6
  computeTimeAtSlot,
7
7
  getBlockProposerSignatureSet,
8
8
  isExecutionBlockBodyType,
9
+ isExecutionEnabled,
9
10
  isExecutionStateType,
10
11
  } from "@lodestar/state-transition";
11
12
  import {SignedBeaconBlock, deneb} from "@lodestar/types";
@@ -139,7 +140,7 @@ export async function validateGossipBlock(
139
140
  if (fork === ForkName.bellatrix) {
140
141
  if (!isExecutionBlockBodyType(block.body)) throw Error("Not merge block type");
141
142
  const executionPayload = block.body.executionPayload;
142
- if (isExecutionStateType(blockState)) {
143
+ if (isExecutionStateType(blockState) && isExecutionEnabled(blockState, block)) {
143
144
  const expectedTimestamp = computeTimeAtSlot(config, blockSlot, chain.genesisTime);
144
145
  if (executionPayload.timestamp !== computeTimeAtSlot(config, blockSlot, chain.genesisTime)) {
145
146
  throw new BlockGossipError(GossipAction.REJECT, {
@@ -153,7 +154,7 @@ export async function validateGossipBlock(
153
154
 
154
155
  // [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
155
156
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature)) {
156
- const signatureSet = getBlockProposerSignatureSet(chain.index2pubkey, blockState, signedBlock);
157
+ const signatureSet = getBlockProposerSignatureSet(chain.config, chain.index2pubkey, signedBlock);
157
158
  // Don't batch so verification is not delayed
158
159
  if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
159
160
  throw new BlockGossipError(GossipAction.REJECT, {
@@ -1,8 +1,4 @@
1
- import {
2
- CachedBeaconStateCapella,
3
- getBlsToExecutionChangeSignatureSet,
4
- isValidBlsToExecutionChange,
5
- } from "@lodestar/state-transition";
1
+ import {getBlsToExecutionChangeSignatureSet, isValidBlsToExecutionChange} from "@lodestar/state-transition";
6
2
  import {capella} from "@lodestar/types";
7
3
  import {BlsToExecutionChangeError, BlsToExecutionChangeErrorCode, GossipAction} from "../errors/index.js";
8
4
  import {IBeaconChain} from "../index.js";
@@ -41,11 +37,17 @@ async function validateBlsToExecutionChange(
41
37
  // NOTE: No need to advance head state since the signature's fork is handled with `broadcastedOnFork`,
42
38
  // and chanes relevant to `isValidBlsToExecutionChange()` happen only on processBlock(), not processEpoch()
43
39
  const state = chain.getHeadState();
44
- const {config} = state;
45
-
40
+ const {config} = chain;
41
+ const addressChange = blsToExecutionChange.message;
42
+ if (addressChange.validatorIndex >= state.validators.length) {
43
+ throw new BlsToExecutionChangeError(GossipAction.REJECT, {
44
+ code: BlsToExecutionChangeErrorCode.INVALID,
45
+ });
46
+ }
47
+ const validator = state.validators.getReadonly(addressChange.validatorIndex);
46
48
  // [REJECT] All of the conditions within process_bls_to_execution_change pass validation.
47
49
  // verifySignature = false, verified in batch below
48
- const {valid} = isValidBlsToExecutionChange(state as CachedBeaconStateCapella, blsToExecutionChange, false);
50
+ const {valid} = isValidBlsToExecutionChange(config, validator, blsToExecutionChange, false);
49
51
  if (!valid) {
50
52
  throw new BlsToExecutionChangeError(GossipAction.REJECT, {
51
53
  code: BlsToExecutionChangeErrorCode.INVALID,
@@ -135,8 +135,9 @@ export async function validateGossipDataColumnSidecar(
135
135
  const signature = dataColumnSidecar.signedBlockHeader.signature;
136
136
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockHeader.slot, blockRootHex, signature)) {
137
137
  const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(
138
+ chain.config,
138
139
  chain.index2pubkey,
139
- blockState,
140
+ blockState.slot,
140
141
  dataColumnSidecar.signedBlockHeader
141
142
  );
142
143
 
@@ -336,10 +337,9 @@ export async function validateBlockDataColumnSidecars(
336
337
  const slot = firstSidecarSignedBlockHeader.message.slot;
337
338
  const signature = firstSidecarSignedBlockHeader.signature;
338
339
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(slot, rootHex, signature)) {
339
- const headState = await chain.getHeadState();
340
340
  const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(
341
+ chain.config,
341
342
  chain.index2pubkey,
342
- headState,
343
343
  firstSidecarSignedBlockHeader
344
344
  );
345
345
 
@@ -35,8 +35,9 @@ async function validateProposerSlashing(
35
35
 
36
36
  // [REJECT] All of the conditions within process_proposer_slashing pass validation.
37
37
  try {
38
+ const proposer = state.validators.getReadonly(proposerSlashing.signedHeader1.message.proposerIndex);
38
39
  // verifySignature = false, verified in batch below
39
- assertValidProposerSlashing(state, proposerSlashing, false);
40
+ assertValidProposerSlashing(chain.config, chain.index2pubkey, state.slot, proposerSlashing, proposer, false);
40
41
  } catch (e) {
41
42
  throw new ProposerSlashingError(GossipAction.REJECT, {
42
43
  code: ProposerSlashingErrorCode.INVALID,
@@ -44,7 +45,12 @@ async function validateProposerSlashing(
44
45
  });
45
46
  }
46
47
 
47
- const signatureSets = getProposerSlashingSignatureSets(chain.index2pubkey, state, proposerSlashing);
48
+ const signatureSets = getProposerSlashingSignatureSets(
49
+ chain.config,
50
+ chain.index2pubkey,
51
+ state.slot,
52
+ proposerSlashing
53
+ );
48
54
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
49
55
  throw new ProposerSlashingError(GossipAction.REJECT, {
50
56
  code: ProposerSlashingErrorCode.INVALID,
@@ -14,7 +14,7 @@ export function getAggregateAndProofSigningRoot(
14
14
  epoch: Epoch,
15
15
  aggregateAndProof: SignedAggregateAndProof
16
16
  ): Uint8Array {
17
- // previously, we call `const aggregatorDomain = state.config.getDomain(state.slot, DOMAIN_AGGREGATE_AND_PROOF, slot);`
17
+ // previously, we call `const aggregatorDomain = config.getDomain(state.slot, DOMAIN_AGGREGATE_AND_PROOF, slot);`
18
18
  // at fork boundary, it's required to dial to target epoch https://github.com/ChainSafe/lodestar/blob/v1.11.3/packages/beacon-node/src/chain/validation/attestation.ts#L573
19
19
  // instead of that, just use the fork of slot in the attestation data
20
20
  const slot = computeStartSlotAtEpoch(epoch);
@@ -1,3 +1,4 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_CONTRIBUTION_AND_PROOF} from "@lodestar/params";
2
3
  import {
3
4
  CachedBeaconStateAllForks,
@@ -9,11 +10,12 @@ import {
9
10
  import {altair, ssz} from "@lodestar/types";
10
11
 
11
12
  export function getContributionAndProofSignatureSet(
13
+ config: BeaconConfig,
12
14
  index2pubkey: Index2PubkeyCache,
13
15
  state: CachedBeaconStateAllForks,
14
16
  signedContributionAndProof: altair.SignedContributionAndProof
15
17
  ): ISignatureSet {
16
- const domain = state.config.getDomain(
18
+ const domain = config.getDomain(
17
19
  state.slot,
18
20
  DOMAIN_CONTRIBUTION_AND_PROOF,
19
21
  signedContributionAndProof.message.contribution.slot
@@ -1,3 +1,4 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_SYNC_COMMITTEE} from "@lodestar/params";
2
3
  import {
3
4
  CachedBeaconStateAllForks,
@@ -9,11 +10,12 @@ import {
9
10
  import {altair, ssz} from "@lodestar/types";
10
11
 
11
12
  export function getSyncCommitteeSignatureSet(
13
+ config: BeaconConfig,
12
14
  index2pubkey: Index2PubkeyCache,
13
15
  state: CachedBeaconStateAllForks,
14
16
  syncCommittee: altair.SyncCommitteeMessage
15
17
  ): ISignatureSet {
16
- const domain = state.config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, syncCommittee.slot);
18
+ const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, syncCommittee.slot);
17
19
 
18
20
  return {
19
21
  type: SignatureSetType.single,
@@ -1,14 +1,16 @@
1
1
  import {PublicKey} from "@chainsafe/blst";
2
+ import {BeaconConfig} from "@lodestar/config";
2
3
  import {DOMAIN_SYNC_COMMITTEE} from "@lodestar/params";
3
4
  import {CachedBeaconStateAltair, ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition";
4
5
  import {altair, ssz} from "@lodestar/types";
5
6
 
6
7
  export function getSyncCommitteeContributionSignatureSet(
8
+ config: BeaconConfig,
7
9
  state: CachedBeaconStateAltair,
8
10
  contribution: altair.SyncCommitteeContribution,
9
11
  pubkeys: PublicKey[]
10
12
  ): ISignatureSet {
11
- const domain = state.config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, contribution.slot);
13
+ const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, contribution.slot);
12
14
  return {
13
15
  type: SignatureSetType.aggregate,
14
16
  pubkeys,
@@ -1,3 +1,4 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF} from "@lodestar/params";
2
3
  import {
3
4
  CachedBeaconStateAllForks,
@@ -9,11 +10,11 @@ import {
9
10
  import {altair, ssz} from "@lodestar/types";
10
11
 
11
12
  export function getSyncCommitteeSelectionProofSignatureSet(
13
+ config: BeaconConfig,
12
14
  index2pubkey: Index2PubkeyCache,
13
15
  state: CachedBeaconStateAllForks,
14
16
  contributionAndProof: altair.ContributionAndProof
15
17
  ): ISignatureSet {
16
- const {config} = state;
17
18
  const slot = contributionAndProof.contribution.slot;
18
19
  const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF, slot);
19
20
  const signingData: altair.SyncAggregatorSelectionData = {
@@ -89,7 +89,7 @@ async function validateSyncCommitteeSigOnly(
89
89
  syncCommittee: altair.SyncCommitteeMessage,
90
90
  prioritizeBls = false
91
91
  ): Promise<void> {
92
- const signatureSet = getSyncCommitteeSignatureSet(chain.index2pubkey, headState, syncCommittee);
92
+ const signatureSet = getSyncCommitteeSignatureSet(chain.config, chain.index2pubkey, headState, syncCommittee);
93
93
  if (!(await chain.bls.verifySignatureSets([signatureSet], {batchable: true, priority: prioritizeBls}))) {
94
94
  throw new SyncCommitteeError(GossipAction.REJECT, {
95
95
  code: SyncCommitteeErrorCode.INVALID_SIGNATURE,
@@ -78,14 +78,19 @@ export async function validateSyncCommitteeGossipContributionAndProof(
78
78
  const signatureSets = [
79
79
  // [REJECT] The contribution_and_proof.selection_proof is a valid signature of the SyncAggregatorSelectionData
80
80
  // derived from the contribution by the validator with index contribution_and_proof.aggregator_index.
81
- getSyncCommitteeSelectionProofSignatureSet(index2pubkey, headState, contributionAndProof),
81
+ getSyncCommitteeSelectionProofSignatureSet(chain.config, index2pubkey, headState, contributionAndProof),
82
82
 
83
83
  // [REJECT] The aggregator signature, signed_contribution_and_proof.signature, is valid.
84
- getContributionAndProofSignatureSet(index2pubkey, headState, signedContributionAndProof),
84
+ getContributionAndProofSignatureSet(chain.config, index2pubkey, headState, signedContributionAndProof),
85
85
 
86
86
  // [REJECT] The aggregate signature is valid for the message beacon_block_root and aggregate pubkey derived from
87
87
  // the participation info in aggregation_bits for the subcommittee specified by the contribution.subcommittee_index.
88
- getSyncCommitteeContributionSignatureSet(headState as CachedBeaconStateAltair, contribution, participantPubkeys),
88
+ getSyncCommitteeContributionSignatureSet(
89
+ chain.config,
90
+ headState as CachedBeaconStateAltair,
91
+ contribution,
92
+ participantPubkeys
93
+ ),
89
94
  ];
90
95
 
91
96
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true}))) {
@@ -59,7 +59,7 @@ async function validateVoluntaryExit(
59
59
  });
60
60
  }
61
61
 
62
- const signatureSet = getVoluntaryExitSignatureSet(chain.index2pubkey, state, voluntaryExit);
62
+ const signatureSet = getVoluntaryExitSignatureSet(chain.config, chain.index2pubkey, state.slot, voluntaryExit);
63
63
  if (!(await chain.bls.verifySignatureSets([signatureSet], {batchable: true, priority: prioritizeBls}))) {
64
64
  throw new VoluntaryExitError(GossipAction.REJECT, {
65
65
  code: VoluntaryExitErrorCode.INVALID_SIGNATURE,
package/src/db/beacon.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {Db, LevelDbControllerMetrics} from "@lodestar/db";
2
+ import {Db, LevelDbControllerMetrics, encodeKey} from "@lodestar/db";
3
+ import {Bucket} from "./buckets.js";
3
4
  import {IBeaconDb} from "./interface.js";
4
5
  import {CheckpointStateRepository} from "./repositories/checkpointState.js";
5
6
  import {
@@ -95,4 +96,40 @@ export class BeaconDb implements IBeaconDb {
95
96
  // TODO: Enable once it's deemed safe
96
97
  // await this.block.batchDelete(await this.block.keys());
97
98
  }
99
+
100
+ async deleteDeprecatedEth1Data(): Promise<void> {
101
+ const deprecatedBuckets = [
102
+ Bucket.phase0_eth1Data,
103
+ Bucket.index_depositDataRoot,
104
+ Bucket.phase0_depositData,
105
+ Bucket.phase0_depositEvent,
106
+ Bucket.phase0_preGenesisState,
107
+ Bucket.phase0_preGenesisStateLastProcessedBlock,
108
+ ];
109
+
110
+ for (const bucket of deprecatedBuckets) {
111
+ await this.deleteBucketData(bucket);
112
+ }
113
+ }
114
+
115
+ private async deleteBucketData(bucket: Bucket): Promise<void> {
116
+ const minKey = encodeKey(bucket, Buffer.alloc(0));
117
+ const maxKey = encodeKey(bucket + 1, Buffer.alloc(0));
118
+
119
+ // Batch delete to avoid loading all keys into memory at once
120
+ const BATCH_DELETE_SIZE = 1000;
121
+ let keysBatch: Uint8Array[] = [];
122
+
123
+ for await (const key of this.db.keysStream({gte: minKey, lt: maxKey})) {
124
+ keysBatch.push(key);
125
+ if (keysBatch.length >= BATCH_DELETE_SIZE) {
126
+ await this.db.batchDelete(keysBatch);
127
+ keysBatch = [];
128
+ }
129
+ }
130
+
131
+ if (keysBatch.length > 0) {
132
+ await this.db.batchDelete(keysBatch);
133
+ }
134
+ }
98
135
  }
package/src/db/buckets.ts CHANGED
@@ -16,13 +16,16 @@ export enum Bucket {
16
16
  index_mainChain = 6, // Slot -> Root<BeaconBlock>
17
17
  // justified, finalized state and block hashes
18
18
  index_chainInfo = 7, // Key -> Number64 | stateHash | blockHash
19
- // phase0_eth1Data = 8, // DEPRECATED - eth1 deposit tracking is not required since electra
20
- // index_depositDataRoot = 9, // DEPRECATED - eth1 deposit tracking is not required since electra
19
+ /** @deprecated Eth1 deposit tracking is not required since electra, only kept around to delete data from existing databases */
20
+ phase0_eth1Data = 8,
21
+ /** @deprecated Eth1 deposit tracking is not required since electra, only kept around to delete data from existing databases */
22
+ index_depositDataRoot = 9,
21
23
 
22
24
  // op pool
23
25
  // phase0_attestation = 10, // DEPRECATED on v0.25.0
24
26
  // phase0_aggregateAndProof = 11, // Root -> AggregateAndProof, DEPRECATED on v.27.0
25
- // phase0_depositData = 12, // DEPRECATED - eth1 deposit tracking is not required since electra
27
+ /** @deprecated Eth1 deposit tracking is not required since electra, only kept around to delete data from existing databases */
28
+ phase0_depositData = 12,
26
29
  phase0_exit = 13, // ValidatorIndex -> VoluntaryExit
27
30
  phase0_proposerSlashing = 14, // ValidatorIndex -> ProposerSlashing
28
31
  allForks_attesterSlashing = 15, // Root -> AttesterSlashing
@@ -31,15 +34,18 @@ export enum Bucket {
31
34
  allForks_checkpointState = 17, // Root -> BeaconState
32
35
 
33
36
  // allForks_pendingBlock = 25, // Root -> SignedBeaconBlock // DEPRECATED on v0.30.0
34
- // phase0_depositEvent = 19, // DEPRECATED - eth1 deposit tracking is not required since electra
37
+ /** @deprecated Eth1 deposit tracking is not required since electra, only kept around to delete data from existing databases */
38
+ phase0_depositEvent = 19,
35
39
 
36
40
  index_stateArchiveRootIndex = 26, // State Root -> slot
37
41
 
38
42
  deneb_blobSidecars = 27, // DENEB BeaconBlockRoot -> BlobSidecars
39
43
  deneb_blobSidecarsArchive = 28, // DENEB BeaconBlockSlot -> BlobSidecars
40
44
 
41
- // phase0_preGenesisState = 30, // DEPRECATED - genesis from eth1 is no longer supported
42
- // phase0_preGenesisStateLastProcessedBlock = 31, // DEPRECATED - genesis from eth1 is no longer supported
45
+ /** @deprecated Genesis from eth1 is no longer supported, only kept around to delete data from existing databases */
46
+ phase0_preGenesisState = 30,
47
+ /** @deprecated Genesis from eth1 is no longer supported, only kept around to delete data from existing databases */
48
+ phase0_preGenesisStateLastProcessedBlock = 31,
43
49
 
44
50
  // Lightclient server
45
51
  // altair_bestUpdatePerCommitteePeriod = 30, // DEPRECATED on v0.32.0
@@ -56,6 +56,8 @@ export interface IBeaconDb {
56
56
 
57
57
  pruneHotDb(): Promise<void>;
58
58
 
59
+ deleteDeprecatedEth1Data(): Promise<void>;
60
+
59
61
  /** Close the connection to the db instance and close the db store. */
60
62
  close(): Promise<void>;
61
63
  /** To inject metrics after CLI initialization */