@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.
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -1
- package/lib/block/index.js.map +1 -1
- package/lib/block/processDeposit.d.ts +2 -2
- package/lib/block/processDeposit.d.ts.map +1 -1
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processEth1Data.d.ts +3 -3
- package/lib/block/processEth1Data.d.ts.map +1 -1
- package/lib/block/processEth1Data.js.map +1 -1
- package/lib/block/processOperations.d.ts.map +1 -1
- package/lib/block/processOperations.js +8 -6
- package/lib/block/processOperations.js.map +1 -1
- package/lib/cache/stateCache.d.ts +2 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/types.d.ts +2 -1
- package/lib/cache/types.d.ts.map +1 -1
- package/lib/epoch/index.d.ts.map +1 -1
- package/lib/epoch/index.js +3 -1
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processEth1DataReset.d.ts +2 -2
- package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
- package/lib/epoch/processEth1DataReset.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
- package/lib/slot/upgradeStateToHeze.js +4 -4
- package/lib/slot/upgradeStateToHeze.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +3 -0
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +4 -0
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/types.d.ts +2 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/util/blindedBlock.d.ts +1 -1
- package/lib/util/blindedBlock.d.ts.map +1 -1
- package/lib/util/blindedBlock.js +5 -2
- package/lib/util/blindedBlock.js.map +1 -1
- package/lib/util/clock.d.ts +5 -0
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +19 -16
- package/lib/util/clock.js.map +1 -1
- package/lib/util/deposit.d.ts +2 -2
- package/lib/util/deposit.d.ts.map +1 -1
- package/lib/util/deposit.js.map +1 -1
- package/lib/util/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +40 -22
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/slot.d.ts +3 -1
- package/lib/util/slot.d.ts.map +1 -1
- package/lib/util/slot.js +4 -0
- package/lib/util/slot.js.map +1 -1
- package/package.json +7 -7
- package/src/block/index.ts +4 -3
- package/src/block/processDeposit.ts +7 -2
- package/src/block/processEth1Data.ts +3 -3
- package/src/block/processOperations.ts +14 -11
- package/src/cache/stateCache.ts +2 -0
- package/src/cache/types.ts +2 -1
- package/src/epoch/index.ts +4 -1
- package/src/epoch/processEth1DataReset.ts +2 -2
- package/src/index.ts +2 -0
- package/src/slot/upgradeStateToHeze.ts +6 -4
- package/src/stateView/beaconStateView.ts +5 -1
- package/src/stateView/nativeBeaconStateView.ts +3 -0
- package/src/types.ts +2 -0
- package/src/util/blindedBlock.ts +8 -3
- package/src/util/clock.ts +25 -16
- package/src/util/deposit.ts +2 -2
- package/src/util/genesis.ts +45 -28
- package/src/util/slot.ts +6 -1
package/src/util/deposit.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {ForkSeq, MAX_DEPOSITS} from "@lodestar/params";
|
|
2
2
|
import {UintNum64, phase0} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {CachedBeaconStateElectra, CachedBeaconStatePreHeze} from "../types.js";
|
|
4
4
|
|
|
5
|
-
export function getEth1DepositCount(state:
|
|
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;
|
package/src/util/genesis.ts
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
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
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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));
|