@lodestar/beacon-node 1.39.0-dev.aceb5b7416 → 1.39.0-dev.b2437a6348

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 (240) hide show
  1. package/README.md +1 -1
  2. package/lib/api/impl/beacon/state/utils.d.ts +2 -7
  3. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  4. package/lib/api/impl/beacon/state/utils.js +0 -12
  5. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  6. package/lib/api/impl/lodestar/index.js +1 -1
  7. package/lib/api/impl/lodestar/index.js.map +1 -1
  8. package/lib/api/impl/proof/index.d.ts.map +1 -1
  9. package/lib/api/impl/proof/index.js +1 -2
  10. package/lib/api/impl/proof/index.js.map +1 -1
  11. package/lib/api/impl/validator/index.d.ts.map +1 -1
  12. package/lib/api/impl/validator/index.js +1 -3
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  15. package/lib/chain/blocks/importBlock.js +8 -2
  16. package/lib/chain/blocks/importBlock.js.map +1 -1
  17. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  18. package/lib/chain/blocks/verifyBlock.js +1 -1
  19. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  20. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  21. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +4 -2
  22. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  23. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -1
  24. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  25. package/lib/chain/blocks/verifyBlocksSignatures.js +3 -2
  26. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  27. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  28. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +1 -0
  29. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  30. package/lib/chain/chain.d.ts +11 -11
  31. package/lib/chain/chain.d.ts.map +1 -1
  32. package/lib/chain/chain.js +36 -40
  33. package/lib/chain/chain.js.map +1 -1
  34. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  35. package/lib/chain/forkChoice/index.js +3 -3
  36. package/lib/chain/forkChoice/index.js.map +1 -1
  37. package/lib/chain/interface.d.ts +6 -9
  38. package/lib/chain/interface.d.ts.map +1 -1
  39. package/lib/chain/interface.js.map +1 -1
  40. package/lib/chain/lightClient/proofs.d.ts.map +1 -1
  41. package/lib/chain/lightClient/proofs.js +0 -2
  42. package/lib/chain/lightClient/proofs.js.map +1 -1
  43. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +6 -7
  44. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  45. package/lib/chain/opPools/aggregatedAttestationPool.js +8 -133
  46. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  47. package/lib/chain/opPools/opPool.d.ts +3 -0
  48. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  49. package/lib/chain/opPools/opPool.js +9 -8
  50. package/lib/chain/opPools/opPool.js.map +1 -1
  51. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  52. package/lib/chain/prepareNextSlot.js +4 -7
  53. package/lib/chain/prepareNextSlot.js.map +1 -1
  54. package/lib/chain/produceBlock/produceBlockBody.js +3 -3
  55. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  56. package/lib/chain/regen/interface.d.ts +1 -5
  57. package/lib/chain/regen/interface.d.ts.map +1 -1
  58. package/lib/chain/regen/queued.d.ts +4 -7
  59. package/lib/chain/regen/queued.d.ts.map +1 -1
  60. package/lib/chain/regen/queued.js +15 -25
  61. package/lib/chain/regen/queued.js.map +1 -1
  62. package/lib/chain/regen/regen.d.ts +1 -1
  63. package/lib/chain/regen/regen.d.ts.map +1 -1
  64. package/lib/chain/regen/regen.js +13 -17
  65. package/lib/chain/regen/regen.js.map +1 -1
  66. package/lib/chain/shufflingCache.d.ts +5 -12
  67. package/lib/chain/shufflingCache.d.ts.map +1 -1
  68. package/lib/chain/shufflingCache.js +12 -50
  69. package/lib/chain/shufflingCache.js.map +1 -1
  70. package/lib/chain/stateCache/blockStateCacheImpl.d.ts +1 -2
  71. package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +1 -1
  72. package/lib/chain/stateCache/blockStateCacheImpl.js +2 -2
  73. package/lib/chain/stateCache/blockStateCacheImpl.js.map +1 -1
  74. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +1 -2
  75. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  76. package/lib/chain/stateCache/fifoBlockStateCache.js +4 -4
  77. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  78. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts +4 -5
  79. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +1 -1
  80. package/lib/chain/stateCache/inMemoryCheckpointsCache.js +9 -10
  81. package/lib/chain/stateCache/inMemoryCheckpointsCache.js.map +1 -1
  82. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +9 -7
  83. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  84. package/lib/chain/stateCache/persistentCheckpointsCache.js +21 -19
  85. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  86. package/lib/chain/stateCache/types.d.ts +5 -6
  87. package/lib/chain/stateCache/types.d.ts.map +1 -1
  88. package/lib/chain/stateCache/types.js.map +1 -1
  89. package/lib/chain/validation/aggregateAndProof.js +9 -0
  90. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  91. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  92. package/lib/chain/validation/attesterSlashing.js +2 -2
  93. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  94. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  95. package/lib/chain/validation/blobSidecar.js +2 -3
  96. package/lib/chain/validation/blobSidecar.js.map +1 -1
  97. package/lib/chain/validation/block.d.ts.map +1 -1
  98. package/lib/chain/validation/block.js +3 -3
  99. package/lib/chain/validation/block.js.map +1 -1
  100. package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -1
  101. package/lib/chain/validation/blsToExecutionChange.js +10 -3
  102. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  103. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  104. package/lib/chain/validation/dataColumnSidecar.js +2 -3
  105. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  106. package/lib/chain/validation/proposerSlashing.js +3 -2
  107. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  108. package/lib/chain/validation/signatureSets/aggregateAndProof.js +1 -1
  109. package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
  110. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -1
  111. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  112. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  113. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  114. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -1
  115. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  116. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  117. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  118. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -1
  119. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  120. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  121. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  122. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -1
  123. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  124. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -2
  125. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  126. package/lib/chain/validation/syncCommittee.js +1 -1
  127. package/lib/chain/validation/syncCommittee.js.map +1 -1
  128. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  129. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  130. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  131. package/lib/chain/validation/voluntaryExit.js +1 -1
  132. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  133. package/lib/db/beacon.d.ts +2 -0
  134. package/lib/db/beacon.d.ts.map +1 -1
  135. package/lib/db/beacon.js +32 -0
  136. package/lib/db/beacon.js.map +1 -1
  137. package/lib/db/buckets.d.ts +12 -0
  138. package/lib/db/buckets.d.ts.map +1 -1
  139. package/lib/db/buckets.js +12 -6
  140. package/lib/db/buckets.js.map +1 -1
  141. package/lib/db/interface.d.ts +1 -0
  142. package/lib/db/interface.d.ts.map +1 -1
  143. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  144. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  145. package/lib/db/repositories/stateArchive.d.ts +1 -1
  146. package/lib/db/repositories/stateArchive.d.ts.map +1 -1
  147. package/lib/db/repositories/stateArchive.js +2 -2
  148. package/lib/db/repositories/stateArchive.js.map +1 -1
  149. package/lib/execution/engine/mock.d.ts +9 -6
  150. package/lib/execution/engine/mock.d.ts.map +1 -1
  151. package/lib/execution/engine/mock.js +34 -7
  152. package/lib/execution/engine/mock.js.map +1 -1
  153. package/lib/metrics/metrics/lodestar.d.ts +1 -6
  154. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  155. package/lib/metrics/metrics/lodestar.js +3 -17
  156. package/lib/metrics/metrics/lodestar.js.map +1 -1
  157. package/lib/network/peers/discover.d.ts.map +1 -1
  158. package/lib/network/peers/discover.js.map +1 -1
  159. package/lib/node/nodejs.d.ts +6 -3
  160. package/lib/node/nodejs.d.ts.map +1 -1
  161. package/lib/node/nodejs.js +30 -3
  162. package/lib/node/nodejs.js.map +1 -1
  163. package/lib/node/notifier.d.ts.map +1 -1
  164. package/lib/node/notifier.js +9 -6
  165. package/lib/node/notifier.js.map +1 -1
  166. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  167. package/lib/sync/backfill/backfill.js +2 -4
  168. package/lib/sync/backfill/backfill.js.map +1 -1
  169. package/lib/sync/backfill/verify.d.ts +2 -2
  170. package/lib/sync/backfill/verify.d.ts.map +1 -1
  171. package/lib/sync/backfill/verify.js +3 -3
  172. package/lib/sync/backfill/verify.js.map +1 -1
  173. package/package.json +28 -20
  174. package/src/api/impl/beacon/state/utils.ts +2 -22
  175. package/src/api/impl/lodestar/index.ts +1 -1
  176. package/src/api/impl/proof/index.ts +1 -2
  177. package/src/api/impl/validator/index.ts +1 -3
  178. package/src/chain/blocks/importBlock.ts +9 -2
  179. package/src/chain/blocks/verifyBlock.ts +1 -0
  180. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -2
  181. package/src/chain/blocks/verifyBlocksSignatures.ts +13 -3
  182. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +1 -0
  183. package/src/chain/chain.ts +50 -48
  184. package/src/chain/forkChoice/index.ts +3 -2
  185. package/src/chain/interface.ts +6 -8
  186. package/src/chain/lightClient/proofs.ts +0 -2
  187. package/src/chain/opPools/aggregatedAttestationPool.ts +12 -187
  188. package/src/chain/opPools/opPool.ts +8 -8
  189. package/src/chain/prepareNextSlot.ts +2 -6
  190. package/src/chain/produceBlock/produceBlockBody.ts +3 -3
  191. package/src/chain/regen/interface.ts +1 -5
  192. package/src/chain/regen/queued.ts +15 -34
  193. package/src/chain/regen/regen.ts +12 -18
  194. package/src/chain/shufflingCache.ts +15 -61
  195. package/src/chain/stateCache/blockStateCacheImpl.ts +2 -3
  196. package/src/chain/stateCache/fifoBlockStateCache.ts +4 -5
  197. package/src/chain/stateCache/inMemoryCheckpointsCache.ts +9 -15
  198. package/src/chain/stateCache/persistentCheckpointsCache.ts +32 -27
  199. package/src/chain/stateCache/types.ts +5 -10
  200. package/src/chain/validation/aggregateAndProof.ts +12 -0
  201. package/src/chain/validation/attesterSlashing.ts +14 -2
  202. package/src/chain/validation/blobSidecar.ts +3 -3
  203. package/src/chain/validation/block.ts +3 -2
  204. package/src/chain/validation/blsToExecutionChange.ts +10 -8
  205. package/src/chain/validation/dataColumnSidecar.ts +3 -3
  206. package/src/chain/validation/proposerSlashing.ts +8 -2
  207. package/src/chain/validation/signatureSets/aggregateAndProof.ts +1 -1
  208. package/src/chain/validation/signatureSets/contributionAndProof.ts +3 -1
  209. package/src/chain/validation/signatureSets/syncCommittee.ts +3 -1
  210. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +3 -1
  211. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -1
  212. package/src/chain/validation/syncCommittee.ts +1 -1
  213. package/src/chain/validation/syncCommitteeContributionAndProof.ts +8 -3
  214. package/src/chain/validation/voluntaryExit.ts +1 -1
  215. package/src/db/beacon.ts +38 -1
  216. package/src/db/buckets.ts +12 -6
  217. package/src/db/interface.ts +2 -0
  218. package/src/db/repositories/stateArchive.ts +2 -2
  219. package/src/execution/engine/mock.ts +40 -13
  220. package/src/metrics/metrics/lodestar.ts +3 -17
  221. package/src/network/peers/discover.ts +3 -3
  222. package/src/node/nodejs.ts +37 -4
  223. package/src/node/notifier.ts +13 -7
  224. package/src/sync/backfill/backfill.ts +2 -9
  225. package/src/sync/backfill/verify.ts +3 -8
  226. package/lib/chain/rewards/attestationsRewards.d.ts +0 -7
  227. package/lib/chain/rewards/attestationsRewards.d.ts.map +0 -1
  228. package/lib/chain/rewards/attestationsRewards.js +0 -112
  229. package/lib/chain/rewards/attestationsRewards.js.map +0 -1
  230. package/lib/chain/rewards/blockRewards.d.ts +0 -14
  231. package/lib/chain/rewards/blockRewards.d.ts.map +0 -1
  232. package/lib/chain/rewards/blockRewards.js +0 -94
  233. package/lib/chain/rewards/blockRewards.js.map +0 -1
  234. package/lib/chain/rewards/syncCommitteeRewards.d.ts +0 -6
  235. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +0 -1
  236. package/lib/chain/rewards/syncCommitteeRewards.js +0 -36
  237. package/lib/chain/rewards/syncCommitteeRewards.js.map +0 -1
  238. package/src/chain/rewards/attestationsRewards.ts +0 -197
  239. package/src/chain/rewards/blockRewards.ts +0 -150
  240. package/src/chain/rewards/syncCommitteeRewards.ts +0 -58
