@lodestar/beacon-node 1.42.0-dev.7b5ce3932d → 1.42.0-dev.7e96447c23

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 (301) hide show
  1. package/lib/api/impl/beacon/blocks/index.js +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  3. package/lib/api/impl/beacon/pool/index.js +1 -1
  4. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  5. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  6. package/lib/api/impl/beacon/state/index.js +27 -32
  7. package/lib/api/impl/beacon/state/index.js.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.d.ts +4 -4
  9. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  10. package/lib/api/impl/beacon/state/utils.js +7 -10
  11. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  12. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  13. package/lib/api/impl/lodestar/index.js +4 -6
  14. package/lib/api/impl/lodestar/index.js.map +1 -1
  15. package/lib/api/impl/proof/index.d.ts.map +1 -1
  16. package/lib/api/impl/proof/index.js +2 -6
  17. package/lib/api/impl/proof/index.js.map +1 -1
  18. package/lib/api/impl/validator/index.d.ts.map +1 -1
  19. package/lib/api/impl/validator/index.js +27 -27
  20. package/lib/api/impl/validator/index.js.map +1 -1
  21. package/lib/api/impl/validator/utils.d.ts +2 -2
  22. package/lib/api/impl/validator/utils.d.ts.map +1 -1
  23. package/lib/api/impl/validator/utils.js +3 -3
  24. package/lib/api/impl/validator/utils.js.map +1 -1
  25. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +2 -6
  26. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  27. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +3 -23
  28. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  29. package/lib/chain/archiveStore/historicalState/worker.js +1 -0
  30. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  31. package/lib/chain/balancesCache.d.ts +2 -2
  32. package/lib/chain/balancesCache.d.ts.map +1 -1
  33. package/lib/chain/balancesCache.js +4 -4
  34. package/lib/chain/balancesCache.js.map +1 -1
  35. package/lib/chain/blocks/blockInput/types.d.ts +1 -0
  36. package/lib/chain/blocks/blockInput/types.d.ts.map +1 -1
  37. package/lib/chain/blocks/blockInput/types.js +1 -0
  38. package/lib/chain/blocks/blockInput/types.js.map +1 -1
  39. package/lib/chain/blocks/importBlock.d.ts +3 -3
  40. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  41. package/lib/chain/blocks/importBlock.js +9 -9
  42. package/lib/chain/blocks/importBlock.js.map +1 -1
  43. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  44. package/lib/chain/blocks/importExecutionPayload.js +4 -5
  45. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  46. package/lib/chain/blocks/index.js +1 -1
  47. package/lib/chain/blocks/index.js.map +1 -1
  48. package/lib/chain/blocks/types.d.ts +2 -2
  49. package/lib/chain/blocks/types.d.ts.map +1 -1
  50. package/lib/chain/blocks/types.js.map +1 -1
  51. package/lib/chain/blocks/utils/checkpoint.d.ts +2 -2
  52. package/lib/chain/blocks/utils/checkpoint.d.ts.map +1 -1
  53. package/lib/chain/blocks/utils/checkpoint.js.map +1 -1
  54. package/lib/chain/blocks/verifyBlock.d.ts +2 -2
  55. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  56. package/lib/chain/blocks/verifyBlock.js +4 -4
  57. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  58. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +3 -3
  59. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  60. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +3 -3
  61. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  62. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  63. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  64. package/lib/chain/blocks/verifyBlocksSignatures.js +1 -1
  65. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  66. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts +3 -3
  67. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  68. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +3 -3
  69. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  70. package/lib/chain/chain.d.ts +11 -12
  71. package/lib/chain/chain.d.ts.map +1 -1
  72. package/lib/chain/chain.js +33 -39
  73. package/lib/chain/chain.js.map +1 -1
  74. package/lib/chain/emitter.d.ts +2 -2
  75. package/lib/chain/emitter.d.ts.map +1 -1
  76. package/lib/chain/errors/blockError.d.ts +4 -4
  77. package/lib/chain/errors/blockError.d.ts.map +1 -1
  78. package/lib/chain/forkChoice/index.d.ts +4 -4
  79. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  80. package/lib/chain/forkChoice/index.js +27 -23
  81. package/lib/chain/forkChoice/index.js.map +1 -1
  82. package/lib/chain/initState.d.ts +2 -2
  83. package/lib/chain/initState.d.ts.map +1 -1
  84. package/lib/chain/initState.js +1 -1
  85. package/lib/chain/initState.js.map +1 -1
  86. package/lib/chain/interface.d.ts +10 -12
  87. package/lib/chain/interface.d.ts.map +1 -1
  88. package/lib/chain/lightClient/index.d.ts +2 -2
  89. package/lib/chain/lightClient/index.d.ts.map +1 -1
  90. package/lib/chain/lightClient/index.js +4 -4
  91. package/lib/chain/lightClient/index.js.map +1 -1
  92. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +6 -6
  93. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  94. package/lib/chain/opPools/aggregatedAttestationPool.js +10 -13
  95. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  96. package/lib/chain/opPools/opPool.d.ts +3 -3
  97. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  98. package/lib/chain/opPools/opPool.js +7 -7
  99. package/lib/chain/opPools/opPool.js.map +1 -1
  100. package/lib/chain/opPools/utils.d.ts +2 -2
  101. package/lib/chain/opPools/utils.d.ts.map +1 -1
  102. package/lib/chain/opPools/utils.js +1 -1
  103. package/lib/chain/opPools/utils.js.map +1 -1
  104. package/lib/chain/prepareNextSlot.d.ts +2 -2
  105. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  106. package/lib/chain/prepareNextSlot.js +3 -3
  107. package/lib/chain/prepareNextSlot.js.map +1 -1
  108. package/lib/chain/produceBlock/computeNewStateRoot.d.ts +4 -4
  109. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  110. package/lib/chain/produceBlock/computeNewStateRoot.js +3 -4
  111. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  112. package/lib/chain/produceBlock/produceBlockBody.d.ts +5 -5
  113. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  114. package/lib/chain/produceBlock/produceBlockBody.js +12 -16
  115. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  116. package/lib/chain/regen/interface.d.ts +13 -13
  117. package/lib/chain/regen/interface.d.ts.map +1 -1
  118. package/lib/chain/regen/queued.d.ts +14 -14
  119. package/lib/chain/regen/queued.d.ts.map +1 -1
  120. package/lib/chain/regen/queued.js.map +1 -1
  121. package/lib/chain/regen/regen.d.ts +6 -5
  122. package/lib/chain/regen/regen.d.ts.map +1 -1
  123. package/lib/chain/regen/regen.js +6 -6
  124. package/lib/chain/regen/regen.js.map +1 -1
  125. package/lib/chain/serializeState.d.ts +2 -2
  126. package/lib/chain/serializeState.d.ts.map +1 -1
  127. package/lib/chain/serializeState.js +1 -1
  128. package/lib/chain/serializeState.js.map +1 -1
  129. package/lib/chain/shufflingCache.d.ts +2 -2
  130. package/lib/chain/shufflingCache.d.ts.map +1 -1
  131. package/lib/chain/shufflingCache.js +3 -4
  132. package/lib/chain/shufflingCache.js.map +1 -1
  133. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +6 -6
  134. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  135. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  136. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +11 -11
  137. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  138. package/lib/chain/stateCache/persistentCheckpointsCache.js +12 -16
  139. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  140. package/lib/chain/stateCache/types.d.ts +14 -14
  141. package/lib/chain/stateCache/types.d.ts.map +1 -1
  142. package/lib/chain/stateCache/types.js.map +1 -1
  143. package/lib/chain/validation/attesterSlashing.js +3 -3
  144. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  145. package/lib/chain/validation/blobSidecar.js +1 -1
  146. package/lib/chain/validation/blobSidecar.js.map +1 -1
  147. package/lib/chain/validation/block.d.ts.map +1 -1
  148. package/lib/chain/validation/block.js +3 -3
  149. package/lib/chain/validation/block.js.map +1 -1
  150. package/lib/chain/validation/blsToExecutionChange.js +2 -2
  151. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  152. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  153. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  154. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  155. package/lib/chain/validation/executionPayloadBid.js +4 -4
  156. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  157. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  158. package/lib/chain/validation/executionPayloadEnvelope.js +2 -3
  159. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  160. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  161. package/lib/chain/validation/payloadAttestationMessage.js +1 -2
  162. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  163. package/lib/chain/validation/proposerSlashing.js +1 -1
  164. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  165. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  166. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  167. package/lib/chain/validation/signatureSets/contributionAndProof.js +1 -1
  168. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  169. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  170. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  171. package/lib/chain/validation/signatureSets/syncCommittee.js +1 -1
  172. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  173. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
  174. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  175. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  176. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  177. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  178. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -1
  179. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  180. package/lib/chain/validation/syncCommittee.d.ts +4 -4
  181. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  182. package/lib/chain/validation/syncCommittee.js +13 -12
  183. package/lib/chain/validation/syncCommittee.js.map +1 -1
  184. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  185. package/lib/chain/validation/syncCommitteeContributionAndProof.js +1 -1
  186. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  187. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  188. package/lib/chain/validation/voluntaryExit.js +3 -3
  189. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  190. package/lib/chain/validatorMonitor.d.ts +3 -3
  191. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  192. package/lib/chain/validatorMonitor.js +9 -7
  193. package/lib/chain/validatorMonitor.js.map +1 -1
  194. package/lib/metrics/metrics/lodestar.d.ts +12 -4
  195. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  196. package/lib/metrics/metrics/lodestar.js +19 -15
  197. package/lib/metrics/metrics/lodestar.js.map +1 -1
  198. package/lib/network/gossip/encoding.d.ts.map +1 -1
  199. package/lib/network/gossip/encoding.js +15 -0
  200. package/lib/network/gossip/encoding.js.map +1 -1
  201. package/lib/network/interface.d.ts +1 -1
  202. package/lib/network/interface.d.ts.map +1 -1
  203. package/lib/network/network.d.ts +1 -1
  204. package/lib/network/network.d.ts.map +1 -1
  205. package/lib/network/network.js +3 -3
  206. package/lib/network/network.js.map +1 -1
  207. package/lib/network/processor/extractSlotRootFns.d.ts +1 -1
  208. package/lib/network/processor/extractSlotRootFns.js +1 -1
  209. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  210. package/lib/network/processor/gossipHandlers.js +9 -7
  211. package/lib/network/processor/gossipHandlers.js.map +1 -1
  212. package/lib/network/processor/index.d.ts +12 -7
  213. package/lib/network/processor/index.d.ts.map +1 -1
  214. package/lib/network/processor/index.js +99 -78
  215. package/lib/network/processor/index.js.map +1 -1
  216. package/lib/node/nodejs.d.ts +2 -2
  217. package/lib/node/nodejs.d.ts.map +1 -1
  218. package/lib/node/nodejs.js +1 -4
  219. package/lib/node/nodejs.js.map +1 -1
  220. package/lib/node/notifier.d.ts.map +1 -1
  221. package/lib/node/notifier.js +3 -3
  222. package/lib/node/notifier.js.map +1 -1
  223. package/lib/sync/backfill/backfill.d.ts +2 -2
  224. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  225. package/lib/sync/backfill/backfill.js +2 -2
  226. package/lib/sync/backfill/backfill.js.map +1 -1
  227. package/lib/sync/unknownBlock.d.ts +3 -9
  228. package/lib/sync/unknownBlock.d.ts.map +1 -1
  229. package/lib/sync/unknownBlock.js +8 -41
  230. package/lib/sync/unknownBlock.js.map +1 -1
  231. package/package.json +15 -15
  232. package/src/api/impl/beacon/blocks/index.ts +1 -1
  233. package/src/api/impl/beacon/pool/index.ts +1 -1
  234. package/src/api/impl/beacon/state/index.ts +29 -41
  235. package/src/api/impl/beacon/state/utils.ts +11 -25
  236. package/src/api/impl/lodestar/index.ts +4 -8
  237. package/src/api/impl/proof/index.ts +2 -9
  238. package/src/api/impl/validator/index.ts +29 -41
  239. package/src/api/impl/validator/utils.ts +4 -7
  240. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +6 -36
  241. package/src/chain/archiveStore/historicalState/worker.ts +1 -0
  242. package/src/chain/balancesCache.ts +5 -11
  243. package/src/chain/blocks/blockInput/types.ts +1 -0
  244. package/src/chain/blocks/importBlock.ts +11 -14
  245. package/src/chain/blocks/importExecutionPayload.ts +6 -11
  246. package/src/chain/blocks/index.ts +1 -1
  247. package/src/chain/blocks/types.ts +2 -2
  248. package/src/chain/blocks/utils/checkpoint.ts +2 -2
  249. package/src/chain/blocks/verifyBlock.ts +5 -10
  250. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +5 -10
  251. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -3
  252. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +6 -8
  253. package/src/chain/chain.ts +57 -67
  254. package/src/chain/emitter.ts +2 -2
  255. package/src/chain/errors/blockError.ts +4 -4
  256. package/src/chain/forkChoice/index.ts +33 -42
  257. package/src/chain/initState.ts +7 -2
  258. package/src/chain/interface.ts +11 -13
  259. package/src/chain/lightClient/index.ts +9 -22
  260. package/src/chain/opPools/aggregatedAttestationPool.ts +15 -21
  261. package/src/chain/opPools/opPool.ts +13 -14
  262. package/src/chain/opPools/utils.ts +3 -3
  263. package/src/chain/prepareNextSlot.ts +6 -8
  264. package/src/chain/produceBlock/computeNewStateRoot.ts +6 -10
  265. package/src/chain/produceBlock/produceBlockBody.ts +22 -49
  266. package/src/chain/regen/interface.ts +13 -17
  267. package/src/chain/regen/queued.ts +16 -20
  268. package/src/chain/regen/regen.ts +16 -17
  269. package/src/chain/serializeState.ts +3 -3
  270. package/src/chain/shufflingCache.ts +5 -7
  271. package/src/chain/stateCache/fifoBlockStateCache.ts +7 -7
  272. package/src/chain/stateCache/persistentCheckpointsCache.ts +27 -42
  273. package/src/chain/stateCache/types.ts +14 -18
  274. package/src/chain/validation/attesterSlashing.ts +3 -3
  275. package/src/chain/validation/blobSidecar.ts +1 -1
  276. package/src/chain/validation/block.ts +2 -4
  277. package/src/chain/validation/blsToExecutionChange.ts +2 -2
  278. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  279. package/src/chain/validation/executionPayloadBid.ts +3 -7
  280. package/src/chain/validation/executionPayloadEnvelope.ts +2 -8
  281. package/src/chain/validation/payloadAttestationMessage.ts +2 -4
  282. package/src/chain/validation/proposerSlashing.ts +1 -1
  283. package/src/chain/validation/signatureSets/contributionAndProof.ts +2 -7
  284. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -7
  285. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -2
  286. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -7
  287. package/src/chain/validation/syncCommittee.ts +21 -20
  288. package/src/chain/validation/syncCommitteeContributionAndProof.ts +5 -10
  289. package/src/chain/validation/voluntaryExit.ts +3 -8
  290. package/src/chain/validatorMonitor.ts +12 -11
  291. package/src/metrics/metrics/lodestar.ts +23 -19
  292. package/src/network/gossip/encoding.ts +16 -0
  293. package/src/network/interface.ts +1 -1
  294. package/src/network/network.ts +3 -3
  295. package/src/network/processor/extractSlotRootFns.ts +1 -1
  296. package/src/network/processor/gossipHandlers.ts +9 -8
  297. package/src/network/processor/index.ts +110 -89
  298. package/src/node/nodejs.ts +3 -5
  299. package/src/node/notifier.ts +4 -10
  300. package/src/sync/backfill/backfill.ts +3 -3
  301. package/src/sync/unknownBlock.ts +10 -50
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import {PrivateKey} from "@libp2p/interface";
3
- import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
3
+ import {Type} from "@chainsafe/ssz";
4
4
  import {BeaconConfig} from "@lodestar/config";
