@lodestar/state-transition 1.50.0-dev.c24762bc60 → 1.50.0-dev.c785f2463a

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 (74) 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/cache/stateCache.d.ts +2 -1
  14. package/lib/cache/stateCache.d.ts.map +1 -1
  15. package/lib/cache/stateCache.js.map +1 -1
  16. package/lib/cache/types.d.ts +2 -1
  17. package/lib/cache/types.d.ts.map +1 -1
  18. package/lib/epoch/index.d.ts.map +1 -1
  19. package/lib/epoch/index.js +3 -1
  20. package/lib/epoch/index.js.map +1 -1
  21. package/lib/epoch/processEth1DataReset.d.ts +2 -2
  22. package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
  23. package/lib/epoch/processEth1DataReset.js.map +1 -1
  24. package/lib/index.d.ts +1 -1
  25. package/lib/index.d.ts.map +1 -1
  26. package/lib/index.js.map +1 -1
  27. package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
  28. package/lib/slot/upgradeStateToHeze.js +4 -4
  29. package/lib/slot/upgradeStateToHeze.js.map +1 -1
  30. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  31. package/lib/stateView/beaconStateView.js +3 -0
  32. package/lib/stateView/beaconStateView.js.map +1 -1
  33. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  34. package/lib/stateView/nativeBeaconStateView.js +4 -0
  35. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  36. package/lib/types.d.ts +2 -2
  37. package/lib/types.d.ts.map +1 -1
  38. package/lib/util/blindedBlock.d.ts +1 -1
  39. package/lib/util/blindedBlock.d.ts.map +1 -1
  40. package/lib/util/blindedBlock.js +5 -2
  41. package/lib/util/blindedBlock.js.map +1 -1
  42. package/lib/util/clock.d.ts +5 -0
  43. package/lib/util/clock.d.ts.map +1 -1
  44. package/lib/util/clock.js +19 -16
  45. package/lib/util/clock.js.map +1 -1
  46. package/lib/util/deposit.d.ts +2 -2
  47. package/lib/util/deposit.d.ts.map +1 -1
  48. package/lib/util/deposit.js.map +1 -1
  49. package/lib/util/genesis.d.ts.map +1 -1
  50. package/lib/util/genesis.js +40 -22
  51. package/lib/util/genesis.js.map +1 -1
  52. package/lib/util/slot.d.ts +3 -1
  53. package/lib/util/slot.d.ts.map +1 -1
  54. package/lib/util/slot.js +4 -0
  55. package/lib/util/slot.js.map +1 -1
  56. package/package.json +7 -7
  57. package/src/block/index.ts +4 -3
  58. package/src/block/processDeposit.ts +7 -2
  59. package/src/block/processEth1Data.ts +3 -3
  60. package/src/block/processOperations.ts +14 -11
  61. package/src/cache/stateCache.ts +2 -0
  62. package/src/cache/types.ts +2 -1
  63. package/src/epoch/index.ts +4 -1
  64. package/src/epoch/processEth1DataReset.ts +2 -2
  65. package/src/index.ts +2 -0
  66. package/src/slot/upgradeStateToHeze.ts +6 -4
  67. package/src/stateView/beaconStateView.ts +5 -1
  68. package/src/stateView/nativeBeaconStateView.ts +3 -0
  69. package/src/types.ts +2 -0
  70. package/src/util/blindedBlock.ts +8 -3
  71. package/src/util/clock.ts +25 -16
  72. package/src/util/deposit.ts +2 -2
  73. package/src/util/genesis.ts +45 -28
  74. package/src/util/slot.ts +6 -1
@@ -1,8 +1,8 @@
1
1
  import {ForkSeq, MAX_DEPOSITS} from "@lodestar/params";
2
2
  import {UintNum64, phase0} from "@lodestar/types";
3
- import {CachedBeaconStateAllForks, CachedBeaconStateElectra} from "../types.js";
3
+ import {CachedBeaconStateElectra, CachedBeaconStatePreHeze} from "../types.js";
4
4
 