@@ -1,11 +1,10 @@
1
1
  import {Signature, aggregateSignatures} from "@chainsafe/blst";
2
2
  import {BitArray} from "@chainsafe/ssz";
3
- import {ChainForkConfig} from "@lodestar/config";
3
+ import {BeaconConfig} from "@lodestar/config";
4
4
  import {IForkChoice} from "@lodestar/fork-choice";
5
5
  import {
6
6
  ForkName,
7
7
  ForkSeq,
8
- MAX_ATTESTATIONS,
9
8
  MAX_ATTESTATIONS_ELECTRA,
10
9
  MAX_COMMITTEES_PER_SLOT,
11
10
  MIN_ATTESTATION_INCLUSION_DELAY,
@@ -23,7 +22,6 @@ import {
23
22
  CachedBeaconStateAllForks,
24
23
  CachedBeaconStateAltair,
25
24
  CachedBeaconStateGloas,
26
- CachedBeaconStatePhase0,
27
25
  EffectiveBalanceIncrements,
28
26
  RootCache,
29
27
  computeEpochAtSlot,
@@ -32,17 +30,7 @@ import {
32
30
  getAttestationParticipationStatus,
33
31
  getBlockRootAtSlot,
34
32
  } from "@lodestar/state-transition";
35
- import {
36
- Attestation,
37
- Epoch,
38
- RootHex,
39
- Slot,
40
- ValidatorIndex,
41
- electra,
42
- isElectraAttestation,
43
- phase0,
44
- ssz,
45
- } from "@lodestar/types";
33
+ import {Attestation, Epoch, RootHex, Slot, electra, isElectraAttestation, phase0, ssz} from "@lodestar/types";
46
34
  import {MapDef, assert, toRootHex} from "@lodestar/utils";
47
35
  import {Metrics} from "../../metrics/metrics.js";
48
36
  import {IntersectResult, intersectUint8Arrays} from "../../util/bitArray.js";
@@ -54,8 +42,6 @@ type DataRootHex = string;
54
42
 
55
43
  type CommitteeIndex = number;
56
44
 
57
- // for pre-electra
58
- type AttestationWithScore = {attestation: Attestation; score: number};
59
45
  /**
60
46
  * for electra, this is to consolidate aggregated attestations of the same attestation data into a single attestation to be included in block
61
47
  * note that this is local definition in this file and it's NOT validator consolidation
@@ -110,15 +96,6 @@ const MAX_RETAINED_ATTESTATIONS_PER_GROUP = 4;
110
96
  */
111
97
  const MAX_RETAINED_ATTESTATIONS_PER_GROUP_ELECTRA = 8;
112
98
 
113
- /**
114
- * Pre-electra, each slot has 64 committees, and each block has 128 attestations max so in average
115
- * we get 2 attestation per groups.
116
- * Starting from Jan 2024, we have a performance issue getting attestations for a block. Based on the
117
- * fact that lot of groups will have only 1 full participation attestation, increase this number
118
- * a bit higher than average. This also help decrease number of slots to search for attestations.
119
- */
120
- const MAX_ATTESTATIONS_PER_GROUP = 3;
121
-
122
99
  /**
123
100
  * For electra, there is on chain aggregation of attestations across committees, so we can just pick up to 8
124
101
  * attestations per group, sort by scores to get first 8.
@@ -162,7 +139,7 @@ export class AggregatedAttestationPool {
162
139
  private lowestPermissibleSlot = 0;
163
140
 
164
141
  constructor(
165
- private readonly config: ChainForkConfig,
142
+ private readonly config: BeaconConfig,
166
143
  private readonly metrics: Metrics | null = null
167
144
  ) {
168
145
  metrics?.opPool.aggregatedAttestationPool.attDataPerSlot.addCollect(() => this.onScrapeMetrics(metrics));
@@ -241,112 +218,11 @@ export class AggregatedAttestationPool {
241
218
  * Get attestations to be included in a block pre-electra. Returns up to $MAX_ATTESTATIONS items
242
219
  */
243
220
  getAttestationsForBlockPreElectra(
244
- fork: ForkName,
245
- forkChoice: IForkChoice,
246
- state: CachedBeaconStateAllForks
221
+ _fork: ForkName,
222
+ _forkChoice: IForkChoice,
223
+ _state: CachedBeaconStateAllForks
247
224
  ): phase0.Attestation[] {
248
- const stateSlot = state.slot;
249
- const stateEpoch = state.epochCtx.epoch;
250
- const statePrevEpoch = stateEpoch - 1;
251
-
252
- const notSeenValidatorsFn = getNotSeenValidatorsFn(state);
253
- const validateAttestationDataFn = getValidateAttestationDataFn(forkChoice, state);
254
-
255
- const attestationsByScore: AttestationWithScore[] = [];
256
-
257
- const slots = Array.from(this.attestationGroupByIndexByDataHexBySlot.keys()).sort((a, b) => b - a);
258
- let minScore = Number.MAX_SAFE_INTEGER;
259
- let slotCount = 0;
260
- slot: for (const slot of slots) {
261
- slotCount++;
262
- const attestationGroupByIndexByDataHash = this.attestationGroupByIndexByDataHexBySlot.get(slot);
263
- // should not happen
264
- if (!attestationGroupByIndexByDataHash) {
265
- throw Error(`No aggregated attestation pool for slot=${slot}`);
266
- }
267
-
268
- const epoch = computeEpochAtSlot(slot);
269
- // validateAttestation condition: Attestation target epoch not in previous or current epoch
270
- if (!(epoch === stateEpoch || epoch === statePrevEpoch)) {
271
- continue; // Invalid attestations
272
- }
273
- // validateAttestation condition: Attestation slot not within inclusion window
274
- if (
275
- !(
276
- slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot &&
277
- // Post deneb, attestations are valid for current and previous epoch
278
- (ForkSeq[fork] >= ForkSeq.deneb || stateSlot <= slot + SLOTS_PER_EPOCH)
279
- )
280
- ) {
281
- continue; // Invalid attestations
282
- }
283
-
284
- const inclusionDistance = stateSlot - slot;
285
- for (const attestationGroupByIndex of attestationGroupByIndexByDataHash.values()) {
286
- for (const [committeeIndex, attestationGroup] of attestationGroupByIndex.entries()) {
287
- const notSeenCommitteeMembers = notSeenValidatorsFn(epoch, slot, committeeIndex);
288
- if (notSeenCommitteeMembers === null || notSeenCommitteeMembers.size === 0) {
289
- continue;
290
- }
291
-
292
- if (
293
- slotCount > 2 &&
294
- attestationsByScore.length >= MAX_ATTESTATIONS &&
295
- notSeenCommitteeMembers.size / inclusionDistance < minScore
296
- ) {
297
- // after 2 slots, there are a good chance that we have 2 * MAX_ATTESTATIONS attestations and break the for loop early
298
- // if not, we may have to scan all slots in the pool
299
- // if we have enough attestations and the max possible score is lower than scores of `attestationsByScore`, we should skip
300
- // otherwise it takes time to check attestation, add it and remove it later after the sort by score
301
- continue;
302
- }
303
-
304
- if (validateAttestationDataFn(attestationGroup.data) !== null) {
305
- continue;
306
- }
307
-
308
- // TODO: Is it necessary to validateAttestation for:
309
- // - Attestation committee index not within current committee count
310
- // - Attestation aggregation bits length does not match committee length
311
- //
312
- // These properties should not change after being validate in gossip
313
- // IF they have to be validated, do it only with one attestation per group since same data
314
- // The committeeCountPerSlot can be precomputed once per slot
315
- const getAttestationsResult = attestationGroup.getAttestationsForBlock(
316
- fork,
317
- state.epochCtx.effectiveBalanceIncrements,
318
- notSeenCommitteeMembers,
319
- MAX_ATTESTATIONS_PER_GROUP
320
- );
321
- for (const {attestation, newSeenEffectiveBalance} of getAttestationsResult.result) {
322
- const score = newSeenEffectiveBalance / inclusionDistance;
323
- if (score < minScore) {
324
- minScore = score;
325
- }
326
- attestationsByScore.push({
327
- attestation,
328
- score,
329
- });
330
- }
331
-
332
- // Stop accumulating attestations there are enough that may have good scoring
333
- if (attestationsByScore.length >= MAX_ATTESTATIONS * 2) {
334
- break slot;
335
- }
336
- }
337
- }
338
- }
339
-
340
- const sortedAttestationsByScore = attestationsByScore.sort((a, b) => b.score - a.score);
341
- const attestationsForBlock: phase0.Attestation[] = [];
342
- for (const [i, attestationWithScore] of sortedAttestationsByScore.entries()) {
343
- if (i >= MAX_ATTESTATIONS) {
344
- break;
345
- }
346
- // attestations could be modified in this op pool, so we need to clone for block
347
- attestationsForBlock.push(ssz.phase0.Attestation.clone(attestationWithScore.attestation));
348
- }
349
- return attestationsForBlock;
225
+ throw new Error("Does not support producing blocks for pre-electra forks anymore");
350
226
  }
351
227
 
352
228
  /**
@@ -362,7 +238,7 @@ export class AggregatedAttestationPool {
362
238
  const statePrevEpoch = stateEpoch - 1;
363
239
  const rootCache = new RootCache(state);
364
240
 
365
- const notSeenValidatorsFn = getNotSeenValidatorsFn(state);
241
+ const notSeenValidatorsFn = getNotSeenValidatorsFn(this.config, state);
366
242
  const validateAttestationDataFn = getValidateAttestationDataFn(forkChoice, state);
367
243
 
368
244
  const slots = Array.from(this.attestationGroupByIndexByDataHexBySlot.keys()).sort((a, b) => b - a);
@@ -656,7 +532,7 @@ export class MatchingDataAttestationGroup {
656
532
  private readonly attestations: AttestationWithIndex[] = [];
657
533
 
658
534
  constructor(
659
- private readonly config: ChainForkConfig,
535
+ private readonly config: BeaconConfig,
660
536
  readonly committee: Uint32Array,
661
537
  readonly data: phase0.AttestationData
662
538
  ) {}
@@ -864,41 +740,10 @@ export function aggregateConsolidation({byCommittee, attData}: AttestationsConso
864
740
  * Pre-compute participation from a CachedBeaconStateAllForks, for use to check if an attestation's committee
865
741
  * has already attested or not.
866
742
  */
867
- export function getNotSeenValidatorsFn(state: CachedBeaconStateAllForks): GetNotSeenValidatorsFn {
743
+ export function getNotSeenValidatorsFn(config: BeaconConfig, state: CachedBeaconStateAllForks): GetNotSeenValidatorsFn {
868
744
  const stateSlot = state.slot;
869
- if (state.config.getForkName(stateSlot) === ForkName.phase0) {
870
- // Get attestations to be included in a phase0 block.
871
- // As we are close to altair, this is not really important, it's mainly for e2e.
872
- // The performance is not great due to the different BeaconState data structure to altair.
873
- // check for phase0 block already
874
- const phase0State = state as CachedBeaconStatePhase0;
875
- const stateEpoch = computeEpochAtSlot(stateSlot);
876
-
877
- const previousEpochParticipants = extractParticipationPhase0(
878
- phase0State.previousEpochAttestations.getAllReadonly(),
879
- state
880
- );
881
- const currentEpochParticipants = extractParticipationPhase0(
882
- phase0State.currentEpochAttestations.getAllReadonly(),
883
- state
884
- );
885
-
886
- return (epoch: Epoch, slot: Slot, committeeIndex: number) => {
887
- const participants =
888
- epoch === stateEpoch ? currentEpochParticipants : epoch === stateEpoch - 1 ? previousEpochParticipants : null;
889
- if (participants === null) {
890
- return null;
891
- }
892
- const committee = state.epochCtx.getBeaconCommittee(slot, committeeIndex);
893
-
894
- const notSeenCommitteeMembers = new Set<number>();
895
- for (const [i, validatorIndex] of committee.entries()) {
896
- if (!participants.has(validatorIndex)) {
897
- notSeenCommitteeMembers.add(i);
898
- }
899
- }
900
- return notSeenCommitteeMembers.size === 0 ? null : notSeenCommitteeMembers;
901
- };
745
+ if (config.getForkName(stateSlot) === ForkName.phase0) {
746
+ throw new Error("getNotSeenValidatorsFn is not supported phase0 state");
902
747
  }
903
748
 
904
749
  // altair and future forks
@@ -942,26 +787,6 @@ export function getNotSeenValidatorsFn(state: CachedBeaconStateAllForks): GetNot
942
787
  };
943
788
  }
944
789
 
945
- export function extractParticipationPhase0(
946
- attestations: phase0.PendingAttestation[],
947
- state: CachedBeaconStateAllForks
948
- ): Set<ValidatorIndex> {
949
- const {epochCtx} = state;
950
- const allParticipants = new Set<ValidatorIndex>();
951
- for (const att of attestations) {
952
- const aggregationBits = att.aggregationBits;
953
- const attData = att.data;
954
- const attSlot = attData.slot;
955
- const committeeIndex = attData.index;
956
- const committee = epochCtx.getBeaconCommittee(attSlot, committeeIndex);
957
- const participants = aggregationBits.intersectValues(committee);
958
- for (const participant of participants) {
959
- allParticipants.add(participant);
960
- }
961
- }
962
- return allParticipants;
963
- }
964
-
965
790
  /**
966
791
  * This returns a function to validate if an attestation data is compatible to a state.
967
792
  *
@@ -1,3 +1,4 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {Id, Repository} from "@lodestar/db";
2
3
  import {
3
4
  BLS_WITHDRAWAL_PREFIX,
@@ -51,6 +52,8 @@ export class OpPool {
51
52
  /** Map of validator index -> SignedBLSToExecutionChange */
52
53
  private readonly blsToExecutionChanges = new Map<ValidatorIndex, SignedBLSToExecutionChangeVersioned>();
53
54
 
55
+ constructor(private readonly config: BeaconConfig) {}
56
+
54
57
  // Getters for metrics
55
58
 
56
59
  get attesterSlashingsSize(): number {
@@ -191,9 +194,8 @@ export class OpPool {
191
194
  phase0.SignedVoluntaryExit[],
192
195
  capella.SignedBLSToExecutionChange[],
193
196
  ] {
194
- const {config} = state;
195
197
  const stateEpoch = computeEpochAtSlot(state.slot);
196
- const stateFork = config.getForkSeq(state.slot);
198
+ const stateFork = this.config.getForkSeq(state.slot);
197
199
  const toBeSlashedIndices = new Set<ValidatorIndex>();
198
200
  const proposerSlashings: phase0.ProposerSlashing[] = [];
199
201
 
@@ -265,7 +267,7 @@ export class OpPool {
265
267
  // a future fork.
266
268
  isVoluntaryExitSignatureIncludable(
267
269
  stateFork,
268
- config.getForkSeq(computeStartSlotAtEpoch(voluntaryExit.message.epoch))
270
+ this.config.getForkSeq(computeStartSlotAtEpoch(voluntaryExit.message.epoch))
269
271
  )
270
272
  ) {
271
273
  voluntaryExits.push(voluntaryExit);
@@ -368,14 +370,13 @@ export class OpPool {
368
370
  * Prune if validator has already exited at or before the finalized checkpoint of the head.
369
371
  */
370
372
  private pruneVoluntaryExits(headState: CachedBeaconStateAllForks): void {
371
- const {config} = headState;
372
- const headStateFork = config.getForkSeq(headState.slot);
373
+ const headStateFork = this.config.getForkSeq(headState.slot);
373
374
  const finalizedEpoch = headState.finalizedCheckpoint.epoch;
374
375
 
375
376
  for (const [key, voluntaryExit] of this.voluntaryExits.entries()) {
376
377
  // VoluntaryExit messages signed in the previous fork become invalid and can never be included in any future
377
378
  // block, so just drop as the head state advances into the next fork.
378
- if (config.getForkSeq(computeStartSlotAtEpoch(voluntaryExit.message.epoch)) < headStateFork) {
379
+ if (this.config.getForkSeq(computeStartSlotAtEpoch(voluntaryExit.message.epoch)) < headStateFork) {
379
380
  this.voluntaryExits.delete(key);
380
381
  }
381
382
 
@@ -392,9 +393,8 @@ export class OpPool {
392
393
  * to opPool once gossipsub seen cache TTL passes.
393
394
  */
394
395
  private pruneBlsToExecutionChanges(headBlock: SignedBeaconBlock, headState: CachedBeaconStateAllForks): void {
395
- const {config} = headState;
396
396
  const recentBlsToExecutionChanges =
397
- config.getForkSeq(headBlock.message.slot) >= ForkSeq.capella
397
+ this.config.getForkSeq(headBlock.message.slot) >= ForkSeq.capella
398
398
  ? (headBlock as capella.SignedBeaconBlock).message.body.blsToExecutionChanges
399
399
  : [];
400
400
 
@@ -117,12 +117,7 @@ export class PrepareNextSlotScheduler {
117
117
  // the slot 0 of next epoch will likely use this Previous Root Checkpoint state for state transition so we transfer cache here
118
118
  // the resulting state with cache will be cached in Checkpoint State Cache which is used for the upcoming block processing
119
119
  // for other slots dontTransferCached=true because we don't run state transition on this state
120
- //
121
- // Shuffling calculation will be done asynchronously when passing asyncShufflingCalculation=true. Shuffling will be queued in
122
- // beforeProcessEpoch and should theoretically be ready immediately after the synchronous epoch transition finished and the
123
- // event loop is free. In long periods of non-finality too many forks will cause the shufflingCache to throw an error for
124
- // too many queued shufflings so only run async during normal epoch transition. See issue ChainSafe/lodestar#7244
125
- {dontTransferCache: !isEpochTransition, asyncShufflingCalculation: true},
120
+ {dontTransferCache: !isEpochTransition},
126
121
  RegenCaller.precomputeEpoch
127
122
  );
128
123
 
@@ -148,6 +143,7 @@ export class PrepareNextSlotScheduler {
148
143
  updatedPrepareState = (await this.chain.regen.getBlockSlotState(
149
144
  proposerHeadRoot,
150
145
  prepareSlot,
146
+ // only transfer cache if epoch transition because that's the state we will use to stateTransition() the 1st block of epoch
151
147
  {dontTransferCache: !isEpochTransition},
152
148
  RegenCaller.predictProposerHead
153
149
  )) as CachedBeaconStateExecutions;
@@ -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 {
@@ -90,5 +86,5 @@ export interface IStateRegeneratorInternal {
90
86
  /**
91
87
  * Return the exact state with `stateRoot`
92
88
  */
93
- getState(stateRoot: RootHex, rCaller: RegenCaller, opts?: StateRegenerationOpts): Promise<CachedBeaconStateAllForks>;
89
+ getState(stateRoot: RootHex, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks>;
94
90
  }
@@ -79,21 +79,15 @@ export class QueuedStateRegenerator implements IStateRegenerator {
79
79
 
80
80
  /**
81
81
  * Get a state from block state cache.
82
- * This is not for block processing so don't transfer cache
83
82
  */
84
83
  getStateSync(stateRoot: RootHex): CachedBeaconStateAllForks | null {
85
- return this.blockStateCache.get(stateRoot, {dontTransferCache: true});
84
+ return this.blockStateCache.get(stateRoot);
86
85
  }
87
86
 
88
87
  /**
89
88
  * Get state for block processing.
90
- * By default, do not transfer cache except for the block at clock slot
91
- * which is usually the gossip block.
92
89
  */
93
- getPreStateSync(
94
- block: BeaconBlock,
95
- opts: StateRegenerationOpts = {dontTransferCache: true}
96
- ): CachedBeaconStateAllForks | null {
90
+ getPreStateSync(block: BeaconBlock): CachedBeaconStateAllForks | null {
97
91
  const parentRoot = toRootHex(block.parentRoot);
98
92
  const parentBlock = this.forkChoice.getBlockHex(parentRoot);
99
93
  if (!parentBlock) {
@@ -108,7 +102,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
108
102
 
109
103
  // Check the checkpoint cache (if the pre-state is a checkpoint state)
110
104
  if (parentEpoch < blockEpoch) {
111
- const checkpointState = this.checkpointStateCache.getLatest(parentRoot, blockEpoch, opts);
105
+ const checkpointState = this.checkpointStateCache.getLatest(parentRoot, blockEpoch);
112
106
  if (checkpointState && computeEpochAtSlot(checkpointState.slot) === blockEpoch) {
113
107
  return checkpointState;
114
108
  }
@@ -118,7 +112,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
118
112
  // Otherwise the state transition may not be cached and wasted. Queue for regen since the
119
113
  // work required will still be significant.
120
114
  if (parentEpoch === blockEpoch) {
121
- const state = this.blockStateCache.get(parentBlock.stateRoot, opts);
115
+ const state = this.blockStateCache.get(parentBlock.stateRoot);
122
116
  if (state) {
123
117
  return state;
124
118
  }
@@ -132,21 +126,17 @@ export class QueuedStateRegenerator implements IStateRegenerator {
132
126
  }
133
127
 
134
128
  /**
135
- * Get checkpoint state from cache, this function is not for block processing so don't transfer cache
129
+ * Get checkpoint state from cache
136
130
  */
137
131
  getCheckpointStateSync(cp: CheckpointHex): CachedBeaconStateAllForks | null {
138
- return this.checkpointStateCache.get(cp, {dontTransferCache: true});
132
+ return this.checkpointStateCache.get(cp);
139
133
  }
140
134
 
141
135
  /**
142
- * Get state closest to head, this function is not for block processing so don't transfer cache
136
+ * Get state closest to head
143
137
  */
144
138
  getClosestHeadState(head: ProtoBlock): CachedBeaconStateAllForks | null {
145
- const opts = {dontTransferCache: true};
146
- return (
147
- this.checkpointStateCache.getLatest(head.blockRoot, Infinity, opts) ||
148
- this.blockStateCache.get(head.stateRoot, opts)
149
- );
139
+ return this.checkpointStateCache.getLatest(head.blockRoot, Infinity) || this.blockStateCache.get(head.stateRoot);
150
140
  }
151
141
 
152
142
  pruneOnCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void {
@@ -181,10 +171,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
181
171
  maybeHeadStateRoot,
182
172
  };
183
173
  const headState =
184
- newHeadStateRoot === maybeHeadStateRoot
185
- ? maybeHeadState
186
- : // maybeHeadState was already in block state cache so we don't transfer the cache
187
- this.blockStateCache.get(newHeadStateRoot, {dontTransferCache: true});
174
+ newHeadStateRoot === maybeHeadStateRoot ? maybeHeadState : this.blockStateCache.get(newHeadStateRoot);
188
175
 
189
176
  if (headState) {
190
177
  this.blockStateCache.setHeadState(headState);
@@ -199,9 +186,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
199
186
 
200
187
  // for the new FIFOBlockStateCache, it's important to reload state to regen head state here if needed
201
188
  const allowDiskReload = true;
202
- // transfer cache here because we want to regen state asap
203
- const cloneOpts = {dontTransferCache: false};
204
- this.regen.getState(newHeadStateRoot, RegenCaller.processBlock, cloneOpts, allowDiskReload).then(
189
+ this.regen.getState(newHeadStateRoot, RegenCaller.processBlock, allowDiskReload).then(
205
190
  (headStateRegen) => this.blockStateCache.setHeadState(headStateRegen),
206
191
  (e) => this.logger.error("Error on head state regen", logCtx, e)
207
192
  );
@@ -224,7 +209,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
224
209
  this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getPreState});
225
210
 
226
211
  // First attempt to fetch the state from caches before queueing
227
- const cachedState = this.getPreStateSync(block, opts);
212
+ const cachedState = this.getPreStateSync(block);
228
213
 
229
214
  if (cachedState !== null) {
230
215
  return cachedState;
@@ -243,7 +228,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
243
228
  this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getCheckpointState});
244
229
 
245
230
  // First attempt to fetch the state from cache before queueing
246
- const checkpointState = this.checkpointStateCache.get(toCheckpointHex(cp), opts);
231
+ const checkpointState = this.checkpointStateCache.get(toCheckpointHex(cp));
247
232
  if (checkpointState) {
248
233
  return checkpointState;
249
234
  }
@@ -271,22 +256,18 @@ export class QueuedStateRegenerator implements IStateRegenerator {
271
256
  return this.jobQueue.push({key: "getBlockSlotState", args: [blockRoot, slot, opts, rCaller]});
272
257
  }
273
258
 
274
- async getState(
275
- stateRoot: RootHex,
276
- rCaller: RegenCaller,
277
- opts: StateRegenerationOpts = {dontTransferCache: true}
278
- ): Promise<CachedBeaconStateAllForks> {
259
+ async getState(stateRoot: RootHex, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
279
260
  this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getState});
280
261
 
281
262
  // First attempt to fetch the state from cache before queueing
282
- const state = this.blockStateCache.get(stateRoot, opts);
263
+ const state = this.blockStateCache.get(stateRoot);
283
264
  if (state) {
284
265
  return state;
285
266
  }
286
267
 
287
268
  // The state is not immediately available in the cache, enqueue the job
288
269
  this.metrics?.regenFnQueuedTotal.inc({caller: rCaller, entrypoint: RegenFnName.getState});
289
- return this.jobQueue.push({key: "getState", args: [stateRoot, rCaller, opts]});
270
+ return this.jobQueue.push({key: "getState", args: [stateRoot, rCaller]});
290
271
  }
291
272
 
292
273
  private jobQueueProcessor = async (regenRequest: RegenRequest): Promise<CachedBeaconStateAllForks> => {
@@ -78,7 +78,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
78
78
  }
79
79
 
80
80
  // Otherwise, get the state normally.
81
- return this.getState(parentBlock.stateRoot, regenCaller, opts, allowDiskReload);
81
+ return this.getState(parentBlock.stateRoot, regenCaller, allowDiskReload);
82
82
  }
83
83
 
84
84
  /**
@@ -124,8 +124,8 @@ export class StateRegenerator implements IStateRegeneratorInternal {
124
124
  const {checkpointStateCache} = this.modules;
125
125
  const epoch = computeEpochAtSlot(slot);
126
126
  const latestCheckpointStateCtx = allowDiskReload
127
- ? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch, opts)
128
- : checkpointStateCache.getLatest(blockRoot, epoch, opts);
127
+ ? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch)
128
+ : checkpointStateCache.getLatest(blockRoot, epoch);
129
129
 
130
130
  // If a checkpoint state exists with the given checkpoint root, it either is in requested epoch
131
131
  // or needs to have empty slots processed until the requested epoch
@@ -136,7 +136,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
136
136
  // Otherwise, use the fork choice to get the stateRoot from block at the checkpoint root
137
137
  // regenerate that state,
138
138
  // then process empty slots until the requested epoch
139
- const blockStateCtx = await this.getState(block.stateRoot, regenCaller, opts, allowDiskReload);
139
+ const blockStateCtx = await this.getState(block.stateRoot, regenCaller, allowDiskReload);
140
140
  return processSlotsByCheckpoint(this.modules, blockStateCtx, slot, regenCaller, opts);
141
141
  }
142
142
 
@@ -148,23 +148,15 @@ export class StateRegenerator implements IStateRegeneratorInternal {
148
148
  async getState(
149
149
  stateRoot: RootHex,
150
150
  caller: RegenCaller,
151
- opts?: StateRegenerationOpts,
152
151
  // internal option, don't want to expose to external caller
153
152
  allowDiskReload = false
154
153
  ): Promise<CachedBeaconStateAllForks> {
155
154
  // Trivial case, state at stateRoot is already cached
156
- const cachedStateCtx = this.modules.blockStateCache.get(stateRoot, opts);
155
+ const cachedStateCtx = this.modules.blockStateCache.get(stateRoot);
157
156
  if (cachedStateCtx) {
158
157
  return cachedStateCtx;
159
158
  }
160
159
 
161
- // in block gossip validation (getPreState() call), dontTransferCache is specified as true because we only want to transfer cache in verifyBlocksStateTransitionOnly()
162
- // but here we want to process blocks as fast as possible so force to transfer cache in this case
163
- if (opts && allowDiskReload) {
164
- // if there is no `opts` specified, it already means "false"
165
- opts.dontTransferCache = false;
166
- }
167
-
168
160
  // Otherwise we have to use the fork choice to traverse backwards, block by block,
169
161
  // searching the state caches
170
162
  // then replay blocks forward to the desired stateRoot
@@ -179,7 +171,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
179
171
  const getSeedStateTimer = this.modules.metrics?.regenGetState.getSeedState.startTimer({caller});
180
172
  // iterateAncestorBlocks only returns ancestor blocks, not the block itself
181
173
  for (const b of this.modules.forkChoice.iterateAncestorBlocks(block.blockRoot)) {
182
- state = this.modules.blockStateCache.get(b.stateRoot, opts);
174
+ state = this.modules.blockStateCache.get(b.stateRoot);
183
175
  if (state) {
184
176
  break;
185
177
  }
@@ -187,8 +179,8 @@ export class StateRegenerator implements IStateRegeneratorInternal {
187
179
  if (!lastBlockToReplay) continue;
188
180
  const epoch = computeEpochAtSlot(lastBlockToReplay.slot - 1);
189
181
  state = allowDiskReload
190
- ? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch, opts)
191
- : checkpointStateCache.getLatest(b.blockRoot, epoch, opts);
182
+ ? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch)
183
+ : checkpointStateCache.getLatest(b.blockRoot, epoch);
192
184
  if (state) {
193
185
  break;
194
186
  }
@@ -255,6 +247,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
255
247
  try {
256
248
  // Only advances state trusting block's signture and hashes.
257
249
  // We are only running the state transition to get a specific state's data.
250
+ // stateTransition() does the clone() inside, transfer cache to make the regen faster
258
251
  state = stateTransition(
259
252
  state,
260
253
  block,
@@ -265,6 +258,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
265
258
  verifyStateRoot: false,
266
259
  verifyProposer: false,
267
260
  verifySignatures: false,
261
+ dontTransferCache: false,
268
262
  },
269
263
  this.modules
270
264
  );
@@ -390,8 +384,8 @@ export async function processSlotsToNearestCheckpoint(
390
384
  const checkpointState = postState;
391
385
  const cp = getCheckpointFromState(checkpointState);
392
386
  checkpointStateCache.add(cp, checkpointState);
393
- // consumers should not mutate or get the transfered cache
394
- emitter?.emit(ChainEvent.checkpoint, cp, checkpointState.clone(true));
387
+ // consumers should not mutate state ever
388
+ emitter?.emit(ChainEvent.checkpoint, cp, checkpointState);
395
389
 
396
390
  if (count >= 1) {
397
391
  // in normal condition, we only process 1 epoch so never reach this