@lodestar/state-transition 1.41.0-dev.702f7932c2 → 1.41.0-dev.8578102bd2

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 (309) hide show
  1. package/lib/block/externalData.d.ts +2 -1
  2. package/lib/block/externalData.d.ts.map +1 -1
  3. package/lib/block/externalData.js +6 -2
  4. package/lib/block/externalData.js.map +1 -1
  5. package/lib/block/index.d.ts +3 -3
  6. package/lib/block/index.js.map +1 -1
  7. package/lib/block/initiateValidatorExit.js.map +1 -1
  8. package/lib/block/isValidIndexedAttestation.d.ts +3 -3
  9. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  10. package/lib/block/isValidIndexedAttestation.js +4 -4
  11. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  12. package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
  13. package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
  14. package/lib/block/processAttestationPhase0.js +1 -1
  15. package/lib/block/processAttestationPhase0.js.map +1 -1
  16. package/lib/block/processAttestations.js.map +1 -1
  17. package/lib/block/processAttestationsAltair.js +1 -1
  18. package/lib/block/processAttestationsAltair.js.map +1 -1
  19. package/lib/block/processAttesterSlashing.d.ts +2 -2
  20. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  21. package/lib/block/processAttesterSlashing.js +3 -3
  22. package/lib/block/processAttesterSlashing.js.map +1 -1
  23. package/lib/block/processBlobKzgCommitments.js.map +1 -1
  24. package/lib/block/processBlockHeader.js.map +1 -1
  25. package/lib/block/processBlsToExecutionChange.js.map +1 -1
  26. package/lib/block/processConsolidationRequest.js.map +1 -1
  27. package/lib/block/processDeposit.js.map +1 -1
  28. package/lib/block/processDepositRequest.d.ts +1 -1
  29. package/lib/block/processDepositRequest.d.ts.map +1 -1
  30. package/lib/block/processDepositRequest.js +6 -5
  31. package/lib/block/processDepositRequest.js.map +1 -1
  32. package/lib/block/processEth1Data.js.map +1 -1
  33. package/lib/block/processExecutionPayload.js.map +1 -1
  34. package/lib/block/processExecutionPayloadBid.d.ts +1 -1
  35. package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
  36. package/lib/block/processExecutionPayloadBid.js +5 -0
  37. package/lib/block/processExecutionPayloadBid.js.map +1 -1
  38. package/lib/block/processExecutionPayloadEnvelope.d.ts +5 -2
  39. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
  40. package/lib/block/processExecutionPayloadEnvelope.js +25 -24
  41. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
  42. package/lib/block/processOperations.js.map +1 -1
  43. package/lib/block/processPayloadAttestation.d.ts +1 -1
  44. package/lib/block/processPayloadAttestation.js.map +1 -1
  45. package/lib/block/processProposerSlashing.d.ts +2 -2
  46. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  47. package/lib/block/processProposerSlashing.js +3 -3
  48. package/lib/block/processProposerSlashing.js.map +1 -1
  49. package/lib/block/processRandao.js +1 -1
  50. package/lib/block/processRandao.js.map +1 -1
  51. package/lib/block/processSyncCommittee.js +1 -1
  52. package/lib/block/processSyncCommittee.js.map +1 -1
  53. package/lib/block/processVoluntaryExit.js +3 -2
  54. package/lib/block/processVoluntaryExit.js.map +1 -1
  55. package/lib/block/processWithdrawalRequest.js +2 -2
  56. package/lib/block/processWithdrawalRequest.js.map +1 -1
  57. package/lib/block/processWithdrawals.d.ts.map +1 -1
  58. package/lib/block/processWithdrawals.js +9 -1
  59. package/lib/block/processWithdrawals.js.map +1 -1
  60. package/lib/block/slashValidator.js.map +1 -1
  61. package/lib/block/types.js +2 -1
  62. package/lib/block/types.js.map +1 -1
  63. package/lib/cache/effectiveBalanceIncrements.js.map +1 -1
  64. package/lib/cache/epochCache.d.ts +11 -18
  65. package/lib/cache/epochCache.d.ts.map +1 -1
  66. package/lib/cache/epochCache.js +43 -41
  67. package/lib/cache/epochCache.js.map +1 -1
  68. package/lib/cache/epochTransitionCache.js.map +1 -1
  69. package/lib/cache/pubkeyCache.d.ts +21 -6
  70. package/lib/cache/pubkeyCache.d.ts.map +1 -1
  71. package/lib/cache/pubkeyCache.js +39 -14
  72. package/lib/cache/pubkeyCache.js.map +1 -1
  73. package/lib/cache/rewardCache.js.map +1 -1
  74. package/lib/cache/stateCache.d.ts +1 -1
  75. package/lib/cache/stateCache.d.ts.map +1 -1
  76. package/lib/cache/stateCache.js +3 -7
  77. package/lib/cache/stateCache.js.map +1 -1
  78. package/lib/cache/syncCommitteeCache.d.ts +3 -2
  79. package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
  80. package/lib/cache/syncCommitteeCache.js +4 -4
  81. package/lib/cache/syncCommitteeCache.js.map +1 -1
  82. package/lib/epoch/computeUnrealizedCheckpoints.js.map +1 -1
  83. package/lib/epoch/getAttestationDeltas.js.map +1 -1
  84. package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
  85. package/lib/epoch/index.d.ts +1 -1
  86. package/lib/epoch/index.js +2 -1
  87. package/lib/epoch/index.js.map +1 -1
  88. package/lib/epoch/processBuilderPendingPayments.d.ts +1 -1
  89. package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
  90. package/lib/epoch/processEffectiveBalanceUpdates.js.map +1 -1
  91. package/lib/epoch/processEth1DataReset.js.map +1 -1
  92. package/lib/epoch/processHistoricalRootsUpdate.js.map +1 -1
  93. package/lib/epoch/processHistoricalSummariesUpdate.js.map +1 -1
  94. package/lib/epoch/processInactivityUpdates.js.map +1 -1
  95. package/lib/epoch/processJustificationAndFinalization.js.map +1 -1
  96. package/lib/epoch/processParticipationFlagUpdates.js.map +1 -1
  97. package/lib/epoch/processParticipationRecordUpdates.js.map +1 -1
  98. package/lib/epoch/processPendingAttestations.js.map +1 -1
  99. package/lib/epoch/processPendingConsolidations.js.map +1 -1
  100. package/lib/epoch/processPendingDeposits.js.map +1 -1
  101. package/lib/epoch/processProposerLookahead.js.map +1 -1
  102. package/lib/epoch/processRandaoMixesReset.js.map +1 -1
  103. package/lib/epoch/processRegistryUpdates.js.map +1 -1
  104. package/lib/epoch/processRewardsAndPenalties.js.map +1 -1
  105. package/lib/epoch/processSlashings.js.map +1 -1
  106. package/lib/epoch/processSlashingsReset.js.map +1 -1
  107. package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
  108. package/lib/index.d.ts +3 -1
  109. package/lib/index.d.ts.map +1 -1
  110. package/lib/index.js +2 -1
  111. package/lib/index.js.map +1 -1
  112. package/lib/lightClient/proofs.d.ts +10 -0
  113. package/lib/lightClient/proofs.d.ts.map +1 -0
  114. package/lib/lightClient/proofs.js +63 -0
  115. package/lib/lightClient/proofs.js.map +1 -0
  116. package/lib/lightClient/types.d.ts +34 -0
  117. package/lib/lightClient/types.d.ts.map +1 -0
  118. package/lib/lightClient/types.js +2 -0
  119. package/lib/lightClient/types.js.map +1 -0
  120. package/lib/metrics.d.ts.map +1 -1
  121. package/lib/metrics.js.map +1 -1
  122. package/lib/rewards/attestationsRewards.d.ts +2 -2
  123. package/lib/rewards/attestationsRewards.d.ts.map +1 -1
  124. package/lib/rewards/attestationsRewards.js +4 -4
  125. package/lib/rewards/attestationsRewards.js.map +1 -1
  126. package/lib/rewards/blockRewards.js.map +1 -1
  127. package/lib/rewards/syncCommitteeRewards.d.ts +2 -2
  128. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
  129. package/lib/rewards/syncCommitteeRewards.js +5 -2
  130. package/lib/rewards/syncCommitteeRewards.js.map +1 -1
  131. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  132. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  133. package/lib/signatureSets/executionPayloadBid.js.map +1 -1
  134. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
  135. package/lib/signatureSets/index.js.map +1 -1
  136. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  137. package/lib/signatureSets/indexedPayloadAttestation.d.ts +3 -4
  138. package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
  139. package/lib/signatureSets/indexedPayloadAttestation.js +4 -4
  140. package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
  141. package/lib/signatureSets/proposer.d.ts +2 -2
  142. package/lib/signatureSets/proposer.d.ts.map +1 -1
  143. package/lib/signatureSets/proposer.js +2 -2
  144. package/lib/signatureSets/proposer.js.map +1 -1
  145. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  146. package/lib/signatureSets/randao.d.ts +2 -2
  147. package/lib/signatureSets/randao.d.ts.map +1 -1
  148. package/lib/signatureSets/randao.js +2 -2
  149. package/lib/signatureSets/randao.js.map +1 -1
  150. package/lib/signatureSets/voluntaryExits.d.ts +2 -2
  151. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  152. package/lib/signatureSets/voluntaryExits.js +2 -2
  153. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  154. package/lib/slot/index.js.map +1 -1
  155. package/lib/slot/upgradeStateToAltair.js.map +1 -1
  156. package/lib/slot/upgradeStateToBellatrix.js.map +1 -1
  157. package/lib/slot/upgradeStateToCapella.js.map +1 -1
  158. package/lib/slot/upgradeStateToDeneb.js.map +1 -1
  159. package/lib/slot/upgradeStateToElectra.js.map +1 -1
  160. package/lib/slot/upgradeStateToFulu.js.map +1 -1
  161. package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
  162. package/lib/slot/upgradeStateToGloas.js +50 -0
  163. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  164. package/lib/stateTransition.d.ts +2 -1
  165. package/lib/stateTransition.d.ts.map +1 -1
  166. package/lib/stateTransition.js +6 -3
  167. package/lib/stateTransition.js.map +1 -1
  168. package/lib/stateView/beaconStateView.d.ts +144 -0
  169. package/lib/stateView/beaconStateView.d.ts.map +1 -0
  170. package/lib/stateView/beaconStateView.js +496 -0
  171. package/lib/stateView/beaconStateView.js.map +1 -0
  172. package/lib/stateView/index.d.ts +3 -0
  173. package/lib/stateView/index.d.ts.map +1 -0
  174. package/lib/stateView/index.js +3 -0
  175. package/lib/stateView/index.js.map +1 -0
  176. package/lib/stateView/interface.d.ts +118 -0
  177. package/lib/stateView/interface.d.ts.map +1 -0
  178. package/lib/stateView/interface.js +2 -0
  179. package/lib/stateView/interface.js.map +1 -0
  180. package/lib/testUtils/cache.d.ts +2 -0
  181. package/lib/testUtils/cache.d.ts.map +1 -0
  182. package/lib/testUtils/cache.js +7 -0
  183. package/lib/testUtils/cache.js.map +1 -0
  184. package/lib/testUtils/index.d.ts +6 -0
  185. package/lib/testUtils/index.d.ts.map +1 -0
  186. package/lib/testUtils/index.js +6 -0
  187. package/lib/testUtils/index.js.map +1 -0
  188. package/lib/testUtils/infura.d.ts +3 -0
  189. package/lib/testUtils/infura.d.ts.map +1 -0
  190. package/lib/testUtils/infura.js +8 -0
  191. package/lib/testUtils/infura.js.map +1 -0
  192. package/lib/testUtils/interop.d.ts +2 -0
  193. package/lib/testUtils/interop.d.ts.map +1 -0
  194. package/lib/testUtils/interop.js +24 -0
  195. package/lib/testUtils/interop.js.map +1 -0
  196. package/lib/testUtils/params.d.ts +18 -0
  197. package/lib/testUtils/params.d.ts.map +1 -0
  198. package/lib/testUtils/params.js +20 -0
  199. package/lib/testUtils/params.js.map +1 -0
  200. package/lib/testUtils/state.d.ts +20 -0
  201. package/lib/testUtils/state.d.ts.map +1 -0
  202. package/lib/testUtils/state.js +78 -0
  203. package/lib/testUtils/state.js.map +1 -0
  204. package/lib/testUtils/testFileCache.d.ts +17 -0
  205. package/lib/testUtils/testFileCache.d.ts.map +1 -0
  206. package/lib/testUtils/testFileCache.js +96 -0
  207. package/lib/testUtils/testFileCache.js.map +1 -0
  208. package/lib/testUtils/util.d.ts +50 -0
  209. package/lib/testUtils/util.d.ts.map +1 -0
  210. package/lib/testUtils/util.js +329 -0
  211. package/lib/testUtils/util.js.map +1 -0
  212. package/lib/util/aggregator.js.map +1 -1
  213. package/lib/util/altair.js.map +1 -1
  214. package/lib/util/array.js.map +1 -1
  215. package/lib/util/attestation.js.map +1 -1
  216. package/lib/util/attesterStatus.js.map +1 -1
  217. package/lib/util/balance.js.map +1 -1
  218. package/lib/util/blindedBlock.js.map +1 -1
  219. package/lib/util/blockRoot.js.map +1 -1
  220. package/lib/util/capella.js.map +1 -1
  221. package/lib/util/computeAnchorCheckpoint.js.map +1 -1
  222. package/lib/util/deposit.js.map +1 -1
  223. package/lib/util/domain.js.map +1 -1
  224. package/lib/util/electra.js.map +1 -1
  225. package/lib/util/epoch.js.map +1 -1
  226. package/lib/util/epochShuffling.js.map +1 -1
  227. package/lib/util/execution.js.map +1 -1
  228. package/lib/util/finality.js.map +1 -1
  229. package/lib/util/fulu.js.map +1 -1
  230. package/lib/util/genesis.js.map +1 -1
  231. package/lib/util/gloas.d.ts.map +1 -1
  232. package/lib/util/gloas.js +10 -3
  233. package/lib/util/gloas.js.map +1 -1
  234. package/lib/util/interop.js.map +1 -1
  235. package/lib/util/loadState/findModifiedInactivityScores.js.map +1 -1
  236. package/lib/util/loadState/findModifiedValidators.js.map +1 -1
  237. package/lib/util/loadState/loadState.js.map +1 -1
  238. package/lib/util/loadState/loadValidator.js.map +1 -1
  239. package/lib/util/rootCache.d.ts.map +1 -1
  240. package/lib/util/rootCache.js.map +1 -1
  241. package/lib/util/seed.d.ts +20 -12
  242. package/lib/util/seed.d.ts.map +1 -1
  243. package/lib/util/seed.js +80 -72
  244. package/lib/util/seed.js.map +1 -1
  245. package/lib/util/shuffling.js +2 -1
  246. package/lib/util/shuffling.js.map +1 -1
  247. package/lib/util/signatureSets.d.ts +7 -7
  248. package/lib/util/signatureSets.d.ts.map +1 -1
  249. package/lib/util/signatureSets.js +20 -13
  250. package/lib/util/signatureSets.js.map +1 -1
  251. package/lib/util/signingRoot.js.map +1 -1
  252. package/lib/util/slot.js.map +1 -1
  253. package/lib/util/sszBytes.js.map +1 -1
  254. package/lib/util/syncCommittee.js.map +1 -1
  255. package/lib/util/targetUnslashedBalance.js.map +1 -1
  256. package/lib/util/validator.js.map +1 -1
  257. package/lib/util/weakSubjectivity.js +1 -1
  258. package/lib/util/weakSubjectivity.js.map +1 -1
  259. package/package.json +14 -9
  260. package/src/block/externalData.ts +2 -0
  261. package/src/block/index.ts +3 -3
  262. package/src/block/isValidIndexedAttestation.ts +5 -5
  263. package/src/block/isValidIndexedPayloadAttestation.ts +4 -4
  264. package/src/block/processAttestationPhase0.ts +1 -1
  265. package/src/block/processAttestationsAltair.ts +2 -2
  266. package/src/block/processAttesterSlashing.ts +4 -4
  267. package/src/block/processDepositRequest.ts +8 -5
  268. package/src/block/processExecutionPayloadBid.ts +12 -4
  269. package/src/block/processExecutionPayloadEnvelope.ts +40 -37
  270. package/src/block/processOperations.ts +1 -1
  271. package/src/block/processPayloadAttestation.ts +2 -2
  272. package/src/block/processProposerSlashing.ts +4 -4
  273. package/src/block/processRandao.ts +1 -1
  274. package/src/block/processSyncCommittee.ts +1 -1
  275. package/src/block/processVoluntaryExit.ts +1 -1
  276. package/src/block/processWithdrawalRequest.ts +2 -2
  277. package/src/block/processWithdrawals.ts +11 -2
  278. package/src/cache/epochCache.ts +62 -54
  279. package/src/cache/pubkeyCache.ts +62 -21
  280. package/src/cache/stateCache.ts +4 -8
  281. package/src/cache/syncCommitteeCache.ts +4 -5
  282. package/src/epoch/index.ts +1 -1
  283. package/src/epoch/processBuilderPendingPayments.ts +2 -2
  284. package/src/index.ts +3 -1
  285. package/src/lightClient/proofs.ts +83 -0
  286. package/src/lightClient/types.ts +33 -0
  287. package/src/rewards/attestationsRewards.ts +5 -5
  288. package/src/rewards/syncCommitteeRewards.ts +6 -5
  289. package/src/signatureSets/indexedPayloadAttestation.ts +4 -6
  290. package/src/signatureSets/proposer.ts +3 -3
  291. package/src/signatureSets/randao.ts +3 -7
  292. package/src/signatureSets/voluntaryExits.ts +3 -3
  293. package/src/slot/upgradeStateToGloas.ts +74 -0
  294. package/src/stateTransition.ts +2 -1
  295. package/src/stateView/beaconStateView.ts +744 -0
  296. package/src/stateView/index.ts +2 -0
  297. package/src/stateView/interface.ts +196 -0
  298. package/src/testUtils/cache.ts +8 -0
  299. package/src/testUtils/index.ts +5 -0
  300. package/src/testUtils/infura.ts +10 -0
  301. package/src/testUtils/interop.ts +29 -0
  302. package/src/testUtils/params.ts +23 -0
  303. package/src/testUtils/state.ts +110 -0
  304. package/src/testUtils/testFileCache.ts +127 -0
  305. package/src/testUtils/util.ts +429 -0
  306. package/src/util/gloas.ts +11 -3
  307. package/src/util/seed.ts +106 -89
  308. package/src/util/signatureSets.ts +23 -17
  309. package/src/util/weakSubjectivity.ts +1 -1
