@lodestar/state-transition 1.50.0-dev.859c034d37 → 1.50.0-dev.90ea92ca6e
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/indexedBuilderState.d.ts +19 -0
- package/lib/block/indexedBuilderState.d.ts.map +1 -0
- package/lib/block/indexedBuilderState.js +60 -0
- package/lib/block/indexedBuilderState.js.map +1 -0
- package/lib/block/processBuilderDepositRequest.d.ts +2 -2
- package/lib/block/processBuilderDepositRequest.d.ts.map +1 -1
- package/lib/block/processBuilderDepositRequest.js +5 -4
- package/lib/block/processBuilderDepositRequest.js.map +1 -1
- package/lib/block/processBuilderExitRequest.d.ts +2 -2
- package/lib/block/processBuilderExitRequest.d.ts.map +1 -1
- package/lib/block/processBuilderExitRequest.js +4 -3
- package/lib/block/processBuilderExitRequest.js.map +1 -1
- package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
- package/lib/block/processParentExecutionPayload.js +23 -18
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +0 -23
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/slashValidator.d.ts.map +1 -1
- package/lib/block/slashValidator.js +11 -0
- package/lib/block/slashValidator.js.map +1 -1
- package/lib/epoch/processPendingDeposits.d.ts.map +1 -1
- package/lib/epoch/processPendingDeposits.js +8 -4
- package/lib/epoch/processPendingDeposits.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +8 -1
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +2 -2
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +2 -6
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +2 -32
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +22 -21
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +71 -71
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +34 -21
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +92 -100
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +339 -368
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts +6 -5
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +12 -8
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/util/gloas.d.ts +11 -14
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +2 -42
- package/lib/util/gloas.js.map +1 -1
- package/package.json +8 -8
- package/src/block/indexedBuilderState.ts +65 -0
- package/src/block/processBuilderDepositRequest.ts +6 -17
- package/src/block/processBuilderExitRequest.ts +5 -9
- package/src/block/processParentExecutionPayload.ts +27 -23
- package/src/block/processProposerSlashing.ts +2 -28
- package/src/block/slashValidator.ts +13 -2
- package/src/epoch/processPendingDeposits.ts +14 -3
- package/src/index.ts +4 -1
- package/src/rewards/attestationsRewards.ts +8 -1
- package/src/signatureSets/index.ts +4 -2
- package/src/signatureSets/voluntaryExits.ts +3 -55
- package/src/stateView/beaconStateView.ts +75 -76
- package/src/stateView/interface.ts +61 -21
- package/src/stateView/nativeBeaconStateView.ts +354 -375
- package/src/stateView/stateViewFactory.ts +21 -12
- package/src/util/gloas.ts +2 -53
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
-
import {ForkSeq
|
|
2
|
+
import {ForkSeq} from "@lodestar/params";
|
|
3
3
|
import {Slot, phase0, ssz} from "@lodestar/types";
|
|
4
4
|
import {Validator} from "@lodestar/types/phase0";
|
|
5
5
|
import {getProposerSlashingSignatureSets} from "../signatureSets/index.js";
|
|
6
|
-
import {CachedBeaconStateAllForks
|
|
6
|
+
import {CachedBeaconStateAllForks} from "../types.js";
|
|
7
7
|
import {computeEpochAtSlot, isSlashableValidator} from "../util/index.js";
|
|
8
8
|
import {verifySignatureSet} from "../util/signatureSets.js";
|
|
9
9
|
import {slashValidator} from "./slashValidator.js";
|
|
@@ -23,32 +23,6 @@ export function processProposerSlashing(
|
|
|
23
23
|
const proposer = state.validators.getReadonly(proposerSlashing.signedHeader1.message.proposerIndex);
|
|
24
24
|
assertValidProposerSlashing(state.config, state.slot, proposerSlashing, proposer, verifySignatures);
|
|
25
25
|
|
|
26
|
-
if (fork >= ForkSeq.gloas) {
|
|
27
|
-
// Remove the BuilderPendingPayment corresponding to this proposal if it is still in the
|
|
28
|
-
// 2-epoch window. Only clear it when the slashed validator is the proposer associated with
|
|
29
|
-
// the payment; otherwise an unrelated same-slot equivocation could grief an honest proposer's
|
|
30
|
-
// payment.
|
|
31
|
-
const slot = Number(proposerSlashing.signedHeader1.message.slot);
|
|
32
|
-
const proposalEpoch = computeEpochAtSlot(slot);
|
|
33
|
-
const currentEpoch = state.epochCtx.epoch;
|
|
34
|
-
const previousEpoch = currentEpoch - 1;
|
|
35
|
-
|
|
36
|
-
const paymentIndex =
|
|
37
|
-
proposalEpoch === currentEpoch
|
|
38
|
-
? SLOTS_PER_EPOCH + (slot % SLOTS_PER_EPOCH)
|
|
39
|
-
: proposalEpoch === previousEpoch
|
|
40
|
-
? slot % SLOTS_PER_EPOCH
|
|
41
|
-
: undefined;
|
|
42
|
-
|
|
43
|
-
if (paymentIndex !== undefined) {
|
|
44
|
-
const builderPendingPayments = (state as CachedBeaconStateGloas).builderPendingPayments;
|
|
45
|
-
const payment = builderPendingPayments.get(paymentIndex);
|
|
46
|
-
if (payment.proposerIndex === proposerSlashing.signedHeader1.message.proposerIndex) {
|
|
47
|
-
builderPendingPayments.set(paymentIndex, ssz.gloas.BuilderPendingPayment.defaultViewDU());
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
26
|
slashValidator(fork, state, proposerSlashing.signedHeader1.message.proposerIndex);
|
|
53
27
|
}
|
|
54
28
|
|
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
WHISTLEBLOWER_REWARD_QUOTIENT,
|
|
14
14
|
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA,
|
|
15
15
|
} from "@lodestar/params";
|
|
16
|
-
import {ValidatorIndex} from "@lodestar/types";
|
|
17
|
-
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
|
|
16
|
+
import {ValidatorIndex, ssz} from "@lodestar/types";
|
|
17
|
+
import {CachedBeaconStateAllForks, CachedBeaconStateAltair, CachedBeaconStateGloas} from "../types.js";
|
|
18
18
|
import {decreaseBalance, increaseBalance} from "../util/index.js";
|
|
19
19
|
import {initiateValidatorExit} from "./initiateValidatorExit.js";
|
|
20
20
|
|
|
@@ -95,4 +95,15 @@ export function slashValidator(
|
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
if (fork >= ForkSeq.gloas) {
|
|
100
|
+
// Cleared on every slashing, not only proposer slashings: a proposer slashed via an attester slashing
|
|
101
|
+
// first would otherwise keep the builder paying for a block it equivocated on
|
|
102
|
+
const {builderPendingPayments} = state as CachedBeaconStateGloas;
|
|
103
|
+
for (let i = 0; i < builderPendingPayments.length; i++) {
|
|
104
|
+
if (builderPendingPayments.getReadonly(i).proposerIndex === slashedIndex) {
|
|
105
|
+
builderPendingPayments.set(i, ssz.gloas.BuilderPendingPayment.defaultViewDU());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
98
109
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BLS_WITHDRAWAL_PREFIX,
|
|
3
|
+
FAR_FUTURE_EPOCH,
|
|
4
|
+
ForkSeq,
|
|
5
|
+
GENESIS_SLOT,
|
|
6
|
+
MAX_PENDING_DEPOSITS_PER_EPOCH,
|
|
7
|
+
} from "@lodestar/params";
|
|
2
8
|
import {electra} from "@lodestar/types";
|
|
3
9
|
import {addValidatorToRegistry, isValidDepositSignature} from "../block/processDeposit.js";
|
|
4
10
|
import {CachedBeaconStateElectra, EpochTransitionCache} from "../types.js";
|
|
@@ -71,7 +77,7 @@ export function processPendingDeposits(state: CachedBeaconStateElectra, cache: E
|
|
|
71
77
|
|
|
72
78
|
if (isValidatorWithdrawn) {
|
|
73
79
|
// Deposited balance will never become active. Increase balance but do not consume churn
|
|
74
|
-
applyPendingDeposit(state, deposit, cache);
|
|
80
|
+
applyPendingDeposit(fork, state, deposit, cache);
|
|
75
81
|
} else if (isValidatorExited) {
|
|
76
82
|
// Validator is exiting, postpone the deposit until after withdrawable epoch
|
|
77
83
|
depositsToPostpone.push(deposit);
|
|
@@ -83,7 +89,7 @@ export function processPendingDeposits(state: CachedBeaconStateElectra, cache: E
|
|
|
83
89
|
}
|
|
84
90
|
// Consume churn and apply deposit.
|
|
85
91
|
processedAmount += deposit.amount;
|
|
86
|
-
applyPendingDeposit(state, deposit, cache);
|
|
92
|
+
applyPendingDeposit(fork, state, deposit, cache);
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
// Regardless of how the deposit was handled, we move on in the queue.
|
|
@@ -110,6 +116,7 @@ export function processPendingDeposits(state: CachedBeaconStateElectra, cache: E
|
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
function applyPendingDeposit(
|
|
119
|
+
fork: ForkSeq,
|
|
113
120
|
state: CachedBeaconStateElectra,
|
|
114
121
|
deposit: electra.PendingDeposit,
|
|
115
122
|
cache: EpochTransitionCache
|
|
@@ -119,6 +126,10 @@ function applyPendingDeposit(
|
|
|
119
126
|
const cachedBalances = cache.balances;
|
|
120
127
|
|
|
121
128
|
if (!isValidatorKnown(state, validatorIndex)) {
|
|
129
|
+
// Do not create validators with BLS withdrawal credentials, the deposit is skipped without a refund
|
|
130
|
+
if (fork >= ForkSeq.heze && withdrawalCredentials[0] === BLS_WITHDRAWAL_PREFIX) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
122
133
|
// Verify the deposit signature (proof of possession) which is not checked by the deposit contract
|
|
123
134
|
if (isValidDepositSignature(state.config, pubkey, withdrawalCredentials, amount, signature)) {
|
|
124
135
|
addValidatorToRegistry(ForkSeq.electra, state, pubkey, withdrawalCredentials, amount);
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export {type BlockExternalData, DataAvailabilityStatus, ExecutionPayloadStatus} from "./block/externalData.js";
|
|
2
|
+
export {IndexedBuilderState} from "./block/indexedBuilderState.js";
|
|
2
3
|
export {getAttestationParticipationStatus, processAttestationsAltair} from "./block/processAttestationsAltair.js";
|
|
3
4
|
export {assertValidAttesterSlashing} from "./block/processAttesterSlashing.js";
|
|
4
5
|
export {isValidBlsToExecutionChange} from "./block/processBlsToExecutionChange.js";
|
|
@@ -43,7 +44,7 @@ export * from "./signatureSets/index.js";
|
|
|
43
44
|
export * from "./stateTransition.js";
|
|
44
45
|
export {BeaconStateView} from "./stateView/beaconStateView.js";
|
|
45
46
|
export {
|
|
46
|
-
type
|
|
47
|
+
type BlockSTFInput,
|
|
47
48
|
type ComputeNewStateRootResult,
|
|
48
49
|
type IBeaconStateView,
|
|
49
50
|
type IBeaconStateViewAltair,
|
|
@@ -54,6 +55,7 @@ export {
|
|
|
54
55
|
type IBeaconStateViewFulu,
|
|
55
56
|
type IBeaconStateViewGloas,
|
|
56
57
|
type IBeaconStateViewHeze,
|
|
58
|
+
type IBeaconStateViewNative,
|
|
57
59
|
isStatePostAltair,
|
|
58
60
|
isStatePostBellatrix,
|
|
59
61
|
isStatePostCapella,
|
|
@@ -63,6 +65,7 @@ export {
|
|
|
63
65
|
isStatePostGloas,
|
|
64
66
|
isStatePostHeze,
|
|
65
67
|
} from "./stateView/interface.js";
|
|
68
|
+
export {NativeBeaconStateView} from "./stateView/nativeBeaconStateView.js";
|
|
66
69
|
export {createBeaconStateView, createBeaconStateViewForHistoricalRegen} from "./stateView/stateViewFactory.js";
|
|
67
70
|
export type {
|
|
68
71
|
BeaconStateAllForks,
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
import {ValidatorIndex, rewards} from "@lodestar/types";
|
|
19
19
|
import {fromHex} from "@lodestar/utils";
|
|
20
20
|
import {EpochTransitionCache, beforeProcessEpoch} from "../cache/epochTransitionCache.js";
|
|
21
|
+
import {processInactivityUpdates} from "../epoch/processInactivityUpdates.js";
|
|
22
|
+
import {processJustificationAndFinalization} from "../epoch/processJustificationAndFinalization.js";
|
|
21
23
|
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
|
|
22
24
|
import {
|
|
23
25
|
FLAG_ELIGIBLE_ATTESTER,
|
|
@@ -45,8 +47,13 @@ export async function computeAttestationsRewards(
|
|
|
45
47
|
throw Error("Unsupported fork. Attestations rewards calculation is not available in phase0");
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
// Rewards are computed after justification and inactivity updates in epoch processing, so apply both to a clone
|
|
51
|
+
// before reading finality and inactivity scores, see
|
|
52
|
+
// https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.2/specs/altair/beacon-chain.md#epoch-processing
|
|
53
|
+
const stateAltair = state.clone() as CachedBeaconStateAltair;
|
|
49
54
|
const transitionCache = beforeProcessEpoch(stateAltair);
|
|
55
|
+
processJustificationAndFinalization(stateAltair, transitionCache);
|
|
56
|
+
processInactivityUpdates(stateAltair, transitionCache);
|
|
50
57
|
|
|
51
58
|
const [idealRewards, penalties] = computeIdealAttestationsRewardsAndPenaltiesAltair(
|
|
52
59
|
config,
|
|
@@ -12,7 +12,7 @@ import {getPayloadAttestationDataSigningRoot} from "./indexedPayloadAttestation.
|
|
|
12
12
|
import {getBlockProposerSignatureSet} from "./proposer.js";
|
|
13
13
|
import {getProposerSlashingsSignatureSets} from "./proposerSlashings.js";
|
|
14
14
|
import {getRandaoRevealSignatureSet} from "./randao.js";
|
|
15
|
-
import {
|
|
15
|
+
import {getVoluntaryExitSignatureSet} from "./voluntaryExits.js";
|
|
16
16
|
|
|
17
17
|
export * from "./attesterSlashings.js";
|
|
18
18
|
export * from "./blsToExecutionChange.js";
|
|
@@ -49,7 +49,9 @@ export function getBlockSignatureSets(
|
|
|
49
49
|
...getProposerSlashingsSignatureSets(config, signedBlock),
|
|
50
50
|
...getAttesterSlashingsSignatureSets(config, signedBlock),
|
|
51
51
|
...getAttestationsSignatureSets(config, signedBlock, indexedAttestations),
|
|
52
|
-
...
|
|
52
|
+
...signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
|
|
53
|
+
getVoluntaryExitSignatureSet(config, state, voluntaryExit)
|
|
54
|
+
),
|
|
53
55
|
];
|
|
54
56
|
|
|
55
57
|
if (!opts?.skipProposerSignature) {
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {IBeaconStateView, IBeaconStateViewGloas, isStatePostGloas} from "../stateView/interface.js";
|
|
2
|
+
import {phase0, ssz} from "@lodestar/types";
|
|
3
|
+
import {IBeaconStateView} from "../stateView/interface.js";
|
|
5
4
|
import {
|
|
6
5
|
ISignatureSet,
|
|
7
6
|
SignatureSetType,
|
|
8
7
|
computeSigningRoot,
|
|
9
8
|
computeStartSlotAtEpoch,
|
|
10
|
-
convertValidatorIndexToBuilderIndex,
|
|
11
|
-
isBuilderIndex,
|
|
12
9
|
verifySignatureSet,
|
|
13
10
|
} from "../util/index.js";
|
|
14
11
|
|
|
@@ -27,36 +24,9 @@ export function getVoluntaryExitSignatureSet(
|
|
|
27
24
|
config: BeaconConfig,
|
|
28
25
|
state: IBeaconStateView,
|
|
29
26
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
30
|
-
): ISignatureSet {
|
|
31
|
-
const fork = config.getForkSeq(state.slot);
|
|
32
|
-
|
|
33
|
-
if (fork >= ForkSeq.gloas && isBuilderVoluntaryExit(signedVoluntaryExit)) {
|
|
34
|
-
if (!isStatePostGloas(state)) {
|
|
35
|
-
throw new Error(`Expected gloas+ state for builder voluntary exit signature, got fork=${state.forkName}`);
|
|
36
|
-
}
|
|
37
|
-
return getBuilderVoluntaryExitSignatureSet(config, state, signedVoluntaryExit);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return getValidatorVoluntaryExitSignatureSet(config, state.slot, signedVoluntaryExit);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getVoluntaryExitsSignatureSets(
|
|
44
|
-
config: BeaconConfig,
|
|
45
|
-
state: IBeaconStateView,
|
|
46
|
-
signedBlock: SignedBeaconBlock
|
|
47
|
-
): ISignatureSet[] {
|
|
48
|
-
return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
|
|
49
|
-
getVoluntaryExitSignatureSet(config, state, voluntaryExit)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function getValidatorVoluntaryExitSignatureSet(
|
|
54
|
-
config: BeaconConfig,
|
|
55
|
-
stateSlot: Slot,
|
|
56
|
-
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
57
27
|
): ISignatureSet {
|
|
58
28
|
const messageSlot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
|
|
59
|
-
const domain = config.getDomainForVoluntaryExit(
|
|
29
|
+
const domain = config.getDomainForVoluntaryExit(state.slot, messageSlot);
|
|
60
30
|
|
|
61
31
|
return {
|
|
62
32
|
type: SignatureSetType.indexed,
|
|
@@ -65,25 +35,3 @@ export function getValidatorVoluntaryExitSignatureSet(
|
|
|
65
35
|
signature: signedVoluntaryExit.signature,
|
|
66
36
|
};
|
|
67
37
|
}
|
|
68
|
-
|
|
69
|
-
export function getBuilderVoluntaryExitSignatureSet(
|
|
70
|
-
config: BeaconConfig,
|
|
71
|
-
state: IBeaconStateViewGloas,
|
|
72
|
-
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
73
|
-
): ISignatureSet {
|
|
74
|
-
const messageSlot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
|
|
75
|
-
const domain = config.getDomainForVoluntaryExit(state.slot, messageSlot);
|
|
76
|
-
const builderIndex = convertValidatorIndexToBuilderIndex(signedVoluntaryExit.message.validatorIndex);
|
|
77
|
-
const builder = state.getBuilder(builderIndex);
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
type: SignatureSetType.single,
|
|
81
|
-
pubkey: builder.pubkey,
|
|
82
|
-
signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
|
|
83
|
-
signature: signedVoluntaryExit.signature,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function isBuilderVoluntaryExit(signedVoluntaryExit: phase0.SignedVoluntaryExit): boolean {
|
|
88
|
-
return isBuilderIndex(signedVoluntaryExit.message.validatorIndex);
|
|
89
|
-
}
|
|
@@ -14,8 +14,6 @@ import {
|
|
|
14
14
|
ExecutionPayloadHeader,
|
|
15
15
|
Root,
|
|
16
16
|
RootHex,
|
|
17
|
-
SignedBeaconBlock,
|
|
18
|
-
SignedBlindedBeaconBlock,
|
|
19
17
|
Slot,
|
|
20
18
|
SyncCommittee,
|
|
21
19
|
ValidatorIndex,
|
|
@@ -71,7 +69,7 @@ import {getRandaoMix} from "../util/seed.js";
|
|
|
71
69
|
import {getLatestWeakSubjectivityCheckpointEpoch} from "../util/weakSubjectivity.js";
|
|
72
70
|
import {computeNewStateRootStateTransitionOpts, getComputeNewStateRootResult} from "./computeNewStateRoot.js";
|
|
73
71
|
import {
|
|
74
|
-
|
|
72
|
+
BlockSTFInput,
|
|
75
73
|
ComputeNewStateRootResult,
|
|
76
74
|
IBeaconStateView,
|
|
77
75
|
IBeaconStateViewGloas,
|
|
@@ -83,34 +81,36 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
83
81
|
private readonly config: BeaconConfig;
|
|
84
82
|
// Cached values extracted from the tree
|
|
85
83
|
// phase0
|
|
86
|
-
private
|
|
87
|
-
private
|
|
84
|
+
private cachedFork: Fork | null = null;
|
|
85
|
+
private cachedLatestBlockHeader: phase0.BeaconBlockHeader | null = null;
|
|
88
86
|
// altair
|
|
89
|
-
private
|
|
90
|
-
private
|
|
91
|
-
private
|
|
92
|
-
private
|
|
87
|
+
private cachedCurrentSyncCommittee: SyncCommittee | null = null;
|
|
88
|
+
private cachedNextSyncCommittee: SyncCommittee | null = null;
|
|
89
|
+
private cachedPreviousEpochParticipation: Uint8Array | null = null;
|
|
90
|
+
private cachedCurrentEpochParticipation: Uint8Array | null = null;
|
|
93
91
|
// bellatrix
|
|
94
|
-
private
|
|
92
|
+
private cachedLatestExecutionPayloadHeader: ExecutionPayloadHeader | null = null;
|
|
95
93
|
// capella
|
|
96
|
-
private
|
|
94
|
+
private cachedHistoricalSummaries: capella.HistoricalSummaries | null = null;
|
|
97
95
|
// electra
|
|
98
|
-
private
|
|
99
|
-
private
|
|
100
|
-
private
|
|
96
|
+
private cachedPendingPartialWithdrawals: electra.PendingPartialWithdrawals | null = null;
|
|
97
|
+
private cachedPendingConsolidations: electra.PendingConsolidations | null = null;
|
|
98
|
+
private cachedPendingDeposits: electra.PendingDeposits | null = null;
|
|
101
99
|
// fulu
|
|
102
|
-
private
|
|
100
|
+
private cachedProposerLookahead: fulu.ProposerLookahead | null = null;
|
|
103
101
|
// gloas
|
|
104
|
-
private
|
|
105
|
-
private
|
|
106
|
-
private
|
|
107
|
-
private
|
|
108
|
-
private
|
|
102
|
+
private cachedExecutionPayloadAvailability: BitArray | null = null;
|
|
103
|
+
private cachedLatestExecutionPayloadBid: ExecutionPayloadBid | null = null;
|
|
104
|
+
private cachedPayloadExpectedWithdrawals: capella.Withdrawal[] | null = null;
|
|
105
|
+
private cachedBuilderPendingPayments: gloas.BuilderPendingPayments | null = null;
|
|
106
|
+
private cachedBuilderPendingWithdrawals: gloas.BuilderPendingWithdrawals | null = null;
|
|
109
107
|
|
|
110
108
|
constructor(readonly cachedState: CachedBeaconStateAllForks) {
|
|
111
109
|
this.config = cachedState.config;
|
|
112
110
|
}
|
|
113
111
|
|
|
112
|
+
release(): void {}
|
|
113
|
+
|
|
114
114
|
// phase0
|
|
115
115
|
|
|
116
116
|
get forkName(): ForkName {
|
|
@@ -126,10 +126,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
get fork(): Fork {
|
|
129
|
-
if (this.
|
|
130
|
-
this.
|
|
129
|
+
if (this.cachedFork === null) {
|
|
130
|
+
this.cachedFork = this.cachedState.fork.toValue();
|
|
131
131
|
}
|
|
132
|
-
return this.
|
|
132
|
+
return this.cachedFork;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
get epoch(): number {
|
|
@@ -149,10 +149,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
get latestBlockHeader(): phase0.BeaconBlockHeader {
|
|
152
|
-
if (this.
|
|
153
|
-
this.
|
|
152
|
+
if (this.cachedLatestBlockHeader === null) {
|
|
153
|
+
this.cachedLatestBlockHeader = this.cachedState.latestBlockHeader.toValue();
|
|
154
154
|
}
|
|
155
|
-
return this.
|
|
155
|
+
return this.cachedLatestBlockHeader;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
get previousJustifiedCheckpoint(): Checkpoint {
|
|
@@ -188,13 +188,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
188
188
|
throw new Error("previousEpochParticipation is not available before Altair");
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
if (this.
|
|
192
|
-
this.
|
|
191
|
+
if (this.cachedPreviousEpochParticipation === null) {
|
|
192
|
+
this.cachedPreviousEpochParticipation = (
|
|
193
193
|
this.cachedState as CachedBeaconStateAltair
|
|
194
194
|
).previousEpochParticipation.serialize();
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
return this.
|
|
197
|
+
return this.cachedPreviousEpochParticipation;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
// altair
|
|
@@ -204,13 +204,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
204
204
|
throw new Error("currentEpochParticipation is not available before Altair");
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
if (this.
|
|
208
|
-
this.
|
|
207
|
+
if (this.cachedCurrentEpochParticipation === null) {
|
|
208
|
+
this.cachedCurrentEpochParticipation = (
|
|
209
209
|
this.cachedState as CachedBeaconStateAltair
|
|
210
210
|
).currentEpochParticipation.serialize();
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
return this.
|
|
213
|
+
return this.cachedCurrentEpochParticipation;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
getPreviousEpochParticipation(validatorIndex: ValidatorIndex): number {
|
|
@@ -238,13 +238,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
238
238
|
throw new Error("latestExecutionPayloadHeader is not available after Gloas");
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
if (this.
|
|
242
|
-
this.
|
|
241
|
+
if (this.cachedLatestExecutionPayloadHeader === null) {
|
|
242
|
+
this.cachedLatestExecutionPayloadHeader = (
|
|
243
243
|
this.cachedState as CachedBeaconStateExecutions
|
|
244
244
|
).latestExecutionPayloadHeader.toValue();
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
return this.
|
|
247
|
+
return this.cachedLatestExecutionPayloadHeader;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
@@ -270,11 +270,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
270
270
|
throw new Error("Historical summaries are not supported before Capella");
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
if (this.
|
|
274
|
-
this.
|
|
273
|
+
if (this.cachedHistoricalSummaries === null) {
|
|
274
|
+
this.cachedHistoricalSummaries = (this.cachedState as CachedBeaconStateCapella).historicalSummaries.toValue();
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
return this.
|
|
277
|
+
return this.cachedHistoricalSummaries;
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
// electra
|
|
@@ -284,11 +284,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
284
284
|
throw new Error("Pending deposits are not supported before Electra");
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
if (this.
|
|
288
|
-
this.
|
|
287
|
+
if (this.cachedPendingDeposits === null) {
|
|
288
|
+
this.cachedPendingDeposits = (this.cachedState as CachedBeaconStateElectra).pendingDeposits.toValue();
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
return this.
|
|
291
|
+
return this.cachedPendingDeposits;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
get pendingDepositsCount(): number {
|
|
@@ -304,13 +304,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
304
304
|
throw new Error("Pending partial withdrawals are not supported before Electra");
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
if (this.
|
|
308
|
-
this.
|
|
307
|
+
if (this.cachedPendingPartialWithdrawals === null) {
|
|
308
|
+
this.cachedPendingPartialWithdrawals = (
|
|
309
309
|
this.cachedState as CachedBeaconStateElectra
|
|
310
310
|
).pendingPartialWithdrawals.toValue();
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
return this.
|
|
313
|
+
return this.cachedPendingPartialWithdrawals;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
get pendingPartialWithdrawalsCount(): number {
|
|
@@ -326,11 +326,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
326
326
|
throw new Error("Pending consolidations are not supported before Electra");
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
if (this.
|
|
330
|
-
this.
|
|
329
|
+
if (this.cachedPendingConsolidations === null) {
|
|
330
|
+
this.cachedPendingConsolidations = (this.cachedState as CachedBeaconStateElectra).pendingConsolidations.toValue();
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
return this.
|
|
333
|
+
return this.cachedPendingConsolidations;
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
get pendingConsolidationsCount(): number {
|
|
@@ -348,11 +348,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
348
348
|
throw new Error("Proposer lookahead is not supported before Fulu");
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
if (this.
|
|
352
|
-
this.
|
|
351
|
+
if (this.cachedProposerLookahead === null) {
|
|
352
|
+
this.cachedProposerLookahead = (this.cachedState as CachedBeaconStateFulu).proposerLookahead.toValue();
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
-
return this.
|
|
355
|
+
return this.cachedProposerLookahead;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
preVerifyBuilderDepositsPreGloas(maxBuilderDeposits: number, maxDurationMs: number): PreVerifyBuilderDepositsResult {
|
|
@@ -381,13 +381,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
381
381
|
throw new Error("executionPayloadAvailability is not available before Gloas");
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
if (this.
|
|
385
|
-
this.
|
|
384
|
+
if (this.cachedExecutionPayloadAvailability === null) {
|
|
385
|
+
this.cachedExecutionPayloadAvailability = (
|
|
386
386
|
this.cachedState as CachedBeaconStateGloas
|
|
387
387
|
).executionPayloadAvailability.toValue();
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
-
return this.
|
|
390
|
+
return this.cachedExecutionPayloadAvailability;
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
get latestExecutionPayloadBid(): ExecutionPayloadBid {
|
|
@@ -395,12 +395,12 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
395
395
|
throw new Error("latestExecutionPayloadBid is not available before Gloas");
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
if (this.
|
|
399
|
-
this.
|
|
398
|
+
if (this.cachedLatestExecutionPayloadBid === null) {
|
|
399
|
+
this.cachedLatestExecutionPayloadBid = (
|
|
400
400
|
this.cachedState as CachedBeaconStateGloas
|
|
401
401
|
).latestExecutionPayloadBid.toValue();
|
|
402
402
|
}
|
|
403
|
-
return this.
|
|
403
|
+
return this.cachedLatestExecutionPayloadBid;
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
get payloadExpectedWithdrawals(): capella.Withdrawal[] {
|
|
@@ -408,12 +408,12 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
408
408
|
throw new Error("payloadExpectedWithdrawals is not available before Gloas");
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
if (this.
|
|
412
|
-
this.
|
|
411
|
+
if (this.cachedPayloadExpectedWithdrawals === null) {
|
|
412
|
+
this.cachedPayloadExpectedWithdrawals = (
|
|
413
413
|
this.cachedState as CachedBeaconStateGloas
|
|
414
414
|
).payloadExpectedWithdrawals.toValue();
|
|
415
415
|
}
|
|
416
|
-
return this.
|
|
416
|
+
return this.cachedPayloadExpectedWithdrawals;
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
get builderPendingPayments(): gloas.BuilderPendingPayments {
|
|
@@ -421,10 +421,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
421
421
|
throw new Error("Pending builder payments are not supported before Gloas");
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
if (this.
|
|
425
|
-
this.
|
|
424
|
+
if (this.cachedBuilderPendingPayments === null) {
|
|
425
|
+
this.cachedBuilderPendingPayments = (this.cachedState as CachedBeaconStateGloas).builderPendingPayments.toValue();
|
|
426
426
|
}
|
|
427
|
-
return this.
|
|
427
|
+
return this.cachedBuilderPendingPayments;
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
get builderPendingWithdrawals(): gloas.BuilderPendingWithdrawals {
|
|
@@ -432,12 +432,12 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
432
432
|
throw new Error("Pending builder withdrawals are not supported before Gloas");
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
if (this.
|
|
436
|
-
this.
|
|
435
|
+
if (this.cachedBuilderPendingWithdrawals === null) {
|
|
436
|
+
this.cachedBuilderPendingWithdrawals = (
|
|
437
437
|
this.cachedState as CachedBeaconStateGloas
|
|
438
438
|
).builderPendingWithdrawals.toValue();
|
|
439
439
|
}
|
|
440
|
-
return this.
|
|
440
|
+
return this.cachedBuilderPendingWithdrawals;
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
getBuilder(index: BuilderIndex): gloas.Builder {
|
|
@@ -588,11 +588,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
588
588
|
throw new Error("currentSyncCommittee is not available before Altair");
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
-
if (this.
|
|
592
|
-
this.
|
|
591
|
+
if (this.cachedCurrentSyncCommittee === null) {
|
|
592
|
+
this.cachedCurrentSyncCommittee = (this.cachedState as CachedBeaconStateAltair).currentSyncCommittee.toValue();
|
|
593
593
|
}
|
|
594
594
|
|
|
595
|
-
return this.
|
|
595
|
+
return this.cachedCurrentSyncCommittee;
|
|
596
596
|
}
|
|
597
597
|
|
|
598
598
|
get nextSyncCommittee(): SyncCommittee {
|
|
@@ -600,11 +600,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
600
600
|
throw new Error("nextSyncCommittee is not available before Altair");
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
-
if (this.
|
|
604
|
-
this.
|
|
603
|
+
if (this.cachedNextSyncCommittee === null) {
|
|
604
|
+
this.cachedNextSyncCommittee = (this.cachedState as CachedBeaconStateAltair).nextSyncCommittee.toValue();
|
|
605
605
|
}
|
|
606
606
|
|
|
607
|
-
return this.
|
|
607
|
+
return this.cachedNextSyncCommittee;
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
get currentSyncCommitteeIndexed(): SyncCommitteeCache {
|
|
@@ -872,7 +872,7 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
872
872
|
|
|
873
873
|
// State transition
|
|
874
874
|
|
|
875
|
-
computeNewStateRoot({block}:
|
|
875
|
+
computeNewStateRoot({block}: BlockSTFInput, modules: StateTransitionModules): ComputeNewStateRootResult {
|
|
876
876
|
const postState = new BeaconStateView(
|
|
877
877
|
stateTransition(this.cachedState, block, computeNewStateRootStateTransitionOpts, modules)
|
|
878
878
|
);
|
|
@@ -880,12 +880,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
880
880
|
}
|
|
881
881
|
|
|
882
882
|
stateTransition(
|
|
883
|
-
|
|
883
|
+
{block}: BlockSTFInput,
|
|
884
884
|
options: StateTransitionOpts,
|
|
885
|
-
|
|
885
|
+
modules: StateTransitionModules
|
|
886
886
|
): IBeaconStateView {
|
|
887
|
-
|
|
888
|
-
return new BeaconStateView(newState);
|
|
887
|
+
return new BeaconStateView(stateTransition(this.cachedState, block, options, modules));
|
|
889
888
|
}
|
|
890
889
|
|
|
891
890
|
processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}, modules?: StateTransitionModules): IBeaconStateView {
|