@lodestar/state-transition 1.43.0-dev.9fa9f08ef6 → 1.43.0-dev.a140dd987e

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 (69) hide show
  1. package/lib/block/index.d.ts +2 -2
  2. package/lib/block/index.d.ts.map +1 -1
  3. package/lib/block/index.js +11 -4
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/processParentExecutionPayload.d.ts +20 -0
  6. package/lib/block/processParentExecutionPayload.d.ts.map +1 -0
  7. package/lib/block/processParentExecutionPayload.js +100 -0
  8. package/lib/block/processParentExecutionPayload.js.map +1 -0
  9. package/lib/block/processWithdrawals.d.ts.map +1 -1
  10. package/lib/block/processWithdrawals.js +12 -4
  11. package/lib/block/processWithdrawals.js.map +1 -1
  12. package/lib/cache/epochCache.d.ts +3 -1
  13. package/lib/cache/epochCache.d.ts.map +1 -1
  14. package/lib/cache/epochCache.js +31 -13
  15. package/lib/cache/epochCache.js.map +1 -1
  16. package/lib/cache/epochTransitionCache.d.ts +5 -0
  17. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  18. package/lib/cache/epochTransitionCache.js +1 -0
  19. package/lib/cache/epochTransitionCache.js.map +1 -1
  20. package/lib/epoch/index.d.ts +3 -1
  21. package/lib/epoch/index.d.ts.map +1 -1
  22. package/lib/epoch/index.js +8 -1
  23. package/lib/epoch/index.js.map +1 -1
  24. package/lib/epoch/processPtcWindow.d.ts +11 -0
  25. package/lib/epoch/processPtcWindow.d.ts.map +1 -0
  26. package/lib/epoch/processPtcWindow.js +28 -0
  27. package/lib/epoch/processPtcWindow.js.map +1 -0
  28. package/lib/signatureSets/executionPayloadEnvelope.js +1 -1
  29. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
  30. package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
  31. package/lib/slot/upgradeStateToGloas.js +3 -1
  32. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  33. package/lib/stateTransition.js +1 -1
  34. package/lib/stateTransition.js.map +1 -1
  35. package/lib/stateView/beaconStateView.d.ts +7 -3
  36. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  37. package/lib/stateView/beaconStateView.js +20 -13
  38. package/lib/stateView/beaconStateView.js.map +1 -1
  39. package/lib/stateView/interface.d.ts +11 -3
  40. package/lib/stateView/interface.d.ts.map +1 -1
  41. package/lib/stateView/interface.js.map +1 -1
  42. package/lib/util/computeAnchorCheckpoint.d.ts +1 -1
  43. package/lib/util/computeAnchorCheckpoint.d.ts.map +1 -1
  44. package/lib/util/computeAnchorCheckpoint.js +6 -19
  45. package/lib/util/computeAnchorCheckpoint.js.map +1 -1
  46. package/lib/util/gloas.d.ts +7 -1
  47. package/lib/util/gloas.d.ts.map +1 -1
  48. package/lib/util/gloas.js +27 -1
  49. package/lib/util/gloas.js.map +1 -1
  50. package/package.json +8 -8
  51. package/src/block/index.ts +12 -4
  52. package/src/block/processParentExecutionPayload.ts +116 -0
  53. package/src/block/processWithdrawals.ts +12 -4
  54. package/src/cache/epochCache.ts +32 -30
  55. package/src/cache/epochTransitionCache.ts +7 -0
  56. package/src/epoch/index.ts +9 -0
  57. package/src/epoch/processPtcWindow.ts +38 -0
  58. package/src/signatureSets/executionPayloadEnvelope.ts +1 -1
  59. package/src/slot/upgradeStateToGloas.ts +5 -1
  60. package/src/stateTransition.ts +1 -1
  61. package/src/stateView/beaconStateView.ts +24 -20
  62. package/src/stateView/interface.ts +13 -6
  63. package/src/util/computeAnchorCheckpoint.ts +6 -19
  64. package/src/util/gloas.ts +49 -1
  65. package/lib/block/processExecutionPayloadEnvelope.d.ts +0 -9
  66. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +0 -1
  67. package/lib/block/processExecutionPayloadEnvelope.js +0 -106
  68. package/lib/block/processExecutionPayloadEnvelope.js.map +0 -1
  69. package/src/block/processExecutionPayloadEnvelope.ts +0 -175
