@lodestar/state-transition 1.50.0-dev.fda8006fc3 → 1.50.0-dev.fe4e7408b4

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 (76) hide show
  1. package/lib/block/index.d.ts.map +1 -1
  2. package/lib/block/index.js +1 -1
  3. package/lib/block/index.js.map +1 -1
  4. package/lib/block/processDeposit.d.ts +2 -2
  5. package/lib/block/processDeposit.d.ts.map +1 -1
  6. package/lib/block/processDeposit.js.map +1 -1
  7. package/lib/block/processEth1Data.d.ts +3 -3
  8. package/lib/block/processEth1Data.d.ts.map +1 -1
  9. package/lib/block/processEth1Data.js.map +1 -1
  10. package/lib/block/processOperations.d.ts.map +1 -1
  11. package/lib/block/processOperations.js +8 -6
  12. package/lib/block/processOperations.js.map +1 -1
  13. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  14. package/lib/block/processProposerSlashing.js +0 -23
  15. package/lib/block/processProposerSlashing.js.map +1 -1
  16. package/lib/block/slashValidator.d.ts.map +1 -1
  17. package/lib/block/slashValidator.js +11 -0
  18. package/lib/block/slashValidator.js.map +1 -1
  19. package/lib/cache/stateCache.d.ts +2 -1
  20. package/lib/cache/stateCache.d.ts.map +1 -1
  21. package/lib/cache/stateCache.js.map +1 -1
  22. package/lib/cache/types.d.ts +2 -1
  23. package/lib/cache/types.d.ts.map +1 -1
  24. package/lib/epoch/index.d.ts.map +1 -1
  25. package/lib/epoch/index.js +3 -1
  26. package/lib/epoch/index.js.map +1 -1
  27. package/lib/epoch/processEth1DataReset.d.ts +2 -2
  28. package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
  29. package/lib/epoch/processEth1DataReset.js.map +1 -1
  30. package/lib/epoch/processPendingDeposits.d.ts.map +1 -1
  31. package/lib/epoch/processPendingDeposits.js +8 -4
  32. package/lib/epoch/processPendingDeposits.js.map +1 -1
  33. package/lib/index.d.ts +1 -1
  34. package/lib/index.d.ts.map +1 -1
  35. package/lib/index.js.map +1 -1
  36. package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
  37. package/lib/slot/upgradeStateToHeze.js +4 -4
  38. package/lib/slot/upgradeStateToHeze.js.map +1 -1
  39. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  40. package/lib/stateView/beaconStateView.js +3 -0
  41. package/lib/stateView/beaconStateView.js.map +1 -1
  42. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  43. package/lib/stateView/nativeBeaconStateView.js +4 -0
  44. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  45. package/lib/types.d.ts +2 -2
  46. package/lib/types.d.ts.map +1 -1
  47. package/lib/util/blindedBlock.d.ts +1 -1
  48. package/lib/util/blindedBlock.d.ts.map +1 -1
  49. package/lib/util/blindedBlock.js +5 -2
  50. package/lib/util/blindedBlock.js.map +1 -1
  51. package/lib/util/deposit.d.ts +2 -2
  52. package/lib/util/deposit.d.ts.map +1 -1
  53. package/lib/util/deposit.js.map +1 -1
  54. package/lib/util/genesis.d.ts.map +1 -1
  55. package/lib/util/genesis.js +46 -23
  56. package/lib/util/genesis.js.map +1 -1
  57. package/package.json +8 -8
  58. package/src/block/index.ts +4 -3
  59. package/src/block/processDeposit.ts +7 -2
  60. package/src/block/processEth1Data.ts +3 -3
  61. package/src/block/processOperations.ts +14 -11
  62. package/src/block/processProposerSlashing.ts +2 -28
  63. package/src/block/slashValidator.ts +13 -2
  64. package/src/cache/stateCache.ts +2 -0
  65. package/src/cache/types.ts +2 -1
  66. package/src/epoch/index.ts +4 -1
  67. package/src/epoch/processEth1DataReset.ts +2 -2
  68. package/src/epoch/processPendingDeposits.ts +14 -3
  69. package/src/index.ts +2 -0
  70. package/src/slot/upgradeStateToHeze.ts +6 -4
  71. package/src/stateView/beaconStateView.ts +5 -1
  72. package/src/stateView/nativeBeaconStateView.ts +3 -0
  73. package/src/types.ts +2 -0
  74. package/src/util/blindedBlock.ts +8 -3
  75. package/src/util/deposit.ts +2 -2
  76. package/src/util/genesis.ts +56 -30
