@lodestar/state-transition 1.42.0 → 1.43.0-dev.0bc48d3b54

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 (78) hide show
  1. package/lib/block/processDepositRequest.d.ts +11 -2
  2. package/lib/block/processDepositRequest.d.ts.map +1 -1
  3. package/lib/block/processDepositRequest.js +34 -4
  4. package/lib/block/processDepositRequest.js.map +1 -1
  5. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
  6. package/lib/block/processExecutionPayloadEnvelope.js +7 -3
  7. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
  8. package/lib/cache/epochCache.d.ts +3 -1
  9. package/lib/cache/epochCache.d.ts.map +1 -1
  10. package/lib/cache/epochCache.js +31 -13
  11. package/lib/cache/epochCache.js.map +1 -1
  12. package/lib/cache/epochTransitionCache.d.ts +5 -0
  13. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  14. package/lib/cache/epochTransitionCache.js +1 -0
  15. package/lib/cache/epochTransitionCache.js.map +1 -1
  16. package/lib/epoch/index.d.ts +3 -1
  17. package/lib/epoch/index.d.ts.map +1 -1
  18. package/lib/epoch/index.js +8 -1
  19. package/lib/epoch/index.js.map +1 -1
  20. package/lib/epoch/processPtcWindow.d.ts +11 -0
  21. package/lib/epoch/processPtcWindow.d.ts.map +1 -0
  22. package/lib/epoch/processPtcWindow.js +28 -0
  23. package/lib/epoch/processPtcWindow.js.map +1 -0
  24. package/lib/index.d.ts +4 -2
  25. package/lib/index.d.ts.map +1 -1
  26. package/lib/index.js +4 -1
  27. package/lib/index.js.map +1 -1
  28. package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -1
  29. package/lib/signatureSets/executionPayloadEnvelope.js +4 -0
  30. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
  31. package/lib/signatureSets/voluntaryExits.d.ts +2 -2
  32. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  33. package/lib/signatureSets/voluntaryExits.js +4 -0
  34. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  35. package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
  36. package/lib/slot/upgradeStateToGloas.js +2 -1
  37. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  38. package/lib/stateTransition.d.ts +1 -2
  39. package/lib/stateTransition.d.ts.map +1 -1
  40. package/lib/stateTransition.js +1 -2
  41. package/lib/stateTransition.js.map +1 -1
  42. package/lib/stateView/beaconStateView.d.ts +10 -10
  43. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  44. package/lib/stateView/beaconStateView.js +37 -34
  45. package/lib/stateView/beaconStateView.js.map +1 -1
  46. package/lib/stateView/interface.d.ts +103 -52
  47. package/lib/stateView/interface.d.ts.map +1 -1
  48. package/lib/stateView/interface.js +22 -1
  49. package/lib/stateView/interface.js.map +1 -1
  50. package/lib/util/attestation.d.ts +12 -1
  51. package/lib/util/attestation.d.ts.map +1 -1
  52. package/lib/util/attestation.js +23 -8
  53. package/lib/util/attestation.js.map +1 -1
  54. package/lib/util/execution.d.ts +4 -2
  55. package/lib/util/execution.d.ts.map +1 -1
  56. package/lib/util/execution.js +7 -0
  57. package/lib/util/execution.js.map +1 -1
  58. package/lib/util/gloas.d.ts +7 -1
  59. package/lib/util/gloas.d.ts.map +1 -1
  60. package/lib/util/gloas.js +26 -1
  61. package/lib/util/gloas.js.map +1 -1
  62. package/package.json +8 -8
  63. package/src/block/processDepositRequest.ts +50 -5
  64. package/src/block/processExecutionPayloadEnvelope.ts +8 -3
  65. package/src/cache/epochCache.ts +32 -30
  66. package/src/cache/epochTransitionCache.ts +7 -0
  67. package/src/epoch/index.ts +9 -0
  68. package/src/epoch/processPtcWindow.ts +38 -0
  69. package/src/index.ts +20 -2
  70. package/src/signatureSets/executionPayloadEnvelope.ts +5 -1
  71. package/src/signatureSets/voluntaryExits.ts +5 -2
  72. package/src/slot/upgradeStateToGloas.ts +2 -1
  73. package/src/stateTransition.ts +1 -2
  74. package/src/stateView/beaconStateView.ts +57 -41
  75. package/src/stateView/interface.ts +155 -74
  76. package/src/util/attestation.ts +37 -8
  77. package/src/util/execution.ts +11 -1
  78. package/src/util/gloas.ts +48 -1
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;
@@ -170,3 +175,45 @@ export function isAttestationSameSlotRootCache(rootCache: RootCache, data: Attes
170
175
  export function isParentBlockFull(state: CachedBeaconStateGloas): boolean {
171
176
  return byteArrayEquals(state.latestExecutionPayloadBid.blockHash, state.latestBlockHash);
172
177
  }
178
+
179
+ export function initializePtcWindow(state: CachedBeaconStateFulu): Uint32Array[] {
180
+ const ptcWindow: Uint32Array[] = Array.from({length: SLOTS_PER_EPOCH}, () => new Uint32Array(PTC_SIZE));
181
+ const currentEpoch = state.epochCtx.epoch;
182
+
183
+ for (let epochOffset = 0; epochOffset <= MIN_SEED_LOOKAHEAD; epochOffset++) {
184
+ const epoch = currentEpoch + epochOffset;
185
+ const shuffling =
186
+ state.epochCtx.getShufflingAtEpochOrNull(epoch) ??
187
+ computeEpochShuffling(state, getActiveValidatorIndices(state, epoch), epoch);
188
+
189
+ ptcWindow.push(
190
+ ...computePayloadTimelinessCommitteesForEpoch(
191
+ state,
192
+ epoch,
193
+ shuffling.committees,
194
+ state.epochCtx.effectiveBalanceIncrements
195
+ )
196
+ );
197
+ }
198
+
199
+ return ptcWindow;
200
+ }
201
+
202
+ export function getPtcWindowEpochCacheData(state: CachedBeaconStateGloas): {
203
+ previousPayloadTimelinessCommittees: Uint32Array[];
204
+ payloadTimelinessCommittees: Uint32Array[];
205
+ nextPayloadTimelinessCommittees: Uint32Array[];
206
+ } {
207
+ const toUint32Arrays = (views: ReturnType<typeof state.ptcWindow.getReadonlyByRange>) =>
208
+ views.map((v) => Uint32Array.from(v.getAll()));
209
+
210
+ const previousPtcWindow = state.ptcWindow.getReadonlyByRange(0, SLOTS_PER_EPOCH);
211
+ const currentPtcWindow = state.ptcWindow.getReadonlyByRange(SLOTS_PER_EPOCH, SLOTS_PER_EPOCH);
212
+ const nextPtcWindow = state.ptcWindow.getReadonlyByRange(2 * SLOTS_PER_EPOCH, SLOTS_PER_EPOCH);
213
+
214
+ return {
215
+ previousPayloadTimelinessCommittees: toUint32Arrays(previousPtcWindow),
216
+ payloadTimelinessCommittees: toUint32Arrays(currentPtcWindow),
217
+ nextPayloadTimelinessCommittees: toUint32Arrays(nextPtcWindow),
218
+ };
219
+ }