@lodestar/state-transition 1.50.0-dev.456b75a81e → 1.50.0-dev.4b00f7bf39

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 (135) hide show
  1. package/lib/block/index.d.ts.map +1 -1
  2. package/lib/block/index.js +1 -1
  3. package/lib/block/index.js.map +1 -1
  4. package/lib/block/indexedBuilderState.d.ts +19 -0
  5. package/lib/block/indexedBuilderState.d.ts.map +1 -0
  6. package/lib/block/indexedBuilderState.js +60 -0
  7. package/lib/block/indexedBuilderState.js.map +1 -0
  8. package/lib/block/processBuilderDepositRequest.d.ts +2 -2
  9. package/lib/block/processBuilderDepositRequest.d.ts.map +1 -1
  10. package/lib/block/processBuilderDepositRequest.js +5 -4
  11. package/lib/block/processBuilderDepositRequest.js.map +1 -1
  12. package/lib/block/processBuilderExitRequest.d.ts +2 -2
  13. package/lib/block/processBuilderExitRequest.d.ts.map +1 -1
  14. package/lib/block/processBuilderExitRequest.js +4 -3
  15. package/lib/block/processBuilderExitRequest.js.map +1 -1
  16. package/lib/block/processDeposit.d.ts +2 -2
  17. package/lib/block/processDeposit.d.ts.map +1 -1
  18. package/lib/block/processDeposit.js.map +1 -1
  19. package/lib/block/processEth1Data.d.ts +3 -3
  20. package/lib/block/processEth1Data.d.ts.map +1 -1
  21. package/lib/block/processEth1Data.js.map +1 -1
  22. package/lib/block/processOperations.d.ts.map +1 -1
  23. package/lib/block/processOperations.js +8 -6
  24. package/lib/block/processOperations.js.map +1 -1
  25. package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
  26. package/lib/block/processParentExecutionPayload.js +23 -18
  27. package/lib/block/processParentExecutionPayload.js.map +1 -1
  28. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  29. package/lib/block/processProposerSlashing.js +0 -23
  30. package/lib/block/processProposerSlashing.js.map +1 -1
  31. package/lib/block/slashValidator.d.ts.map +1 -1
  32. package/lib/block/slashValidator.js +11 -0
  33. package/lib/block/slashValidator.js.map +1 -1
  34. package/lib/cache/stateCache.d.ts +2 -1
  35. package/lib/cache/stateCache.d.ts.map +1 -1
  36. package/lib/cache/stateCache.js.map +1 -1
  37. package/lib/cache/types.d.ts +2 -1
  38. package/lib/cache/types.d.ts.map +1 -1
  39. package/lib/epoch/index.d.ts.map +1 -1
  40. package/lib/epoch/index.js +3 -1
  41. package/lib/epoch/index.js.map +1 -1
  42. package/lib/epoch/processEth1DataReset.d.ts +2 -2
  43. package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
  44. package/lib/epoch/processEth1DataReset.js.map +1 -1
  45. package/lib/epoch/processPendingDeposits.d.ts.map +1 -1
  46. package/lib/epoch/processPendingDeposits.js +8 -4
  47. package/lib/epoch/processPendingDeposits.js.map +1 -1
  48. package/lib/index.d.ts +4 -2
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +2 -0
  51. package/lib/index.js.map +1 -1
  52. package/lib/rewards/attestationsRewards.d.ts.map +1 -1
  53. package/lib/rewards/attestationsRewards.js +8 -1
  54. package/lib/rewards/attestationsRewards.js.map +1 -1
  55. package/lib/signatureSets/index.d.ts.map +1 -1
  56. package/lib/signatureSets/index.js +2 -2
  57. package/lib/signatureSets/index.js.map +1 -1
  58. package/lib/signatureSets/voluntaryExits.d.ts +2 -6
  59. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  60. package/lib/signatureSets/voluntaryExits.js +2 -32
  61. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  62. package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
  63. package/lib/slot/upgradeStateToHeze.js +4 -4
  64. package/lib/slot/upgradeStateToHeze.js.map +1 -1
  65. package/lib/stateView/beaconStateView.d.ts +23 -21
  66. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  67. package/lib/stateView/beaconStateView.js +77 -71
  68. package/lib/stateView/beaconStateView.js.map +1 -1
  69. package/lib/stateView/interface.d.ts +37 -21
  70. package/lib/stateView/interface.d.ts.map +1 -1
  71. package/lib/stateView/interface.js.map +1 -1
  72. package/lib/stateView/nativeBeaconStateView.d.ts +94 -100
  73. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  74. package/lib/stateView/nativeBeaconStateView.js +353 -368
  75. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  76. package/lib/stateView/stateViewFactory.d.ts +6 -5
  77. package/lib/stateView/stateViewFactory.d.ts.map +1 -1
  78. package/lib/stateView/stateViewFactory.js +12 -8
  79. package/lib/stateView/stateViewFactory.js.map +1 -1
  80. package/lib/types.d.ts +2 -2
  81. package/lib/types.d.ts.map +1 -1
  82. package/lib/util/blindedBlock.d.ts +1 -1
  83. package/lib/util/blindedBlock.d.ts.map +1 -1
  84. package/lib/util/blindedBlock.js +5 -2
  85. package/lib/util/blindedBlock.js.map +1 -1
  86. package/lib/util/clock.d.ts +5 -0
  87. package/lib/util/clock.d.ts.map +1 -1
  88. package/lib/util/clock.js +19 -16
  89. package/lib/util/clock.js.map +1 -1
  90. package/lib/util/deposit.d.ts +2 -2
  91. package/lib/util/deposit.d.ts.map +1 -1
  92. package/lib/util/deposit.js.map +1 -1
  93. package/lib/util/genesis.d.ts.map +1 -1
  94. package/lib/util/genesis.js +46 -23
  95. package/lib/util/genesis.js.map +1 -1
  96. package/lib/util/gloas.d.ts +11 -14
  97. package/lib/util/gloas.d.ts.map +1 -1
  98. package/lib/util/gloas.js +2 -42
  99. package/lib/util/gloas.js.map +1 -1
  100. package/lib/util/slot.d.ts +3 -1
  101. package/lib/util/slot.d.ts.map +1 -1
  102. package/lib/util/slot.js +4 -0
  103. package/lib/util/slot.js.map +1 -1
  104. package/package.json +8 -8
  105. package/src/block/index.ts +4 -3
  106. package/src/block/indexedBuilderState.ts +65 -0
  107. package/src/block/processBuilderDepositRequest.ts +6 -17
  108. package/src/block/processBuilderExitRequest.ts +5 -9
  109. package/src/block/processDeposit.ts +7 -2
  110. package/src/block/processEth1Data.ts +3 -3
  111. package/src/block/processOperations.ts +14 -11
  112. package/src/block/processParentExecutionPayload.ts +27 -23
  113. package/src/block/processProposerSlashing.ts +2 -28
  114. package/src/block/slashValidator.ts +13 -2
  115. package/src/cache/stateCache.ts +2 -0
  116. package/src/cache/types.ts +2 -1
  117. package/src/epoch/index.ts +4 -1
  118. package/src/epoch/processEth1DataReset.ts +2 -2
  119. package/src/epoch/processPendingDeposits.ts +14 -3
  120. package/src/index.ts +6 -1
  121. package/src/rewards/attestationsRewards.ts +8 -1
  122. package/src/signatureSets/index.ts +4 -2
  123. package/src/signatureSets/voluntaryExits.ts +3 -55
  124. package/src/slot/upgradeStateToHeze.ts +6 -4
  125. package/src/stateView/beaconStateView.ts +84 -77
  126. package/src/stateView/interface.ts +65 -21
  127. package/src/stateView/nativeBeaconStateView.ts +368 -375
  128. package/src/stateView/stateViewFactory.ts +21 -12
  129. package/src/types.ts +2 -0
  130. package/src/util/blindedBlock.ts +8 -3
  131. package/src/util/clock.ts +25 -16
  132. package/src/util/deposit.ts +2 -2
  133. package/src/util/genesis.ts +56 -30
  134. package/src/util/gloas.ts +2 -53
  135. package/src/util/slot.ts +6 -1