5
5
  import {
6
6
  CheckpointWithPayloadStatus,
@@ -14,30 +14,21 @@ import {LoggerNode} from "@lodestar/logger/node";
14
14
  import {
15
15
  BUILDER_INDEX_SELF_BUILD,
16
16
  EFFECTIVE_BALANCE_INCREMENT,
17
- ForkPostFulu,
17
+ type ForkPostFulu,
18
18
  GENESIS_SLOT,
19
19
  SLOTS_PER_EPOCH,
20
20
  isForkPostElectra,
21
21
  isForkPostGloas,
22
22
  } from "@lodestar/params";
23
23
  import {
24
- BeaconStateAllForks,
25
- BeaconStateElectra,
26
- CachedBeaconStateAllForks,
27
- CachedBeaconStateGloas,
28
24
  EffectiveBalanceIncrements,
29
25
  EpochShuffling,
26
+ IBeaconStateView,
30
27
  PubkeyCache,
31
- computeAnchorCheckpoint,
32
- computeAttestationsRewards,
33
- computeBlockRewards,
34
28
  computeEndSlotAtEpoch,
35
29
  computeEpochAtSlot,
36
30
  computeStartSlotAtEpoch,
37
- computeSyncCommitteeRewards,
38
- getEffectiveBalanceIncrementsZeroInactive,
39
31
  getEffectiveBalancesFromStateBytes,
40
- processSlots,
41
32
  } from "@lodestar/state-transition";
42
33
  import {
43
34
  BeaconBlock,
@@ -283,7 +274,7 @@ export class BeaconChain implements IBeaconChain {
283
274
  clock?: IClock;
284
275
  metrics: Metrics | null;
285
276
  validatorMonitor: ValidatorMonitor | null;
286
- anchorState: CachedBeaconStateAllForks;
277
+ anchorState: IBeaconStateView;
287
278
  isAnchorStateFinalized: boolean;
288
279
  executionEngine: IExecutionEngine;
289
280
  executionBuilder?: IExecutionBuilder;
@@ -359,16 +350,16 @@ export class BeaconChain implements IBeaconChain {
359
350
 
360
351
  this.shufflingCache = new ShufflingCache(metrics, logger, this.opts, [
361
352
  {
362
- shuffling: anchorState.epochCtx.previousShuffling,
363
- decisionRoot: anchorState.epochCtx.previousDecisionRoot,
353
+ shuffling: anchorState.getPreviousShuffling(),
354
+ decisionRoot: anchorState.previousDecisionRoot,
364
355
  },
365
356
  {
366
- shuffling: anchorState.epochCtx.currentShuffling,
367
- decisionRoot: anchorState.epochCtx.currentDecisionRoot,
357
+ shuffling: anchorState.getCurrentShuffling(),
358
+ decisionRoot: anchorState.currentDecisionRoot,
368
359
  },
369
360
  {
370
- shuffling: anchorState.epochCtx.nextShuffling,
371
- decisionRoot: anchorState.epochCtx.nextDecisionRoot,
361
+ shuffling: anchorState.getNextShuffling(),
362
+ decisionRoot: anchorState.nextDecisionRoot,
372
363
  },
373
364
  ]);
374
365
 
@@ -377,7 +368,7 @@ export class BeaconChain implements IBeaconChain {
377
368
 
378
369
  const fileDataStore = opts.nHistoricalStatesFileDataStore ?? true;
379
370
  const blockStateCache = new FIFOBlockStateCache(this.opts, {metrics});
380
- this.bufferPool = new BufferPool(anchorState.type.tree_serializedSize(anchorState.node), metrics);
371
+ this.bufferPool = new BufferPool(anchorState.serializedSize(), metrics);
381
372
 
382
373
  this.cpStateDatastore = fileDataStore ? new FileCPStateDatastore(dataDir) : new DbCPStateDatastore(this.db);
383
374
  const checkpointStateCache: CheckpointStateCache = new PersistentCheckpointStateCache(
@@ -393,10 +384,10 @@ export class BeaconChain implements IBeaconChain {
393
384
  this.opts
394
385
  );
395
386
 
396
- const {checkpoint} = computeAnchorCheckpoint(config, anchorState);
387
+ const {checkpoint} = anchorState.computeAnchorCheckpoint();
397
388
  blockStateCache.add(anchorState);
398
389
  blockStateCache.setHeadState(anchorState);
399
- const payloadPresent = getCheckpointPayloadStatus(anchorState, checkpoint.epoch) === PayloadStatus.FULL;
390
+ const payloadPresent = getCheckpointPayloadStatus(config, anchorState, checkpoint.epoch) === PayloadStatus.FULL;
400
391
  checkpointStateCache.add(checkpoint, anchorState, payloadPresent);
401
392
 
402
393
  const forkChoice = initializeForkChoice(
@@ -557,7 +548,7 @@ export class BeaconChain implements IBeaconChain {
557
548
  await this.opPool.toPersisted(this.db);
558
549
  }
559
550
 
560
- getHeadState(): CachedBeaconStateAllForks {
551
+ getHeadState(): IBeaconStateView {
561
552
  // head state should always exist
562
553
  const head = this.forkChoice.getHead();
563
554
  const headState = this.regen.getClosestHeadState(head);
@@ -567,11 +558,11 @@ export class BeaconChain implements IBeaconChain {
567
558
  return headState;
568
559
  }
569
560
 
570
- async getHeadStateAtCurrentEpoch(regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
561
+ async getHeadStateAtCurrentEpoch(regenCaller: RegenCaller): Promise<IBeaconStateView> {
571
562
  return this.getHeadStateAtEpoch(this.clock.currentEpoch, regenCaller);
572
563
  }
573
564
 
574
- async getHeadStateAtEpoch(epoch: Epoch, regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
565
+ async getHeadStateAtEpoch(epoch: Epoch, regenCaller: RegenCaller): Promise<IBeaconStateView> {
575
566
  // using getHeadState() means we'll use checkpointStateCache if it's available
576
567
  const headState = this.getHeadState();
577
568
  // head state is in the same epoch, or we pulled up head state already from past epoch
@@ -588,7 +579,7 @@ export class BeaconChain implements IBeaconChain {
588
579
  async getStateBySlot(
589
580
  slot: Slot,
590
581
  opts?: StateGetOpts
591
- ): Promise<{state: CachedBeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null> {
582
+ ): Promise<{state: IBeaconStateView; executionOptimistic: boolean; finalized: boolean} | null> {
592
583
  const finalizedBlock = this.forkChoice.getFinalizedBlock();
593
584
 
594
585
  if (slot < finalizedBlock.slot) {
@@ -638,15 +629,17 @@ export class BeaconChain implements IBeaconChain {
638
629
  async getStateByStateRoot(
639
630
  stateRoot: RootHex,
640
631
  opts?: StateGetOpts
641
- ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
632
+ ): Promise<{state: IBeaconStateView | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
642
633
  if (opts?.allowRegen) {
643
634
  const state = await this.regen.getState(stateRoot, RegenCaller.restApi);
644
- const block = this.forkChoice.getBlockDefaultStatus(state.latestBlockHeader.hashTreeRoot());
635
+ const block = this.forkChoice.getBlockDefaultStatus(
636
+ ssz.phase0.BeaconBlockHeader.hashTreeRoot(state.latestBlockHeader)
637
+ );
645
638
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
646
639
  return {
647
640
  state,
648
641
  executionOptimistic: block != null && isOptimisticBlock(block),
649
- finalized: state.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
642
+ finalized: state.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
650
643
  };
651
644
  }
652
645
 
@@ -657,12 +650,14 @@ export class BeaconChain implements IBeaconChain {
657
650
  // TODO: This is very inneficient for debug requests of serialized content, since it deserializes to serialize again
658
651
  const cachedStateCtx = this.regen.getStateSync(stateRoot);
659
652
  if (cachedStateCtx) {
660
- const block = this.forkChoice.getBlockDefaultStatus(cachedStateCtx.latestBlockHeader.hashTreeRoot());
653
+ const block = this.forkChoice.getBlockDefaultStatus(
654
+ ssz.phase0.BeaconBlockHeader.hashTreeRoot(cachedStateCtx.latestBlockHeader)
655
+ );
661
656
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
662
657
  return {
663
658
  state: cachedStateCtx,
664
659
  executionOptimistic: block != null && isOptimisticBlock(block),
665
- finalized: cachedStateCtx.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
660
+ finalized: cachedStateCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
666
661
  };
667
662
  }
668
663
 
@@ -689,17 +684,19 @@ export class BeaconChain implements IBeaconChain {
689
684
 
690
685
  getStateByCheckpoint(
691
686
  checkpoint: CheckpointWithPayloadStatus
692
- ): {state: BeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null {
687
+ ): {state: IBeaconStateView; executionOptimistic: boolean; finalized: boolean} | null {
693
688
  // finalized or justified checkpoint states maynot be available with PersistentCheckpointStateCache, use getCheckpointStateOrBytes() api to get Uint8Array
694
689
  const checkpointHexPayload = fcCheckpointToHexPayload(checkpoint);
695
690
  const cachedStateCtx = this.regen.getCheckpointStateSync(checkpointHexPayload);
696
691
  if (cachedStateCtx) {
697
- const block = this.forkChoice.getBlockDefaultStatus(cachedStateCtx.latestBlockHeader.hashTreeRoot());
692
+ const block = this.forkChoice.getBlockDefaultStatus(
693
+ ssz.phase0.BeaconBlockHeader.hashTreeRoot(cachedStateCtx.latestBlockHeader)
694
+ );
698
695
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
699
696
  return {
700
697
  state: cachedStateCtx,
701
698
  executionOptimistic: block != null && isOptimisticBlock(block),
702
- finalized: cachedStateCtx.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
699
+ finalized: cachedStateCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
703
700
  };
704
701
  }
705
702
 
@@ -708,7 +705,7 @@ export class BeaconChain implements IBeaconChain {
708
705
 
709
706
  async getStateOrBytesByCheckpoint(
710
707
  checkpoint: CheckpointWithPayloadStatus
711
- ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
708
+ ): Promise<{state: IBeaconStateView | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
712
709
  const checkpointHexPayload = fcCheckpointToHexPayload(checkpoint);
713
710
  const cachedStateCtx = await this.regen.getCheckpointStateOrBytes(checkpointHexPayload);
714
711
  if (cachedStateCtx) {
@@ -952,14 +949,13 @@ export class BeaconChain implements IBeaconChain {
952
949
  consensusBlockValue: Wei;
953
950
  shouldOverrideBuilder?: boolean;
954
951
  }> {
955
- const fork = this.config.getForkName(slot);
956
952
  const state = await this.regen.getBlockSlotState(
957
953
  parentBlock,
958
954
  slot,
959
955
  {dontTransferCache: true},
960
956
  RegenCaller.produceBlock
961
957
  );
962
- const proposerIndex = state.epochCtx.getBeaconProposer(slot);
958
+ const proposerIndex = state.getBeaconProposer(slot);
963
959
  const proposerPubKey = this.pubkeyCache.getOrThrow(proposerIndex).toBytes();
964
960
 
965
961
  const {body, produceResult, executionPayloadValue, shouldOverrideBuilder} = await produceBlockBody.call(
@@ -981,7 +977,7 @@ export class BeaconChain implements IBeaconChain {
981
977
  // The hashtree root computed here for debug log will get cached and hence won't introduce additional delays
982
978
  const bodyRoot =
983
979
  produceResult.type === BlockType.Full
984
- ? sszTypesFor(fork).BeaconBlockBody.hashTreeRoot(body)
980
+ ? this.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(body)
985
981
  : this.config
986
982
  .getPostBellatrixForkTypes(slot)
987
983
  .BlindedBeaconBlockBody.hashTreeRoot(body as BlindedBeaconBlockBody);
@@ -1003,10 +999,11 @@ export class BeaconChain implements IBeaconChain {
1003
999
  block.stateRoot = newStateRoot;
1004
1000
  const blockRoot =
1005
1001
  produceResult.type === BlockType.Full
1006
- ? sszTypesFor(fork).BeaconBlock.hashTreeRoot(block)
1002
+ ? this.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block)
1007
1003
  : this.config.getPostBellatrixForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block as BlindedBeaconBlock);
1008
1004
  const blockRootHex = toRootHex(blockRoot);
1009
1005
 
1006
+ const fork = this.config.getForkName(slot);
1010
1007
  if (isForkPostGloas(fork)) {
1011
1008
  // TODO GLOAS: we should retire BlockType post-gloas, may need a new enum for self vs non-self built
1012
1009
  if (produceResult.type !== BlockType.Full) {
@@ -1022,7 +1019,7 @@ export class BeaconChain implements IBeaconChain {
1022
1019
  slot,
1023
1020
  stateRoot: ZERO_HASH,
1024
1021
  };
1025
- const envelopeStateRoot = computeEnvelopeStateRoot(this.metrics, postState as CachedBeaconStateGloas, envelope);
1022
+ const envelopeStateRoot = computeEnvelopeStateRoot(this.metrics, postState, envelope);
1026
1023
  gloasResult.envelopeStateRoot = envelopeStateRoot;
1027
1024
  }
1028
1025
 
@@ -1143,8 +1140,8 @@ export class BeaconChain implements IBeaconChain {
1143
1140
  * persist preState, postState and block for further investigation.
1144
1141
  */
1145
1142
  async persistInvalidStateRoot(
1146
- preState: CachedBeaconStateAllForks,
1147
- postState: CachedBeaconStateAllForks,
1143
+ preState: IBeaconStateView,
1144
+ postState: IBeaconStateView,
1148
1145
  block: SignedBeaconBlock
1149
1146
  ): Promise<void> {
1150
1147
  const blockSlot = block.message.slot;
@@ -1159,13 +1156,13 @@ export class BeaconChain implements IBeaconChain {
1159
1156
  `${logStr}_block`
1160
1157
  ),
1161
1158
  this.persistSszObject(
1162
- `preState_slot_${preState.slot}_${preState.type.typeName}`,
1159
+ `preState_slot_${preState.slot}_BeaconState`,
1163
1160
  preState.serialize(),
1164
1161
  preState.hashTreeRoot(),
1165
1162
  `${logStr}_pre_state`
1166
1163
  ),
1167
1164
  this.persistSszObject(
1168
- `postState_slot_${postState.slot}_${postState.type.typeName}`,
1165
+ `postState_slot_${postState.slot}_BeaconState`,
1169
1166
  postState.serialize(),
1170
1167
  postState.hashTreeRoot(),
1171
1168
  `${logStr}_post_state`
@@ -1185,12 +1182,6 @@ export class BeaconChain implements IBeaconChain {
1185
1182
  }
1186
1183
  }
1187
1184
 
1188
- persistInvalidSszView(view: TreeView<CompositeTypeAny>, suffix?: string): void {
1189
- if (this.opts.persistInvalidSszObjects) {
1190
- void this.persistSszObject(view.type.typeName, view.serialize(), view.hashTreeRoot(), suffix);
1191
- }
1192
- }
1193
-
1194
1185
  /**
1195
1186
  * Regenerate state for attestation verification, this does not happen with default chain option of maxSkipSlots = 32 .
1196
1187
  * However, need to handle just in case. Lodestar doesn't support multiple regen state requests for attestation verification
@@ -1208,7 +1199,7 @@ export class BeaconChain implements IBeaconChain {
1208
1199
  this.shufflingCache.insertPromise(attEpoch, shufflingDependentRoot);
1209
1200
  const blockEpoch = computeEpochAtSlot(attHeadBlock.slot);
1210
1201
 
1211
- let state: CachedBeaconStateAllForks;
1202
+ let state: IBeaconStateView;
1212
1203
  if (blockEpoch < attEpoch - 1) {
1213
1204
  // thanks to one epoch look ahead, we don't need to dial up to attEpoch
1214
1205
  const targetSlot = computeStartSlotAtEpoch(attEpoch - 1);
@@ -1226,7 +1217,7 @@ export class BeaconChain implements IBeaconChain {
1226
1217
  }
1227
1218
  // resolve the promise to unblock other calls of the same epoch and dependent root
1228
1219
  this.shufflingCache.processState(state);
1229
- return state.epochCtx.getShufflingAtEpoch(attEpoch);
1220
+ return state.getShufflingAtEpoch(attEpoch);
1230
1221
  }
1231
1222
 
1232
1223
  /**
@@ -1236,7 +1227,7 @@ export class BeaconChain implements IBeaconChain {
1236
1227
  */
1237
1228
  private justifiedBalancesGetter(
1238
1229
  checkpoint: CheckpointWithPayloadStatus,
1239
- blockState: CachedBeaconStateAllForks
1230
+ blockState: IBeaconStateView
1240
1231
  ): EffectiveBalanceIncrements {
1241
1232
  this.metrics?.balancesCache.requests.inc();
1242
1233
 
@@ -1263,7 +1254,7 @@ export class BeaconChain implements IBeaconChain {
1263
1254
  });
1264
1255
  }
1265
1256
 
1266
- return getEffectiveBalanceIncrementsZeroInactive(state);
1257
+ return state.getEffectiveBalanceIncrementsZeroInactive();
1267
1258
  }
1268
1259
 
1269
1260
  /**
@@ -1275,8 +1266,8 @@ export class BeaconChain implements IBeaconChain {
1275
1266
  */
1276
1267
  private closestJustifiedBalancesStateToCheckpoint(
1277
1268
  checkpoint: CheckpointWithPayloadStatus,
1278
- blockState: CachedBeaconStateAllForks
1279
- ): {state: CachedBeaconStateAllForks; stateId: string; shouldWarn: boolean} {
1269
+ blockState: IBeaconStateView
1270
+ ): {state: IBeaconStateView; stateId: string; shouldWarn: boolean} {
1280
1271
  const checkpointHexPayload = fcCheckpointToHexPayload(checkpoint);
1281
1272
  const state = this.regen.getCheckpointStateSync(checkpointHexPayload);
1282
1273
  if (state) {
@@ -1359,10 +1350,9 @@ export class BeaconChain implements IBeaconChain {
1359
1350
  const fork = this.config.getForkName(headState.slot);
1360
1351
 
1361
1352
  if (isForkPostElectra(fork)) {
1362
- const headStateElectra = headState as BeaconStateElectra;
1363
- metrics.pendingDeposits.set(headStateElectra.pendingDeposits.length);
1364
- metrics.pendingPartialWithdrawals.set(headStateElectra.pendingPartialWithdrawals.length);
1365
- metrics.pendingConsolidations.set(headStateElectra.pendingConsolidations.length);
1353
+ metrics.pendingDeposits.set(headState.pendingDepositsCount);
1354
+ metrics.pendingPartialWithdrawals.set(headState.pendingPartialWithdrawalsCount);
1355
+ metrics.pendingConsolidations.set(headState.pendingConsolidationsCount);
1366
1356
  }
1367
1357
  }
1368
1358
 
@@ -1426,7 +1416,7 @@ export class BeaconChain implements IBeaconChain {
1426
1416
  this.logger.verbose("Fork choice justified", {epoch: cp.epoch, root: cp.rootHex});
1427
1417
  }
1428
1418
 
1429
- private onCheckpoint(this: BeaconChain, _checkpoint: phase0.Checkpoint, state: CachedBeaconStateAllForks): void {
1419
+ private onCheckpoint(this: BeaconChain, _checkpoint: phase0.Checkpoint, state: IBeaconStateView): void {
1430
1420
  // Defer to not block other checkpoint event handlers, which can cause lightclient update delays
1431
1421
  callInNextEventLoop(() => {
1432
1422
  this.shufflingCache.processState(state);
@@ -1512,7 +1502,7 @@ export class BeaconChain implements IBeaconChain {
1512
1502
  if (stateOrBytes instanceof Uint8Array) {
1513
1503
  effectiveBalances = getEffectiveBalancesFromStateBytes(this.config, stateOrBytes, validatorIndices);
1514
1504
  } else {
1515
- effectiveBalances = validatorIndices.map((index) => stateOrBytes.validators.get(index).effectiveBalance ?? 0);
1505
+ effectiveBalances = validatorIndices.map((index) => stateOrBytes.getValidator(index).effectiveBalance ?? 0);
1516
1506
  }
1517
1507
  }
1518
1508
 
@@ -1562,11 +1552,11 @@ export class BeaconChain implements IBeaconChain {
1562
1552
  throw Error(`Pre-state is unavailable given block's parent root ${toRootHex(block.parentRoot)}`);
1563
1553
  }
1564
1554
 
1565
- preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1555
+ preState = preState.processSlots(block.slot); // Dial preState's slot to block.slot
1566
1556
 
1567
1557
  const proposerRewards = this.regen.getStateSync(toRootHex(block.stateRoot))?.proposerRewards ?? undefined;
1568
1558
 
1569
- return computeBlockRewards(this.config, block, preState, proposerRewards);
1559
+ return preState.computeBlockRewards(block, proposerRewards);
1570
1560
  }
1571
1561
 
1572
1562
  async getAttestationsRewards(
@@ -1590,7 +1580,7 @@ export class BeaconChain implements IBeaconChain {
1590
1580
  throw Error(`State is not in cache for slot ${slot}`);
1591
1581
  }
1592
1582
 
1593
- const rewards = await computeAttestationsRewards(this.config, this.pubkeyCache, cachedState, validatorIds);
1583
+ const rewards = await cachedState.computeAttestationsRewards(validatorIds);
1594
1584
 
1595
1585
  return {rewards, executionOptimistic, finalized};
1596
1586
  }
@@ -1605,8 +1595,8 @@ export class BeaconChain implements IBeaconChain {
1605
1595
  throw Error(`Pre-state is unavailable given block's parent root ${toRootHex(block.parentRoot)}`);
1606
1596
  }
1607
1597
 
1608
- preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1598
+ preState = preState.processSlots(block.slot); // Dial preState's slot to block.slot
1609
1599
 
1610
- return computeSyncCommitteeRewards(this.config, this.pubkeyCache, block, preState, validatorIds);
1600
+ return preState.computeSyncCommitteeRewards(block, validatorIds ?? []);
1611
1601
  }
1612
1602
  }
@@ -2,7 +2,7 @@ import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {routes} from "@lodestar/api";
4
4
  import {CheckpointWithPayloadStatus} from "@lodestar/fork-choice";
5
- import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
5
+ import {IBeaconStateView} from "@lodestar/state-transition";
6
6
  import {DataColumnSidecars, RootHex, deneb, phase0} from "@lodestar/types";
7
7
  import {PeerIdStr} from "../util/peerId.js";
8
8
  import {BlockInputSource, IBlockInput} from "./blocks/blockInput/types.js";
@@ -81,7 +81,7 @@ export type ChainEventData = {
81
81
  };
82
82
 
83
83
  export type IChainEvents = ApiEvents & {
84
- [ChainEvent.checkpoint]: (checkpoint: phase0.Checkpoint, state: CachedBeaconStateAllForks) => void;
84
+ [ChainEvent.checkpoint]: (checkpoint: phase0.Checkpoint, state: IBeaconStateView) => void;
85
85
 
86
86
  [ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithPayloadStatus) => void;
87
87
  [ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithPayloadStatus) => void;
@@ -1,4 +1,4 @@
1
- import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
1
+ import {IBeaconStateView} from "@lodestar/state-transition";
2
2
  import {RootHex, SignedBeaconBlock, Slot, ValidatorIndex} from "@lodestar/types";
3
3
  import {LodestarError, toRootHex} from "@lodestar/utils";
4
4
  import {ExecutionPayloadStatus} from "../../execution/engine/interface.js";
@@ -91,13 +91,13 @@ export type BlockErrorType =
91
91
  | {code: BlockErrorCode.INCORRECT_PROPOSER; proposerIndex: ValidatorIndex}
92
92
  | {code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID; blockSlot: Slot}
93
93
  | {code: BlockErrorCode.UNKNOWN_PROPOSER; proposerIndex: ValidatorIndex}
94
- | {code: BlockErrorCode.INVALID_SIGNATURE; state: CachedBeaconStateAllForks}
94
+ | {code: BlockErrorCode.INVALID_SIGNATURE; state: IBeaconStateView}
95
95
  | {
96
96
  code: BlockErrorCode.INVALID_STATE_ROOT;
97
97
  root: Uint8Array;
98
98
  expectedRoot: Uint8Array;
99
- preState: CachedBeaconStateAllForks;
100
- postState: CachedBeaconStateAllForks;
99
+ preState: IBeaconStateView;
100
+ postState: IBeaconStateView;
101
101
  }
102
102
  | {code: BlockErrorCode.NOT_FINALIZED_DESCENDANT; parentRoot: RootHex}
103
103
  | {code: BlockErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
@@ -10,18 +10,12 @@ import {
10
10
  ForkChoiceOpts as RawForkChoiceOpts,
11
11
  getCheckpointPayloadStatus,
12
12
  } from "@lodestar/fork-choice";
13
- import {ZERO_HASH_HEX} from "@lodestar/params";
13
+ import {ForkSeq, ZERO_HASH_HEX} from "@lodestar/params";
14
14
  import {
15
- CachedBeaconStateAllForks,
16
- CachedBeaconStateGloas,
17
15
  DataAvailabilityStatus,
18
- computeAnchorCheckpoint,
16
+ IBeaconStateView,
19
17
  computeEpochAtSlot,
20
18
  computeStartSlotAtEpoch,
21
- getBlockRootAtSlot,
22
- getEffectiveBalanceIncrementsZeroInactive,
23
- isExecutionStateType,
24
- isMergeTransitionComplete,
25
19
  } from "@lodestar/state-transition";
26
20
  import {Slot, ssz} from "@lodestar/types";
27
21
  import {Logger, toRootHex} from "@lodestar/utils";
@@ -46,7 +40,7 @@ export function initializeForkChoice(
46
40
  config: ChainForkConfig,
47
41
  emitter: ChainEventEmitter,
48
42
  currentSlot: Slot,
49
- state: CachedBeaconStateAllForks,
43
+ state: IBeaconStateView,
50
44
  isFinalizedState: boolean,
51
45
  opts: ForkChoiceOpts,
52
46
  justifiedBalancesGetter: JustifiedBalancesGetter,
@@ -83,13 +77,13 @@ export function initializeForkChoiceFromFinalizedState(
83
77
  config: ChainForkConfig,
84
78
  emitter: ChainEventEmitter,
85
79
  currentSlot: Slot,
86
- state: CachedBeaconStateAllForks,
80
+ state: IBeaconStateView,
87
81
  opts: ForkChoiceOpts,
88
82
  justifiedBalancesGetter: JustifiedBalancesGetter,
89
83
  metrics: Metrics | null,
90
84
  logger?: Logger
91
85
  ): ForkChoice {
92
- const {blockHeader, checkpoint} = computeAnchorCheckpoint(config, state);
86
+ const {blockHeader, checkpoint} = state.computeAnchorCheckpoint();
93
87
  const finalizedCheckpoint = {...checkpoint};
94
88
  const justifiedCheckpoint = {
95
89
  ...checkpoint,
@@ -100,19 +94,19 @@ export function initializeForkChoiceFromFinalizedState(
100
94
  epoch: checkpoint.epoch === 0 ? checkpoint.epoch : checkpoint.epoch + 1,
101
95
  };
102
96
 
103
- const justifiedBalances = getEffectiveBalanceIncrementsZeroInactive(state);
97
+ const justifiedBalances = state.getEffectiveBalanceIncrementsZeroInactive();
104
98
 
105
99
  // forkchoiceConstructor is only used for some test cases
106
100
  // production code use ForkChoice constructor directly
107
101
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
108
102
 
109
- const isForkPostGloas = (state as CachedBeaconStateGloas).latestBlockHash !== undefined;
103
+ const isForkPostGloas = computeEpochAtSlot(state.slot) >= config.GLOAS_FORK_EPOCH;
110
104
 
111
105
  // Determine justified checkpoint payload status
112
- const justifiedPayloadStatus = getCheckpointPayloadStatus(state, justifiedCheckpoint.epoch);
106
+ const justifiedPayloadStatus = getCheckpointPayloadStatus(config, state, justifiedCheckpoint.epoch);
113
107
 
114
108
  // Determine finalized checkpoint payload status
115
- const finalizedPayloadStatus = getCheckpointPayloadStatus(state, finalizedCheckpoint.epoch);
109
+ const finalizedPayloadStatus = getCheckpointPayloadStatus(config, state, finalizedCheckpoint.epoch);
116
110
 
117
111
  return new forkchoiceConstructor(
118
112
  config,
@@ -148,21 +142,23 @@ export function initializeForkChoiceFromFinalizedState(
148
142
  unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
149
143
  unrealizedFinalizedRoot: toRootHex(finalizedCheckpoint.root),
150
144
 
151
- ...(isExecutionStateType(state) && isMergeTransitionComplete(state)
145
+ ...(state.isExecutionStateType && state.isMergeTransitionComplete
152
146
  ? {
153
- executionPayloadBlockHash: toRootHex(state.latestExecutionPayloadHeader.blockHash),
154
- executionPayloadNumber: state.latestExecutionPayloadHeader.blockNumber,
147
+ executionPayloadBlockHash: toRootHex(state.latestBlockHash),
148
+ // TODO GLOAS: executionPayloadNumber is not tracked in BeaconState post-gloas (EIP-7732 removed
149
+ // latestExecutionPayloadHeader). Using 0 as unavailable fallback until a solution is found.
150
+ executionPayloadNumber: config.getForkSeq(state.slot) >= ForkSeq.gloas ? 0 : state.payloadBlockNumber,
155
151
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
156
152
  }
157
153
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
158
154
 
159
155
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
160
156
  payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL, // TODO GLOAS: Post-gloas how do we know if the checkpoint payload is FULL or EMPTY?
161
- parentBlockHash: isForkPostGloas ? toRootHex((state as CachedBeaconStateGloas).latestBlockHash) : null,
157
+ parentBlockHash: isForkPostGloas ? toRootHex(state.latestBlockHash) : null,
162
158
  },
163
159
  currentSlot
164
160
  ),
165
- state.validators.length,
161
+ state.validatorCount,
166
162
  metrics,
167
163
  opts,
168
164
  logger
@@ -176,15 +172,15 @@ export function initializeForkChoiceFromUnfinalizedState(
176
172
  config: ChainForkConfig,
177
173
  emitter: ChainEventEmitter,
178
174
  currentSlot: Slot,
179
- unfinalizedState: CachedBeaconStateAllForks,
175
+ unfinalizedState: IBeaconStateView,
180
176
  opts: ForkChoiceOpts,
181
177
  justifiedBalancesGetter: JustifiedBalancesGetter,
182
178
  metrics: Metrics | null,
183
179
  logger?: Logger
184
180
  ): ForkChoice {
185
- const {blockHeader} = computeAnchorCheckpoint(config, unfinalizedState);
186
- const finalizedCheckpoint = unfinalizedState.finalizedCheckpoint.toValue();
187
- const justifiedCheckpoint = unfinalizedState.currentJustifiedCheckpoint.toValue();
181
+ const {blockHeader} = unfinalizedState.computeAnchorCheckpoint();
182
+ const finalizedCheckpoint = unfinalizedState.finalizedCheckpoint;
183
+ const justifiedCheckpoint = unfinalizedState.currentJustifiedCheckpoint;
188
184
  const headRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader));
189
185
 
190
186
  const logCtx = {
@@ -200,14 +196,14 @@ export function initializeForkChoiceFromUnfinalizedState(
200
196
  logger?.warn("Initializing fork choice from unfinalized state", logCtx);
201
197
 
202
198
  // this is not the justified state, but there is no other ways to get justified balances
203
- const justifiedBalances = getEffectiveBalanceIncrementsZeroInactive(unfinalizedState);
199
+ const justifiedBalances = unfinalizedState.getEffectiveBalanceIncrementsZeroInactive();
204
200
 
205
- const isForkPostGloas = (unfinalizedState as CachedBeaconStateGloas).latestBlockHash !== undefined;
201
+ const isForkPostGloas = computeEpochAtSlot(unfinalizedState.slot) >= config.GLOAS_FORK_EPOCH;
206
202
 
207
203
  // For unfinalized state, use getCheckpointPayloadStatus to determine the correct status.
208
204
  // It checks state.execution_payload_availability to determine EMPTY vs FULL.
209
- const justifiedPayloadStatus = getCheckpointPayloadStatus(unfinalizedState, justifiedCheckpoint.epoch);
210
- const finalizedPayloadStatus = getCheckpointPayloadStatus(unfinalizedState, finalizedCheckpoint.epoch);
205
+ const justifiedPayloadStatus = getCheckpointPayloadStatus(config, unfinalizedState, justifiedCheckpoint.epoch);
206
+ const finalizedPayloadStatus = getCheckpointPayloadStatus(config, unfinalizedState, finalizedCheckpoint.epoch);
211
207
 
212
208
  const store = new ForkChoiceStore(
213
209
  currentSlot,
@@ -241,17 +237,20 @@ export function initializeForkChoiceFromUnfinalizedState(
241
237
  unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
242
238
  unrealizedFinalizedRoot: toRootHex(finalizedCheckpoint.root),
243
239
 
244
- ...(isExecutionStateType(unfinalizedState) && isMergeTransitionComplete(unfinalizedState)
240
+ ...(unfinalizedState.isExecutionStateType && unfinalizedState.isMergeTransitionComplete
245
241
  ? {
246
- executionPayloadBlockHash: toRootHex(unfinalizedState.latestExecutionPayloadHeader.blockHash),
247
- executionPayloadNumber: unfinalizedState.latestExecutionPayloadHeader.blockNumber,
242
+ executionPayloadBlockHash: toRootHex(unfinalizedState.latestBlockHash),
243
+ // TODO GLOAS: executionPayloadNumber is not tracked in BeaconState post-gloas (EIP-7732 removed
244
+ // latestExecutionPayloadHeader). Using 0 as unavailable fallback until a solution is found.
245
+ executionPayloadNumber:
246
+ config.getForkSeq(unfinalizedState.slot) >= ForkSeq.gloas ? 0 : unfinalizedState.payloadBlockNumber,
248
247
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
249
248
  }
250
249
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
251
250
 
252
251
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
253
252
  payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL, // TODO GLOAS: Post-gloas how do we know if the checkpoint payload is FULL or EMPTY?
254
- parentBlockHash: isForkPostGloas ? toRootHex((unfinalizedState as CachedBeaconStateGloas).latestBlockHash) : null,
253
+ parentBlockHash: isForkPostGloas ? toRootHex(unfinalizedState.latestBlockHash) : null,
255
254
  };
256
255
 
257
256
  const parentSlot = blockHeader.slot - 1;
@@ -265,7 +264,7 @@ export function initializeForkChoiceFromUnfinalizedState(
265
264
  // dummy data, we're not able to regen state before headBlock
266
265
  stateRoot: ZERO_HASH_HEX,
267
266
  blockRoot: headBlock.parentRoot,
268
- targetRoot: toRootHex(getBlockRootAtSlot(unfinalizedState, computeStartSlotAtEpoch(parentEpoch))),
267
+ targetRoot: toRootHex(unfinalizedState.getBlockRootAtSlot(computeStartSlotAtEpoch(parentEpoch))),
269
268
  };
270
269
 
271
270
  const justifiedBlock: ProtoBlock = {
@@ -303,13 +302,5 @@ export function initializeForkChoiceFromUnfinalizedState(
303
302
  // production code use ForkChoice constructor directly
304
303
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
305
304
 
306
- return new forkchoiceConstructor(
307
- config,
308
- store,
309
- protoArray,
310
- unfinalizedState.validators.length,
311
- metrics,
312
- opts,
313
- logger
314
- );
305
+ return new forkchoiceConstructor(config, store, protoArray, unfinalizedState.validatorCount, metrics, opts, logger);
315
306
  }
@@ -1,6 +1,11 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
2
  import {ZERO_HASH} from "@lodestar/params";
3
- import {BeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
3
+ import {
4
+ BeaconStateAllForks,
5
+ IBeaconStateView,
6
+ computeEpochAtSlot,
7
+ computeStartSlotAtEpoch,
8
+ } from "@lodestar/state-transition";
4
9
  import {SignedBeaconBlock, ssz} from "@lodestar/types";
5
10
  import {Logger, byteArrayEquals, toHex, toRootHex} from "@lodestar/utils";
6
11
  import {GENESIS_SLOT} from "../constants/index.js";
@@ -119,7 +124,7 @@ export async function checkAndPersistAnchorState(
119
124
  }
120
125
  }
121
126
 
122
- export function initBeaconMetrics(metrics: Metrics, state: BeaconStateAllForks): void {
127
+ export function initBeaconMetrics(metrics: Metrics, state: IBeaconStateView): void {
123
128
  metrics.headSlot.set(state.slot);
124
129
  metrics.previousJustifiedEpoch.set(state.previousJustifiedCheckpoint.epoch);
125
130
  metrics.currentJustifiedEpoch.set(state.currentJustifiedCheckpoint.epoch);