@lodestar/state-transition 1.51.0-dev.2593063a82 → 1.51.0-dev.312812503e

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 (94) hide show
  1. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  2. package/lib/block/processAttestationsAltair.js +3 -1
  3. package/lib/block/processAttestationsAltair.js.map +1 -1
  4. package/lib/cache/epochCache.d.ts +3 -0
  5. package/lib/cache/epochCache.d.ts.map +1 -1
  6. package/lib/cache/epochCache.js +11 -4
  7. package/lib/cache/epochCache.js.map +1 -1
  8. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  9. package/lib/cache/epochTransitionCache.js +2 -1
  10. package/lib/cache/epochTransitionCache.js.map +1 -1
  11. package/lib/epoch/getRewardsAndPenalties.d.ts.map +1 -1
  12. package/lib/epoch/getRewardsAndPenalties.js +9 -2
  13. package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
  14. package/lib/metrics.d.ts +1 -1
  15. package/lib/metrics.d.ts.map +1 -1
  16. package/lib/metrics.js +4 -4
  17. package/lib/metrics.js.map +1 -1
  18. package/lib/rewards/attestationsRewards.d.ts.map +1 -1
  19. package/lib/rewards/attestationsRewards.js +10 -3
  20. package/lib/rewards/attestationsRewards.js.map +1 -1
  21. package/lib/signatureSets/inclusionList.d.ts +5 -0
  22. package/lib/signatureSets/inclusionList.d.ts.map +1 -0
  23. package/lib/signatureSets/inclusionList.js +14 -0
  24. package/lib/signatureSets/inclusionList.js.map +1 -0
  25. package/lib/signatureSets/index.d.ts +1 -0
  26. package/lib/signatureSets/index.d.ts.map +1 -1
  27. package/lib/signatureSets/index.js +1 -0
  28. package/lib/signatureSets/index.js.map +1 -1
  29. package/lib/stateTransition.js +2 -2
  30. package/lib/stateTransition.js.map +1 -1
  31. package/lib/stateView/interface.d.ts +2 -4
  32. package/lib/stateView/interface.d.ts.map +1 -1
  33. package/lib/stateView/interface.js.map +1 -1
  34. package/lib/stateView/nativeBeaconStateView.d.ts +14 -6
  35. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  36. package/lib/stateView/nativeBeaconStateView.js +85 -25
  37. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  38. package/lib/stateView/stateViewFactory.js +3 -2
  39. package/lib/stateView/stateViewFactory.js.map +1 -1
  40. package/lib/util/altair.d.ts +3 -1
  41. package/lib/util/altair.d.ts.map +1 -1
  42. package/lib/util/altair.js +7 -4
  43. package/lib/util/altair.js.map +1 -1
  44. package/lib/util/clock.js +1 -1
  45. package/lib/util/clock.js.map +1 -1
  46. package/lib/util/inclusionListCommittee.d.ts +9 -0
  47. package/lib/util/inclusionListCommittee.d.ts.map +1 -0
  48. package/lib/util/inclusionListCommittee.js +18 -0
  49. package/lib/util/inclusionListCommittee.js.map +1 -0
  50. package/lib/util/index.d.ts +1 -0
  51. package/lib/util/index.d.ts.map +1 -1
  52. package/lib/util/index.js +1 -0
  53. package/lib/util/index.js.map +1 -1
  54. package/lib/util/shuffling.d.ts +3 -0
  55. package/lib/util/shuffling.d.ts.map +1 -1
  56. package/lib/util/shuffling.js +41 -1
  57. package/lib/util/shuffling.js.map +1 -1
  58. package/lib/util/slot.d.ts +15 -1
  59. package/lib/util/slot.d.ts.map +1 -1
  60. package/lib/util/slot.js +66 -6
  61. package/lib/util/slot.js.map +1 -1
  62. package/lib/util/syncCommittee.d.ts +4 -3
  63. package/lib/util/syncCommittee.d.ts.map +1 -1
  64. package/lib/util/syncCommittee.js +9 -7
  65. package/lib/util/syncCommittee.js.map +1 -1
  66. package/lib/util/validator.d.ts +1 -1
  67. package/lib/util/validator.d.ts.map +1 -1
  68. package/lib/util/validator.js +32 -11
  69. package/lib/util/validator.js.map +1 -1
  70. package/lib/util/weakSubjectivity.d.ts.map +1 -1
  71. package/lib/util/weakSubjectivity.js +4 -3
  72. package/lib/util/weakSubjectivity.js.map +1 -1
  73. package/package.json +8 -8
  74. package/src/block/processAttestationsAltair.ts +4 -1
  75. package/src/cache/epochCache.ts +28 -4
  76. package/src/cache/epochTransitionCache.ts +2 -1
  77. package/src/epoch/getRewardsAndPenalties.ts +11 -1
  78. package/src/metrics.ts +5 -4
  79. package/src/rewards/attestationsRewards.ts +12 -1
  80. package/src/signatureSets/inclusionList.ts +20 -0
  81. package/src/signatureSets/index.ts +1 -0
  82. package/src/stateTransition.ts +2 -2
  83. package/src/stateView/interface.ts +1 -10
  84. package/src/stateView/nativeBeaconStateView.ts +86 -29
  85. package/src/stateView/stateViewFactory.ts +3 -2
  86. package/src/util/altair.ts +15 -4
  87. package/src/util/clock.ts +1 -1
  88. package/src/util/inclusionListCommittee.ts +17 -0
  89. package/src/util/index.ts +1 -0
  90. package/src/util/shuffling.ts +46 -1
  91. package/src/util/slot.ts +72 -7
  92. package/src/util/syncCommittee.ts +21 -9
  93. package/src/util/validator.ts +47 -20
  94. package/src/util/weakSubjectivity.ts +3 -3
