@lodestar/state-transition 1.50.1 → 1.51.0-dev.09763aa8d2

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 (211) hide show
  1. package/lib/block/index.d.ts +1 -1
  2. package/lib/block/index.d.ts.map +1 -1
  3. package/lib/block/index.js +3 -3
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  6. package/lib/block/processAttestationsAltair.js +3 -1
  7. package/lib/block/processAttestationsAltair.js.map +1 -1
  8. package/lib/block/processDeposit.d.ts +2 -2
  9. package/lib/block/processDeposit.d.ts.map +1 -1
  10. package/lib/block/processDeposit.js +1 -1
  11. package/lib/block/processDeposit.js.map +1 -1
  12. package/lib/block/processEth1Data.d.ts +3 -3
  13. package/lib/block/processEth1Data.d.ts.map +1 -1
  14. package/lib/block/processEth1Data.js.map +1 -1
  15. package/lib/block/processOperations.d.ts +1 -1
  16. package/lib/block/processOperations.d.ts.map +1 -1
  17. package/lib/block/processOperations.js +9 -7
  18. package/lib/block/processOperations.js.map +1 -1
  19. package/lib/cache/epochCache.d.ts +5 -2
  20. package/lib/cache/epochCache.d.ts.map +1 -1
  21. package/lib/cache/epochCache.js +12 -5
  22. package/lib/cache/epochCache.js.map +1 -1
  23. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  24. package/lib/cache/epochTransitionCache.js +2 -1
  25. package/lib/cache/epochTransitionCache.js.map +1 -1
  26. package/lib/cache/stateCache.d.ts +2 -1
  27. package/lib/cache/stateCache.d.ts.map +1 -1
  28. package/lib/cache/stateCache.js.map +1 -1
  29. package/lib/cache/syncCommitteeCache.d.ts +1 -1
  30. package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
  31. package/lib/cache/types.d.ts +2 -1
  32. package/lib/cache/types.d.ts.map +1 -1
  33. package/lib/epoch/getRewardsAndPenalties.d.ts.map +1 -1
  34. package/lib/epoch/getRewardsAndPenalties.js +9 -2
  35. package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
  36. package/lib/epoch/index.d.ts +2 -2
  37. package/lib/epoch/index.d.ts.map +1 -1
  38. package/lib/epoch/index.js +5 -3
  39. package/lib/epoch/index.js.map +1 -1
  40. package/lib/epoch/processEth1DataReset.d.ts +2 -2
  41. package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
  42. package/lib/epoch/processEth1DataReset.js.map +1 -1
  43. package/lib/epoch/processSyncCommitteeUpdates.js +1 -1
  44. package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
  45. package/lib/index.d.ts +1 -1
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js.map +1 -1
  48. package/lib/lightClient/spec/store.d.ts +1 -1
  49. package/lib/lightClient/spec/store.d.ts.map +1 -1
  50. package/lib/lightClient/spec/utils.d.ts.map +1 -1
  51. package/lib/lightClient/spec/utils.js +1 -1
  52. package/lib/lightClient/spec/utils.js.map +1 -1
  53. package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
  54. package/lib/lightClient/spec/validateLightClientUpdate.js +1 -1
  55. package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
  56. package/lib/metrics.d.ts +1 -1
  57. package/lib/metrics.d.ts.map +1 -1
  58. package/lib/metrics.js +4 -4
  59. package/lib/metrics.js.map +1 -1
  60. package/lib/rewards/attestationsRewards.d.ts +1 -1
  61. package/lib/rewards/attestationsRewards.d.ts.map +1 -1
  62. package/lib/rewards/attestationsRewards.js +10 -3
  63. package/lib/rewards/attestationsRewards.js.map +1 -1
  64. package/lib/rewards/syncCommitteeRewards.d.ts +1 -1
  65. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
  66. package/lib/signatureSets/inclusionList.d.ts +5 -0
  67. package/lib/signatureSets/inclusionList.d.ts.map +1 -0
  68. package/lib/signatureSets/inclusionList.js +14 -0
  69. package/lib/signatureSets/inclusionList.js.map +1 -0
  70. package/lib/signatureSets/index.d.ts +1 -0
  71. package/lib/signatureSets/index.d.ts.map +1 -1
  72. package/lib/signatureSets/index.js +1 -0
  73. package/lib/signatureSets/index.js.map +1 -1
  74. package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
  75. package/lib/slot/upgradeStateToHeze.js +4 -4
  76. package/lib/slot/upgradeStateToHeze.js.map +1 -1
  77. package/lib/stateTransition.js +2 -2
  78. package/lib/stateTransition.js.map +1 -1
  79. package/lib/stateView/beaconStateView.d.ts +2 -0
  80. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  81. package/lib/stateView/beaconStateView.js +11 -1
  82. package/lib/stateView/beaconStateView.js.map +1 -1
  83. package/lib/stateView/interface.d.ts +5 -4
  84. package/lib/stateView/interface.d.ts.map +1 -1
  85. package/lib/stateView/interface.js.map +1 -1
  86. package/lib/stateView/nativeBeaconStateView.d.ts +16 -6
  87. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  88. package/lib/stateView/nativeBeaconStateView.js +99 -25
  89. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  90. package/lib/stateView/stateViewFactory.d.ts.map +1 -1
  91. package/lib/stateView/stateViewFactory.js +5 -4
  92. package/lib/stateView/stateViewFactory.js.map +1 -1
  93. package/lib/testUtils/interopPubkeyCache.js +1 -1
  94. package/lib/testUtils/interopPubkeyCache.js.map +1 -1
  95. package/lib/testUtils/state.d.ts.map +1 -1
  96. package/lib/testUtils/state.js +1 -1
  97. package/lib/testUtils/state.js.map +1 -1
  98. package/lib/testUtils/util.d.ts +1 -1
  99. package/lib/testUtils/util.d.ts.map +1 -1
  100. package/lib/testUtils/util.js +2 -2
  101. package/lib/testUtils/util.js.map +1 -1
  102. package/lib/types.d.ts +2 -2
  103. package/lib/types.d.ts.map +1 -1
  104. package/lib/util/altair.d.ts +3 -1
  105. package/lib/util/altair.d.ts.map +1 -1
  106. package/lib/util/altair.js +7 -4
  107. package/lib/util/altair.js.map +1 -1
  108. package/lib/util/blindedBlock.d.ts +1 -1
  109. package/lib/util/blindedBlock.d.ts.map +1 -1
  110. package/lib/util/blindedBlock.js +9 -14
  111. package/lib/util/blindedBlock.js.map +1 -1
  112. package/lib/util/clock.d.ts +5 -0
  113. package/lib/util/clock.d.ts.map +1 -1
  114. package/lib/util/clock.js +20 -17
  115. package/lib/util/clock.js.map +1 -1
  116. package/lib/util/deposit.d.ts +2 -2
  117. package/lib/util/deposit.d.ts.map +1 -1
  118. package/lib/util/deposit.js.map +1 -1
  119. package/lib/util/epochShuffling.d.ts.map +1 -1
  120. package/lib/util/epochShuffling.js +1 -1
  121. package/lib/util/epochShuffling.js.map +1 -1
  122. package/lib/util/genesis.d.ts.map +1 -1
  123. package/lib/util/genesis.js +46 -23
  124. package/lib/util/genesis.js.map +1 -1
  125. package/lib/util/inclusionListCommittee.d.ts +9 -0
  126. package/lib/util/inclusionListCommittee.d.ts.map +1 -0
  127. package/lib/util/inclusionListCommittee.js +18 -0
  128. package/lib/util/inclusionListCommittee.js.map +1 -0
  129. package/lib/util/index.d.ts +1 -0
  130. package/lib/util/index.d.ts.map +1 -1
  131. package/lib/util/index.js +1 -0
  132. package/lib/util/index.js.map +1 -1
  133. package/lib/util/interop.d.ts +1 -1
  134. package/lib/util/interop.d.ts.map +1 -1
  135. package/lib/util/interop.js +1 -1
  136. package/lib/util/interop.js.map +1 -1
  137. package/lib/util/seed.js +1 -1
  138. package/lib/util/seed.js.map +1 -1
  139. package/lib/util/shuffling.d.ts +3 -0
  140. package/lib/util/shuffling.d.ts.map +1 -1
  141. package/lib/util/shuffling.js +41 -1
  142. package/lib/util/shuffling.js.map +1 -1
  143. package/lib/util/signatureSets.d.ts +1 -1
  144. package/lib/util/signatureSets.d.ts.map +1 -1
  145. package/lib/util/signatureSets.js +1 -1
  146. package/lib/util/signatureSets.js.map +1 -1
  147. package/lib/util/slot.d.ts +18 -2
  148. package/lib/util/slot.d.ts.map +1 -1
  149. package/lib/util/slot.js +70 -6
  150. package/lib/util/slot.js.map +1 -1
  151. package/lib/util/syncCommittee.d.ts +4 -3
  152. package/lib/util/syncCommittee.d.ts.map +1 -1
  153. package/lib/util/syncCommittee.js +10 -8
  154. package/lib/util/syncCommittee.js.map +1 -1
  155. package/lib/util/validator.d.ts +1 -1
  156. package/lib/util/validator.d.ts.map +1 -1
  157. package/lib/util/validator.js +32 -11
  158. package/lib/util/validator.js.map +1 -1
  159. package/lib/util/weakSubjectivity.d.ts.map +1 -1
  160. package/lib/util/weakSubjectivity.js +4 -3
  161. package/lib/util/weakSubjectivity.js.map +1 -1
  162. package/package.json +9 -9
  163. package/src/block/index.ts +15 -15
  164. package/src/block/processAttestationsAltair.ts +4 -1
  165. package/src/block/processDeposit.ts +9 -4
  166. package/src/block/processEth1Data.ts +3 -3
  167. package/src/block/processOperations.ts +19 -16
  168. package/src/cache/epochCache.ts +30 -6
  169. package/src/cache/epochTransitionCache.ts +2 -1
  170. package/src/cache/stateCache.ts +2 -0
  171. package/src/cache/syncCommitteeCache.ts +1 -1
  172. package/src/cache/types.ts +2 -1
  173. package/src/epoch/getRewardsAndPenalties.ts +11 -1
  174. package/src/epoch/index.ts +18 -16
  175. package/src/epoch/processEth1DataReset.ts +2 -2
  176. package/src/epoch/processSyncCommitteeUpdates.ts +1 -1
  177. package/src/index.ts +2 -0
  178. package/src/lightClient/spec/store.ts +1 -1
  179. package/src/lightClient/spec/utils.ts +1 -1
  180. package/src/lightClient/spec/validateLightClientUpdate.ts +1 -1
  181. package/src/metrics.ts +5 -4
  182. package/src/rewards/attestationsRewards.ts +13 -2
  183. package/src/rewards/syncCommitteeRewards.ts +1 -1
  184. package/src/signatureSets/inclusionList.ts +20 -0
  185. package/src/signatureSets/index.ts +1 -0
  186. package/src/slot/upgradeStateToHeze.ts +6 -4
  187. package/src/stateTransition.ts +2 -2
  188. package/src/stateView/beaconStateView.ts +14 -2
  189. package/src/stateView/interface.ts +5 -10
  190. package/src/stateView/nativeBeaconStateView.ts +100 -29
  191. package/src/stateView/stateViewFactory.ts +5 -4
  192. package/src/testUtils/interopPubkeyCache.ts +1 -1
  193. package/src/testUtils/state.ts +1 -1
  194. package/src/testUtils/util.ts +2 -2
  195. package/src/types.ts +2 -0
  196. package/src/util/altair.ts +15 -4
  197. package/src/util/blindedBlock.ts +12 -15
  198. package/src/util/clock.ts +26 -17
  199. package/src/util/deposit.ts +2 -2
  200. package/src/util/epochShuffling.ts +1 -1
  201. package/src/util/genesis.ts +56 -30
  202. package/src/util/inclusionListCommittee.ts +17 -0
  203. package/src/util/index.ts +1 -0
  204. package/src/util/interop.ts +1 -1
  205. package/src/util/seed.ts +1 -1
  206. package/src/util/shuffling.ts +46 -1
  207. package/src/util/signatureSets.ts +1 -1
  208. package/src/util/slot.ts +78 -8
  209. package/src/util/syncCommittee.ts +22 -10
  210. package/src/util/validator.ts +47 -20
  211. package/src/util/weakSubjectivity.ts +3 -3
