@lodestar/state-transition 1.39.1 → 1.40.0-dev.059f489b0f

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 (252) hide show
  1. package/lib/block/index.d.ts +1 -0
  2. package/lib/block/index.d.ts.map +1 -1
  3. package/lib/block/index.js +1 -0
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/isValidIndexedAttestation.d.ts +4 -5
  6. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  7. package/lib/block/isValidIndexedAttestation.js +9 -10
  8. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  9. package/lib/block/isValidIndexedPayloadAttestation.d.ts.map +1 -1
  10. package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
  11. package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
  12. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  13. package/lib/block/processAttestationPhase0.js +1 -1
  14. package/lib/block/processAttestationPhase0.js.map +1 -1
  15. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  16. package/lib/block/processAttestationsAltair.js +3 -4
  17. package/lib/block/processAttestationsAltair.js.map +1 -1
  18. package/lib/block/processAttesterSlashing.d.ts +3 -2
  19. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  20. package/lib/block/processAttesterSlashing.js +3 -3
  21. package/lib/block/processAttesterSlashing.js.map +1 -1
  22. package/lib/block/processBlockHeader.d.ts.map +1 -1
  23. package/lib/block/processBlockHeader.js +1 -2
  24. package/lib/block/processBlockHeader.js.map +1 -1
  25. package/lib/block/processBlsToExecutionChange.d.ts +3 -1
  26. package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
  27. package/lib/block/processBlsToExecutionChange.js +8 -13
  28. package/lib/block/processBlsToExecutionChange.js.map +1 -1
  29. package/lib/block/processConsolidationRequest.d.ts +1 -2
  30. package/lib/block/processConsolidationRequest.d.ts.map +1 -1
  31. package/lib/block/processConsolidationRequest.js +5 -4
  32. package/lib/block/processConsolidationRequest.js.map +1 -1
  33. package/lib/block/processDepositRequest.d.ts +8 -2
  34. package/lib/block/processDepositRequest.d.ts.map +1 -1
  35. package/lib/block/processDepositRequest.js +81 -8
  36. package/lib/block/processDepositRequest.js.map +1 -1
  37. package/lib/block/processExecutionPayload.d.ts.map +1 -1
  38. package/lib/block/processExecutionPayload.js +1 -2
  39. package/lib/block/processExecutionPayload.js.map +1 -1
  40. package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
  41. package/lib/block/processExecutionPayloadBid.js +17 -31
  42. package/lib/block/processExecutionPayloadBid.js.map +1 -1
  43. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
  44. package/lib/block/processExecutionPayloadEnvelope.js +27 -27
  45. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
  46. package/lib/block/processOperations.js +2 -2
  47. package/lib/block/processOperations.js.map +1 -1
  48. package/lib/block/processPayloadAttestation.d.ts.map +1 -1
  49. package/lib/block/processPayloadAttestation.js +1 -1
  50. package/lib/block/processPayloadAttestation.js.map +1 -1
  51. package/lib/block/processProposerSlashing.d.ts +5 -2
  52. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  53. package/lib/block/processProposerSlashing.js +8 -6
  54. package/lib/block/processProposerSlashing.js.map +1 -1
  55. package/lib/block/processSyncCommittee.d.ts +1 -2
  56. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  57. package/lib/block/processSyncCommittee.js +6 -6
  58. package/lib/block/processSyncCommittee.js.map +1 -1
  59. package/lib/block/processVoluntaryExit.d.ts +1 -1
  60. package/lib/block/processVoluntaryExit.d.ts.map +1 -1
  61. package/lib/block/processVoluntaryExit.js +45 -3
  62. package/lib/block/processVoluntaryExit.js.map +1 -1
  63. package/lib/block/processWithdrawalRequest.js +1 -1
  64. package/lib/block/processWithdrawalRequest.js.map +1 -1
  65. package/lib/block/processWithdrawals.d.ts +1 -0
  66. package/lib/block/processWithdrawals.d.ts.map +1 -1
  67. package/lib/block/processWithdrawals.js +122 -68
  68. package/lib/block/processWithdrawals.js.map +1 -1
  69. package/lib/cache/epochCache.d.ts +8 -28
  70. package/lib/cache/epochCache.d.ts.map +1 -1
  71. package/lib/cache/epochCache.js +40 -180
  72. package/lib/cache/epochCache.js.map +1 -1
  73. package/lib/cache/epochTransitionCache.d.ts +5 -12
  74. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  75. package/lib/cache/epochTransitionCache.js +4 -14
  76. package/lib/cache/epochTransitionCache.js.map +1 -1
  77. package/lib/cache/stateCache.d.ts.map +1 -1
  78. package/lib/cache/stateCache.js +1 -2
  79. package/lib/cache/stateCache.js.map +1 -1
  80. package/lib/epoch/processBuilderPendingPayments.d.ts.map +1 -1
  81. package/lib/epoch/processBuilderPendingPayments.js +1 -4
  82. package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
  83. package/lib/epoch/processPendingAttestations.d.ts.map +1 -1
  84. package/lib/epoch/processPendingAttestations.js +1 -1
  85. package/lib/epoch/processPendingAttestations.js.map +1 -1
  86. package/lib/epoch/processProposerLookahead.d.ts.map +1 -1
  87. package/lib/epoch/processProposerLookahead.js +3 -6
  88. package/lib/epoch/processProposerLookahead.js.map +1 -1
  89. package/lib/index.d.ts +1 -1
  90. package/lib/index.d.ts.map +1 -1
  91. package/lib/index.js +1 -1
  92. package/lib/index.js.map +1 -1
  93. package/lib/rewards/blockRewards.d.ts +2 -1
  94. package/lib/rewards/blockRewards.d.ts.map +1 -1
  95. package/lib/rewards/blockRewards.js +3 -2
  96. package/lib/rewards/blockRewards.js.map +1 -1
  97. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
  98. package/lib/rewards/syncCommitteeRewards.js +10 -11
  99. package/lib/rewards/syncCommitteeRewards.js.map +1 -1
  100. package/lib/signatureSets/attesterSlashings.d.ts +3 -4
  101. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  102. package/lib/signatureSets/attesterSlashings.js +6 -6
  103. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  104. package/lib/signatureSets/blsToExecutionChange.d.ts +4 -5
  105. package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
  106. package/lib/signatureSets/blsToExecutionChange.js +2 -2
  107. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  108. package/lib/signatureSets/executionPayloadBid.d.ts +4 -0
  109. package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -0
  110. package/lib/signatureSets/executionPayloadBid.js +8 -0
  111. package/lib/signatureSets/executionPayloadBid.js.map +1 -0
  112. package/lib/signatureSets/executionPayloadEnvelope.d.ts +4 -0
  113. package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -0
  114. package/lib/signatureSets/executionPayloadEnvelope.js +8 -0
  115. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -0
  116. package/lib/signatureSets/index.d.ts +3 -2
  117. package/lib/signatureSets/index.d.ts.map +1 -1
  118. package/lib/signatureSets/index.js +10 -8
  119. package/lib/signatureSets/index.js.map +1 -1
  120. package/lib/signatureSets/indexedAttestation.d.ts +3 -4
  121. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  122. package/lib/signatureSets/indexedAttestation.js +6 -6
  123. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  124. package/lib/signatureSets/indexedPayloadAttestation.d.ts +5 -4
  125. package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
  126. package/lib/signatureSets/indexedPayloadAttestation.js +3 -3
  127. package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
  128. package/lib/signatureSets/proposer.d.ts +3 -3
  129. package/lib/signatureSets/proposer.d.ts.map +1 -1
  130. package/lib/signatureSets/proposer.js +12 -12
  131. package/lib/signatureSets/proposer.js.map +1 -1
  132. package/lib/signatureSets/proposerSlashings.d.ts +2 -3
  133. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  134. package/lib/signatureSets/proposerSlashings.js +6 -6
  135. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  136. package/lib/signatureSets/randao.d.ts +1 -1
  137. package/lib/signatureSets/randao.d.ts.map +1 -1
  138. package/lib/signatureSets/randao.js +4 -4
  139. package/lib/signatureSets/randao.js.map +1 -1
  140. package/lib/signatureSets/voluntaryExits.d.ts +2 -2
  141. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  142. package/lib/signatureSets/voluntaryExits.js +6 -6
  143. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  144. package/lib/slot/index.d.ts.map +1 -1
  145. package/lib/slot/index.js +1 -1
  146. package/lib/slot/index.js.map +1 -1
  147. package/lib/types.d.ts +1 -1
  148. package/lib/types.d.ts.map +1 -1
  149. package/lib/util/electra.d.ts.map +1 -1
  150. package/lib/util/electra.js +1 -2
  151. package/lib/util/electra.js.map +1 -1
  152. package/lib/util/epochShuffling.d.ts +1 -34
  153. package/lib/util/epochShuffling.d.ts.map +1 -1
  154. package/lib/util/epochShuffling.js +1 -1
  155. package/lib/util/epochShuffling.js.map +1 -1
  156. package/lib/util/gloas.d.ts +46 -5
  157. package/lib/util/gloas.d.ts.map +1 -1
  158. package/lib/util/gloas.js +92 -6
  159. package/lib/util/gloas.js.map +1 -1
  160. package/lib/util/index.d.ts +2 -2
  161. package/lib/util/index.d.ts.map +1 -1
  162. package/lib/util/index.js +2 -2
  163. package/lib/util/index.js.map +1 -1
  164. package/lib/util/interop.js +1 -1
  165. package/lib/util/interop.js.map +1 -1
  166. package/lib/util/loadState/findModifiedInactivityScores.d.ts +1 -1
  167. package/lib/util/loadState/findModifiedInactivityScores.d.ts.map +1 -1
  168. package/lib/util/loadState/findModifiedInactivityScores.js +3 -2
  169. package/lib/util/loadState/findModifiedInactivityScores.js.map +1 -1
  170. package/lib/util/loadState/findModifiedValidators.d.ts +2 -2
  171. package/lib/util/loadState/findModifiedValidators.d.ts.map +1 -1
  172. package/lib/util/loadState/findModifiedValidators.js +4 -3
  173. package/lib/util/loadState/findModifiedValidators.js.map +1 -1
  174. package/lib/util/loadState/loadValidator.d.ts.map +1 -1
  175. package/lib/util/loadState/loadValidator.js +3 -2
  176. package/lib/util/loadState/loadValidator.js.map +1 -1
  177. package/lib/util/shuffling.d.ts +58 -0
  178. package/lib/util/shuffling.d.ts.map +1 -0
  179. package/lib/util/shuffling.js +175 -0
  180. package/lib/util/shuffling.js.map +1 -0
  181. package/lib/util/signatureSets.d.ts +38 -5
  182. package/lib/util/signatureSets.d.ts.map +1 -1
  183. package/lib/util/signatureSets.js +48 -6
  184. package/lib/util/signatureSets.js.map +1 -1
  185. package/lib/util/validator.d.ts +6 -1
  186. package/lib/util/validator.d.ts.map +1 -1
  187. package/lib/util/validator.js +26 -16
  188. package/lib/util/validator.js.map +1 -1
  189. package/package.json +8 -8
  190. package/src/block/index.ts +1 -0
  191. package/src/block/isValidIndexedAttestation.ts +18 -12
  192. package/src/block/isValidIndexedPayloadAttestation.ts +4 -1
  193. package/src/block/processAttestationPhase0.ts +2 -1
  194. package/src/block/processAttestationsAltair.ts +3 -10
  195. package/src/block/processAttesterSlashing.ts +16 -4
  196. package/src/block/processBlockHeader.ts +1 -2
  197. package/src/block/processBlsToExecutionChange.ts +14 -16
  198. package/src/block/processConsolidationRequest.ts +5 -5
  199. package/src/block/processDepositRequest.ts +101 -8
  200. package/src/block/processExecutionPayload.ts +1 -2
  201. package/src/block/processExecutionPayloadBid.ts +21 -44
  202. package/src/block/processExecutionPayloadEnvelope.ts +35 -32
  203. package/src/block/processOperations.ts +2 -2
  204. package/src/block/processPayloadAttestation.ts +1 -1
  205. package/src/block/processProposerSlashing.ts +22 -12
  206. package/src/block/processSyncCommittee.ts +4 -7
  207. package/src/block/processVoluntaryExit.ts +60 -5
  208. package/src/block/processWithdrawalRequest.ts +1 -1
  209. package/src/block/processWithdrawals.ts +169 -72
  210. package/src/cache/epochCache.ts +52 -214
  211. package/src/cache/epochTransitionCache.ts +9 -34
  212. package/src/cache/stateCache.ts +1 -2
  213. package/src/epoch/processBuilderPendingPayments.ts +1 -5
  214. package/src/epoch/processPendingAttestations.ts +1 -1
  215. package/src/epoch/processProposerLookahead.ts +3 -7
  216. package/src/index.ts +0 -2
  217. package/src/rewards/blockRewards.ts +6 -3
  218. package/src/rewards/syncCommitteeRewards.ts +10 -13
  219. package/src/signatureSets/attesterSlashings.ts +3 -7
  220. package/src/signatureSets/blsToExecutionChange.ts +5 -6
  221. package/src/signatureSets/executionPayloadBid.ts +14 -0
  222. package/src/signatureSets/executionPayloadEnvelope.ts +13 -0
  223. package/src/signatureSets/index.ts +8 -9
  224. package/src/signatureSets/indexedAttestation.ts +2 -7
  225. package/src/signatureSets/indexedPayloadAttestation.ts +9 -7
  226. package/src/signatureSets/proposer.ts +8 -12
  227. package/src/signatureSets/proposerSlashings.ts +4 -7
  228. package/src/signatureSets/randao.ts +4 -8
  229. package/src/signatureSets/voluntaryExits.ts +5 -10
  230. package/src/slot/index.ts +1 -1
  231. package/src/types.ts +1 -0
  232. package/src/util/electra.ts +1 -4
  233. package/src/util/epochShuffling.ts +2 -43
  234. package/src/util/gloas.ts +117 -11
  235. package/src/util/index.ts +2 -2
  236. package/src/util/interop.ts +1 -1
  237. package/src/util/loadState/findModifiedInactivityScores.ts +4 -2
  238. package/src/util/loadState/findModifiedValidators.ts +4 -3
  239. package/src/util/loadState/loadValidator.ts +3 -2
  240. package/src/util/shuffling.ts +234 -0
  241. package/src/util/signatureSets.ts +84 -8
  242. package/src/util/validator.ts +31 -16
  243. package/lib/util/calculateCommitteeAssignments.d.ts +0 -12
  244. package/lib/util/calculateCommitteeAssignments.d.ts.map +0 -1
  245. package/lib/util/calculateCommitteeAssignments.js +0 -26
  246. package/lib/util/calculateCommitteeAssignments.js.map +0 -1
  247. package/lib/util/shufflingDecisionRoot.d.ts +0 -20
  248. package/lib/util/shufflingDecisionRoot.d.ts.map +0 -1
  249. package/lib/util/shufflingDecisionRoot.js +0 -76
  250. package/lib/util/shufflingDecisionRoot.js.map +0 -1
  251. package/src/util/calculateCommitteeAssignments.ts +0 -43
  252. package/src/util/shufflingDecisionRoot.ts +0 -81
