@lodestar/state-transition 1.42.0-dev.4411584fd8 → 1.42.0-dev.5007abf468

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 (47) hide show
  1. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  2. package/lib/block/isValidIndexedAttestation.js +2 -3
  3. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  4. package/lib/block/processAttestationsAltair.d.ts +2 -1
  5. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  6. package/lib/block/processAttestationsAltair.js +5 -3
  7. package/lib/block/processAttestationsAltair.js.map +1 -1
  8. package/lib/block/processExecutionPayloadEnvelope.d.ts +3 -1
  9. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
  10. package/lib/block/processExecutionPayloadEnvelope.js +11 -28
  11. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
  12. package/lib/signatureSets/executionPayloadEnvelope.d.ts +5 -1
  13. package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -1
  14. package/lib/signatureSets/executionPayloadEnvelope.js +10 -1
  15. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
  16. package/lib/signatureSets/index.d.ts +2 -2
  17. package/lib/signatureSets/index.d.ts.map +1 -1
  18. package/lib/signatureSets/index.js +1 -2
  19. package/lib/signatureSets/index.js.map +1 -1
  20. package/lib/slot/upgradeStateToAltair.d.ts.map +1 -1
  21. package/lib/slot/upgradeStateToAltair.js +2 -1
  22. package/lib/slot/upgradeStateToAltair.js.map +1 -1
  23. package/lib/stateView/beaconStateView.d.ts +11 -7
  24. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  25. package/lib/stateView/beaconStateView.js +13 -10
  26. package/lib/stateView/beaconStateView.js.map +1 -1
  27. package/lib/stateView/interface.d.ts +14 -9
  28. package/lib/stateView/interface.d.ts.map +1 -1
  29. package/lib/util/rootCache.d.ts +2 -2
  30. package/lib/util/rootCache.d.ts.map +1 -1
  31. package/lib/util/rootCache.js +2 -3
  32. package/lib/util/rootCache.js.map +1 -1
  33. package/lib/util/shuffling.d.ts +2 -1
  34. package/lib/util/shuffling.d.ts.map +1 -1
  35. package/lib/util/shuffling.js +2 -2
  36. package/lib/util/shuffling.js.map +1 -1
  37. package/package.json +7 -7
  38. package/src/block/isValidIndexedAttestation.ts +2 -3
  39. package/src/block/processAttestationsAltair.ts +7 -4
  40. package/src/block/processExecutionPayloadEnvelope.ts +18 -35
  41. package/src/signatureSets/executionPayloadEnvelope.ts +26 -2
  42. package/src/signatureSets/index.ts +3 -4
  43. package/src/slot/upgradeStateToAltair.ts +2 -1
  44. package/src/stateView/beaconStateView.ts +31 -13
  45. package/src/stateView/interface.ts +15 -6
  46. package/src/util/rootCache.ts +4 -5
  47. package/src/util/shuffling.ts +5 -4
@@ -1,9 +1,10 @@
1
1
  import {CompactMultiProof, ProofType, Tree, createProof} from "@chainsafe/persistent-merkle-tree";
2
- import {ByteViews} from "@chainsafe/ssz";
2
+ import {BitArray, ByteViews} from "@chainsafe/ssz";
3
3
  import {BeaconConfig} from "@lodestar/config";
4
4
  import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT, isForkPostGloas} from "@lodestar/params";
