@lodestar/state-transition 1.41.0-dev.116358ed6c → 1.41.0-dev.165a02f873

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 (135) hide show
  1. package/lib/block/externalData.d.ts +2 -1
  2. package/lib/block/externalData.d.ts.map +1 -1
  3. package/lib/block/externalData.js +2 -0
  4. package/lib/block/externalData.js.map +1 -1
  5. package/lib/block/isValidIndexedAttestation.d.ts +3 -3
  6. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  7. package/lib/block/isValidIndexedAttestation.js +4 -4
  8. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  9. package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
  10. package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
  11. package/lib/block/processAttestationPhase0.js +1 -1
  12. package/lib/block/processAttestationPhase0.js.map +1 -1
  13. package/lib/block/processAttestationsAltair.js +1 -1
  14. package/lib/block/processAttestationsAltair.js.map +1 -1
  15. package/lib/block/processAttesterSlashing.d.ts +2 -2
  16. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  17. package/lib/block/processAttesterSlashing.js +3 -3
  18. package/lib/block/processAttesterSlashing.js.map +1 -1
  19. package/lib/block/processExecutionPayloadEnvelope.d.ts +4 -1
  20. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
  21. package/lib/block/processExecutionPayloadEnvelope.js +25 -15
  22. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
  23. package/lib/block/processProposerSlashing.d.ts +2 -2
  24. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  25. package/lib/block/processProposerSlashing.js +3 -3
  26. package/lib/block/processProposerSlashing.js.map +1 -1
  27. package/lib/block/processRandao.js +1 -1
  28. package/lib/block/processRandao.js.map +1 -1
  29. package/lib/block/processSyncCommittee.js +1 -1
  30. package/lib/block/processSyncCommittee.js.map +1 -1
  31. package/lib/block/processVoluntaryExit.js +1 -1
  32. package/lib/block/processVoluntaryExit.js.map +1 -1
  33. package/lib/block/processWithdrawalRequest.js +2 -2
  34. package/lib/block/processWithdrawalRequest.js.map +1 -1
  35. package/lib/cache/epochCache.d.ts +8 -15
  36. package/lib/cache/epochCache.d.ts.map +1 -1
  37. package/lib/cache/epochCache.js +34 -33
  38. package/lib/cache/epochCache.js.map +1 -1
  39. package/lib/cache/pubkeyCache.d.ts +21 -6
  40. package/lib/cache/pubkeyCache.d.ts.map +1 -1
  41. package/lib/cache/pubkeyCache.js +39 -14
  42. package/lib/cache/pubkeyCache.js.map +1 -1
  43. package/lib/cache/stateCache.d.ts +1 -1
  44. package/lib/cache/stateCache.d.ts.map +1 -1
  45. package/lib/cache/stateCache.js +3 -7
  46. package/lib/cache/stateCache.js.map +1 -1
  47. package/lib/cache/syncCommitteeCache.d.ts +3 -2
  48. package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
  49. package/lib/cache/syncCommitteeCache.js +4 -4
  50. package/lib/cache/syncCommitteeCache.js.map +1 -1
  51. package/lib/index.d.ts +3 -1
  52. package/lib/index.d.ts.map +1 -1
  53. package/lib/index.js +2 -1
  54. package/lib/index.js.map +1 -1
  55. package/lib/lightClient/proofs.d.ts +10 -0
  56. package/lib/lightClient/proofs.d.ts.map +1 -0
  57. package/lib/lightClient/proofs.js +63 -0
  58. package/lib/lightClient/proofs.js.map +1 -0
  59. package/lib/lightClient/types.d.ts +34 -0
  60. package/lib/lightClient/types.d.ts.map +1 -0
  61. package/lib/lightClient/types.js +2 -0
  62. package/lib/lightClient/types.js.map +1 -0
  63. package/lib/rewards/attestationsRewards.d.ts +2 -2
  64. package/lib/rewards/attestationsRewards.d.ts.map +1 -1
  65. package/lib/rewards/attestationsRewards.js +4 -4
  66. package/lib/rewards/attestationsRewards.js.map +1 -1
  67. package/lib/rewards/syncCommitteeRewards.d.ts +2 -2
  68. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
  69. package/lib/rewards/syncCommitteeRewards.js +5 -2
  70. package/lib/rewards/syncCommitteeRewards.js.map +1 -1
  71. package/lib/signatureSets/proposer.d.ts +2 -2
  72. package/lib/signatureSets/proposer.d.ts.map +1 -1
  73. package/lib/signatureSets/proposer.js +2 -2
  74. package/lib/signatureSets/proposer.js.map +1 -1
  75. package/lib/signatureSets/randao.d.ts +2 -2
  76. package/lib/signatureSets/randao.d.ts.map +1 -1
  77. package/lib/signatureSets/randao.js +2 -2
  78. package/lib/signatureSets/randao.js.map +1 -1
  79. package/lib/signatureSets/voluntaryExits.d.ts +2 -2
  80. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  81. package/lib/signatureSets/voluntaryExits.js +2 -2
  82. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  83. package/lib/stateTransition.d.ts +2 -1
  84. package/lib/stateTransition.d.ts.map +1 -1
  85. package/lib/stateTransition.js +2 -1
  86. package/lib/stateTransition.js.map +1 -1
  87. package/lib/stateView/beaconStateView.d.ts +144 -0
  88. package/lib/stateView/beaconStateView.d.ts.map +1 -0
  89. package/lib/stateView/beaconStateView.js +496 -0
  90. package/lib/stateView/beaconStateView.js.map +1 -0
  91. package/lib/stateView/index.d.ts +3 -0
  92. package/lib/stateView/index.d.ts.map +1 -0
  93. package/lib/stateView/index.js +3 -0
  94. package/lib/stateView/index.js.map +1 -0
  95. package/lib/stateView/interface.d.ts +118 -0
  96. package/lib/stateView/interface.d.ts.map +1 -0
  97. package/lib/stateView/interface.js +2 -0
  98. package/lib/stateView/interface.js.map +1 -0
  99. package/lib/util/signatureSets.d.ts +7 -7
  100. package/lib/util/signatureSets.d.ts.map +1 -1
  101. package/lib/util/signatureSets.js +18 -12
  102. package/lib/util/signatureSets.js.map +1 -1
  103. package/lib/util/weakSubjectivity.js +1 -1
  104. package/lib/util/weakSubjectivity.js.map +1 -1
  105. package/package.json +7 -7
  106. package/src/block/externalData.ts +2 -0
  107. package/src/block/isValidIndexedAttestation.ts +5 -5
  108. package/src/block/isValidIndexedPayloadAttestation.ts +1 -1
  109. package/src/block/processAttestationPhase0.ts +1 -1
  110. package/src/block/processAttestationsAltair.ts +1 -1
  111. package/src/block/processAttesterSlashing.ts +4 -4
  112. package/src/block/processExecutionPayloadEnvelope.ts +34 -16
  113. package/src/block/processProposerSlashing.ts +4 -4
  114. package/src/block/processRandao.ts +1 -1
  115. package/src/block/processSyncCommittee.ts +1 -1
  116. package/src/block/processVoluntaryExit.ts +1 -1
  117. package/src/block/processWithdrawalRequest.ts +2 -2
  118. package/src/cache/epochCache.ts +44 -36
  119. package/src/cache/pubkeyCache.ts +62 -21
  120. package/src/cache/stateCache.ts +4 -8
  121. package/src/cache/syncCommitteeCache.ts +4 -5
  122. package/src/index.ts +3 -1
  123. package/src/lightClient/proofs.ts +83 -0
  124. package/src/lightClient/types.ts +33 -0
  125. package/src/rewards/attestationsRewards.ts +5 -5
  126. package/src/rewards/syncCommitteeRewards.ts +6 -5
  127. package/src/signatureSets/proposer.ts +3 -3
  128. package/src/signatureSets/randao.ts +3 -7
  129. package/src/signatureSets/voluntaryExits.ts +3 -3
  130. package/src/stateTransition.ts +2 -1
  131. package/src/stateView/beaconStateView.ts +744 -0
  132. package/src/stateView/index.ts +2 -0
  133. package/src/stateView/interface.ts +196 -0
  134. package/src/util/signatureSets.ts +23 -17
  135. package/src/util/weakSubjectivity.ts +1 -1