@@ -2,13 +2,15 @@ import {ChainForkConfig} from "@lodestar/config";
2
2
  import {
3
3
  EFFECTIVE_BALANCE_INCREMENT,
4
4
  ForkSeq,
5
+ MAX_EFFECTIVE_BALANCE,
5
6
  MAX_EFFECTIVE_BALANCE_ELECTRA,
6
7
  MIN_ACTIVATION_BALANCE,
7
8
  } from "@lodestar/params";
8
9
  import {Epoch, ValidatorIndex, phase0} from "@lodestar/types";
9
10
  import {intDiv} from "@lodestar/utils";
10
11
  import {BeaconStateAllForks, CachedBeaconStateElectra, CachedBeaconStateGloas, EpochCache} from "../types.js";
11
- import {hasCompoundingWithdrawalCredential} from "./electra.js";
12
+ import {hasEth1WithdrawalCredential} from "./capella.js";
13
+ import {hasCompoundingWithdrawalCredential, hasExecutionWithdrawalCredential} from "./electra.js";
12
14
 
13
15
  /**
14
16
  * Check if [[validator]] is active
@@ -94,8 +96,35 @@ export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): numbe
94
96
  return MIN_ACTIVATION_BALANCE;
95
97
  }
96
98
 
99
+ /**
100
+ * Check if validator is partially withdrawable.
101
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/electra/beacon-chain.md#modified-is_partially_withdrawable_validator
102
+ */
103
+ export function isPartiallyWithdrawableValidator(fork: ForkSeq, validator: phase0.Validator, balance: number): boolean {
104
+ const isPostElectra = fork >= ForkSeq.electra;
105
+
106
+ // Check withdrawal credentials
107
+ const hasWithdrawableCredentials = isPostElectra
108
+ ? hasExecutionWithdrawalCredential(validator.withdrawalCredentials)
109
+ : hasEth1WithdrawalCredential(validator.withdrawalCredentials);
110
+
111
+ if (!hasWithdrawableCredentials) {
112
+ return false;
113
+ }
114
+
115
+ // Get max effective balance based on fork
116
+ const maxEffectiveBalance = isPostElectra
117
+ ? getMaxEffectiveBalance(validator.withdrawalCredentials)
118
+ : MAX_EFFECTIVE_BALANCE;
119
+
120
+ // Check if at max effective balance and has excess balance
121
+ const hasMaxEffectiveBalance = validator.effectiveBalance === maxEffectiveBalance;
122
+ const hasExcessBalance = balance > maxEffectiveBalance;
123
+
124
+ return hasMaxEffectiveBalance && hasExcessBalance;
125
+ }
126
+
97
127
  export function getPendingBalanceToWithdraw(
98
- fork: ForkSeq,
99
128
  state: CachedBeaconStateElectra | CachedBeaconStateGloas,
100
129
  validatorIndex: ValidatorIndex
101
130
  ): number {
@@ -106,19 +135,5 @@ export function getPendingBalanceToWithdraw(
106
135
  }
107
136
  }
