@lodestar/state-transition 1.50.0-dev.11028e782c → 1.50.0-dev.15ca1827f4

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 (63) 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 +6 -5
  35. package/lib/stateView/stateViewFactory.d.ts.map +1 -1
  36. package/lib/stateView/stateViewFactory.js +12 -8
  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 -1
  43. package/lib/util/index.d.ts.map +1 -1
  44. package/lib/util/index.js +1 -1
  45. package/lib/util/index.js.map +1 -1
  46. package/lib/util/sszBytes.d.ts +2 -0
  47. package/lib/util/sszBytes.d.ts.map +1 -1
  48. package/lib/util/sszBytes.js +14 -1
  49. package/lib/util/sszBytes.js.map +1 -1
  50. package/package.json +7 -7
  51. package/src/block/indexedBuilderState.ts +65 -0
  52. package/src/block/processBuilderDepositRequest.ts +6 -17
  53. package/src/block/processBuilderExitRequest.ts +5 -9
  54. package/src/block/processParentExecutionPayload.ts +27 -23
  55. package/src/index.ts +4 -1
  56. package/src/rewards/attestationsRewards.ts +8 -1
  57. package/src/stateView/beaconStateView.ts +75 -76
  58. package/src/stateView/interface.ts +61 -21
  59. package/src/stateView/nativeBeaconStateView.ts +354 -375
  60. package/src/stateView/stateViewFactory.ts +21 -12
  61. package/src/util/gloas.ts +2 -53
  62. package/src/util/index.ts +1 -0
  63. package/src/util/sszBytes.ts +19 -1
@@ -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;
@@ -317,33 +327,63 @@ export type IBeaconStateViewLatestFork = Omit<
317
327
  /**
318
328
  * Contract a BeaconStateView backing implementation must satisfy.
319
329
  *
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`.
330
+ * Differs from `IBeaconStateViewLatestFork` in these ways:
331
+ * - SSZ-backed lists use serialized bytes or native typed arrays at the FFI boundary.
332
+ * - Methods that produce another view return `IBeaconStateViewNative` so callers can re-wrap them.
333
+ * - `stateTransition` accepts the native block inputs and omits JS-only modules.
334
+ * - `computeNewStateRoot` is implemented by the wrapper because its inputs differ between implementations.
333
335
  */
334
336
  export type IBeaconStateViewNative = Omit<
335
337
  IBeaconStateViewLatestFork,
338
+ | "builderPendingPayments"
339
+ | "builderPendingWithdrawals"
340
+ | "computeAttestationsRewards"
341
+ | "computeBlockRewards"
336
342
  | "computeNewStateRoot"
343
+ | "computeSyncCommitteeRewards"
344
+ | "eth1Data"
337
345
  | "executionPayloadAvailability"
346
+ | "getBeaconCommittee"
347
+ | "getIndicesInPayloadTimelinessCommittee"
348
+ | "getPayloadTimelinessCommittee"
338
349
  | "loadOtherState"
339
- | "stateTransition"
350
+ | "pendingConsolidations"
351
+ | "pendingDeposits"
352
+ | "pendingPartialWithdrawals"
353
+ | "preVerifyBuilderDepositsPreGloas"
354
+ | "clearPreGloasBuilderDepositCache"
340
355
  | "processSlots"
356
+ | "proposerLookahead"
357
+ | "stateTransition"
341
358
  | "withParentPayloadApplied"
342
359
  > & {
360
+ pendingDeposits: Uint8Array;
361
+ pendingPartialWithdrawals: Uint8Array;
362
+ pendingConsolidations: Uint8Array;
363
+ proposerLookahead: Uint32Array;
364
+ // UintBn64 lowers to number across the FFI boundary; the wrapper lifts it back to bigint
365
+ eth1Data: phase0.Eth1Data;
343
366
  executionPayloadAvailability: {uint8Array: Uint8Array; bitLen: number};
367
+ computeBlockRewards(
368
+ signedBlockBytes: Uint8Array,
369
+ isBlinded: boolean,
370
+ proposerRewards?: RewardCache
371
+ ): rewards.BlockRewards;
372
+ computeAttestationsRewards(validatorIds?: (ValidatorIndex | string)[]): rewards.AttestationsRewards;
373
+ computeSyncCommitteeRewards(
374
+ block: BeaconBlock,
375
+ validatorIds: (ValidatorIndex | string)[]
376
+ ): rewards.SyncCommitteeRewards;
377
+ getBeaconCommittee(slot: Slot, index: CommitteeIndex): Uint32Array;
378
+ getIndexInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number;
379
+ getIndicesInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number[];
344
380
  loadOtherState(...args: Parameters<IBeaconStateViewLatestFork["loadOtherState"]>): IBeaconStateViewNative;
345
- stateTransition(...args: Parameters<IBeaconStateViewLatestFork["stateTransition"]>): IBeaconStateViewNative;
346
- processSlots(...args: Parameters<IBeaconStateViewLatestFork["processSlots"]>): IBeaconStateViewNative;
381
+ stateTransition(
382
+ signedBlockBytes: Uint8Array,
383
+ isBlinded: boolean,
384
+ options?: StateTransitionOpts
385
+ ): IBeaconStateViewNative;
386
+ processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}): IBeaconStateViewNative;
347
387
  withParentPayloadApplied(
348
388
  ...args: Parameters<IBeaconStateViewLatestFork["withParentPayloadApplied"]>
349
389
  ): IBeaconStateViewNative;