5
- export function getEth1DepositCount(state: CachedBeaconStateAllForks, eth1Data?: phase0.Eth1Data): UintNum64 {
5
+ export function getEth1DepositCount(state: CachedBeaconStatePreHeze, eth1Data?: phase0.Eth1Data): UintNum64 {
6
6
  const eth1DataToUse = eth1Data ?? state.eth1Data;
7
7
  // Proposer can set any value, use in bigint until the result is bounded by MAX_DEPOSITS
8
8
  const depositCount = eth1DataToUse.depositCount;
@@ -11,15 +11,17 @@ 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
18
  import {
19
19
  BeaconStateAllForks,
20
+ BeaconStatePreHeze,
20
21
  CachedBeaconStateAllForks,
21
22
  CachedBeaconStateElectra,
22
23
  CachedBeaconStateGloas,
24
+ CachedBeaconStatePreHeze,
23
25
  } from "../types.js";
24
26
  import {newFilledArray} from "./array.js";
25
27
  import {getTemporaryBlockHeader} from "./blockRoot.js";
@@ -92,7 +94,9 @@ export function getGenesisBeaconState(
92
94
  state.latestBlockHeader = ssz.phase0.BeaconBlockHeader.toViewDU(latestBlockHeader);
93
95
 
94
96
  // Ethereum 1.0 chain data
95
- 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
+ }
96
100
  state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(randaoMixes);
97
101
 
98
102
  return state;
@@ -105,7 +109,9 @@ export function getGenesisBeaconState(
105
109
  * @param eth1BlockHash eth1 block hash
106
110
  */
107
111
  export function applyEth1BlockHash(state: CachedBeaconStateAllForks, eth1BlockHash: Bytes32): void {
108
- state.eth1Data.blockHash = eth1BlockHash;
112
+ if (state.config.getForkSeq(state.slot) < ForkSeq.heze) {
113
+ (state as CachedBeaconStatePreHeze).eth1Data.blockHash = eth1BlockHash;
114
+ }
109
115
  state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(newFilledArray(EPOCHS_PER_HISTORICAL_VECTOR, eth1BlockHash));
110
116
  }
111
117
 
@@ -139,36 +145,41 @@ export function applyDeposits(
139
145
  fullDepositDataRootList?: DepositDataRootViewDU
140
146
  ): {activatedValidatorCount: number} {
141
147
  const fork = config.getForkSeq(state.slot);
142
- const depositDataRootList: Root[] = [];
143
-
144
- const fullDepositDataRootArr = fullDepositDataRootList ? fullDepositDataRootList.getAllReadonlyValues() : null;
145
-
146
- if (fullDepositDataRootArr) {
147
- const depositCount = Number(state.eth1Data.depositCount);
148
- for (let index = 0; index < depositCount; index++) {
149
- 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);
150
152
  }
151
- }
153
+ } else {
154
+ const statePreHeze = state as CachedBeaconStatePreHeze;
155
+ const depositDataRootList: Root[] = [];
156
+ const fullDepositDataRootArr = fullDepositDataRootList ? fullDepositDataRootList.getAllReadonlyValues() : null;
152
157
 
153
- const initDepositCount = depositDataRootList.length;
154
- const depositDatas = fullDepositDataRootList ? null : newDeposits.map((deposit) => deposit.data);
155
- const {DepositData, DepositDataRootList} = ssz.phase0;
156
-
157
- for (const [index, deposit] of newDeposits.entries()) {
158
158
  if (fullDepositDataRootArr) {
159
- depositDataRootList.push(fullDepositDataRootArr[index + initDepositCount]);
160
- state.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(depositDataRootList);
161
- } else if (depositDatas) {
162
- const depositDataList = depositDatas.slice(0, index + 1);
163
- state.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(
164
- depositDataList.map((d) => DepositData.hashTreeRoot(d))
165
- );
159
+ const depositCount = Number(statePreHeze.eth1Data.depositCount);
160
+ for (let index = 0; index < depositCount; index++) {
161
+ depositDataRootList.push(fullDepositDataRootArr[index]);
162
+ }
166
163
  }
167
164
 
168
- 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
+ }
169
179
 
170
- const fork = config.getForkSeq(GENESIS_SLOT);
171
- processDeposit(fork, state, deposit);
180
+ statePreHeze.eth1Data.depositCount += 1n;
181
+ processDeposit(fork, statePreHeze, deposit);
182
+ }
172
183
  }
173
184
 
174
185
  // Process deposit balance updates
@@ -325,7 +336,9 @@ export function initializeBeaconStateFromEth1(
325
336
  stateElectra.latestExecutionPayloadHeader =
326
337
  (executionPayloadHeader as CompositeViewDU<typeof ssz.electra.ExecutionPayloadHeader>) ??
327
338
  ssz.electra.ExecutionPayloadHeader.defaultViewDU();
328
- stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
339
+ if (fork < ForkSeq.heze) {
340
+ stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
341
+ }
329
342
  }
330
343
 
331
344
  if (fork >= ForkSeq.fulu) {
@@ -335,6 +348,10 @@ export function initializeBeaconStateFromEth1(
335
348
  stateFulu.latestExecutionPayloadHeader =
336
349
  (executionPayloadHeader as CompositeViewDU<typeof ssz.fulu.ExecutionPayloadHeader>) ??
337
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
+ }
338
355
  }
339
356
 
340
357
  if (fork >= ForkSeq.gloas) {
package/src/util/slot.ts CHANGED
@@ -1,8 +1,13 @@
1
- import {ChainConfig} from "@lodestar/config";
1
+ import {ChainConfig, ChainForkConfig} from "@lodestar/config";
2
2
  import {GENESIS_SLOT} from "@lodestar/params";
3
3
  import {Epoch, Slot, TimeSeconds} from "@lodestar/types";
4
4
  import {computeEpochAtSlot, computeStartSlotAtEpoch} from "./epoch.js";
5
5
 
6
+ /** Slot duration in ms for a given slot */
7
+ export function getSlotDurationMs(config: ChainForkConfig, slot: Slot): number {
8
+ return config.getSlotDurationMs(config.getForkName(slot));
9
+ }
10
+
6
11
  export function getSlotsSinceGenesis(config: ChainConfig, genesisTime: TimeSeconds): Slot {
7
12
  const diffInSeconds = Date.now() / 1000 - genesisTime;
8
13
  return Math.floor(diffInSeconds / (config.SLOT_DURATION_MS / 1000));