108
137
 
109
- if (fork >= ForkSeq.gloas) {
110
- const stateGloas = state as CachedBeaconStateGloas;
111
- for (const item of stateGloas.builderPendingWithdrawals.getAllReadonly()) {
112
- if (item.builderIndex === validatorIndex) {
113
- total += item.amount;
114
- }
115
- }
116
- for (const item of stateGloas.builderPendingPayments.getAllReadonly()) {
117
- if (item.withdrawal.builderIndex === validatorIndex) {
118
- total += item.withdrawal.amount;
119
- }
120
- }
121
- }
122
-
123
138
  return total;
124
139
  }
@@ -1,12 +0,0 @@
1
- import { CommitteeIndex, Slot, ValidatorIndex } from "@lodestar/types";
2
- import { EpochShuffling } from "./epochShuffling.js";
3
- export interface AttesterDuty {
4
- validatorIndex: ValidatorIndex;
5
- committeeIndex: CommitteeIndex;
6
- committeeLength: number;
7
- committeesAtSlot: number;
8
- validatorCommitteeIndex: number;
9
- slot: Slot;
10
- }
11
- export declare function calculateCommitteeAssignments(epochShuffling: EpochShuffling, requestedValidatorIndices: ValidatorIndex[]): Map<ValidatorIndex, AttesterDuty>;
12
- //# sourceMappingURL=calculateCommitteeAssignments.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculateCommitteeAssignments.d.ts","sourceRoot":"","sources":["../../src/util/calculateCommitteeAssignments.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAE,IAAI,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAGnD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,cAAc,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB,EAAE,MAAM,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,wBAAgB,6BAA6B,CAC3C,cAAc,EAAE,cAAc,EAC9B,yBAAyB,EAAE,cAAc,EAAE,GAC1C,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAyBnC"}
@@ -1,26 +0,0 @@
1
- import { SLOTS_PER_EPOCH } from "@lodestar/params";
2
- export function calculateCommitteeAssignments(epochShuffling, requestedValidatorIndices) {
3
- const requestedValidatorIndicesSet = new Set(requestedValidatorIndices);
4
- const duties = new Map();
5
- const epochCommittees = epochShuffling.committees;
6
- for (let epochSlot = 0; epochSlot < SLOTS_PER_EPOCH; epochSlot++) {
7
- const slotCommittees = epochCommittees[epochSlot];
8
- for (let i = 0, committeesAtSlot = slotCommittees.length; i < committeesAtSlot; i++) {
9
- for (let j = 0, committeeLength = slotCommittees[i].length; j < committeeLength; j++) {
10
- const validatorIndex = slotCommittees[i][j];
11
- if (requestedValidatorIndicesSet.has(validatorIndex)) {
12
- duties.set(validatorIndex, {
13
- validatorIndex,
14
- committeeLength,
15
- committeesAtSlot,
16
- validatorCommitteeIndex: j,
17
- committeeIndex: i,
18
- slot: epochShuffling.epoch * SLOTS_PER_EPOCH + epochSlot,
19
- });
20
- }
21
- }
22
- }
23
- }
24
- return duties;
25
- }
26
- //# sourceMappingURL=calculateCommitteeAssignments.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculateCommitteeAssignments.js","sourceRoot":"","sources":["../../src/util/calculateCommitteeAssignments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAcjD,MAAM,UAAU,6BAA6B,CAC3C,cAA8B,EAC9B,yBAA2C;IAE3C,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEvD,MAAM,eAAe,GAAG,cAAc,CAAC,UAAU,CAAC;IAClD,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,eAAe,EAAE,SAAS,EAAE,EAAE,CAAC;QACjE,MAAM,cAAc,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,EAAE,EAAE,CAAC;YACpF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;gBACrF,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5C,IAAI,4BAA4B,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;oBACrD,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE;wBACzB,cAAc;wBACd,eAAe;wBACf,gBAAgB;wBAChB,uBAAuB,EAAE,CAAC;wBAC1B,cAAc,EAAE,CAAC;wBACjB,IAAI,EAAE,cAAc,CAAC,KAAK,GAAG,eAAe,GAAG,SAAS;qBACzD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,20 +0,0 @@
1
- import { ForkName } from "@lodestar/params";
2
- import { Epoch, Root } from "@lodestar/types";
3
- import { CachedBeaconStateAllForks } from "../types.js";
4
- /**
5
- * Returns the block root which decided the proposer shuffling for the current epoch. This root
6
- * can be used to key this proposer shuffling.
7
- *
8
- * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
9
- * It should be set to the latest block applied to this `state` or the genesis block root.
10
- */
11
- export declare function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null;
12
- /**
13
- * Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
14
- * This root can be used to key that attester shuffling.
15
- *
16
- * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
17
- * It should be set to the latest block applied to this `state` or the genesis block root.
18
- */
19
- export declare function attesterShufflingDecisionRoot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Root | null;
20
- //# sourceMappingURL=shufflingDecisionRoot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shufflingDecisionRoot.d.ts","sourceRoot":"","sources":["../../src/util/shufflingDecisionRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAiB,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAC,KAAK,EAAE,IAAI,EAAO,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,yBAAyB,EAAC,MAAM,aAAa,CAAC;AAItD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,yBAAyB,GAAG,IAAI,GAAG,IAAI,CAM3G;AAaD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAMlH"}
@@ -1,76 +0,0 @@
1
- import { isForkPostFulu } from "@lodestar/params";
2
- import { getBlockRootAtSlot } from "./blockRoot.js";
3
- import { computeStartSlotAtEpoch } from "./epoch.js";
4
- /**
5
- * Returns the block root which decided the proposer shuffling for the current epoch. This root
6
- * can be used to key this proposer shuffling.
7
- *
8
- * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
9
- * It should be set to the latest block applied to this `state` or the genesis block root.
10
- */
11
- export function proposerShufflingDecisionRoot(fork, state) {
12
- const decisionSlot = proposerShufflingDecisionSlot(fork, state);
13
- if (state.slot === decisionSlot) {
14
- return null;
15
- }
16
- return getBlockRootAtSlot(state, decisionSlot);
17
- }
18
- /**
19
- * Returns the slot at which the proposer shuffling was decided. The block root at this slot
20
- * can be used to key the proposer shuffling for the current epoch.
21
- */
22
- function proposerShufflingDecisionSlot(fork, state) {
23
- // After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
24
- const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
25
- const startSlot = computeStartSlotAtEpoch(epoch);
26
- return Math.max(startSlot - 1, 0);
27
- }
28
- /**
29
- * Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
30
- * This root can be used to key that attester shuffling.
31
- *
32
- * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
33
- * It should be set to the latest block applied to this `state` or the genesis block root.
34
- */
35
- export function attesterShufflingDecisionRoot(state, requestedEpoch) {
36
- const decisionSlot = attesterShufflingDecisionSlot(state, requestedEpoch);
37
- if (state.slot === decisionSlot) {
38
- return null;
39
- }
40
- return getBlockRootAtSlot(state, decisionSlot);
41
- }
42
- /**
43
- * Returns the slot at which the proposer shuffling was decided. The block root at this slot
44
- * can be used to key the proposer shuffling for the current epoch.
45
- */
46
- function attesterShufflingDecisionSlot(state, requestedEpoch) {
47
- const epoch = attesterShufflingDecisionEpoch(state, requestedEpoch);
48
- const slot = computeStartSlotAtEpoch(epoch);
49
- return Math.max(slot - 1, 0);
50
- }
51
- /**
52
- * Returns the epoch at which the attester shuffling was decided.
53
- *
54
- * Spec ref: https://github.com/ethereum/beacon-APIs/blob/v2.1.0/apis/validator/duties/attester.yaml#L15
55
- *
56
- * Throws an error when:
57
- * - `EpochTooLow` when `requestedEpoch` is more than 1 prior to `currentEpoch`.
58
- * - `EpochTooHigh` when `requestedEpoch` is more than 1 after `currentEpoch`.
59
- */
60
- function attesterShufflingDecisionEpoch(state, requestedEpoch) {
61
- const currentEpoch = state.epochCtx.epoch;
62
- // Next
63
- if (requestedEpoch === currentEpoch + 1)
64
- return currentEpoch;
65
- // Current
66
- if (requestedEpoch === currentEpoch)
67
- return Math.max(currentEpoch - 1, 0);
68
- // Previous
69
- if (requestedEpoch === currentEpoch - 1)
70
- return Math.max(currentEpoch - 2, 0);
71
- if (requestedEpoch < currentEpoch) {
72
- throw Error(`EpochTooLow: current ${currentEpoch} requested ${requestedEpoch}`);
73
- }
74
- throw Error(`EpochTooHigh: current ${currentEpoch} requested ${requestedEpoch}`);
75
- }
76
- //# sourceMappingURL=shufflingDecisionRoot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shufflingDecisionRoot.js","sourceRoot":"","sources":["../../src/util/shufflingDecisionRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,uBAAuB,EAAC,MAAM,YAAY,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,IAAc,EAAE,KAAgC;IAC5F,MAAM,YAAY,GAAG,6BAA6B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChE,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAS,6BAA6B,CAAC,IAAc,EAAE,KAAgC;IACrF,6FAA6F;IAC7F,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrF,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAgC,EAAE,cAAqB;IACnG,MAAM,YAAY,GAAG,6BAA6B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAC1E,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAS,6BAA6B,CAAC,KAAgC,EAAE,cAAqB;IAC5F,MAAM,KAAK,GAAG,8BAA8B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,8BAA8B,CAAC,KAAgC,EAAE,cAAqB;IAC7F,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IAE1C,OAAO;IACP,IAAI,cAAc,KAAK,YAAY,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC;IAC7D,UAAU;IACV,IAAI,cAAc,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1E,WAAW;IACX,IAAI,cAAc,KAAK,YAAY,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9E,IAAI,cAAc,GAAG,YAAY,EAAE,CAAC;QAClC,MAAM,KAAK,CAAC,wBAAwB,YAAY,cAAc,cAAc,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,KAAK,CAAC,yBAAyB,YAAY,cAAc,cAAc,EAAE,CAAC,CAAC;AACnF,CAAC"}
@@ -1,43 +0,0 @@
1
- import {SLOTS_PER_EPOCH} from "@lodestar/params";
2
- import {CommitteeIndex, Slot, ValidatorIndex} from "@lodestar/types";
3
- import {EpochShuffling} from "./epochShuffling.js";
4
-
5
- // Copied from lodestar-api package to avoid depending on the package
6
- export interface AttesterDuty {
7
- validatorIndex: ValidatorIndex;
8
- committeeIndex: CommitteeIndex;
9
- committeeLength: number;
10
- committeesAtSlot: number;
11
- validatorCommitteeIndex: number;
12
- slot: Slot;
13
- }
14
-
15
- export function calculateCommitteeAssignments(
16
- epochShuffling: EpochShuffling,
17
- requestedValidatorIndices: ValidatorIndex[]
18
- ): Map<ValidatorIndex, AttesterDuty> {
19
- const requestedValidatorIndicesSet = new Set(requestedValidatorIndices);
20
- const duties = new Map<ValidatorIndex, AttesterDuty>();
21
-
22
- const epochCommittees = epochShuffling.committees;
23
- for (let epochSlot = 0; epochSlot < SLOTS_PER_EPOCH; epochSlot++) {
24
- const slotCommittees = epochCommittees[epochSlot];
25
- for (let i = 0, committeesAtSlot = slotCommittees.length; i < committeesAtSlot; i++) {
26
- for (let j = 0, committeeLength = slotCommittees[i].length; j < committeeLength; j++) {
27
- const validatorIndex = slotCommittees[i][j];
28
- if (requestedValidatorIndicesSet.has(validatorIndex)) {
29
- duties.set(validatorIndex, {
30
- validatorIndex,
31
- committeeLength,
32
- committeesAtSlot,
33
- validatorCommitteeIndex: j,
34
- committeeIndex: i,
35
- slot: epochShuffling.epoch * SLOTS_PER_EPOCH + epochSlot,
36
- });
37
- }
38
- }
39
- }
40
- }
41
-
42
- return duties;
43
- }
@@ -1,81 +0,0 @@
1
- import {ForkName, isForkPostFulu} from "@lodestar/params";
2
- import {Epoch, Root, Slot} from "@lodestar/types";
3
- import {CachedBeaconStateAllForks} from "../types.js";
4
- import {getBlockRootAtSlot} from "./blockRoot.js";
5
- import {computeStartSlotAtEpoch} from "./epoch.js";
6
-
7
- /**
8
- * Returns the block root which decided the proposer shuffling for the current epoch. This root
9
- * can be used to key this proposer shuffling.
10
- *
11
- * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
12
- * It should be set to the latest block applied to this `state` or the genesis block root.
13
- */
14
- export function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null {
15
- const decisionSlot = proposerShufflingDecisionSlot(fork, state);
16
- if (state.slot === decisionSlot) {
17
- return null;
18
- }
19
- return getBlockRootAtSlot(state, decisionSlot);
20
- }
21
-
22
- /**
23
- * Returns the slot at which the proposer shuffling was decided. The block root at this slot
24
- * can be used to key the proposer shuffling for the current epoch.
25
- */
26
- function proposerShufflingDecisionSlot(fork: ForkName, state: CachedBeaconStateAllForks): Slot {
27
- // After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
28
- const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
29
- const startSlot = computeStartSlotAtEpoch(epoch);
30
- return Math.max(startSlot - 1, 0);
31
- }
32
-
33
- /**
34
- * Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
35
- * This root can be used to key that attester shuffling.
36
- *
37
- * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
38
- * It should be set to the latest block applied to this `state` or the genesis block root.
39
- */
40
- export function attesterShufflingDecisionRoot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Root | null {
41
- const decisionSlot = attesterShufflingDecisionSlot(state, requestedEpoch);
42
- if (state.slot === decisionSlot) {
43
- return null;
44
- }
45
- return getBlockRootAtSlot(state, decisionSlot);
46
- }
47
-
48
- /**
49
- * Returns the slot at which the proposer shuffling was decided. The block root at this slot
50
- * can be used to key the proposer shuffling for the current epoch.
51
- */
52
- function attesterShufflingDecisionSlot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Slot {
53
- const epoch = attesterShufflingDecisionEpoch(state, requestedEpoch);
54
- const slot = computeStartSlotAtEpoch(epoch);
55
- return Math.max(slot - 1, 0);
56
- }
57
-
58
- /**
59
- * Returns the epoch at which the attester shuffling was decided.
60
- *
61
- * Spec ref: https://github.com/ethereum/beacon-APIs/blob/v2.1.0/apis/validator/duties/attester.yaml#L15
62
- *
63
- * Throws an error when:
64
- * - `EpochTooLow` when `requestedEpoch` is more than 1 prior to `currentEpoch`.
65
- * - `EpochTooHigh` when `requestedEpoch` is more than 1 after `currentEpoch`.
66
- */
67
- function attesterShufflingDecisionEpoch(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Epoch {
68
- const currentEpoch = state.epochCtx.epoch;
69
-
70
- // Next
71
- if (requestedEpoch === currentEpoch + 1) return currentEpoch;
72
- // Current
73
- if (requestedEpoch === currentEpoch) return Math.max(currentEpoch - 1, 0);
74
- // Previous
75
- if (requestedEpoch === currentEpoch - 1) return Math.max(currentEpoch - 2, 0);
76
-
77
- if (requestedEpoch < currentEpoch) {
78
- throw Error(`EpochTooLow: current ${currentEpoch} requested ${requestedEpoch}`);
79
- }
80
- throw Error(`EpochTooHigh: current ${currentEpoch} requested ${requestedEpoch}`);
81
- }