@@ -14,6 +14,7 @@ import {
14
14
  CachedBeaconStateFulu,
15
15
  CachedBeaconStateGloas,
16
16
  CachedBeaconStatePhase0,
17
+ CachedBeaconStatePreHeze,
17
18
  EpochTransitionCache,
18
19
  } from "../types.js";
19
20
  import {processBuilderPendingPayments} from "./processBuilderPendingPayments.js";
@@ -36,32 +37,31 @@ import {processSlashings} from "./processSlashings.js";
36
37
  import {processSlashingsReset} from "./processSlashingsReset.js";
37
38
  import {processSyncCommitteeUpdates} from "./processSyncCommitteeUpdates.js";
38
39
 
40
+ export {computeUnrealizedCheckpoints} from "./computeUnrealizedCheckpoints.js";
39
41
  // For spec tests
40
42
  export {getRewardsAndPenalties} from "./processRewardsAndPenalties.js";
41
43
  export {
42
- processJustificationAndFinalization,
43
- processInactivityUpdates,
44
- processRewardsAndPenalties,
45
- processRegistryUpdates,
46
- processSlashings,
47
- processEth1DataReset,
44
+ processBuilderPendingPayments,
48
45
  processEffectiveBalanceUpdates,
49
- processSlashingsReset,
50
- processRandaoMixesReset,
46
+ processEth1DataReset,
51
47
  processHistoricalRootsUpdate,
52
- processParticipationRecordUpdates,
53
- processParticipationFlagUpdates,
54
- processSyncCommitteeUpdates,
55
48
  processHistoricalSummariesUpdate,
56
- processPendingDeposits,
49
+ processInactivityUpdates,
50
+ processJustificationAndFinalization,
51
+ processParticipationFlagUpdates,
52
+ processParticipationRecordUpdates,
57
53
  processPendingConsolidations,
54
+ processPendingDeposits,
58
55
  processProposerLookahead,
59
56
  processPtcWindow,
60
- processBuilderPendingPayments,
57
+ processRandaoMixesReset,
58
+ processRegistryUpdates,
59
+ processRewardsAndPenalties,
60
+ processSlashings,
61
+ processSlashingsReset,
62
+ processSyncCommitteeUpdates,
61
63
  };