@@ -1,4 +1,3 @@
1
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
2
1
  import {BeaconConfig} from "@lodestar/config";
3
2
  import {
4
3
  EFFECTIVE_BALANCE_INCREMENT,
@@ -16,6 +15,7 @@ import {
16
15
  import {ValidatorIndex, rewards} from "@lodestar/types";
17
16
  import {fromHex} from "@lodestar/utils";
18
17
  import {EpochTransitionCache, beforeProcessEpoch} from "../cache/epochTransitionCache.js";
18
+ import {PubkeyCache} from "../cache/pubkeyCache.js";
19
19
  import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
20
20
  import {
21
21
  FLAG_ELIGIBLE_ATTESTER,
@@ -34,7 +34,7 @@ const defaultAttestationsPenalty = {target: 0, source: 0};
34
34
 
35
35
  export async function computeAttestationsRewards(
36
36
  config: BeaconConfig,
37
- pubkey2index: PubkeyIndexMap,
37
+ pubkeyCache: PubkeyCache,
38
38
  state: CachedBeaconStateAllForks,
39
39
  validatorIds?: (ValidatorIndex | string)[]
40
40
  ): Promise<rewards.AttestationsRewards> {
@@ -53,7 +53,7 @@ export async function computeAttestationsRewards(
53
53
  );
54
54
  const totalRewards = computeTotalAttestationsRewardsAltair(
55
55
  config,
56
- pubkey2index,
56
+ pubkeyCache,
57
57
  stateAltair,
58
58
  transitionCache,
59
59
  idealRewards,
@@ -142,7 +142,7 @@ function computeIdealAttestationsRewardsAndPenaltiesAltair(
142
142
  // Same calculation as `getRewardsAndPenaltiesAltair` but returns the breakdown of rewards instead of aggregated
143
143
  function computeTotalAttestationsRewardsAltair(
144
144
  config: BeaconConfig,
145
- pubkey2index: PubkeyIndexMap,
145
+ pubkeyCache: PubkeyCache,
146
146
  state: CachedBeaconStateAltair,
147
147
  transitionCache: EpochTransitionCache,
148
148
  idealRewards: rewards.IdealAttestationsReward[],
@@ -153,7 +153,7 @@ function computeTotalAttestationsRewardsAltair(
153
153
  const {flags} = transitionCache;
154
154
  const {epochCtx} = state;
155
155
  const validatorIndices = validatorIds
156
- .map((id) => (typeof id === "number" ? id : pubkey2index.get(fromHex(id))))
156
+ .map((id) => (typeof id === "number" ? id : pubkeyCache.getIndex(fromHex(id))))
157
157
  .filter((index) => index !== undefined); // Validator indices to include in the result
158
158
 
159
159
  const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;
@@ -1,12 +1,12 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
3
3
  import {BeaconBlock, ValidatorIndex, altair, rewards} from "@lodestar/types";
4
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
+ import {PubkeyCache} from "../cache/pubkeyCache.js";
5
5
  import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../cache/stateCache.js";
6
6
 
7
7
  export async function computeSyncCommitteeRewards(
8
8
  config: BeaconConfig,
9
- index2pubkey: Index2PubkeyCache,
9
+ pubkeyCache: PubkeyCache,
10
10
  block: BeaconBlock,
11
11
  preState: CachedBeaconStateAllForks,
12
12
  validatorIds: (ValidatorIndex | string)[] = []
@@ -47,9 +47,10 @@ export async function computeSyncCommitteeRewards(
47
47
 
48
48
  if (validatorIds.length) {
49
49
  const filtersSet = new Set(validatorIds);
50
- return rewards.filter(
51
- (reward) => filtersSet.has(reward.validatorIndex) || filtersSet.has(index2pubkey[reward.validatorIndex].toHex())
52
- );
50
+ return rewards.filter((reward) => {
51
+ const pubkeyHex = pubkeyCache.get(reward.validatorIndex)?.toHex();
52
+ return filtersSet.has(reward.validatorIndex) || (pubkeyHex !== undefined && filtersSet.has(pubkeyHex));
53
+ });
53
54
  }
54
55
 
55
56
  return rewards;
@@ -1,17 +1,17 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
3
3
  import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
4
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
+ import {PubkeyCache} from "../cache/pubkeyCache.js";
5
5
  import {computeSigningRoot} from "../util/index.js";
6
6
  import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
7
7
 
8
8
  export function verifyProposerSignature(
9
9
  config: BeaconConfig,
10
- index2pubkey: Index2PubkeyCache,
10
+ pubkeyCache: PubkeyCache,
11
11
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
12
12
  ): boolean {
13
13
  const signatureSet = getBlockProposerSignatureSet(config, signedBlock);
14
- return verifySignatureSet(signatureSet, index2pubkey);
14
+ return verifySignatureSet(signatureSet, pubkeyCache);
15
15
  }
16
16
 
17
17
  export function getBlockProposerSignatureSet(
@@ -1,7 +1,7 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_RANDAO} from "@lodestar/params";
3
3
  import {BeaconBlock, ssz} from "@lodestar/types";
4
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
+ import {PubkeyCache} from "../cache/pubkeyCache.js";
5
5
  import {
6
6
  ISignatureSet,
7
7
  SignatureSetType,
@@ -10,12 +10,8 @@ import {
10
10
  verifySignatureSet,
11
11
  } from "../util/index.js";
12
12
 
13
- export function verifyRandaoSignature(
14
- config: BeaconConfig,
15
- index2pubkey: Index2PubkeyCache,
16
- block: BeaconBlock
17
- ): boolean {
18
- return verifySignatureSet(getRandaoRevealSignatureSet(config, block), index2pubkey);
13
+ export function verifyRandaoSignature(config: BeaconConfig, pubkeyCache: PubkeyCache, block: BeaconBlock): boolean {
14
+ return verifySignatureSet(getRandaoRevealSignatureSet(config, block), pubkeyCache);
19
15
  }
20
16
 
21
17
  /**
@@ -1,6 +1,6 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
3
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
+ import {PubkeyCache} from "../cache/pubkeyCache.js";
4
4
  import {
5
5
  ISignatureSet,
6
6
  SignatureSetType,
@@ -11,11 +11,11 @@ import {
11
11
 
12
12
  export function verifyVoluntaryExitSignature(
13
13
  config: BeaconConfig,
14
- index2pubkey: Index2PubkeyCache,
14
+ pubkeyCache: PubkeyCache,
15
15
  stateSlot: Slot,
16
16
  signedVoluntaryExit: phase0.SignedVoluntaryExit
17
17
  ): boolean {
18
- return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit), index2pubkey);
18
+ return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit), pubkeyCache);
19
19
  }
20
20
 
21
21
  /**
@@ -76,6 +76,7 @@ export enum StateHashTreeRootSource {
76
76
  prepareNextEpoch = "prepare_next_epoch",
77
77
  regenState = "regen_state",
78
78
  computeNewStateRoot = "compute_new_state_root",
79
+ computeEnvelopeStateRoot = "compute_envelope_state_root",
79
80
  }
80
81
 
81
82
  /**
@@ -111,7 +112,7 @@ export function stateTransition(
111
112
  postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
112
113
 
113
114
  // Verify proposer signature only
114
- if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.index2pubkey, signedBlock)) {
115
+ if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.pubkeyCache, signedBlock)) {
115
116
  throw new Error("Invalid block signature");
116
117
  }
117
118