@@ -158,6 +158,12 @@ export interface EpochTransitionCache {
158
158
  */
159
159
  nextShuffling: EpochShuffling | null;
160
160
 
161
+ /**
162
+ * Pre-computed PTC for epoch N + MIN_SEED_LOOKAHEAD + 1, populated by processPtcWindow (Gloas+).
163
+ * Used by finalProcessEpoch to shift PTC arrays in epoch cache without reading from state.
164
+ */
165
+ nextEpochPayloadTimelinessCommittees: Uint32Array[] | null;
166
+
161
167
  /**
162
168
  * Altair specific, this is total active balances for the next epoch.
163
169
  * This is only used in `afterProcessEpoch` to compute base reward and sync participant reward.
@@ -502,6 +508,7 @@ export function beforeProcessEpoch(
502
508
  indicesToEject,
503
509
  nextShufflingActiveIndices,
504
510
  nextShuffling: null,
511
+ nextEpochPayloadTimelinessCommittees: null,
505
512
  // to be updated in processEffectiveBalanceUpdates
506
513
  nextEpochTotalActiveBalanceByIncrement: 0,
507
514
  isActivePrevEpoch,
@@ -28,6 +28,7 @@ import {processParticipationRecordUpdates} from "./processParticipationRecordUpd
28
28
  import {processPendingConsolidations} from "./processPendingConsolidations.js";
29
29
  import {processPendingDeposits} from "./processPendingDeposits.js";
30
30
  import {processProposerLookahead} from "./processProposerLookahead.js";
31
+ import {processPtcWindow} from "./processPtcWindow.js";
31
32
  import {processRandaoMixesReset} from "./processRandaoMixesReset.js";
32
33
  import {processRegistryUpdates} from "./processRegistryUpdates.js";
33
34
  import {processRewardsAndPenalties} from "./processRewardsAndPenalties.js";
@@ -55,6 +56,7 @@ export {
55
56
  processPendingDeposits,
56
57
  processPendingConsolidations,
57
58
  processProposerLookahead,
59
+ processPtcWindow,
58
60
  processBuilderPendingPayments,
59
61
  };
60
62
 
@@ -81,6 +83,7 @@ export enum EpochTransitionStep {
81
83
  processPendingDeposits = "processPendingDeposits",
82
84
  processPendingConsolidations = "processPendingConsolidations",
83
85
  processProposerLookahead = "processProposerLookahead",
86
+ processPtcWindow = "processPtcWindow",
84
87
  processBuilderPendingPayments = "processBuilderPendingPayments",
85
88
  }
86
89
 
@@ -211,4 +214,10 @@ export function processEpoch(
211
214
  processProposerLookahead(fork, state as CachedBeaconStateFulu, cache);
212
215
  timer?.();
213
216
  }
217
+
218
+ if (fork >= ForkSeq.gloas) {
219
+ const timer = metrics?.epochTransitionStepTime.startTimer({step: EpochTransitionStep.processPtcWindow});
220
+ processPtcWindow(state as CachedBeaconStateGloas, cache);
221
+ timer?.();
222
+ }
214
223
  }
@@ -0,0 +1,38 @@
1
+ import {MIN_SEED_LOOKAHEAD} from "@lodestar/params";
2
+ import {ssz} from "@lodestar/types";
3
+ import {CachedBeaconStateGloas, EpochTransitionCache} from "../types.js";
4
+ import {computeEpochShuffling} from "../util/epochShuffling.js";
5
+ import {computePayloadTimelinessCommitteesForEpoch} from "../util/seed.js";
6
+
7
+ /**
8
+ * Update the `ptc_window` field in the beacon state by shifting out the oldest epoch's
9
+ * PTC entries and appending newly computed entries for the next lookahead epoch.
10
+ * Stashes the computed PTCs in the transition cache for finalProcessEpoch to shift
11
+ * into the epoch cache without reading from state.
12
+ *
13
+ * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.4/specs/gloas/beacon-chain.md#new-process_ptc_window
14
+ */
15
+ export function processPtcWindow(state: CachedBeaconStateGloas, cache: EpochTransitionCache): void {
16
+ const nextEpoch = state.epochCtx.epoch + MIN_SEED_LOOKAHEAD + 1;
17
+ const nextEpochShuffling =
18
+ cache.nextShuffling ?? computeEpochShuffling(state, cache.nextShufflingActiveIndices, nextEpoch);
19
+ cache.nextShuffling = nextEpochShuffling;
20
+
21
+ const newNextPayloadTimelinessCommittees = computePayloadTimelinessCommitteesForEpoch(
22
+ state,
23
+ nextEpoch,
24
+ nextEpochShuffling.committees,
25
+ state.epochCtx.effectiveBalanceIncrements
26
+ );
27
+
28
+ // Stash for finalProcessEpoch to shift into epoch cache
29
+ cache.nextEpochPayloadTimelinessCommittees = newNextPayloadTimelinessCommittees;
30
+
31
+ // Write shifted window to state: current(N) + next(N+1) + newlyComputed(N+2)
32
+ // From the perspective of upcoming epoch N+1, this is previous + current + next
33
+ state.ptcWindow = ssz.gloas.PtcWindow.toViewDU([
34
+ ...state.epochCtx.payloadTimelinessCommittees,
35
+ ...state.epochCtx.nextPayloadTimelinessCommittees,
36
+ ...newNextPayloadTimelinessCommittees,
37
+ ]);
38
+ }
@@ -11,7 +11,7 @@ export function getExecutionPayloadEnvelopeSigningRoot(
11
11
  config: BeaconConfig,
12
12
  envelope: gloas.ExecutionPayloadEnvelope
13
13
  ): Uint8Array {
14
- const domain = config.getDomain(envelope.slot, DOMAIN_BEACON_BUILDER);
14
+ const domain = config.getDomain(envelope.payload.slotNumber, DOMAIN_BEACON_BUILDER);
15
15
 
16
16
  return computeSigningRoot(ssz.gloas.ExecutionPayloadEnvelope, envelope, domain);
17
17
  }
@@ -5,7 +5,7 @@ import {isValidDepositSignature} from "../block/processDeposit.js";
5
5
  import {applyDepositForBuilder} from "../block/processDepositRequest.js";
6
6
  import {getCachedBeaconState} from "../cache/stateCache.js";
7
7
  import {CachedBeaconStateFulu, CachedBeaconStateGloas} from "../types.js";
8
- import {isBuilderWithdrawalCredential} from "../util/gloas.js";
8
+ import {initializePtcWindow, isBuilderWithdrawalCredential} from "../util/gloas.js";
9
9
  import {isValidatorKnown} from "../util/index.js";
10
10
 
11
11
  /**
@@ -48,6 +48,9 @@ export function upgradeStateToGloas(stateFulu: CachedBeaconStateFulu): CachedBea
48
48
  stateGloasView.currentSyncCommittee = stateGloasCloned.currentSyncCommittee;
49
49
  stateGloasView.nextSyncCommittee = stateGloasCloned.nextSyncCommittee;
50
50
  stateGloasView.latestExecutionPayloadBid.blockHash = stateFulu.latestExecutionPayloadHeader.blockHash;
51
+ stateGloasView.latestExecutionPayloadBid.executionRequestsRoot = ssz.electra.ExecutionRequests.hashTreeRoot(
52
+ ssz.electra.ExecutionRequests.defaultValue()
53
+ );
51
54
  stateGloasView.nextWithdrawalIndex = stateGloasCloned.nextWithdrawalIndex;
52
55
  stateGloasView.nextWithdrawalValidatorIndex = stateGloasCloned.nextWithdrawalValidatorIndex;
53
56
  stateGloasView.historicalSummaries = stateGloasCloned.historicalSummaries;
@@ -61,6 +64,7 @@ export function upgradeStateToGloas(stateFulu: CachedBeaconStateFulu): CachedBea
61
64
  stateGloasView.pendingPartialWithdrawals = stateGloasCloned.pendingPartialWithdrawals;
62
65
  stateGloasView.pendingConsolidations = stateGloasCloned.pendingConsolidations;
63
66
  stateGloasView.proposerLookahead = stateGloasCloned.proposerLookahead;
67
+ stateGloasView.ptcWindow = ssz.gloas.PtcWindow.toViewDU(initializePtcWindow(stateFulu));
64
68
 
65
69
  for (let i = 0; i < SLOTS_PER_HISTORICAL_ROOT; i++) {
66
70
  stateGloasView.executionPayloadAvailability.set(i, true);
@@ -282,7 +282,7 @@ function processSlotsWithTransientCache(
282
282
  {
283
283
  const timer = metrics?.epochTransitionStepTime.startTimer({step: EpochTransitionStep.finalProcessEpoch});
284
284
  // last step to prepare epoch data that depends on the upgraded state, for example proposerLookahead of BeaconStateFulu
285
- postState.epochCtx.finalProcessEpoch(postState);
285
+ postState.epochCtx.finalProcessEpoch(postState, epochTransitionCache);
286
286
  timer?.();
287
287
  }
288
288
 
@@ -1,7 +1,7 @@
1
1
  import {CompactMultiProof, ProofType, Tree, createProof} from "@chainsafe/persistent-merkle-tree";
2
2
  import {BitArray, ByteViews} from "@chainsafe/ssz";
3
3
  import {BeaconConfig} from "@lodestar/config";
4
- import {ForkName, ForkSeq, SLOTS_PER_HISTORICAL_ROOT, isForkPostGloas} from "@lodestar/params";
4
+ import {ForkName, ForkSeq, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
5
5
  import {
6
6
  BeaconBlock,
7
7
  BeaconState,
@@ -28,8 +28,7 @@ import {
28
28
  rewards,
29
29
  } from "@lodestar/types";
30
30
  import {Checkpoint, Fork} from "@lodestar/types/phase0";
31
- import {processExecutionPayloadEnvelope} from "../block/index.js";
32
- import {ProcessExecutionPayloadEnvelopeOpts} from "../block/processExecutionPayloadEnvelope.js";
31
+ import {applyParentExecutionPayload} from "../block/processParentExecutionPayload.js";
33
32
  import {VoluntaryExitValidity, getVoluntaryExitValidity} from "../block/processVoluntaryExit.js";
34
33
  import {getExpectedWithdrawals} from "../block/processWithdrawals.js";
35
34
  import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
@@ -704,7 +703,11 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
704
703
 
705
704
  // Serialization
706
705
 
707
- loadOtherState(stateBytes: Uint8Array, seedValidatorsBytes?: Uint8Array): IBeaconStateView {
706
+ loadOtherState(
707
+ stateBytes: Uint8Array,
708
+ seedValidatorsBytes?: Uint8Array,
709
+ opts?: {preloadValidatorsAndBalances?: boolean}
710
+ ): IBeaconStateView {
708
711
  const {state} = loadState(this.config, this.cachedState, stateBytes, seedValidatorsBytes);
709
712
 
710
713
  const cachedState = createCachedBeaconState(
@@ -719,9 +722,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
719
722
  }
720
723
  );
721
724
 
722
- // load all cache in order for consumers (usually regen.getState()) to process blocks faster
723
- cachedState.validators.getAllReadonlyValues();
724
- cachedState.balances.getAll();
725
+ if (opts?.preloadValidatorsAndBalances) {
726
+ cachedState.validators.getAllReadonlyValues();
727
+ cachedState.balances.getAll();
728
+ }
725
729
 
726
730
  return new BeaconStateView(cachedState);
727
731
  }
@@ -779,19 +783,19 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
779
783
  return new BeaconStateView(newState);
780
784
  }
781
785
 
782
- processExecutionPayloadEnvelope(
783
- signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
784
- opts?: ProcessExecutionPayloadEnvelopeOpts
785
- ): BeaconStateView {
786
- const fork = this.config.getForkName(this.cachedState.slot);
787
- if (!isForkPostGloas(fork)) {
788
- throw Error(`processExecutionPayloadEnvelope is only available for gloas+ forks, got fork=${fork}`);
786
+ /**
787
+ * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.5/specs/gloas/validator.md#executionpayload
788
+ */
789
+ getExpectedWithdrawalsForFullParent(executionRequests: electra.ExecutionRequests): capella.Withdrawal[] {
790
+ const fork = this.config.getForkSeq(this.cachedState.slot);
791
+ if (fork < ForkSeq.gloas) {
792
+ throw new Error("getExpectedWithdrawalsForFullParent is not available before Gloas");
789
793
  }
790
- const postPayloadState = processExecutionPayloadEnvelope(
791
- this.cachedState as CachedBeaconStateGloas,
792
- signedEnvelope,
793
- opts
794
- );
795
- return new BeaconStateView(postPayloadState);
794
+ // Make a copy of the state to avoid mutability issues
795
+ const stateCopy = this.cachedState.clone(true) as CachedBeaconStateGloas;
796
+ // Apply parent payload before computing withdrawals
797
+ applyParentExecutionPayload(stateCopy, executionRequests);
798
+
799
+ return getExpectedWithdrawals(fork, stateCopy).expectedWithdrawals;
796
800
  }
797
801
  }
