@lodestar/state-transition 1.35.0-dev.fcf8d024ea → 1.35.0-dev.feed916580
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/cache/types.d.ts +2 -2
- package/lib/util/genesis.js +3 -0
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/slot.d.ts +1 -0
- package/lib/util/slot.js +5 -1
- package/lib/util/slot.js.map +1 -1
- package/package.json +11 -13
- package/lib/block/externalData.d.ts.map +0 -1
- package/lib/block/index.d.ts.map +0 -1
- package/lib/block/initiateValidatorExit.d.ts.map +0 -1
- package/lib/block/isValidIndexedAttestation.d.ts.map +0 -1
- package/lib/block/processAttestationPhase0.d.ts.map +0 -1
- package/lib/block/processAttestations.d.ts.map +0 -1
- package/lib/block/processAttestationsAltair.d.ts.map +0 -1
- package/lib/block/processAttesterSlashing.d.ts.map +0 -1
- package/lib/block/processBlobKzgCommitments.d.ts.map +0 -1
- package/lib/block/processBlockHeader.d.ts.map +0 -1
- package/lib/block/processBlsToExecutionChange.d.ts.map +0 -1
- package/lib/block/processConsolidationRequest.d.ts.map +0 -1
- package/lib/block/processDeposit.d.ts.map +0 -1
- package/lib/block/processDepositRequest.d.ts.map +0 -1
- package/lib/block/processEth1Data.d.ts.map +0 -1
- package/lib/block/processExecutionPayload.d.ts.map +0 -1
- package/lib/block/processOperations.d.ts.map +0 -1
- package/lib/block/processProposerSlashing.d.ts.map +0 -1
- package/lib/block/processRandao.d.ts.map +0 -1
- package/lib/block/processSyncCommittee.d.ts.map +0 -1
- package/lib/block/processVoluntaryExit.d.ts.map +0 -1
- package/lib/block/processWithdrawalRequest.d.ts.map +0 -1
- package/lib/block/processWithdrawals.d.ts.map +0 -1
- package/lib/block/slashValidator.d.ts.map +0 -1
- package/lib/block/types.d.ts.map +0 -1
- package/lib/cache/effectiveBalanceIncrements.d.ts.map +0 -1
- package/lib/cache/epochCache.d.ts.map +0 -1
- package/lib/cache/epochTransitionCache.d.ts.map +0 -1
- package/lib/cache/pubkeyCache.d.ts.map +0 -1
- package/lib/cache/rewardCache.d.ts.map +0 -1
- package/lib/cache/stateCache.d.ts.map +0 -1
- package/lib/cache/syncCommitteeCache.d.ts.map +0 -1
- package/lib/cache/types.d.ts.map +0 -1
- package/lib/constants/constants.d.ts.map +0 -1
- package/lib/constants/index.d.ts.map +0 -1
- package/lib/epoch/computeUnrealizedCheckpoints.d.ts.map +0 -1
- package/lib/epoch/getAttestationDeltas.d.ts.map +0 -1
- package/lib/epoch/getRewardsAndPenalties.d.ts.map +0 -1
- package/lib/epoch/index.d.ts.map +0 -1
- package/lib/epoch/processEffectiveBalanceUpdates.d.ts.map +0 -1
- package/lib/epoch/processEth1DataReset.d.ts.map +0 -1
- package/lib/epoch/processHistoricalRootsUpdate.d.ts.map +0 -1
- package/lib/epoch/processHistoricalSummariesUpdate.d.ts.map +0 -1
- package/lib/epoch/processInactivityUpdates.d.ts.map +0 -1
- package/lib/epoch/processJustificationAndFinalization.d.ts.map +0 -1
- package/lib/epoch/processParticipationFlagUpdates.d.ts.map +0 -1
- package/lib/epoch/processParticipationRecordUpdates.d.ts.map +0 -1
- package/lib/epoch/processPendingAttestations.d.ts.map +0 -1
- package/lib/epoch/processPendingConsolidations.d.ts.map +0 -1
- package/lib/epoch/processPendingDeposits.d.ts.map +0 -1
- package/lib/epoch/processProposerLookahead.d.ts.map +0 -1
- package/lib/epoch/processRandaoMixesReset.d.ts.map +0 -1
- package/lib/epoch/processRegistryUpdates.d.ts.map +0 -1
- package/lib/epoch/processRewardsAndPenalties.d.ts.map +0 -1
- package/lib/epoch/processSlashings.d.ts.map +0 -1
- package/lib/epoch/processSlashingsReset.d.ts.map +0 -1
- package/lib/epoch/processSyncCommitteeUpdates.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/metrics.d.ts.map +0 -1
- package/lib/signatureSets/attesterSlashings.d.ts.map +0 -1
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +0 -1
- package/lib/signatureSets/index.d.ts.map +0 -1
- package/lib/signatureSets/indexedAttestation.d.ts.map +0 -1
- package/lib/signatureSets/proposer.d.ts.map +0 -1
- package/lib/signatureSets/proposerSlashings.d.ts.map +0 -1
- package/lib/signatureSets/randao.d.ts.map +0 -1
- package/lib/signatureSets/voluntaryExits.d.ts.map +0 -1
- package/lib/slot/index.d.ts.map +0 -1
- package/lib/slot/upgradeStateToAltair.d.ts.map +0 -1
- package/lib/slot/upgradeStateToBellatrix.d.ts.map +0 -1
- package/lib/slot/upgradeStateToCapella.d.ts.map +0 -1
- package/lib/slot/upgradeStateToDeneb.d.ts.map +0 -1
- package/lib/slot/upgradeStateToElectra.d.ts.map +0 -1
- package/lib/slot/upgradeStateToFulu.d.ts.map +0 -1
- package/lib/slot/upgradeStateToGloas.d.ts.map +0 -1
- package/lib/stateTransition.d.ts.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/util/aggregator.d.ts.map +0 -1
- package/lib/util/altair.d.ts.map +0 -1
- package/lib/util/array.d.ts.map +0 -1
- package/lib/util/attestation.d.ts.map +0 -1
- package/lib/util/attesterStatus.d.ts.map +0 -1
- package/lib/util/balance.d.ts.map +0 -1
- package/lib/util/blindedBlock.d.ts.map +0 -1
- package/lib/util/blockRoot.d.ts.map +0 -1
- package/lib/util/calculateCommitteeAssignments.d.ts.map +0 -1
- package/lib/util/capella.d.ts.map +0 -1
- package/lib/util/computeAnchorCheckpoint.d.ts.map +0 -1
- package/lib/util/deposit.d.ts.map +0 -1
- package/lib/util/domain.d.ts.map +0 -1
- package/lib/util/electra.d.ts.map +0 -1
- package/lib/util/epoch.d.ts.map +0 -1
- package/lib/util/epochShuffling.d.ts.map +0 -1
- package/lib/util/execution.d.ts.map +0 -1
- package/lib/util/finality.d.ts.map +0 -1
- package/lib/util/fulu.d.ts.map +0 -1
- package/lib/util/genesis.d.ts.map +0 -1
- package/lib/util/index.d.ts.map +0 -1
- package/lib/util/interop.d.ts.map +0 -1
- package/lib/util/loadState/findModifiedInactivityScores.d.ts.map +0 -1
- package/lib/util/loadState/findModifiedValidators.d.ts.map +0 -1
- package/lib/util/loadState/index.d.ts.map +0 -1
- package/lib/util/loadState/loadState.d.ts.map +0 -1
- package/lib/util/loadState/loadValidator.d.ts.map +0 -1
- package/lib/util/rootCache.d.ts.map +0 -1
- package/lib/util/seed.d.ts.map +0 -1
- package/lib/util/shufflingDecisionRoot.d.ts.map +0 -1
- package/lib/util/signatureSets.d.ts.map +0 -1
- package/lib/util/signingRoot.d.ts.map +0 -1
- package/lib/util/slot.d.ts.map +0 -1
- package/lib/util/sszBytes.d.ts.map +0 -1
- package/lib/util/syncCommittee.d.ts.map +0 -1
- package/lib/util/targetUnslashedBalance.d.ts.map +0 -1
- package/lib/util/validator.d.ts.map +0 -1
- package/lib/util/weakSubjectivity.d.ts.map +0 -1
- package/src/block/externalData.ts +0 -26
- package/src/block/index.ts +0 -81
- package/src/block/initiateValidatorExit.ts +0 -62
- package/src/block/isValidIndexedAttestation.ts +0 -70
- package/src/block/processAttestationPhase0.ts +0 -158
- package/src/block/processAttestations.ts +0 -25
- package/src/block/processAttestationsAltair.ts +0 -184
- package/src/block/processAttesterSlashing.ts +0 -59
- package/src/block/processBlobKzgCommitments.ts +0 -21
- package/src/block/processBlockHeader.ts +0 -54
- package/src/block/processBlsToExecutionChange.ts +0 -78
- package/src/block/processConsolidationRequest.ts +0 -147
- package/src/block/processDeposit.ts +0 -166
- package/src/block/processDepositRequest.ts +0 -19
- package/src/block/processEth1Data.ts +0 -86
- package/src/block/processExecutionPayload.ts +0 -84
- package/src/block/processOperations.ts +0 -83
- package/src/block/processProposerSlashing.ts +0 -66
- package/src/block/processRandao.ts +0 -27
- package/src/block/processSyncCommittee.ts +0 -117
- package/src/block/processVoluntaryExit.ts +0 -55
- package/src/block/processWithdrawalRequest.ts +0 -98
- package/src/block/processWithdrawals.ts +0 -207
- package/src/block/slashValidator.ts +0 -98
- package/src/block/types.ts +0 -9
- package/src/cache/effectiveBalanceIncrements.ts +0 -39
- package/src/cache/epochCache.ts +0 -1213
- package/src/cache/epochTransitionCache.ts +0 -542
- package/src/cache/pubkeyCache.ts +0 -33
- package/src/cache/rewardCache.ts +0 -19
- package/src/cache/stateCache.ts +0 -268
- package/src/cache/syncCommitteeCache.ts +0 -96
- package/src/cache/types.ts +0 -18
- package/src/constants/constants.ts +0 -12
- package/src/constants/index.ts +0 -1
- package/src/epoch/computeUnrealizedCheckpoints.ts +0 -55
- package/src/epoch/getAttestationDeltas.ts +0 -169
- package/src/epoch/getRewardsAndPenalties.ts +0 -137
- package/src/epoch/index.ts +0 -202
- package/src/epoch/processEffectiveBalanceUpdates.ts +0 -111
- package/src/epoch/processEth1DataReset.ts +0 -17
- package/src/epoch/processHistoricalRootsUpdate.ts +0 -25
- package/src/epoch/processHistoricalSummariesUpdate.ts +0 -23
- package/src/epoch/processInactivityUpdates.ts +0 -60
- package/src/epoch/processJustificationAndFinalization.ts +0 -90
- package/src/epoch/processParticipationFlagUpdates.ts +0 -27
- package/src/epoch/processParticipationRecordUpdates.ts +0 -14
- package/src/epoch/processPendingAttestations.ts +0 -75
- package/src/epoch/processPendingConsolidations.ts +0 -59
- package/src/epoch/processPendingDeposits.ts +0 -136
- package/src/epoch/processProposerLookahead.ts +0 -39
- package/src/epoch/processRandaoMixesReset.ts +0 -18
- package/src/epoch/processRegistryUpdates.ts +0 -65
- package/src/epoch/processRewardsAndPenalties.ts +0 -58
- package/src/epoch/processSlashings.ts +0 -97
- package/src/epoch/processSlashingsReset.ts +0 -20
- package/src/epoch/processSyncCommitteeUpdates.ts +0 -44
- package/src/index.ts +0 -67
- package/src/metrics.ts +0 -169
- package/src/signatureSets/attesterSlashings.ts +0 -39
- package/src/signatureSets/blsToExecutionChange.ts +0 -43
- package/src/signatureSets/index.ts +0 -73
- package/src/signatureSets/indexedAttestation.ts +0 -51
- package/src/signatureSets/proposer.ts +0 -47
- package/src/signatureSets/proposerSlashings.ts +0 -41
- package/src/signatureSets/randao.ts +0 -31
- package/src/signatureSets/voluntaryExits.ts +0 -44
- package/src/slot/index.ts +0 -32
- package/src/slot/upgradeStateToAltair.ts +0 -149
- package/src/slot/upgradeStateToBellatrix.ts +0 -63
- package/src/slot/upgradeStateToCapella.ts +0 -71
- package/src/slot/upgradeStateToDeneb.ts +0 -40
- package/src/slot/upgradeStateToElectra.ts +0 -126
- package/src/slot/upgradeStateToFulu.ts +0 -31
- package/src/slot/upgradeStateToGloas.ts +0 -29
- package/src/stateTransition.ts +0 -305
- package/src/types.ts +0 -26
- package/src/util/aggregator.ts +0 -33
- package/src/util/altair.ts +0 -13
- package/src/util/array.ts +0 -53
- package/src/util/attestation.ts +0 -36
- package/src/util/attesterStatus.ts +0 -83
- package/src/util/balance.ts +0 -83
- package/src/util/blindedBlock.ts +0 -144
- package/src/util/blockRoot.ts +0 -72
- package/src/util/calculateCommitteeAssignments.ts +0 -43
- package/src/util/capella.ts +0 -8
- package/src/util/computeAnchorCheckpoint.ts +0 -38
- package/src/util/deposit.ts +0 -22
- package/src/util/domain.ts +0 -31
- package/src/util/electra.ts +0 -68
- package/src/util/epoch.ts +0 -135
- package/src/util/epochShuffling.ts +0 -185
- package/src/util/execution.ts +0 -177
- package/src/util/finality.ts +0 -17
- package/src/util/fulu.ts +0 -43
- package/src/util/genesis.ts +0 -340
- package/src/util/index.ts +0 -29
- package/src/util/interop.ts +0 -22
- package/src/util/loadState/findModifiedInactivityScores.ts +0 -47
- package/src/util/loadState/findModifiedValidators.ts +0 -46
- package/src/util/loadState/index.ts +0 -2
- package/src/util/loadState/loadState.ts +0 -225
- package/src/util/loadState/loadValidator.ts +0 -77
- package/src/util/rootCache.ts +0 -37
- package/src/util/seed.ts +0 -381
- package/src/util/shufflingDecisionRoot.ts +0 -78
- package/src/util/signatureSets.ts +0 -65
- package/src/util/signingRoot.ts +0 -13
- package/src/util/slot.ts +0 -22
- package/src/util/sszBytes.ts +0 -52
- package/src/util/syncCommittee.ts +0 -69
- package/src/util/targetUnslashedBalance.ts +0 -30
- package/src/util/validator.ts +0 -105
- package/src/util/weakSubjectivity.ts +0 -186
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import {asyncUnshuffleList, unshuffleList} from "@chainsafe/swap-or-not-shuffle";
|
|
2
|
-
import {BeaconConfig} from "@lodestar/config";
|
|
3
|
-
import {
|
|
4
|
-
DOMAIN_BEACON_ATTESTER,
|
|
5
|
-
GENESIS_SLOT,
|
|
6
|
-
MAX_COMMITTEES_PER_SLOT,
|
|
7
|
-
SHUFFLE_ROUND_COUNT,
|
|
8
|
-
SLOTS_PER_EPOCH,
|
|
9
|
-
TARGET_COMMITTEE_SIZE,
|
|
10
|
-
} from "@lodestar/params";
|
|
11
|
-
import {Epoch, RootHex, ValidatorIndex, ssz} from "@lodestar/types";
|
|
12
|
-
import {GaugeExtra, Logger, NoLabels, intDiv, toRootHex} from "@lodestar/utils";
|
|
13
|
-
import {BeaconStateAllForks} from "../types.js";
|
|
14
|
-
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
15
|
-
import {computeAnchorCheckpoint} from "./computeAnchorCheckpoint.js";
|
|
16
|
-
import {computeStartSlotAtEpoch} from "./epoch.js";
|
|
17
|
-
import {getSeed} from "./seed.js";
|
|
18
|
-
|
|
19
|
-
export interface ShufflingBuildProps {
|
|
20
|
-
state: BeaconStateAllForks;
|
|
21
|
-
activeIndices: Uint32Array;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface PublicShufflingCacheMetrics {
|
|
25
|
-
shufflingCache: {
|
|
26
|
-
nextShufflingNotOnEpochCache: GaugeExtra<NoLabels>;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export interface IShufflingCache {
|
|
30
|
-
metrics: PublicShufflingCacheMetrics | null;
|
|
31
|
-
logger: Logger | null;
|
|
32
|
-
/**
|
|
33
|
-
* Gets a cached shuffling via the epoch and decision root. If the state and
|
|
34
|
-
* activeIndices are passed and a shuffling is not available it will be built
|
|
35
|
-
* synchronously. If the state is not passed and the shuffling is not available
|
|
36
|
-
* nothing will be returned.
|
|
37
|
-
*
|
|
38
|
-
* NOTE: If a shuffling is already queued and not calculated it will build and resolve
|
|
39
|
-
* the promise but the already queued build will happen at some later time
|
|
40
|
-
*/
|
|
41
|
-
getSync<T extends ShufflingBuildProps | undefined>(
|
|
42
|
-
epoch: Epoch,
|
|
43
|
-
decisionRoot: RootHex,
|
|
44
|
-
buildProps?: T
|
|
45
|
-
): T extends ShufflingBuildProps ? EpochShuffling : EpochShuffling | null;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Gets a cached shuffling via the epoch and decision root. Returns a promise
|
|
49
|
-
* for the shuffling if it hs not calculated yet. Returns null if a build has
|
|
50
|
-
* not been queued nor a shuffling was calculated.
|
|
51
|
-
*/
|
|
52
|
-
get(epoch: Epoch, decisionRoot: RootHex): Promise<EpochShuffling | null>;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Queue asynchronous build for an EpochShuffling
|
|
56
|
-
*/
|
|
57
|
-
build(epoch: Epoch, decisionRoot: RootHex, state: BeaconStateAllForks, activeIndices: Uint32Array): void;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Readonly interface for EpochShuffling.
|
|
62
|
-
*/
|
|
63
|
-
export type ReadonlyEpochShuffling = {
|
|
64
|
-
readonly epoch: Epoch;
|
|
65
|
-
readonly committees: Readonly<ValidatorIndex[][][]>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type EpochShuffling = {
|
|
69
|
-
/**
|
|
70
|
-
* Epoch being shuffled
|
|
71
|
-
*/
|
|
72
|
-
epoch: Epoch;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Non-shuffled active validator indices
|
|
76
|
-
*/
|
|
77
|
-
activeIndices: Uint32Array;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The active validator indices, shuffled into their committee
|
|
81
|
-
*/
|
|
82
|
-
shuffling: Uint32Array;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* List of list of committees Committees
|
|
86
|
-
*
|
|
87
|
-
* Committees by index, by slot
|
|
88
|
-
*
|
|
89
|
-
* Note: With a high amount of shards, or low amount of validators,
|
|
90
|
-
* some shards may not have a committee this epoch
|
|
91
|
-
*/
|
|
92
|
-
committees: Uint32Array[][];
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Committees per slot, for fast attestation verification
|
|
96
|
-
*/
|
|
97
|
-
committeesPerSlot: number;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export function computeCommitteeCount(activeValidatorCount: number): number {
|
|
101
|
-
const validatorsPerSlot = intDiv(activeValidatorCount, SLOTS_PER_EPOCH);
|
|
102
|
-
const committeesPerSlot = intDiv(validatorsPerSlot, TARGET_COMMITTEE_SIZE);
|
|
103
|
-
return Math.max(1, Math.min(MAX_COMMITTEES_PER_SLOT, committeesPerSlot));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function buildCommitteesFromShuffling(shuffling: Uint32Array): Uint32Array[][] {
|
|
107
|
-
const activeValidatorCount = shuffling.length;
|
|
108
|
-
const committeesPerSlot = computeCommitteeCount(activeValidatorCount);
|
|
109
|
-
const committeeCount = committeesPerSlot * SLOTS_PER_EPOCH;
|
|
110
|
-
|
|
111
|
-
const committees = new Array<Uint32Array[]>(SLOTS_PER_EPOCH);
|
|
112
|
-
for (let slot = 0; slot < SLOTS_PER_EPOCH; slot++) {
|
|
113
|
-
const slotCommittees = new Array<Uint32Array>(committeesPerSlot);
|
|
114
|
-
|
|
115
|
-
for (let committeeIndex = 0; committeeIndex < committeesPerSlot; committeeIndex++) {
|
|
116
|
-
const index = slot * committeesPerSlot + committeeIndex;
|
|
117
|
-
const startOffset = Math.floor((activeValidatorCount * index) / committeeCount);
|
|
118
|
-
const endOffset = Math.floor((activeValidatorCount * (index + 1)) / committeeCount);
|
|
119
|
-
if (!(startOffset <= endOffset)) {
|
|
120
|
-
throw new Error(`Invalid offsets: start ${startOffset} must be less than or equal end ${endOffset}`);
|
|
121
|
-
}
|
|
122
|
-
slotCommittees[committeeIndex] = shuffling.subarray(startOffset, endOffset);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
committees[slot] = slotCommittees;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return committees;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function computeEpochShuffling(
|
|
132
|
-
// TODO: (@matthewkeil) remove state/epoch and pass in seed to clean this up
|
|
133
|
-
state: BeaconStateAllForks,
|
|
134
|
-
activeIndices: Uint32Array,
|
|
135
|
-
epoch: Epoch
|
|
136
|
-
): EpochShuffling {
|
|
137
|
-
const seed = getSeed(state, epoch, DOMAIN_BEACON_ATTESTER);
|
|
138
|
-
const shuffling = unshuffleList(activeIndices, seed, SHUFFLE_ROUND_COUNT);
|
|
139
|
-
const committees = buildCommitteesFromShuffling(shuffling);
|
|
140
|
-
return {
|
|
141
|
-
epoch,
|
|
142
|
-
activeIndices,
|
|
143
|
-
shuffling,
|
|
144
|
-
committees,
|
|
145
|
-
committeesPerSlot: committees[0].length,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export async function computeEpochShufflingAsync(
|
|
150
|
-
// TODO: (@matthewkeil) remove state/epoch and pass in seed to clean this up
|
|
151
|
-
state: BeaconStateAllForks,
|
|
152
|
-
activeIndices: Uint32Array,
|
|
153
|
-
epoch: Epoch
|
|
154
|
-
): Promise<EpochShuffling> {
|
|
155
|
-
const seed = getSeed(state, epoch, DOMAIN_BEACON_ATTESTER);
|
|
156
|
-
const shuffling = await asyncUnshuffleList(activeIndices, seed, SHUFFLE_ROUND_COUNT);
|
|
157
|
-
const committees = buildCommitteesFromShuffling(shuffling);
|
|
158
|
-
return {
|
|
159
|
-
epoch,
|
|
160
|
-
activeIndices,
|
|
161
|
-
shuffling,
|
|
162
|
-
committees,
|
|
163
|
-
committeesPerSlot: committees[0].length,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function calculateDecisionRoot(state: BeaconStateAllForks, epoch: Epoch): RootHex {
|
|
168
|
-
const pivotSlot = computeStartSlotAtEpoch(epoch - 1) - 1;
|
|
169
|
-
return toRootHex(getBlockRootAtSlot(state, pivotSlot));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Get the shuffling decision block root for the given epoch of given state
|
|
174
|
-
* - Special case close to genesis block, return the genesis block root
|
|
175
|
-
* - This is similar to forkchoice.getDependentRoot() function, otherwise we cannot get cached shuffing in attestation verification when syncing from genesis.
|
|
176
|
-
*/
|
|
177
|
-
export function calculateShufflingDecisionRoot(
|
|
178
|
-
config: BeaconConfig,
|
|
179
|
-
state: BeaconStateAllForks,
|
|
180
|
-
epoch: Epoch
|
|
181
|
-
): RootHex {
|
|
182
|
-
return state.slot > GENESIS_SLOT
|
|
183
|
-
? calculateDecisionRoot(state, epoch)
|
|
184
|
-
: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(computeAnchorCheckpoint(config, state).blockHeader));
|
|
185
|
-
}
|
package/src/util/execution.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import {ForkName, ForkPostBellatrix, ForkSeq} from "@lodestar/params";
|
|
2
|
-
import {
|
|
3
|
-
BeaconBlock,
|
|
4
|
-
BeaconBlockBody,
|
|
5
|
-
BlindedBeaconBlock,
|
|
6
|
-
BlindedBeaconBlockBody,
|
|
7
|
-
ExecutionPayload,
|
|
8
|
-
ExecutionPayloadHeader,
|
|
9
|
-
bellatrix,
|
|
10
|
-
capella,
|
|
11
|
-
deneb,
|
|
12
|
-
isBlindedBeaconBlockBody,
|
|
13
|
-
isExecutionPayload,
|
|
14
|
-
ssz,
|
|
15
|
-
} from "@lodestar/types";
|
|
16
|
-
import {
|
|
17
|
-
BeaconStateAllForks,
|
|
18
|
-
BeaconStateBellatrix,
|
|
19
|
-
BeaconStateCapella,
|
|
20
|
-
BeaconStateExecutions,
|
|
21
|
-
CachedBeaconStateAllForks,
|
|
22
|
-
CachedBeaconStateExecutions,
|
|
23
|
-
} from "../types.js";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Execution enabled = merge is done.
|
|
27
|
-
* When (A) state has execution data OR (B) block has execution data
|
|
28
|
-
*/
|
|
29
|
-
export function isExecutionEnabled(state: BeaconStateExecutions, block: BeaconBlock | BlindedBeaconBlock): boolean {
|
|
30
|
-
if (isMergeTransitionComplete(state)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Throws if not post-bellatrix block. A fork-guard in isExecutionEnabled() prevents this from happening
|
|
35
|
-
const payload = getFullOrBlindedPayload(block);
|
|
36
|
-
// Note: spec says to check all payload is zero-ed. However a state-root cannot be zero for any non-empty payload
|
|
37
|
-
// TODO: Consider comparing with the payload root if this assumption is not correct.
|
|
38
|
-
// return !byteArrayEquals(payload.stateRoot, ZERO_HASH);
|
|
39
|
-
|
|
40
|
-
// UPDATE: stateRoot comparision should have been enough with zero hash, but spec tests were failing
|
|
41
|
-
// Revisit this later to fix specs and make this efficient
|
|
42
|
-
return isExecutionPayload(payload)
|
|
43
|
-
? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
|
|
44
|
-
: !ssz.bellatrix.ExecutionPayloadHeader.equals(
|
|
45
|
-
state.latestExecutionPayloadHeader,
|
|
46
|
-
// TODO: Performance
|
|
47
|
-
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Merge block is the SINGLE block that transitions from POW to POS.
|
|
53
|
-
* state has no execution data AND this block has execution data
|
|
54
|
-
*/
|
|
55
|
-
export function isMergeTransitionBlock(state: BeaconStateExecutions, body: bellatrix.BeaconBlockBody): boolean {
|
|
56
|
-
return (
|
|
57
|
-
!isMergeTransitionComplete(state) &&
|
|
58
|
-
!ssz.bellatrix.ExecutionPayload.equals(body.executionPayload, ssz.bellatrix.ExecutionPayload.defaultValue())
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Merge is complete when the state includes execution layer data:
|
|
64
|
-
* state.latestExecutionPayloadHeader NOT EMPTY
|
|
65
|
-
*/
|
|
66
|
-
export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
|
|
67
|
-
if (!isCapellaStateType(state)) {
|
|
68
|
-
return !ssz.bellatrix.ExecutionPayloadHeader.equals(
|
|
69
|
-
(state as BeaconStateBellatrix).latestExecutionPayloadHeader,
|
|
70
|
-
// TODO: Performance
|
|
71
|
-
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return !ssz.capella.ExecutionPayloadHeader.equals(
|
|
76
|
-
state.latestExecutionPayloadHeader,
|
|
77
|
-
// TODO: Performance
|
|
78
|
-
ssz.capella.ExecutionPayloadHeader.defaultValue()
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Type guard for bellatrix.BeaconState */
|
|
83
|
-
export function isExecutionStateType(state: BeaconStateAllForks): state is BeaconStateExecutions {
|
|
84
|
-
return (state as BeaconStateExecutions).latestExecutionPayloadHeader !== undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Type guard for capella.BeaconState */
|
|
88
|
-
export function isCapellaStateType(state: BeaconStateAllForks): state is BeaconStateCapella {
|
|
89
|
-
return (
|
|
90
|
-
(state as BeaconStateCapella).latestExecutionPayloadHeader !== undefined &&
|
|
91
|
-
(state as BeaconStateCapella).latestExecutionPayloadHeader.withdrawalsRoot !== undefined
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Type guard for bellatrix.CachedBeaconState */
|
|
96
|
-
export function isExecutionCachedStateType(state: CachedBeaconStateAllForks): state is CachedBeaconStateExecutions {
|
|
97
|
-
return (state as CachedBeaconStateExecutions).latestExecutionPayloadHeader !== undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Type guard for ExecutionBlockBody */
|
|
101
|
-
export function isExecutionBlockBodyType(blockBody: BeaconBlockBody): blockBody is BeaconBlockBody<ForkPostBellatrix> {
|
|
102
|
-
return (blockBody as BeaconBlockBody<ForkPostBellatrix>).executionPayload !== undefined;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function getFullOrBlindedPayload(block: BeaconBlock): ExecutionPayload | ExecutionPayloadHeader {
|
|
106
|
-
return getFullOrBlindedPayloadFromBody(block.body);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function getFullOrBlindedPayloadFromBody(
|
|
110
|
-
body: BeaconBlockBody | BlindedBeaconBlockBody
|
|
111
|
-
): ExecutionPayload | ExecutionPayloadHeader {
|
|
112
|
-
if (isBlindedBeaconBlockBody(body)) {
|
|
113
|
-
return body.executionPayloadHeader;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if ((body as bellatrix.BeaconBlockBody).executionPayload !== undefined) {
|
|
117
|
-
return (body as bellatrix.BeaconBlockBody).executionPayload;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
throw Error("Not full or blinded beacon block");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function isCapellaPayload(
|
|
124
|
-
payload: ExecutionPayload | ExecutionPayloadHeader
|
|
125
|
-
): payload is ExecutionPayload<ForkName.capella> | ExecutionPayloadHeader<ForkName.capella> {
|
|
126
|
-
return (
|
|
127
|
-
(payload as ExecutionPayload<ForkName.capella>).withdrawals !== undefined ||
|
|
128
|
-
(payload as ExecutionPayloadHeader<ForkName.capella>).withdrawalsRoot !== undefined
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function isCapellaPayloadHeader(
|
|
133
|
-
payload: capella.FullOrBlindedExecutionPayload
|
|
134
|
-
): payload is capella.ExecutionPayloadHeader {
|
|
135
|
-
return (payload as capella.ExecutionPayloadHeader).withdrawalsRoot !== undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function executionPayloadToPayloadHeader(fork: ForkSeq, payload: ExecutionPayload): ExecutionPayloadHeader {
|
|
139
|
-
const transactionsRoot = ssz.bellatrix.Transactions.hashTreeRoot(payload.transactions);
|
|
140
|
-
|
|
141
|
-
const bellatrixPayloadFields: ExecutionPayloadHeader = {
|
|
142
|
-
parentHash: payload.parentHash,
|
|
143
|
-
feeRecipient: payload.feeRecipient,
|
|
144
|
-
stateRoot: payload.stateRoot,
|
|
145
|
-
receiptsRoot: payload.receiptsRoot,
|
|
146
|
-
logsBloom: payload.logsBloom,
|
|
147
|
-
prevRandao: payload.prevRandao,
|
|
148
|
-
blockNumber: payload.blockNumber,
|
|
149
|
-
gasLimit: payload.gasLimit,
|
|
150
|
-
gasUsed: payload.gasUsed,
|
|
151
|
-
timestamp: payload.timestamp,
|
|
152
|
-
extraData: payload.extraData,
|
|
153
|
-
baseFeePerGas: payload.baseFeePerGas,
|
|
154
|
-
blockHash: payload.blockHash,
|
|
155
|
-
transactionsRoot,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
if (fork >= ForkSeq.capella) {
|
|
159
|
-
(bellatrixPayloadFields as capella.ExecutionPayloadHeader).withdrawalsRoot = ssz.capella.Withdrawals.hashTreeRoot(
|
|
160
|
-
(payload as capella.ExecutionPayload).withdrawals
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (fork >= ForkSeq.deneb) {
|
|
165
|
-
// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/beacon-chain.md#process_execution_payload
|
|
166
|
-
(bellatrixPayloadFields as deneb.ExecutionPayloadHeader).blobGasUsed = (
|
|
167
|
-
payload as deneb.ExecutionPayloadHeader | deneb.ExecutionPayload
|
|
168
|
-
).blobGasUsed;
|
|
169
|
-
(bellatrixPayloadFields as deneb.ExecutionPayloadHeader).excessBlobGas = (
|
|
170
|
-
payload as deneb.ExecutionPayloadHeader | deneb.ExecutionPayload
|
|
171
|
-
).excessBlobGas;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// No change in Electra
|
|
175
|
-
|
|
176
|
-
return bellatrixPayloadFields;
|
|
177
|
-
}
|
package/src/util/finality.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {MIN_EPOCHS_TO_INACTIVITY_PENALTY} from "@lodestar/params";
|
|
2
|
-
import {CachedBeaconStateAllForks} from "../types.js";
|
|
3
|
-
|
|
4
|
-
export function getFinalityDelay(state: CachedBeaconStateAllForks): number {
|
|
5
|
-
// previousEpoch = epoch - 1
|
|
6
|
-
return state.epochCtx.epoch - 1 - state.finalizedCheckpoint.epoch;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* If the chain has not been finalized for >4 epochs, the chain enters an "inactivity leak" mode,
|
|
11
|
-
* where inactive validators get progressively penalized more and more, to reduce their influence
|
|
12
|
-
* until blocks get finalized again. See here (https://github.com/ethereum/annotated-spec/blob/master/phase0/beacon-chain.md#inactivity-quotient) for what the inactivity leak is, what it's for and how
|
|
13
|
-
* it works.
|
|
14
|
-
*/
|
|
15
|
-
export function isInInactivityLeak(state: CachedBeaconStateAllForks): boolean {
|
|
16
|
-
return getFinalityDelay(state) > MIN_EPOCHS_TO_INACTIVITY_PENALTY;
|
|
17
|
-
}
|
package/src/util/fulu.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {ForkSeq, MIN_SEED_LOOKAHEAD} from "@lodestar/params";
|
|
2
|
-
import {ValidatorIndex} from "@lodestar/types";
|
|
3
|
-
import {CachedBeaconStateElectra} from "../types.js";
|
|
4
|
-
import {computeEpochShuffling} from "./epochShuffling.js";
|
|
5
|
-
import {computeProposerIndices} from "./seed.js";
|
|
6
|
-
import {getActiveValidatorIndices} from "./validator.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Return the proposer indices for the full available lookahead starting from current epoch.
|
|
10
|
-
* Used to initialize the `proposer_lookahead` field in the beacon state at genesis and after forks.
|
|
11
|
-
*/
|
|
12
|
-
export function initializeProposerLookahead(state: CachedBeaconStateElectra): ValidatorIndex[] {
|
|
13
|
-
const currentEpoch = state.epochCtx.epoch;
|
|
14
|
-
|
|
15
|
-
const lookahead: ValidatorIndex[] = [];
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i <= MIN_SEED_LOOKAHEAD; i++) {
|
|
18
|
-
const epoch = currentEpoch + i;
|
|
19
|
-
|
|
20
|
-
// Try to pull cached shuffling first
|
|
21
|
-
let shuffling = state.epochCtx.getShufflingAtEpochOrNull(epoch);
|
|
22
|
-
|
|
23
|
-
if (!shuffling) {
|
|
24
|
-
// Only compute epoch shuffling if cache is not yet populated
|
|
25
|
-
let activeIndices: Uint32Array;
|
|
26
|
-
if (epoch === currentEpoch) {
|
|
27
|
-
// This should never happen as current shuffling will always be cached
|
|
28
|
-
activeIndices = state.epochCtx.currentShuffling.activeIndices;
|
|
29
|
-
} else if (epoch === currentEpoch + 1) {
|
|
30
|
-
activeIndices = state.epochCtx.nextActiveIndices;
|
|
31
|
-
} else {
|
|
32
|
-
// This will never be reached with current spec as `MIN_SEED_LOOKAHEAD == 1`
|
|
33
|
-
activeIndices = getActiveValidatorIndices(state, epoch);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
shuffling = computeEpochShuffling(state, activeIndices, epoch);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
lookahead.push(...computeProposerIndices(ForkSeq.fulu, state, shuffling, epoch));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return lookahead;
|
|
43
|
-
}
|