@@ -1,7 +1,8 @@
1
- import { EFFECTIVE_BALANCE_INCREMENT, ForkSeq, GENESIS_SLOT, MAX_DEPOSITS, MAX_EFFECTIVE_BALANCE, SLOTS_PER_EPOCH, isForkPostElectra, isForkPostGloas, } from "@lodestar/params";
1
+ import { EFFECTIVE_BALANCE_INCREMENT, ForkSeq, MAX_DEPOSITS, MAX_EFFECTIVE_BALANCE, SLOTS_PER_EPOCH, isForkPostElectra, isForkPostGloas, } from "@lodestar/params";
2
2
  import { ssz } from "@lodestar/types";
3
3
  import { ZERO_HASH } from "../constants/constants.js";
4
4
  import { computeCheckpointEpochAtStateSlot, computeEpochAtSlot, getCurrentEpoch } from "./epoch.js";
5
+ import { computeSlotAtTimeMs } from "./slot.js";
5
6
  import { getStateTypeFromBytes, scanActiveValidatorsFromStateBytes } from "./sszBytes.js";
6
7
  import { getActivationChurnLimit, getActiveValidatorIndices, getBalanceChurnLimit, getBalanceChurnLimitFromCache, getChurnLimit, getConsolidationChurnLimit, getExitChurnLimit, getGloasChurnLimits, } from "./validator.js";
7
8
  export const ETH_TO_GWEI = 10 ** 9;
@@ -50,7 +51,7 @@ export function computeWeakSubjectivityPeriod(config, state) {
50
51
  }
51
52
  function computeWeakSubjectivityPeriodFromActiveValidators(config, slot, { activeValidatorCount, totalActiveBalanceIncrements, }) {
52
53
  const fork = config.getForkName(slot);
53
- const churnLimitsGloas = getGloasChurnLimits(config, totalActiveBalanceIncrements);
54
+ const churnLimitsGloas = getGloasChurnLimits(config, computeEpochAtSlot(slot), totalActiveBalanceIncrements);
54
55
  return isForkPostGloas(fork)
55
56
  ? computeWeakSubjectivityPeriodFromConstituentsGloas(totalActiveBalanceIncrements, churnLimitsGloas.exit, churnLimitsGloas.activation, churnLimitsGloas.consolidation, config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY)
56
57
  : isForkPostElectra(fork)
@@ -113,7 +114,7 @@ export function computeWeakSubjectivitySummaryFromStateBytes(config, bytes, meta
113
114
  return { checkpointEpoch: computeCheckpointEpochAtStateSlot(slot), genesisTime, period };
114
115
  }
115
116
  export function isWithinWeakSubjectivityPeriodFromSummary(config, summary, now = Date.now() / 1000) {
116
- const clockSlot = GENESIS_SLOT + Math.floor((now - summary.genesisTime) / (config.SLOT_DURATION_MS / 1000));
117
+ const clockSlot = computeSlotAtTimeMs(config, now * 1000, summary.genesisTime * 1000);
117
118
  return computeEpochAtSlot(clockSlot) <= summary.checkpointEpoch + summary.period;
118
119
  }
119
120
  //# sourceMappingURL=weakSubjectivity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"weakSubjectivity.js","sourceRoot":"","sources":["../../src/util/weakSubjectivity.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAiC,GAAG,EAAC,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AA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B,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;AACnF,CAAC"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.51.0-dev.2593063a82",
14
+ "version": "1.51.0-dev.312812503e",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -68,15 +68,15 @@
68
68
  "@chainsafe/as-sha256": "^1.2.5",
69
69
  "@chainsafe/lodestar-z": "catalog:",
70
70
  "@chainsafe/persistent-merkle-tree": "^1.3.1",
71
- "@chainsafe/ssz": "^1.8.1",
72
- "@lodestar/config": "^1.51.0-dev.2593063a82",
73
- "@lodestar/params": "^1.51.0-dev.2593063a82",
74
- "@lodestar/types": "^1.51.0-dev.2593063a82",
75
- "@lodestar/utils": "^1.51.0-dev.2593063a82",
71
+ "@chainsafe/ssz": "^1.9.0",
72
+ "@lodestar/config": "^1.51.0-dev.312812503e",
73
+ "@lodestar/params": "^1.51.0-dev.312812503e",
74
+ "@lodestar/types": "^1.51.0-dev.312812503e",
75
+ "@lodestar/utils": "^1.51.0-dev.312812503e",
76
76
  "@vekexasia/bigint-buffer2": "^1.1.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@lodestar/test-utils": "^1.51.0-dev.2593063a82"
79
+ "@lodestar/test-utils": "^1.51.0-dev.312812503e"
80
80
  },
81
81
  "keywords": [
82
82
  "ethereum",
@@ -84,5 +84,5 @@
84
84
  "beacon",
85
85
  "blockchain"
86
86
  ],
87
- "gitHead": "9ef629e5938036e197e32f9dd5c99eeeb89a9e48"
87
+ "gitHead": "dc14bc73022c16b7b25771faea254b6202d1883a"
88
88
  }