@@ -14,8 +14,6 @@ import {
14
14
  ExecutionPayloadHeader,
15
15
  Root,
16
16
  RootHex,
17
- SignedBeaconBlock,
18
- SignedBlindedBeaconBlock,
19
17
  Slot,
20
18
  SyncCommittee,
21
19
  ValidatorIndex,
@@ -42,6 +40,7 @@ import {
42
40
  CachedBeaconStateExecutions,
43
41
  CachedBeaconStateFulu,
44
42
  CachedBeaconStateGloas,
43
+ CachedBeaconStatePreHeze,
45
44
  createCachedBeaconState,
46
45
  isStateValidatorsNodesPopulated,
47
46
  } from "../cache/stateCache.js";
@@ -71,7 +70,7 @@ import {getRandaoMix} from "../util/seed.js";
71
70
  import {getLatestWeakSubjectivityCheckpointEpoch} from "../util/weakSubjectivity.js";
72
71
  import {computeNewStateRootStateTransitionOpts, getComputeNewStateRootResult} from "./computeNewStateRoot.js";
73
72
  import {
74
- ComputeNewStateRootInput,
73
+ BlockSTFInput,
75
74
  ComputeNewStateRootResult,
76
75
  IBeaconStateView,
77
76
  IBeaconStateViewGloas,
@@ -83,34 +82,36 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
83
82
  private readonly config: BeaconConfig;
84
83
  // Cached values extracted from the tree
85
84
  // phase0
86
- private _fork: Fork | null = null;
87
- private _latestBlockHeader: phase0.BeaconBlockHeader | null = null;
85
+ private cachedFork: Fork | null = null;
86
+ private cachedLatestBlockHeader: phase0.BeaconBlockHeader | null = null;
88
87
  // altair
89
- private _currentSyncCommittee: SyncCommittee | null = null;
90
- private _nextSyncCommittee: SyncCommittee | null = null;
91
- private _previousEpochParticipation: Uint8Array | null = null;
92
- private _currentEpochParticipation: Uint8Array | null = null;
88
+ private cachedCurrentSyncCommittee: SyncCommittee | null = null;
89
+ private cachedNextSyncCommittee: SyncCommittee | null = null;
90
+ private cachedPreviousEpochParticipation: Uint8Array | null = null;
91
+ private cachedCurrentEpochParticipation: Uint8Array | null = null;
93
92
  // bellatrix
94
- private _latestExecutionPayloadHeader: ExecutionPayloadHeader | null = null;
93
+ private cachedLatestExecutionPayloadHeader: ExecutionPayloadHeader | null = null;
95
94
  // capella
96
- private _historicalSummaries: capella.HistoricalSummaries | null = null;
95
+ private cachedHistoricalSummaries: capella.HistoricalSummaries | null = null;
97
96
  // electra
98
- private _pendingPartialWithdrawals: electra.PendingPartialWithdrawals | null = null;
99
- private _pendingConsolidations: electra.PendingConsolidations | null = null;
100
- private _pendingDeposits: electra.PendingDeposits | null = null;
97
+ private cachedPendingPartialWithdrawals: electra.PendingPartialWithdrawals | null = null;
98
+ private cachedPendingConsolidations: electra.PendingConsolidations | null = null;
99
+ private cachedPendingDeposits: electra.PendingDeposits | null = null;
101
100
  // fulu
102
- private _proposerLookahead: fulu.ProposerLookahead | null = null;
101
+ private cachedProposerLookahead: fulu.ProposerLookahead | null = null;
103
102
  // gloas
104
- private _executionPayloadAvailability: BitArray | null = null;
105
- private _latestExecutionPayloadBid: ExecutionPayloadBid | null = null;
106
- private _payloadExpectedWithdrawals: capella.Withdrawal[] | null = null;
107
- private _builderPendingPayments: gloas.BuilderPendingPayments | null = null;
108
- private _builderPendingWithdrawals: gloas.BuilderPendingWithdrawals | null = null;
103
+ private cachedExecutionPayloadAvailability: BitArray | null = null;
104
+ private cachedLatestExecutionPayloadBid: ExecutionPayloadBid | null = null;
105
+ private cachedPayloadExpectedWithdrawals: capella.Withdrawal[] | null = null;
106
+ private cachedBuilderPendingPayments: gloas.BuilderPendingPayments | null = null;
107
+ private cachedBuilderPendingWithdrawals: gloas.BuilderPendingWithdrawals | null = null;
109
108
 
110
109
  constructor(readonly cachedState: CachedBeaconStateAllForks) {
111
110
  this.config = cachedState.config;
112
111
  }
113
112
 
113
+ release(): void {}
114
+
114
115
  // phase0
115
116
 
116
117
  get forkName(): ForkName {
@@ -126,10 +127,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
126
127
  }
127
128
 
128
129
  get fork(): Fork {
129
- if (this._fork === null) {
130
- this._fork = this.cachedState.fork.toValue();
130
+ if (this.cachedFork === null) {
131
+ this.cachedFork = this.cachedState.fork.toValue();
131
132
  }
132
- return this._fork;
133
+ return this.cachedFork;
133
134
  }
134
135
 
135
136
  get epoch(): number {
@@ -145,14 +146,17 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
145
146
  }
146
147
 
147
148
  get eth1Data(): phase0.Eth1Data {
148
- return this.cachedState.eth1Data;
149
+ if (this.forkSeq >= ForkSeq.heze) {
150
+ throw new Error("eth1Data was removed from the beacon state in Heze");
151
+ }
152
+ return (this.cachedState as CachedBeaconStatePreHeze).eth1Data;
149
153
  }
150
154
 
151
155
  get latestBlockHeader(): phase0.BeaconBlockHeader {
152
- if (this._latestBlockHeader === null) {
153
- this._latestBlockHeader = this.cachedState.latestBlockHeader.toValue();
156
+ if (this.cachedLatestBlockHeader === null) {
157
+ this.cachedLatestBlockHeader = this.cachedState.latestBlockHeader.toValue();
154
158
  }
155
- return this._latestBlockHeader;
159
+ return this.cachedLatestBlockHeader;
156
160
  }
157
161
 
158
162
  get previousJustifiedCheckpoint(): Checkpoint {
@@ -188,13 +192,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
188
192
  throw new Error("previousEpochParticipation is not available before Altair");
189
193
  }
190
194
 
191
- if (this._previousEpochParticipation === null) {
192
- this._previousEpochParticipation = (
195
+ if (this.cachedPreviousEpochParticipation === null) {
196
+ this.cachedPreviousEpochParticipation = (
193
197
  this.cachedState as CachedBeaconStateAltair
194
198
  ).previousEpochParticipation.serialize();
195
199
  }
196
200
 
197
- return this._previousEpochParticipation;
201
+ return this.cachedPreviousEpochParticipation;
198
202
  }
199
203
 
200
204
  // altair
@@ -204,13 +208,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
204
208
  throw new Error("currentEpochParticipation is not available before Altair");
205
209
  }
206
210
 
207
- if (this._currentEpochParticipation === null) {
208
- this._currentEpochParticipation = (
211
+ if (this.cachedCurrentEpochParticipation === null) {
212
+ this.cachedCurrentEpochParticipation = (
209
213
  this.cachedState as CachedBeaconStateAltair
210
214
  ).currentEpochParticipation.serialize();
211
215
  }
212
216
 
213
- return this._currentEpochParticipation;
217
+ return this.cachedCurrentEpochParticipation;
214
218
  }
215
219
 
216
220
  getPreviousEpochParticipation(validatorIndex: ValidatorIndex): number {
@@ -238,13 +242,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
238
242
  throw new Error("latestExecutionPayloadHeader is not available after Gloas");
239
243
  }
240
244
 
241
- if (this._latestExecutionPayloadHeader === null) {
242
- this._latestExecutionPayloadHeader = (
245
+ if (this.cachedLatestExecutionPayloadHeader === null) {
246
+ this.cachedLatestExecutionPayloadHeader = (
243
247
  this.cachedState as CachedBeaconStateExecutions
244
248
  ).latestExecutionPayloadHeader.toValue();
245
249
  }
246
250
 
247
- return this._latestExecutionPayloadHeader;
251
+ return this.cachedLatestExecutionPayloadHeader;
248
252
  }
249
253
 
250
254
  /**
@@ -270,11 +274,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
270
274
  throw new Error("Historical summaries are not supported before Capella");
271
275
  }
272
276
 
273
- if (this._historicalSummaries === null) {
274
- this._historicalSummaries = (this.cachedState as CachedBeaconStateCapella).historicalSummaries.toValue();
277
+ if (this.cachedHistoricalSummaries === null) {
278
+ this.cachedHistoricalSummaries = (this.cachedState as CachedBeaconStateCapella).historicalSummaries.toValue();
275
279
  }
276
280
 
277
- return this._historicalSummaries;
281
+ return this.cachedHistoricalSummaries;
278
282
  }
279
283
 
280
284
  // electra
@@ -284,11 +288,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
284
288
  throw new Error("Pending deposits are not supported before Electra");
285
289
  }
286
290
 
287
- if (this._pendingDeposits === null) {
288
- this._pendingDeposits = (this.cachedState as CachedBeaconStateElectra).pendingDeposits.toValue();
291
+ if (this.cachedPendingDeposits === null) {
292
+ this.cachedPendingDeposits = (this.cachedState as CachedBeaconStateElectra).pendingDeposits.toValue();
289
293
  }
290
294
 
291
- return this._pendingDeposits;
295
+ return this.cachedPendingDeposits;
292
296
  }
293
297
 
294
298
  get pendingDepositsCount(): number {
@@ -304,13 +308,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
304
308
  throw new Error("Pending partial withdrawals are not supported before Electra");
305
309
  }
306
310
 
307
- if (this._pendingPartialWithdrawals === null) {
308
- this._pendingPartialWithdrawals = (
311
+ if (this.cachedPendingPartialWithdrawals === null) {
312
+ this.cachedPendingPartialWithdrawals = (
309
313
  this.cachedState as CachedBeaconStateElectra
310
314
  ).pendingPartialWithdrawals.toValue();
311
315
  }
312
316
 
313
- return this._pendingPartialWithdrawals;
317
+ return this.cachedPendingPartialWithdrawals;
314
318
  }
315
319
 
316
320
  get pendingPartialWithdrawalsCount(): number {
@@ -326,11 +330,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
326
330
  throw new Error("Pending consolidations are not supported before Electra");
327
331
  }
328
332
 
329
- if (this._pendingConsolidations === null) {
330
- this._pendingConsolidations = (this.cachedState as CachedBeaconStateElectra).pendingConsolidations.toValue();
333
+ if (this.cachedPendingConsolidations === null) {
334
+ this.cachedPendingConsolidations = (this.cachedState as CachedBeaconStateElectra).pendingConsolidations.toValue();
331
335
  }
332
336
 
333
- return this._pendingConsolidations;
337
+ return this.cachedPendingConsolidations;
334
338
  }
335
339
 
336
340
  get pendingConsolidationsCount(): number {
@@ -348,11 +352,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
348
352
  throw new Error("Proposer lookahead is not supported before Fulu");
349
353
  }
350
354
 
351
- if (this._proposerLookahead === null) {
352
- this._proposerLookahead = (this.cachedState as CachedBeaconStateFulu).proposerLookahead.toValue();
355
+ if (this.cachedProposerLookahead === null) {
356
+ this.cachedProposerLookahead = (this.cachedState as CachedBeaconStateFulu).proposerLookahead.toValue();
353
357
  }
354
358
 
355
- return this._proposerLookahead;
359
+ return this.cachedProposerLookahead;
356
360
  }
357
361
 
358
362
  preVerifyBuilderDepositsPreGloas(maxBuilderDeposits: number, maxDurationMs: number): PreVerifyBuilderDepositsResult {
@@ -381,13 +385,13 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
381
385
  throw new Error("executionPayloadAvailability is not available before Gloas");
382
386
  }
383
387
 
384
- if (this._executionPayloadAvailability === null) {
385
- this._executionPayloadAvailability = (
388
+ if (this.cachedExecutionPayloadAvailability === null) {
389
+ this.cachedExecutionPayloadAvailability = (
386
390
  this.cachedState as CachedBeaconStateGloas
387
391
  ).executionPayloadAvailability.toValue();
388
392
  }
389
393
 
390
- return this._executionPayloadAvailability;
394
+ return this.cachedExecutionPayloadAvailability;
391
395
  }
392
396
 
393
397
  get latestExecutionPayloadBid(): ExecutionPayloadBid {
@@ -395,12 +399,12 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
395
399
  throw new Error("latestExecutionPayloadBid is not available before Gloas");
396
400
  }
397
401
 
398
- if (this._latestExecutionPayloadBid === null) {
399
- this._latestExecutionPayloadBid = (
402
+ if (this.cachedLatestExecutionPayloadBid === null) {
403
+ this.cachedLatestExecutionPayloadBid = (
400
404
  this.cachedState as CachedBeaconStateGloas
401
405
  ).latestExecutionPayloadBid.toValue();
402
406
  }
403
- return this._latestExecutionPayloadBid;
407
+ return this.cachedLatestExecutionPayloadBid;
404
408
  }
405
409
 
406
410
  get payloadExpectedWithdrawals(): capella.Withdrawal[] {
@@ -408,12 +412,12 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
408
412
  throw new Error("payloadExpectedWithdrawals is not available before Gloas");
409
413
  }
410
414
 
411
- if (this._payloadExpectedWithdrawals === null) {
412
- this._payloadExpectedWithdrawals = (
415
+ if (this.cachedPayloadExpectedWithdrawals === null) {
416
+ this.cachedPayloadExpectedWithdrawals = (
413
417
  this.cachedState as CachedBeaconStateGloas
414
418
  ).payloadExpectedWithdrawals.toValue();
415
419
  }
416
- return this._payloadExpectedWithdrawals;
420
+ return this.cachedPayloadExpectedWithdrawals;
417
421
  }
418
422
 
419
423
  get builderPendingPayments(): gloas.BuilderPendingPayments {
@@ -421,10 +425,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
421
425
  throw new Error("Pending builder payments are not supported before Gloas");
422
426
  }
423
427
 
424
- if (this._builderPendingPayments === null) {
425
- this._builderPendingPayments = (this.cachedState as CachedBeaconStateGloas).builderPendingPayments.toValue();
428
+ if (this.cachedBuilderPendingPayments === null) {
429
+ this.cachedBuilderPendingPayments = (this.cachedState as CachedBeaconStateGloas).builderPendingPayments.toValue();
426
430
  }
427
- return this._builderPendingPayments;
431
+ return this.cachedBuilderPendingPayments;
428
432
  }
429
433
 
430
434
  get builderPendingWithdrawals(): gloas.BuilderPendingWithdrawals {
@@ -432,12 +436,12 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
432
436
  throw new Error("Pending builder withdrawals are not supported before Gloas");
433
437
  }
434
438
 
435
- if (this._builderPendingWithdrawals === null) {
436
- this._builderPendingWithdrawals = (
439
+ if (this.cachedBuilderPendingWithdrawals === null) {
440
+ this.cachedBuilderPendingWithdrawals = (
437
441
  this.cachedState as CachedBeaconStateGloas
438
442
  ).builderPendingWithdrawals.toValue();
439
443
  }
440
- return this._builderPendingWithdrawals;
444
+ return this.cachedBuilderPendingWithdrawals;
441
445
  }
442
446
 
443
447
  getBuilder(index: BuilderIndex): gloas.Builder {
@@ -588,11 +592,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
588
592
  throw new Error("currentSyncCommittee is not available before Altair");
589
593
  }
590
594
 
591
- if (this._currentSyncCommittee === null) {
592
- this._currentSyncCommittee = (this.cachedState as CachedBeaconStateAltair).currentSyncCommittee.toValue();
595
+ if (this.cachedCurrentSyncCommittee === null) {
596
+ this.cachedCurrentSyncCommittee = (this.cachedState as CachedBeaconStateAltair).currentSyncCommittee.toValue();
593
597
  }
594
598
 
595
- return this._currentSyncCommittee;
599
+ return this.cachedCurrentSyncCommittee;
596
600
  }
597
601
 
598
602
  get nextSyncCommittee(): SyncCommittee {
@@ -600,17 +604,21 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
600
604
  throw new Error("nextSyncCommittee is not available before Altair");
601
605
  }
602
606
 
603
- if (this._nextSyncCommittee === null) {
604
- this._nextSyncCommittee = (this.cachedState as CachedBeaconStateAltair).nextSyncCommittee.toValue();
607
+ if (this.cachedNextSyncCommittee === null) {
608
+ this.cachedNextSyncCommittee = (this.cachedState as CachedBeaconStateAltair).nextSyncCommittee.toValue();
605
609
  }
606
610
 
607
- return this._nextSyncCommittee;
611
+ return this.cachedNextSyncCommittee;
608
612
  }
609
613
 
610
614
  get currentSyncCommitteeIndexed(): SyncCommitteeCache {
611
615
  return this.cachedState.epochCtx.currentSyncCommitteeIndexed;
612
616
  }
613
617
 
618
+ get currentSyncCommitteeValidatorIndices(): Uint32Array {
619
+ return this.cachedState.epochCtx.currentSyncCommitteeIndexed.validatorIndices;
620
+ }
621
+
614
622
  get syncProposerReward(): number {
615
623
  return this.cachedState.epochCtx.syncProposerReward;
616
624
  }
@@ -872,7 +880,7 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
872
880
 
873
881
  // State transition
874
882
 
875
- computeNewStateRoot({block}: ComputeNewStateRootInput, modules: StateTransitionModules): ComputeNewStateRootResult {
883
+ computeNewStateRoot({block}: BlockSTFInput, modules: StateTransitionModules): ComputeNewStateRootResult {
876
884
  const postState = new BeaconStateView(
877
885
  stateTransition(this.cachedState, block, computeNewStateRootStateTransitionOpts, modules)
878
886
  );
@@ -880,12 +888,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
880
888
  }
881
889
 
882
890
  stateTransition(
883
- signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock,
891
+ {block}: BlockSTFInput,
884
892
  options: StateTransitionOpts,
885
- {metrics, validatorMonitor}: StateTransitionModules
893
+ modules: StateTransitionModules
886
894
  ): IBeaconStateView {
887
- const newState = stateTransition(this.cachedState, signedBlock, options, {metrics, validatorMonitor});
888
- return new BeaconStateView(newState);
895
+ return new BeaconStateView(stateTransition(this.cachedState, block, options, modules));
889
896
  }
890
897
 
891
898
  processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}, modules?: StateTransitionModules): IBeaconStateView {
@@ -55,10 +55,13 @@ import {StateTransitionModules, StateTransitionOpts} from "../stateTransition.js
55
55
  import {EpochShuffling} from "../util/epochShuffling.js";
56
56
  import {PreVerifyBuilderDepositsResult} from "../util/preVerifyBuilderDeposits.js";
57
57
 
58
- /** Inputs for computing the state root of a locally produced block. */
59
- export type ComputeNewStateRootInput = {
58
+ /** Signed block to apply in a state transition. */
59
+ export type BlockSTFInput = {
60
60
  block: SignedBeaconBlock | SignedBlindedBeaconBlock;
61
- /** Pre-serialized block bytes for native implementations. */
61
+ /**
62
+ * Fork-specific SSZ serialization of `block`, using the matching full or blinded block type. Native
63
+ * implementations serialize `block` when omitted.
64
+ */
62
65
  ssz?: Uint8Array;
63
66
  };
64
67
 
@@ -159,6 +162,13 @@ export interface IBeaconStateView {
159
162
  // TODO is there a better name that is less implementation specific but still conveys the meaning?
160
163
  isStateValidatorsNodesPopulated(): boolean;
161
164
 
165
+ // Lifecycle
166
+ /**
167
+ * Release resources owned by this view.
168
+ * Do not use the view after calling this method.
169
+ */
170
+ release(): void;
171
+
162
172
  // Serialization
163
173
  /** Set `preloadValidatorsAndBalances` only when the whole state will be consumed
164
174
  * immediately (e.g. CP reload before block replay). */
@@ -178,9 +188,9 @@ export interface IBeaconStateView {
178
188
  hashTreeRoot(): Uint8Array;
179
189
 
180
190
  // State transition
181
- computeNewStateRoot(input: ComputeNewStateRootInput, modules: StateTransitionModules): ComputeNewStateRootResult;
191
+ computeNewStateRoot(input: BlockSTFInput, modules: StateTransitionModules): ComputeNewStateRootResult;
182
192
  stateTransition(
183
- signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock,
193
+ input: BlockSTFInput,
184
194
  options: StateTransitionOpts,
185
195
  modules: StateTransitionModules
186
196
  ): IBeaconStateView;
@@ -197,6 +207,7 @@ export interface IBeaconStateViewAltair extends IBeaconStateView {
197
207
  currentSyncCommittee: altair.SyncCommittee;
198
208
  nextSyncCommittee: altair.SyncCommittee;
199
209
  currentSyncCommitteeIndexed: SyncCommitteeCache;
210
+ readonly currentSyncCommitteeValidatorIndices: Uint32Array;
200
211
  syncProposerReward: number;
201
212
  getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
202
213
  /** Get indexed sync committee with slot+1 offset for duty lookups */
@@ -317,33 +328,66 @@ export type IBeaconStateViewLatestFork = Omit<
317
328
  /**
318
329
  * Contract a BeaconStateView backing implementation must satisfy.
319
330
  *
320
- * Differs from `IBeaconStateViewLatestFork` in two ways:
321
- * - `executionPayloadAvailability` is a raw `{uint8Array, bitLen}` POJO — a
322
- * native (`.node`) binding cannot construct a `BitArray` across FFI.
323
- * `NativeBeaconStateView` lifts it back to `BitArray` for beacon-node.
324
- * - Methods that produce another view (`stateTransition`, `processSlots`,
325
- * `loadOtherState`, `withParentPayloadApplied`) return `IBeaconStateViewNative`
326
- * so callers can re-wrap without an `as unknown` cast. Param lists are reused
327
- * via `Parameters<...>` to avoid duplicating signatures.
328
- * - `computeNewStateRoot` is implemented by the wrapper because its inputs differ
329
- * between the TypeScript and Zig implementations.
330
- *
331
- * The TS-side `BeaconStateView` also structurally satisfies this contract since
332
- * `BitArray` exposes `uint8Array` and `bitLen`.
331
+ * Differs from `IBeaconStateViewLatestFork` in these ways:
332
+ * - SSZ-backed lists use serialized bytes or native typed arrays at the FFI boundary.
333
+ * - Methods that produce another view return `IBeaconStateViewNative` so callers can re-wrap them.
334
+ * - `stateTransition` accepts the native block inputs and omits JS-only modules.
335
+ * - `computeNewStateRoot` is implemented by the wrapper because its inputs differ between implementations.
333
336
  */
334
337
  export type IBeaconStateViewNative = Omit<
335
338
  IBeaconStateViewLatestFork,
339
+ | "builderPendingPayments"
340
+ | "builderPendingWithdrawals"
341
+ | "computeAttestationsRewards"
342
+ | "computeBlockRewards"
336
343
  | "computeNewStateRoot"
344
+ | "computeSyncCommitteeRewards"
345
+ | "currentSyncCommitteeValidatorIndices"
346
+ | "eth1Data"
337
347
  | "executionPayloadAvailability"
348
+ | "getBeaconCommittee"
349
+ | "getIndicesInPayloadTimelinessCommittee"
350
+ | "getPayloadTimelinessCommittee"
338
351
  | "loadOtherState"
339
- | "stateTransition"
352
+ | "pendingConsolidations"
353
+ | "pendingDeposits"
354
+ | "pendingPartialWithdrawals"
355
+ | "preVerifyBuilderDepositsPreGloas"
356
+ | "clearPreGloasBuilderDepositCache"
340
357
  | "processSlots"
358
+ | "proposerLookahead"
359
+ | "stateTransition"
341
360
  | "withParentPayloadApplied"
342
361
  > & {
362
+ pendingDeposits: Uint8Array;
363
+ /** Older native addons expose indices only through currentSyncCommitteeIndexed. */
364
+ readonly currentSyncCommitteeValidatorIndices?: Uint32Array;
365
+ pendingPartialWithdrawals: Uint8Array;
366
+ pendingConsolidations: Uint8Array;
367
+ proposerLookahead: Uint32Array;
368
+ // UintBn64 lowers to number across the FFI boundary; the wrapper lifts it back to bigint
369
+ eth1Data: phase0.Eth1Data;
343
370
  executionPayloadAvailability: {uint8Array: Uint8Array; bitLen: number};
371
+ computeBlockRewards(
372
+ signedBlockBytes: Uint8Array,
373
+ isBlinded: boolean,
374
+ proposerRewards?: RewardCache
375
+ ): rewards.BlockRewards;
376
+ computeAttestationsRewards(validatorIds?: (ValidatorIndex | string)[]): rewards.AttestationsRewards;
377
+ computeSyncCommitteeRewards(
378
+ block: BeaconBlock,
379
+ validatorIds: (ValidatorIndex | string)[]
380
+ ): rewards.SyncCommitteeRewards;
381
+ getBeaconCommittee(slot: Slot, index: CommitteeIndex): Uint32Array;
382
+ getIndexInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number;
383
+ getIndicesInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number[];
344
384
  loadOtherState(...args: Parameters<IBeaconStateViewLatestFork["loadOtherState"]>): IBeaconStateViewNative;
345
- stateTransition(...args: Parameters<IBeaconStateViewLatestFork["stateTransition"]>): IBeaconStateViewNative;
346
- processSlots(...args: Parameters<IBeaconStateViewLatestFork["processSlots"]>): IBeaconStateViewNative;
385
+ stateTransition(
386
+ signedBlockBytes: Uint8Array,
387
+ isBlinded: boolean,
388
+ options?: StateTransitionOpts
389
+ ): IBeaconStateViewNative;
390
+ processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}): IBeaconStateViewNative;
347
391
  withParentPayloadApplied(
348
392
  ...args: Parameters<IBeaconStateViewLatestFork["withParentPayloadApplied"]>
349
393
  ): IBeaconStateViewNative;