62
64
 
63
- export {computeUnrealizedCheckpoints} from "./computeUnrealizedCheckpoints.js";
64
-
65
65
  const maxValidatorsPerStateSlashing = SLOTS_PER_EPOCH * MAX_ATTESTER_SLASHINGS * MAX_VALIDATORS_PER_COMMITTEE;
66
66
  const maxSafeValidators = Math.floor(Number.MAX_SAFE_INTEGER / MAX_EFFECTIVE_BALANCE);
67
67
 
@@ -140,7 +140,9 @@ export function processEpoch(
140
140
  timer?.();
141
141
  }
142
142
 
143
- processEth1DataReset(state, cache);
143
+ if (fork < ForkSeq.heze) {
144
+ processEth1DataReset(state as CachedBeaconStatePreHeze, cache);
145
+ }
144
146
 
145
147
  if (fork >= ForkSeq.electra) {
146
148
  const stateElectra = state as CachedBeaconStateElectra;
@@ -1,13 +1,13 @@
1
1
  import {EPOCHS_PER_ETH1_VOTING_PERIOD} from "@lodestar/params";
2
2
  import {ssz} from "@lodestar/types";
3
- import {CachedBeaconStateAllForks, EpochTransitionCache} from "../types.js";
3
+ import {CachedBeaconStatePreHeze, EpochTransitionCache} from "../types.js";
4
4
 
5
5
  /**
6
6
  * Reset eth1DataVotes tree every `EPOCHS_PER_ETH1_VOTING_PERIOD`.
7
7
  *
8
8
  * PERF: Almost no (constant) cost
9
9
  */
10
- export function processEth1DataReset(state: CachedBeaconStateAllForks, cache: EpochTransitionCache): void {
10
+ export function processEth1DataReset(state: CachedBeaconStatePreHeze, cache: EpochTransitionCache): void {
11
11
  const nextEpoch = cache.currentEpoch + 1;
12
12
 
13
13
  // reset eth1 data votes
@@ -1,4 +1,4 @@
1
- import {aggregateSerializedPublicKeys} from "@chainsafe/lodestar-z/blst";
1
+ import {aggregateSerializedPublicKeys} from "@lodestar/native/blst";
2
2
  import {EPOCHS_PER_SYNC_COMMITTEE_PERIOD, ForkSeq} from "@lodestar/params";
3
3
  import {ssz} from "@lodestar/types";
4
4
  import {CachedBeaconStateAltair} from "../types.js";
package/src/index.ts CHANGED
@@ -80,6 +80,7 @@ export type {
80
80
  BeaconStateHeze,
81
81
  // Non-cached states
82
82
  BeaconStatePhase0,
83
+ BeaconStatePreHeze,
83
84
  CachedBeaconStateAllForks,
84
85
  CachedBeaconStateAltair,
85
86
  CachedBeaconStateBellatrix,
@@ -91,5 +92,6 @@ export type {
91
92
  CachedBeaconStateGloas,
92
93
  CachedBeaconStateHeze,
93
94
  CachedBeaconStatePhase0,
95
+ CachedBeaconStatePreHeze,
94
96
  } from "./types.js";
95
97
  export * from "./util/index.js";
@@ -1,5 +1,5 @@
1
- import type {PublicKey} from "@chainsafe/lodestar-z/blst";
2
1
  import {BeaconConfig} from "@lodestar/config";
2
+ import type {PublicKey} from "@lodestar/native/blst";
3
3
  import {LightClientBootstrap, LightClientHeader, LightClientUpdate, SyncPeriod} from "@lodestar/types";
4
4
  import {computeSyncPeriodAtSlot} from "../../util/epoch.js";
5
5
  import type {LightClientUpdateSummary} from "./isBetterUpdate.js";
@@ -1,7 +1,7 @@
1
- import {PublicKey} from "@chainsafe/lodestar-z/blst";
2
1
  import {Tree} from "@chainsafe/persistent-merkle-tree";
3
2
  import {BitArray} from "@chainsafe/ssz";
4
3
  import {ChainForkConfig} from "@lodestar/config";
4
+ import {PublicKey} from "@lodestar/native/blst";
5
5
  import {
6
6
  BLOCK_BODY_EXECUTION_PAYLOAD_GINDEX,
7
7
  CURRENT_SYNC_COMMITTEE_GINDEX,
@@ -1,5 +1,5 @@
1
- import {PublicKey, Signature, fastAggregateVerify} from "@chainsafe/lodestar-z/blst";
2
1
  import {ChainForkConfig} from "@lodestar/config";
2
+ import {PublicKey, Signature, fastAggregateVerify} from "@lodestar/native/blst";
3
3
  import {DOMAIN_SYNC_COMMITTEE, GENESIS_SLOT, MIN_SYNC_COMMITTEE_PARTICIPANTS} from "@lodestar/params";
4
4
  import {LightClientUpdate, Root, ssz} from "@lodestar/types";
5
5
  import type {ILightClientStore, SyncCommitteeFast} from "./store.js";
package/src/metrics.ts CHANGED
@@ -156,19 +156,20 @@ export function getMetrics(register: MetricsRegister) {
156
156
  }
157
157
 
158
158
  export function onStateCloneMetrics(
159
- state: CachedBeaconStateAllForks,
159
+ clonedState: CachedBeaconStateAllForks,
160
+ clonedCount: number,
160
161
  metrics: BeaconStateTransitionMetrics,
161
162
  source: StateCloneSource
162
163
  ): void {
163
- metrics.preStateClonedCount.observe(state.clonedCount);
164
+ metrics.preStateClonedCount.observe(clonedCount);
164
165
 
165
- if (isBalancesNodesPopulated(state)) {
166
+ if (isBalancesNodesPopulated(clonedState)) {
166
167
  metrics.preStateBalancesNodesPopulatedHit.inc({source});
167
168
  } else {
168
169
  metrics.preStateBalancesNodesPopulatedMiss.inc({source});
169
170
  }
170
171
 
171
- if (isValidatorsNodesPopulated(state)) {
172
+ if (isValidatorsNodesPopulated(clonedState)) {
172
173
  metrics.preStateValidatorsNodesPopulatedHit.inc({source});
173
174
  } else {
174
175
  metrics.preStateValidatorsNodesPopulatedMiss.inc({source});
@@ -1,9 +1,10 @@
1
- import {type PubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
2
1
  import {BeaconConfig} from "@lodestar/config";
2
+ import {type PubkeyCache} from "@lodestar/native/pubkeys";
3
3
  import {
4
4
  EFFECTIVE_BALANCE_INCREMENT,
5
5
  ForkName,
6
6
  ForkSeq,
7
+ GENESIS_EPOCH,
7
8
  INACTIVITY_PENALTY_QUOTIENT_ALTAIR,
8
9
  INACTIVITY_PENALTY_QUOTIENT_BELLATRIX,
9
10
  MAX_EFFECTIVE_BALANCE,
@@ -26,6 +27,7 @@ import {
26
27
  FLAG_PREV_HEAD_ATTESTER_UNSLASHED,
27
28
  FLAG_PREV_SOURCE_ATTESTER_UNSLASHED,
28
29
  FLAG_PREV_TARGET_ATTESTER_UNSLASHED,
30
+ getSlotDurationMsAtEpoch,
29
31
  hasMarkers,
30
32
  isInInactivityLeak,
31
33
  } from "../util/index.js";
@@ -168,7 +170,16 @@ function computeTotalAttestationsRewardsAltair(
168
170
  config.getForkSeq(state.slot) === ForkSeq.altair
169
171
  ? INACTIVITY_PENALTY_QUOTIENT_ALTAIR
170
172
  : INACTIVITY_PENALTY_QUOTIENT_BELLATRIX;
171
- const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * inactivityPenaltyQuotient;
173
+ let inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * inactivityPenaltyQuotient;
174
+ // The penalty pays for the previous epoch and scales with the square of its slot duration
175
+ const genesisSlotDurationMs = getSlotDurationMsAtEpoch(config, GENESIS_EPOCH);
176
+ const prevEpochSlotDurationMs = getSlotDurationMsAtEpoch(config, Math.max(epochCtx.epoch - 1, GENESIS_EPOCH));
177
+ if (prevEpochSlotDurationMs !== genesisSlotDurationMs) {
178
+ inactivityPenaltyDenominator = Number(
179
+ (BigInt(inactivityPenaltyDenominator) * BigInt(genesisSlotDurationMs) ** 2n) /
180
+ BigInt(prevEpochSlotDurationMs) ** 2n
181
+ );
182
+ }
172
183
 
173
184
  for (let i = 0; i < flags.length; i++) {
174
185
  if (validatorIndices.length && !validatorIndices.includes(i)) {
@@ -1,5 +1,5 @@
1
- import {type PubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
2
1
  import {BeaconConfig} from "@lodestar/config";
2
+ import {type PubkeyCache} from "@lodestar/native/pubkeys";
3
3
  import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
4
4
  import {BeaconBlock, ValidatorIndex, altair, rewards} from "@lodestar/types";
5
5
  import {toPubkeyHex} from "@lodestar/utils";
@@ -0,0 +1,20 @@
1
+ import {BeaconConfig} from "@lodestar/config";
2
+ import {DOMAIN_INCLUSION_LIST_COMMITTEE} from "@lodestar/params";
3
+ import {Slot, heze, ssz} from "@lodestar/types";
4
+ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
5
+
6
+ export function getInclusionListSignatureSet(
7
+ config: BeaconConfig,
8
+ stateSlot: Slot,
9
+ signedInclusionList: heze.SignedInclusionList
10
+ ): ISignatureSet {
11
+ const message = signedInclusionList.message;
12
+ const domain = config.getDomain(stateSlot, DOMAIN_INCLUSION_LIST_COMMITTEE, message.slot);
13
+
14
+ return {
15
+ type: SignatureSetType.indexed,
16
+ index: message.validatorIndex,
17
+ signingRoot: computeSigningRoot(ssz.heze.InclusionList, message, domain),
18
+ signature: signedInclusionList.signature,
19
+ };
20
+ }
@@ -18,6 +18,7 @@ export * from "./attesterSlashings.js";
18
18
  export * from "./blsToExecutionChange.js";
19
19
  export * from "./executionPayloadBid.js";
20
20
  export * from "./executionPayloadEnvelope.js";
21
+ export * from "./inclusionList.js";
21
22
  export * from "./indexedAttestation.js";
22
23
  export * from "./indexedPayloadAttestation.js";
23
24
  export * from "./proposer.js";
@@ -7,6 +7,12 @@ import {CachedBeaconStateGloas, CachedBeaconStateHeze} from "../types.js";
7
7
  * Spec: heze/fork.md `upgrade_to_heze`.
8
8
  */
9
9
  export function upgradeStateToHeze(stateGloas: CachedBeaconStateGloas): CachedBeaconStateHeze {
10
+ // In Heze, the old deposit mechanism must be fully drained before the fork
11
+ if (BigInt(stateGloas.eth1DepositIndex) !== stateGloas.depositRequestsStartIndex) {
12
+ throw new Error(
13
+ `Cannot upgrade to Heze: legacy deposit mechanism still active eth1DepositIndex=${stateGloas.eth1DepositIndex} depositRequestsStartIndex=${stateGloas.depositRequestsStartIndex}`
14
+ );
15
+ }
10
16
  const {config} = stateGloas;
11
17
 
12
18
  ssz.gloas.BeaconState.commitViewDU(stateGloas);
@@ -26,9 +32,6 @@ export function upgradeStateToHeze(stateGloas: CachedBeaconStateGloas): CachedBe
26
32
  stateHezeView.blockRoots = stateHezeCloned.blockRoots;
27
33
  stateHezeView.stateRoots = stateHezeCloned.stateRoots;
28
34
  stateHezeView.historicalRoots = stateHezeCloned.historicalRoots;
29
- stateHezeView.eth1Data = stateHezeCloned.eth1Data;
30
- stateHezeView.eth1DataVotes = stateHezeCloned.eth1DataVotes;
31
- stateHezeView.eth1DepositIndex = stateHezeCloned.eth1DepositIndex;
32
35
  stateHezeView.validators = stateHezeCloned.validators;
33
36
  stateHezeView.balances = stateHezeCloned.balances;
34
37
  stateHezeView.randaoMixes = stateHezeCloned.randaoMixes;
@@ -46,7 +49,6 @@ export function upgradeStateToHeze(stateGloas: CachedBeaconStateGloas): CachedBe
46
49
  stateHezeView.nextWithdrawalIndex = stateHezeCloned.nextWithdrawalIndex;
47
50
  stateHezeView.nextWithdrawalValidatorIndex = stateHezeCloned.nextWithdrawalValidatorIndex;
48
51
  stateHezeView.historicalSummaries = stateHezeCloned.historicalSummaries;
49
- stateHezeView.depositRequestsStartIndex = stateHezeCloned.depositRequestsStartIndex;
50
52
  stateHezeView.depositBalanceToConsume = stateHezeCloned.depositBalanceToConsume;
51
53
  stateHezeView.exitBalanceToConsume = stateHezeCloned.exitBalanceToConsume;
52
54
  stateHezeView.earliestExitEpoch = stateHezeCloned.earliestExitEpoch;
@@ -101,7 +101,7 @@ export function stateTransition(
101
101
  let postState = state.clone(options.dontTransferCache);
102
102
 
103
103
  if (metrics) {
104
- onStateCloneMetrics(postState, metrics, StateCloneSource.stateTransition);
104
+ onStateCloneMetrics(postState, state.clonedCount, metrics, StateCloneSource.stateTransition);
105
105
  }
106
106
 
107
107
  // State is already a ViewDU, which won't commit changes. Equivalent to .setStateCachesAsTransient()
@@ -168,7 +168,7 @@ export function processSlots(
168
168
  let postState = state.clone(opts?.dontTransferCache);
169
169
 
170
170
  if (metrics) {
171
- onStateCloneMetrics(postState, metrics, StateCloneSource.processSlots);
171
+ onStateCloneMetrics(postState, state.clonedCount, metrics, StateCloneSource.processSlots);
172
172
  }
173
173
 
174
174
  // State is already a ViewDU, which won't commit changes. Equivalent to .setStateCachesAsTransient()
@@ -40,6 +40,7 @@ import {
40
40
  CachedBeaconStateExecutions,
41
41
  CachedBeaconStateFulu,
42
42
  CachedBeaconStateGloas,
43
+ CachedBeaconStatePreHeze,
43
44
  createCachedBeaconState,
44
45
  isStateValidatorsNodesPopulated,
45
46
  } from "../cache/stateCache.js";
@@ -83,6 +84,7 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
83
84
  // phase0
84
85
  private cachedFork: Fork | null = null;
85
86
  private cachedLatestBlockHeader: phase0.BeaconBlockHeader | null = null;
87
+ private cachedEffectiveBalanceIncrementsZeroInactive: EffectiveBalanceIncrements | null = null;
86
88
  // altair
87
89
  private cachedCurrentSyncCommittee: SyncCommittee | null = null;
88
90
  private cachedNextSyncCommittee: SyncCommittee | null = null;
@@ -145,7 +147,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
145
147
  }
146
148
 
147
149
  get eth1Data(): phase0.Eth1Data {
148
- return this.cachedState.eth1Data;
150
+ if (this.forkSeq >= ForkSeq.heze) {
151
+ throw new Error("eth1Data was removed from the beacon state in Heze");
152
+ }
153
+ return (this.cachedState as CachedBeaconStatePreHeze).eth1Data;
149
154
  }
150
155
 
151
156
  get latestBlockHeader(): phase0.BeaconBlockHeader {
@@ -611,6 +616,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
611
616
  return this.cachedState.epochCtx.currentSyncCommitteeIndexed;
612
617
  }
613
618
 
619
+ get currentSyncCommitteeValidatorIndices(): Uint32Array {
620
+ return this.cachedState.epochCtx.currentSyncCommitteeIndexed.validatorIndices;
621
+ }
622
+
614
623
  get syncProposerReward(): number {
615
624
  return this.cachedState.epochCtx.syncProposerReward;
616
625
  }
@@ -630,7 +639,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
630
639
  }
631
640
 
632
641
  getEffectiveBalanceIncrementsZeroInactive(): EffectiveBalanceIncrements {
633
- return getEffectiveBalanceIncrementsZeroInactive(this.cachedState);
642
+ if (this.cachedEffectiveBalanceIncrementsZeroInactive === null) {
643
+ this.cachedEffectiveBalanceIncrementsZeroInactive = getEffectiveBalanceIncrementsZeroInactive(this.cachedState);
644
+ }
645
+ return this.cachedEffectiveBalanceIncrementsZeroInactive;
634
646
  }
635
647
 
636
648
  getBalance(index: number): number {
@@ -207,6 +207,7 @@ export interface IBeaconStateViewAltair extends IBeaconStateView {
207
207
  currentSyncCommittee: altair.SyncCommittee;
208
208
  nextSyncCommittee: altair.SyncCommittee;
209
209
  currentSyncCommitteeIndexed: SyncCommitteeCache;
210
+ readonly currentSyncCommitteeValidatorIndices: Uint32Array;
210
211
  syncProposerReward: number;
211
212
  getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
212
213
  /** Get indexed sync committee with slot+1 offset for duty lookups */
@@ -335,17 +336,14 @@ export type IBeaconStateViewLatestFork = Omit<
335
336
  */
336
337
  export type IBeaconStateViewNative = Omit<
337
338
  IBeaconStateViewLatestFork,
338
- | "builderPendingPayments"
339
- | "builderPendingWithdrawals"
340
339
  | "computeAttestationsRewards"
341
340
  | "computeBlockRewards"
342
341
  | "computeNewStateRoot"
343
342
  | "computeSyncCommitteeRewards"
343
+ | "currentSyncCommitteeValidatorIndices"
344
344
  | "eth1Data"
345
345
  | "executionPayloadAvailability"
346
346
  | "getBeaconCommittee"
347
- | "getIndicesInPayloadTimelinessCommittee"
348
- | "getPayloadTimelinessCommittee"
349
347
  | "loadOtherState"
350
348
  | "pendingConsolidations"
351
349
  | "pendingDeposits"
@@ -358,10 +356,11 @@ export type IBeaconStateViewNative = Omit<
358
356
  | "withParentPayloadApplied"
359
357
  > & {
360
358
  pendingDeposits: Uint8Array;
359
+ /** Older native addons expose indices only through currentSyncCommitteeIndexed. */
360
+ readonly currentSyncCommitteeValidatorIndices?: Uint32Array;
361
361
  pendingPartialWithdrawals: Uint8Array;
362
362
  pendingConsolidations: Uint8Array;
363
363
  proposerLookahead: Uint32Array;
364
- // UintBn64 lowers to number across the FFI boundary; the wrapper lifts it back to bigint
365
364
  eth1Data: phase0.Eth1Data;
366
365
  executionPayloadAvailability: {uint8Array: Uint8Array; bitLen: number};
367
366
  computeBlockRewards(
@@ -375,8 +374,6 @@ export type IBeaconStateViewNative = Omit<
375
374
  validatorIds: (ValidatorIndex | string)[]
376
375
  ): rewards.SyncCommitteeRewards;
377
376
  getBeaconCommittee(slot: Slot, index: CommitteeIndex): Uint32Array;
378
- getIndexInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number;
379
- getIndicesInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number[];
380
377
  loadOtherState(...args: Parameters<IBeaconStateViewLatestFork["loadOtherState"]>): IBeaconStateViewNative;
381
378
  stateTransition(
382
379
  signedBlockBytes: Uint8Array,
@@ -384,9 +381,7 @@ export type IBeaconStateViewNative = Omit<
384
381
  options?: StateTransitionOpts
385
382
  ): IBeaconStateViewNative;
386
383
  processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}): IBeaconStateViewNative;
387
- withParentPayloadApplied(
388
- ...args: Parameters<IBeaconStateViewLatestFork["withParentPayloadApplied"]>
389
- ): IBeaconStateViewNative;
384
+ withParentPayloadApplied(executionRequestsBytes: Uint8Array): IBeaconStateViewNative;
390
385
  };
391
386
 
392
387
  export function isStatePostAltair(state: IBeaconStateView): state is IBeaconStateViewAltair {