@lodestar/state-transition 1.46.0-dev.b22e48117e → 1.46.0-dev.b9d4e89e49
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/processExecutionPayloadBid.d.ts +2 -2
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +8 -3
- package/lib/block/processExecutionPayloadBid.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 +1 -0
- package/lib/cache/types.d.ts.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +6 -0
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/signatureSets/executionPayloadBid.d.ts +2 -2
- package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -1
- package/lib/signatureSets/executionPayloadBid.js +7 -5
- package/lib/signatureSets/executionPayloadBid.js.map +1 -1
- package/lib/slot/index.d.ts +1 -0
- package/lib/slot/index.d.ts.map +1 -1
- package/lib/slot/index.js +1 -0
- package/lib/slot/index.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts +7 -0
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -0
- package/lib/slot/upgradeStateToHeze.js +83 -0
- package/lib/slot/upgradeStateToHeze.js.map +1 -0
- package/lib/stateTransition.d.ts.map +1 -1
- package/lib/stateTransition.js +4 -1
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/interface.d.ts +8 -3
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js +4 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/testUtils/state.js +1 -1
- package/lib/testUtils/state.js.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/deposit.d.ts.map +1 -1
- package/lib/util/deposit.js +10 -8
- package/lib/util/deposit.js.map +1 -1
- package/lib/util/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +7 -2
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/validator.d.ts +5 -0
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +9 -0
- package/lib/util/validator.js.map +1 -1
- package/lib/util/weakSubjectivity.d.ts +1 -0
- package/lib/util/weakSubjectivity.d.ts.map +1 -1
- package/lib/util/weakSubjectivity.js +20 -8
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +7 -7
- package/src/block/processExecutionPayloadBid.ts +18 -8
- package/src/cache/stateCache.ts +2 -0
- package/src/cache/types.ts +1 -0
- package/src/index.ts +4 -0
- package/src/lightClient/spec/utils.ts +7 -0
- package/src/signatureSets/executionPayloadBid.ts +7 -9
- package/src/slot/index.ts +1 -0
- package/src/slot/upgradeStateToHeze.ts +91 -0
- package/src/stateTransition.ts +5 -0
- package/src/stateView/interface.ts +13 -2
- package/src/testUtils/state.ts +1 -1
- package/src/testUtils/util.ts +2 -2
- package/src/types.ts +2 -0
- package/src/util/deposit.ts +11 -9
- package/src/util/genesis.ts +8 -2
- package/src/util/validator.ts +17 -0
- package/src/util/weakSubjectivity.ts +61 -22
package/src/cache/stateCache.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
BeaconStateExecutions,
|
|
14
14
|
BeaconStateFulu,
|
|
15
15
|
BeaconStateGloas,
|
|
16
|
+
BeaconStateHeze,
|
|
16
17
|
BeaconStatePhase0,
|
|
17
18
|
} from "./types.js";
|
|
18
19
|
|
|
@@ -137,6 +138,7 @@ export type CachedBeaconStateDeneb = CachedBeaconState<BeaconStateDeneb>;
|
|
|
137
138
|
export type CachedBeaconStateElectra = CachedBeaconState<BeaconStateElectra>;
|
|
138
139
|
export type CachedBeaconStateFulu = CachedBeaconState<BeaconStateFulu>;
|
|
139
140
|
export type CachedBeaconStateGloas = CachedBeaconState<BeaconStateGloas>;
|
|
141
|
+
export type CachedBeaconStateHeze = CachedBeaconState<BeaconStateHeze>;
|
|
140
142
|
|
|
141
143
|
export type CachedBeaconStateAllForks = CachedBeaconState<BeaconStateAllForks>;
|
|
142
144
|
export type CachedBeaconStateExecutions = CachedBeaconState<BeaconStateExecutions>;
|
package/src/cache/types.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type BeaconStateDeneb = CompositeViewDU<SSZTypesFor<ForkName.deneb, "Beac
|
|
|
11
11
|
export type BeaconStateElectra = CompositeViewDU<SSZTypesFor<ForkName.electra, "BeaconState">>;
|
|
12
12
|
export type BeaconStateFulu = CompositeViewDU<SSZTypesFor<ForkName.fulu, "BeaconState">>;
|
|
13
13
|
export type BeaconStateGloas = CompositeViewDU<SSZTypesFor<ForkName.gloas, "BeaconState">>;
|
|
14
|
+
export type BeaconStateHeze = CompositeViewDU<SSZTypesFor<ForkName.heze, "BeaconState">>;
|
|
14
15
|
|
|
15
16
|
export type BeaconStateAllForks = CompositeViewDU<SSZTypesFor<ForkAll, "BeaconState">>;
|
|
16
17
|
export type BeaconStateExecutions = CompositeViewDU<SSZTypesFor<ForkPostBellatrix & ForkPreGloas, "BeaconState">>;
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ export {
|
|
|
52
52
|
type IBeaconStateViewElectra,
|
|
53
53
|
type IBeaconStateViewFulu,
|
|
54
54
|
type IBeaconStateViewGloas,
|
|
55
|
+
type IBeaconStateViewHeze,
|
|
55
56
|
isStatePostAltair,
|
|
56
57
|
isStatePostBellatrix,
|
|
57
58
|
isStatePostCapella,
|
|
@@ -59,6 +60,7 @@ export {
|
|
|
59
60
|
isStatePostElectra,
|
|
60
61
|
isStatePostFulu,
|
|
61
62
|
isStatePostGloas,
|
|
63
|
+
isStatePostHeze,
|
|
62
64
|
} from "./stateView/interface.js";
|
|
63
65
|
export {createBeaconStateView, createBeaconStateViewForHistoricalRegen} from "./stateView/stateViewFactory.js";
|
|
64
66
|
export type {
|
|
@@ -71,6 +73,7 @@ export type {
|
|
|
71
73
|
BeaconStateExecutions,
|
|
72
74
|
BeaconStateFulu,
|
|
73
75
|
BeaconStateGloas,
|
|
76
|
+
BeaconStateHeze,
|
|
74
77
|
// Non-cached states
|
|
75
78
|
BeaconStatePhase0,
|
|
76
79
|
CachedBeaconStateAllForks,
|
|
@@ -82,6 +85,7 @@ export type {
|
|
|
82
85
|
CachedBeaconStateExecutions,
|
|
83
86
|
CachedBeaconStateFulu,
|
|
84
87
|
CachedBeaconStateGloas,
|
|
88
|
+
CachedBeaconStateHeze,
|
|
85
89
|
CachedBeaconStatePhase0,
|
|
86
90
|
} from "./types.js";
|
|
87
91
|
export * from "./util/index.js";
|
|
@@ -263,6 +263,7 @@ export function upgradeLightClientHeader(
|
|
|
263
263
|
// Break if no further upgrades is required else fall through
|
|
264
264
|
if (ForkSeq[targetFork] <= ForkSeq.fulu) break;
|
|
265
265
|
|
|
266
|
+
// biome-ignore lint/suspicious/noFallthroughSwitchClause: We need fall-through behavior here
|
|
266
267
|
case ForkName.gloas:
|
|
267
268
|
if (isGloasLightClientHeader(upgradedHeader)) {
|
|
268
269
|
break;
|
|
@@ -272,6 +273,12 @@ export function upgradeLightClientHeader(
|
|
|
272
273
|
|
|
273
274
|
// Break if no further upgrades is required else fall through
|
|
274
275
|
if (ForkSeq[targetFork] <= ForkSeq.gloas) break;
|
|
276
|
+
|
|
277
|
+
case ForkName.heze:
|
|
278
|
+
// No changes to LightClientHeader in Heze
|
|
279
|
+
|
|
280
|
+
// Break if no further upgrades is required else fall through
|
|
281
|
+
if (ForkSeq[targetFork] <= ForkSeq.heze) break;
|
|
275
282
|
}
|
|
276
283
|
return upgradedHeader;
|
|
277
284
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
-
import {DOMAIN_BEACON_BUILDER} from "@lodestar/params";
|
|
3
|
-
import {
|
|
2
|
+
import {DOMAIN_BEACON_BUILDER, isForkPostGloas} from "@lodestar/params";
|
|
3
|
+
import {ExecutionPayloadBid, ssz, sszTypesFor} from "@lodestar/types";
|
|
4
4
|
import {computeSigningRoot} from "../util/index.js";
|
|
5
5
|
|
|
6
|
-
export function getExecutionPayloadBidSigningRoot(
|
|
7
|
-
config
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
): Uint8Array {
|
|
11
|
-
const domain = config.getDomain(stateSlot, DOMAIN_BEACON_BUILDER);
|
|
6
|
+
export function getExecutionPayloadBidSigningRoot(config: BeaconConfig, bid: ExecutionPayloadBid): Uint8Array {
|
|
7
|
+
const fork = config.getForkName(bid.slot);
|
|
8
|
+
const domain = config.getDomain(bid.slot, DOMAIN_BEACON_BUILDER);
|
|
9
|
+
const sszType = isForkPostGloas(fork) ? sszTypesFor(fork).ExecutionPayloadBid : ssz.gloas.ExecutionPayloadBid;
|
|
12
10
|
|
|
13
|
-
return computeSigningRoot(
|
|
11
|
+
return computeSigningRoot(sszType, bid, domain);
|
|
14
12
|
}
|
package/src/slot/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export {upgradeStateToDeneb} from "./upgradeStateToDeneb.js";
|
|
|
10
10
|
export {upgradeStateToElectra} from "./upgradeStateToElectra.js";
|
|
11
11
|
export {upgradeStateToFulu} from "./upgradeStateToFulu.js";
|
|
12
12
|
export {upgradeStateToGloas} from "./upgradeStateToGloas.js";
|
|
13
|
+
export {upgradeStateToHeze} from "./upgradeStateToHeze.js";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Dial state to next slot. Common for all forks
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
3
|
+
import {CachedBeaconStateGloas, CachedBeaconStateHeze} from "../types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Upgrade a state from Gloas to Heze.
|
|
7
|
+
* Spec: heze/fork.md `upgrade_to_heze`.
|
|
8
|
+
*/
|
|
9
|
+
export function upgradeStateToHeze(stateGloas: CachedBeaconStateGloas): CachedBeaconStateHeze {
|
|
10
|
+
const {config} = stateGloas;
|
|
11
|
+
|
|
12
|
+
ssz.gloas.BeaconState.commitViewDU(stateGloas);
|
|
13
|
+
const stateHezeCloned = stateGloas;
|
|
14
|
+
|
|
15
|
+
const stateHezeView = ssz.heze.BeaconState.defaultViewDU();
|
|
16
|
+
|
|
17
|
+
stateHezeView.genesisTime = stateHezeCloned.genesisTime;
|
|
18
|
+
stateHezeView.genesisValidatorsRoot = stateHezeCloned.genesisValidatorsRoot;
|
|
19
|
+
stateHezeView.slot = stateHezeCloned.slot;
|
|
20
|
+
stateHezeView.fork = ssz.phase0.Fork.toViewDU({
|
|
21
|
+
previousVersion: stateGloas.fork.currentVersion,
|
|
22
|
+
currentVersion: config.HEZE_FORK_VERSION,
|
|
23
|
+
epoch: stateGloas.epochCtx.epoch,
|
|
24
|
+
});
|
|
25
|
+
stateHezeView.latestBlockHeader = stateHezeCloned.latestBlockHeader;
|
|
26
|
+
stateHezeView.blockRoots = stateHezeCloned.blockRoots;
|
|
27
|
+
stateHezeView.stateRoots = stateHezeCloned.stateRoots;
|
|
28
|
+
stateHezeView.historicalRoots = stateHezeCloned.historicalRoots;
|
|
29
|
+
stateHezeView.eth1Data = stateHezeCloned.eth1Data;
|
|
30
|
+
stateHezeView.eth1DataVotes = stateHezeCloned.eth1DataVotes;
|
|
31
|
+
stateHezeView.eth1DepositIndex = stateHezeCloned.eth1DepositIndex;
|
|
32
|
+
stateHezeView.validators = stateHezeCloned.validators;
|
|
33
|
+
stateHezeView.balances = stateHezeCloned.balances;
|
|
34
|
+
stateHezeView.randaoMixes = stateHezeCloned.randaoMixes;
|
|
35
|
+
stateHezeView.slashings = stateHezeCloned.slashings;
|
|
36
|
+
stateHezeView.previousEpochParticipation = stateHezeCloned.previousEpochParticipation;
|
|
37
|
+
stateHezeView.currentEpochParticipation = stateHezeCloned.currentEpochParticipation;
|
|
38
|
+
stateHezeView.justificationBits = stateHezeCloned.justificationBits;
|
|
39
|
+
stateHezeView.previousJustifiedCheckpoint = stateHezeCloned.previousJustifiedCheckpoint;
|
|
40
|
+
stateHezeView.currentJustifiedCheckpoint = stateHezeCloned.currentJustifiedCheckpoint;
|
|
41
|
+
stateHezeView.finalizedCheckpoint = stateHezeCloned.finalizedCheckpoint;
|
|
42
|
+
stateHezeView.inactivityScores = stateHezeCloned.inactivityScores;
|
|
43
|
+
stateHezeView.currentSyncCommittee = stateHezeCloned.currentSyncCommittee;
|
|
44
|
+
stateHezeView.nextSyncCommittee = stateHezeCloned.nextSyncCommittee;
|
|
45
|
+
stateHezeView.latestBlockHash = stateHezeCloned.latestBlockHash;
|
|
46
|
+
stateHezeView.nextWithdrawalIndex = stateHezeCloned.nextWithdrawalIndex;
|
|
47
|
+
stateHezeView.nextWithdrawalValidatorIndex = stateHezeCloned.nextWithdrawalValidatorIndex;
|
|
48
|
+
stateHezeView.historicalSummaries = stateHezeCloned.historicalSummaries;
|
|
49
|
+
stateHezeView.depositRequestsStartIndex = stateHezeCloned.depositRequestsStartIndex;
|
|
50
|
+
stateHezeView.depositBalanceToConsume = stateHezeCloned.depositBalanceToConsume;
|
|
51
|
+
stateHezeView.exitBalanceToConsume = stateHezeCloned.exitBalanceToConsume;
|
|
52
|
+
stateHezeView.earliestExitEpoch = stateHezeCloned.earliestExitEpoch;
|
|
53
|
+
stateHezeView.consolidationBalanceToConsume = stateHezeCloned.consolidationBalanceToConsume;
|
|
54
|
+
stateHezeView.earliestConsolidationEpoch = stateHezeCloned.earliestConsolidationEpoch;
|
|
55
|
+
stateHezeView.pendingDeposits = stateHezeCloned.pendingDeposits;
|
|
56
|
+
stateHezeView.pendingPartialWithdrawals = stateHezeCloned.pendingPartialWithdrawals;
|
|
57
|
+
stateHezeView.pendingConsolidations = stateHezeCloned.pendingConsolidations;
|
|
58
|
+
stateHezeView.proposerLookahead = stateHezeCloned.proposerLookahead;
|
|
59
|
+
stateHezeView.builders = stateHezeCloned.builders;
|
|
60
|
+
stateHezeView.nextWithdrawalBuilderIndex = stateHezeCloned.nextWithdrawalBuilderIndex;
|
|
61
|
+
stateHezeView.executionPayloadAvailability = stateHezeCloned.executionPayloadAvailability;
|
|
62
|
+
stateHezeView.builderPendingPayments = stateHezeCloned.builderPendingPayments;
|
|
63
|
+
stateHezeView.builderPendingWithdrawals = stateHezeCloned.builderPendingWithdrawals;
|
|
64
|
+
|
|
65
|
+
// [Modified in Heze:EIP7805] inclusion_list_bits = Bitvector[INCLUSION_LIST_COMMITTEE_SIZE]() (default zero)
|
|
66
|
+
const oldBid = stateHezeCloned.latestExecutionPayloadBid;
|
|
67
|
+
const newBid = ssz.heze.ExecutionPayloadBid.defaultViewDU();
|
|
68
|
+
newBid.parentBlockHash = oldBid.parentBlockHash;
|
|
69
|
+
newBid.parentBlockRoot = oldBid.parentBlockRoot;
|
|
70
|
+
newBid.blockHash = oldBid.blockHash;
|
|
71
|
+
newBid.prevRandao = oldBid.prevRandao;
|
|
72
|
+
newBid.feeRecipient = oldBid.feeRecipient;
|
|
73
|
+
newBid.gasLimit = oldBid.gasLimit;
|
|
74
|
+
newBid.builderIndex = oldBid.builderIndex;
|
|
75
|
+
newBid.slot = oldBid.slot;
|
|
76
|
+
newBid.value = oldBid.value;
|
|
77
|
+
newBid.executionPayment = oldBid.executionPayment;
|
|
78
|
+
newBid.blobKzgCommitments = oldBid.blobKzgCommitments;
|
|
79
|
+
newBid.executionRequestsRoot = oldBid.executionRequestsRoot;
|
|
80
|
+
stateHezeView.latestExecutionPayloadBid = newBid;
|
|
81
|
+
|
|
82
|
+
stateHezeView.payloadExpectedWithdrawals = stateHezeCloned.payloadExpectedWithdrawals;
|
|
83
|
+
stateHezeView.ptcWindow = stateHezeCloned.ptcWindow;
|
|
84
|
+
|
|
85
|
+
const stateHeze = getCachedBeaconState(stateHezeView, stateGloas);
|
|
86
|
+
stateHeze.commit();
|
|
87
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
88
|
+
stateHeze["clearCache"]();
|
|
89
|
+
|
|
90
|
+
return stateHeze;
|
|
91
|
+
}
|
package/src/stateTransition.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
upgradeStateToDeneb,
|
|
17
17
|
upgradeStateToElectra,
|
|
18
18
|
upgradeStateToGloas,
|
|
19
|
+
upgradeStateToHeze,
|
|
19
20
|
} from "./slot/index.js";
|
|
20
21
|
import {upgradeStateToFulu} from "./slot/upgradeStateToFulu.js";
|
|
21
22
|
import {
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
CachedBeaconStateDeneb,
|
|
27
28
|
CachedBeaconStateElectra,
|
|
28
29
|
CachedBeaconStateFulu,
|
|
30
|
+
CachedBeaconStateGloas,
|
|
29
31
|
CachedBeaconStatePhase0,
|
|
30
32
|
} from "./types.js";
|
|
31
33
|
import {computeEpochAtSlot} from "./util/index.js";
|
|
@@ -278,6 +280,9 @@ function processSlotsWithTransientCache(
|
|
|
278
280
|
if (stateEpoch === config.GLOAS_FORK_EPOCH) {
|
|
279
281
|
postState = upgradeStateToGloas(postState as CachedBeaconStateFulu) as CachedBeaconStateAllForks;
|
|
280
282
|
}
|
|
283
|
+
if (stateEpoch === config.HEZE_FORK_EPOCH) {
|
|
284
|
+
postState = upgradeStateToHeze(postState as CachedBeaconStateGloas) as CachedBeaconStateAllForks;
|
|
285
|
+
}
|
|
281
286
|
|
|
282
287
|
{
|
|
283
288
|
const timer = metrics?.epochTransitionStepTime.startTimer({step: EpochTransitionStep.finalProcessEpoch});
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ForkPostElectra,
|
|
10
10
|
ForkPostFulu,
|
|
11
11
|
ForkPostGloas,
|
|
12
|
+
ForkPostHeze,
|
|
12
13
|
isForkPostAltair,
|
|
13
14
|
isForkPostBellatrix,
|
|
14
15
|
isForkPostCapella,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
isForkPostElectra,
|
|
17
18
|
isForkPostFulu,
|
|
18
19
|
isForkPostGloas,
|
|
20
|
+
isForkPostHeze,
|
|
19
21
|
} from "@lodestar/params";
|
|
20
22
|
import {
|
|
21
23
|
BeaconBlock,
|
|
@@ -267,14 +269,19 @@ export interface IBeaconStateViewGloas extends IBeaconStateViewFulu {
|
|
|
267
269
|
withParentPayloadApplied(executionRequests: gloas.ExecutionRequests): IBeaconStateViewGloas;
|
|
268
270
|
}
|
|
269
271
|
|
|
272
|
+
/** Heze+ state fields — use isStatePostHeze() guard */
|
|
273
|
+
export interface IBeaconStateViewHeze extends IBeaconStateViewGloas {
|
|
274
|
+
forkName: ForkPostHeze;
|
|
275
|
+
}
|
|
276
|
+
|
|
270
277
|
/**
|
|
271
278
|
* Type constraint for the concrete BeaconStateView class.
|
|
272
|
-
* Requires all fields from the latest fork interface (
|
|
279
|
+
* Requires all fields from the latest fork interface (IBeaconStateViewHeze) but keeps
|
|
273
280
|
* forkName as ForkName since the class wraps any fork's state.
|
|
274
281
|
* Sub-interfaces retain their narrowed forkName discriminants for caller-side type guards.
|
|
275
282
|
*/
|
|
276
283
|
export type IBeaconStateViewLatestFork = Omit<
|
|
277
|
-
|
|
284
|
+
IBeaconStateViewHeze,
|
|
278
285
|
"forkName" | "latestExecutionPayloadHeader" | "payloadBlockNumber"
|
|
279
286
|
> & {
|
|
280
287
|
forkName: ForkName;
|
|
@@ -337,3 +344,7 @@ export function isStatePostFulu(state: IBeaconStateView): state is IBeaconStateV
|
|
|
337
344
|
export function isStatePostGloas(state: IBeaconStateView): state is IBeaconStateViewGloas {
|
|
338
345
|
return isForkPostGloas(state.forkName);
|
|
339
346
|
}
|
|
347
|
+
|
|
348
|
+
export function isStatePostHeze(state: IBeaconStateView): state is IBeaconStateViewHeze {
|
|
349
|
+
return isForkPostHeze(state.forkName);
|
|
350
|
+
}
|
package/src/testUtils/state.ts
CHANGED
package/src/testUtils/util.ts
CHANGED
|
@@ -437,13 +437,13 @@ function buildPerformanceStatePhase0(pubkeysArg?: Uint8Array[]): phase0.BeaconSt
|
|
|
437
437
|
historicalRoots: [],
|
|
438
438
|
// Eth1
|
|
439
439
|
eth1Data: {
|
|
440
|
-
depositCount: pubkeys.length,
|
|
440
|
+
depositCount: BigInt(pubkeys.length),
|
|
441
441
|
depositRoot: fromHexString("0xcb1f89a924cfd31224823db5a41b1643f10faa7aedf231f1e28887f6ee98c047"),
|
|
442
442
|
blockHash: fromHexString("0x701fb2869ce16d0f1d14f6705725adb0dec6799da29006dfc6fff83960298f21"),
|
|
443
443
|
},
|
|
444
444
|
// minus one so that inserting 1 from block works
|
|
445
445
|
eth1DataVotes: newFilledArray(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH - 1, {
|
|
446
|
-
depositCount:
|
|
446
|
+
depositCount: 1n,
|
|
447
447
|
depositRoot: Buffer.alloc(32, 1),
|
|
448
448
|
blockHash: Buffer.alloc(32, 1),
|
|
449
449
|
}),
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type {
|
|
|
10
10
|
CachedBeaconStateExecutions,
|
|
11
11
|
CachedBeaconStateFulu,
|
|
12
12
|
CachedBeaconStateGloas,
|
|
13
|
+
CachedBeaconStateHeze,
|
|
13
14
|
CachedBeaconStatePhase0,
|
|
14
15
|
} from "./cache/stateCache.js";
|
|
15
16
|
export type {
|
|
@@ -22,6 +23,7 @@ export type {
|
|
|
22
23
|
BeaconStateExecutions,
|
|
23
24
|
BeaconStateFulu,
|
|
24
25
|
BeaconStateGloas,
|
|
26
|
+
BeaconStateHeze,
|
|
25
27
|
BeaconStatePhase0,
|
|
26
28
|
ShufflingGetter,
|
|
27
29
|
} from "./cache/types.js";
|
package/src/util/deposit.ts
CHANGED
|
@@ -4,19 +4,21 @@ import {CachedBeaconStateAllForks, CachedBeaconStateElectra} from "../types.js";
|
|
|
4
4
|
|
|
5
5
|
export function getEth1DepositCount(state: CachedBeaconStateAllForks, eth1Data?: phase0.Eth1Data): UintNum64 {
|
|
6
6
|
const eth1DataToUse = eth1Data ?? state.eth1Data;
|
|
7
|
+
// Proposer can set any value, use in bigint until the result is bounded by MAX_DEPOSITS
|
|
8
|
+
const depositCount = eth1DataToUse.depositCount;
|
|
9
|
+
const eth1DepositIndex = BigInt(state.eth1DepositIndex);
|
|
10
|
+
const maxDeposits = BigInt(MAX_DEPOSITS);
|
|
7
11
|
if (state.config.getForkSeq(state.slot) >= ForkSeq.electra) {
|
|
8
12
|
const electraState = state as CachedBeaconStateElectra;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const eth1DataIndexLimit: UintNum64 =
|
|
12
|
-
eth1DataToUse.depositCount < electraState.depositRequestsStartIndex
|
|
13
|
-
? eth1DataToUse.depositCount
|
|
14
|
-
: Number(electraState.depositRequestsStartIndex);
|
|
13
|
+
const eth1DataIndexLimit =
|
|
14
|
+
depositCount < electraState.depositRequestsStartIndex ? depositCount : electraState.depositRequestsStartIndex;
|
|
15
15
|
|
|
16
|
-
if (
|
|
17
|
-
|
|
16
|
+
if (eth1DepositIndex < eth1DataIndexLimit) {
|
|
17
|
+
const available = eth1DataIndexLimit - eth1DepositIndex;
|
|
18
|
+
return Number(available < maxDeposits ? available : maxDeposits);
|
|
18
19
|
}
|
|
19
20
|
return 0;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
const available = depositCount - eth1DepositIndex;
|
|
23
|
+
return Number(available < maxDeposits ? available : maxDeposits);
|
|
22
24
|
}
|
package/src/util/genesis.ts
CHANGED
|
@@ -139,7 +139,7 @@ export function applyDeposits(
|
|
|
139
139
|
const fullDepositDataRootArr = fullDepositDataRootList ? fullDepositDataRootList.getAllReadonlyValues() : null;
|
|
140
140
|
|
|
141
141
|
if (fullDepositDataRootArr) {
|
|
142
|
-
const depositCount = state.eth1Data.depositCount;
|
|
142
|
+
const depositCount = Number(state.eth1Data.depositCount);
|
|
143
143
|
for (let index = 0; index < depositCount; index++) {
|
|
144
144
|
depositDataRootList.push(fullDepositDataRootArr[index]);
|
|
145
145
|
}
|
|
@@ -160,7 +160,7 @@ export function applyDeposits(
|
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
state.eth1Data.depositCount +=
|
|
163
|
+
state.eth1Data.depositCount += 1n;
|
|
164
164
|
|
|
165
165
|
const fork = config.getForkSeq(GENESIS_SLOT);
|
|
166
166
|
processDeposit(fork, state, deposit);
|
|
@@ -334,6 +334,12 @@ export function initializeBeaconStateFromEth1(
|
|
|
334
334
|
stateGloas.fork.currentVersion = config.GLOAS_FORK_VERSION;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
if (fork >= ForkSeq.heze) {
|
|
338
|
+
const stateHeze = state as CompositeViewDU<typeof ssz.heze.BeaconState>;
|
|
339
|
+
stateHeze.fork.previousVersion = config.HEZE_FORK_VERSION;
|
|
340
|
+
stateHeze.fork.currentVersion = config.HEZE_FORK_VERSION;
|
|
341
|
+
}
|
|
342
|
+
|
|
337
343
|
state.commit();
|
|
338
344
|
|
|
339
345
|
return state;
|
package/src/util/validator.ts
CHANGED
|
@@ -128,6 +128,23 @@ export function getConsolidationChurnLimit(fork: ForkSeq, epochCtx: EpochCache):
|
|
|
128
128
|
return getBalanceChurnLimitFromCache(epochCtx) - getActivationExitChurnLimit(epochCtx);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// NOTE: duplicates the quotient/min choices in get{Exit,Activation,Consolidation}ChurnLimit.
|
|
132
|
+
export function getGloasChurnLimits(
|
|
133
|
+
config: ChainForkConfig,
|
|
134
|
+
totalActiveBalanceIncrements: number
|
|
135
|
+
): {exit: number; activation: number; consolidation: number} {
|
|
136
|
+
const exit = getBalanceChurnLimit(
|
|
137
|
+
totalActiveBalanceIncrements,
|
|
138
|
+
config.CHURN_LIMIT_QUOTIENT_GLOAS,
|
|
139
|
+
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
exit,
|
|
143
|
+
activation: Math.min(config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT_GLOAS, exit),
|
|
144
|
+
consolidation: getBalanceChurnLimit(totalActiveBalanceIncrements, config.CONSOLIDATION_CHURN_LIMIT_QUOTIENT, 0),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
131
148
|
export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): number {
|
|
132
149
|
// Compounding withdrawal credential only available since Electra
|
|
133
150
|
if (hasCompoundingWithdrawalCredential(withdrawalCredentials)) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {BeaconConfig, ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
|
+
ForkSeq,
|
|
4
5
|
MAX_DEPOSITS,
|
|
5
6
|
MAX_EFFECTIVE_BALANCE,
|
|
6
7
|
SLOTS_PER_EPOCH,
|
|
7
8
|
isForkPostElectra,
|
|
9
|
+
isForkPostGloas,
|
|
8
10
|
} from "@lodestar/params";
|
|
9
11
|
import {Epoch, Root, ssz} from "@lodestar/types";
|
|
10
12
|
import {Checkpoint} from "@lodestar/types/phase0";
|
|
@@ -14,10 +16,14 @@ import {BeaconStateAllForks, CachedBeaconStateAllForks} from "../types.js";
|
|
|
14
16
|
import {computeCheckpointEpochAtStateSlot, computeEpochAtSlot, getCurrentEpoch} from "./epoch.js";
|
|
15
17
|
import {getCurrentSlot} from "./slot.js";
|
|
16
18
|
import {
|
|
19
|
+
getActivationChurnLimit,
|
|
17
20
|
getActiveValidatorIndices,
|
|
18
21
|
getBalanceChurnLimit,
|
|
19
22
|
getBalanceChurnLimitFromCache,
|
|
20
23
|
getChurnLimit,
|
|
24
|
+
getConsolidationChurnLimit,
|
|
25
|
+
getExitChurnLimit,
|
|
26
|
+
getGloasChurnLimits,
|
|
21
27
|
} from "./validator.js";
|
|
22
28
|
|
|
23
29
|
export const ETH_TO_GWEI = 10 ** 9;
|
|
@@ -49,18 +55,26 @@ export function computeWeakSubjectivityPeriodCachedState(
|
|
|
49
55
|
const activeValidatorCount = state.epochCtx.currentShuffling.activeIndices.length;
|
|
50
56
|
const fork = config.getForkName(state.slot);
|
|
51
57
|
|
|
52
|
-
return
|
|
53
|
-
?
|
|
58
|
+
return isForkPostGloas(fork)
|
|
59
|
+
? computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
54
60
|
state.epochCtx.totalActiveBalanceIncrements,
|
|
55
|
-
|
|
61
|
+
getExitChurnLimit(state.epochCtx),
|
|
62
|
+
getActivationChurnLimit(state.epochCtx),
|
|
63
|
+
getConsolidationChurnLimit(ForkSeq.gloas, state.epochCtx),
|
|
56
64
|
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
57
65
|
)
|
|
58
|
-
:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
: isForkPostElectra(fork)
|
|
67
|
+
? computeWeakSubjectivityPeriodFromConstituentsElectra(
|
|
68
|
+
state.epochCtx.totalActiveBalanceIncrements,
|
|
69
|
+
getBalanceChurnLimitFromCache(state.epochCtx),
|
|
70
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
71
|
+
)
|
|
72
|
+
: computeWeakSubjectivityPeriodFromConstituentsPhase0(
|
|
73
|
+
activeValidatorCount,
|
|
74
|
+
state.epochCtx.totalActiveBalanceIncrements,
|
|
75
|
+
getChurnLimit(config, activeValidatorCount),
|
|
76
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
77
|
+
);
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
/**
|
|
@@ -80,22 +94,32 @@ export function computeWeakSubjectivityPeriod(config: ChainForkConfig, state: Be
|
|
|
80
94
|
totalActiveBalanceIncrements = 1;
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
const churnLimitsGloas = getGloasChurnLimits(config, totalActiveBalanceIncrements);
|
|
98
|
+
|
|
99
|
+
return isForkPostGloas(fork)
|
|
100
|
+
? computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
85
101
|
totalActiveBalanceIncrements,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
90
|
-
),
|
|
102
|
+
churnLimitsGloas.exit,
|
|
103
|
+
churnLimitsGloas.activation,
|
|
104
|
+
churnLimitsGloas.consolidation,
|
|
91
105
|
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
92
106
|
)
|
|
93
|
-
:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
: isForkPostElectra(fork)
|
|
108
|
+
? computeWeakSubjectivityPeriodFromConstituentsElectra(
|
|
109
|
+
totalActiveBalanceIncrements,
|
|
110
|
+
getBalanceChurnLimit(
|
|
111
|
+
totalActiveBalanceIncrements,
|
|
112
|
+
config.CHURN_LIMIT_QUOTIENT,
|
|
113
|
+
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
114
|
+
),
|
|
115
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
116
|
+
)
|
|
117
|
+
: computeWeakSubjectivityPeriodFromConstituentsPhase0(
|
|
118
|
+
activeIndices.length,
|
|
119
|
+
totalActiveBalanceIncrements,
|
|
120
|
+
getChurnLimit(config, activeIndices.length),
|
|
121
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
122
|
+
);
|
|
99
123
|
}
|
|
100
124
|
|
|
101
125
|
export function computeWeakSubjectivityPeriodFromConstituentsPhase0(
|
|
@@ -142,6 +166,21 @@ export function computeWeakSubjectivityPeriodFromConstituentsElectra(
|
|
|
142
166
|
return minWithdrawabilityDelay + epochsForValidatorSetChurn;
|
|
143
167
|
}
|
|
144
168
|
|
|
169
|
+
export function computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
170
|
+
totalBalanceByIncrement: number,
|
|
171
|
+
exitChurnLimit: number,
|
|
172
|
+
activationChurnLimit: number,
|
|
173
|
+
consolidationChurnLimit: number,
|
|
174
|
+
minWithdrawabilityDelay: number
|
|
175
|
+
): number {
|
|
176
|
+
// Keep t as increment for now. Multiply final result by EFFECTIVE_BALANCE_INCREMENT
|
|
177
|
+
const t = totalBalanceByIncrement;
|
|
178
|
+
const delta = Math.floor((2 * exitChurnLimit) / 3) + Math.floor(activationChurnLimit / 3) + consolidationChurnLimit;
|
|
179
|
+
const epochsForValidatorSetChurn = Math.floor(((SAFETY_DECAY * t) / (2 * delta * 100)) * EFFECTIVE_BALANCE_INCREMENT);
|
|
180
|
+
|
|
181
|
+
return minWithdrawabilityDelay + epochsForValidatorSetChurn;
|
|
182
|
+
}
|
|
183
|
+
|
|
145
184
|
export function getLatestBlockRoot(state: BeaconStateAllForks): Root {
|
|
146
185
|
const header = ssz.phase0.BeaconBlockHeader.clone(state.latestBlockHeader);
|
|
147
186
|
if (ssz.Root.equals(header.stateRoot, ZERO_HASH)) {
|