@@ -11,11 +11,18 @@ import {
11
11
  UNSET_DEPOSIT_REQUESTS_START_INDEX,
12
12
  } from "@lodestar/params";
13
13
  import {Bytes32, Root, TimeSeconds, phase0, ssz} from "@lodestar/types";
14
- import {processDeposit} from "../block/processDeposit.js";
14
+ import {applyDeposit, processDeposit} from "../block/processDeposit.js";
15
15
  import {EpochCacheImmutableData} from "../cache/epochCache.js";
16
16
  import {createCachedBeaconState} from "../cache/stateCache.js";
17
17
  import {increaseBalance} from "../index.js";
18
- import {BeaconStateAllForks, CachedBeaconStateAllForks, CachedBeaconStateElectra} from "../types.js";
18
+ import {
19
+ BeaconStateAllForks,
20
+ BeaconStatePreHeze,
21
+ CachedBeaconStateAllForks,
22
+ CachedBeaconStateElectra,
23
+ CachedBeaconStateGloas,
24
+ CachedBeaconStatePreHeze,
25
+ } from "../types.js";
19
26
  import {newFilledArray} from "./array.js";
20
27
  import {getTemporaryBlockHeader} from "./blockRoot.js";
21
28
  import {computeEpochAtSlot} from "./epoch.js";
