@lodestar/state-transition 1.42.0-dev.d32f5153b6 → 1.42.0-dev.d4d0b21dfe

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 (34) hide show
  1. package/lib/index.d.ts +4 -2
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +4 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -1
  6. package/lib/signatureSets/executionPayloadEnvelope.js +4 -0
  7. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
  8. package/lib/signatureSets/voluntaryExits.d.ts +2 -2
  9. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  10. package/lib/signatureSets/voluntaryExits.js +4 -0
  11. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  12. package/lib/stateTransition.d.ts +1 -1
  13. package/lib/stateTransition.d.ts.map +1 -1
  14. package/lib/stateTransition.js +1 -1
  15. package/lib/stateTransition.js.map +1 -1
  16. package/lib/stateView/beaconStateView.d.ts +6 -2
  17. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  18. package/lib/stateView/beaconStateView.js +18 -5
  19. package/lib/stateView/beaconStateView.js.map +1 -1
  20. package/lib/stateView/interface.d.ts +98 -51
  21. package/lib/stateView/interface.d.ts.map +1 -1
  22. package/lib/stateView/interface.js +22 -1
  23. package/lib/stateView/interface.js.map +1 -1
  24. package/lib/util/gloas.d.ts +2 -1
  25. package/lib/util/gloas.d.ts.map +1 -1
  26. package/lib/util/gloas.js.map +1 -1
  27. package/package.json +7 -7
  28. package/src/index.ts +20 -2
  29. package/src/signatureSets/executionPayloadEnvelope.ts +5 -1
  30. package/src/signatureSets/voluntaryExits.ts +5 -2
  31. package/src/stateTransition.ts +1 -1
  32. package/src/stateView/beaconStateView.ts +26 -8
  33. package/src/stateView/interface.ts +143 -73
  34. package/src/util/gloas.ts +2 -1
@@ -1,5 +1,22 @@
1
1
  import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
2
2
  import {BitArray, ByteViews} from "@chainsafe/ssz";