@@ -41,7 +41,6 @@ import {
41
41
  rewards,
42
42
  } from "@lodestar/types";
43
43
  import {Checkpoint, Fork} from "@lodestar/types/phase0";
44
- import {ProcessExecutionPayloadEnvelopeOpts} from "../block/processExecutionPayloadEnvelope.js";
45
44
  import {VoluntaryExitValidity} from "../block/processVoluntaryExit.js";
46
45
  import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
47
46
  import {EpochTransitionCacheOpts} from "../cache/epochTransitionCache.js";
@@ -138,7 +137,13 @@ export interface IBeaconStateView {
138
137
  isStateValidatorsNodesPopulated(): boolean;
139
138
 
140
139
  // Serialization
141
- loadOtherState(stateBytes: Uint8Array, seedValidatorsBytes?: Uint8Array): IBeaconStateView;
140
+ /** Set `preloadValidatorsAndBalances` only when the whole state will be consumed
141
+ * immediately (e.g. CP reload before block replay). */
142
+ loadOtherState(
143
+ stateBytes: Uint8Array,
144
+ seedValidatorsBytes?: Uint8Array,
145
+ opts?: {preloadValidatorsAndBalances?: boolean}
146
+ ): IBeaconStateView;
142
147
  toValue(): BeaconState;
143
148
  serialize(): Uint8Array;
144
149
  serializedSize(): number;
@@ -248,10 +253,12 @@ export interface IBeaconStateViewGloas extends IBeaconStateViewFulu {
248
253
  getBuilder(index: BuilderIndex): gloas.Builder;
249
254
  canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
250
255
  getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number;
251
- processExecutionPayloadEnvelope(
252
- signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
253
- opts?: ProcessExecutionPayloadEnvelopeOpts
254
- ): IBeaconStateView;
256
+ /**
257
+ * Compute expected withdrawals as if the parent was FULL.
258
+ * Clones the state, applies parent payload effects, then computes withdrawals.
259
+ * Used by prepare_execution_payload when building on FULL parent.
260
+ */
261
+ getExpectedWithdrawalsForFullParent(executionRequests: electra.ExecutionRequests): capella.Withdrawal[];
255
262
  }
256
263
 
257
264
  /**
@@ -1,34 +1,21 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {GENESIS_SLOT, ZERO_HASH} from "@lodestar/params";
2
+ import {ZERO_HASH} from "@lodestar/params";
3
3
  import {phase0, ssz} from "@lodestar/types";
4
4
  import {BeaconStateAllForks} from "../types.js";
5
- import {blockToHeader} from "./blockRoot.js";
6
5
  import {computeCheckpointEpochAtStateSlot} from "./epoch.js";
7
6
 
8
7
  export function computeAnchorCheckpoint(
9
- config: ChainForkConfig,
8
+ _config: ChainForkConfig,
10
9
  anchorState: BeaconStateAllForks
11
10
  ): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader} {
12
- let blockHeader: phase0.BeaconBlockHeader;
13
- let root: Uint8Array;
14
- const blockTypes = config.getForkTypes(anchorState.latestBlockHeader.slot);
15
-
16
- if (anchorState.latestBlockHeader.slot === GENESIS_SLOT) {
17
- const block = blockTypes.BeaconBlock.defaultValue();
18
- block.stateRoot = anchorState.hashTreeRoot();
19
- blockHeader = blockToHeader(config, block);
20
- root = ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader);
21
- } else {
22
- blockHeader = ssz.phase0.BeaconBlockHeader.clone(anchorState.latestBlockHeader);
23
- if (ssz.Root.equals(blockHeader.stateRoot, ZERO_HASH)) {
24
- blockHeader.stateRoot = anchorState.hashTreeRoot();
25
- }
26
- root = ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader);
11
+ const blockHeader = ssz.phase0.BeaconBlockHeader.clone(anchorState.latestBlockHeader);
12
+ if (ssz.Root.equals(blockHeader.stateRoot, ZERO_HASH)) {
13
+ blockHeader.stateRoot = anchorState.hashTreeRoot();
27
14
  }
28
15
 
29
16
  return {
30
17
  checkpoint: {
31
- root,
18
+ root: ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader),
32
19
  // the checkpoint epoch = computeEpochAtSlot(anchorState.slot) + 1 if slot is not at epoch boundary
33
20
  // this is similar to a process_slots() call
34
21
  epoch: computeCheckpointEpochAtStateSlot(anchorState.slot),
package/src/util/gloas.ts CHANGED
@@ -6,15 +6,20 @@ import {
6
6
  EFFECTIVE_BALANCE_INCREMENT,
7
7
  FAR_FUTURE_EPOCH,
8
8
  MIN_DEPOSIT_AMOUNT,
9
+ MIN_SEED_LOOKAHEAD,
10
+ PTC_SIZE,
9
11
  SLOTS_PER_EPOCH,
10
12
  } from "@lodestar/params";
11
13
  import {BuilderIndex, Epoch, ValidatorIndex, gloas} from "@lodestar/types";
12
14
  import {AttestationData} from "@lodestar/types/phase0";
13
15
  import {byteArrayEquals} from "@lodestar/utils";
14
- import {CachedBeaconStateGloas} from "../types.js";
16
+ import {CachedBeaconStateFulu, CachedBeaconStateGloas} from "../types.js";
15
17
  import {getBlockRootAtSlot} from "./blockRoot.js";
16
18
  import {computeEpochAtSlot} from "./epoch.js";
19
+ import {computeEpochShuffling} from "./epochShuffling.js";
17
20
  import {RootCache} from "./rootCache.js";
21
+ import {computePayloadTimelinessCommitteesForEpoch} from "./seed.js";
22
+ import {getActiveValidatorIndices} from "./validator.js";
18
23
 
19
24
  export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
20
25
  return withdrawalCredentials[0] === BUILDER_WITHDRAWAL_PREFIX;
@@ -167,6 +172,49 @@ export function isAttestationSameSlotRootCache(rootCache: RootCache, data: Attes
167
172
  return isMatchingBlockRoot && isCurrentBlockRoot;
168
173
  }
169
174
 
175
+ // TODO GLOAS: This function no longer exists in v1.7.0-alpha.5 specs. Remove it when appropriate to do so
170
176
  export function isParentBlockFull(state: CachedBeaconStateGloas): boolean {
171
177
  return byteArrayEquals(state.latestExecutionPayloadBid.blockHash, state.latestBlockHash);
172
178
  }
179
+
180
+ export function initializePtcWindow(state: CachedBeaconStateFulu): Uint32Array[] {
181
+ const ptcWindow: Uint32Array[] = Array.from({length: SLOTS_PER_EPOCH}, () => new Uint32Array(PTC_SIZE));
182
+ const currentEpoch = state.epochCtx.epoch;
183
+
184
+ for (let epochOffset = 0; epochOffset <= MIN_SEED_LOOKAHEAD; epochOffset++) {
185
+ const epoch = currentEpoch + epochOffset;
186
+ const shuffling =
187
+ state.epochCtx.getShufflingAtEpochOrNull(epoch) ??
188
+ computeEpochShuffling(state, getActiveValidatorIndices(state, epoch), epoch);
189
+
190
+ ptcWindow.push(
191
+ ...computePayloadTimelinessCommitteesForEpoch(
192
+ state,
193
+ epoch,
194
+ shuffling.committees,
195
+ state.epochCtx.effectiveBalanceIncrements
196
+ )
197
+ );
198
+ }
199
+
200
+ return ptcWindow;
201
+ }
202
+
203
+ export function getPtcWindowEpochCacheData(state: CachedBeaconStateGloas): {
204
+ previousPayloadTimelinessCommittees: Uint32Array[];
205
+ payloadTimelinessCommittees: Uint32Array[];
206
+ nextPayloadTimelinessCommittees: Uint32Array[];
207
+ } {
208
+ const toUint32Arrays = (views: ReturnType<typeof state.ptcWindow.getReadonlyByRange>) =>
209
+ views.map((v) => Uint32Array.from(v.getAll()));
210
+
211
+ const previousPtcWindow = state.ptcWindow.getReadonlyByRange(0, SLOTS_PER_EPOCH);
212
+ const currentPtcWindow = state.ptcWindow.getReadonlyByRange(SLOTS_PER_EPOCH, SLOTS_PER_EPOCH);
213
+ const nextPtcWindow = state.ptcWindow.getReadonlyByRange(2 * SLOTS_PER_EPOCH, SLOTS_PER_EPOCH);
214
+
215
+ return {
216
+ previousPayloadTimelinessCommittees: toUint32Arrays(previousPtcWindow),
217
+ payloadTimelinessCommittees: toUint32Arrays(currentPtcWindow),
218
+ nextPayloadTimelinessCommittees: toUint32Arrays(nextPtcWindow),
219
+ };
220
+ }
@@ -1,9 +0,0 @@
1
- import { gloas } from "@lodestar/types";
2
- import { CachedBeaconStateGloas } from "../types.js";
3
- export type ProcessExecutionPayloadEnvelopeOpts = {
4
- verifySignature?: boolean;
5
- verifyStateRoot?: boolean;
6
- dontTransferCache?: boolean;
7
- };
8
- export declare function processExecutionPayloadEnvelope(state: CachedBeaconStateGloas, signedEnvelope: gloas.SignedExecutionPayloadEnvelope, opts?: ProcessExecutionPayloadEnvelopeOpts): CachedBeaconStateGloas;
9
- //# sourceMappingURL=processExecutionPayloadEnvelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"processExecutionPayloadEnvelope.d.ts","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAM,MAAM,iBAAiB,CAAC;AAI3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAOnD,MAAM,MAAM,mCAAmC,GAAG;IAChD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAKF,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,sBAAsB,EAC7B,cAAc,EAAE,KAAK,CAAC,8BAA8B,EACpD,IAAI,CAAC,EAAE,mCAAmC,GACzC,sBAAsB,CA0DxB"}
@@ -1,106 +0,0 @@
1
- import { SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT } from "@lodestar/params";
2
- import { ssz } from "@lodestar/types";
3
- import { byteArrayEquals, toHex, toRootHex } from "@lodestar/utils";
4
- import { getExecutionPayloadEnvelopeSignatureSet } from "../signatureSets/executionPayloadEnvelope.js";
5
- import { BeaconStateView } from "../stateView/beaconStateView.js";
6
- import { computeTimeAtSlot } from "../util/index.js";
7
- import { verifySignatureSet } from "../util/signatureSets.js";
8
- import { processConsolidationRequest } from "./processConsolidationRequest.js";
9
- import { getPendingValidatorPubkeys, processDepositRequest } from "./processDepositRequest.js";
10
- import { processWithdrawalRequest } from "./processWithdrawalRequest.js";
11
- // Unlike other block processing functions which mutate state in-place, this function
12
- // clones the state and returns the post-state, similar to stateTransition().
13
- // This function does not call execution engine to verify payload. Need to call it from other place.
14
- export function processExecutionPayloadEnvelope(state, signedEnvelope, opts) {
15
- const { verifySignature = true, verifyStateRoot = true } = opts ?? {};
16
- const envelope = signedEnvelope.message;
17
- const payload = envelope.payload;
18
- const fork = state.config.getForkSeq(envelope.slot);
19
- if (verifySignature && !verifyExecutionPayloadEnvelopeSignature(state, signedEnvelope)) {
20
- throw Error(`Execution payload envelope has invalid signature builderIndex=${envelope.builderIndex}`);
21
- }
22
- // .clone() before mutating state, similar to stateTransition()
23
- const postState = state.clone(opts?.dontTransferCache);
24
- validateExecutionPayloadEnvelope(postState, envelope);
25
- const requests = envelope.executionRequests;
26
- if (requests.deposits.length > 0) {
27
- // Build cache of pending validator pubkeys once, shared across all deposit requests
28
- const pendingValidatorPubkeys = getPendingValidatorPubkeys(postState.config, postState);
29
- for (const deposit of requests.deposits) {
30
- processDepositRequest(fork, postState, deposit, pendingValidatorPubkeys);
31
- }
32
- }
33
- for (const withdrawal of requests.withdrawals) {
34
- processWithdrawalRequest(fork, postState, withdrawal);
35
- }
36
- for (const consolidation of requests.consolidations) {
37
- processConsolidationRequest(postState, consolidation);
38
- }
39
- // Queue the builder payment
40
- const paymentIndex = SLOTS_PER_EPOCH + (postState.slot % SLOTS_PER_EPOCH);
41
- const payment = postState.builderPendingPayments.get(paymentIndex).clone();
42
- const amount = payment.withdrawal.amount;
43
- if (amount > 0) {
44
- postState.builderPendingWithdrawals.push(payment.withdrawal);
45
- }
46
- postState.builderPendingPayments.set(paymentIndex, ssz.gloas.BuilderPendingPayment.defaultViewDU());
47
- // Cache the execution payload hash
48
- postState.executionPayloadAvailability.set(postState.slot % SLOTS_PER_HISTORICAL_ROOT, true);
49
- postState.latestBlockHash = payload.blockHash;
50
- postState.commit();
51
- if (verifyStateRoot && !byteArrayEquals(envelope.stateRoot, postState.hashTreeRoot())) {
52
- throw new Error(`Envelope's state root does not match state envelope=${toRootHex(envelope.stateRoot)} state=${toRootHex(postState.hashTreeRoot())}`);
53
- }
54
- return postState;
55
- }
56
- function validateExecutionPayloadEnvelope(state, envelope) {
57
- const payload = envelope.payload;
58
- // Cache latest block header state root
59
- if (byteArrayEquals(state.latestBlockHeader.stateRoot, ssz.Root.defaultValue())) {
60
- const previousStateRoot = state.hashTreeRoot();
61
- state.latestBlockHeader.stateRoot = previousStateRoot;
62
- }
63
- // Verify consistency with the beacon block
64
- if (!byteArrayEquals(envelope.beaconBlockRoot, state.latestBlockHeader.hashTreeRoot())) {
65
- throw new Error(`Envelope's block is not the latest block header envelope=${toRootHex(envelope.beaconBlockRoot)} latestBlockHeader=${toRootHex(state.latestBlockHeader.hashTreeRoot())}`);
66
- }
67
- if (envelope.slot !== state.slot) {
68
- throw new Error(`Slot mismatch between envelope and state envelope=${envelope.slot} state=${state.slot}`);
69
- }
70
- // Verify consistency with the committed bid
71
- const committedBid = state.latestExecutionPayloadBid;
72
- if (envelope.builderIndex !== committedBid.builderIndex) {
73
- throw new Error(`Builder index mismatch between envelope and committed bid envelope=${envelope.builderIndex} committedBid=${committedBid.builderIndex}`);
74
- }
75
- if (!byteArrayEquals(committedBid.prevRandao, payload.prevRandao)) {
76
- throw new Error(`Prev randao mismatch between committed bid and payload committedBid=${toHex(committedBid.prevRandao)} payload=${toHex(payload.prevRandao)}`);
77
- }
78
- // Verify consistency with expected withdrawals
79
- const payloadWithdrawalsRoot = ssz.capella.Withdrawals.hashTreeRoot(payload.withdrawals);
80
- const expectedWithdrawalsRoot = state.payloadExpectedWithdrawals.hashTreeRoot();
81
- if (!byteArrayEquals(payloadWithdrawalsRoot, expectedWithdrawalsRoot)) {
82
- throw new Error(`Withdrawals mismatch between payload and expected withdrawals payload=${toRootHex(payloadWithdrawalsRoot)} expected=${toRootHex(expectedWithdrawalsRoot)}`);
83
- }
84
- // Verify the gas_limit
85
- if (Number(committedBid.gasLimit) !== payload.gasLimit) {
86
- throw new Error(`Gas limit mismatch between envelope's payload and committed bid envelope=${payload.gasLimit} committedBid=${Number(committedBid.gasLimit)}`);
87
- }
88
- // Verify the block hash
89
- if (!byteArrayEquals(committedBid.blockHash, payload.blockHash)) {
90
- throw new Error(`Block hash mismatch between envelope's payload and committed bid envelope=${toRootHex(payload.blockHash)} committedBid=${toRootHex(committedBid.blockHash)}`);
91
- }
92
- // Verify consistency of the parent hash with respect to the previous execution payload
93
- if (!byteArrayEquals(payload.parentHash, state.latestBlockHash)) {
94
- throw new Error(`Parent hash mismatch between envelope's payload and state envelope=${toRootHex(payload.parentHash)} state=${toRootHex(state.latestBlockHash)}`);
95
- }
96
- // Verify timestamp
97
- if (payload.timestamp !== computeTimeAtSlot(state.config, state.slot, state.genesisTime)) {
98
- throw new Error(`Timestamp mismatch between envelope's payload and state envelope=${payload.timestamp} state=${computeTimeAtSlot(state.config, state.slot, state.genesisTime)}`);
99
- }
100
- // Skipped: Verify the execution payload is valid
101
- }
102
- function verifyExecutionPayloadEnvelopeSignature(state, signedEnvelope) {
103
- const signatureSet = getExecutionPayloadEnvelopeSignatureSet(state.config, state.epochCtx.pubkeyCache, new BeaconStateView(state), signedEnvelope, state.latestBlockHeader.proposerIndex);
104
- return verifySignatureSet(signatureSet);
105
- }
106
- //# sourceMappingURL=processExecutionPayloadEnvelope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"processExecutionPayloadEnvelope.js","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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