@@ -141,7 +141,10 @@ export function processAttestationsAltair(
141
141
 
142
142
  // Do the discrete math inside the loop to ensure a deterministic result
143
143
  const totalIncrements = totalBalanceIncrementsWithWeight;
144
- const proposerRewardNumerator = totalIncrements * state.epochCtx.baseRewardPerIncrement;
144
+ // The proposer reward is priced at the attestation's target epoch
145
+ const proposerRewardNumerator =
146
+ totalIncrements *
147
+ (inCurrentEpoch ? state.epochCtx.baseRewardPerIncrement : state.epochCtx.baseRewardPerIncrementPrevEpoch);
145
148
  proposerReward += Math.floor(proposerRewardNumerator / PROPOSER_REWARD_DOMINATOR);
146
149
 
147
150
  if (fork >= ForkSeq.gloas) {
@@ -178,6 +178,8 @@ export class EpochCache {
178
178
  * Update freq: once per epoch after `process_effective_balance_updates()`
179
179
  */
180
180
  baseRewardPerIncrement: number;
181
+ /** As baseRewardPerIncrement but priced at the previous epoch's slot duration */
182
+ baseRewardPerIncrementPrevEpoch: number;
181
183
  /**
182
184
  * Total active balance for current epoch, to be used instead of getTotalBalance()
183
185
  */
@@ -269,6 +271,7 @@ export class EpochCache {
269
271
  syncParticipantReward: number;
270
272
  syncProposerReward: number;
271
273
  baseRewardPerIncrement: number;
274
+ baseRewardPerIncrementPrevEpoch: number;
272
275
  totalActiveBalanceIncrements: number;
273
276
  churnLimit: number;
274
277
  activationChurnLimit: number;
@@ -302,6 +305,7 @@ export class EpochCache {
302
305
  this.syncParticipantReward = data.syncParticipantReward;
303
306
  this.syncProposerReward = data.syncProposerReward;
304
307
  this.baseRewardPerIncrement = data.baseRewardPerIncrement;
308
+ this.baseRewardPerIncrementPrevEpoch = data.baseRewardPerIncrementPrevEpoch;
305
309
  this.totalActiveBalanceIncrements = data.totalActiveBalanceIncrements;
306
310
  this.churnLimit = data.churnLimit;
307
311
  this.activationChurnLimit = data.activationChurnLimit;
@@ -452,9 +456,14 @@ export class EpochCache {
452
456
 
453
457
  // Values syncParticipantReward, syncProposerReward, baseRewardPerIncrement are only used after altair.
454
458
  // However, since they are very cheap to compute they are computed always to simplify upgradeState function.
455
- const syncParticipantReward = computeSyncParticipantReward(totalActiveBalanceIncrements);
459
+ const syncParticipantReward = computeSyncParticipantReward(config, currentEpoch, totalActiveBalanceIncrements);
456
460
  const syncProposerReward = Math.floor(syncParticipantReward * PROPOSER_WEIGHT_FACTOR);
457
- const baseRewardPerIncrement = computeBaseRewardPerIncrement(totalActiveBalanceIncrements);
461
+ const baseRewardPerIncrement = computeBaseRewardPerIncrement(config, currentEpoch, totalActiveBalanceIncrements);
462
+ const baseRewardPerIncrementPrevEpoch = computeBaseRewardPerIncrement(
463
+ config,
464
+ Math.max(currentEpoch - 1, GENESIS_EPOCH),
465
+ totalActiveBalanceIncrements
466
+ );
458
467
 
459
468
  let currentSyncCommitteeIndexed: SyncCommitteeCache;
460
469
  let nextSyncCommitteeIndexed: SyncCommitteeCache;
@@ -542,6 +551,7 @@ export class EpochCache {
542
551
  syncParticipantReward,
543
552
  syncProposerReward,
544
553
  baseRewardPerIncrement,
554
+ baseRewardPerIncrementPrevEpoch,
545
555
  totalActiveBalanceIncrements,
546
556
  churnLimit,
547
557
  activationChurnLimit,
@@ -591,6 +601,7 @@ export class EpochCache {
591
601
  syncParticipantReward: this.syncParticipantReward,
592
602
  syncProposerReward: this.syncProposerReward,
593
603
  baseRewardPerIncrement: this.baseRewardPerIncrement,
604
+ baseRewardPerIncrementPrevEpoch: this.baseRewardPerIncrementPrevEpoch,
594
605
  totalActiveBalanceIncrements: this.totalActiveBalanceIncrements,
595
606
  churnLimit: this.churnLimit,
596
607
  activationChurnLimit: this.activationChurnLimit,
@@ -685,9 +696,22 @@ export class EpochCache {
685
696
 
686
697
  this.totalActiveBalanceIncrements = epochTransitionCache.nextEpochTotalActiveBalanceByIncrement;
687
698
  if (upcomingEpoch >= this.config.ALTAIR_FORK_EPOCH) {
688
- this.syncParticipantReward = computeSyncParticipantReward(this.totalActiveBalanceIncrements);
699
+ this.syncParticipantReward = computeSyncParticipantReward(
700
+ this.config,
701
+ upcomingEpoch,
702
+ this.totalActiveBalanceIncrements
703
+ );
689
704
  this.syncProposerReward = Math.floor(this.syncParticipantReward * PROPOSER_WEIGHT_FACTOR);
690
- this.baseRewardPerIncrement = computeBaseRewardPerIncrement(this.totalActiveBalanceIncrements);
705
+ this.baseRewardPerIncrement = computeBaseRewardPerIncrement(
706
+ this.config,
707
+ upcomingEpoch,
708
+ this.totalActiveBalanceIncrements
709
+ );
710
+ this.baseRewardPerIncrementPrevEpoch = computeBaseRewardPerIncrement(
711
+ this.config,
712
+ Math.max(upcomingEpoch - 1, GENESIS_EPOCH),
713
+ this.totalActiveBalanceIncrements
714
+ );
691
715
  }
692
716
 
693
717
  this.previousTargetUnslashedBalanceIncrements = this.currentTargetUnslashedBalanceIncrements;
@@ -384,7 +384,8 @@ export function beforeProcessEpoch(
384
384
  }
385
385
 
386
386
  // SPEC: function getBaseRewardPerIncrement()
387
- const baseRewardPerIncrement = computeBaseRewardPerIncrement(totalActiveStakeByIncrement);
387
+ // Flag deltas pay for the previous epoch, so they are priced at its slot duration
388
+ const baseRewardPerIncrement = computeBaseRewardPerIncrement(config, prevEpoch, totalActiveStakeByIncrement);
388
389
 
389
390
  // To optimize process_registry_updates():
390
391
  // order by sequence of activationEligibilityEpoch setting and then index
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  EFFECTIVE_BALANCE_INCREMENT,
3
3
  ForkSeq,
4
+ GENESIS_EPOCH,
4
5
  INACTIVITY_PENALTY_QUOTIENT_ALTAIR,
5
6
  INACTIVITY_PENALTY_QUOTIENT_BELLATRIX,
6
7
  PARTICIPATION_FLAG_WEIGHTS,
@@ -18,6 +19,7 @@ import {
18
19
  hasMarkers,
19
20
  } from "../util/attesterStatus.js";
20
21
  import {isInInactivityLeak} from "../util/index.js";
22
+ import {getSlotDurationMsAtEpoch} from "../util/slot.js";
21
23
 
22
24
  type RewardPenaltyItem = {
23
25
  baseReward: number;
@@ -67,7 +69,15 @@ export function getRewardsAndPenaltiesAltair(
67
69
 
68
70
  const inactivityPenalityMultiplier =
69
71
  fork === ForkSeq.altair ? INACTIVITY_PENALTY_QUOTIENT_ALTAIR : INACTIVITY_PENALTY_QUOTIENT_BELLATRIX;
70
- const penaltyDenominator = config.INACTIVITY_SCORE_BIAS * inactivityPenalityMultiplier;
72
+ let penaltyDenominator = config.INACTIVITY_SCORE_BIAS * inactivityPenalityMultiplier;
73
+ // The penalty pays for the previous epoch and scales with the square of its slot duration
74
+ const genesisSlotDurationMs = getSlotDurationMsAtEpoch(config, GENESIS_EPOCH);
75
+ const prevEpochSlotDurationMs = getSlotDurationMsAtEpoch(config, Math.max(epochCtx.epoch - 1, GENESIS_EPOCH));
76
+ if (prevEpochSlotDurationMs !== genesisSlotDurationMs) {
77
+ penaltyDenominator = Number(
78
+ (BigInt(penaltyDenominator) * BigInt(genesisSlotDurationMs) ** 2n) / BigInt(prevEpochSlotDurationMs) ** 2n
79
+ );
80
+ }
71
81
 
72
82
  const {flags} = cache;
73
83
  for (let i = 0; i < flags.length; i++) {
package/src/metrics.ts CHANGED
@@ -156,19 +156,20 @@ export function getMetrics(register: MetricsRegister) {
156
156
  }
157
157
 
158
158
  export function onStateCloneMetrics(
159
- state: CachedBeaconStateAllForks,
159
+ clonedState: CachedBeaconStateAllForks,
160
+ clonedCount: number,
160
161
  metrics: BeaconStateTransitionMetrics,
161
162
  source: StateCloneSource
162
163
  ): void {
163
- metrics.preStateClonedCount.observe(state.clonedCount);
164
+ metrics.preStateClonedCount.observe(clonedCount);
164
165
 
165
- if (isBalancesNodesPopulated(state)) {
166
+ if (isBalancesNodesPopulated(clonedState)) {
166
167
  metrics.preStateBalancesNodesPopulatedHit.inc({source});
167
168
  } else {
168
169
  metrics.preStateBalancesNodesPopulatedMiss.inc({source});
169
170
  }
170
171
 
171
- if (isValidatorsNodesPopulated(state)) {
172
+ if (isValidatorsNodesPopulated(clonedState)) {
172
173
  metrics.preStateValidatorsNodesPopulatedHit.inc({source});
173
174
  } else {
174
175
  metrics.preStateValidatorsNodesPopulatedMiss.inc({source});
@@ -4,6 +4,7 @@ import {
4
4
  EFFECTIVE_BALANCE_INCREMENT,
5
5
  ForkName,
6
6
  ForkSeq,
7
+ GENESIS_EPOCH,
7
8
  INACTIVITY_PENALTY_QUOTIENT_ALTAIR,
8
9
  INACTIVITY_PENALTY_QUOTIENT_BELLATRIX,
9
10
  MAX_EFFECTIVE_BALANCE,
@@ -26,6 +27,7 @@ import {
26
27
  FLAG_PREV_HEAD_ATTESTER_UNSLASHED,
27
28
  FLAG_PREV_SOURCE_ATTESTER_UNSLASHED,
28
29
  FLAG_PREV_TARGET_ATTESTER_UNSLASHED,
30
+ getSlotDurationMsAtEpoch,
29
31
  hasMarkers,
30
32
  isInInactivityLeak,
31
33
  } from "../util/index.js";
@@ -168,7 +170,16 @@ function computeTotalAttestationsRewardsAltair(
168
170
  config.getForkSeq(state.slot) === ForkSeq.altair
169
171
  ? INACTIVITY_PENALTY_QUOTIENT_ALTAIR
170
172
  : INACTIVITY_PENALTY_QUOTIENT_BELLATRIX;
171
- const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * inactivityPenaltyQuotient;
173
+ let inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * inactivityPenaltyQuotient;
174
+ // The penalty pays for the previous epoch and scales with the square of its slot duration
175
+ const genesisSlotDurationMs = getSlotDurationMsAtEpoch(config, GENESIS_EPOCH);
176
+ const prevEpochSlotDurationMs = getSlotDurationMsAtEpoch(config, Math.max(epochCtx.epoch - 1, GENESIS_EPOCH));
177
+ if (prevEpochSlotDurationMs !== genesisSlotDurationMs) {
178
+ inactivityPenaltyDenominator = Number(
179
+ (BigInt(inactivityPenaltyDenominator) * BigInt(genesisSlotDurationMs) ** 2n) /
180
+ BigInt(prevEpochSlotDurationMs) ** 2n
181
+ );
182
+ }
172
183
 
173
184
  for (let i = 0; i < flags.length; i++) {
174
185
  if (validatorIndices.length && !validatorIndices.includes(i)) {
@@ -0,0 +1,20 @@
1
+ import {BeaconConfig} from "@lodestar/config";
2
+ import {DOMAIN_INCLUSION_LIST_COMMITTEE} from "@lodestar/params";
3
+ import {Slot, heze, ssz} from "@lodestar/types";
4
+ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
5
+
6
+ export function getInclusionListSignatureSet(
7
+ config: BeaconConfig,
8
+ stateSlot: Slot,
9
+ signedInclusionList: heze.SignedInclusionList
10
+ ): ISignatureSet {
11
+ const message = signedInclusionList.message;
12
+ const domain = config.getDomain(stateSlot, DOMAIN_INCLUSION_LIST_COMMITTEE, message.slot);
13
+
14
+ return {
15
+ type: SignatureSetType.indexed,
16
+ index: message.validatorIndex,
17
+ signingRoot: computeSigningRoot(ssz.heze.InclusionList, message, domain),
18
+ signature: signedInclusionList.signature,
19
+ };
20
+ }
@@ -18,6 +18,7 @@ export * from "./attesterSlashings.js";
18
18
  export * from "./blsToExecutionChange.js";
19
19
  export * from "./executionPayloadBid.js";
20
20
  export * from "./executionPayloadEnvelope.js";
21
+ export * from "./inclusionList.js";
21
22
  export * from "./indexedAttestation.js";
22
23
  export * from "./indexedPayloadAttestation.js";
23
24
  export * from "./proposer.js";
@@ -101,7 +101,7 @@ export function stateTransition(
101
101
  let postState = state.clone(options.dontTransferCache);
102
102
 
103
103
  if (metrics) {
104
- onStateCloneMetrics(postState, metrics, StateCloneSource.stateTransition);
104
+ onStateCloneMetrics(postState, state.clonedCount, metrics, StateCloneSource.stateTransition);
105
105
  }
106
106
 
107
107
  // State is already a ViewDU, which won't commit changes. Equivalent to .setStateCachesAsTransient()
@@ -168,7 +168,7 @@ export function processSlots(
168
168
  let postState = state.clone(opts?.dontTransferCache);
169
169
 
170
170
  if (metrics) {
171
- onStateCloneMetrics(postState, metrics, StateCloneSource.processSlots);
171
+ onStateCloneMetrics(postState, state.clonedCount, metrics, StateCloneSource.processSlots);
172
172
  }
173
173
 
174
174
  // State is already a ViewDU, which won't commit changes. Equivalent to .setStateCachesAsTransient()
@@ -336,8 +336,6 @@ export type IBeaconStateViewLatestFork = Omit<
336
336
  */
337
337
  export type IBeaconStateViewNative = Omit<
338
338
  IBeaconStateViewLatestFork,
339
- | "builderPendingPayments"
340
- | "builderPendingWithdrawals"
341
339
  | "computeAttestationsRewards"
342
340
  | "computeBlockRewards"
343
341
  | "computeNewStateRoot"
@@ -346,8 +344,6 @@ export type IBeaconStateViewNative = Omit<
346
344
  | "eth1Data"
347
345
  | "executionPayloadAvailability"
348
346
  | "getBeaconCommittee"
349
- | "getIndicesInPayloadTimelinessCommittee"
350
- | "getPayloadTimelinessCommittee"
351
347
  | "loadOtherState"
352
348
  | "pendingConsolidations"
353
349
  | "pendingDeposits"
@@ -365,7 +361,6 @@ export type IBeaconStateViewNative = Omit<
365
361
  pendingPartialWithdrawals: Uint8Array;
366
362
  pendingConsolidations: Uint8Array;
367
363
  proposerLookahead: Uint32Array;
368
- // UintBn64 lowers to number across the FFI boundary; the wrapper lifts it back to bigint
369
364
  eth1Data: phase0.Eth1Data;
370
365
  executionPayloadAvailability: {uint8Array: Uint8Array; bitLen: number};
371
366
  computeBlockRewards(
@@ -379,8 +374,6 @@ export type IBeaconStateViewNative = Omit<
379
374
  validatorIds: (ValidatorIndex | string)[]
380
375
  ): rewards.SyncCommitteeRewards;
381
376
  getBeaconCommittee(slot: Slot, index: CommitteeIndex): Uint32Array;
382
- getIndexInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number;
383
- getIndicesInPayloadTimelinessCommittee?(validatorIndex: ValidatorIndex, slot: Slot): number[];
384
377
  loadOtherState(...args: Parameters<IBeaconStateViewLatestFork["loadOtherState"]>): IBeaconStateViewNative;
385
378
  stateTransition(
386
379
  signedBlockBytes: Uint8Array,
@@ -388,9 +381,7 @@ export type IBeaconStateViewNative = Omit<
388
381
  options?: StateTransitionOpts
389
382
  ): IBeaconStateViewNative;
390
383
  processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}): IBeaconStateViewNative;
391
- withParentPayloadApplied(
392
- ...args: Parameters<IBeaconStateViewLatestFork["withParentPayloadApplied"]>
393
- ): IBeaconStateViewNative;
384
+ withParentPayloadApplied(executionRequestsBytes: Uint8Array): IBeaconStateViewNative;
394
385
  };
395
386
 
396
387
  export function isStatePostAltair(state: IBeaconStateView): state is IBeaconStateViewAltair {
@@ -1,7 +1,7 @@
1
1
  import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
2
2
  import {BitArray, ByteViews} from "@chainsafe/ssz";
3
3
  import type {BeaconConfig} from "@lodestar/config";
4
- import {ForkName, ForkSeq} from "@lodestar/params";
4
+ import {ForkName, ForkPostElectra, ForkSeq} from "@lodestar/params";
5
5
  import {
6
6
  BeaconBlock,
7
7
  BeaconState,
@@ -28,6 +28,7 @@ import {
28
28
  phase0,
29
29
  rewards,
30
30
  ssz,
31
+ sszTypesFor,
31
32
  } from "@lodestar/types";
32
33
  import {Checkpoint, Fork} from "@lodestar/types/phase0";
33
34
  import {VoluntaryExitValidity} from "../block/processVoluntaryExit.js";
@@ -39,6 +40,7 @@ import {SyncCommitteeWitness} from "../lightClient/types.js";
39
40
  import {StateTransitionModules, StateTransitionOpts} from "../stateTransition.js";
40
41
  import {EpochShuffling} from "../util/epochShuffling.js";
41
42
  import {PreVerifyBuilderDepositsResult} from "../util/preVerifyBuilderDeposits.js";
43
+ import {getStateSlotFromBytes} from "../util/sszBytes.js";
42
44
  import {computeNewStateRootStateTransitionOpts, getComputeNewStateRootResult} from "./computeNewStateRoot.js";
43
45
  import {
44
46
  BlockSTFInput,
@@ -47,8 +49,15 @@ import {
47
49
  IBeaconStateViewGloas,
48
50
  IBeaconStateViewLatestFork,
49
51
  IBeaconStateViewNative,
52
+ isStatePostGloas,
50
53
  } from "./interface.js";
51
54
 
55
+ export function assertNativeForkSupported(config: BeaconConfig, slot: Slot): void {
56
+ if (config.getForkSeq(slot) > ForkSeq.gloas) {
57
+ throw Error(`Native state transition does not support ${config.getForkName(slot)}`);
58
+ }
59
+ }
60
+
52
61
  /**
53
62
  * Wraps a native binding (the auto-generated JS interface produced by a `.node`
54
63
  * file) and exposes it as a fully-conformant `IBeaconStateViewLatestFork`.
@@ -115,6 +124,14 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
115
124
  private cachedPendingConsolidationsCount: number | null = null;
116
125
  // fulu
117
126
  private cachedProposerLookahead: fulu.ProposerLookahead | null = null;
127
+ // gloas
128
+ private cachedLatestBlockHash: Bytes32 | null = null;
129
+ private cachedExecutionPayloadAvailability: BitArray | null = null;
130
+ private cachedLatestExecutionPayloadBid: ExecutionPayloadBid | null = null;
131
+ private cachedPayloadExpectedWithdrawals: capella.Withdrawal[] | null = null;
132
+ private cachedBuilderPendingPayments: gloas.BuilderPendingPayments | null = null;
133
+ private cachedBuilderPendingWithdrawals: gloas.BuilderPendingWithdrawals | null = null;
134
+ private cachedBuildersLength: number | null = null;
118
135
  // Per-argument caches for argument-taking methods. The binding is treated as
119
136
  // immutable for the view's lifetime, so a given argument always yields the
120
137
  // same result. Maps grow only with touched arguments — typical call patterns
@@ -174,7 +191,11 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
174
191
  }
175
192
 
176
193
  get executionPayloadAvailability(): BitArray {
177
- throw new Error("NativeBeaconStateView does not support Gloas");
194
+ if (this.cachedExecutionPayloadAvailability === null) {
195
+ const {uint8Array, bitLen} = this.binding.executionPayloadAvailability;
196
+ this.cachedExecutionPayloadAvailability = new BitArray(uint8Array, bitLen);
197
+ }
198
+ return this.cachedExecutionPayloadAvailability;
178
199
  }
179
200
 
180
201
  // ─── phase0 ──────────────────────────────────────────────────────────────
@@ -598,6 +619,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
598
619
  seedValidatorsBytes?: Uint8Array,
599
620
  opts?: {preloadValidatorsAndBalances?: boolean}
600
621
  ): IBeaconStateView {
622
+ assertNativeForkSupported(this.config, getStateSlotFromBytes(stateBytes));
601
623
  return new NativeBeaconStateView(this.config, this.binding.loadOtherState(stateBytes, seedValidatorsBytes, opts));
602
624
  }
603
625
 
@@ -663,6 +685,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
663
685
  options: StateTransitionOpts,
664
686
  _modules: StateTransitionModules
665
687
  ): IBeaconStateView {
688
+ assertNativeForkSupported(this.config, block.message.slot);
666
689
  const isBlinded = isBlindedBeaconBlock(block.message);
667
690
  const signedBlockBytes =
668
691
  ssz ??
@@ -675,6 +698,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
675
698
  }
676
699
 
677
700
  processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}, _modules?: StateTransitionModules): IBeaconStateView {
701
+ assertNativeForkSupported(this.config, slot);
678
702
  return new NativeBeaconStateView(this.config, this.binding.processSlots(slot, opts));
679
703
  }
680
704
 
@@ -832,7 +856,8 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
832
856
 
833
857
  get pendingDeposits(): electra.PendingDeposits {
834
858
  if (this.cachedPendingDeposits === null) {
835
- this.cachedPendingDeposits = ssz.electra.PendingDeposits.deserialize(this.binding.pendingDeposits);
859
+ const type = sszTypesFor(this.forkName as ForkPostElectra).PendingDeposits;
860
+ this.cachedPendingDeposits = type.deserialize(this.binding.pendingDeposits);
836
861
  }
837
862
  return this.cachedPendingDeposits;
838
863
  }
@@ -846,9 +871,8 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
846
871
 
847
872
  get pendingPartialWithdrawals(): electra.PendingPartialWithdrawals {
848
873
  if (this.cachedPendingPartialWithdrawals === null) {
849
- this.cachedPendingPartialWithdrawals = ssz.electra.PendingPartialWithdrawals.deserialize(
850
- this.binding.pendingPartialWithdrawals
851
- );
874
+ const type = sszTypesFor(this.forkName as ForkPostElectra).PendingPartialWithdrawals;
875
+ this.cachedPendingPartialWithdrawals = type.deserialize(this.binding.pendingPartialWithdrawals);
852
876
  }
853
877
  return this.cachedPendingPartialWithdrawals;
854
878
  }
@@ -862,9 +886,8 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
862
886
 
863
887
  get pendingConsolidations(): electra.PendingConsolidations {
864
888
  if (this.cachedPendingConsolidations === null) {
865
- this.cachedPendingConsolidations = ssz.electra.PendingConsolidations.deserialize(
866
- this.binding.pendingConsolidations
867
- );
889
+ const type = sszTypesFor(this.forkName as ForkPostElectra).PendingConsolidations;
890
+ this.cachedPendingConsolidations = type.deserialize(this.binding.pendingConsolidations);
868
891
  }
869
892
  return this.cachedPendingConsolidations;
870
893
  }
@@ -889,60 +912,94 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
889
912
  _maxBuilderDeposits: number,
890
913
  _maxDurationMs: number
891
914
  ): PreVerifyBuilderDepositsResult {
892
- throw new Error("NativeBeaconStateView does not support Gloas");
915
+ // The native fork upgrade verifies directly; it does not maintain a warm-up cache.
916
+ return {
917
+ validBuilderSignaturesCount: 0,
918
+ invalidBuilderSignaturesCount: 0,
919
+ validValidatorSignaturesCount: 0,
920
+ invalidValidatorSignaturesCount: 0,
921
+ scannedPendingDeposits: 0,
922
+ totalCachedDeposits: 0,
923
+ totalBuilderPubkeys: 0,
924
+ pendingDepositsCount: this.pendingDepositsCount,
925
+ };
893
926
  }
894
927
 
895
928
  clearPreGloasBuilderDepositCache(): void {
896
- throw new Error("NativeBeaconStateView does not support Gloas");
929
+ // The native implementation has no pre-Gloas deposit cache to clear.
897
930
  }
898
931
 
899
932
  // ─── gloas ───────────────────────────────────────────────────────────────
900
933
 
901
934
  get latestBlockHash(): Bytes32 {
902
- throw new Error("NativeBeaconStateView does not support Gloas");
935
+ if (this.cachedLatestBlockHash === null) {
936
+ this.cachedLatestBlockHash = this.binding.latestBlockHash;
937
+ }
938
+ return this.cachedLatestBlockHash;
903
939
  }
904
940
 
905
941
  get latestExecutionPayloadBid(): ExecutionPayloadBid {
906
- throw new Error("NativeBeaconStateView does not support Gloas");
942
+ if (this.cachedLatestExecutionPayloadBid === null) {
943
+ this.cachedLatestExecutionPayloadBid = this.binding.latestExecutionPayloadBid;
944
+ }
945
+ return this.cachedLatestExecutionPayloadBid;
907
946
  }
908
947
 
909
948
  get payloadExpectedWithdrawals(): capella.Withdrawal[] {
910
- throw new Error("NativeBeaconStateView does not support Gloas");
949
+ if (this.cachedPayloadExpectedWithdrawals === null) {
950
+ this.cachedPayloadExpectedWithdrawals = this.binding.payloadExpectedWithdrawals;
951
+ }
952
+ return this.cachedPayloadExpectedWithdrawals;
911
953
  }
912
954
 
913
955
  get builderPendingPayments(): gloas.BuilderPendingPayments {
914
- throw new Error("NativeBeaconStateView does not support Gloas");
956
+ if (this.cachedBuilderPendingPayments === null) {
957
+ this.cachedBuilderPendingPayments = this.binding.builderPendingPayments;
958
+ }
959
+ return this.cachedBuilderPendingPayments;
915
960
  }
916
961
 
917
962
  get builderPendingWithdrawals(): gloas.BuilderPendingWithdrawals {
918
- throw new Error("NativeBeaconStateView does not support Gloas");
963
+ if (this.cachedBuilderPendingWithdrawals === null) {
964
+ this.cachedBuilderPendingWithdrawals = this.binding.builderPendingWithdrawals;
965
+ }
966
+ return this.cachedBuilderPendingWithdrawals;
919
967
  }
920
968
 
921
- getBuilder(_index: BuilderIndex): gloas.Builder {
922
- throw new Error("NativeBeaconStateView does not support Gloas");
969
+ getBuilder(index: BuilderIndex): gloas.Builder {
970
+ return this.binding.getBuilder(index);
923
971
  }
924
972
 
925
973
  getBuildersLength(): number {
926
- throw new Error("NativeBeaconStateView does not support Gloas");
974
+ if (this.cachedBuildersLength === null) {
975
+ this.cachedBuildersLength = this.binding.getBuildersLength();
976
+ }
977
+ return this.cachedBuildersLength;
927
978
  }
928
979
 
929
- canBuilderCoverBid(_builderIndex: BuilderIndex, _bidAmount: number): boolean {
930
- throw new Error("NativeBeaconStateView does not support Gloas");
980
+ canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean {
981
+ return this.binding.canBuilderCoverBid(builderIndex, bidAmount);
931
982
  }
932
983
 
933
- getEpochPTCs(_epoch: Epoch): Uint32Array[] {
934
- throw new Error("NativeBeaconStateView does not support Gloas");
984
+ getEpochPTCs(epoch: Epoch): Uint32Array[] {
985
+ return this.binding.getEpochPTCs(epoch);
935
986
  }
936
987
 
937
- getPayloadTimelinessCommittee(_slot: Slot): Uint32Array {
938
- throw new Error("NativeBeaconStateView does not support Gloas");
988
+ getPayloadTimelinessCommittee(slot: Slot): Uint32Array {
989
+ return this.binding.getPayloadTimelinessCommittee(slot);
939
990
  }
940
991
 
941
- getIndicesInPayloadTimelinessCommittee(_validatorIndex: ValidatorIndex, _slot: Slot): number[] {
942
- throw new Error("NativeBeaconStateView does not support Gloas");
992
+ getIndicesInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number[] {
993
+ return this.binding.getIndicesInPayloadTimelinessCommittee(validatorIndex, slot);
943
994
  }
944
995
 
945
- withParentPayloadApplied(_executionRequests: gloas.ExecutionRequests): IBeaconStateViewGloas {
946
- throw new Error("NativeBeaconStateView does not support Gloas");
996
+ withParentPayloadApplied(executionRequests: gloas.ExecutionRequests): IBeaconStateViewGloas {
997
+ const bytes = ssz.gloas.ExecutionRequests.serialize(executionRequests);
998
+ const state = new NativeBeaconStateView(this.config, this.binding.withParentPayloadApplied(bytes));
999
+ if (!isStatePostGloas(state)) {
1000
+ state.release();
1001
+ throw Error("Expected Gloas state after applying the parent payload");
1002
+ }
1003
+ return state;
947
1004
  }
948
1005
  }
@@ -2,10 +2,10 @@ import bindings from "@chainsafe/lodestar-z";
2
2
  import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
3
3
  import {BeaconConfig} from "@lodestar/config";
4
4
  import {createCachedBeaconState} from "../cache/stateCache.js";
5
- import {getStateTypeFromBytes} from "../util/sszBytes.js";
5
+ import {getStateSlotFromBytes, getStateTypeFromBytes} from "../util/sszBytes.js";
6
6
  import {BeaconStateView} from "./beaconStateView.js";
7
7
  import {IBeaconStateView, IBeaconStateViewNative} from "./interface.js";
8
- import {NativeBeaconStateView} from "./nativeBeaconStateView.js";
8
+ import {NativeBeaconStateView, assertNativeForkSupported} from "./nativeBeaconStateView.js";
9
9
 
10
10
  // ---- createBeaconStateView (startup path) ----
11
11
 
@@ -62,6 +62,7 @@ export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts |
62
62
  }
63
63
 
64
64
  function createNativeBeaconStateView(config: BeaconConfig, stateBytes: Uint8Array): IBeaconStateView {
65
+ assertNativeForkSupported(config, getStateSlotFromBytes(stateBytes));
65
66
  const nativeConfig = new bindings.BeaconConfig(config, config.genesisValidatorsRoot);
66
67
  return new NativeBeaconStateView(
67
68
  config,