3
+ import {
4
+ ForkName,
5
+ ForkPostAltair,
6
+ ForkPostBellatrix,
7
+ ForkPostCapella,
8
+ ForkPostDeneb,
9
+ ForkPostElectra,
10
+ ForkPostFulu,
11
+ ForkPostGloas,
12
+ isForkPostAltair,
13
+ isForkPostBellatrix,
14
+ isForkPostCapella,
15
+ isForkPostDeneb,
16
+ isForkPostElectra,
17
+ isForkPostFulu,
18
+ isForkPostGloas,
19
+ } from "@lodestar/params";
3
20
  import {
4
21
  BeaconBlock,
5
22
  BeaconState,
@@ -41,6 +58,7 @@ export interface IBeaconStateView {
41
58
  // State access
42
59
 
43
60
  // phase0
61
+ forkName: ForkName;
44
62
  slot: Slot;
45
63
  fork: Fork;
46
64
  epoch: Epoch;
@@ -56,50 +74,6 @@ export interface IBeaconStateView {
56
74
  getStateRootAtSlot(slot: Slot): Root;
57
75
  getRandaoMix(epoch: Epoch): Bytes32;
58
76
 
59
- // altair
60
- previousEpochParticipation: Uint8Array;
61
- currentEpochParticipation: Uint8Array;
62
- getPreviousEpochParticipation(validatorIndex: ValidatorIndex): number;
63
- getCurrentEpochParticipation(validatorIndex: ValidatorIndex): number;
64
-
65
- // bellatrix
66
- latestExecutionPayloadHeader: ExecutionPayloadHeader;
67
- /**
68
- * Cross-fork accessor for the execution block hash of the most recently included payload.
69
- * Pre-gloas: returns latestExecutionPayloadHeader.blockHash (bellatrix–fulu).
70
- * Gloas+: returns the dedicated latestBlockHash state field (EIP-7732).
71
- * Throws before bellatrix.
72
- */
73
- latestBlockHash: Bytes32;
74
- /**
75
- * The execution block number of the most recently included payload.
76
- * Named payloadBlockNumber (not latestBlockNumber) to mirror ExecutionPayloadHeader.blockNumber pre-gloas.
77
- * Only available from bellatrix through fulu — not tracked on BeaconState in gloas+ (EIP-7732).
78
- * Throws before bellatrix and from gloas onwards.
79
- */
80
- payloadBlockNumber: number;
81
-
82
- // capella
83
- historicalSummaries: capella.HistoricalSummaries;
84
-
85
- // electra
86
- pendingDeposits: electra.PendingDeposits;
87
- pendingDepositsCount: number;
88
- pendingPartialWithdrawals: electra.PendingPartialWithdrawals;
89
- pendingPartialWithdrawalsCount: number;
90
- pendingConsolidations: electra.PendingConsolidations;
91
- pendingConsolidationsCount: number;
92
-
93
- // fulu
94
- proposerLookahead: fulu.ProposerLookahead;
95
-
96
- // gloas
97
- executionPayloadAvailability: BitArray;
98
- latestExecutionPayloadBid: ExecutionPayloadBid;
99
- getBuilder(index: BuilderIndex): gloas.Builder;
100
- canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
101
- getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number;
102
-
103
77
  // Shuffling and committees
104
78
  getShufflingAtEpoch(epoch: Epoch): EpochShuffling;
105
79
  // Decision roots
@@ -117,15 +91,6 @@ export interface IBeaconStateView {
117
91
  nextProposers: ValidatorIndex[];
118
92
  getBeaconProposer(slot: Slot): ValidatorIndex;
119
93
 
120
- // Sync committees
121
- currentSyncCommittee: altair.SyncCommittee;
122
- nextSyncCommittee: altair.SyncCommittee;
123
- currentSyncCommitteeIndexed: SyncCommitteeCache;
124
- syncProposerReward: number;
125
- getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
126
- /** Get indexed sync committee with slot+1 offset for duty lookups */
127
- getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache;
128
-
129
94
  // Validators and balances
130
95
  effectiveBalanceIncrements: EffectiveBalanceIncrements;
131
96
  getEffectiveBalanceIncrementsZeroInactive(): EffectiveBalanceIncrements;
@@ -140,29 +105,10 @@ export interface IBeaconStateView {
140
105
  getAllValidators(): phase0.Validator[];
141
106
  getAllBalances(): number[];
142
107
 
143
- // Merge
144
- isExecutionStateType: boolean;
145
- isMergeTransitionComplete: boolean;
146
- // TODO this should go away (or rather only need block)
147
- isExecutionEnabled(block: BeaconBlock | BlindedBeaconBlock): boolean;
148
-
149
- // Block production
150
- getExpectedWithdrawals(): {
151
- expectedWithdrawals: capella.Withdrawal[];
152
- processedBuilderWithdrawalsCount: number;
153
- processedPartialWithdrawalsCount: number;
154
- processedBuildersSweepCount: number;
155
- processedValidatorSweepCount: number;
156
- };
157
-
158
108
  // API
159
109
  proposerRewards: RewardCache;
160
110
  computeBlockRewards(block: BeaconBlock, proposerRewards?: RewardCache): Promise<rewards.BlockRewards>;
161
111
  computeAttestationsRewards(validatorIds?: (ValidatorIndex | string)[]): Promise<rewards.AttestationsRewards>;
162
- computeSyncCommitteeRewards(
163
- block: BeaconBlock,
164
- validatorIds: (ValidatorIndex | string)[]
165
- ): Promise<rewards.SyncCommitteeRewards>;
166
112
  getLatestWeakSubjectivityCheckpointEpoch(): Epoch;
167
113
 
168
114
  // Validation
@@ -174,7 +120,6 @@ export interface IBeaconStateView {
174
120
 
175
121
  // Proofs
176
122
  getFinalizedRootProof(): Uint8Array[];
177
- getSyncCommitteesWitness(): SyncCommitteeWitness;
178
123
  getSingleProof(gindex: bigint): Uint8Array[];
179
124
  createMultiProof(descriptor: Uint8Array): CompactMultiProof;
180
125
 
@@ -215,8 +160,133 @@ export interface IBeaconStateView {
215
160
  epochTransitionCacheOpts?: EpochTransitionCacheOpts & {dontTransferCache?: boolean},
216
161
  modules?: StateTransitionModules
217
162
  ): IBeaconStateView;
163
+ }
164
+
165
+ /** Altair+ state fields — use isStatePostAltair() guard */
166
+ export interface IBeaconStateViewAltair extends IBeaconStateView {
167
+ forkName: ForkPostAltair;
168
+ previousEpochParticipation: Uint8Array;
169
+ currentEpochParticipation: Uint8Array;
170
+ getPreviousEpochParticipation(validatorIndex: ValidatorIndex): number;
171
+ getCurrentEpochParticipation(validatorIndex: ValidatorIndex): number;
172
+ currentSyncCommittee: altair.SyncCommittee;
173
+ nextSyncCommittee: altair.SyncCommittee;
174
+ currentSyncCommitteeIndexed: SyncCommitteeCache;
175
+ syncProposerReward: number;
176
+ getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
177
+ /** Get indexed sync committee with slot+1 offset for duty lookups */
178
+ getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache;
179
+ computeSyncCommitteeRewards(
180
+ block: BeaconBlock,
181
+ validatorIds: (ValidatorIndex | string)[]
182
+ ): Promise<rewards.SyncCommitteeRewards>;
183
+ getSyncCommitteesWitness(): SyncCommitteeWitness;
184
+ }
185
+
186
+ /** Bellatrix+ state fields — use isStatePostBellatrix() guard */
187
+ export interface IBeaconStateViewBellatrix extends IBeaconStateViewAltair {
188
+ forkName: ForkPostBellatrix;
189
+ latestExecutionPayloadHeader: ExecutionPayloadHeader;
190
+ /**
191
+ * Cross-fork accessor for the execution block hash of the most recently included payload.
192
+ * Pre-gloas: returns latestExecutionPayloadHeader.blockHash (bellatrix–fulu).
193
+ * Gloas+: returns the dedicated latestBlockHash state field (EIP-7732).
194
+ * Throws before bellatrix.
195
+ */
196
+ latestBlockHash: Bytes32;
197
+ /**
198
+ * The execution block number of the most recently included payload.
199
+ * Named payloadBlockNumber (not latestBlockNumber) to mirror ExecutionPayloadHeader.blockNumber pre-gloas.
200
+ * Only available from bellatrix through fulu — not tracked on BeaconState in gloas+ (EIP-7732).
201
+ * Throws before bellatrix and from gloas onwards.
202
+ */
203
+ payloadBlockNumber: number;
204
+ isExecutionStateType: boolean;
205
+ isMergeTransitionComplete: boolean;
206
+ isExecutionEnabled(block: BeaconBlock | BlindedBeaconBlock): boolean;
207
+ }
208
+
209
+ /** Capella+ state fields — use isStatePostCapella() guard */
210
+ export interface IBeaconStateViewCapella extends IBeaconStateViewBellatrix {
211
+ forkName: ForkPostCapella;
212
+ historicalSummaries: capella.HistoricalSummaries;
213
+ getExpectedWithdrawals(): {
214
+ expectedWithdrawals: capella.Withdrawal[];
215
+ processedBuilderWithdrawalsCount: number;
216
+ processedPartialWithdrawalsCount: number;
217
+ processedBuildersSweepCount: number;
218
+ processedValidatorSweepCount: number;
219
+ };
220
+ }
221
+
222
+ /** Deneb+ state — no new state-view fields; placeholder for fork completeness and isStatePostDeneb() narrowing */
223
+ export interface IBeaconStateViewDeneb extends IBeaconStateViewCapella {
224
+ forkName: ForkPostDeneb;
225
+ }
226
+
227
+ /** Electra+ state fields — use isStatePostElectra() guard */
228
+ export interface IBeaconStateViewElectra extends IBeaconStateViewDeneb {
229
+ forkName: ForkPostElectra;
230
+ pendingDeposits: electra.PendingDeposits;
231
+ pendingDepositsCount: number;
232
+ pendingPartialWithdrawals: electra.PendingPartialWithdrawals;
233
+ pendingPartialWithdrawalsCount: number;
234
+ pendingConsolidations: electra.PendingConsolidations;
235
+ pendingConsolidationsCount: number;
236
+ }
237
+
238
+ /** Fulu+ state fields — use isStatePostFulu() guard */
239
+ export interface IBeaconStateViewFulu extends IBeaconStateViewElectra {
240
+ forkName: ForkPostFulu;
241
+ proposerLookahead: fulu.ProposerLookahead;
242
+ }
243
+
244
+ /** Gloas+ state fields — use isStatePostGloas() guard */
245
+ export interface IBeaconStateViewGloas extends IBeaconStateViewFulu {
246
+ forkName: ForkPostGloas;
247
+ executionPayloadAvailability: BitArray;
248
+ latestExecutionPayloadBid: ExecutionPayloadBid;
249
+ payloadExpectedWithdrawals: capella.Withdrawal[];
250
+ getBuilder(index: BuilderIndex): gloas.Builder;
251
+ canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
252
+ getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number;
218
253
  processExecutionPayloadEnvelope(
219
254
  signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
220
255
  opts?: ProcessExecutionPayloadEnvelopeOpts
221
256
  ): IBeaconStateView;
222
257
  }
258
+
259
+ /**
260
+ * Type constraint for the concrete BeaconStateView class.
261
+ * Requires all fields from the latest fork interface (IBeaconStateViewGloas) but keeps
262
+ * forkName as ForkName since the class wraps any fork's state.
263
+ * Sub-interfaces retain their narrowed forkName discriminants for caller-side type guards.
264
+ */
265
+ export type IBeaconStateViewLatestFork = Omit<IBeaconStateViewGloas, "forkName"> & {forkName: ForkName};
266
+ export function isStatePostAltair(state: IBeaconStateView): state is IBeaconStateViewAltair {
267
+ return isForkPostAltair(state.forkName);
268
+ }
269
+
270
+ export function isStatePostBellatrix(state: IBeaconStateView): state is IBeaconStateViewBellatrix {
271
+ return isForkPostBellatrix(state.forkName);
272
+ }
273
+
274
+ export function isStatePostCapella(state: IBeaconStateView): state is IBeaconStateViewCapella {
275
+ return isForkPostCapella(state.forkName);
276
+ }
277
+
278
+ export function isStatePostDeneb(state: IBeaconStateView): state is IBeaconStateViewDeneb {
279
+ return isForkPostDeneb(state.forkName);
280
+ }
281
+
282
+ export function isStatePostElectra(state: IBeaconStateView): state is IBeaconStateViewElectra {
283
+ return isForkPostElectra(state.forkName);
284
+ }
285
+
286
+ export function isStatePostFulu(state: IBeaconStateView): state is IBeaconStateViewFulu {
287
+ return isForkPostFulu(state.forkName);
288
+ }
289
+
290
+ export function isStatePostGloas(state: IBeaconStateView): state is IBeaconStateViewGloas {
291
+ return isForkPostGloas(state.forkName);
292
+ }
package/src/util/gloas.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  import {BuilderIndex, Epoch, ValidatorIndex, gloas} from "@lodestar/types";
12
12
  import {AttestationData} from "@lodestar/types/phase0";
13
13
  import {byteArrayEquals} from "@lodestar/utils";
14
+ import {IBeaconStateViewGloas} from "../stateView/interface.js";
14
15
  import {CachedBeaconStateGloas} from "../types.js";
15
16
  import {getBlockRootAtSlot} from "./blockRoot.js";
16
17
  import {computeEpochAtSlot} from "./epoch.js";
@@ -167,6 +168,6 @@ export function isAttestationSameSlotRootCache(rootCache: RootCache, data: Attes
167
168
  return isMatchingBlockRoot && isCurrentBlockRoot;
168
169
  }
169
170
 
170
- export function isParentBlockFull(state: CachedBeaconStateGloas): boolean {
171
+ export function isParentBlockFull(state: CachedBeaconStateGloas | IBeaconStateViewGloas): boolean {
171
172
  return byteArrayEquals(state.latestExecutionPayloadBid.blockHash, state.latestBlockHash);
172
173
  }