@@ -0,0 +1,2 @@
1
+ export * from "./beaconStateView.js";
2
+ export * from "./interface.js";
@@ -0,0 +1,196 @@
1
+ import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
2
+ import {ByteViews} from "@chainsafe/ssz";
3
+ import {
4
+ BeaconBlock,
5
+ BlindedBeaconBlock,
6
+ BuilderIndex,
7
+ Bytes32,
8
+ Epoch,
9
+ ExecutionPayloadBid,
10
+ ExecutionPayloadHeader,
11
+ Root,
12
+ RootHex,
13
+ SignedBeaconBlock,
14
+ SignedBlindedBeaconBlock,
15
+ Slot,
16
+ ValidatorIndex,
17
+ altair,
18
+ capella,
19
+ electra,
20
+ fulu,
21
+ gloas,
22
+ phase0,
23
+ rewards,
24
+ } from "@lodestar/types";
25
+ import {Checkpoint, Fork} from "@lodestar/types/phase0";
26
+ import {VoluntaryExitValidity} from "../block/processVoluntaryExit.js";
27
+ import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
28
+ import {EpochTransitionCacheOpts} from "../cache/epochTransitionCache.js";
29
+ import {RewardCache} from "../cache/rewardCache.js";
30
+ import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
31
+ import {SyncCommitteeWitness} from "../lightClient/types.js";
32
+ import {StateTransitionModules, StateTransitionOpts} from "../stateTransition.js";
33
+ import {EpochShuffling} from "../util/epochShuffling.js";
34
+
35
+ /**
36
+ * A read-only view of the BeaconState.
37
+ */
38
+ export interface IBeaconStateView {
39
+ // State access
40
+
41
+ // phase0
42
+ slot: Slot;
43
+ fork: Fork;
44
+ epoch: Epoch;
45
+ genesisTime: number;
46
+ genesisValidatorsRoot: Root;
47
+ eth1Data: phase0.Eth1Data;
48
+ latestBlockHeader: phase0.BeaconBlockHeader;
49
+ previousJustifiedCheckpoint: Checkpoint;
50
+ currentJustifiedCheckpoint: Checkpoint;
51
+ finalizedCheckpoint: Checkpoint;
52
+ getBlockRootAtSlot(slot: Slot): Root;
53
+ getBlockRootAtEpoch(epoch: Epoch): Root;
54
+ getStateRootAtSlot(slot: Slot): Root;
55
+ getRandaoMix(epoch: Epoch): Bytes32;
56
+
57
+ // altair
58
+ previousEpochParticipation: number[];
59
+ currentEpochParticipation: number[];
60
+
61
+ // bellatrix
62
+ latestExecutionPayloadHeader: ExecutionPayloadHeader;
63
+
64
+ // capella
65
+ historicalSummaries: capella.HistoricalSummaries;
66
+
67
+ // electra
68
+ pendingDeposits: electra.PendingDeposits;
69
+ pendingDepositsCount: number;
70
+ pendingPartialWithdrawals: electra.PendingPartialWithdrawals;
71
+ pendingPartialWithdrawalsCount: number;
72
+ pendingConsolidations: electra.PendingConsolidations;
73
+ pendingConsolidationsCount: number;
74
+
75
+ // fulu
76
+ proposerLookahead: fulu.ProposerLookahead;
77
+
78
+ // gloas
79
+ executionPayloadAvailability: boolean[];
80
+ latestExecutionPayloadBid: ExecutionPayloadBid;
81
+ getBuilder(index: BuilderIndex): gloas.Builder;
82
+ canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
83
+ validatorPTCCommitteeIndex(validatorIndex: ValidatorIndex, slot: Slot): number;
84
+
85
+ // Shuffling and committees
86
+ getShufflingAtEpoch(epoch: Epoch): EpochShuffling;
87
+ // Decision roots
88
+ previousDecisionRoot: RootHex;
89
+ currentDecisionRoot: RootHex;
90
+ nextDecisionRoot: RootHex;
91
+ getShufflingDecisionRoot(epoch: Epoch): RootHex;
92
+ getPreviousShuffling(): EpochShuffling;
93
+ getCurrentShuffling(): EpochShuffling;
94
+ getNextShuffling(): EpochShuffling;
95
+
96
+ // utils: proposers, anchor checkpoint
97
+ previousProposers: ValidatorIndex[] | null;
98
+ currentProposers: ValidatorIndex[];
99
+ nextProposers: ValidatorIndex[];
100
+ getBeaconProposer(slot: Slot): ValidatorIndex;
101
+ computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader};
102
+
103
+ // Sync committees
104
+ currentSyncCommittee: altair.SyncCommittee;
105
+ nextSyncCommittee: altair.SyncCommittee;
106
+ currentSyncCommitteeIndexed: SyncCommitteeCache;
107
+ syncProposerReward: number;
108
+ getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
109
+
110
+ // Validators and balances
111
+ effectiveBalanceIncrements: EffectiveBalanceIncrements;
112
+ getEffectiveBalanceIncrementsZeroInactive(): EffectiveBalanceIncrements;
113
+ getBalance(index: number): number;
114
+ // readonly
115
+ getValidator(index: ValidatorIndex): phase0.Validator;
116
+ getValidatorsByStatus(statuses: Set<string>, currentEpoch: Epoch): phase0.Validator[];
117
+ validatorCount: number;
118
+ // this get number of active validators in the current shuffling
119
+ activeValidatorCount: number;
120
+ // this is needed for apis only
121
+ getAllValidators(): phase0.Validator[];
122
+ getAllBalances(): number[];
123
+
124
+ // Merge
125
+ isExecutionStateType: boolean;
126
+ isMergeTransitionComplete: boolean;
127
+ // TODO this should go away (or rather only need block)
128
+ isExecutionEnabled(block: BeaconBlock | BlindedBeaconBlock): boolean;
129
+
130
+ // Block production
131
+ getExpectedWithdrawals(): {
132
+ expectedWithdrawals: capella.Withdrawal[];
133
+ processedBuilderWithdrawalsCount: number;
134
+ processedPartialWithdrawalsCount: number;
135
+ processedValidatorSweepCount: number;
136
+ };
137
+
138
+ // API
139
+ proposerRewards: RewardCache;
140
+ computeBlockRewards(block: BeaconBlock, proposerRewards?: RewardCache): Promise<rewards.BlockRewards>;
141
+ computeAttestationsRewards(validatorIds?: (ValidatorIndex | string)[]): Promise<rewards.AttestationsRewards>;
142
+ computeSyncCommitteeRewards(
143
+ block: BeaconBlock,
144
+ validatorIds: (ValidatorIndex | string)[]
145
+ ): Promise<rewards.SyncCommitteeRewards>;
146
+ getLatestWeakSubjectivityCheckpointEpoch(): Epoch;
147
+
148
+ // Validation
149
+ getVoluntaryExitValidity(
150
+ signedVoluntaryExit: phase0.SignedVoluntaryExit,
151
+ verifySignature: boolean
152
+ ): VoluntaryExitValidity;
153
+ isValidVoluntaryExit(signedVoluntaryExit: phase0.SignedVoluntaryExit, verifySignature: boolean): boolean;
154
+
155
+ // Proofs
156
+ getFinalizedRootProof(): Uint8Array[];
157
+ getSyncCommitteesWitness(): SyncCommitteeWitness;
158
+ getSingleProof(gindex: bigint): Uint8Array[];
159
+ createMultiProof(descriptor: Uint8Array): CompactMultiProof;
160
+
161
+ // Fork choice
162
+ computeUnrealizedCheckpoints(): {
163
+ justifiedCheckpoint: phase0.Checkpoint;
164
+ finalizedCheckpoint: phase0.Checkpoint;
165
+ };
166
+
167
+ // this is for backward compatible
168
+ clonedCount: number;
169
+ clonedCountWithTransferCache: number;
170
+ createdWithTransferCache: boolean;
171
+ // TODO is there a better name that is less implementation specific but still conveys the meaning?
172
+ isStateValidatorsNodesPopulated(): boolean;
173
+
174
+ // Serialization
175
+ loadOtherState(stateBytes: Uint8Array, seedValidatorsBytes?: Uint8Array): IBeaconStateView;
176
+ serialize(): Uint8Array;
177
+ serializedSize(): number;
178
+ serializeToBytes(output: ByteViews, offset: number): number;
179
+ serializeValidators(): Uint8Array;
180
+ serializedValidatorsSize(): number;
181
+ serializeValidatorsToBytes(output: ByteViews, offset: number): number;
182
+
183
+ hashTreeRoot(): Uint8Array;
184
+
185
+ // State transition
186
+ stateTransition(
187
+ signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock,
188
+ options: StateTransitionOpts,
189
+ modules: StateTransitionModules
190
+ ): IBeaconStateView;
191
+ processSlots(
192
+ slot: Slot,
193
+ epochTransitionCacheOpts?: EpochTransitionCacheOpts & {dontTransferCache?: boolean},
194
+ modules?: StateTransitionModules
195
+ ): IBeaconStateView;
196
+ }
@@ -0,0 +1,8 @@
1
+ import path from "node:path";
2
+ import {fileURLToPath} from "node:url";
3
+
4
+ // Global variable __dirname no longer available in ES6 modules.
5
+ // Solutions: https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+
8
+ export const testCachePath = path.join(__dirname, "../../test/test-cache");
@@ -0,0 +1,5 @@
1
+ export * from "./cache.js";
2
+ export * from "./interop.js";
3
+ export * from "./params.js";
4
+ export * from "./testFileCache.js";
5
+ export * from "./util.js";
@@ -0,0 +1,10 @@
1
+ import {NetworkName} from "@lodestar/config/networks";
2
+
3
+ export function getInfuraBeaconUrl(network: NetworkName): string {
4
+ const INFURA_ETH2_CREDENTIALS = process.env.INFURA_ETH2_CREDENTIALS;
5
+ if (!INFURA_ETH2_CREDENTIALS) {
6
+ throw Error("Must set ENV INFURA_ETH2_CREDENTIALS");
7
+ }
8
+
9
+ return `https://${INFURA_ETH2_CREDENTIALS}@eth2-beacon-${network}.infura.io`;
10
+ }
@@ -0,0 +1,29 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import {fromHexString, toHexString} from "@chainsafe/ssz";
4
+ import {interopSecretKey} from "../index.js";
5
+ import {testCachePath} from "./cache.js";
6
+
7
+ const interopPubkeysCachedPath = path.join(testCachePath, "interop-pubkeys.json");
8
+
9
+ export function interopPubkeysCached(validatorCount: number): Uint8Array[] {
10
+ fs.mkdirSync(path.dirname(interopPubkeysCachedPath), {recursive: true});
11
+
12
+ const cachedKeysHex = fs.existsSync(interopPubkeysCachedPath)
13
+ ? (JSON.parse(fs.readFileSync(interopPubkeysCachedPath, "utf8")) as string[])
14
+ : ([] as string[]);
15
+
16
+ const keys = cachedKeysHex.slice(0, validatorCount).map((hex) => fromHexString(hex));
17
+
18
+ if (cachedKeysHex.length < validatorCount) {
19
+ for (let i = cachedKeysHex.length; i < validatorCount; i++) {
20
+ const sk = interopSecretKey(i);
21
+ const pk = sk.toPublicKey().toBytes();
22
+ keys.push(pk);
23
+ }
24
+ const keysHex = keys.map((pk) => toHexString(pk));
25
+ fs.writeFileSync(interopPubkeysCachedPath, JSON.stringify(keysHex, null, 2));
26
+ }
27
+
28
+ return keys;
29
+ }
@@ -0,0 +1,23 @@
1
+ // DON'T MODIFY OR FORMAT THIS FILE
2
+ // USE FOR GA CACHE
3
+
4
+ export const phase0State = {
5
+ network: "mainnet" as const,
6
+ epoch: 58758, // Pre-altair fork
7
+ };
8
+
9
+ export const altairState = {
10
+ network: "mainnet" as const,
11
+ epoch: 81889, // Post altair fork
12
+ };
13
+
14
+ export const capellaState = {
15
+ network: "mainnet" as const,
16
+ epoch: 217614, // Post capella fork
17
+ };
18
+
19
+ export const rangeSyncTest = {
20
+ network: "mainnet" as const,
21
+ startSlot: 3766816, // Post altair, first slot in epoch 117713
22
+ endSlot: 3766847, // 3766816 + 31, all blocks in same epoch
23
+ };
@@ -0,0 +1,110 @@
1
+ import {ChainForkConfig, createBeaconConfig} from "@lodestar/config";
2
+ import {config, config as minimalConfig} from "@lodestar/config/default";
3
+ import {
4
+ EPOCHS_PER_HISTORICAL_VECTOR,
5
+ EPOCHS_PER_SLASHINGS_VECTOR,
6
+ GENESIS_EPOCH,
7
+ GENESIS_SLOT,
8
+ SLOTS_PER_HISTORICAL_ROOT,
9
+ } from "@lodestar/params";
10
+ import {phase0, ssz} from "@lodestar/types";
11
+ import {EpochCacheOpts} from "../cache/epochCache.js";
12
+ import {BeaconStateCache} from "../cache/stateCache.js";
13
+ import {ZERO_HASH} from "../constants/index.js";
14
+ import {
15
+ BeaconStateAllForks,
16
+ BeaconStatePhase0,
17
+ CachedBeaconStateAllForks,
18
+ createCachedBeaconState,
19
+ createPubkeyCache,
20
+ } from "../index.js";
21
+ import {newZeroedArray} from "../util/index.js";
22
+
23
+ /**
24
+ * Copy of BeaconState, but all fields are marked optional to allow for swapping out variables as needed.
25
+ */
26
+ type TestBeaconState = Partial<phase0.BeaconState>;
27
+
28
+ /**
29
+ * Generate beaconState, by default it will use the initial state defined when the `ChainStart` log is emitted.
30
+ * NOTE: All fields can be overridden through `opts`.
31
+ * @param {TestBeaconState} opts
32
+ * @returns {BeaconState}
33
+ */
34
+ export function generateState(opts?: TestBeaconState): BeaconStatePhase0 {
35
+ return ssz.phase0.BeaconState.toViewDU({
36
+ genesisTime: Math.floor(Date.now() / 1000),
37
+ genesisValidatorsRoot: ZERO_HASH,
38
+ slot: GENESIS_SLOT,
39
+ fork: {
40
+ previousVersion: config.GENESIS_FORK_VERSION,
41
+ currentVersion: config.GENESIS_FORK_VERSION,
42
+ epoch: GENESIS_EPOCH,
43
+ },
44
+ latestBlockHeader: {
45
+ slot: 0,
46
+ proposerIndex: 0,
47
+ parentRoot: Buffer.alloc(32),
48
+ stateRoot: Buffer.alloc(32),
49
+ bodyRoot: ssz.phase0.BeaconBlockBody.hashTreeRoot(ssz.phase0.BeaconBlockBody.defaultValue()),
50
+ },
51
+ blockRoots: Array.from({length: SLOTS_PER_HISTORICAL_ROOT}, () => ZERO_HASH),
52
+ stateRoots: Array.from({length: SLOTS_PER_HISTORICAL_ROOT}, () => ZERO_HASH),
53
+ historicalRoots: [],
54
+ eth1Data: {
55
+ depositRoot: Buffer.alloc(32),
56
+ blockHash: Buffer.alloc(32),
57
+ depositCount: 0,
58
+ },
59
+ eth1DataVotes: [],
60
+ eth1DepositIndex: 0,
61
+ validators: [],
62
+ balances: [],
63
+ randaoMixes: Array.from({length: EPOCHS_PER_HISTORICAL_VECTOR}, () => ZERO_HASH),
64
+ slashings: newZeroedArray(EPOCHS_PER_SLASHINGS_VECTOR),
65
+ previousEpochAttestations: [],
66
+ currentEpochAttestations: [],
67
+ justificationBits: ssz.phase0.JustificationBits.defaultValue(),
68
+ previousJustifiedCheckpoint: {
69
+ epoch: GENESIS_EPOCH,
70
+ root: ZERO_HASH,
71
+ },
72
+ currentJustifiedCheckpoint: {
73
+ epoch: GENESIS_EPOCH,
74
+ root: ZERO_HASH,
75
+ },
76
+ finalizedCheckpoint: {
77
+ epoch: GENESIS_EPOCH,
78
+ root: ZERO_HASH,
79
+ },
80
+ ...opts,
81
+ });
82
+ }
83
+
84
+ export function generateCachedState(
85
+ config: ChainForkConfig = minimalConfig,
86
+ opts: TestBeaconState = {}
87
+ ): CachedBeaconStateAllForks {
88
+ const state = generateState(opts);
89
+ return createCachedBeaconState(state, {
90
+ config: createBeaconConfig(config, state.genesisValidatorsRoot),
91
+ // This is a test state, there's no need to have a global shared cache of keys
92
+ pubkeyCache: createPubkeyCache(),
93
+ });
94
+ }
95
+
96
+ export function createCachedBeaconStateTest<T extends BeaconStateAllForks>(
97
+ state: T,
98
+ configCustom: ChainForkConfig = config,
99
+ opts?: EpochCacheOpts
100
+ ): T & BeaconStateCache {
101
+ return createCachedBeaconState<T>(
102
+ state,
103
+ {
104
+ config: createBeaconConfig(configCustom, state.genesisValidatorsRoot),
105
+ // This is a test state, there's no need to have a global shared cache of keys
106
+ pubkeyCache: createPubkeyCache(),
107
+ },
108
+ opts
109
+ );
110
+ }
@@ -0,0 +1,127 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import {getClient} from "@lodestar/api";
4
+ import {ChainForkConfig, createChainForkConfig} from "@lodestar/config";
5
+ import {NetworkName, networksChainConfig} from "@lodestar/config/networks";
6
+ import {SignedBeaconBlock} from "@lodestar/types";
7
+ import {fetch} from "@lodestar/utils";
8
+ import {CachedBeaconStateAllForks} from "../index.js";
9
+ import {testCachePath} from "./cache.js";
10
+ import {getInfuraBeaconUrl} from "./infura.js";
11
+ import {createCachedBeaconStateTest} from "./state.js";
12
+
13
+ /**
14
+ * Full link example:
15
+ * ```
16
+ * https://github.com/dapplion/ethereum-consensus-test-data/releases/download/v0.1.0/block_mainnet_3766821.ssz
17
+ * ``` */
18
+ const TEST_FILES_BASE_URL = "https://github.com/dapplion/ethereum-consensus-test-data/releases/download/v0.1.0";
19
+
20
+ /**
21
+ * Create a network config from known network params
22
+ */
23
+ export function getNetworkConfig(network: NetworkName): ChainForkConfig {
24
+ const configNetwork = networksChainConfig[network];
25
+ return createChainForkConfig(configNetwork);
26
+ }
27
+
28
+ /**
29
+ * Download a state from Infura. Caches states in local fs by network and slot to only download once.
30
+ */
31
+ export async function getNetworkCachedState(
32
+ network: NetworkName,
33
+ slot: number,
34
+ timeout?: number
35
+ ): Promise<CachedBeaconStateAllForks> {
36
+ const config = getNetworkConfig(network);
37
+ const fileId = `state_${network}_${slot}.ssz`;
38
+
39
+ const filepath = path.join(testCachePath, fileId);
40
+
41
+ if (fs.existsSync(filepath)) {
42
+ const stateSsz = fs.readFileSync(filepath);
43
+ return createCachedBeaconStateTest(config.getForkTypes(slot).BeaconState.deserializeToViewDU(stateSsz), config);
44
+ }
45
+
46
+ const stateSsz = await tryEach([
47
+ () => downloadTestFile(fileId),
48
+ () => {
49
+ const client = getClient(
50
+ {baseUrl: getInfuraBeaconUrl(network), globalInit: {timeoutMs: timeout ?? 300_000}},
51
+ {config}
52
+ );
53
+ return client.debug.getStateV2({stateId: slot}).then((r) => {
54
+ return r.ssz();
55
+ });
56
+ },
57
+ ]);
58
+
59
+ fs.writeFileSync(filepath, stateSsz);
60
+ return createCachedBeaconStateTest(config.getForkTypes(slot).BeaconState.deserializeToViewDU(stateSsz), config);
61
+ }
62
+
63
+ /**
64
+ * Download a state from Infura. Caches states in local fs by network and slot to only download once.
65
+ */
66
+ export async function getNetworkCachedBlock(
67
+ network: NetworkName,
68
+ slot: number,
69
+ timeout?: number
70
+ ): Promise<SignedBeaconBlock> {
71
+ const config = getNetworkConfig(network);
72
+ const fileId = `block_${network}_${slot}.ssz`;
73
+
74
+ const filepath = path.join(testCachePath, fileId);
75
+
76
+ if (fs.existsSync(filepath)) {
77
+ const blockSsz = fs.readFileSync(filepath);
78
+ return config.getForkTypes(slot).SignedBeaconBlock.deserialize(blockSsz);
79
+ }
80
+
81
+ const blockSsz = await tryEach([
82
+ () => downloadTestFile(fileId),
83
+ async () => {
84
+ const client = getClient(
85
+ {baseUrl: getInfuraBeaconUrl(network), globalInit: {timeoutMs: timeout ?? 300_000}},
86
+ {config}
87
+ );
88
+
89
+ return (await client.beacon.getBlockV2({blockId: slot})).ssz();
90
+ },
91
+ ]);
92
+
93
+ fs.writeFileSync(filepath, blockSsz);
94
+ return config.getForkTypes(slot).SignedBeaconBlock.deserialize(blockSsz);
95
+ }
96
+
97
+ async function downloadTestFile(fileId: string): Promise<Uint8Array> {
98
+ const fileUrl = `${TEST_FILES_BASE_URL}/${fileId}`;
99
+ // biome-ignore lint/suspicious/noConsole: We explicity need to log to console
100
+ console.log(`Downloading file ${fileUrl}`);
101
+
102
+ try {
103
+ const res = await fetch(fileUrl);
104
+ if (!res.ok) {
105
+ throw new Error(`Error downloading ${fileUrl}: ${res.status} ${res.statusText}`);
106
+ }
107
+ return new Uint8Array(await res.arrayBuffer());
108
+ } catch (e) {
109
+ const error = e as Error;
110
+ error.message = `Error downloading ${fileUrl}: ${error.message}`;
111
+ throw error;
112
+ }
113
+ }
114
+
115
+ async function tryEach<T>(promises: (() => Promise<T>)[]): Promise<T> {
116
+ const errors: Error[] = [];
117
+
118
+ for (let i = 0; i < promises.length; i++) {
119
+ try {
120
+ return await promises[i]();
121
+ } catch (e) {
122
+ errors.push(e as Error);
123
+ }
124
+ }
125
+
126
+ throw Error(errors.map((e, i) => `Error[${i}] ${e.message}`).join("\n"));
127
+ }