5
5
  import {
6
6
  BeaconBlock,
7
+ BeaconState,
7
8
  BlindedBeaconBlock,
8
9
  BuilderIndex,
9
10
  Bytes32,
@@ -28,11 +29,12 @@ import {
28
29
  } from "@lodestar/types";
29
30
  import {Checkpoint, Fork} from "@lodestar/types/phase0";
30
31
  import {processExecutionPayloadEnvelope} from "../block/index.js";
32
+ import {ProcessExecutionPayloadEnvelopeOpts} from "../block/processExecutionPayloadEnvelope.js";
31
33
  import {VoluntaryExitValidity, getVoluntaryExitValidity} from "../block/processVoluntaryExit.js";
32
34
  import {getExpectedWithdrawals} from "../block/processWithdrawals.js";
33
35
  import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
34
36
  import {EpochTransitionCacheOpts} from "../cache/epochTransitionCache.js";
35
- import {PubkeyCache, createPubkeyCache} from "../cache/pubkeyCache.js";
37
+ import {PubkeyCache} from "../cache/pubkeyCache.js";
36
38
  import {RewardCache} from "../cache/rewardCache.js";
37
39
  import {
38
40
  CachedBeaconStateAllForks,
@@ -91,7 +93,7 @@ export class BeaconStateView implements IBeaconStateView {
91
93
  // fulu
92
94
  private _proposerLookahead: fulu.ProposerLookahead | null = null;
93
95
  // gloas
94
- private _executionPayloadAvailability: boolean[] | null = null;
96
+ private _executionPayloadAvailability: BitArray | null = null;
95
97
  private _latestExecutionPayloadBid: ExecutionPayloadBid | null = null;
96
98
 
97
99
  constructor(readonly cachedState: CachedBeaconStateAllForks) {
@@ -356,15 +358,15 @@ export class BeaconStateView implements IBeaconStateView {
356
358
 
357
359
  // gloas
358
360
 
359
- get executionPayloadAvailability(): boolean[] {
361
+ get executionPayloadAvailability(): BitArray {
360
362
  if (this.config.getForkSeq(this.cachedState.slot) < ForkSeq.gloas) {
361
363
  throw new Error("executionPayloadAvailability is not available before GLOAS");
362
364
  }
363
365
 
364
366
  if (this._executionPayloadAvailability === null) {
365
- this._executionPayloadAvailability = (this.cachedState as CachedBeaconStateGloas).executionPayloadAvailability
366
- .toValue()
367
- .toBoolArray();
367
+ this._executionPayloadAvailability = (
368
+ this.cachedState as CachedBeaconStateGloas
369
+ ).executionPayloadAvailability.toValue();
368
370
  }
369
371
 
370
372
  return this._executionPayloadAvailability;
@@ -403,7 +405,7 @@ export class BeaconStateView implements IBeaconStateView {
403
405
  * Return the index of the validator in the PTC committee for the given slot.
404
406
  * return -1 if validator is not in the PTC committee for the given slot.
405
407
  */
406
- validatorPTCCommitteeIndex(validatorIndex: ValidatorIndex, slot: Slot): number {
408
+ getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number {
407
409
  if (this.config.getForkSeq(this.cachedState.slot) < ForkSeq.gloas) {
408
410
  throw new Error("PTC committees are not supported before GLOAS");
409
411
  }
@@ -502,6 +504,10 @@ export class BeaconStateView implements IBeaconStateView {
502
504
  return this.cachedState.epochCtx.syncProposerReward;
503
505
  }
504
506
 
507
+ getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache {
508
+ return this.cachedState.epochCtx.getIndexedSyncCommittee(slot);
509
+ }
510
+
505
511
  getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache {
506
512
  return this.cachedState.epochCtx.getIndexedSyncCommitteeAtEpoch(epoch);
507
513
  }
@@ -712,6 +718,10 @@ export class BeaconStateView implements IBeaconStateView {
712
718
  return new BeaconStateView(cachedState);
713
719
  }
714
720
 
721
+ toValue(): BeaconState {
722
+ return this.cachedState.toValue();
723
+ }
724
+
715
725
  serialize(): Uint8Array {
716
726
  return this.cachedState.serialize();
717
727
  }
@@ -761,25 +771,33 @@ export class BeaconStateView implements IBeaconStateView {
761
771
  return new BeaconStateView(newState);
762
772
  }
763
773
 
764
- processExecutionPayloadEnvelope(signedEnvelope: gloas.SignedExecutionPayloadEnvelope, verify: boolean): void {
774
+ processExecutionPayloadEnvelope(
775
+ signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
776
+ opts?: ProcessExecutionPayloadEnvelopeOpts
777
+ ): BeaconStateView {
765
778
  const fork = this.config.getForkName(this.cachedState.slot);
766
779
  if (!isForkPostGloas(fork)) {
767
780
  throw Error(`processExecutionPayloadEnvelope is only available for gloas+ forks, got fork=${fork}`);
768
781
  }
769
- processExecutionPayloadEnvelope(this.cachedState as CachedBeaconStateGloas, signedEnvelope, verify);
782
+ const postPayloadState = processExecutionPayloadEnvelope(
783
+ this.cachedState as CachedBeaconStateGloas,
784
+ signedEnvelope,
785
+ opts
786
+ );
787
+ return new BeaconStateView(postPayloadState);
770
788
  }
771
789
  }
772
790
 
773
791
  /**
774
- * Create BeaconStateView for historical state regen, no need to sync pubkey cache there.
792
+ * Create BeaconStateView for historical state regen, this is called from a worker thread.
775
793
  */
776
794
  export function createBeaconStateViewForHistoricalRegen(
777
795
  config: BeaconConfig,
778
- stateBytes: Uint8Array
796
+ stateBytes: Uint8Array,
797
+ pubkeyCache: PubkeyCache
779
798
  ): IBeaconStateView {
780
799
  const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
781
800
 
782
- const pubkeyCache = createPubkeyCache();
783
801
  syncPubkeyCache(state, pubkeyCache);
784
802
  const cachedState = createCachedBeaconState(
785
803
  state,
@@ -1,7 +1,8 @@
1
1
  import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
2
- import {ByteViews} from "@chainsafe/ssz";
2
+ import {BitArray, ByteViews} from "@chainsafe/ssz";
3
3
  import {
4
4
  BeaconBlock,
5
+ BeaconState,
5
6
  BlindedBeaconBlock,
6
7
  BuilderIndex,
7
8
  Bytes32,
@@ -23,6 +24,7 @@ import {
23
24
  rewards,
24
25
  } from "@lodestar/types";
25
26
  import {Checkpoint, Fork} from "@lodestar/types/phase0";
27
+ import {ProcessExecutionPayloadEnvelopeOpts} from "../block/processExecutionPayloadEnvelope.js";
26
28
  import {VoluntaryExitValidity} from "../block/processVoluntaryExit.js";
27
29
  import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
28
30
  import {EpochTransitionCacheOpts} from "../cache/epochTransitionCache.js";
@@ -92,11 +94,11 @@ export interface IBeaconStateView {
92
94
  proposerLookahead: fulu.ProposerLookahead;
93
95
 
94
96
  // gloas
95
- executionPayloadAvailability: boolean[];
97
+ executionPayloadAvailability: BitArray;
96
98
  latestExecutionPayloadBid: ExecutionPayloadBid;
97
99
  getBuilder(index: BuilderIndex): gloas.Builder;
98
100
  canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
99
- validatorPTCCommitteeIndex(validatorIndex: ValidatorIndex, slot: Slot): number;
101
+ getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number;
100
102
 
101
103
  // Shuffling and committees
102
104
  getShufflingAtEpoch(epoch: Epoch): EpochShuffling;
@@ -109,12 +111,11 @@ export interface IBeaconStateView {
109
111
  getCurrentShuffling(): EpochShuffling;
110
112
  getNextShuffling(): EpochShuffling;
111
113
 
112
- // utils: proposers, anchor checkpoint
114
+ // Proposer shuffling
113
115
  previousProposers: ValidatorIndex[] | null;
114
116
  currentProposers: ValidatorIndex[];
115
117
  nextProposers: ValidatorIndex[];
116
118
  getBeaconProposer(slot: Slot): ValidatorIndex;
117
- computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader};
118
119
 
119
120
  // Sync committees
120
121
  currentSyncCommittee: altair.SyncCommittee;
@@ -122,6 +123,8 @@ export interface IBeaconStateView {
122
123
  currentSyncCommitteeIndexed: SyncCommitteeCache;
123
124
  syncProposerReward: number;
124
125
  getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
126
+ /** Get indexed sync committee with slot+1 offset for duty lookups */
127
+ getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache;
125
128
 
126
129
  // Validators and balances
127
130
  effectiveBalanceIncrements: EffectiveBalanceIncrements;
@@ -148,6 +151,7 @@ export interface IBeaconStateView {
148
151
  expectedWithdrawals: capella.Withdrawal[];
149
152
  processedBuilderWithdrawalsCount: number;
150
153
  processedPartialWithdrawalsCount: number;
154
+ processedBuildersSweepCount: number;
151
155
  processedValidatorSweepCount: number;
152
156
  };
153
157
 
@@ -179,6 +183,7 @@ export interface IBeaconStateView {
179
183
  justifiedCheckpoint: phase0.Checkpoint;
180
184
  finalizedCheckpoint: phase0.Checkpoint;
181
185
  };
186
+ computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader};
182
187
 
183
188
  // this is for backward compatible
184
189
  clonedCount: number;
@@ -189,6 +194,7 @@ export interface IBeaconStateView {
189
194
 
190
195
  // Serialization
191
196
  loadOtherState(stateBytes: Uint8Array, seedValidatorsBytes?: Uint8Array): IBeaconStateView;
197
+ toValue(): BeaconState;
192
198
  serialize(): Uint8Array;
193
199
  serializedSize(): number;
194
200
  serializeToBytes(output: ByteViews, offset: number): number;
@@ -209,5 +215,8 @@ export interface IBeaconStateView {
209
215
  epochTransitionCacheOpts?: EpochTransitionCacheOpts & {dontTransferCache?: boolean},
210
216
  modules?: StateTransitionModules
211
217
  ): IBeaconStateView;
212
- processExecutionPayloadEnvelope(signedEnvelope: gloas.SignedExecutionPayloadEnvelope, verify: boolean): void;
218
+ processExecutionPayloadEnvelope(
219
+ signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
220
+ opts?: ProcessExecutionPayloadEnvelopeOpts
221
+ ): IBeaconStateView;
213
222
  }
@@ -1,6 +1,5 @@
1
1
  import {Epoch, Root, Slot, phase0} from "@lodestar/types";
2
- import {CachedBeaconStateAllForks} from "../types.js";
3
- import {getBlockRoot, getBlockRootAtSlot} from "./blockRoot.js";
2
+ import {IBeaconStateView} from "../stateView/interface.js";
4
3
 
5
4
  /**
6
5
  * Cache to prevent accessing the state tree to fetch block roots repeteadly.
@@ -12,7 +11,7 @@ export class RootCache {
12
11
  private readonly blockRootEpochCache = new Map<Epoch, Root>();
13
12
  private readonly blockRootSlotCache = new Map<Slot, Root>();
14
13
 
15
- constructor(private readonly state: CachedBeaconStateAllForks) {
14
+ constructor(private readonly state: IBeaconStateView) {
16
15
  this.currentJustifiedCheckpoint = state.currentJustifiedCheckpoint;
17
16
  this.previousJustifiedCheckpoint = state.previousJustifiedCheckpoint;
18
17
  }
@@ -20,7 +19,7 @@ export class RootCache {
20
19
  getBlockRoot(epoch: Epoch): Root {
21
20
  let root = this.blockRootEpochCache.get(epoch);
22
21
  if (!root) {
23
- root = getBlockRoot(this.state, epoch);
22
+ root = this.state.getBlockRootAtEpoch(epoch);
24
23
  this.blockRootEpochCache.set(epoch, root);
25
24
  }
26
25
  return root;
@@ -29,7 +28,7 @@ export class RootCache {
29
28
  getBlockRootAtSlot(slot: Slot): Root {
30
29
  let root = this.blockRootSlotCache.get(slot);
31
30
  if (!root) {
32
- root = getBlockRootAtSlot(this.state, slot);
31
+ root = this.state.getBlockRootAtSlot(slot);
33
32
  this.blockRootSlotCache.set(slot, root);
34
33
  }
35
34
  return root;
@@ -11,6 +11,7 @@ import {
11
11
  } from "@lodestar/types";
12
12
  import {LodestarError} from "@lodestar/utils";
13
13
  import {CachedBeaconStateAllForks} from "../cache/stateCache.js";
14
+ import {IBeaconStateView} from "../stateView/interface.js";
14
15
  import {getBlockRootAtSlot} from "./blockRoot.js";
15
16
  import {computeStartSlotAtEpoch} from "./epoch.js";
16
17
  import {EpochShuffling} from "./epochShuffling.js";
@@ -22,21 +23,21 @@ import {EpochShuffling} from "./epochShuffling.js";
22
23
  * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
23
24
  * It should be set to the latest block applied to this `state` or the genesis block root.
24
25
  */
25
- export function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null {
26
+ export function proposerShufflingDecisionRoot(fork: ForkName, state: IBeaconStateView): Root | null {
26
27
  const decisionSlot = proposerShufflingDecisionSlot(fork, state);
27
28
  if (state.slot === decisionSlot) {
28
29
  return null;
29
30
  }
30
- return getBlockRootAtSlot(state, decisionSlot);
31
+ return state.getBlockRootAtSlot(decisionSlot);
31
32
  }
32
33
 
33
34
  /**
34
35
  * Returns the slot at which the proposer shuffling was decided. The block root at this slot
35
36
  * can be used to key the proposer shuffling for the current epoch.
36
37
  */
37
- function proposerShufflingDecisionSlot(fork: ForkName, state: CachedBeaconStateAllForks): Slot {
38
+ function proposerShufflingDecisionSlot(fork: ForkName, state: IBeaconStateView): Slot {
38
39
  // After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
39
- const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
40
+ const epoch = isForkPostFulu(fork) ? state.epoch - 1 : state.epoch;
40
41
  const startSlot = computeStartSlotAtEpoch(epoch);
41
42
  return Math.max(startSlot - 1, 0);
42
43
  }