@@ -87,7 +94,9 @@ export function getGenesisBeaconState(
87
94
  state.latestBlockHeader = ssz.phase0.BeaconBlockHeader.toViewDU(latestBlockHeader);
88
95
 
89
96
  // Ethereum 1.0 chain data
90
- state.eth1Data = ssz.phase0.Eth1Data.toViewDU(genesisEth1Data);
97
+ if (config.getForkSeq(GENESIS_SLOT) < ForkSeq.heze) {
98
+ (state as BeaconStatePreHeze).eth1Data = ssz.phase0.Eth1Data.toViewDU(genesisEth1Data);
99
+ }
91
100
  state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(randaoMixes);
92
101
 
93
102
  return state;
@@ -100,7 +109,9 @@ export function getGenesisBeaconState(
100
109
  * @param eth1BlockHash eth1 block hash
101
110
  */
102
111
  export function applyEth1BlockHash(state: CachedBeaconStateAllForks, eth1BlockHash: Bytes32): void {
103
- state.eth1Data.blockHash = eth1BlockHash;
112
+ if (state.config.getForkSeq(state.slot) < ForkSeq.heze) {
113
+ (state as CachedBeaconStatePreHeze).eth1Data.blockHash = eth1BlockHash;
114
+ }
104
115
  state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(newFilledArray(EPOCHS_PER_HISTORICAL_VECTOR, eth1BlockHash));
105
116
  }
106
117
 
@@ -134,36 +145,41 @@ export function applyDeposits(
134
145
  fullDepositDataRootList?: DepositDataRootViewDU
135
146
  ): {activatedValidatorCount: number} {
136
147
  const fork = config.getForkSeq(state.slot);
137
- const depositDataRootList: Root[] = [];
138
-
139
- const fullDepositDataRootArr = fullDepositDataRootList ? fullDepositDataRootList.getAllReadonlyValues() : null;
140
-
141
- if (fullDepositDataRootArr) {
142
- const depositCount = Number(state.eth1Data.depositCount);
143
- for (let index = 0; index < depositCount; index++) {
144
- depositDataRootList.push(fullDepositDataRootArr[index]);
148
+ if (fork >= ForkSeq.heze) {
149
+ // Genesis deposits do not use the removed legacy deposit tree.
150
+ for (const deposit of newDeposits) {
151
+ applyDeposit(fork, state, deposit.data);
145
152
  }
146
- }
153
+ } else {
154
+ const statePreHeze = state as CachedBeaconStatePreHeze;
155
+ const depositDataRootList: Root[] = [];
156
+ const fullDepositDataRootArr = fullDepositDataRootList ? fullDepositDataRootList.getAllReadonlyValues() : null;
147
157
 
148
- const initDepositCount = depositDataRootList.length;
149
- const depositDatas = fullDepositDataRootList ? null : newDeposits.map((deposit) => deposit.data);
150
- const {DepositData, DepositDataRootList} = ssz.phase0;
151
-
152
- for (const [index, deposit] of newDeposits.entries()) {
153
158
  if (fullDepositDataRootArr) {
154
- depositDataRootList.push(fullDepositDataRootArr[index + initDepositCount]);
155
- state.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(depositDataRootList);
156
- } else if (depositDatas) {
157
- const depositDataList = depositDatas.slice(0, index + 1);
158
- state.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(
159
- depositDataList.map((d) => DepositData.hashTreeRoot(d))
160
- );
159
+ const depositCount = Number(statePreHeze.eth1Data.depositCount);
160
+ for (let index = 0; index < depositCount; index++) {
161
+ depositDataRootList.push(fullDepositDataRootArr[index]);
162
+ }
161
163
  }
162
164
 
163
- state.eth1Data.depositCount += 1n;
165
+ const initDepositCount = depositDataRootList.length;
166
+ const depositDatas = fullDepositDataRootList ? null : newDeposits.map((deposit) => deposit.data);
167
+ const {DepositData, DepositDataRootList} = ssz.phase0;
168
+
169
+ for (const [index, deposit] of newDeposits.entries()) {
170
+ if (fullDepositDataRootArr) {
171
+ depositDataRootList.push(fullDepositDataRootArr[index + initDepositCount]);
172
+ statePreHeze.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(depositDataRootList);
173
+ } else if (depositDatas) {
174
+ const depositDataList = depositDatas.slice(0, index + 1);
175
+ statePreHeze.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(
176
+ depositDataList.map((d) => DepositData.hashTreeRoot(d))
177
+ );
178
+ }
164
179
 
165
- const fork = config.getForkSeq(GENESIS_SLOT);
166
- processDeposit(fork, state, deposit);
180
+ statePreHeze.eth1Data.depositCount += 1n;
181
+ processDeposit(fork, statePreHeze, deposit);
182
+ }
167
183
  }
168
184
 
169
185
  // Process deposit balance updates
@@ -178,7 +194,11 @@ export function applyDeposits(
178
194
  }
179
195
  increaseBalance(state, validatorIndex, amount);
180
196
  }
181
- stateElectra.pendingDeposits = ssz.electra.PendingDeposits.defaultViewDU();
197
+ if (fork >= ForkSeq.gloas) {
198
+ (state as CachedBeaconStateGloas).pendingDeposits = ssz.gloas.PendingDeposits.defaultViewDU();
199
+ } else {
200
+ stateElectra.pendingDeposits = ssz.electra.PendingDeposits.defaultViewDU();
201
+ }
182
202
  }
183
203
 
184
204
  // Process activations
@@ -316,7 +336,9 @@ export function initializeBeaconStateFromEth1(
316
336
  stateElectra.latestExecutionPayloadHeader =
317
337
  (executionPayloadHeader as CompositeViewDU<typeof ssz.electra.ExecutionPayloadHeader>) ??
318
338
  ssz.electra.ExecutionPayloadHeader.defaultViewDU();
319
- stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
339
+ if (fork < ForkSeq.heze) {
340
+ stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
341
+ }
320
342
  }
321
343
 
322
344
  if (fork >= ForkSeq.fulu) {
@@ -326,6 +348,10 @@ export function initializeBeaconStateFromEth1(
326
348
  stateFulu.latestExecutionPayloadHeader =
327
349
  (executionPayloadHeader as CompositeViewDU<typeof ssz.fulu.ExecutionPayloadHeader>) ??
328
350
  ssz.fulu.ExecutionPayloadHeader.defaultViewDU();
351
+ if (fork < ForkSeq.heze) {
352
+ // Fulu retires the legacy bridge after the genesis deposits.
353
+ stateFulu.depositRequestsStartIndex = BigInt(stateFulu.eth1DepositIndex);
354
+ }
329
355
  }
330
356
 
331
357
  if (fork >= ForkSeq.gloas) {