@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.
- package/lib/block/index.d.ts +1 -1
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +3 -3
- package/lib/block/index.js.map +1 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +3 -1
- package/lib/block/processAttestationsAltair.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 +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 +1 -1
- package/lib/block/processOperations.d.ts.map +1 -1
- package/lib/block/processOperations.js +9 -7
- package/lib/block/processOperations.js.map +1 -1
- package/lib/cache/epochCache.d.ts +5 -2
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +12 -5
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/epochTransitionCache.d.ts.map +1 -1
- package/lib/cache/epochTransitionCache.js +2 -1
- package/lib/cache/epochTransitionCache.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/syncCommitteeCache.d.ts +1 -1
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/cache/types.d.ts +2 -1
- package/lib/cache/types.d.ts.map +1 -1
- package/lib/epoch/getRewardsAndPenalties.d.ts.map +1 -1
- package/lib/epoch/getRewardsAndPenalties.js +9 -2
- package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
- package/lib/epoch/index.d.ts +2 -2
- package/lib/epoch/index.d.ts.map +1 -1
- package/lib/epoch/index.js +5 -3
- 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/epoch/processSyncCommitteeUpdates.js +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.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/lightClient/spec/store.d.ts +1 -1
- package/lib/lightClient/spec/store.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +1 -1
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/metrics.d.ts +1 -1
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +4 -4
- package/lib/metrics.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +1 -1
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +10 -3
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/signatureSets/inclusionList.d.ts +5 -0
- package/lib/signatureSets/inclusionList.d.ts.map +1 -0
- package/lib/signatureSets/inclusionList.js +14 -0
- package/lib/signatureSets/inclusionList.js.map +1 -0
- package/lib/signatureSets/index.d.ts +1 -0
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +1 -0
- package/lib/signatureSets/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/stateTransition.js +2 -2
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +2 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +11 -1
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +5 -4
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +16 -6
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +99 -25
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +5 -4
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/testUtils/interopPubkeyCache.js +1 -1
- package/lib/testUtils/interopPubkeyCache.js.map +1 -1
- package/lib/testUtils/state.d.ts.map +1 -1
- package/lib/testUtils/state.js +1 -1
- package/lib/testUtils/state.js.map +1 -1
- package/lib/testUtils/util.d.ts +1 -1
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +2 -2
- package/lib/testUtils/util.js.map +1 -1
- package/lib/types.d.ts +2 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/util/altair.d.ts +3 -1
- package/lib/util/altair.d.ts.map +1 -1
- package/lib/util/altair.js +7 -4
- package/lib/util/altair.js.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 +9 -14
- 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 +20 -17
- 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/epochShuffling.d.ts.map +1 -1
- package/lib/util/epochShuffling.js +1 -1
- package/lib/util/epochShuffling.js.map +1 -1
- package/lib/util/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +46 -23
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/inclusionListCommittee.d.ts +9 -0
- package/lib/util/inclusionListCommittee.d.ts.map +1 -0
- package/lib/util/inclusionListCommittee.js +18 -0
- package/lib/util/inclusionListCommittee.js.map +1 -0
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/interop.d.ts +1 -1
- package/lib/util/interop.d.ts.map +1 -1
- package/lib/util/interop.js +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/seed.js +1 -1
- package/lib/util/seed.js.map +1 -1
- package/lib/util/shuffling.d.ts +3 -0
- package/lib/util/shuffling.d.ts.map +1 -1
- package/lib/util/shuffling.js +41 -1
- package/lib/util/shuffling.js.map +1 -1
- package/lib/util/signatureSets.d.ts +1 -1
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +1 -1
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/slot.d.ts +18 -2
- package/lib/util/slot.d.ts.map +1 -1
- package/lib/util/slot.js +70 -6
- package/lib/util/slot.js.map +1 -1
- package/lib/util/syncCommittee.d.ts +4 -3
- package/lib/util/syncCommittee.d.ts.map +1 -1
- package/lib/util/syncCommittee.js +10 -8
- package/lib/util/syncCommittee.js.map +1 -1
- package/lib/util/validator.d.ts +1 -1
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +32 -11
- package/lib/util/validator.js.map +1 -1
- package/lib/util/weakSubjectivity.d.ts.map +1 -1
- package/lib/util/weakSubjectivity.js +4 -3
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +9 -9
- package/src/block/index.ts +15 -15
- package/src/block/processAttestationsAltair.ts +4 -1
- package/src/block/processDeposit.ts +9 -4
- package/src/block/processEth1Data.ts +3 -3
- package/src/block/processOperations.ts +19 -16
- package/src/cache/epochCache.ts +30 -6
- package/src/cache/epochTransitionCache.ts +2 -1
- package/src/cache/stateCache.ts +2 -0
- package/src/cache/syncCommitteeCache.ts +1 -1
- package/src/cache/types.ts +2 -1
- package/src/epoch/getRewardsAndPenalties.ts +11 -1
- package/src/epoch/index.ts +18 -16
- package/src/epoch/processEth1DataReset.ts +2 -2
- package/src/epoch/processSyncCommitteeUpdates.ts +1 -1
- package/src/index.ts +2 -0
- package/src/lightClient/spec/store.ts +1 -1
- package/src/lightClient/spec/utils.ts +1 -1
- package/src/lightClient/spec/validateLightClientUpdate.ts +1 -1
- package/src/metrics.ts +5 -4
- package/src/rewards/attestationsRewards.ts +13 -2
- package/src/rewards/syncCommitteeRewards.ts +1 -1
- package/src/signatureSets/inclusionList.ts +20 -0
- package/src/signatureSets/index.ts +1 -0
- package/src/slot/upgradeStateToHeze.ts +6 -4
- package/src/stateTransition.ts +2 -2
- package/src/stateView/beaconStateView.ts +14 -2
- package/src/stateView/interface.ts +5 -10
- package/src/stateView/nativeBeaconStateView.ts +100 -29
- package/src/stateView/stateViewFactory.ts +5 -4
- package/src/testUtils/interopPubkeyCache.ts +1 -1
- package/src/testUtils/state.ts +1 -1
- package/src/testUtils/util.ts +2 -2
- package/src/types.ts +2 -0
- package/src/util/altair.ts +15 -4
- package/src/util/blindedBlock.ts +12 -15
- package/src/util/clock.ts +26 -17
- package/src/util/deposit.ts +2 -2
- package/src/util/epochShuffling.ts +1 -1
- package/src/util/genesis.ts +56 -30
- package/src/util/inclusionListCommittee.ts +17 -0
- package/src/util/index.ts +1 -0
- package/src/util/interop.ts +1 -1
- package/src/util/seed.ts +1 -1
- package/src/util/shuffling.ts +46 -1
- package/src/util/signatureSets.ts +1 -1
- package/src/util/slot.ts +78 -8
- package/src/util/syncCommittee.ts +22 -10
- package/src/util/validator.ts +47 -20
- package/src/util/weakSubjectivity.ts +3 -3
package/src/util/genesis.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {ValidatorIndex} from "@lodestar/types";
|
|
2
|
+
|
|
3
|
+
/** Spec `InclusionListCommittee` of one slot */
|
|
4
|
+
export class InclusionListCommittee {
|
|
5
|
+
constructor(readonly validatorIndices: Uint32Array) {}
|
|
6
|
+
|
|
7
|
+
/** Positions of `validatorIndex`, several when the committee cycles over a slot with fewer validators than its size */
|
|
8
|
+
getCommitteeIndices(validatorIndex: ValidatorIndex): number[] {
|
|
9
|
+
const committeeIndices: number[] = [];
|
|
10
|
+
for (let i = 0; i < this.validatorIndices.length; i++) {
|
|
11
|
+
if (this.validatorIndices[i] === validatorIndex) {
|
|
12
|
+
committeeIndices.push(i);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return committeeIndices;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/util/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./execution.js";
|
|
|
17
17
|
export * from "./finality.js";
|
|
18
18
|
export * from "./genesis.js";
|
|
19
19
|
export * from "./gloas.js";
|
|
20
|
+
export * from "./inclusionListCommittee.js";
|
|
20
21
|
export * from "./interop.js";
|
|
21
22
|
export * from "./loadState/index.js";
|
|
22
23
|
export * from "./pendingDepositsLookup.js";
|
package/src/util/interop.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {toBufferBE} from "@vekexasia/bigint-buffer2";
|
|
2
2
|
import {digest} from "@chainsafe/as-sha256";
|
|
3
|
-
import {SecretKey} from "@
|
|
3
|
+
import {SecretKey} from "@lodestar/native/blst";
|
|
4
4
|
import {bytesToBigInt, intToBytes} from "@lodestar/utils";
|
|
5
5
|
|
|
6
6
|
let curveOrder: bigint;
|
package/src/util/seed.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
computePtcIndicesForEpoch,
|
|
4
4
|
computeProposerIndex as nativeComputeProposerIndex,
|
|
5
5
|
computeSyncCommitteeIndices as nativeComputeSyncCommitteeIndices,
|
|
6
|
-
} from "@
|
|
6
|
+
} from "@lodestar/native/shuffle";
|
|
7
7
|
import {
|
|
8
8
|
DOMAIN_BEACON_PROPOSER,
|
|
9
9
|
DOMAIN_PTC_ATTESTER,
|
package/src/util/shuffling.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ForkName, ForkSeq, SLOTS_PER_EPOCH, isForkPostFulu} from "@lodestar/params";
|
|
1
|
+
import {ForkName, ForkSeq, INCLUSION_LIST_COMMITTEE_SIZE, SLOTS_PER_EPOCH, isForkPostFulu} from "@lodestar/params";
|
|
2
2
|
import {
|
|
3
3
|
Attestation,
|
|
4
4
|
CommitteeIndex,
|
|
@@ -15,6 +15,7 @@ import {IBeaconStateView} from "../stateView/interface.js";
|
|
|
15
15
|
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
16
16
|
import {computeStartSlotAtEpoch} from "./epoch.js";
|
|
17
17
|
import {EpochShuffling} from "./epochShuffling.js";
|
|
18
|
+
import {InclusionListCommittee} from "./inclusionListCommittee.js";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Block root that decided the proposer shuffling for `proposalEpoch` (keys that shuffling).
|
|
@@ -196,6 +197,50 @@ export function getBeaconCommittee(epochShuffling: EpochShuffling, slot: Slot, i
|
|
|
196
197
|
return getBeaconCommittees(epochShuffling, slot, [index])[0];
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
/** Inclusion list committees of a shuffling by slot index, computed on first use and freed with the shuffling */
|
|
201
|
+
// TODO HEZE: replace this module-level map with an extended EpochShuffling tracked by the beacon-node ShufflingCache
|
|
202
|
+
const inclusionListCommitteesByShuffling = new WeakMap<EpochShuffling, InclusionListCommittee[]>();
|
|
203
|
+
|
|
204
|
+
/** Spec get_inclusion_list_committee: cycle over the slot's concatenated beacon committees */
|
|
205
|
+
export function getInclusionListCommittee(epochShuffling: EpochShuffling, slot: Slot): InclusionListCommittee {
|
|
206
|
+
let committees = inclusionListCommitteesByShuffling.get(epochShuffling);
|
|
207
|
+
if (committees === undefined) {
|
|
208
|
+
committees = [];
|
|
209
|
+
inclusionListCommitteesByShuffling.set(epochShuffling, committees);
|
|
210
|
+
}
|
|
211
|
+
const slotIndex = slot % SLOTS_PER_EPOCH;
|
|
212
|
+
let committee = committees[slotIndex];
|
|
213
|
+
if (committee === undefined) {
|
|
214
|
+
committee = new InclusionListCommittee(computeInclusionListCommittee(epochShuffling.committees[slotIndex]));
|
|
215
|
+
committees[slotIndex] = committee;
|
|
216
|
+
}
|
|
217
|
+
return committee;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function computeInclusionListCommittee(slotCommittees: Uint32Array[]): Uint32Array {
|
|
221
|
+
let totalLen = 0;
|
|
222
|
+
for (const committee of slotCommittees) {
|
|
223
|
+
totalLen += committee.length;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const result = new Uint32Array(INCLUSION_LIST_COMMITTEE_SIZE);
|
|
227
|
+
if (totalLen === 0) {
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
for (let i = 0; i < INCLUSION_LIST_COMMITTEE_SIZE; i++) {
|
|
232
|
+
let offset = i % totalLen;
|
|
233
|
+
for (const committee of slotCommittees) {
|
|
234
|
+
if (offset < committee.length) {
|
|
235
|
+
result[i] = committee[offset];
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
offset -= committee.length;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
|
|
199
244
|
/**
|
|
200
245
|
* Return a Uint32Array[] representing committees validator indices
|
|
201
246
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BLS_VERIFIER_SET_TYPE, type BlsSignatureSet, verifySignatureSets} from "@
|
|
1
|
+
import {BLS_VERIFIER_SET_TYPE, type BlsSignatureSet, verifySignatureSets} from "@lodestar/native/bls-verifier";
|
|
2
2
|
import {Root} from "@lodestar/types";
|
|
3
3
|
|
|
4
4
|
export enum SignatureSetType {
|
package/src/util/slot.ts
CHANGED
|
@@ -1,22 +1,92 @@
|
|
|
1
|
-
import {ChainConfig} from "@lodestar/config";
|
|
2
|
-
import {GENESIS_SLOT} from "@lodestar/params";
|
|
1
|
+
import {ChainConfig, ChainForkConfig} from "@lodestar/config";
|
|
2
|
+
import {GENESIS_EPOCH, 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
|
+
/**
|
|
7
|
+
* Slot durations with their activation epochs, derived from the configuration.
|
|
8
|
+
* A fork that changes the slot duration must add an entry here and in `ForkConfig.getSlotDurationMs`.
|
|
9
|
+
*/
|
|
10
|
+
export function getSlotDurations(config: ChainConfig): [Epoch, number][] {
|
|
11
|
+
const durations: [Epoch, number][] = [[GENESIS_EPOCH, config.SLOT_DURATION_MS]];
|
|
12
|
+
if (config.HEZE_FORK_EPOCH !== Infinity) {
|
|
13
|
+
durations.push([config.HEZE_FORK_EPOCH, config.SLOT_DURATION_MS_HEZE]);
|
|
14
|
+
}
|
|
15
|
+
return durations;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Slot duration in ms in effect at a given epoch */
|
|
19
|
+
export function getSlotDurationMsAtEpoch(config: ChainConfig, epoch: Epoch): number {
|
|
20
|
+
let slotDurationMs = config.SLOT_DURATION_MS;
|
|
21
|
+
for (const [forkEpoch, forkSlotDurationMs] of getSlotDurations(config)) {
|
|
22
|
+
if (epoch >= forkEpoch) {
|
|
23
|
+
slotDurationMs = forkSlotDurationMs;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return slotDurationMs;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Slot duration in ms for a given slot */
|
|
30
|
+
export function getSlotDurationMs(config: ChainForkConfig, slot: Slot): number {
|
|
31
|
+
return config.getSlotDurationMs(config.getForkName(slot));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function computeTimeAtSlotMs(config: ChainConfig, slot: Slot, genesisTimeMs: number): number {
|
|
35
|
+
let endSlot = slot;
|
|
36
|
+
let timeMs = genesisTimeMs;
|
|
37
|
+
for (const [forkEpoch, slotDurationMs] of getSlotDurations(config).reverse()) {
|
|
38
|
+
const forkSlot = computeStartSlotAtEpoch(forkEpoch);
|
|
39
|
+
if (forkSlot < endSlot) {
|
|
40
|
+
timeMs += (endSlot - forkSlot) * slotDurationMs;
|
|
41
|
+
endSlot = forkSlot;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Pre-genesis slots extrapolate linearly so the clock keeps ticking before genesis
|
|
45
|
+
return timeMs + (endSlot - GENESIS_SLOT) * getSlotDurationMsAtEpoch(config, GENESIS_EPOCH);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function computeTimeAtSlot(config: ChainConfig, slot: Slot, genesisTime: TimeSeconds): TimeSeconds {
|
|
49
|
+
return computeTimeAtSlotMs(config, slot, genesisTime * 1000) / 1000;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function computeSlotAtTimeMs(config: ChainConfig, timeMs: number, genesisTimeMs: number): Slot {
|
|
53
|
+
let startSlot = GENESIS_SLOT;
|
|
54
|
+
let startTimeMs = genesisTimeMs;
|
|
55
|
+
let slotDurationMs = getSlotDurationMsAtEpoch(config, GENESIS_EPOCH);
|
|
56
|
+
for (const [forkEpoch, forkSlotDurationMs] of getSlotDurations(config)) {
|
|
57
|
+
const forkSlot = computeStartSlotAtEpoch(forkEpoch);
|
|
58
|
+
const forkTimeMs = computeTimeAtSlotMs(config, forkSlot, genesisTimeMs);
|
|
59
|
+
if (timeMs >= forkTimeMs) {
|
|
60
|
+
startSlot = forkSlot;
|
|
61
|
+
startTimeMs = forkTimeMs;
|
|
62
|
+
slotDurationMs = forkSlotDurationMs;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return startSlot + Math.floor((timeMs - startTimeMs) / slotDurationMs);
|
|
66
|
+
}
|
|
67
|
+
|
|
6
68
|
export function getSlotsSinceGenesis(config: ChainConfig, genesisTime: TimeSeconds): Slot {
|
|
7
|
-
|
|
8
|
-
return Math.floor(diffInSeconds / (config.SLOT_DURATION_MS / 1000));
|
|
69
|
+
return computeSlotAtTimeMs(config, Date.now(), genesisTime * 1000) - GENESIS_SLOT;
|
|
9
70
|
}
|
|
10
71
|
|
|
11
72
|
export function getCurrentSlot(config: ChainConfig, genesisTime: TimeSeconds): Slot {
|
|
12
73
|
return GENESIS_SLOT + getSlotsSinceGenesis(config, genesisTime);
|
|
13
74
|
}
|
|
14
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Start epoch of the blob data retention window, preserving its wall-clock length
|
|
78
|
+
* across slot duration changes
|
|
79
|
+
*/
|
|
80
|
+
export function getBlobDataRetentionStartEpoch(config: ChainConfig, epoch: Epoch): Epoch {
|
|
81
|
+
const windowMs = config.MIN_BLOB_DATA_RETENTION_MS;
|
|
82
|
+
const currentStartMs = computeTimeAtSlotMs(config, computeStartSlotAtEpoch(epoch), 0);
|
|
83
|
+
if (currentStartMs < windowMs) {
|
|
84
|
+
return GENESIS_EPOCH;
|
|
85
|
+
}
|
|
86
|
+
return computeEpochAtSlot(computeSlotAtTimeMs(config, currentStartMs - windowMs, 0));
|
|
87
|
+
}
|
|
88
|
+
|
|
15
89
|
export function computeSlotsSinceEpochStart(slot: Slot, epoch?: Epoch): Slot {
|
|
16
90
|
const computeEpoch = epoch ?? computeEpochAtSlot(slot);
|
|
17
91
|
return slot - computeStartSlotAtEpoch(computeEpoch);
|
|
18
92
|
}
|
|
19
|
-
|
|
20
|
-
export function computeTimeAtSlot(config: ChainConfig, slot: Slot, genesisTime: TimeSeconds): TimeSeconds {
|
|
21
|
-
return genesisTime + slot * (config.SLOT_DURATION_MS / 1000);
|
|
22
|
-
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ChainConfig} from "@lodestar/config";
|
|
2
|
+
import {aggregateSerializedPublicKeys} from "@lodestar/native/blst";
|
|
2
3
|
import {
|
|
3
4
|
BASE_REWARD_FACTOR,
|
|
4
5
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
5
6
|
ForkSeq,
|
|
7
|
+
GENESIS_EPOCH,
|
|
6
8
|
SLOTS_PER_EPOCH,
|
|
7
9
|
SYNC_COMMITTEE_SIZE,
|
|
8
10
|
SYNC_REWARD_WEIGHT,
|
|
9
11
|
WEIGHT_DENOMINATOR,
|
|
10
12
|
} from "@lodestar/params";
|
|
11
|
-
import {altair} from "@lodestar/types";
|
|
13
|
+
import {Epoch, altair} from "@lodestar/types";
|
|
12
14
|
import {bigIntSqrt} from "@lodestar/utils";
|
|
13
15
|
import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
|
|
14
16
|
import {BeaconStateAllForks} from "../types.js";
|
|
15
17
|
import {getNextSyncCommitteeIndices} from "./seed.js";
|
|
18
|
+
import {getSlotDurationMsAtEpoch} from "./slot.js";
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* Return the sync committee for a given state and epoch.
|
|
@@ -45,11 +48,12 @@ export function getNextSyncCommittee(
|
|
|
45
48
|
/**
|
|
46
49
|
* Same logic in https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/specs/altair/beacon-chain.md#sync-committee-processing
|
|
47
50
|
*/
|
|
48
|
-
export function computeSyncParticipantReward(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
export function computeSyncParticipantReward(
|
|
52
|
+
config: ChainConfig,
|
|
53
|
+
epoch: Epoch,
|
|
54
|
+
totalActiveBalanceIncrements: number
|
|
55
|
+
): number {
|
|
56
|
+
const baseRewardPerIncrement = computeBaseRewardPerIncrement(config, epoch, totalActiveBalanceIncrements);
|
|
53
57
|
const totalBaseRewards = baseRewardPerIncrement * totalActiveBalanceIncrements;
|
|
54
58
|
const maxParticipantRewards = Math.floor(
|
|
55
59
|
Math.floor((totalBaseRewards * SYNC_REWARD_WEIGHT) / WEIGHT_DENOMINATOR) / SLOTS_PER_EPOCH
|
|
@@ -61,9 +65,17 @@ export function computeSyncParticipantReward(totalActiveBalanceIncrements: numbe
|
|
|
61
65
|
* Before we manage bigIntSqrt(totalActiveStake) as BigInt and return BigInt.
|
|
62
66
|
* bigIntSqrt(totalActiveStake) should fit a number (2 ** 53 -1 max)
|
|
63
67
|
**/
|
|
64
|
-
export function computeBaseRewardPerIncrement(
|
|
68
|
+
export function computeBaseRewardPerIncrement(
|
|
69
|
+
config: ChainConfig,
|
|
70
|
+
epoch: Epoch,
|
|
71
|
+
totalActiveStakeByIncrement: number
|
|
72
|
+
): number {
|
|
73
|
+
// Divide last so the exact slot duration ratio applies
|
|
74
|
+
const numerator = Math.floor(
|
|
75
|
+
(EFFECTIVE_BALANCE_INCREMENT * BASE_REWARD_FACTOR * getSlotDurationMsAtEpoch(config, epoch)) /
|
|
76
|
+
getSlotDurationMsAtEpoch(config, GENESIS_EPOCH)
|
|
77
|
+
);
|
|
65
78
|
return Math.floor(
|
|
66
|
-
(
|
|
67
|
-
Number(bigIntSqrt(BigInt(totalActiveStakeByIncrement) * BigInt(EFFECTIVE_BALANCE_INCREMENT)))
|
|
79
|
+
numerator / Number(bigIntSqrt(BigInt(totalActiveStakeByIncrement) * BigInt(EFFECTIVE_BALANCE_INCREMENT)))
|
|
68
80
|
);
|
|
69
81
|
}
|
package/src/util/validator.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {ChainForkConfig} from "@lodestar/config";
|
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
4
|
ForkSeq,
|
|
5
|
+
GENESIS_EPOCH,
|
|
5
6
|
MAX_EFFECTIVE_BALANCE,
|
|
6
7
|
MAX_EFFECTIVE_BALANCE_ELECTRA,
|
|
7
8
|
MIN_ACTIVATION_BALANCE,
|
|
@@ -11,6 +12,7 @@ import {intDiv} from "@lodestar/utils";
|
|
|
11
12
|
import {BeaconStateAllForks, CachedBeaconStateElectra, CachedBeaconStateGloas, EpochCache} from "../types.js";
|
|
12
13
|
import {hasEth1WithdrawalCredential} from "./capella.js";
|
|
13
14
|
import {hasCompoundingWithdrawalCredential, hasExecutionWithdrawalCredential} from "./electra.js";
|
|
15
|
+
import {getSlotDurationMsAtEpoch} from "./slot.js";
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Check if [[validator]] is active
|
|
@@ -93,23 +95,35 @@ export function getActivationExitChurnLimit(epochCtx: EpochCache): number {
|
|
|
93
95
|
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.6/specs/gloas/beacon-chain.md#new-get_activation_churn_limit
|
|
94
96
|
*/
|
|
95
97
|
export function getActivationChurnLimit(epochCtx: EpochCache): number {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const {config, epoch, totalActiveBalanceIncrements} = epochCtx;
|
|
99
|
+
const churnByBalance = Math.floor(
|
|
100
|
+
(totalActiveBalanceIncrements / config.CHURN_LIMIT_QUOTIENT_GLOAS) * EFFECTIVE_BALANCE_INCREMENT
|
|
101
|
+
);
|
|
102
|
+
const churn = Math.min(
|
|
103
|
+
config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT_GLOAS,
|
|
104
|
+
Math.max(churnByBalance, config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA)
|
|
100
105
|
);
|
|
101
|
-
|
|
106
|
+
// Scale by the slot duration ratio, rounding to the increment once after scaling
|
|
107
|
+
const scaled = Math.floor(
|
|
108
|
+
(churn * getSlotDurationMsAtEpoch(config, epoch)) / getSlotDurationMsAtEpoch(config, GENESIS_EPOCH)
|
|
109
|
+
);
|
|
110
|
+
return scaled - (scaled % EFFECTIVE_BALANCE_INCREMENT);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
/**
|
|
105
114
|
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.6/specs/gloas/beacon-chain.md#new-get_exit_churn_limit
|
|
106
115
|
*/
|
|
107
116
|
export function getExitChurnLimit(epochCtx: EpochCache): number {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
const {config, epoch, totalActiveBalanceIncrements} = epochCtx;
|
|
118
|
+
const churnByBalance = Math.floor(
|
|
119
|
+
(totalActiveBalanceIncrements / config.CHURN_LIMIT_QUOTIENT_GLOAS) * EFFECTIVE_BALANCE_INCREMENT
|
|
120
|
+
);
|
|
121
|
+
const churn = Math.max(churnByBalance, config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA);
|
|
122
|
+
// Scale by the slot duration ratio, rounding to the increment once after scaling
|
|
123
|
+
const scaled = Math.floor(
|
|
124
|
+
(churn * getSlotDurationMsAtEpoch(config, epoch)) / getSlotDurationMsAtEpoch(config, GENESIS_EPOCH)
|
|
112
125
|
);
|
|
126
|
+
return scaled - (scaled % EFFECTIVE_BALANCE_INCREMENT);
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
/**
|
|
@@ -118,12 +132,16 @@ export function getExitChurnLimit(epochCtx: EpochCache): number {
|
|
|
118
132
|
*/
|
|
119
133
|
export function getConsolidationChurnLimit(fork: ForkSeq, epochCtx: EpochCache): number {
|
|
120
134
|
if (fork >= ForkSeq.gloas) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
0
|
|
135
|
+
const {config, epoch, totalActiveBalanceIncrements} = epochCtx;
|
|
136
|
+
// No MIN floor in gloas
|
|
137
|
+
const churn = Math.floor(
|
|
138
|
+
(totalActiveBalanceIncrements / config.CONSOLIDATION_CHURN_LIMIT_QUOTIENT) * EFFECTIVE_BALANCE_INCREMENT
|
|
126
139
|
);
|
|
140
|
+
// Scale by the slot duration ratio, rounding to the increment once after scaling
|
|
141
|
+
const scaled = Math.floor(
|
|
142
|
+
(churn * getSlotDurationMsAtEpoch(config, epoch)) / getSlotDurationMsAtEpoch(config, GENESIS_EPOCH)
|
|
143
|
+
);
|
|
144
|
+
return scaled - (scaled % EFFECTIVE_BALANCE_INCREMENT);
|
|
127
145
|
}
|
|
128
146
|
return getBalanceChurnLimitFromCache(epochCtx) - getActivationExitChurnLimit(epochCtx);
|
|
129
147
|
}
|
|
@@ -131,17 +149,26 @@ export function getConsolidationChurnLimit(fork: ForkSeq, epochCtx: EpochCache):
|
|
|
131
149
|
// NOTE: duplicates the quotient/min choices in get{Exit,Activation,Consolidation}ChurnLimit.
|
|
132
150
|
export function getGloasChurnLimits(
|
|
133
151
|
config: ChainForkConfig,
|
|
152
|
+
epoch: Epoch,
|
|
134
153
|
totalActiveBalanceIncrements: number
|
|
135
154
|
): {exit: number; activation: number; consolidation: number} {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
155
|
+
const ratioNumerator = getSlotDurationMsAtEpoch(config, epoch);
|
|
156
|
+
const ratioDenominator = getSlotDurationMsAtEpoch(config, GENESIS_EPOCH);
|
|
157
|
+
const exitUnscaled = Math.max(
|
|
158
|
+
Math.floor((totalActiveBalanceIncrements / config.CHURN_LIMIT_QUOTIENT_GLOAS) * EFFECTIVE_BALANCE_INCREMENT),
|
|
139
159
|
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
140
160
|
);
|
|
161
|
+
const activationUnscaled = Math.min(config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT_GLOAS, exitUnscaled);
|
|
162
|
+
const consolidationUnscaled = Math.floor(
|
|
163
|
+
(totalActiveBalanceIncrements / config.CONSOLIDATION_CHURN_LIMIT_QUOTIENT) * EFFECTIVE_BALANCE_INCREMENT
|
|
164
|
+
);
|
|
165
|
+
const exit = Math.floor((exitUnscaled * ratioNumerator) / ratioDenominator);
|
|
166
|
+
const activation = Math.floor((activationUnscaled * ratioNumerator) / ratioDenominator);
|
|
167
|
+
const consolidation = Math.floor((consolidationUnscaled * ratioNumerator) / ratioDenominator);
|
|
141
168
|
return {
|
|
142
|
-
exit,
|
|
143
|
-
activation:
|
|
144
|
-
consolidation:
|
|
169
|
+
exit: exit - (exit % EFFECTIVE_BALANCE_INCREMENT),
|
|
170
|
+
activation: activation - (activation % EFFECTIVE_BALANCE_INCREMENT),
|
|
171
|
+
consolidation: consolidation - (consolidation % EFFECTIVE_BALANCE_INCREMENT),
|
|
145
172
|
};
|
|
146
173
|
}
|
|
147
174
|
|
|
@@ -2,7 +2,6 @@ import {ChainForkConfig} from "@lodestar/config";
|
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
4
|
ForkSeq,
|
|
5
|
-
GENESIS_SLOT,
|
|
6
5
|
MAX_DEPOSITS,
|
|
7
6
|
MAX_EFFECTIVE_BALANCE,
|
|
8
7
|
SLOTS_PER_EPOCH,
|
|
@@ -13,6 +12,7 @@ import {Epoch, Root, Slot, TimeSeconds, ssz} from "@lodestar/types";
|
|
|
13
12
|
import {ZERO_HASH} from "../constants/constants.js";
|
|
14
13
|
import {BeaconStateAllForks, CachedBeaconStateAllForks} from "../types.js";
|
|
15
14
|
import {computeCheckpointEpochAtStateSlot, computeEpochAtSlot, getCurrentEpoch} from "./epoch.js";
|
|
15
|
+
import {computeSlotAtTimeMs} from "./slot.js";
|
|
16
16
|
import {StateBytesMetadata, getStateTypeFromBytes, scanActiveValidatorsFromStateBytes} from "./sszBytes.js";
|
|
17
17
|
import {
|
|
18
18
|
getActivationChurnLimit,
|
|
@@ -107,7 +107,7 @@ function computeWeakSubjectivityPeriodFromActiveValidators(
|
|
|
107
107
|
): number {
|
|
108
108
|
const fork = config.getForkName(slot);
|
|
109
109
|
|
|
110
|
-
const churnLimitsGloas = getGloasChurnLimits(config, totalActiveBalanceIncrements);
|
|
110
|
+
const churnLimitsGloas = getGloasChurnLimits(config, computeEpochAtSlot(slot), totalActiveBalanceIncrements);
|
|
111
111
|
|
|
112
112
|
return isForkPostGloas(fork)
|
|
113
113
|
? computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
@@ -223,6 +223,6 @@ export function isWithinWeakSubjectivityPeriodFromSummary(
|
|
|
223
223
|
summary: WeakSubjectivitySummary,
|
|
224
224
|
now: TimeSeconds = Date.now() / 1000
|
|
225
225
|
): boolean {
|
|
226
|
-
const clockSlot =
|
|
226
|
+
const clockSlot = computeSlotAtTimeMs(config, now * 1000, summary.genesisTime * 1000);
|
|
227
227
|
return computeEpochAtSlot(clockSlot) <= summary.checkpointEpoch + summary.period;
|
|
228
228
|
}
|