@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.
Files changed (68) hide show
  1. package/lib/block/indexedBuilderState.d.ts +19 -0
  2. package/lib/block/indexedBuilderState.d.ts.map +1 -0
  3. package/lib/block/indexedBuilderState.js +60 -0
  4. package/lib/block/indexedBuilderState.js.map +1 -0
  5. package/lib/block/processBuilderDepositRequest.d.ts +2 -2
  6. package/lib/block/processBuilderDepositRequest.d.ts.map +1 -1
  7. package/lib/block/processBuilderDepositRequest.js +5 -4
  8. package/lib/block/processBuilderDepositRequest.js.map +1 -1
  9. package/lib/block/processBuilderExitRequest.d.ts +2 -2
  10. package/lib/block/processBuilderExitRequest.d.ts.map +1 -1
  11. package/lib/block/processBuilderExitRequest.js +4 -3
  12. package/lib/block/processBuilderExitRequest.js.map +1 -1
  13. package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
  14. package/lib/block/processParentExecutionPayload.js +23 -18
  15. package/lib/block/processParentExecutionPayload.js.map +1 -1
  16. package/lib/index.d.ts +3 -1
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +2 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/rewards/attestationsRewards.d.ts.map +1 -1
  21. package/lib/rewards/attestationsRewards.js +8 -1
  22. package/lib/rewards/attestationsRewards.js.map +1 -1
  23. package/lib/stateView/beaconStateView.d.ts +22 -21
  24. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  25. package/lib/stateView/beaconStateView.js +71 -71
  26. package/lib/stateView/beaconStateView.js.map +1 -1
  27. package/lib/stateView/interface.d.ts +34 -21
  28. package/lib/stateView/interface.d.ts.map +1 -1
  29. package/lib/stateView/interface.js.map +1 -1
  30. package/lib/stateView/nativeBeaconStateView.d.ts +92 -100
  31. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  32. package/lib/stateView/nativeBeaconStateView.js +339 -368
  33. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  34. package/lib/stateView/stateViewFactory.d.ts +10 -17
  35. package/lib/stateView/stateViewFactory.d.ts.map +1 -1
  36. package/lib/stateView/stateViewFactory.js +17 -13
  37. package/lib/stateView/stateViewFactory.js.map +1 -1
  38. package/lib/util/gloas.d.ts +11 -14
  39. package/lib/util/gloas.d.ts.map +1 -1
  40. package/lib/util/gloas.js +2 -42
  41. package/lib/util/gloas.js.map +1 -1
  42. package/lib/util/index.d.ts +1 -0
  43. package/lib/util/index.d.ts.map +1 -1
  44. package/lib/util/index.js +1 -0
  45. package/lib/util/index.js.map +1 -1
  46. package/lib/util/sszBytes.d.ts +16 -17
  47. package/lib/util/sszBytes.d.ts.map +1 -1
  48. package/lib/util/sszBytes.js +93 -20
  49. package/lib/util/sszBytes.js.map +1 -1
  50. package/lib/util/weakSubjectivity.d.ts +11 -6
  51. package/lib/util/weakSubjectivity.d.ts.map +1 -1
  52. package/lib/util/weakSubjectivity.js +22 -28
  53. package/lib/util/weakSubjectivity.js.map +1 -1
  54. package/package.json +7 -7
  55. package/src/block/indexedBuilderState.ts +65 -0
  56. package/src/block/processBuilderDepositRequest.ts +6 -17
  57. package/src/block/processBuilderExitRequest.ts +5 -9
  58. package/src/block/processParentExecutionPayload.ts +27 -23
  59. package/src/index.ts +4 -1
  60. package/src/rewards/attestationsRewards.ts +8 -1
  61. package/src/stateView/beaconStateView.ts +75 -76
  62. package/src/stateView/interface.ts +61 -21
  63. package/src/stateView/nativeBeaconStateView.ts +354 -375
  64. package/src/stateView/stateViewFactory.ts +29 -27
  65. package/src/util/gloas.ts +2 -53
  66. package/src/util/index.ts +6 -0
  67. package/src/util/sszBytes.ts +129 -22
  68. 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
