@lodestar/state-transition 1.50.0-dev.033e6b7138 → 1.50.0-dev.040a952dd7
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/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/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 +10 -17
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +17 -13
- 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/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/sszBytes.d.ts +16 -17
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +93 -20
- package/lib/util/sszBytes.js.map +1 -1
- package/lib/util/weakSubjectivity.d.ts +11 -6
- package/lib/util/weakSubjectivity.d.ts.map +1 -1
- package/lib/util/weakSubjectivity.js +22 -28
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +7 -7
- 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/index.ts +4 -1
- package/src/rewards/attestationsRewards.ts +8 -1
- 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 +29 -27
- package/src/util/gloas.ts +2 -53
- package/src/util/index.ts +6 -0
- package/src/util/sszBytes.ts +129 -22
- package/src/util/weakSubjectivity.ts +43 -40
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
|
|
2
2
|
import {BitArray, ByteViews} from "@chainsafe/ssz";
|
|
3
|
+
import type {BeaconConfig} from "@lodestar/config";
|
|
3
4
|
import {ForkName, ForkSeq} from "@lodestar/params";
|
|
4
5
|
import {
|
|
5
6
|
BeaconBlock,
|
|
@@ -23,38 +24,38 @@ import {
|
|
|
23
24
|
electra,
|
|
24
25
|
fulu,
|
|
25
26
|
gloas,
|
|
27
|
+
isBlindedBeaconBlock,
|
|
26
28
|
phase0,
|
|
27
29
|
rewards,
|
|
30
|
+
ssz,
|
|
28
31
|
} from "@lodestar/types";
|
|
29
32
|
import {Checkpoint, Fork} from "@lodestar/types/phase0";
|
|
30
33
|
import {VoluntaryExitValidity} from "../block/processVoluntaryExit.js";
|
|
31
34
|
import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
|
|
32
35
|
import {RewardCache} from "../cache/rewardCache.js";
|
|
33
36
|
import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
|
|
37
|
+
import {EMPTY_SIGNATURE} from "../constants/constants.js";
|
|
34
38
|
import {SyncCommitteeWitness} from "../lightClient/types.js";
|
|
35
39
|
import {StateTransitionModules, StateTransitionOpts} from "../stateTransition.js";
|
|
36
40
|
import {EpochShuffling} from "../util/epochShuffling.js";
|
|
37
41
|
import {PreVerifyBuilderDepositsResult} from "../util/preVerifyBuilderDeposits.js";
|
|
38
42
|
import {computeNewStateRootStateTransitionOpts, getComputeNewStateRootResult} from "./computeNewStateRoot.js";
|
|
39
43
|
import {
|
|
40
|
-
|
|
44
|
+
BlockSTFInput,
|
|
41
45
|
ComputeNewStateRootResult,
|
|
42
46
|
IBeaconStateView,
|
|
43
47
|
IBeaconStateViewGloas,
|
|
44
48
|
IBeaconStateViewLatestFork,
|
|
45
49
|
IBeaconStateViewNative,
|
|
46
|
-
isStatePostGloas,
|
|
47
50
|
} from "./interface.js";
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
53
|
* Wraps a native binding (the auto-generated JS interface produced by a `.node`
|
|
51
54
|
* file) and exposes it as a fully-conformant `IBeaconStateViewLatestFork`.
|
|
52
55
|
*
|
|
53
|
-
* The binding is typed `IBeaconStateViewNative
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* that POJO back to a `BitArray` so beacon-node consumers see no difference from
|
|
57
|
-
* the TS-side `BeaconStateView`.
|
|
56
|
+
* The binding is typed `IBeaconStateViewNative`. This type models FFI-specific
|
|
57
|
+
* inputs and outputs, such as serialized blocks and typed arrays. The wrapper
|
|
58
|
+
* converts those values to the forms used by `IBeaconStateViewLatestFork`.
|
|
58
59
|
*
|
|
59
60
|
* Every getter that returns a value stable for the view's lifetime is cached so
|
|
60
61
|
* the binding is hit at most once per field per view. Only mutable counters
|
|
@@ -64,109 +65,97 @@ import {
|
|
|
64
65
|
*/
|
|
65
66
|
export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
66
67
|
// phase0
|
|
67
|
-
private
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
private
|
|
72
|
-
private
|
|
73
|
-
private
|
|
74
|
-
private
|
|
75
|
-
private
|
|
76
|
-
private
|
|
77
|
-
private
|
|
78
|
-
private
|
|
68
|
+
private cachedForkName: ForkName | null = null;
|
|
69
|
+
private cachedForkSeq: ForkSeq | null = null;
|
|
70
|
+
private cachedSlot: Slot | null = null;
|
|
71
|
+
private cachedFork: Fork | null = null;
|
|
72
|
+
private cachedEpoch: Epoch | null = null;
|
|
73
|
+
private cachedGenesisTime: number | null = null;
|
|
74
|
+
private cachedGenesisValidatorsRoot: Root | null = null;
|
|
75
|
+
private cachedEth1Data: phase0.Eth1Data | null = null;
|
|
76
|
+
private cachedLatestBlockHeader: phase0.BeaconBlockHeader | null = null;
|
|
77
|
+
private cachedPreviousJustifiedCheckpoint: Checkpoint | null = null;
|
|
78
|
+
private cachedCurrentJustifiedCheckpoint: Checkpoint | null = null;
|
|
79
|
+
private cachedFinalizedCheckpoint: Checkpoint | null = null;
|
|
79
80
|
// shuffling / decision roots / proposers
|
|
80
|
-
private
|
|
81
|
-
private
|
|
82
|
-
private
|
|
81
|
+
private cachedPreviousDecisionRoot: RootHex | null = null;
|
|
82
|
+
private cachedCurrentDecisionRoot: RootHex | null = null;
|
|
83
|
+
private cachedNextDecisionRoot: RootHex | null = null;
|
|
83
84
|
// previousProposers can be null, so use undefined as the "not loaded" sentinel
|
|
84
|
-
private
|
|
85
|
-
private
|
|
86
|
-
private
|
|
85
|
+
private cachedPreviousProposers: ValidatorIndex[] | null | undefined = undefined;
|
|
86
|
+
private cachedCurrentProposers: ValidatorIndex[] | null = null;
|
|
87
|
+
private cachedNextProposers: ValidatorIndex[] | null = null;
|
|
87
88
|
// validators / balances
|
|
88
|
-
private
|
|
89
|
-
private
|
|
90
|
-
private
|
|
89
|
+
private cachedEffectiveBalanceIncrements: EffectiveBalanceIncrements | null = null;
|
|
90
|
+
private cachedValidatorCount: number | null = null;
|
|
91
|
+
private cachedActiveValidatorCount: number | null = null;
|
|
91
92
|
// backward compat
|
|
92
|
-
private
|
|
93
|
+
private cachedCreatedWithTransferCache: boolean | null = null;
|
|
93
94
|
// altair
|
|
94
|
-
private
|
|
95
|
-
private
|
|
96
|
-
private
|
|
97
|
-
private
|
|
98
|
-
private
|
|
99
|
-
private
|
|
95
|
+
private cachedCurrentSyncCommittee: SyncCommittee | null = null;
|
|
96
|
+
private cachedNextSyncCommittee: SyncCommittee | null = null;
|
|
97
|
+
private cachedPreviousEpochParticipation: Uint8Array | null = null;
|
|
98
|
+
private cachedCurrentEpochParticipation: Uint8Array | null = null;
|
|
99
|
+
private cachedCurrentSyncCommitteeIndexed: SyncCommitteeCache | null = null;
|
|
100
|
+
private cachedSyncProposerReward: number | null = null;
|
|
100
101
|
// bellatrix
|
|
101
|
-
private
|
|
102
|
-
private
|
|
103
|
-
private
|
|
104
|
-
private
|
|
102
|
+
private cachedLatestExecutionPayloadHeader: ExecutionPayloadHeader | null = null;
|
|
103
|
+
private cachedPayloadBlockNumber: number | null = null;
|
|
104
|
+
private cachedIsExecutionStateType: boolean | null = null;
|
|
105
|
+
private cachedIsMergeTransitionComplete: boolean | null = null;
|
|
105
106
|
// capella
|
|
106
|
-
private
|
|
107
|
+
private cachedHistoricalSummaries: capella.HistoricalSummaries | null = null;
|
|
107
108
|
// electra
|
|
108
|
-
private
|
|
109
|
-
private
|
|
110
|
-
private
|
|
111
|
-
private
|
|
112
|
-
private
|
|
113
|
-
private
|
|
109
|
+
private cachedPendingPartialWithdrawals: electra.PendingPartialWithdrawals | null = null;
|
|
110
|
+
private cachedPendingConsolidations: electra.PendingConsolidations | null = null;
|
|
111
|
+
private cachedPendingDeposits: electra.PendingDeposits | null = null;
|
|
112
|
+
private cachedPendingDepositsCount: number | null = null;
|
|
113
|
+
private cachedPendingPartialWithdrawalsCount: number | null = null;
|
|
114
|
+
private cachedPendingConsolidationsCount: number | null = null;
|
|
114
115
|
// fulu
|
|
115
|
-
private
|
|
116
|
-
// gloas
|
|
117
|
-
private _executionPayloadAvailability: BitArray | null = null;
|
|
118
|
-
private _latestBlockHash: Bytes32 | null = null;
|
|
119
|
-
private _latestExecutionPayloadBid: ExecutionPayloadBid | null = null;
|
|
120
|
-
private _payloadExpectedWithdrawals: capella.Withdrawal[] | null = null;
|
|
121
|
-
private _builderPendingPayments: gloas.BuilderPendingPayments | null = null;
|
|
122
|
-
private _builderPendingWithdrawals: gloas.BuilderPendingWithdrawals | null = null;
|
|
123
|
-
|
|
116
|
+
private cachedProposerLookahead: fulu.ProposerLookahead | null = null;
|
|
124
117
|
// Per-argument caches for argument-taking methods. The binding is treated as
|
|
125
118
|
// immutable for the view's lifetime, so a given argument always yields the
|
|
126
119
|
// same result. Maps grow only with touched arguments — typical call patterns
|
|
127
120
|
// (e.g. a handful of slots per attestation pool scan) keep them tiny.
|
|
128
|
-
private readonly
|
|
129
|
-
private readonly
|
|
130
|
-
private readonly
|
|
131
|
-
private readonly
|
|
132
|
-
private readonly
|
|
133
|
-
private readonly
|
|
134
|
-
private readonly
|
|
135
|
-
private readonly
|
|
136
|
-
private readonly
|
|
137
|
-
private readonly
|
|
138
|
-
private readonly
|
|
139
|
-
private readonly
|
|
140
|
-
private readonly
|
|
141
|
-
private readonly
|
|
142
|
-
private readonly _getEpochPTCs = new Map<Epoch, Uint32Array[]>();
|
|
143
|
-
private readonly _getBuilder = new Map<BuilderIndex, gloas.Builder>();
|
|
121
|
+
private readonly cachedBlockRootAtSlot = new Map<Slot, Root>();
|
|
122
|
+
private readonly cachedBlockRootAtEpoch = new Map<Epoch, Root>();
|
|
123
|
+
private readonly cachedStateRootAtSlot = new Map<Slot, Root>();
|
|
124
|
+
private readonly cachedRandaoMix = new Map<Epoch, Bytes32>();
|
|
125
|
+
private readonly cachedShufflingAtEpoch = new Map<Epoch, EpochShuffling>();
|
|
126
|
+
private readonly cachedBeaconCommittee = new Map<string, Uint32Array>();
|
|
127
|
+
private readonly cachedBeaconCommitteeCountPerSlot = new Map<Epoch, number>();
|
|
128
|
+
private readonly cachedShufflingDecisionRoot = new Map<Epoch, RootHex>();
|
|
129
|
+
private readonly cachedBeaconProposer = new Map<Slot, ValidatorIndex>();
|
|
130
|
+
private readonly cachedValidator = new Map<ValidatorIndex, phase0.Validator>();
|
|
131
|
+
private readonly cachedBalance = new Map<number, number>();
|
|
132
|
+
private readonly cachedIndexedSyncCommitteeAtEpoch = new Map<Epoch, SyncCommitteeCache>();
|
|
133
|
+
private readonly cachedIndexedSyncCommittee = new Map<Slot, SyncCommitteeCache>();
|
|
134
|
+
private readonly cachedSingleProof = new Map<bigint, Uint8Array[]>();
|
|
144
135
|
|
|
145
136
|
// No-arg method caches
|
|
146
|
-
private
|
|
147
|
-
private
|
|
148
|
-
private
|
|
149
|
-
private
|
|
150
|
-
private
|
|
151
|
-
private
|
|
152
|
-
private
|
|
153
|
-
private
|
|
154
|
-
private
|
|
155
|
-
private _computeUnrealizedCheckpoints: {
|
|
137
|
+
private cachedPreviousShuffling: EpochShuffling | null = null;
|
|
138
|
+
private cachedCurrentShuffling: EpochShuffling | null = null;
|
|
139
|
+
private cachedNextShuffling: EpochShuffling | null = null;
|
|
140
|
+
private cachedEffectiveBalanceIncrementsZeroInactive: EffectiveBalanceIncrements | null = null;
|
|
141
|
+
private cachedAllValidators: phase0.Validator[] | null = null;
|
|
142
|
+
private cachedAllBalances: number[] | null = null;
|
|
143
|
+
private cachedLatestWeakSubjectivityCheckpointEpoch: Epoch | null = null;
|
|
144
|
+
private cachedFinalizedRootProof: Uint8Array[] | null = null;
|
|
145
|
+
private cachedUnrealizedCheckpoints: {
|
|
156
146
|
justifiedCheckpoint: phase0.Checkpoint;
|
|
157
147
|
finalizedCheckpoint: phase0.Checkpoint;
|
|
158
148
|
} | null = null;
|
|
159
|
-
private
|
|
160
|
-
|
|
161
|
-
private
|
|
162
|
-
private
|
|
163
|
-
private
|
|
164
|
-
private
|
|
165
|
-
private
|
|
166
|
-
private
|
|
167
|
-
private
|
|
168
|
-
private
|
|
169
|
-
private _getExpectedWithdrawals: {
|
|
149
|
+
private cachedAnchorCheckpoint: {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader} | null = null;
|
|
150
|
+
private cachedIsStateValidatorsNodesPopulated: boolean | null = null;
|
|
151
|
+
private cachedValue: BeaconState | null = null;
|
|
152
|
+
private cachedSerialized: Uint8Array | null = null;
|
|
153
|
+
private cachedSerializedSize: number | null = null;
|
|
154
|
+
private cachedSerializedValidators: Uint8Array | null = null;
|
|
155
|
+
private cachedSerializedValidatorsSize: number | null = null;
|
|
156
|
+
private cachedHashTreeRoot: Uint8Array | null = null;
|
|
157
|
+
private cachedSyncCommitteesWitness: SyncCommitteeWitness | null = null;
|
|
158
|
+
private cachedExpectedWithdrawals: {
|
|
170
159
|
expectedWithdrawals: capella.Withdrawal[];
|
|
171
160
|
processedBuilderWithdrawalsCount: number;
|
|
172
161
|
processedPartialWithdrawalsCount: number;
|
|
@@ -174,137 +163,137 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
174
163
|
processedValidatorSweepCount: number;
|
|
175
164
|
} | null = null;
|
|
176
165
|
|
|
177
|
-
constructor(
|
|
166
|
+
constructor(
|
|
167
|
+
private readonly config: BeaconConfig,
|
|
168
|
+
readonly binding: IBeaconStateViewNative
|
|
169
|
+
) {}
|
|
178
170
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (this._executionPayloadAvailability === null) {
|
|
183
|
-
const pojo = this.binding.executionPayloadAvailability;
|
|
184
|
-
this._executionPayloadAvailability = new BitArray(pojo.uint8Array, pojo.bitLen);
|
|
185
|
-
}
|
|
171
|
+
release(): void {
|
|
172
|
+
this.binding.release();
|
|
173
|
+
}
|
|
186
174
|
|
|
187
|
-
|
|
175
|
+
get executionPayloadAvailability(): BitArray {
|
|
176
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
188
177
|
}
|
|
189
178
|
|
|
190
179
|
// ─── phase0 ──────────────────────────────────────────────────────────────
|
|
191
180
|
|
|
192
181
|
get forkName(): ForkName {
|
|
193
|
-
if (this.
|
|
194
|
-
this.
|
|
182
|
+
if (this.cachedForkName === null) {
|
|
183
|
+
this.cachedForkName = this.binding.forkName;
|
|
195
184
|
}
|
|
196
|
-
return this.
|
|
185
|
+
return this.cachedForkName;
|
|
197
186
|
}
|
|
198
187
|
|
|
199
188
|
get forkSeq(): ForkSeq {
|
|
200
|
-
if (this.
|
|
201
|
-
this.
|
|
189
|
+
if (this.cachedForkSeq === null) {
|
|
190
|
+
this.cachedForkSeq = this.binding.forkSeq;
|
|
202
191
|
}
|
|
203
|
-
return this.
|
|
192
|
+
return this.cachedForkSeq;
|
|
204
193
|
}
|
|
205
194
|
|
|
206
195
|
get slot(): Slot {
|
|
207
|
-
if (this.
|
|
208
|
-
this.
|
|
196
|
+
if (this.cachedSlot === null) {
|
|
197
|
+
this.cachedSlot = this.binding.slot;
|
|
209
198
|
}
|
|
210
|
-
return this.
|
|
199
|
+
return this.cachedSlot;
|
|
211
200
|
}
|
|
212
201
|
|
|
213
202
|
get fork(): Fork {
|
|
214
|
-
if (this.
|
|
215
|
-
this.
|
|
203
|
+
if (this.cachedFork === null) {
|
|
204
|
+
this.cachedFork = this.binding.fork;
|
|
216
205
|
}
|
|
217
|
-
return this.
|
|
206
|
+
return this.cachedFork;
|
|
218
207
|
}
|
|
219
208
|
|
|
220
209
|
get epoch(): Epoch {
|
|
221
|
-
if (this.
|
|
222
|
-
this.
|
|
210
|
+
if (this.cachedEpoch === null) {
|
|
211
|
+
this.cachedEpoch = this.binding.epoch;
|
|
223
212
|
}
|
|
224
|
-
return this.
|
|
213
|
+
return this.cachedEpoch;
|
|
225
214
|
}
|
|
226
215
|
|
|
227
216
|
get genesisTime(): number {
|
|
228
|
-
if (this.
|
|
229
|
-
this.
|
|
217
|
+
if (this.cachedGenesisTime === null) {
|
|
218
|
+
this.cachedGenesisTime = this.binding.genesisTime;
|
|
230
219
|
}
|
|
231
|
-
return this.
|
|
220
|
+
return this.cachedGenesisTime;
|
|
232
221
|
}
|
|
233
222
|
|
|
234
223
|
get genesisValidatorsRoot(): Root {
|
|
235
|
-
if (this.
|
|
236
|
-
this.
|
|
224
|
+
if (this.cachedGenesisValidatorsRoot === null) {
|
|
225
|
+
this.cachedGenesisValidatorsRoot = this.binding.genesisValidatorsRoot;
|
|
237
226
|
}
|
|
238
|
-
return this.
|
|
227
|
+
return this.cachedGenesisValidatorsRoot;
|
|
239
228
|
}
|
|
240
229
|
|
|
241
230
|
get eth1Data(): phase0.Eth1Data {
|
|
242
|
-
if (this.
|
|
243
|
-
this.
|
|
231
|
+
if (this.cachedEth1Data === null) {
|
|
232
|
+
this.cachedEth1Data = this.binding.eth1Data;
|
|
244
233
|
}
|
|
245
|
-
return this.
|
|
234
|
+
return this.cachedEth1Data;
|
|
246
235
|
}
|
|
247
236
|
|
|
248
237
|
get latestBlockHeader(): phase0.BeaconBlockHeader {
|
|
249
|
-
if (this.
|
|
250
|
-
this.
|
|
238
|
+
if (this.cachedLatestBlockHeader === null) {
|
|
239
|
+
this.cachedLatestBlockHeader = this.binding.latestBlockHeader;
|
|
251
240
|
}
|
|
252
|
-
return this.
|
|
241
|
+
return this.cachedLatestBlockHeader;
|
|
253
242
|
}
|
|
254
243
|
|
|
255
244
|
get previousJustifiedCheckpoint(): Checkpoint {
|
|
256
|
-
if (this.
|
|
257
|
-
this.
|
|
245
|
+
if (this.cachedPreviousJustifiedCheckpoint === null) {
|
|
246
|
+
this.cachedPreviousJustifiedCheckpoint = this.binding.previousJustifiedCheckpoint;
|
|
258
247
|
}
|
|
259
|
-
return this.
|
|
248
|
+
return this.cachedPreviousJustifiedCheckpoint;
|
|
260
249
|
}
|
|
261
250
|
|
|
262
251
|
get currentJustifiedCheckpoint(): Checkpoint {
|
|
263
|
-
if (this.
|
|
264
|
-
this.
|
|
252
|
+
if (this.cachedCurrentJustifiedCheckpoint === null) {
|
|
253
|
+
this.cachedCurrentJustifiedCheckpoint = this.binding.currentJustifiedCheckpoint;
|
|
265
254
|
}
|
|
266
|
-
return this.
|
|
255
|
+
return this.cachedCurrentJustifiedCheckpoint;
|
|
267
256
|
}
|
|
268
257
|
|
|
269
258
|
get finalizedCheckpoint(): Checkpoint {
|
|
270
|
-
if (this.
|
|
271
|
-
this.
|
|
259
|
+
if (this.cachedFinalizedCheckpoint === null) {
|
|
260
|
+
this.cachedFinalizedCheckpoint = this.binding.finalizedCheckpoint;
|
|
272
261
|
}
|
|
273
|
-
return this.
|
|
262
|
+
return this.cachedFinalizedCheckpoint;
|
|
274
263
|
}
|
|
275
264
|
|
|
276
265
|
getBlockRootAtSlot(slot: Slot): Root {
|
|
277
|
-
let cached = this.
|
|
266
|
+
let cached = this.cachedBlockRootAtSlot.get(slot);
|
|
278
267
|
if (cached === undefined) {
|
|
279
268
|
cached = this.binding.getBlockRootAtSlot(slot);
|
|
280
|
-
this.
|
|
269
|
+
this.cachedBlockRootAtSlot.set(slot, cached);
|
|
281
270
|
}
|
|
282
271
|
return cached;
|
|
283
272
|
}
|
|
284
273
|
|
|
285
274
|
getBlockRootAtEpoch(epoch: Epoch): Root {
|
|
286
|
-
let cached = this.
|
|
275
|
+
let cached = this.cachedBlockRootAtEpoch.get(epoch);
|
|
287
276
|
if (cached === undefined) {
|
|
288
277
|
cached = this.binding.getBlockRootAtEpoch(epoch);
|
|
289
|
-
this.
|
|
278
|
+
this.cachedBlockRootAtEpoch.set(epoch, cached);
|
|
290
279
|
}
|
|
291
280
|
return cached;
|
|
292
281
|
}
|
|
293
282
|
|
|
294
283
|
getStateRootAtSlot(slot: Slot): Root {
|
|
295
|
-
let cached = this.
|
|
284
|
+
let cached = this.cachedStateRootAtSlot.get(slot);
|
|
296
285
|
if (cached === undefined) {
|
|
297
286
|
cached = this.binding.getStateRootAtSlot(slot);
|
|
298
|
-
this.
|
|
287
|
+
this.cachedStateRootAtSlot.set(slot, cached);
|
|
299
288
|
}
|
|
300
289
|
return cached;
|
|
301
290
|
}
|
|
302
291
|
|
|
303
292
|
getRandaoMix(epoch: Epoch): Bytes32 {
|
|
304
|
-
let cached = this.
|
|
293
|
+
let cached = this.cachedRandaoMix.get(epoch);
|
|
305
294
|
if (cached === undefined) {
|
|
306
295
|
cached = this.binding.getRandaoMix(epoch);
|
|
307
|
-
this.
|
|
296
|
+
this.cachedRandaoMix.set(epoch, cached);
|
|
308
297
|
}
|
|
309
298
|
return cached;
|
|
310
299
|
}
|
|
@@ -312,112 +301,112 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
312
301
|
// Shuffling and committees
|
|
313
302
|
|
|
314
303
|
getShufflingAtEpoch(epoch: Epoch): EpochShuffling {
|
|
315
|
-
let cached = this.
|
|
304
|
+
let cached = this.cachedShufflingAtEpoch.get(epoch);
|
|
316
305
|
if (cached === undefined) {
|
|
317
306
|
cached = this.binding.getShufflingAtEpoch(epoch);
|
|
318
|
-
this.
|
|
307
|
+
this.cachedShufflingAtEpoch.set(epoch, cached);
|
|
319
308
|
}
|
|
320
309
|
return cached;
|
|
321
310
|
}
|
|
322
311
|
|
|
323
312
|
getBeaconCommittee(slot: Slot, index: CommitteeIndex): Uint32Array {
|
|
324
313
|
const key = `${slot}:${index}`;
|
|
325
|
-
let cached = this.
|
|
314
|
+
let cached = this.cachedBeaconCommittee.get(key);
|
|
326
315
|
if (cached === undefined) {
|
|
327
316
|
cached = this.binding.getBeaconCommittee(slot, index);
|
|
328
|
-
this.
|
|
317
|
+
this.cachedBeaconCommittee.set(key, cached);
|
|
329
318
|
}
|
|
330
319
|
return cached;
|
|
331
320
|
}
|
|
332
321
|
|
|
333
322
|
getBeaconCommitteeCountPerSlot(epoch: Epoch): number {
|
|
334
|
-
let cached = this.
|
|
323
|
+
let cached = this.cachedBeaconCommitteeCountPerSlot.get(epoch);
|
|
335
324
|
if (cached === undefined) {
|
|
336
325
|
cached = this.binding.getBeaconCommitteeCountPerSlot(epoch);
|
|
337
|
-
this.
|
|
326
|
+
this.cachedBeaconCommitteeCountPerSlot.set(epoch, cached);
|
|
338
327
|
}
|
|
339
328
|
return cached;
|
|
340
329
|
}
|
|
341
330
|
|
|
342
331
|
get previousDecisionRoot(): RootHex {
|
|
343
|
-
if (this.
|
|
344
|
-
this.
|
|
332
|
+
if (this.cachedPreviousDecisionRoot === null) {
|
|
333
|
+
this.cachedPreviousDecisionRoot = this.binding.previousDecisionRoot;
|
|
345
334
|
}
|
|
346
|
-
return this.
|
|
335
|
+
return this.cachedPreviousDecisionRoot;
|
|
347
336
|
}
|
|
348
337
|
|
|
349
338
|
get currentDecisionRoot(): RootHex {
|
|
350
|
-
if (this.
|
|
351
|
-
this.
|
|
339
|
+
if (this.cachedCurrentDecisionRoot === null) {
|
|
340
|
+
this.cachedCurrentDecisionRoot = this.binding.currentDecisionRoot;
|
|
352
341
|
}
|
|
353
|
-
return this.
|
|
342
|
+
return this.cachedCurrentDecisionRoot;
|
|
354
343
|
}
|
|
355
344
|
|
|
356
345
|
get nextDecisionRoot(): RootHex {
|
|
357
|
-
if (this.
|
|
358
|
-
this.
|
|
346
|
+
if (this.cachedNextDecisionRoot === null) {
|
|
347
|
+
this.cachedNextDecisionRoot = this.binding.nextDecisionRoot;
|
|
359
348
|
}
|
|
360
|
-
return this.
|
|
349
|
+
return this.cachedNextDecisionRoot;
|
|
361
350
|
}
|
|
362
351
|
|
|
363
352
|
getShufflingDecisionRoot(epoch: Epoch): RootHex {
|
|
364
|
-
let cached = this.
|
|
353
|
+
let cached = this.cachedShufflingDecisionRoot.get(epoch);
|
|
365
354
|
if (cached === undefined) {
|
|
366
355
|
cached = this.binding.getShufflingDecisionRoot(epoch);
|
|
367
|
-
this.
|
|
356
|
+
this.cachedShufflingDecisionRoot.set(epoch, cached);
|
|
368
357
|
}
|
|
369
358
|
return cached;
|
|
370
359
|
}
|
|
371
360
|
|
|
372
361
|
getPreviousShuffling(): EpochShuffling {
|
|
373
|
-
if (this.
|
|
374
|
-
this.
|
|
362
|
+
if (this.cachedPreviousShuffling === null) {
|
|
363
|
+
this.cachedPreviousShuffling = this.binding.getPreviousShuffling();
|
|
375
364
|
}
|
|
376
|
-
return this.
|
|
365
|
+
return this.cachedPreviousShuffling;
|
|
377
366
|
}
|
|
378
367
|
|
|
379
368
|
getCurrentShuffling(): EpochShuffling {
|
|
380
|
-
if (this.
|
|
381
|
-
this.
|
|
369
|
+
if (this.cachedCurrentShuffling === null) {
|
|
370
|
+
this.cachedCurrentShuffling = this.binding.getCurrentShuffling();
|
|
382
371
|
}
|
|
383
|
-
return this.
|
|
372
|
+
return this.cachedCurrentShuffling;
|
|
384
373
|
}
|
|
385
374
|
|
|
386
375
|
getNextShuffling(): EpochShuffling {
|
|
387
|
-
if (this.
|
|
388
|
-
this.
|
|
376
|
+
if (this.cachedNextShuffling === null) {
|
|
377
|
+
this.cachedNextShuffling = this.binding.getNextShuffling();
|
|
389
378
|
}
|
|
390
|
-
return this.
|
|
379
|
+
return this.cachedNextShuffling;
|
|
391
380
|
}
|
|
392
381
|
|
|
393
382
|
// Proposer shuffling
|
|
394
383
|
|
|
395
384
|
get previousProposers(): ValidatorIndex[] | null {
|
|
396
|
-
if (this.
|
|
397
|
-
this.
|
|
385
|
+
if (this.cachedPreviousProposers === undefined) {
|
|
386
|
+
this.cachedPreviousProposers = this.binding.previousProposers;
|
|
398
387
|
}
|
|
399
|
-
return this.
|
|
388
|
+
return this.cachedPreviousProposers;
|
|
400
389
|
}
|
|
401
390
|
|
|
402
391
|
get currentProposers(): ValidatorIndex[] {
|
|
403
|
-
if (this.
|
|
404
|
-
this.
|
|
392
|
+
if (this.cachedCurrentProposers === null) {
|
|
393
|
+
this.cachedCurrentProposers = this.binding.currentProposers;
|
|
405
394
|
}
|
|
406
|
-
return this.
|
|
395
|
+
return this.cachedCurrentProposers;
|
|
407
396
|
}
|
|
408
397
|
|
|
409
398
|
get nextProposers(): ValidatorIndex[] {
|
|
410
|
-
if (this.
|
|
411
|
-
this.
|
|
399
|
+
if (this.cachedNextProposers === null) {
|
|
400
|
+
this.cachedNextProposers = this.binding.nextProposers;
|
|
412
401
|
}
|
|
413
|
-
return this.
|
|
402
|
+
return this.cachedNextProposers;
|
|
414
403
|
}
|
|
415
404
|
|
|
416
405
|
getBeaconProposer(slot: Slot): ValidatorIndex {
|
|
417
|
-
let cached = this.
|
|
406
|
+
let cached = this.cachedBeaconProposer.get(slot);
|
|
418
407
|
if (cached === undefined) {
|
|
419
408
|
cached = this.binding.getBeaconProposer(slot);
|
|
420
|
-
this.
|
|
409
|
+
this.cachedBeaconProposer.set(slot, cached);
|
|
421
410
|
}
|
|
422
411
|
return cached;
|
|
423
412
|
}
|
|
@@ -425,33 +414,33 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
425
414
|
// Validators and balances
|
|
426
415
|
|
|
427
416
|
get effectiveBalanceIncrements(): EffectiveBalanceIncrements {
|
|
428
|
-
if (this.
|
|
429
|
-
this.
|
|
417
|
+
if (this.cachedEffectiveBalanceIncrements === null) {
|
|
418
|
+
this.cachedEffectiveBalanceIncrements = this.binding.effectiveBalanceIncrements;
|
|
430
419
|
}
|
|
431
|
-
return this.
|
|
420
|
+
return this.cachedEffectiveBalanceIncrements;
|
|
432
421
|
}
|
|
433
422
|
|
|
434
423
|
getEffectiveBalanceIncrementsZeroInactive(): EffectiveBalanceIncrements {
|
|
435
|
-
if (this.
|
|
436
|
-
this.
|
|
424
|
+
if (this.cachedEffectiveBalanceIncrementsZeroInactive === null) {
|
|
425
|
+
this.cachedEffectiveBalanceIncrementsZeroInactive = this.binding.getEffectiveBalanceIncrementsZeroInactive();
|
|
437
426
|
}
|
|
438
|
-
return this.
|
|
427
|
+
return this.cachedEffectiveBalanceIncrementsZeroInactive;
|
|
439
428
|
}
|
|
440
429
|
|
|
441
430
|
getBalance(index: number): number {
|
|
442
|
-
let cached = this.
|
|
431
|
+
let cached = this.cachedBalance.get(index);
|
|
443
432
|
if (cached === undefined) {
|
|
444
433
|
cached = this.binding.getBalance(index);
|
|
445
|
-
this.
|
|
434
|
+
this.cachedBalance.set(index, cached);
|
|
446
435
|
}
|
|
447
436
|
return cached;
|
|
448
437
|
}
|
|
449
438
|
|
|
450
439
|
getValidator(index: ValidatorIndex): phase0.Validator {
|
|
451
|
-
let cached = this.
|
|
440
|
+
let cached = this.cachedValidator.get(index);
|
|
452
441
|
if (cached === undefined) {
|
|
453
442
|
cached = this.binding.getValidator(index);
|
|
454
|
-
this.
|
|
443
|
+
this.cachedValidator.set(index, cached);
|
|
455
444
|
}
|
|
456
445
|
return cached;
|
|
457
446
|
}
|
|
@@ -461,31 +450,31 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
461
450
|
}
|
|
462
451
|
|
|
463
452
|
get validatorCount(): number {
|
|
464
|
-
if (this.
|
|
465
|
-
this.
|
|
453
|
+
if (this.cachedValidatorCount === null) {
|
|
454
|
+
this.cachedValidatorCount = this.binding.validatorCount;
|
|
466
455
|
}
|
|
467
|
-
return this.
|
|
456
|
+
return this.cachedValidatorCount;
|
|
468
457
|
}
|
|
469
458
|
|
|
470
459
|
get activeValidatorCount(): number {
|
|
471
|
-
if (this.
|
|
472
|
-
this.
|
|
460
|
+
if (this.cachedActiveValidatorCount === null) {
|
|
461
|
+
this.cachedActiveValidatorCount = this.binding.activeValidatorCount;
|
|
473
462
|
}
|
|
474
|
-
return this.
|
|
463
|
+
return this.cachedActiveValidatorCount;
|
|
475
464
|
}
|
|
476
465
|
|
|
477
466
|
getAllValidators(): phase0.Validator[] {
|
|
478
|
-
if (this.
|
|
479
|
-
this.
|
|
467
|
+
if (this.cachedAllValidators === null) {
|
|
468
|
+
this.cachedAllValidators = this.binding.getAllValidators();
|
|
480
469
|
}
|
|
481
|
-
return this.
|
|
470
|
+
return this.cachedAllValidators;
|
|
482
471
|
}
|
|
483
472
|
|
|
484
473
|
getAllBalances(): number[] {
|
|
485
|
-
if (this.
|
|
486
|
-
this.
|
|
474
|
+
if (this.cachedAllBalances === null) {
|
|
475
|
+
this.cachedAllBalances = this.binding.getAllBalances();
|
|
487
476
|
}
|
|
488
|
-
return this.
|
|
477
|
+
return this.cachedAllBalances;
|
|
489
478
|
}
|
|
490
479
|
|
|
491
480
|
// API
|
|
@@ -494,19 +483,30 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
494
483
|
return this.binding.proposerRewards;
|
|
495
484
|
}
|
|
496
485
|
|
|
497
|
-
computeBlockRewards(block: BeaconBlock, proposerRewards?: RewardCache): Promise<rewards.BlockRewards> {
|
|
498
|
-
|
|
486
|
+
async computeBlockRewards(block: BeaconBlock, proposerRewards?: RewardCache): Promise<rewards.BlockRewards> {
|
|
487
|
+
const isBlinded = isBlindedBeaconBlock(block);
|
|
488
|
+
const signedBlockBytes = isBlinded
|
|
489
|
+
? this.config.getPostBellatrixForkTypes(block.slot).SignedBlindedBeaconBlock.serialize({
|
|
490
|
+
message: block as BlindedBeaconBlock,
|
|
491
|
+
signature: EMPTY_SIGNATURE,
|
|
492
|
+
} as SignedBlindedBeaconBlock)
|
|
493
|
+
: this.config.getForkTypes(block.slot).SignedBeaconBlock.serialize({
|
|
494
|
+
message: block,
|
|
495
|
+
signature: EMPTY_SIGNATURE,
|
|
496
|
+
} as SignedBeaconBlock);
|
|
497
|
+
|
|
498
|
+
return this.binding.computeBlockRewards(signedBlockBytes, isBlinded, proposerRewards);
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
computeAttestationsRewards(validatorIds?: (ValidatorIndex | string)[]): Promise<rewards.AttestationsRewards> {
|
|
501
|
+
async computeAttestationsRewards(validatorIds?: (ValidatorIndex | string)[]): Promise<rewards.AttestationsRewards> {
|
|
502
502
|
return this.binding.computeAttestationsRewards(validatorIds);
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
getLatestWeakSubjectivityCheckpointEpoch(): Epoch {
|
|
506
|
-
if (this.
|
|
507
|
-
this.
|
|
506
|
+
if (this.cachedLatestWeakSubjectivityCheckpointEpoch === null) {
|
|
507
|
+
this.cachedLatestWeakSubjectivityCheckpointEpoch = this.binding.getLatestWeakSubjectivityCheckpointEpoch();
|
|
508
508
|
}
|
|
509
|
-
return this.
|
|
509
|
+
return this.cachedLatestWeakSubjectivityCheckpointEpoch;
|
|
510
510
|
}
|
|
511
511
|
|
|
512
512
|
// Validation
|
|
@@ -525,17 +525,17 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
525
525
|
// Proofs
|
|
526
526
|
|
|
527
527
|
getFinalizedRootProof(): Uint8Array[] {
|
|
528
|
-
if (this.
|
|
529
|
-
this.
|
|
528
|
+
if (this.cachedFinalizedRootProof === null) {
|
|
529
|
+
this.cachedFinalizedRootProof = this.binding.getFinalizedRootProof();
|
|
530
530
|
}
|
|
531
|
-
return this.
|
|
531
|
+
return this.cachedFinalizedRootProof;
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
getSingleProof(gindex: bigint): Uint8Array[] {
|
|
535
|
-
let cached = this.
|
|
535
|
+
let cached = this.cachedSingleProof.get(gindex);
|
|
536
536
|
if (cached === undefined) {
|
|
537
537
|
cached = this.binding.getSingleProof(gindex);
|
|
538
|
-
this.
|
|
538
|
+
this.cachedSingleProof.set(gindex, cached);
|
|
539
539
|
}
|
|
540
540
|
return cached;
|
|
541
541
|
}
|
|
@@ -550,17 +550,17 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
550
550
|
justifiedCheckpoint: phase0.Checkpoint;
|
|
551
551
|
finalizedCheckpoint: phase0.Checkpoint;
|
|
552
552
|
} {
|
|
553
|
-
if (this.
|
|
554
|
-
this.
|
|
553
|
+
if (this.cachedUnrealizedCheckpoints === null) {
|
|
554
|
+
this.cachedUnrealizedCheckpoints = this.binding.computeUnrealizedCheckpoints();
|
|
555
555
|
}
|
|
556
|
-
return this.
|
|
556
|
+
return this.cachedUnrealizedCheckpoints;
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader} {
|
|
560
|
-
if (this.
|
|
561
|
-
this.
|
|
560
|
+
if (this.cachedAnchorCheckpoint === null) {
|
|
561
|
+
this.cachedAnchorCheckpoint = this.binding.computeAnchorCheckpoint();
|
|
562
562
|
}
|
|
563
|
-
return this.
|
|
563
|
+
return this.cachedAnchorCheckpoint;
|
|
564
564
|
}
|
|
565
565
|
|
|
566
566
|
// Backward compatibility
|
|
@@ -574,17 +574,17 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
574
574
|
}
|
|
575
575
|
|
|
576
576
|
get createdWithTransferCache(): boolean {
|
|
577
|
-
if (this.
|
|
578
|
-
this.
|
|
577
|
+
if (this.cachedCreatedWithTransferCache === null) {
|
|
578
|
+
this.cachedCreatedWithTransferCache = this.binding.createdWithTransferCache;
|
|
579
579
|
}
|
|
580
|
-
return this.
|
|
580
|
+
return this.cachedCreatedWithTransferCache;
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
isStateValidatorsNodesPopulated(): boolean {
|
|
584
|
-
if (this.
|
|
585
|
-
this.
|
|
584
|
+
if (this.cachedIsStateValidatorsNodesPopulated === null) {
|
|
585
|
+
this.cachedIsStateValidatorsNodesPopulated = this.binding.isStateValidatorsNodesPopulated();
|
|
586
586
|
}
|
|
587
|
-
return this.
|
|
587
|
+
return this.cachedIsStateValidatorsNodesPopulated;
|
|
588
588
|
}
|
|
589
589
|
|
|
590
590
|
// Serialization
|
|
@@ -594,28 +594,28 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
594
594
|
seedValidatorsBytes?: Uint8Array,
|
|
595
595
|
opts?: {preloadValidatorsAndBalances?: boolean}
|
|
596
596
|
): IBeaconStateView {
|
|
597
|
-
return new NativeBeaconStateView(this.binding.loadOtherState(stateBytes, seedValidatorsBytes, opts));
|
|
597
|
+
return new NativeBeaconStateView(this.config, this.binding.loadOtherState(stateBytes, seedValidatorsBytes, opts));
|
|
598
598
|
}
|
|
599
599
|
|
|
600
600
|
toValue(): BeaconState {
|
|
601
|
-
if (this.
|
|
602
|
-
this.
|
|
601
|
+
if (this.cachedValue === null) {
|
|
602
|
+
this.cachedValue = this.binding.toValue();
|
|
603
603
|
}
|
|
604
|
-
return this.
|
|
604
|
+
return this.cachedValue;
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
serialize(): Uint8Array {
|
|
608
|
-
if (this.
|
|
609
|
-
this.
|
|
608
|
+
if (this.cachedSerialized === null) {
|
|
609
|
+
this.cachedSerialized = this.binding.serialize();
|
|
610
610
|
}
|
|
611
|
-
return this.
|
|
611
|
+
return this.cachedSerialized;
|
|
612
612
|
}
|
|
613
613
|
|
|
614
614
|
serializedSize(): number {
|
|
615
|
-
if (this.
|
|
616
|
-
this.
|
|
615
|
+
if (this.cachedSerializedSize === null) {
|
|
616
|
+
this.cachedSerializedSize = this.binding.serializedSize();
|
|
617
617
|
}
|
|
618
|
-
return this.
|
|
618
|
+
return this.cachedSerializedSize;
|
|
619
619
|
}
|
|
620
620
|
|
|
621
621
|
serializeToBytes(output: ByteViews, offset: number): number {
|
|
@@ -623,17 +623,17 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
623
623
|
}
|
|
624
624
|
|
|
625
625
|
serializeValidators(): Uint8Array {
|
|
626
|
-
if (this.
|
|
627
|
-
this.
|
|
626
|
+
if (this.cachedSerializedValidators === null) {
|
|
627
|
+
this.cachedSerializedValidators = this.binding.serializeValidators();
|
|
628
628
|
}
|
|
629
|
-
return this.
|
|
629
|
+
return this.cachedSerializedValidators;
|
|
630
630
|
}
|
|
631
631
|
|
|
632
632
|
serializedValidatorsSize(): number {
|
|
633
|
-
if (this.
|
|
634
|
-
this.
|
|
633
|
+
if (this.cachedSerializedValidatorsSize === null) {
|
|
634
|
+
this.cachedSerializedValidatorsSize = this.binding.serializedValidatorsSize();
|
|
635
635
|
}
|
|
636
|
-
return this.
|
|
636
|
+
return this.cachedSerializedValidatorsSize;
|
|
637
637
|
}
|
|
638
638
|
|
|
639
639
|
serializeValidatorsToBytes(output: ByteViews, offset: number): number {
|
|
@@ -641,47 +641,53 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
hashTreeRoot(): Uint8Array {
|
|
644
|
-
if (this.
|
|
645
|
-
this.
|
|
644
|
+
if (this.cachedHashTreeRoot === null) {
|
|
645
|
+
this.cachedHashTreeRoot = this.binding.hashTreeRoot();
|
|
646
646
|
}
|
|
647
|
-
return this.
|
|
647
|
+
return this.cachedHashTreeRoot;
|
|
648
648
|
}
|
|
649
649
|
|
|
650
650
|
// State transition
|
|
651
651
|
|
|
652
|
-
computeNewStateRoot(input:
|
|
653
|
-
const postState =
|
|
654
|
-
this.binding.stateTransition(input.block, computeNewStateRootStateTransitionOpts, modules)
|
|
655
|
-
);
|
|
652
|
+
computeNewStateRoot(input: BlockSTFInput, modules: StateTransitionModules): ComputeNewStateRootResult {
|
|
653
|
+
const postState = this.stateTransition(input, computeNewStateRootStateTransitionOpts, modules);
|
|
656
654
|
return getComputeNewStateRootResult(postState);
|
|
657
655
|
}
|
|
658
656
|
|
|
659
657
|
stateTransition(
|
|
660
|
-
|
|
658
|
+
{block, ssz}: BlockSTFInput,
|
|
661
659
|
options: StateTransitionOpts,
|
|
662
|
-
|
|
660
|
+
_modules: StateTransitionModules
|
|
663
661
|
): IBeaconStateView {
|
|
664
|
-
|
|
662
|
+
const isBlinded = isBlindedBeaconBlock(block.message);
|
|
663
|
+
const signedBlockBytes =
|
|
664
|
+
ssz ??
|
|
665
|
+
(isBlinded
|
|
666
|
+
? this.config
|
|
667
|
+
.getPostBellatrixForkTypes(block.message.slot)
|
|
668
|
+
.SignedBlindedBeaconBlock.serialize(block as SignedBlindedBeaconBlock)
|
|
669
|
+
: this.config.getForkTypes(block.message.slot).SignedBeaconBlock.serialize(block as SignedBeaconBlock));
|
|
670
|
+
return new NativeBeaconStateView(this.config, this.binding.stateTransition(signedBlockBytes, isBlinded, options));
|
|
665
671
|
}
|
|
666
672
|
|
|
667
|
-
processSlots(slot: Slot, opts?: {dontTransferCache?: boolean},
|
|
668
|
-
return new NativeBeaconStateView(this.binding.processSlots(slot, opts
|
|
673
|
+
processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}, _modules?: StateTransitionModules): IBeaconStateView {
|
|
674
|
+
return new NativeBeaconStateView(this.config, this.binding.processSlots(slot, opts));
|
|
669
675
|
}
|
|
670
676
|
|
|
671
677
|
// ─── altair ──────────────────────────────────────────────────────────────
|
|
672
678
|
|
|
673
679
|
get previousEpochParticipation(): Uint8Array {
|
|
674
|
-
if (this.
|
|
675
|
-
this.
|
|
680
|
+
if (this.cachedPreviousEpochParticipation === null) {
|
|
681
|
+
this.cachedPreviousEpochParticipation = this.binding.previousEpochParticipation;
|
|
676
682
|
}
|
|
677
|
-
return this.
|
|
683
|
+
return this.cachedPreviousEpochParticipation;
|
|
678
684
|
}
|
|
679
685
|
|
|
680
686
|
get currentEpochParticipation(): Uint8Array {
|
|
681
|
-
if (this.
|
|
682
|
-
this.
|
|
687
|
+
if (this.cachedCurrentEpochParticipation === null) {
|
|
688
|
+
this.cachedCurrentEpochParticipation = this.binding.currentEpochParticipation;
|
|
683
689
|
}
|
|
684
|
-
return this.
|
|
690
|
+
return this.cachedCurrentEpochParticipation;
|
|
685
691
|
}
|
|
686
692
|
|
|
687
693
|
getPreviousEpochParticipation(validatorIndex: ValidatorIndex): number {
|
|
@@ -693,52 +699,52 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
693
699
|
}
|
|
694
700
|
|
|
695
701
|
get currentSyncCommittee(): altair.SyncCommittee {
|
|
696
|
-
if (this.
|
|
697
|
-
this.
|
|
702
|
+
if (this.cachedCurrentSyncCommittee === null) {
|
|
703
|
+
this.cachedCurrentSyncCommittee = this.binding.currentSyncCommittee;
|
|
698
704
|
}
|
|
699
|
-
return this.
|
|
705
|
+
return this.cachedCurrentSyncCommittee;
|
|
700
706
|
}
|
|
701
707
|
|
|
702
708
|
get nextSyncCommittee(): altair.SyncCommittee {
|
|
703
|
-
if (this.
|
|
704
|
-
this.
|
|
709
|
+
if (this.cachedNextSyncCommittee === null) {
|
|
710
|
+
this.cachedNextSyncCommittee = this.binding.nextSyncCommittee;
|
|
705
711
|
}
|
|
706
|
-
return this.
|
|
712
|
+
return this.cachedNextSyncCommittee;
|
|
707
713
|
}
|
|
708
714
|
|
|
709
715
|
get currentSyncCommitteeIndexed(): SyncCommitteeCache {
|
|
710
|
-
if (this.
|
|
711
|
-
this.
|
|
716
|
+
if (this.cachedCurrentSyncCommitteeIndexed === null) {
|
|
717
|
+
this.cachedCurrentSyncCommitteeIndexed = this.binding.currentSyncCommitteeIndexed;
|
|
712
718
|
}
|
|
713
|
-
return this.
|
|
719
|
+
return this.cachedCurrentSyncCommitteeIndexed;
|
|
714
720
|
}
|
|
715
721
|
|
|
716
722
|
get syncProposerReward(): number {
|
|
717
|
-
if (this.
|
|
718
|
-
this.
|
|
723
|
+
if (this.cachedSyncProposerReward === null) {
|
|
724
|
+
this.cachedSyncProposerReward = this.binding.syncProposerReward;
|
|
719
725
|
}
|
|
720
|
-
return this.
|
|
726
|
+
return this.cachedSyncProposerReward;
|
|
721
727
|
}
|
|
722
728
|
|
|
723
729
|
getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache {
|
|
724
|
-
let cached = this.
|
|
730
|
+
let cached = this.cachedIndexedSyncCommitteeAtEpoch.get(epoch);
|
|
725
731
|
if (cached === undefined) {
|
|
726
732
|
cached = this.binding.getIndexedSyncCommitteeAtEpoch(epoch);
|
|
727
|
-
this.
|
|
733
|
+
this.cachedIndexedSyncCommitteeAtEpoch.set(epoch, cached);
|
|
728
734
|
}
|
|
729
735
|
return cached;
|
|
730
736
|
}
|
|
731
737
|
|
|
732
738
|
getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache {
|
|
733
|
-
let cached = this.
|
|
739
|
+
let cached = this.cachedIndexedSyncCommittee.get(slot);
|
|
734
740
|
if (cached === undefined) {
|
|
735
741
|
cached = this.binding.getIndexedSyncCommittee(slot);
|
|
736
|
-
this.
|
|
742
|
+
this.cachedIndexedSyncCommittee.set(slot, cached);
|
|
737
743
|
}
|
|
738
744
|
return cached;
|
|
739
745
|
}
|
|
740
746
|
|
|
741
|
-
computeSyncCommitteeRewards(
|
|
747
|
+
async computeSyncCommitteeRewards(
|
|
742
748
|
block: BeaconBlock,
|
|
743
749
|
validatorIds: (ValidatorIndex | string)[]
|
|
744
750
|
): Promise<rewards.SyncCommitteeRewards> {
|
|
@@ -746,40 +752,40 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
746
752
|
}
|
|
747
753
|
|
|
748
754
|
getSyncCommitteesWitness(): SyncCommitteeWitness {
|
|
749
|
-
if (this.
|
|
750
|
-
this.
|
|
755
|
+
if (this.cachedSyncCommitteesWitness === null) {
|
|
756
|
+
this.cachedSyncCommitteesWitness = this.binding.getSyncCommitteesWitness();
|
|
751
757
|
}
|
|
752
|
-
return this.
|
|
758
|
+
return this.cachedSyncCommitteesWitness;
|
|
753
759
|
}
|
|
754
760
|
|
|
755
761
|
// ─── bellatrix ───────────────────────────────────────────────────────────
|
|
756
762
|
|
|
757
763
|
get latestExecutionPayloadHeader(): ExecutionPayloadHeader {
|
|
758
|
-
if (this.
|
|
759
|
-
this.
|
|
764
|
+
if (this.cachedLatestExecutionPayloadHeader === null) {
|
|
765
|
+
this.cachedLatestExecutionPayloadHeader = this.binding.latestExecutionPayloadHeader;
|
|
760
766
|
}
|
|
761
|
-
return this.
|
|
767
|
+
return this.cachedLatestExecutionPayloadHeader;
|
|
762
768
|
}
|
|
763
769
|
|
|
764
770
|
get payloadBlockNumber(): number {
|
|
765
|
-
if (this.
|
|
766
|
-
this.
|
|
771
|
+
if (this.cachedPayloadBlockNumber === null) {
|
|
772
|
+
this.cachedPayloadBlockNumber = this.binding.payloadBlockNumber;
|
|
767
773
|
}
|
|
768
|
-
return this.
|
|
774
|
+
return this.cachedPayloadBlockNumber;
|
|
769
775
|
}
|
|
770
776
|
|
|
771
777
|
get isExecutionStateType(): boolean {
|
|
772
|
-
if (this.
|
|
773
|
-
this.
|
|
778
|
+
if (this.cachedIsExecutionStateType === null) {
|
|
779
|
+
this.cachedIsExecutionStateType = this.binding.isExecutionStateType;
|
|
774
780
|
}
|
|
775
|
-
return this.
|
|
781
|
+
return this.cachedIsExecutionStateType;
|
|
776
782
|
}
|
|
777
783
|
|
|
778
784
|
get isMergeTransitionComplete(): boolean {
|
|
779
|
-
if (this.
|
|
780
|
-
this.
|
|
785
|
+
if (this.cachedIsMergeTransitionComplete === null) {
|
|
786
|
+
this.cachedIsMergeTransitionComplete = this.binding.isMergeTransitionComplete;
|
|
781
787
|
}
|
|
782
|
-
return this.
|
|
788
|
+
return this.cachedIsMergeTransitionComplete;
|
|
783
789
|
}
|
|
784
790
|
|
|
785
791
|
isExecutionEnabled(block: BeaconBlock | BlindedBeaconBlock): boolean {
|
|
@@ -789,10 +795,10 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
789
795
|
// ─── capella ─────────────────────────────────────────────────────────────
|
|
790
796
|
|
|
791
797
|
get historicalSummaries(): capella.HistoricalSummaries {
|
|
792
|
-
if (this.
|
|
793
|
-
this.
|
|
798
|
+
if (this.cachedHistoricalSummaries === null) {
|
|
799
|
+
this.cachedHistoricalSummaries = this.binding.historicalSummaries;
|
|
794
800
|
}
|
|
795
|
-
return this.
|
|
801
|
+
return this.cachedHistoricalSummaries;
|
|
796
802
|
}
|
|
797
803
|
|
|
798
804
|
getExpectedWithdrawals(): {
|
|
@@ -802,154 +808,127 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
802
808
|
processedBuildersSweepCount: number;
|
|
803
809
|
processedValidatorSweepCount: number;
|
|
804
810
|
} {
|
|
805
|
-
if (this.
|
|
806
|
-
this.
|
|
811
|
+
if (this.cachedExpectedWithdrawals === null) {
|
|
812
|
+
this.cachedExpectedWithdrawals = this.binding.getExpectedWithdrawals();
|
|
807
813
|
}
|
|
808
|
-
return this.
|
|
814
|
+
return this.cachedExpectedWithdrawals;
|
|
809
815
|
}
|
|
810
816
|
|
|
811
817
|
// ─── electra ─────────────────────────────────────────────────────────────
|
|
812
818
|
|
|
813
819
|
get pendingDeposits(): electra.PendingDeposits {
|
|
814
|
-
if (this.
|
|
815
|
-
this.
|
|
820
|
+
if (this.cachedPendingDeposits === null) {
|
|
821
|
+
this.cachedPendingDeposits = ssz.electra.PendingDeposits.deserialize(this.binding.pendingDeposits);
|
|
816
822
|
}
|
|
817
|
-
return this.
|
|
823
|
+
return this.cachedPendingDeposits;
|
|
818
824
|
}
|
|
819
825
|
|
|
820
826
|
get pendingDepositsCount(): number {
|
|
821
|
-
if (this.
|
|
822
|
-
this.
|
|
827
|
+
if (this.cachedPendingDepositsCount === null) {
|
|
828
|
+
this.cachedPendingDepositsCount = this.binding.pendingDepositsCount;
|
|
823
829
|
}
|
|
824
|
-
return this.
|
|
830
|
+
return this.cachedPendingDepositsCount;
|
|
825
831
|
}
|
|
826
832
|
|
|
827
833
|
get pendingPartialWithdrawals(): electra.PendingPartialWithdrawals {
|
|
828
|
-
if (this.
|
|
829
|
-
this.
|
|
834
|
+
if (this.cachedPendingPartialWithdrawals === null) {
|
|
835
|
+
this.cachedPendingPartialWithdrawals = ssz.electra.PendingPartialWithdrawals.deserialize(
|
|
836
|
+
this.binding.pendingPartialWithdrawals
|
|
837
|
+
);
|
|
830
838
|
}
|
|
831
|
-
return this.
|
|
839
|
+
return this.cachedPendingPartialWithdrawals;
|
|
832
840
|
}
|
|
833
841
|
|
|
834
842
|
get pendingPartialWithdrawalsCount(): number {
|
|
835
|
-
if (this.
|
|
836
|
-
this.
|
|
843
|
+
if (this.cachedPendingPartialWithdrawalsCount === null) {
|
|
844
|
+
this.cachedPendingPartialWithdrawalsCount = this.binding.pendingPartialWithdrawalsCount;
|
|
837
845
|
}
|
|
838
|
-
return this.
|
|
846
|
+
return this.cachedPendingPartialWithdrawalsCount;
|
|
839
847
|
}
|
|
840
848
|
|
|
841
849
|
get pendingConsolidations(): electra.PendingConsolidations {
|
|
842
|
-
if (this.
|
|
843
|
-
this.
|
|
850
|
+
if (this.cachedPendingConsolidations === null) {
|
|
851
|
+
this.cachedPendingConsolidations = ssz.electra.PendingConsolidations.deserialize(
|
|
852
|
+
this.binding.pendingConsolidations
|
|
853
|
+
);
|
|
844
854
|
}
|
|
845
|
-
return this.
|
|
855
|
+
return this.cachedPendingConsolidations;
|
|
846
856
|
}
|
|
847
857
|
|
|
848
858
|
get pendingConsolidationsCount(): number {
|
|
849
|
-
if (this.
|
|
850
|
-
this.
|
|
859
|
+
if (this.cachedPendingConsolidationsCount === null) {
|
|
860
|
+
this.cachedPendingConsolidationsCount = this.binding.pendingConsolidationsCount;
|
|
851
861
|
}
|
|
852
|
-
return this.
|
|
862
|
+
return this.cachedPendingConsolidationsCount;
|
|
853
863
|
}
|
|
854
864
|
|
|
855
865
|
// ─── fulu ────────────────────────────────────────────────────────────────
|
|
856
866
|
|
|
857
867
|
get proposerLookahead(): fulu.ProposerLookahead {
|
|
858
|
-
if (this.
|
|
859
|
-
this.
|
|
868
|
+
if (this.cachedProposerLookahead === null) {
|
|
869
|
+
this.cachedProposerLookahead = Array.from(this.binding.proposerLookahead);
|
|
860
870
|
}
|
|
861
|
-
return this.
|
|
871
|
+
return this.cachedProposerLookahead;
|
|
862
872
|
}
|
|
863
873
|
|
|
864
|
-
preVerifyBuilderDepositsPreGloas(
|
|
865
|
-
|
|
874
|
+
preVerifyBuilderDepositsPreGloas(
|
|
875
|
+
_maxBuilderDeposits: number,
|
|
876
|
+
_maxDurationMs: number
|
|
877
|
+
): PreVerifyBuilderDepositsResult {
|
|
878
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
866
879
|
}
|
|
867
880
|
|
|
868
881
|
clearPreGloasBuilderDepositCache(): void {
|
|
869
|
-
|
|
882
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
870
883
|
}
|
|
871
884
|
|
|
872
885
|
// ─── gloas ───────────────────────────────────────────────────────────────
|
|
873
886
|
|
|
874
887
|
get latestBlockHash(): Bytes32 {
|
|
875
|
-
|
|
876
|
-
this._latestBlockHash = this.binding.latestBlockHash;
|
|
877
|
-
}
|
|
878
|
-
return this._latestBlockHash;
|
|
888
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
879
889
|
}
|
|
880
890
|
|
|
881
|
-
// executionPayloadAvailability getter is defined near the top of the class.
|
|
882
|
-
|
|
883
891
|
get latestExecutionPayloadBid(): ExecutionPayloadBid {
|
|
884
|
-
|
|
885
|
-
this._latestExecutionPayloadBid = this.binding.latestExecutionPayloadBid;
|
|
886
|
-
}
|
|
887
|
-
return this._latestExecutionPayloadBid;
|
|
892
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
888
893
|
}
|
|
889
894
|
|
|
890
895
|
get payloadExpectedWithdrawals(): capella.Withdrawal[] {
|
|
891
|
-
|
|
892
|
-
this._payloadExpectedWithdrawals = this.binding.payloadExpectedWithdrawals;
|
|
893
|
-
}
|
|
894
|
-
return this._payloadExpectedWithdrawals;
|
|
896
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
895
897
|
}
|
|
896
898
|
|
|
897
899
|
get builderPendingPayments(): gloas.BuilderPendingPayments {
|
|
898
|
-
|
|
899
|
-
this._builderPendingPayments = this.binding.builderPendingPayments;
|
|
900
|
-
}
|
|
901
|
-
return this._builderPendingPayments;
|
|
900
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
902
901
|
}
|
|
903
902
|
|
|
904
903
|
get builderPendingWithdrawals(): gloas.BuilderPendingWithdrawals {
|
|
905
|
-
|
|
906
|
-
this._builderPendingWithdrawals = this.binding.builderPendingWithdrawals;
|
|
907
|
-
}
|
|
908
|
-
return this._builderPendingWithdrawals;
|
|
904
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
909
905
|
}
|
|
910
906
|
|
|
911
|
-
getBuilder(
|
|
912
|
-
|
|
913
|
-
if (cached === undefined) {
|
|
914
|
-
cached = this.binding.getBuilder(index);
|
|
915
|
-
this._getBuilder.set(index, cached);
|
|
916
|
-
}
|
|
917
|
-
return cached;
|
|
907
|
+
getBuilder(_index: BuilderIndex): gloas.Builder {
|
|
908
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
918
909
|
}
|
|
919
910
|
|
|
920
911
|
getBuildersLength(): number {
|
|
921
|
-
|
|
922
|
-
this._getBuildersLength = this.binding.getBuildersLength();
|
|
923
|
-
}
|
|
924
|
-
return this._getBuildersLength;
|
|
912
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
925
913
|
}
|
|
926
914
|
|
|
927
|
-
canBuilderCoverBid(
|
|
928
|
-
|
|
915
|
+
canBuilderCoverBid(_builderIndex: BuilderIndex, _bidAmount: number): boolean {
|
|
916
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
929
917
|
}
|
|
930
918
|
|
|
931
|
-
getEpochPTCs(
|
|
932
|
-
|
|
933
|
-
if (cached === undefined) {
|
|
934
|
-
cached = this.binding.getEpochPTCs(epoch);
|
|
935
|
-
this._getEpochPTCs.set(epoch, cached);
|
|
936
|
-
}
|
|
937
|
-
return cached;
|
|
919
|
+
getEpochPTCs(_epoch: Epoch): Uint32Array[] {
|
|
920
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
938
921
|
}
|
|
939
922
|
|
|
940
|
-
getPayloadTimelinessCommittee(
|
|
941
|
-
|
|
923
|
+
getPayloadTimelinessCommittee(_slot: Slot): Uint32Array {
|
|
924
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
942
925
|
}
|
|
943
926
|
|
|
944
|
-
getIndicesInPayloadTimelinessCommittee(
|
|
945
|
-
|
|
927
|
+
getIndicesInPayloadTimelinessCommittee(_validatorIndex: ValidatorIndex, _slot: Slot): number[] {
|
|
928
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
946
929
|
}
|
|
947
930
|
|
|
948
|
-
withParentPayloadApplied(
|
|
949
|
-
|
|
950
|
-
if (!isStatePostGloas(view)) {
|
|
951
|
-
throw new Error("Expected gloas state from withParentPayloadApplied");
|
|
952
|
-
}
|
|
953
|
-
return view;
|
|
931
|
+
withParentPayloadApplied(_executionRequests: gloas.ExecutionRequests): IBeaconStateViewGloas {
|
|
932
|
+
throw new Error("NativeBeaconStateView does not support Gloas");
|
|
954
933
|
}
|
|
955
934
|
}
|