@lodestar/state-transition 1.35.0-dev.47c570ab76 → 1.35.0-dev.549f58dd39
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/externalData.d.ts.map +1 -0
- package/lib/block/index.d.ts.map +1 -0
- package/lib/block/initiateValidatorExit.d.ts.map +1 -0
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -0
- package/lib/block/processAttestationPhase0.d.ts.map +1 -0
- package/lib/block/processAttestations.d.ts.map +1 -0
- package/lib/block/processAttestationsAltair.d.ts.map +1 -0
- package/lib/block/processAttesterSlashing.d.ts.map +1 -0
- package/lib/block/processBlobKzgCommitments.d.ts.map +1 -0
- package/lib/block/processBlockHeader.d.ts.map +1 -0
- package/lib/block/processBlsToExecutionChange.d.ts.map +1 -0
- package/lib/block/processConsolidationRequest.d.ts.map +1 -0
- package/lib/block/processDeposit.d.ts.map +1 -0
- package/lib/block/processDepositRequest.d.ts.map +1 -0
- package/lib/block/processEth1Data.d.ts.map +1 -0
- package/lib/block/processExecutionPayload.d.ts.map +1 -0
- package/lib/block/processOperations.d.ts.map +1 -0
- package/lib/block/processProposerSlashing.d.ts.map +1 -0
- package/lib/block/processRandao.d.ts.map +1 -0
- package/lib/block/processSyncCommittee.d.ts.map +1 -0
- package/lib/block/processVoluntaryExit.d.ts.map +1 -0
- package/lib/block/processWithdrawalRequest.d.ts.map +1 -0
- package/lib/block/processWithdrawals.d.ts.map +1 -0
- package/lib/block/slashValidator.d.ts.map +1 -0
- package/lib/block/types.d.ts.map +1 -0
- package/lib/cache/effectiveBalanceIncrements.d.ts.map +1 -0
- package/lib/cache/epochCache.d.ts.map +1 -0
- package/lib/cache/epochTransitionCache.d.ts.map +1 -0
- package/lib/cache/pubkeyCache.d.ts.map +1 -0
- package/lib/cache/rewardCache.d.ts.map +1 -0
- package/lib/cache/stateCache.d.ts.map +1 -0
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -0
- package/lib/cache/types.d.ts.map +1 -0
- package/lib/constants/constants.d.ts.map +1 -0
- package/lib/constants/index.d.ts.map +1 -0
- package/lib/epoch/computeUnrealizedCheckpoints.d.ts.map +1 -0
- package/lib/epoch/getAttestationDeltas.d.ts.map +1 -0
- package/lib/epoch/getRewardsAndPenalties.d.ts.map +1 -0
- package/lib/epoch/index.d.ts.map +1 -0
- package/lib/epoch/processEffectiveBalanceUpdates.d.ts.map +1 -0
- package/lib/epoch/processEth1DataReset.d.ts.map +1 -0
- package/lib/epoch/processHistoricalRootsUpdate.d.ts.map +1 -0
- package/lib/epoch/processHistoricalSummariesUpdate.d.ts.map +1 -0
- package/lib/epoch/processInactivityUpdates.d.ts.map +1 -0
- package/lib/epoch/processJustificationAndFinalization.d.ts.map +1 -0
- package/lib/epoch/processParticipationFlagUpdates.d.ts.map +1 -0
- package/lib/epoch/processParticipationRecordUpdates.d.ts.map +1 -0
- package/lib/epoch/processPendingAttestations.d.ts.map +1 -0
- package/lib/epoch/processPendingConsolidations.d.ts.map +1 -0
- package/lib/epoch/processPendingDeposits.d.ts.map +1 -0
- package/lib/epoch/processProposerLookahead.d.ts.map +1 -0
- package/lib/epoch/processRandaoMixesReset.d.ts.map +1 -0
- package/lib/epoch/processRegistryUpdates.d.ts.map +1 -0
- package/lib/epoch/processRewardsAndPenalties.d.ts.map +1 -0
- package/lib/epoch/processSlashings.d.ts.map +1 -0
- package/lib/epoch/processSlashingsReset.d.ts.map +1 -0
- package/lib/epoch/processSyncCommitteeUpdates.d.ts.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/metrics.d.ts.map +1 -0
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -0
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -0
- package/lib/signatureSets/index.d.ts.map +1 -0
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -0
- package/lib/signatureSets/proposer.d.ts.map +1 -0
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -0
- package/lib/signatureSets/randao.d.ts.map +1 -0
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -0
- package/lib/slot/index.d.ts.map +1 -0
- package/lib/slot/upgradeStateToAltair.d.ts.map +1 -0
- package/lib/slot/upgradeStateToBellatrix.d.ts.map +1 -0
- package/lib/slot/upgradeStateToCapella.d.ts.map +1 -0
- package/lib/slot/upgradeStateToDeneb.d.ts.map +1 -0
- package/lib/slot/upgradeStateToElectra.d.ts.map +1 -0
- package/lib/slot/upgradeStateToFulu.d.ts.map +1 -0
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -0
- package/lib/stateTransition.d.ts.map +1 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/util/aggregator.d.ts.map +1 -0
- package/lib/util/altair.d.ts.map +1 -0
- package/lib/util/array.d.ts.map +1 -0
- package/lib/util/attestation.d.ts.map +1 -0
- package/lib/util/attesterStatus.d.ts.map +1 -0
- package/lib/util/balance.d.ts.map +1 -0
- package/lib/util/blindedBlock.d.ts.map +1 -0
- package/lib/util/blockRoot.d.ts.map +1 -0
- package/lib/util/calculateCommitteeAssignments.d.ts.map +1 -0
- package/lib/util/capella.d.ts.map +1 -0
- package/lib/util/computeAnchorCheckpoint.d.ts.map +1 -0
- package/lib/util/deposit.d.ts.map +1 -0
- package/lib/util/domain.d.ts.map +1 -0
- package/lib/util/electra.d.ts.map +1 -0
- package/lib/util/epoch.d.ts.map +1 -0
- package/lib/util/epochShuffling.d.ts.map +1 -0
- package/lib/util/execution.d.ts.map +1 -0
- package/lib/util/finality.d.ts.map +1 -0
- package/lib/util/fulu.d.ts.map +1 -0
- package/lib/util/genesis.d.ts.map +1 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/interop.d.ts.map +1 -0
- package/lib/util/loadState/findModifiedInactivityScores.d.ts.map +1 -0
- package/lib/util/loadState/findModifiedValidators.d.ts.map +1 -0
- package/lib/util/loadState/index.d.ts.map +1 -0
- package/lib/util/loadState/loadState.d.ts.map +1 -0
- package/lib/util/loadState/loadValidator.d.ts.map +1 -0
- package/lib/util/rootCache.d.ts.map +1 -0
- package/lib/util/seed.d.ts.map +1 -0
- package/lib/util/shufflingDecisionRoot.d.ts.map +1 -0
- package/lib/util/signatureSets.d.ts.map +1 -0
- package/lib/util/signingRoot.d.ts.map +1 -0
- package/lib/util/slot.d.ts +0 -1
- package/lib/util/slot.d.ts.map +1 -0
- package/lib/util/slot.js +1 -5
- package/lib/util/slot.js.map +1 -1
- package/lib/util/sszBytes.d.ts.map +1 -0
- package/lib/util/syncCommittee.d.ts.map +1 -0
- package/lib/util/targetUnslashedBalance.d.ts.map +1 -0
- package/lib/util/validator.d.ts.map +1 -0
- package/lib/util/weakSubjectivity.d.ts.map +1 -0
- package/package.json +9 -11
- package/src/block/externalData.ts +26 -0
- package/src/block/index.ts +81 -0
- package/src/block/initiateValidatorExit.ts +62 -0
- package/src/block/isValidIndexedAttestation.ts +70 -0
- package/src/block/processAttestationPhase0.ts +158 -0
- package/src/block/processAttestations.ts +25 -0
- package/src/block/processAttestationsAltair.ts +184 -0
- package/src/block/processAttesterSlashing.ts +59 -0
- package/src/block/processBlobKzgCommitments.ts +21 -0
- package/src/block/processBlockHeader.ts +54 -0
- package/src/block/processBlsToExecutionChange.ts +78 -0
- package/src/block/processConsolidationRequest.ts +147 -0
- package/src/block/processDeposit.ts +166 -0
- package/src/block/processDepositRequest.ts +19 -0
- package/src/block/processEth1Data.ts +86 -0
- package/src/block/processExecutionPayload.ts +84 -0
- package/src/block/processOperations.ts +83 -0
- package/src/block/processProposerSlashing.ts +66 -0
- package/src/block/processRandao.ts +27 -0
- package/src/block/processSyncCommittee.ts +117 -0
- package/src/block/processVoluntaryExit.ts +55 -0
- package/src/block/processWithdrawalRequest.ts +98 -0
- package/src/block/processWithdrawals.ts +207 -0
- package/src/block/slashValidator.ts +98 -0
- package/src/block/types.ts +9 -0
- package/src/cache/effectiveBalanceIncrements.ts +39 -0
- package/src/cache/epochCache.ts +1213 -0
- package/src/cache/epochTransitionCache.ts +542 -0
- package/src/cache/pubkeyCache.ts +33 -0
- package/src/cache/rewardCache.ts +19 -0
- package/src/cache/stateCache.ts +268 -0
- package/src/cache/syncCommitteeCache.ts +96 -0
- package/src/cache/types.ts +18 -0
- package/src/constants/constants.ts +12 -0
- package/src/constants/index.ts +1 -0
- package/src/epoch/computeUnrealizedCheckpoints.ts +55 -0
- package/src/epoch/getAttestationDeltas.ts +169 -0
- package/src/epoch/getRewardsAndPenalties.ts +137 -0
- package/src/epoch/index.ts +202 -0
- package/src/epoch/processEffectiveBalanceUpdates.ts +111 -0
- package/src/epoch/processEth1DataReset.ts +17 -0
- package/src/epoch/processHistoricalRootsUpdate.ts +25 -0
- package/src/epoch/processHistoricalSummariesUpdate.ts +23 -0
- package/src/epoch/processInactivityUpdates.ts +60 -0
- package/src/epoch/processJustificationAndFinalization.ts +90 -0
- package/src/epoch/processParticipationFlagUpdates.ts +27 -0
- package/src/epoch/processParticipationRecordUpdates.ts +14 -0
- package/src/epoch/processPendingAttestations.ts +75 -0
- package/src/epoch/processPendingConsolidations.ts +59 -0
- package/src/epoch/processPendingDeposits.ts +136 -0
- package/src/epoch/processProposerLookahead.ts +39 -0
- package/src/epoch/processRandaoMixesReset.ts +18 -0
- package/src/epoch/processRegistryUpdates.ts +65 -0
- package/src/epoch/processRewardsAndPenalties.ts +58 -0
- package/src/epoch/processSlashings.ts +97 -0
- package/src/epoch/processSlashingsReset.ts +20 -0
- package/src/epoch/processSyncCommitteeUpdates.ts +44 -0
- package/src/index.ts +67 -0
- package/src/metrics.ts +169 -0
- package/src/signatureSets/attesterSlashings.ts +39 -0
- package/src/signatureSets/blsToExecutionChange.ts +43 -0
- package/src/signatureSets/index.ts +73 -0
- package/src/signatureSets/indexedAttestation.ts +51 -0
- package/src/signatureSets/proposer.ts +47 -0
- package/src/signatureSets/proposerSlashings.ts +41 -0
- package/src/signatureSets/randao.ts +31 -0
- package/src/signatureSets/voluntaryExits.ts +44 -0
- package/src/slot/index.ts +32 -0
- package/src/slot/upgradeStateToAltair.ts +149 -0
- package/src/slot/upgradeStateToBellatrix.ts +63 -0
- package/src/slot/upgradeStateToCapella.ts +71 -0
- package/src/slot/upgradeStateToDeneb.ts +40 -0
- package/src/slot/upgradeStateToElectra.ts +126 -0
- package/src/slot/upgradeStateToFulu.ts +31 -0
- package/src/slot/upgradeStateToGloas.ts +29 -0
- package/src/stateTransition.ts +305 -0
- package/src/types.ts +26 -0
- package/src/util/aggregator.ts +33 -0
- package/src/util/altair.ts +13 -0
- package/src/util/array.ts +53 -0
- package/src/util/attestation.ts +36 -0
- package/src/util/attesterStatus.ts +83 -0
- package/src/util/balance.ts +83 -0
- package/src/util/blindedBlock.ts +144 -0
- package/src/util/blockRoot.ts +72 -0
- package/src/util/calculateCommitteeAssignments.ts +43 -0
- package/src/util/capella.ts +8 -0
- package/src/util/computeAnchorCheckpoint.ts +38 -0
- package/src/util/deposit.ts +22 -0
- package/src/util/domain.ts +31 -0
- package/src/util/electra.ts +68 -0
- package/src/util/epoch.ts +135 -0
- package/src/util/epochShuffling.ts +185 -0
- package/src/util/execution.ts +177 -0
- package/src/util/finality.ts +17 -0
- package/src/util/fulu.ts +43 -0
- package/src/util/genesis.ts +343 -0
- package/src/util/index.ts +29 -0
- package/src/util/interop.ts +22 -0
- package/src/util/loadState/findModifiedInactivityScores.ts +47 -0
- package/src/util/loadState/findModifiedValidators.ts +46 -0
- package/src/util/loadState/index.ts +2 -0
- package/src/util/loadState/loadState.ts +225 -0
- package/src/util/loadState/loadValidator.ts +77 -0
- package/src/util/rootCache.ts +37 -0
- package/src/util/seed.ts +381 -0
- package/src/util/shufflingDecisionRoot.ts +78 -0
- package/src/util/signatureSets.ts +65 -0
- package/src/util/signingRoot.ts +13 -0
- package/src/util/slot.ts +22 -0
- package/src/util/sszBytes.ts +52 -0
- package/src/util/syncCommittee.ts +69 -0
- package/src/util/targetUnslashedBalance.ts +30 -0
- package/src/util/validator.ts +105 -0
- package/src/util/weakSubjectivity.ts +186 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {CompositeViewDU} from "@chainsafe/ssz";
|
|
2
|
+
import {ForkSeq} from "@lodestar/params";
|
|
3
|
+
import {ssz} from "@lodestar/types";
|
|
4
|
+
import {getAttestationParticipationStatus} from "../block/processAttestationsAltair.js";
|
|
5
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
6
|
+
import {CachedBeaconStateAltair, CachedBeaconStatePhase0} from "../types.js";
|
|
7
|
+
import {RootCache, newZeroedArray} from "../util/index.js";
|
|
8
|
+
import {getNextSyncCommittee} from "../util/syncCommittee.js";
|
|
9
|
+
import {sumTargetUnslashedBalanceIncrements} from "../util/targetUnslashedBalance.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Upgrade a state from phase0 to altair.
|
|
13
|
+
*/
|
|
14
|
+
export function upgradeStateToAltair(statePhase0: CachedBeaconStatePhase0): CachedBeaconStateAltair {
|
|
15
|
+
const {config} = statePhase0;
|
|
16
|
+
|
|
17
|
+
// Get underlying node and cast phase0 tree to altair tree
|
|
18
|
+
//
|
|
19
|
+
// A phase0 BeaconState tree can be safely casted to an altair BeaconState tree because:
|
|
20
|
+
// - Deprecated fields are replaced by new fields at the exact same indexes
|
|
21
|
+
// - All new fields are appended at the end
|
|
22
|
+
//
|
|
23
|
+
// So by just setting all new fields to some value, all the old nodes are dropped
|
|
24
|
+
//
|
|
25
|
+
// phase0 | op | altair
|
|
26
|
+
// ----------------------------- | ---- | ------------
|
|
27
|
+
// genesis_time | - | genesis_time
|
|
28
|
+
// genesis_validators_root | - | genesis_validators_root
|
|
29
|
+
// slot | - | slot
|
|
30
|
+
// fork | - | fork
|
|
31
|
+
// latest_block_header | - | latest_block_header
|
|
32
|
+
// block_roots | - | block_roots
|
|
33
|
+
// state_roots | - | state_roots
|
|
34
|
+
// historical_roots | - | historical_roots
|
|
35
|
+
// eth1_data | - | eth1_data
|
|
36
|
+
// eth1_data_votes | - | eth1_data_votes
|
|
37
|
+
// eth1_deposit_index | - | eth1_deposit_index
|
|
38
|
+
// validators | - | validators
|
|
39
|
+
// balances | - | balances
|
|
40
|
+
// randao_mixes | - | randao_mixes
|
|
41
|
+
// slashings | - | slashings
|
|
42
|
+
// previous_epoch_attestations | diff | previous_epoch_participation
|
|
43
|
+
// current_epoch_attestations | diff | current_epoch_participation
|
|
44
|
+
// justification_bits | - | justification_bits
|
|
45
|
+
// previous_justified_checkpoint | - | previous_justified_checkpoint
|
|
46
|
+
// current_justified_checkpoint | - | current_justified_checkpoint
|
|
47
|
+
// finalized_checkpoint | - | finalized_checkpoint
|
|
48
|
+
// - | new | inactivity_scores
|
|
49
|
+
// - | new | current_sync_committee
|
|
50
|
+
// - | new | next_sync_committee
|
|
51
|
+
|
|
52
|
+
const statePhase0Node = ssz.phase0.BeaconState.commitViewDU(statePhase0);
|
|
53
|
+
const stateAltairView = ssz.altair.BeaconState.getViewDU(statePhase0Node);
|
|
54
|
+
// Attach existing BeaconStateCache from statePhase0 to new stateAltairView object
|
|
55
|
+
const stateAltair = getCachedBeaconState(stateAltairView, statePhase0);
|
|
56
|
+
|
|
57
|
+
stateAltair.fork = ssz.phase0.Fork.toViewDU({
|
|
58
|
+
previousVersion: statePhase0.fork.currentVersion,
|
|
59
|
+
currentVersion: config.ALTAIR_FORK_VERSION,
|
|
60
|
+
epoch: statePhase0.epochCtx.epoch,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const validatorCount = statePhase0.validators.length;
|
|
64
|
+
const emptyEpochParticipationView = ssz.altair.EpochParticipation.toViewDU(newZeroedArray(validatorCount));
|
|
65
|
+
const emptyEpochParticipationNode = ssz.altair.EpochParticipation.commitViewDU(emptyEpochParticipationView);
|
|
66
|
+
stateAltair.previousEpochParticipation = emptyEpochParticipationView;
|
|
67
|
+
// Cloned instance with same immutable Node
|
|
68
|
+
stateAltair.currentEpochParticipation = ssz.altair.EpochParticipation.getViewDU(emptyEpochParticipationNode);
|
|
69
|
+
|
|
70
|
+
stateAltair.inactivityScores = ssz.altair.InactivityScores.toViewDU(newZeroedArray(validatorCount));
|
|
71
|
+
|
|
72
|
+
const {syncCommittee, indices} = getNextSyncCommittee(
|
|
73
|
+
ForkSeq.altair,
|
|
74
|
+
stateAltair,
|
|
75
|
+
stateAltair.epochCtx.nextActiveIndices,
|
|
76
|
+
stateAltair.epochCtx.effectiveBalanceIncrements
|
|
77
|
+
);
|
|
78
|
+
const syncCommitteeView = ssz.altair.SyncCommittee.toViewDU(syncCommittee);
|
|
79
|
+
|
|
80
|
+
stateAltair.currentSyncCommittee = syncCommitteeView;
|
|
81
|
+
stateAltair.nextSyncCommittee = syncCommitteeView;
|
|
82
|
+
stateAltair.epochCtx.setSyncCommitteesIndexed(indices);
|
|
83
|
+
|
|
84
|
+
const pendingAttesations = statePhase0.previousEpochAttestations;
|
|
85
|
+
translateParticipation(stateAltair, pendingAttesations);
|
|
86
|
+
|
|
87
|
+
// Commit new added fields ViewDU to the root node
|
|
88
|
+
stateAltair.commit();
|
|
89
|
+
// Clear cache to ensure the cache of phase0 fields is not used by new altair fields
|
|
90
|
+
// [15] previous_epoch_attestations -> previous_epoch_participation
|
|
91
|
+
// [16] current_epoch_attestations -> current_epoch_participation
|
|
92
|
+
//
|
|
93
|
+
// TODO: This could only drop the caches of index 15,16. However this would couple this code tightly with SSZ ViewDU
|
|
94
|
+
// internals. If the cache is not cleared, consuming the ViewDU instance could break in strange ways.
|
|
95
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
96
|
+
stateAltair["clearCache"]();
|
|
97
|
+
|
|
98
|
+
// TODO: describe issue. Compute progressive target balances
|
|
99
|
+
//
|
|
100
|
+
// Note: in EpochCache.afterProcessEpoch previousTargetUnslashedBalanceIncrements is overwritten,
|
|
101
|
+
// currentTargetUnslashedBalanceIncrements is rotated to previousTargetUnslashedBalanceIncrements
|
|
102
|
+
//
|
|
103
|
+
// Here target balance is computed in full, which is slightly less performant than doing so in the loop
|
|
104
|
+
// above but gurantees consistency with EpochCache.createFromState(). Note execution order below:
|
|
105
|
+
// ```
|
|
106
|
+
// processEpoch()
|
|
107
|
+
// epochCtx.afterProcessEpoch()
|
|
108
|
+
// if (...) upgradeStateToAltair()
|
|
109
|
+
// ```
|
|
110
|
+
const previousEpoch = stateAltair.epochCtx.epoch - 1;
|
|
111
|
+
stateAltair.epochCtx.previousTargetUnslashedBalanceIncrements = sumTargetUnslashedBalanceIncrements(
|
|
112
|
+
stateAltair.previousEpochParticipation.getAll(),
|
|
113
|
+
previousEpoch,
|
|
114
|
+
stateAltair.validators.getAllReadonlyValues()
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return stateAltair;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Translate_participation in https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/altair/fork.md
|
|
122
|
+
*/
|
|
123
|
+
function translateParticipation(
|
|
124
|
+
state: CachedBeaconStateAltair,
|
|
125
|
+
pendingAttesations: CompositeViewDU<typeof ssz.phase0.EpochAttestations>
|
|
126
|
+
): void {
|
|
127
|
+
const {epochCtx} = state;
|
|
128
|
+
const rootCache = new RootCache(state);
|
|
129
|
+
const epochParticipation = state.previousEpochParticipation;
|
|
130
|
+
|
|
131
|
+
for (const attestation of pendingAttesations.getAllReadonly()) {
|
|
132
|
+
const data = attestation.data;
|
|
133
|
+
const attestationFlags = getAttestationParticipationStatus(
|
|
134
|
+
ForkSeq.altair,
|
|
135
|
+
data,
|
|
136
|
+
attestation.inclusionDelay,
|
|
137
|
+
epochCtx.epoch,
|
|
138
|
+
rootCache
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const committeeIndices = epochCtx.getBeaconCommittee(data.slot, data.index);
|
|
142
|
+
const attestingIndices = attestation.aggregationBits.intersectValues(committeeIndices);
|
|
143
|
+
|
|
144
|
+
for (const index of attestingIndices) {
|
|
145
|
+
// ParticipationFlags type uses option {setBitwiseOR: true}, .set() does a |= operation
|
|
146
|
+
epochParticipation.set(index, attestationFlags);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
3
|
+
import {CachedBeaconStateAltair, CachedBeaconStateBellatrix} from "../types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Upgrade a state from altair to bellatrix.
|
|
7
|
+
*/
|
|
8
|
+
export function upgradeStateToBellatrix(stateAltair: CachedBeaconStateAltair): CachedBeaconStateBellatrix {
|
|
9
|
+
const {config} = stateAltair;
|
|
10
|
+
|
|
11
|
+
// Get underlying node and cast altair tree to bellatrix tree
|
|
12
|
+
//
|
|
13
|
+
// An altair BeaconState tree can be safely casted to a bellatrix BeaconState tree because:
|
|
14
|
+
// - All new fields are appended at the end
|
|
15
|
+
//
|
|
16
|
+
// altair | op | bellatrix
|
|
17
|
+
// ----------------------------- | --- | ------------
|
|
18
|
+
// genesis_time | - | genesis_time
|
|
19
|
+
// genesis_validators_root | - | genesis_validators_root
|
|
20
|
+
// slot | - | slot
|
|
21
|
+
// fork | - | fork
|
|
22
|
+
// latest_block_header | - | latest_block_header
|
|
23
|
+
// block_roots | - | block_roots
|
|
24
|
+
// state_roots | - | state_roots
|
|
25
|
+
// historical_roots | - | historical_roots
|
|
26
|
+
// eth1_data | - | eth1_data
|
|
27
|
+
// eth1_data_votes | - | eth1_data_votes
|
|
28
|
+
// eth1_deposit_index | - | eth1_deposit_index
|
|
29
|
+
// validators | - | validators
|
|
30
|
+
// balances | - | balances
|
|
31
|
+
// randao_mixes | - | randao_mixes
|
|
32
|
+
// slashings | - | slashings
|
|
33
|
+
// previous_epoch_participation | - | previous_epoch_participation
|
|
34
|
+
// current_epoch_participation | - | current_epoch_participation
|
|
35
|
+
// justification_bits | - | justification_bits
|
|
36
|
+
// previous_justified_checkpoint | - | previous_justified_checkpoint
|
|
37
|
+
// current_justified_checkpoint | - | current_justified_checkpoint
|
|
38
|
+
// finalized_checkpoint | - | finalized_checkpoint
|
|
39
|
+
// inactivity_scores | - | inactivity_scores
|
|
40
|
+
// current_sync_committee | - | current_sync_committee
|
|
41
|
+
// next_sync_committee | - | next_sync_committee
|
|
42
|
+
// - | new | latest_execution_payload_header
|
|
43
|
+
|
|
44
|
+
const stateAltairNode = ssz.altair.BeaconState.commitViewDU(stateAltair);
|
|
45
|
+
const stateBellatrixView = ssz.bellatrix.BeaconState.getViewDU(stateAltairNode);
|
|
46
|
+
// Attach existing BeaconStateCache from stateAltair to new stateBellatrixView object
|
|
47
|
+
const stateBellatrix = getCachedBeaconState(stateBellatrixView, stateAltair);
|
|
48
|
+
|
|
49
|
+
stateBellatrix.fork = ssz.phase0.Fork.toViewDU({
|
|
50
|
+
previousVersion: stateAltair.fork.currentVersion,
|
|
51
|
+
currentVersion: config.BELLATRIX_FORK_VERSION,
|
|
52
|
+
epoch: stateAltair.epochCtx.epoch,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Execution-layer
|
|
56
|
+
stateBellatrix.latestExecutionPayloadHeader = ssz.bellatrix.ExecutionPayloadHeader.defaultViewDU();
|
|
57
|
+
|
|
58
|
+
// Commit new added fields ViewDU to the root node
|
|
59
|
+
stateBellatrix.commit();
|
|
60
|
+
// No need to clear cache since no index is replaced, only appended at the end
|
|
61
|
+
|
|
62
|
+
return stateBellatrix;
|
|
63
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
3
|
+
import {CachedBeaconStateBellatrix, CachedBeaconStateCapella} from "../types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Upgrade a state from bellatrix to capella.
|
|
7
|
+
*/
|
|
8
|
+
export function upgradeStateToCapella(stateBellatrix: CachedBeaconStateBellatrix): CachedBeaconStateCapella {
|
|
9
|
+
const {config} = stateBellatrix;
|
|
10
|
+
|
|
11
|
+
// Get underlying node and cast bellatrix tree to capella tree
|
|
12
|
+
//
|
|
13
|
+
// An bellatrix BeaconState tree can be safely casted to a capella BeaconState tree because:
|
|
14
|
+
// - Deprecated fields are replaced by new fields at the exact same indexes
|
|
15
|
+
// - All new fields are appended at the end
|
|
16
|
+
//
|
|
17
|
+
// bellatrix | op | capella
|
|
18
|
+
// -------------------------------- | ---- | ------------
|
|
19
|
+
// genesis_time | - | genesis_time
|
|
20
|
+
// genesis_validators_root | - | genesis_validators_root
|
|
21
|
+
// slot | - | slot
|
|
22
|
+
// fork | - | fork
|
|
23
|
+
// latest_block_header | - | latest_block_header
|
|
24
|
+
// block_roots | - | block_roots
|
|
25
|
+
// state_roots | - | state_roots
|
|
26
|
+
// historical_roots | frozen| historical_roots
|
|
27
|
+
// eth1_data | - | eth1_data
|
|
28
|
+
// eth1_data_votes | - | eth1_data_votes
|
|
29
|
+
// eth1_deposit_index | - | eth1_deposit_index
|
|
30
|
+
// validators | - | validators
|
|
31
|
+
// balances | - | balances
|
|
32
|
+
// randao_mixes | - | randao_mixes
|
|
33
|
+
// slashings | - | slashings
|
|
34
|
+
// previous_epoch_participation | - | previous_epoch_participation
|
|
35
|
+
// current_epoch_participation | - | current_epoch_participation
|
|
36
|
+
// justification_bits | - | justification_bits
|
|
37
|
+
// previous_justified_checkpoint | - | previous_justified_checkpoint
|
|
38
|
+
// current_justified_checkpoint | - | current_justified_checkpoint
|
|
39
|
+
// finalized_checkpoint | - | finalized_checkpoint
|
|
40
|
+
// inactivity_scores | - | inactivity_scores
|
|
41
|
+
// current_sync_committee | - | current_sync_committee
|
|
42
|
+
// next_sync_committee | - | next_sync_committee
|
|
43
|
+
// latest_execution_payload_header | diff | latest_execution_payload_header
|
|
44
|
+
// - | new | next_withdrawal_index
|
|
45
|
+
// - | new | next_withdrawal_validator_index
|
|
46
|
+
// - | new | historical_summaries
|
|
47
|
+
|
|
48
|
+
const stateBellatrixNode = ssz.bellatrix.BeaconState.commitViewDU(stateBellatrix);
|
|
49
|
+
const stateCapellaView = ssz.capella.BeaconState.getViewDU(stateBellatrixNode);
|
|
50
|
+
// Attach existing BeaconStateCache from stateBellatrix to new stateCapellaView object
|
|
51
|
+
const stateCapella = getCachedBeaconState(stateCapellaView, stateBellatrix);
|
|
52
|
+
|
|
53
|
+
stateCapella.fork = ssz.phase0.Fork.toViewDU({
|
|
54
|
+
previousVersion: stateBellatrix.fork.currentVersion,
|
|
55
|
+
currentVersion: config.CAPELLA_FORK_VERSION,
|
|
56
|
+
epoch: stateBellatrix.epochCtx.epoch,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// nextWithdrawalIndex and nextWithdrawalValidatorIndex are already set to 0 by default
|
|
60
|
+
// latestExecutionPayloadHeader's withdrawalRoot set to zeros by default
|
|
61
|
+
// historicalRoots should be cloned over already and historicalSummaries need to be default []
|
|
62
|
+
stateCapella.historicalSummaries = ssz.capella.BeaconState.fields.historicalSummaries.defaultViewDU();
|
|
63
|
+
|
|
64
|
+
// Commit new added fields ViewDU to the root node
|
|
65
|
+
stateCapella.commit();
|
|
66
|
+
// Clear cache to ensure the cache of bellatrix fields is not used by new capella fields
|
|
67
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
68
|
+
stateCapella["clearCache"]();
|
|
69
|
+
|
|
70
|
+
return stateCapella;
|
|
71
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
3
|
+
import {CachedBeaconStateCapella, CachedBeaconStateDeneb} from "../types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Upgrade a state from Capella to Deneb.
|
|
7
|
+
*/
|
|
8
|
+
export function upgradeStateToDeneb(stateCapella: CachedBeaconStateCapella): CachedBeaconStateDeneb {
|
|
9
|
+
const {config} = stateCapella;
|
|
10
|
+
|
|
11
|
+
const stateCapellaNode = ssz.capella.BeaconState.commitViewDU(stateCapella);
|
|
12
|
+
const stateDenebView = ssz.deneb.BeaconState.getViewDU(stateCapellaNode);
|
|
13
|
+
|
|
14
|
+
const stateDeneb = getCachedBeaconState(stateDenebView, stateCapella);
|
|
15
|
+
|
|
16
|
+
stateDeneb.fork = ssz.phase0.Fork.toViewDU({
|
|
17
|
+
previousVersion: stateCapella.fork.currentVersion,
|
|
18
|
+
currentVersion: config.DENEB_FORK_VERSION,
|
|
19
|
+
epoch: stateCapella.epochCtx.epoch,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Since excessBlobGas and blobGasUsed are appened in the end to latestExecutionPayloadHeader so they should
|
|
23
|
+
// be set to defaults and need no assigning, but right now any access to latestExecutionPayloadHeader fails
|
|
24
|
+
// with LeafNode has no left node. Weirdly its beacuse of addition of the second field as with one field
|
|
25
|
+
// it seems to work.
|
|
26
|
+
//
|
|
27
|
+
// TODO DENEB: Debug and remove the following cloning
|
|
28
|
+
stateDeneb.latestExecutionPayloadHeader = ssz.deneb.BeaconState.fields.latestExecutionPayloadHeader.toViewDU({
|
|
29
|
+
...stateCapella.latestExecutionPayloadHeader.toValue(),
|
|
30
|
+
excessBlobGas: BigInt(0),
|
|
31
|
+
blobGasUsed: BigInt(0),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
stateDeneb.commit();
|
|
35
|
+
// Clear cache to ensure the cache of capella fields is not used by new deneb fields
|
|
36
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
37
|
+
stateDeneb["clearCache"]();
|
|
38
|
+
|
|
39
|
+
return stateDeneb;
|
|
40
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {FAR_FUTURE_EPOCH, GENESIS_SLOT, UNSET_DEPOSIT_REQUESTS_START_INDEX} from "@lodestar/params";
|
|
2
|
+
import {ValidatorIndex, ssz} from "@lodestar/types";
|
|
3
|
+
import {CachedBeaconStateElectra, getCachedBeaconState} from "../cache/stateCache.js";
|
|
4
|
+
import {G2_POINT_AT_INFINITY} from "../constants/constants.js";
|
|
5
|
+
import {CachedBeaconStateDeneb} from "../types.js";
|
|
6
|
+
import {hasCompoundingWithdrawalCredential, queueExcessActiveBalance} from "../util/electra.js";
|
|
7
|
+
import {computeActivationExitEpoch} from "../util/epoch.js";
|
|
8
|
+
import {getActivationExitChurnLimit, getConsolidationChurnLimit} from "../util/validator.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Upgrade a state from Deneb to Electra.
|
|
12
|
+
*/
|
|
13
|
+
export function upgradeStateToElectra(stateDeneb: CachedBeaconStateDeneb): CachedBeaconStateElectra {
|
|
14
|
+
const {config} = stateDeneb;
|
|
15
|
+
|
|
16
|
+
ssz.deneb.BeaconState.commitViewDU(stateDeneb);
|
|
17
|
+
const stateElectraCloned = stateDeneb;
|
|
18
|
+
|
|
19
|
+
const stateElectraView = ssz.electra.BeaconState.defaultViewDU();
|
|
20
|
+
stateElectraView.genesisTime = stateElectraCloned.genesisTime;
|
|
21
|
+
stateElectraView.genesisValidatorsRoot = stateElectraCloned.genesisValidatorsRoot;
|
|
22
|
+
stateElectraView.slot = stateElectraCloned.slot;
|
|
23
|
+
stateElectraView.fork = ssz.phase0.Fork.toViewDU({
|
|
24
|
+
previousVersion: stateDeneb.fork.currentVersion,
|
|
25
|
+
currentVersion: config.ELECTRA_FORK_VERSION,
|
|
26
|
+
epoch: stateDeneb.epochCtx.epoch,
|
|
27
|
+
});
|
|
28
|
+
stateElectraView.latestBlockHeader = stateElectraCloned.latestBlockHeader;
|
|
29
|
+
stateElectraView.blockRoots = stateElectraCloned.blockRoots;
|
|
30
|
+
stateElectraView.stateRoots = stateElectraCloned.stateRoots;
|
|
31
|
+
stateElectraView.historicalRoots = stateElectraCloned.historicalRoots;
|
|
32
|
+
stateElectraView.eth1Data = stateElectraCloned.eth1Data;
|
|
33
|
+
stateElectraView.eth1DataVotes = stateElectraCloned.eth1DataVotes;
|
|
34
|
+
stateElectraView.eth1DepositIndex = stateElectraCloned.eth1DepositIndex;
|
|
35
|
+
stateElectraView.validators = stateElectraCloned.validators;
|
|
36
|
+
stateElectraView.balances = stateElectraCloned.balances;
|
|
37
|
+
stateElectraView.randaoMixes = stateElectraCloned.randaoMixes;
|
|
38
|
+
stateElectraView.slashings = stateElectraCloned.slashings;
|
|
39
|
+
stateElectraView.previousEpochParticipation = stateElectraCloned.previousEpochParticipation;
|
|
40
|
+
stateElectraView.currentEpochParticipation = stateElectraCloned.currentEpochParticipation;
|
|
41
|
+
stateElectraView.justificationBits = stateElectraCloned.justificationBits;
|
|
42
|
+
stateElectraView.previousJustifiedCheckpoint = stateElectraCloned.previousJustifiedCheckpoint;
|
|
43
|
+
stateElectraView.currentJustifiedCheckpoint = stateElectraCloned.currentJustifiedCheckpoint;
|
|
44
|
+
stateElectraView.finalizedCheckpoint = stateElectraCloned.finalizedCheckpoint;
|
|
45
|
+
stateElectraView.inactivityScores = stateElectraCloned.inactivityScores;
|
|
46
|
+
stateElectraView.currentSyncCommittee = stateElectraCloned.currentSyncCommittee;
|
|
47
|
+
stateElectraView.nextSyncCommittee = stateElectraCloned.nextSyncCommittee;
|
|
48
|
+
stateElectraView.latestExecutionPayloadHeader = stateElectraCloned.latestExecutionPayloadHeader;
|
|
49
|
+
stateElectraView.nextWithdrawalIndex = stateDeneb.nextWithdrawalIndex;
|
|
50
|
+
stateElectraView.nextWithdrawalValidatorIndex = stateDeneb.nextWithdrawalValidatorIndex;
|
|
51
|
+
stateElectraView.historicalSummaries = stateElectraCloned.historicalSummaries;
|
|
52
|
+
|
|
53
|
+
// default value of depositRequestsStartIndex is UNSET_DEPOSIT_REQUESTS_START_INDEX
|
|
54
|
+
stateElectraView.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
|
|
55
|
+
stateElectraView.depositBalanceToConsume = BigInt(0);
|
|
56
|
+
stateElectraView.exitBalanceToConsume = BigInt(0);
|
|
57
|
+
|
|
58
|
+
const validatorsArr = stateElectraView.validators.getAllReadonly();
|
|
59
|
+
const currentEpochPre = stateDeneb.epochCtx.epoch;
|
|
60
|
+
let earliestExitEpoch = computeActivationExitEpoch(currentEpochPre);
|
|
61
|
+
|
|
62
|
+
// [EIP-7251]: add validators that are not yet active to pending balance deposits
|
|
63
|
+
const preActivation: ValidatorIndex[] = [];
|
|
64
|
+
for (let validatorIndex = 0; validatorIndex < validatorsArr.length; validatorIndex++) {
|
|
65
|
+
const {activationEpoch, exitEpoch} = validatorsArr[validatorIndex];
|
|
66
|
+
if (activationEpoch === FAR_FUTURE_EPOCH) {
|
|
67
|
+
preActivation.push(validatorIndex);
|
|
68
|
+
}
|
|
69
|
+
if (exitEpoch !== FAR_FUTURE_EPOCH && exitEpoch > earliestExitEpoch) {
|
|
70
|
+
earliestExitEpoch = exitEpoch;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
stateElectraView.earliestExitEpoch = earliestExitEpoch + 1;
|
|
75
|
+
stateElectraView.consolidationBalanceToConsume = BigInt(0);
|
|
76
|
+
stateElectraView.earliestConsolidationEpoch = computeActivationExitEpoch(currentEpochPre);
|
|
77
|
+
// TODO-electra: can we improve this?
|
|
78
|
+
stateElectraView.commit();
|
|
79
|
+
const tmpElectraState = getCachedBeaconState(stateElectraView, stateDeneb);
|
|
80
|
+
stateElectraView.exitBalanceToConsume = BigInt(getActivationExitChurnLimit(tmpElectraState.epochCtx));
|
|
81
|
+
stateElectraView.consolidationBalanceToConsume = BigInt(getConsolidationChurnLimit(tmpElectraState.epochCtx));
|
|
82
|
+
|
|
83
|
+
preActivation.sort((i0, i1) => {
|
|
84
|
+
const res = validatorsArr[i0].activationEligibilityEpoch - validatorsArr[i1].activationEligibilityEpoch;
|
|
85
|
+
return res !== 0 ? res : i0 - i1;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
for (const validatorIndex of preActivation) {
|
|
89
|
+
const stateElectra = stateElectraView as CachedBeaconStateElectra;
|
|
90
|
+
const balance = stateElectra.balances.get(validatorIndex);
|
|
91
|
+
stateElectra.balances.set(validatorIndex, 0);
|
|
92
|
+
|
|
93
|
+
const validator = stateElectra.validators.get(validatorIndex);
|
|
94
|
+
validator.effectiveBalance = 0;
|
|
95
|
+
stateElectra.epochCtx.effectiveBalanceIncrementsSet(validatorIndex, 0);
|
|
96
|
+
validator.activationEligibilityEpoch = FAR_FUTURE_EPOCH;
|
|
97
|
+
|
|
98
|
+
const pendingDeposit = ssz.electra.PendingDeposit.toViewDU({
|
|
99
|
+
pubkey: validator.pubkey,
|
|
100
|
+
withdrawalCredentials: validator.withdrawalCredentials,
|
|
101
|
+
amount: balance,
|
|
102
|
+
signature: G2_POINT_AT_INFINITY,
|
|
103
|
+
slot: GENESIS_SLOT,
|
|
104
|
+
});
|
|
105
|
+
stateElectra.pendingDeposits.push(pendingDeposit);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < validatorsArr.length; i++) {
|
|
109
|
+
const validator = validatorsArr[i];
|
|
110
|
+
|
|
111
|
+
// [EIP-7251]: Ensure early adopters of compounding credentials go through the activation churn
|
|
112
|
+
const withdrawalCredential = validator.withdrawalCredentials;
|
|
113
|
+
if (hasCompoundingWithdrawalCredential(withdrawalCredential)) {
|
|
114
|
+
queueExcessActiveBalance(stateElectraView as CachedBeaconStateElectra, i);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const stateElectra = getCachedBeaconState(stateElectraView, stateDeneb);
|
|
119
|
+
// Commit new added fields ViewDU to the root node
|
|
120
|
+
stateElectra.commit();
|
|
121
|
+
// Clear cache to ensure the cache of deneb fields is not used by new ELECTRA fields
|
|
122
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
123
|
+
stateElectra["clearCache"]();
|
|
124
|
+
|
|
125
|
+
return stateElectra;
|
|
126
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
3
|
+
import {CachedBeaconStateElectra, CachedBeaconStateFulu} from "../types.js";
|
|
4
|
+
import {initializeProposerLookahead} from "../util/fulu.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Upgrade a state from Electra to Fulu.
|
|
8
|
+
*/
|
|
9
|
+
export function upgradeStateToFulu(stateElectra: CachedBeaconStateElectra): CachedBeaconStateFulu {
|
|
10
|
+
const {config} = stateElectra;
|
|
11
|
+
|
|
12
|
+
const stateElectraNode = ssz.electra.BeaconState.commitViewDU(stateElectra);
|
|
13
|
+
const stateFuluView = ssz.fulu.BeaconState.getViewDU(stateElectraNode);
|
|
14
|
+
|
|
15
|
+
const stateFulu = getCachedBeaconState(stateFuluView, stateElectra);
|
|
16
|
+
|
|
17
|
+
stateFulu.fork = ssz.phase0.Fork.toViewDU({
|
|
18
|
+
previousVersion: stateElectra.fork.currentVersion,
|
|
19
|
+
currentVersion: config.FULU_FORK_VERSION,
|
|
20
|
+
epoch: stateElectra.epochCtx.epoch,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
stateFulu.proposerLookahead = ssz.fulu.ProposerLookahead.toViewDU(initializeProposerLookahead(stateElectra));
|
|
24
|
+
|
|
25
|
+
stateFulu.commit();
|
|
26
|
+
// Clear cache to ensure the cache of electra fields is not used by new fulu fields
|
|
27
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
28
|
+
stateFulu["clearCache"]();
|
|
29
|
+
|
|
30
|
+
return stateFulu;
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
3
|
+
import {CachedBeaconStateFulu, CachedBeaconStateGloas} from "../types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Upgrade a state from Fulu to Gloas.
|
|
7
|
+
* TODO GLOAS: Implement this
|
|
8
|
+
*/
|
|
9
|
+
export function upgradeStateToGloas(stateFulu: CachedBeaconStateFulu): CachedBeaconStateGloas {
|
|
10
|
+
const {config} = stateFulu;
|
|
11
|
+
|
|
12
|
+
const stateFuluNode = ssz.fulu.BeaconState.commitViewDU(stateFulu);
|
|
13
|
+
const stateGloasView = ssz.gloas.BeaconState.getViewDU(stateFuluNode);
|
|
14
|
+
|
|
15
|
+
const stateGloas = getCachedBeaconState(stateGloasView, stateFulu);
|
|
16
|
+
|
|
17
|
+
stateGloas.fork = ssz.phase0.Fork.toViewDU({
|
|
18
|
+
previousVersion: stateFulu.fork.currentVersion,
|
|
19
|
+
currentVersion: config.GLOAS_FORK_VERSION,
|
|
20
|
+
epoch: stateFulu.epochCtx.epoch,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
stateGloas.commit();
|
|
24
|
+
// Clear cache to ensure the cache of fulu fields is not used by new gloas fields
|
|
25
|
+
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
26
|
+
stateGloas["clearCache"]();
|
|
27
|
+
|
|
28
|
+
return stateGloas;
|
|
29
|
+
}
|