- ComputeNewStateRootInput,
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` — identical to
54
- * `IBeaconStateViewLatestFork` except `executionPayloadAvailability` is a raw
55
- * `{uint8Array, bitLen}` POJO. The `executionPayloadAvailability` getter lifts
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 _forkName: ForkName | null = null;
68
- private _forkSeq: ForkSeq | null = null;
69
- private _slot: Slot | null = null;
70
- private _fork: Fork | null = null;
71
- private _epoch: Epoch | null = null;
72
- private _genesisTime: number | null = null;
73
- private _genesisValidatorsRoot: Root | null = null;
74
- private _eth1Data: phase0.Eth1Data | null = null;
75
- private _latestBlockHeader: phase0.BeaconBlockHeader | null = null;
76
- private _previousJustifiedCheckpoint: Checkpoint | null = null;
77
- private _currentJustifiedCheckpoint: Checkpoint | null = null;
78
- private _finalizedCheckpoint: Checkpoint | null = null;
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 _previousDecisionRoot: RootHex | null = null;
81
- private _currentDecisionRoot: RootHex | null = null;
82
- private _nextDecisionRoot: RootHex | null = null;
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 _previousProposers: ValidatorIndex[] | null | undefined = undefined;
85
- private _currentProposers: ValidatorIndex[] | null = null;
86
- private _nextProposers: ValidatorIndex[] | null = null;
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 _effectiveBalanceIncrements: EffectiveBalanceIncrements | null = null;
89
- private _validatorCount: number | null = null;
90
- private _activeValidatorCount: number | null = null;
89
+ private cachedEffectiveBalanceIncrements: EffectiveBalanceIncrements | null = null;
90
+ private cachedValidatorCount: number | null = null;
91
+ private cachedActiveValidatorCount: number | null = null;
91
92
  // backward compat
92
- private _createdWithTransferCache: boolean | null = null;
93
+ private cachedCreatedWithTransferCache: boolean | null = null;
93
94
  // altair
94
- private _currentSyncCommittee: SyncCommittee | null = null;
95
- private _nextSyncCommittee: SyncCommittee | null = null;
96
- private _previousEpochParticipation: Uint8Array | null = null;
97
- private _currentEpochParticipation: Uint8Array | null = null;
98
- private _currentSyncCommitteeIndexed: SyncCommitteeCache | null = null;
99
- private _syncProposerReward: number | null = null;
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 _latestExecutionPayloadHeader: ExecutionPayloadHeader | null = null;
102
- private _payloadBlockNumber: number | null = null;
103
- private _isExecutionStateType: boolean | null = null;
104
- private _isMergeTransitionComplete: boolean | null = null;
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 _historicalSummaries: capella.HistoricalSummaries | null = null;
107
+ private cachedHistoricalSummaries: capella.HistoricalSummaries | null = null;
107
108
  // electra
108
- private _pendingPartialWithdrawals: electra.PendingPartialWithdrawals | null = null;
109
- private _pendingConsolidations: electra.PendingConsolidations | null = null;
110
- private _pendingDeposits: electra.PendingDeposits | null = null;
111
- private _pendingDepositsCount: number | null = null;
112
- private _pendingPartialWithdrawalsCount: number | null = null;
113
- private _pendingConsolidationsCount: number | null = null;
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 _proposerLookahead: fulu.ProposerLookahead | null = null;
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 _getBlockRootAtSlot = new Map<Slot, Root>();
129
- private readonly _getBlockRootAtEpoch = new Map<Epoch, Root>();
130
- private readonly _getStateRootAtSlot = new Map<Slot, Root>();
131
- private readonly _getRandaoMix = new Map<Epoch, Bytes32>();
132
- private readonly _getShufflingAtEpoch = new Map<Epoch, EpochShuffling>();
133
- private readonly _getBeaconCommittee = new Map<string, Uint32Array>();
134
- private readonly _getBeaconCommitteeCountPerSlot = new Map<Epoch, number>();
135
- private readonly _getShufflingDecisionRoot = new Map<Epoch, RootHex>();
136
- private readonly _getBeaconProposer = new Map<Slot, ValidatorIndex>();
137
- private readonly _getValidator = new Map<ValidatorIndex, phase0.Validator>();
138
- private readonly _getBalance = new Map<number, number>();
139
- private readonly _getIndexedSyncCommitteeAtEpoch = new Map<Epoch, SyncCommitteeCache>();
140
- private readonly _getIndexedSyncCommittee = new Map<Slot, SyncCommitteeCache>();
141
- private readonly _getSingleProof = new Map<bigint, Uint8Array[]>();
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 _getPreviousShuffling: EpochShuffling | null = null;
147
- private _getCurrentShuffling: EpochShuffling | null = null;
148
- private _getNextShuffling: EpochShuffling | null = null;
149
- private _getEffectiveBalanceIncrementsZeroInactive: EffectiveBalanceIncrements | null = null;
150
- private _getAllValidators: phase0.Validator[] | null = null;
151
- private _getBuildersLength: number | null = null;
152
- private _getAllBalances: number[] | null = null;
153
- private _getLatestWeakSubjectivityCheckpointEpoch: Epoch | null = null;
154
- private _getFinalizedRootProof: Uint8Array[] | null = null;
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 _computeAnchorCheckpoint: {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader} | null =
160
- null;
161
- private _isStateValidatorsNodesPopulated: boolean | null = null;
162
- private _toValue: BeaconState | null = null;
163
- private _serialize: Uint8Array | null = null;
164
- private _serializedSize: number | null = null;
165
- private _serializeValidators: Uint8Array | null = null;
166
- private _serializedValidatorsSize: number | null = null;
167
- private _hashTreeRoot: Uint8Array | null = null;
168
- private _getSyncCommitteesWitness: SyncCommitteeWitness | null = null;
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(readonly binding: IBeaconStateViewNative) {}
166
+ constructor(
167
+ private readonly config: BeaconConfig,
168
+ readonly binding: IBeaconStateViewNative
169
+ ) {}
178
170
 
179
- // Binding returns pojo object {uint8Array: Uint8Array; bitLen: number}
180
- // this class wrap it with BitArray to conform to the api
181
- get executionPayloadAvailability(): BitArray {
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
- return this._executionPayloadAvailability;
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._forkName === null) {
194
- this._forkName = this.binding.forkName;
182
+ if (this.cachedForkName === null) {
183
+ this.cachedForkName = this.binding.forkName;
195
184
  }
196
- return this._forkName;
185
+ return this.cachedForkName;
197
186
  }
198
187
 
199
188
  get forkSeq(): ForkSeq {
200
- if (this._forkSeq === null) {
201
- this._forkSeq = this.binding.forkSeq;
189
+ if (this.cachedForkSeq === null) {
190
+ this.cachedForkSeq = this.binding.forkSeq;
202
191
  }
203
- return this._forkSeq;
192
+ return this.cachedForkSeq;
204
193
  }
205
194
 
206
195
  get slot(): Slot {
207
- if (this._slot === null) {
208
- this._slot = this.binding.slot;
196
+ if (this.cachedSlot === null) {
197
+ this.cachedSlot = this.binding.slot;
209
198
  }
210
- return this._slot;
199
+ return this.cachedSlot;
211
200
  }
212
201
 
213
202
  get fork(): Fork {
214
- if (this._fork === null) {
215
- this._fork = this.binding.fork;
203
+ if (this.cachedFork === null) {
204
+ this.cachedFork = this.binding.fork;
216
205
  }
217
- return this._fork;
206
+ return this.cachedFork;
218
207
  }
219
208
 
220
209
  get epoch(): Epoch {
221
- if (this._epoch === null) {
222
- this._epoch = this.binding.epoch;
210
+ if (this.cachedEpoch === null) {
211
+ this.cachedEpoch = this.binding.epoch;
223
212
  }
224
- return this._epoch;
213
+ return this.cachedEpoch;
225
214
  }
226
215
 
227
216
  get genesisTime(): number {
228
- if (this._genesisTime === null) {
229
- this._genesisTime = this.binding.genesisTime;
217
+ if (this.cachedGenesisTime === null) {
218
+ this.cachedGenesisTime = this.binding.genesisTime;
230
219
  }
231
- return this._genesisTime;
220
+ return this.cachedGenesisTime;
232
221
  }
233
222
 
234
223
  get genesisValidatorsRoot(): Root {
235
- if (this._genesisValidatorsRoot === null) {
236
- this._genesisValidatorsRoot = this.binding.genesisValidatorsRoot;
224
+ if (this.cachedGenesisValidatorsRoot === null) {
225
+ this.cachedGenesisValidatorsRoot = this.binding.genesisValidatorsRoot;
237
226
  }
238
- return this._genesisValidatorsRoot;
227
+ return this.cachedGenesisValidatorsRoot;
239
228
  }
240
229
 
241
230
  get eth1Data(): phase0.Eth1Data {
242
- if (this._eth1Data === null) {
243
- this._eth1Data = this.binding.eth1Data;
231
+ if (this.cachedEth1Data === null) {
232
+ this.cachedEth1Data = this.binding.eth1Data;
244
233
  }
245
- return this._eth1Data;
234
+ return this.cachedEth1Data;
246
235
  }
247
236
 
248
237
  get latestBlockHeader(): phase0.BeaconBlockHeader {
249
- if (this._latestBlockHeader === null) {
250
- this._latestBlockHeader = this.binding.latestBlockHeader;
238
+ if (this.cachedLatestBlockHeader === null) {
239
+ this.cachedLatestBlockHeader = this.binding.latestBlockHeader;
251
240
  }
252
- return this._latestBlockHeader;
241
+ return this.cachedLatestBlockHeader;
253
242
  }
254
243
 
255
244
  get previousJustifiedCheckpoint(): Checkpoint {
256
- if (this._previousJustifiedCheckpoint === null) {
257
- this._previousJustifiedCheckpoint = this.binding.previousJustifiedCheckpoint;
245
+ if (this.cachedPreviousJustifiedCheckpoint === null) {
246
+ this.cachedPreviousJustifiedCheckpoint = this.binding.previousJustifiedCheckpoint;
258
247
  }
259
- return this._previousJustifiedCheckpoint;
248
+ return this.cachedPreviousJustifiedCheckpoint;
260
249
  }
261
250
 
262
251
  get currentJustifiedCheckpoint(): Checkpoint {
263
- if (this._currentJustifiedCheckpoint === null) {
264
- this._currentJustifiedCheckpoint = this.binding.currentJustifiedCheckpoint;
252
+ if (this.cachedCurrentJustifiedCheckpoint === null) {
253
+ this.cachedCurrentJustifiedCheckpoint = this.binding.currentJustifiedCheckpoint;
265
254
  }
266
- return this._currentJustifiedCheckpoint;
255
+ return this.cachedCurrentJustifiedCheckpoint;
267
256
  }
268
257
 
269
258
  get finalizedCheckpoint(): Checkpoint {
270
- if (this._finalizedCheckpoint === null) {
271
- this._finalizedCheckpoint = this.binding.finalizedCheckpoint;
259
+ if (this.cachedFinalizedCheckpoint === null) {
260
+ this.cachedFinalizedCheckpoint = this.binding.finalizedCheckpoint;
272
261
  }
273
- return this._finalizedCheckpoint;
262
+ return this.cachedFinalizedCheckpoint;
274
263
  }
275
264
 
276
265
  getBlockRootAtSlot(slot: Slot): Root {
277
- let cached = this._getBlockRootAtSlot.get(slot);
266
+ let cached = this.cachedBlockRootAtSlot.get(slot);
278
267
  if (cached === undefined) {
279
268
  cached = this.binding.getBlockRootAtSlot(slot);
280
- this._getBlockRootAtSlot.set(slot, cached);
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._getBlockRootAtEpoch.get(epoch);
275
+ let cached = this.cachedBlockRootAtEpoch.get(epoch);
287
276
  if (cached === undefined) {
288
277
  cached = this.binding.getBlockRootAtEpoch(epoch);
289
- this._getBlockRootAtEpoch.set(epoch, cached);
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._getStateRootAtSlot.get(slot);
284
+ let cached = this.cachedStateRootAtSlot.get(slot);
296
285
  if (cached === undefined) {
297
286
  cached = this.binding.getStateRootAtSlot(slot);
298
- this._getStateRootAtSlot.set(slot, cached);
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._getRandaoMix.get(epoch);
293
+ let cached = this.cachedRandaoMix.get(epoch);
305
294
  if (cached === undefined) {
306
295
  cached = this.binding.getRandaoMix(epoch);
307
- this._getRandaoMix.set(epoch, cached);
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._getShufflingAtEpoch.get(epoch);
304
+ let cached = this.cachedShufflingAtEpoch.get(epoch);
316
305
  if (cached === undefined) {
317
306
  cached = this.binding.getShufflingAtEpoch(epoch);
318
- this._getShufflingAtEpoch.set(epoch, cached);
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._getBeaconCommittee.get(key);
314
+ let cached = this.cachedBeaconCommittee.get(key);
326
315
  if (cached === undefined) {
327
316
  cached = this.binding.getBeaconCommittee(slot, index);
328
- this._getBeaconCommittee.set(key, cached);
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._getBeaconCommitteeCountPerSlot.get(epoch);
323
+ let cached = this.cachedBeaconCommitteeCountPerSlot.get(epoch);
335
324
  if (cached === undefined) {
336
325
  cached = this.binding.getBeaconCommitteeCountPerSlot(epoch);
337
- this._getBeaconCommitteeCountPerSlot.set(epoch, cached);
326
+ this.cachedBeaconCommitteeCountPerSlot.set(epoch, cached);
338
327
  }
339
328
  return cached;
340
329
  }
341
330
 
342
331
  get previousDecisionRoot(): RootHex {
343
- if (this._previousDecisionRoot === null) {
344
- this._previousDecisionRoot = this.binding.previousDecisionRoot;
332
+ if (this.cachedPreviousDecisionRoot === null) {
333
+ this.cachedPreviousDecisionRoot = this.binding.previousDecisionRoot;
345
334
  }
346
- return this._previousDecisionRoot;
335
+ return this.cachedPreviousDecisionRoot;
347
336
  }
348
337
 
349
338
  get currentDecisionRoot(): RootHex {
350
- if (this._currentDecisionRoot === null) {
351
- this._currentDecisionRoot = this.binding.currentDecisionRoot;
339
+ if (this.cachedCurrentDecisionRoot === null) {
340
+ this.cachedCurrentDecisionRoot = this.binding.currentDecisionRoot;
352
341
  }
353
- return this._currentDecisionRoot;
342
+ return this.cachedCurrentDecisionRoot;
354
343
  }
355
344
 
356
345
  get nextDecisionRoot(): RootHex {
357
- if (this._nextDecisionRoot === null) {
358
- this._nextDecisionRoot = this.binding.nextDecisionRoot;
346
+ if (this.cachedNextDecisionRoot === null) {
347
+ this.cachedNextDecisionRoot = this.binding.nextDecisionRoot;
359
348
  }
360
- return this._nextDecisionRoot;
349
+ return this.cachedNextDecisionRoot;
361
350
  }
362
351
 
363
352
  getShufflingDecisionRoot(epoch: Epoch): RootHex {
364
- let cached = this._getShufflingDecisionRoot.get(epoch);
353
+ let cached = this.cachedShufflingDecisionRoot.get(epoch);
365
354
  if (cached === undefined) {
366
355
  cached = this.binding.getShufflingDecisionRoot(epoch);
367
- this._getShufflingDecisionRoot.set(epoch, cached);
356
+ this.cachedShufflingDecisionRoot.set(epoch, cached);
368
357
  }
369
358
  return cached;
370
359
  }
371
360
 
372
361
  getPreviousShuffling(): EpochShuffling {
373
- if (this._getPreviousShuffling === null) {
374
- this._getPreviousShuffling = this.binding.getPreviousShuffling();
362
+ if (this.cachedPreviousShuffling === null) {
363
+ this.cachedPreviousShuffling = this.binding.getPreviousShuffling();
375
364
  }
376
- return this._getPreviousShuffling;
365
+ return this.cachedPreviousShuffling;
377
366
  }
378
367
 
379
368
  getCurrentShuffling(): EpochShuffling {
380
- if (this._getCurrentShuffling === null) {
381
- this._getCurrentShuffling = this.binding.getCurrentShuffling();
369
+ if (this.cachedCurrentShuffling === null) {
370
+ this.cachedCurrentShuffling = this.binding.getCurrentShuffling();
382
371
  }
383
- return this._getCurrentShuffling;
372
+ return this.cachedCurrentShuffling;
384
373
  }
385
374
 
386
375
  getNextShuffling(): EpochShuffling {
387
- if (this._getNextShuffling === null) {
388
- this._getNextShuffling = this.binding.getNextShuffling();
376
+ if (this.cachedNextShuffling === null) {
377
+ this.cachedNextShuffling = this.binding.getNextShuffling();
389
378
  }
390
- return this._getNextShuffling;
379
+ return this.cachedNextShuffling;
391
380
  }
392
381
 
393
382
  // Proposer shuffling
394
383
 
395
384
  get previousProposers(): ValidatorIndex[] | null {
396
- if (this._previousProposers === undefined) {
397
- this._previousProposers = this.binding.previousProposers;
385
+ if (this.cachedPreviousProposers === undefined) {
386
+ this.cachedPreviousProposers = this.binding.previousProposers;
398
387
  }
399
- return this._previousProposers;
388
+ return this.cachedPreviousProposers;
400
389
  }
401
390
 
402
391
  get currentProposers(): ValidatorIndex[] {
403
- if (this._currentProposers === null) {
404
- this._currentProposers = this.binding.currentProposers;
392
+ if (this.cachedCurrentProposers === null) {
393
+ this.cachedCurrentProposers = this.binding.currentProposers;
405
394
  }
406
- return this._currentProposers;
395
+ return this.cachedCurrentProposers;
407
396
  }
408
397
 
409
398
  get nextProposers(): ValidatorIndex[] {
410
- if (this._nextProposers === null) {
411
- this._nextProposers = this.binding.nextProposers;
399
+ if (this.cachedNextProposers === null) {
400
+ this.cachedNextProposers = this.binding.nextProposers;
412
401
  }
413
- return this._nextProposers;
402
+ return this.cachedNextProposers;
414
403
  }
415
404
 
416
405
  getBeaconProposer(slot: Slot): ValidatorIndex {
417
- let cached = this._getBeaconProposer.get(slot);
406
+ let cached = this.cachedBeaconProposer.get(slot);
418
407
  if (cached === undefined) {
419
408
  cached = this.binding.getBeaconProposer(slot);
420
- this._getBeaconProposer.set(slot, cached);
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._effectiveBalanceIncrements === null) {
429
- this._effectiveBalanceIncrements = this.binding.effectiveBalanceIncrements;
417
+ if (this.cachedEffectiveBalanceIncrements === null) {
418
+ this.cachedEffectiveBalanceIncrements = this.binding.effectiveBalanceIncrements;
430
419
  }
431
- return this._effectiveBalanceIncrements;
420
+ return this.cachedEffectiveBalanceIncrements;
432
421
  }
433
422
 
434
423
  getEffectiveBalanceIncrementsZeroInactive(): EffectiveBalanceIncrements {
435
- if (this._getEffectiveBalanceIncrementsZeroInactive === null) {
436
- this._getEffectiveBalanceIncrementsZeroInactive = this.binding.getEffectiveBalanceIncrementsZeroInactive();
424
+ if (this.cachedEffectiveBalanceIncrementsZeroInactive === null) {
425
+ this.cachedEffectiveBalanceIncrementsZeroInactive = this.binding.getEffectiveBalanceIncrementsZeroInactive();
437
426
  }
438
- return this._getEffectiveBalanceIncrementsZeroInactive;
427
+ return this.cachedEffectiveBalanceIncrementsZeroInactive;
439
428
  }
440
429
 
441
430
  getBalance(index: number): number {
442
- let cached = this._getBalance.get(index);
431
+ let cached = this.cachedBalance.get(index);
443
432
  if (cached === undefined) {
444
433
  cached = this.binding.getBalance(index);
445
- this._getBalance.set(index, cached);
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._getValidator.get(index);
440
+ let cached = this.cachedValidator.get(index);
452
441
  if (cached === undefined) {
453
442
  cached = this.binding.getValidator(index);
454
- this._getValidator.set(index, cached);
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._validatorCount === null) {
465
- this._validatorCount = this.binding.validatorCount;
453
+ if (this.cachedValidatorCount === null) {
454
+ this.cachedValidatorCount = this.binding.validatorCount;
466
455
  }
467
- return this._validatorCount;
456
+ return this.cachedValidatorCount;
468
457
  }
469
458
 
470
459
  get activeValidatorCount(): number {
471
- if (this._activeValidatorCount === null) {
472
- this._activeValidatorCount = this.binding.activeValidatorCount;
460
+ if (this.cachedActiveValidatorCount === null) {
461
+ this.cachedActiveValidatorCount = this.binding.activeValidatorCount;
473
462
  }
474
- return this._activeValidatorCount;
463
+ return this.cachedActiveValidatorCount;
475
464
  }
476
465
 
477
466
  getAllValidators(): phase0.Validator[] {
478
- if (this._getAllValidators === null) {
479
- this._getAllValidators = this.binding.getAllValidators();
467
+ if (this.cachedAllValidators === null) {
468
+ this.cachedAllValidators = this.binding.getAllValidators();
480
469
  }
481
- return this._getAllValidators;
470
+ return this.cachedAllValidators;
482
471
  }
483
472
 
484
473
  getAllBalances(): number[] {
485
- if (this._getAllBalances === null) {
486
- this._getAllBalances = this.binding.getAllBalances();
474
+ if (this.cachedAllBalances === null) {
475
+ this.cachedAllBalances = this.binding.getAllBalances();
487
476
  }
488
- return this._getAllBalances;
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
- return this.binding.computeBlockRewards(block, proposerRewards);
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._getLatestWeakSubjectivityCheckpointEpoch === null) {
507
- this._getLatestWeakSubjectivityCheckpointEpoch = this.binding.getLatestWeakSubjectivityCheckpointEpoch();
506
+ if (this.cachedLatestWeakSubjectivityCheckpointEpoch === null) {
507
+ this.cachedLatestWeakSubjectivityCheckpointEpoch = this.binding.getLatestWeakSubjectivityCheckpointEpoch();
508
508
  }
509
- return this._getLatestWeakSubjectivityCheckpointEpoch;
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._getFinalizedRootProof === null) {
529
- this._getFinalizedRootProof = this.binding.getFinalizedRootProof();
528
+ if (this.cachedFinalizedRootProof === null) {
529
+ this.cachedFinalizedRootProof = this.binding.getFinalizedRootProof();
530
530
  }
531
- return this._getFinalizedRootProof;
531
+ return this.cachedFinalizedRootProof;
532
532
  }
533
533
 
534
534
  getSingleProof(gindex: bigint): Uint8Array[] {
535
- let cached = this._getSingleProof.get(gindex);
535
+ let cached = this.cachedSingleProof.get(gindex);
536
536
  if (cached === undefined) {
537
537
  cached = this.binding.getSingleProof(gindex);
538
- this._getSingleProof.set(gindex, cached);
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._computeUnrealizedCheckpoints === null) {
554
- this._computeUnrealizedCheckpoints = this.binding.computeUnrealizedCheckpoints();
553
+ if (this.cachedUnrealizedCheckpoints === null) {
554
+ this.cachedUnrealizedCheckpoints = this.binding.computeUnrealizedCheckpoints();
555
555
  }
556
- return this._computeUnrealizedCheckpoints;
556
+ return this.cachedUnrealizedCheckpoints;
557
557
  }
558
558
 
559
559
  computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader} {
560
- if (this._computeAnchorCheckpoint === null) {
561
- this._computeAnchorCheckpoint = this.binding.computeAnchorCheckpoint();
560
+ if (this.cachedAnchorCheckpoint === null) {
561
+ this.cachedAnchorCheckpoint = this.binding.computeAnchorCheckpoint();
562
562
  }
563
- return this._computeAnchorCheckpoint;
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._createdWithTransferCache === null) {
578
- this._createdWithTransferCache = this.binding.createdWithTransferCache;
577
+ if (this.cachedCreatedWithTransferCache === null) {
578
+ this.cachedCreatedWithTransferCache = this.binding.createdWithTransferCache;
579
579
  }
580
- return this._createdWithTransferCache;
580
+ return this.cachedCreatedWithTransferCache;
581
581
  }
582
582
 
583
583
  isStateValidatorsNodesPopulated(): boolean {
584
- if (this._isStateValidatorsNodesPopulated === null) {
585
- this._isStateValidatorsNodesPopulated = this.binding.isStateValidatorsNodesPopulated();
584
+ if (this.cachedIsStateValidatorsNodesPopulated === null) {
585
+ this.cachedIsStateValidatorsNodesPopulated = this.binding.isStateValidatorsNodesPopulated();
586
586
  }
587
- return this._isStateValidatorsNodesPopulated;
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._toValue === null) {
602
- this._toValue = this.binding.toValue();
601
+ if (this.cachedValue === null) {
602
+ this.cachedValue = this.binding.toValue();
603
603
  }
604
- return this._toValue;
604
+ return this.cachedValue;
605
605
  }
606
606
 
607
607
  serialize(): Uint8Array {
608
- if (this._serialize === null) {
609
- this._serialize = this.binding.serialize();
608
+ if (this.cachedSerialized === null) {
609
+ this.cachedSerialized = this.binding.serialize();
610
610
  }
611
- return this._serialize;
611
+ return this.cachedSerialized;
612
612
  }
613
613
 
614
614
  serializedSize(): number {
615
- if (this._serializedSize === null) {
616
- this._serializedSize = this.binding.serializedSize();
615
+ if (this.cachedSerializedSize === null) {
616
+ this.cachedSerializedSize = this.binding.serializedSize();
617
617
  }
618
- return this._serializedSize;
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._serializeValidators === null) {
627
- this._serializeValidators = this.binding.serializeValidators();
626
+ if (this.cachedSerializedValidators === null) {
627
+ this.cachedSerializedValidators = this.binding.serializeValidators();
628
628
  }
629
- return this._serializeValidators;
629
+ return this.cachedSerializedValidators;
630
630
  }
631
631
 
632
632
  serializedValidatorsSize(): number {
633
- if (this._serializedValidatorsSize === null) {
634
- this._serializedValidatorsSize = this.binding.serializedValidatorsSize();
633
+ if (this.cachedSerializedValidatorsSize === null) {
634
+ this.cachedSerializedValidatorsSize = this.binding.serializedValidatorsSize();
635
635
  }
636
- return this._serializedValidatorsSize;
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._hashTreeRoot === null) {
645
- this._hashTreeRoot = this.binding.hashTreeRoot();
644
+ if (this.cachedHashTreeRoot === null) {
645
+ this.cachedHashTreeRoot = this.binding.hashTreeRoot();
646
646
  }
647
- return this._hashTreeRoot;
647
+ return this.cachedHashTreeRoot;
648
648
  }
649
649
 
650
650
  // State transition
651
651
 
652
- computeNewStateRoot(input: ComputeNewStateRootInput, modules: StateTransitionModules): ComputeNewStateRootResult {
653
- const postState = new NativeBeaconStateView(
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
- signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock,
658
+ {block, ssz}: BlockSTFInput,
661
659
  options: StateTransitionOpts,
662
- modules: StateTransitionModules
660
+ _modules: StateTransitionModules
663
661
  ): IBeaconStateView {
664
- return new NativeBeaconStateView(this.binding.stateTransition(signedBlock, options, modules));
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}, modules?: StateTransitionModules): IBeaconStateView {
668
- return new NativeBeaconStateView(this.binding.processSlots(slot, opts, modules));
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._previousEpochParticipation === null) {
675
- this._previousEpochParticipation = this.binding.previousEpochParticipation;
680
+ if (this.cachedPreviousEpochParticipation === null) {
681
+ this.cachedPreviousEpochParticipation = this.binding.previousEpochParticipation;
676
682
  }
677
- return this._previousEpochParticipation;
683
+ return this.cachedPreviousEpochParticipation;
678
684
  }
679
685
 
680
686
  get currentEpochParticipation(): Uint8Array {
681
- if (this._currentEpochParticipation === null) {
682
- this._currentEpochParticipation = this.binding.currentEpochParticipation;
687
+ if (this.cachedCurrentEpochParticipation === null) {
688
+ this.cachedCurrentEpochParticipation = this.binding.currentEpochParticipation;
683
689
  }
684
- return this._currentEpochParticipation;
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._currentSyncCommittee === null) {
697
- this._currentSyncCommittee = this.binding.currentSyncCommittee;
702
+ if (this.cachedCurrentSyncCommittee === null) {
703
+ this.cachedCurrentSyncCommittee = this.binding.currentSyncCommittee;
698
704
  }
699
- return this._currentSyncCommittee;
705
+ return this.cachedCurrentSyncCommittee;
700
706
  }
701
707
 
702
708
  get nextSyncCommittee(): altair.SyncCommittee {
703
- if (this._nextSyncCommittee === null) {
704
- this._nextSyncCommittee = this.binding.nextSyncCommittee;
709
+ if (this.cachedNextSyncCommittee === null) {
710
+ this.cachedNextSyncCommittee = this.binding.nextSyncCommittee;
705
711
  }
706
- return this._nextSyncCommittee;
712
+ return this.cachedNextSyncCommittee;
707
713
  }
708
714
 
709
715
  get currentSyncCommitteeIndexed(): SyncCommitteeCache {
710
- if (this._currentSyncCommitteeIndexed === null) {
711
- this._currentSyncCommitteeIndexed = this.binding.currentSyncCommitteeIndexed;
716
+ if (this.cachedCurrentSyncCommitteeIndexed === null) {
717
+ this.cachedCurrentSyncCommitteeIndexed = this.binding.currentSyncCommitteeIndexed;
712
718
  }
713
- return this._currentSyncCommitteeIndexed;
719
+ return this.cachedCurrentSyncCommitteeIndexed;
714
720
  }
715
721
 
716
722
  get syncProposerReward(): number {
717
- if (this._syncProposerReward === null) {
718
- this._syncProposerReward = this.binding.syncProposerReward;
723
+ if (this.cachedSyncProposerReward === null) {
724
+ this.cachedSyncProposerReward = this.binding.syncProposerReward;
719
725
  }
720
- return this._syncProposerReward;
726
+ return this.cachedSyncProposerReward;
721
727
  }
722
728
 
723
729
  getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache {
724
- let cached = this._getIndexedSyncCommitteeAtEpoch.get(epoch);
730
+ let cached = this.cachedIndexedSyncCommitteeAtEpoch.get(epoch);
725
731
  if (cached === undefined) {
726
732
  cached = this.binding.getIndexedSyncCommitteeAtEpoch(epoch);
727
- this._getIndexedSyncCommitteeAtEpoch.set(epoch, cached);
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._getIndexedSyncCommittee.get(slot);
739
+ let cached = this.cachedIndexedSyncCommittee.get(slot);
734
740
  if (cached === undefined) {
735
741
  cached = this.binding.getIndexedSyncCommittee(slot);
736
- this._getIndexedSyncCommittee.set(slot, cached);
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._getSyncCommitteesWitness === null) {
750
- this._getSyncCommitteesWitness = this.binding.getSyncCommitteesWitness();
755
+ if (this.cachedSyncCommitteesWitness === null) {
756
+ this.cachedSyncCommitteesWitness = this.binding.getSyncCommitteesWitness();
751
757
  }
752
- return this._getSyncCommitteesWitness;
758
+ return this.cachedSyncCommitteesWitness;
753
759
  }
754
760
 
755
761
  // ─── bellatrix ───────────────────────────────────────────────────────────
756
762
 
757
763
  get latestExecutionPayloadHeader(): ExecutionPayloadHeader {
758
- if (this._latestExecutionPayloadHeader === null) {
759
- this._latestExecutionPayloadHeader = this.binding.latestExecutionPayloadHeader;
764
+ if (this.cachedLatestExecutionPayloadHeader === null) {
765
+ this.cachedLatestExecutionPayloadHeader = this.binding.latestExecutionPayloadHeader;
760
766
  }
761
- return this._latestExecutionPayloadHeader;
767
+ return this.cachedLatestExecutionPayloadHeader;
762
768
  }
763
769
 
764
770
  get payloadBlockNumber(): number {
765
- if (this._payloadBlockNumber === null) {
766
- this._payloadBlockNumber = this.binding.payloadBlockNumber;
771
+ if (this.cachedPayloadBlockNumber === null) {
772
+ this.cachedPayloadBlockNumber = this.binding.payloadBlockNumber;
767
773
  }
768
- return this._payloadBlockNumber;
774
+ return this.cachedPayloadBlockNumber;
769
775
  }
770
776
 
771
777
  get isExecutionStateType(): boolean {
772
- if (this._isExecutionStateType === null) {
773
- this._isExecutionStateType = this.binding.isExecutionStateType;
778
+ if (this.cachedIsExecutionStateType === null) {
779
+ this.cachedIsExecutionStateType = this.binding.isExecutionStateType;
774
780
  }
775
- return this._isExecutionStateType;
781
+ return this.cachedIsExecutionStateType;
776
782
  }
777
783
 
778
784
  get isMergeTransitionComplete(): boolean {
779
- if (this._isMergeTransitionComplete === null) {
780
- this._isMergeTransitionComplete = this.binding.isMergeTransitionComplete;
785
+ if (this.cachedIsMergeTransitionComplete === null) {
786
+ this.cachedIsMergeTransitionComplete = this.binding.isMergeTransitionComplete;
781
787
  }
782
- return this._isMergeTransitionComplete;
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._historicalSummaries === null) {
793
- this._historicalSummaries = this.binding.historicalSummaries;
798
+ if (this.cachedHistoricalSummaries === null) {
799
+ this.cachedHistoricalSummaries = this.binding.historicalSummaries;
794
800
  }
795
- return this._historicalSummaries;
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._getExpectedWithdrawals === null) {
806
- this._getExpectedWithdrawals = this.binding.getExpectedWithdrawals();
811
+ if (this.cachedExpectedWithdrawals === null) {
812
+ this.cachedExpectedWithdrawals = this.binding.getExpectedWithdrawals();
807
813
  }
808
- return this._getExpectedWithdrawals;
814
+ return this.cachedExpectedWithdrawals;
809
815
  }
810
816
 
811
817
  // ─── electra ─────────────────────────────────────────────────────────────
812
818
 
813
819
  get pendingDeposits(): electra.PendingDeposits {
814
- if (this._pendingDeposits === null) {
815
- this._pendingDeposits = this.binding.pendingDeposits;
820
+ if (this.cachedPendingDeposits === null) {
821
+ this.cachedPendingDeposits = ssz.electra.PendingDeposits.deserialize(this.binding.pendingDeposits);
816
822
  }
817
- return this._pendingDeposits;
823
+ return this.cachedPendingDeposits;
818
824
  }
819
825
 
820
826
  get pendingDepositsCount(): number {
821
- if (this._pendingDepositsCount === null) {
822
- this._pendingDepositsCount = this.binding.pendingDepositsCount;
827
+ if (this.cachedPendingDepositsCount === null) {
828
+ this.cachedPendingDepositsCount = this.binding.pendingDepositsCount;
823
829
  }
824
- return this._pendingDepositsCount;
830
+ return this.cachedPendingDepositsCount;
825
831
  }
826
832
 
827
833
  get pendingPartialWithdrawals(): electra.PendingPartialWithdrawals {
828
- if (this._pendingPartialWithdrawals === null) {
829
- this._pendingPartialWithdrawals = this.binding.pendingPartialWithdrawals;
834
+ if (this.cachedPendingPartialWithdrawals === null) {
835
+ this.cachedPendingPartialWithdrawals = ssz.electra.PendingPartialWithdrawals.deserialize(
836
+ this.binding.pendingPartialWithdrawals
837
+ );
830
838
  }
831
- return this._pendingPartialWithdrawals;
839
+ return this.cachedPendingPartialWithdrawals;
832
840
  }
833
841
 
834
842
  get pendingPartialWithdrawalsCount(): number {
835
- if (this._pendingPartialWithdrawalsCount === null) {
836
- this._pendingPartialWithdrawalsCount = this.binding.pendingPartialWithdrawalsCount;
843
+ if (this.cachedPendingPartialWithdrawalsCount === null) {
844
+ this.cachedPendingPartialWithdrawalsCount = this.binding.pendingPartialWithdrawalsCount;
837
845
  }
838
- return this._pendingPartialWithdrawalsCount;
846
+ return this.cachedPendingPartialWithdrawalsCount;
839
847
  }
840
848
 
841
849
  get pendingConsolidations(): electra.PendingConsolidations {
842
- if (this._pendingConsolidations === null) {
843
- this._pendingConsolidations = this.binding.pendingConsolidations;
850
+ if (this.cachedPendingConsolidations === null) {
851
+ this.cachedPendingConsolidations = ssz.electra.PendingConsolidations.deserialize(
852
+ this.binding.pendingConsolidations
853
+ );
844
854
  }
845
- return this._pendingConsolidations;
855
+ return this.cachedPendingConsolidations;
846
856
  }
847
857
 
848
858
  get pendingConsolidationsCount(): number {
849
- if (this._pendingConsolidationsCount === null) {
850
- this._pendingConsolidationsCount = this.binding.pendingConsolidationsCount;
859
+ if (this.cachedPendingConsolidationsCount === null) {
860
+ this.cachedPendingConsolidationsCount = this.binding.pendingConsolidationsCount;
851
861
  }
852
- return this._pendingConsolidationsCount;
862
+ return this.cachedPendingConsolidationsCount;
853
863
  }
854
864
 
855
865
  // ─── fulu ────────────────────────────────────────────────────────────────
856
866
 
857
867
  get proposerLookahead(): fulu.ProposerLookahead {
858
- if (this._proposerLookahead === null) {
859
- this._proposerLookahead = this.binding.proposerLookahead;
868
+ if (this.cachedProposerLookahead === null) {
869
+ this.cachedProposerLookahead = Array.from(this.binding.proposerLookahead);
860
870
  }
861
- return this._proposerLookahead;
871
+ return this.cachedProposerLookahead;
862
872
  }
863
873
 
864
- preVerifyBuilderDepositsPreGloas(maxBuilderDeposits: number, maxDurationMs: number): PreVerifyBuilderDepositsResult {
865
- return this.binding.preVerifyBuilderDepositsPreGloas(maxBuilderDeposits, maxDurationMs);
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
- this.binding.clearPreGloasBuilderDepositCache();
882
+ throw new Error("NativeBeaconStateView does not support Gloas");
870
883
  }
871
884
 
872
885
  // ─── gloas ───────────────────────────────────────────────────────────────
873
886
 
874
887
  get latestBlockHash(): Bytes32 {
875
- if (this._latestBlockHash === null) {
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
- if (this._latestExecutionPayloadBid === null) {
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
- if (this._payloadExpectedWithdrawals === null) {
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
- if (this._builderPendingPayments === null) {
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
- if (this._builderPendingWithdrawals === null) {
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(index: BuilderIndex): gloas.Builder {
912
- let cached = this._getBuilder.get(index);
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
- if (this._getBuildersLength === null) {
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(builderIndex: BuilderIndex, bidAmount: number): boolean {
928
- return this.binding.canBuilderCoverBid(builderIndex, bidAmount);
915
+ canBuilderCoverBid(_builderIndex: BuilderIndex, _bidAmount: number): boolean {
916
+ throw new Error("NativeBeaconStateView does not support Gloas");
929
917
  }
930
918
 
931
- getEpochPTCs(epoch: Epoch): Uint32Array[] {
932
- let cached = this._getEpochPTCs.get(epoch);
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(slot: Slot): Uint32Array {
941
- return this.binding.getPayloadTimelinessCommittee(slot);
923
+ getPayloadTimelinessCommittee(_slot: Slot): Uint32Array {
924
+ throw new Error("NativeBeaconStateView does not support Gloas");
942
925
  }
943
926
 
944
- getIndicesInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number[] {
945
- return this.binding.getIndicesInPayloadTimelinessCommittee(validatorIndex, slot);
927
+ getIndicesInPayloadTimelinessCommittee(_validatorIndex: ValidatorIndex, _slot: Slot): number[] {
928
+ throw new Error("NativeBeaconStateView does not support Gloas");
946
929
  }
947
930
 
948
- withParentPayloadApplied(executionRequests: gloas.ExecutionRequests): IBeaconStateViewGloas {
949
- const view = new NativeBeaconStateView(this.binding.withParentPayloadApplied(executionRequests));
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
  }