@lodestar/state-transition 1.35.0-dev.98d359db41 → 1.35.0-dev.a70bac5bd3

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 (284) hide show
  1. package/README.md +1 -1
  2. package/lib/block/index.d.ts +2 -2
  3. package/lib/block/index.js +2 -2
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/processAttestationPhase0.js +2 -1
  6. package/lib/block/processAttestationPhase0.js.map +1 -1
  7. package/lib/block/processAttestationsAltair.d.ts +1 -1
  8. package/lib/block/processAttestationsAltair.js +1 -1
  9. package/lib/block/processAttestationsAltair.js.map +1 -1
  10. package/lib/block/processAttesterSlashing.js.map +1 -1
  11. package/lib/block/processBlsToExecutionChange.js.map +1 -1
  12. package/lib/block/processConsolidationRequest.js.map +1 -1
  13. package/lib/block/processDeposit.d.ts +2 -2
  14. package/lib/block/processDeposit.js +1 -1
  15. package/lib/block/processDeposit.js.map +1 -1
  16. package/lib/block/processDepositRequest.js.map +1 -1
  17. package/lib/block/processOperations.js.map +1 -1
  18. package/lib/block/processSyncCommittee.js +2 -1
  19. package/lib/block/processSyncCommittee.js.map +1 -1
  20. package/lib/block/processWithdrawalRequest.js.map +1 -1
  21. package/lib/block/processWithdrawals.js.map +1 -1
  22. package/lib/block/slashValidator.js.map +1 -1
  23. package/lib/cache/epochCache.js +0 -130
  24. package/lib/cache/epochCache.js.map +1 -1
  25. package/lib/cache/epochTransitionCache.js.map +1 -1
  26. package/lib/epoch/index.js.map +1 -1
  27. package/lib/epoch/processSlashings.js.map +1 -1
  28. package/lib/index.d.ts +17 -17
  29. package/lib/index.js +16 -16
  30. package/lib/index.js.map +1 -1
  31. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  32. package/lib/signatureSets/index.d.ts +1 -1
  33. package/lib/signatureSets/index.js +1 -1
  34. package/lib/signatureSets/index.js.map +1 -1
  35. package/lib/slot/upgradeStateToDeneb.d.ts +2 -1
  36. package/lib/slot/upgradeStateToDeneb.js.map +1 -1
  37. package/lib/slot/upgradeStateToGloas.js +2 -2
  38. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  39. package/lib/types.d.ts +2 -2
  40. package/lib/util/blindedBlock.js.map +1 -1
  41. package/lib/util/execution.js.map +1 -1
  42. package/lib/util/genesis.js +4 -4
  43. package/lib/util/genesis.js.map +1 -1
  44. package/lib/util/index.d.ts +5 -5
  45. package/lib/util/index.js +5 -5
  46. package/lib/util/index.js.map +1 -1
  47. package/lib/util/interop.js +1 -1
  48. package/lib/util/interop.js.map +1 -1
  49. package/lib/util/rootCache.js +2 -5
  50. package/lib/util/rootCache.js.map +1 -1
  51. package/lib/util/seed.js +2 -1
  52. package/lib/util/seed.js.map +1 -1
  53. package/lib/util/weakSubjectivity.js.map +1 -1
  54. package/package.json +11 -13
  55. package/lib/block/externalData.d.ts.map +0 -1
  56. package/lib/block/index.d.ts.map +0 -1
  57. package/lib/block/initiateValidatorExit.d.ts.map +0 -1
  58. package/lib/block/isValidIndexedAttestation.d.ts.map +0 -1
  59. package/lib/block/processAttestationPhase0.d.ts.map +0 -1
  60. package/lib/block/processAttestations.d.ts.map +0 -1
  61. package/lib/block/processAttestationsAltair.d.ts.map +0 -1
  62. package/lib/block/processAttesterSlashing.d.ts.map +0 -1
  63. package/lib/block/processBlobKzgCommitments.d.ts.map +0 -1
  64. package/lib/block/processBlockHeader.d.ts.map +0 -1
  65. package/lib/block/processBlsToExecutionChange.d.ts.map +0 -1
  66. package/lib/block/processConsolidationRequest.d.ts.map +0 -1
  67. package/lib/block/processDeposit.d.ts.map +0 -1
  68. package/lib/block/processDepositRequest.d.ts.map +0 -1
  69. package/lib/block/processEth1Data.d.ts.map +0 -1
  70. package/lib/block/processExecutionPayload.d.ts.map +0 -1
  71. package/lib/block/processOperations.d.ts.map +0 -1
  72. package/lib/block/processProposerSlashing.d.ts.map +0 -1
  73. package/lib/block/processRandao.d.ts.map +0 -1
  74. package/lib/block/processSyncCommittee.d.ts.map +0 -1
  75. package/lib/block/processVoluntaryExit.d.ts.map +0 -1
  76. package/lib/block/processWithdrawalRequest.d.ts.map +0 -1
  77. package/lib/block/processWithdrawals.d.ts.map +0 -1
  78. package/lib/block/slashValidator.d.ts.map +0 -1
  79. package/lib/block/types.d.ts.map +0 -1
  80. package/lib/cache/effectiveBalanceIncrements.d.ts.map +0 -1
  81. package/lib/cache/epochCache.d.ts.map +0 -1
  82. package/lib/cache/epochTransitionCache.d.ts.map +0 -1
  83. package/lib/cache/pubkeyCache.d.ts.map +0 -1
  84. package/lib/cache/rewardCache.d.ts.map +0 -1
  85. package/lib/cache/stateCache.d.ts.map +0 -1
  86. package/lib/cache/syncCommitteeCache.d.ts.map +0 -1
  87. package/lib/cache/types.d.ts.map +0 -1
  88. package/lib/constants/constants.d.ts.map +0 -1
  89. package/lib/constants/index.d.ts.map +0 -1
  90. package/lib/epoch/computeUnrealizedCheckpoints.d.ts.map +0 -1
  91. package/lib/epoch/getAttestationDeltas.d.ts.map +0 -1
  92. package/lib/epoch/getRewardsAndPenalties.d.ts.map +0 -1
  93. package/lib/epoch/index.d.ts.map +0 -1
  94. package/lib/epoch/processEffectiveBalanceUpdates.d.ts.map +0 -1
  95. package/lib/epoch/processEth1DataReset.d.ts.map +0 -1
  96. package/lib/epoch/processHistoricalRootsUpdate.d.ts.map +0 -1
  97. package/lib/epoch/processHistoricalSummariesUpdate.d.ts.map +0 -1
  98. package/lib/epoch/processInactivityUpdates.d.ts.map +0 -1
  99. package/lib/epoch/processJustificationAndFinalization.d.ts.map +0 -1
  100. package/lib/epoch/processParticipationFlagUpdates.d.ts.map +0 -1
  101. package/lib/epoch/processParticipationRecordUpdates.d.ts.map +0 -1
  102. package/lib/epoch/processPendingAttestations.d.ts.map +0 -1
  103. package/lib/epoch/processPendingConsolidations.d.ts.map +0 -1
  104. package/lib/epoch/processPendingDeposits.d.ts.map +0 -1
  105. package/lib/epoch/processProposerLookahead.d.ts.map +0 -1
  106. package/lib/epoch/processRandaoMixesReset.d.ts.map +0 -1
  107. package/lib/epoch/processRegistryUpdates.d.ts.map +0 -1
  108. package/lib/epoch/processRewardsAndPenalties.d.ts.map +0 -1
  109. package/lib/epoch/processSlashings.d.ts.map +0 -1
  110. package/lib/epoch/processSlashingsReset.d.ts.map +0 -1
  111. package/lib/epoch/processSyncCommitteeUpdates.d.ts.map +0 -1
  112. package/lib/index.d.ts.map +0 -1
  113. package/lib/metrics.d.ts.map +0 -1
  114. package/lib/signatureSets/attesterSlashings.d.ts.map +0 -1
  115. package/lib/signatureSets/blsToExecutionChange.d.ts.map +0 -1
  116. package/lib/signatureSets/index.d.ts.map +0 -1
  117. package/lib/signatureSets/indexedAttestation.d.ts.map +0 -1
  118. package/lib/signatureSets/proposer.d.ts.map +0 -1
  119. package/lib/signatureSets/proposerSlashings.d.ts.map +0 -1
  120. package/lib/signatureSets/randao.d.ts.map +0 -1
  121. package/lib/signatureSets/voluntaryExits.d.ts.map +0 -1
  122. package/lib/slot/index.d.ts.map +0 -1
  123. package/lib/slot/upgradeStateToAltair.d.ts.map +0 -1
  124. package/lib/slot/upgradeStateToBellatrix.d.ts.map +0 -1
  125. package/lib/slot/upgradeStateToCapella.d.ts.map +0 -1
  126. package/lib/slot/upgradeStateToDeneb.d.ts.map +0 -1
  127. package/lib/slot/upgradeStateToElectra.d.ts.map +0 -1
  128. package/lib/slot/upgradeStateToFulu.d.ts.map +0 -1
  129. package/lib/slot/upgradeStateToGloas.d.ts.map +0 -1
  130. package/lib/stateTransition.d.ts.map +0 -1
  131. package/lib/types.d.ts.map +0 -1
  132. package/lib/util/aggregator.d.ts.map +0 -1
  133. package/lib/util/altair.d.ts.map +0 -1
  134. package/lib/util/array.d.ts.map +0 -1
  135. package/lib/util/attestation.d.ts.map +0 -1
  136. package/lib/util/attesterStatus.d.ts.map +0 -1
  137. package/lib/util/balance.d.ts.map +0 -1
  138. package/lib/util/blindedBlock.d.ts.map +0 -1
  139. package/lib/util/blockRoot.d.ts.map +0 -1
  140. package/lib/util/calculateCommitteeAssignments.d.ts.map +0 -1
  141. package/lib/util/capella.d.ts.map +0 -1
  142. package/lib/util/computeAnchorCheckpoint.d.ts.map +0 -1
  143. package/lib/util/deposit.d.ts.map +0 -1
  144. package/lib/util/domain.d.ts.map +0 -1
  145. package/lib/util/electra.d.ts.map +0 -1
  146. package/lib/util/epoch.d.ts.map +0 -1
  147. package/lib/util/epochShuffling.d.ts.map +0 -1
  148. package/lib/util/execution.d.ts.map +0 -1
  149. package/lib/util/finality.d.ts.map +0 -1
  150. package/lib/util/fulu.d.ts.map +0 -1
  151. package/lib/util/genesis.d.ts.map +0 -1
  152. package/lib/util/index.d.ts.map +0 -1
  153. package/lib/util/interop.d.ts.map +0 -1
  154. package/lib/util/loadState/findModifiedInactivityScores.d.ts.map +0 -1
  155. package/lib/util/loadState/findModifiedValidators.d.ts.map +0 -1
  156. package/lib/util/loadState/index.d.ts.map +0 -1
  157. package/lib/util/loadState/loadState.d.ts.map +0 -1
  158. package/lib/util/loadState/loadValidator.d.ts.map +0 -1
  159. package/lib/util/rootCache.d.ts.map +0 -1
  160. package/lib/util/seed.d.ts.map +0 -1
  161. package/lib/util/shufflingDecisionRoot.d.ts.map +0 -1
  162. package/lib/util/signatureSets.d.ts.map +0 -1
  163. package/lib/util/signingRoot.d.ts.map +0 -1
  164. package/lib/util/slot.d.ts.map +0 -1
  165. package/lib/util/sszBytes.d.ts.map +0 -1
  166. package/lib/util/syncCommittee.d.ts.map +0 -1
  167. package/lib/util/targetUnslashedBalance.d.ts.map +0 -1
  168. package/lib/util/validator.d.ts.map +0 -1
  169. package/lib/util/weakSubjectivity.d.ts.map +0 -1
  170. package/src/block/externalData.ts +0 -26
  171. package/src/block/index.ts +0 -81
  172. package/src/block/initiateValidatorExit.ts +0 -62
  173. package/src/block/isValidIndexedAttestation.ts +0 -70
  174. package/src/block/processAttestationPhase0.ts +0 -158
  175. package/src/block/processAttestations.ts +0 -25
  176. package/src/block/processAttestationsAltair.ts +0 -184
  177. package/src/block/processAttesterSlashing.ts +0 -59
  178. package/src/block/processBlobKzgCommitments.ts +0 -21
  179. package/src/block/processBlockHeader.ts +0 -54
  180. package/src/block/processBlsToExecutionChange.ts +0 -78
  181. package/src/block/processConsolidationRequest.ts +0 -147
  182. package/src/block/processDeposit.ts +0 -166
  183. package/src/block/processDepositRequest.ts +0 -19
  184. package/src/block/processEth1Data.ts +0 -86
  185. package/src/block/processExecutionPayload.ts +0 -84
  186. package/src/block/processOperations.ts +0 -83
  187. package/src/block/processProposerSlashing.ts +0 -66
  188. package/src/block/processRandao.ts +0 -27
  189. package/src/block/processSyncCommittee.ts +0 -117
  190. package/src/block/processVoluntaryExit.ts +0 -55
  191. package/src/block/processWithdrawalRequest.ts +0 -98
  192. package/src/block/processWithdrawals.ts +0 -207
  193. package/src/block/slashValidator.ts +0 -98
  194. package/src/block/types.ts +0 -9
  195. package/src/cache/effectiveBalanceIncrements.ts +0 -39
  196. package/src/cache/epochCache.ts +0 -1213
  197. package/src/cache/epochTransitionCache.ts +0 -542
  198. package/src/cache/pubkeyCache.ts +0 -33
  199. package/src/cache/rewardCache.ts +0 -19
  200. package/src/cache/stateCache.ts +0 -268
  201. package/src/cache/syncCommitteeCache.ts +0 -96
  202. package/src/cache/types.ts +0 -18
  203. package/src/constants/constants.ts +0 -12
  204. package/src/constants/index.ts +0 -1
  205. package/src/epoch/computeUnrealizedCheckpoints.ts +0 -55
  206. package/src/epoch/getAttestationDeltas.ts +0 -169
  207. package/src/epoch/getRewardsAndPenalties.ts +0 -137
  208. package/src/epoch/index.ts +0 -202
  209. package/src/epoch/processEffectiveBalanceUpdates.ts +0 -111
  210. package/src/epoch/processEth1DataReset.ts +0 -17
  211. package/src/epoch/processHistoricalRootsUpdate.ts +0 -25
  212. package/src/epoch/processHistoricalSummariesUpdate.ts +0 -23
  213. package/src/epoch/processInactivityUpdates.ts +0 -60
  214. package/src/epoch/processJustificationAndFinalization.ts +0 -90
  215. package/src/epoch/processParticipationFlagUpdates.ts +0 -27
  216. package/src/epoch/processParticipationRecordUpdates.ts +0 -14
  217. package/src/epoch/processPendingAttestations.ts +0 -75
  218. package/src/epoch/processPendingConsolidations.ts +0 -59
  219. package/src/epoch/processPendingDeposits.ts +0 -136
  220. package/src/epoch/processProposerLookahead.ts +0 -39
  221. package/src/epoch/processRandaoMixesReset.ts +0 -18
  222. package/src/epoch/processRegistryUpdates.ts +0 -65
  223. package/src/epoch/processRewardsAndPenalties.ts +0 -58
  224. package/src/epoch/processSlashings.ts +0 -97
  225. package/src/epoch/processSlashingsReset.ts +0 -20
  226. package/src/epoch/processSyncCommitteeUpdates.ts +0 -44
  227. package/src/index.ts +0 -67
  228. package/src/metrics.ts +0 -169
  229. package/src/signatureSets/attesterSlashings.ts +0 -39
  230. package/src/signatureSets/blsToExecutionChange.ts +0 -43
  231. package/src/signatureSets/index.ts +0 -73
  232. package/src/signatureSets/indexedAttestation.ts +0 -51
  233. package/src/signatureSets/proposer.ts +0 -47
  234. package/src/signatureSets/proposerSlashings.ts +0 -41
  235. package/src/signatureSets/randao.ts +0 -31
  236. package/src/signatureSets/voluntaryExits.ts +0 -44
  237. package/src/slot/index.ts +0 -32
  238. package/src/slot/upgradeStateToAltair.ts +0 -149
  239. package/src/slot/upgradeStateToBellatrix.ts +0 -63
  240. package/src/slot/upgradeStateToCapella.ts +0 -71
  241. package/src/slot/upgradeStateToDeneb.ts +0 -40
  242. package/src/slot/upgradeStateToElectra.ts +0 -126
  243. package/src/slot/upgradeStateToFulu.ts +0 -31
  244. package/src/slot/upgradeStateToGloas.ts +0 -29
  245. package/src/stateTransition.ts +0 -305
  246. package/src/types.ts +0 -26
  247. package/src/util/aggregator.ts +0 -33
  248. package/src/util/altair.ts +0 -13
  249. package/src/util/array.ts +0 -53
  250. package/src/util/attestation.ts +0 -36
  251. package/src/util/attesterStatus.ts +0 -83
  252. package/src/util/balance.ts +0 -83
  253. package/src/util/blindedBlock.ts +0 -144
  254. package/src/util/blockRoot.ts +0 -72
  255. package/src/util/calculateCommitteeAssignments.ts +0 -43
  256. package/src/util/capella.ts +0 -8
  257. package/src/util/computeAnchorCheckpoint.ts +0 -38
  258. package/src/util/deposit.ts +0 -22
  259. package/src/util/domain.ts +0 -31
  260. package/src/util/electra.ts +0 -68
  261. package/src/util/epoch.ts +0 -135
  262. package/src/util/epochShuffling.ts +0 -185
  263. package/src/util/execution.ts +0 -177
  264. package/src/util/finality.ts +0 -17
  265. package/src/util/fulu.ts +0 -43
  266. package/src/util/genesis.ts +0 -343
  267. package/src/util/index.ts +0 -29
  268. package/src/util/interop.ts +0 -22
  269. package/src/util/loadState/findModifiedInactivityScores.ts +0 -47
  270. package/src/util/loadState/findModifiedValidators.ts +0 -46
  271. package/src/util/loadState/index.ts +0 -2
  272. package/src/util/loadState/loadState.ts +0 -225
  273. package/src/util/loadState/loadValidator.ts +0 -77
  274. package/src/util/rootCache.ts +0 -37
  275. package/src/util/seed.ts +0 -381
  276. package/src/util/shufflingDecisionRoot.ts +0 -78
  277. package/src/util/signatureSets.ts +0 -65
  278. package/src/util/signingRoot.ts +0 -13
  279. package/src/util/slot.ts +0 -27
  280. package/src/util/sszBytes.ts +0 -52
  281. package/src/util/syncCommittee.ts +0 -69
  282. package/src/util/targetUnslashedBalance.ts +0 -30
  283. package/src/util/validator.ts +0 -105
  284. package/src/util/weakSubjectivity.ts +0 -186
@@ -1,207 +0,0 @@
1
- import {byteArrayEquals} from "@chainsafe/ssz";
2
- import {
3
- FAR_FUTURE_EPOCH,
4
- ForkSeq,
5
- MAX_EFFECTIVE_BALANCE,
6
- MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,
7
- MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP,
8
- MAX_WITHDRAWALS_PER_PAYLOAD,
9
- MIN_ACTIVATION_BALANCE,
10
- } from "@lodestar/params";
11
- import {ValidatorIndex, capella, ssz} from "@lodestar/types";
12
- import {MapDef, toRootHex} from "@lodestar/utils";
13
- import {CachedBeaconStateCapella, CachedBeaconStateElectra} from "../types.js";
14
- import {
15
- decreaseBalance,
16
- getMaxEffectiveBalance,
17
- hasEth1WithdrawalCredential,
18
- hasExecutionWithdrawalCredential,
19
- isCapellaPayloadHeader,
20
- } from "../util/index.js";
21
-
22
- export function processWithdrawals(
23
- fork: ForkSeq,
24
- state: CachedBeaconStateCapella | CachedBeaconStateElectra,
25
- payload: capella.FullOrBlindedExecutionPayload
26
- ): void {
27
- // processedPartialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
28
- const {withdrawals: expectedWithdrawals, processedPartialWithdrawalsCount} = getExpectedWithdrawals(fork, state);
29
- const numWithdrawals = expectedWithdrawals.length;
30
-
31
- if (isCapellaPayloadHeader(payload)) {
32
- const expectedWithdrawalsRoot = ssz.capella.Withdrawals.hashTreeRoot(expectedWithdrawals);
33
- const actualWithdrawalsRoot = payload.withdrawalsRoot;
34
- if (!byteArrayEquals(expectedWithdrawalsRoot, actualWithdrawalsRoot)) {
35
- throw Error(
36
- `Invalid withdrawalsRoot of executionPayloadHeader, expected=${toRootHex(
37
- expectedWithdrawalsRoot
38
- )}, actual=${toRootHex(actualWithdrawalsRoot)}`
39
- );
40
- }
41
- } else {
42
- if (expectedWithdrawals.length !== payload.withdrawals.length) {
43
- throw Error(`Invalid withdrawals length expected=${numWithdrawals} actual=${payload.withdrawals.length}`);
44
- }
45
- for (let i = 0; i < numWithdrawals; i++) {
46
- const withdrawal = expectedWithdrawals[i];
47
- if (!ssz.capella.Withdrawal.equals(withdrawal, payload.withdrawals[i])) {
48
- throw Error(`Withdrawal mismatch at index=${i}`);
49
- }
50
- }
51
- }
52
-
53
- for (let i = 0; i < numWithdrawals; i++) {
54
- const withdrawal = expectedWithdrawals[i];
55
- decreaseBalance(state, withdrawal.validatorIndex, Number(withdrawal.amount));
56
- }
57
-
58
- if (fork >= ForkSeq.electra) {
59
- const stateElectra = state as CachedBeaconStateElectra;
60
- stateElectra.pendingPartialWithdrawals = stateElectra.pendingPartialWithdrawals.sliceFrom(
61
- processedPartialWithdrawalsCount
62
- );
63
- }
64
-
65
- // Update the nextWithdrawalIndex
66
- const latestWithdrawal = expectedWithdrawals.at(-1);
67
- if (latestWithdrawal) {
68
- state.nextWithdrawalIndex = latestWithdrawal.index + 1;
69
- }
70
-
71
- // Update the nextWithdrawalValidatorIndex
72
- if (latestWithdrawal && expectedWithdrawals.length === MAX_WITHDRAWALS_PER_PAYLOAD) {
73
- // All slots filled, nextWithdrawalValidatorIndex should be validatorIndex having next turn
74
- state.nextWithdrawalValidatorIndex = (latestWithdrawal.validatorIndex + 1) % state.validators.length;
75
- } else {
76
- // expected withdrawals came up short in the bound, so we move nextWithdrawalValidatorIndex to
77
- // the next post the bound
78
- state.nextWithdrawalValidatorIndex =
79
- (state.nextWithdrawalValidatorIndex + MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP) % state.validators.length;
80
- }
81
- }
82
-
83
- export function getExpectedWithdrawals(
84
- fork: ForkSeq,
85
- state: CachedBeaconStateCapella | CachedBeaconStateElectra
86
- ): {
87
- withdrawals: capella.Withdrawal[];
88
- sampledValidators: number;
89
- processedPartialWithdrawalsCount: number;
90
- } {
91
- if (fork < ForkSeq.capella) {
92
- throw new Error(`getExpectedWithdrawals not supported at forkSeq=${fork} < ForkSeq.capella`);
93
- }
94
-
95
- const epoch = state.epochCtx.epoch;
96
- let withdrawalIndex = state.nextWithdrawalIndex;
97
- const {validators, balances, nextWithdrawalValidatorIndex} = state;
98
-
99
- const withdrawals: capella.Withdrawal[] = [];
100
- const withdrawnBalances = new MapDef<ValidatorIndex, number>(() => 0);
101
- const isPostElectra = fork >= ForkSeq.electra;
102
- // partialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
103
- let processedPartialWithdrawalsCount = 0;
104
-
105
- if (isPostElectra) {
106
- const stateElectra = state as CachedBeaconStateElectra;
107
-
108
- // MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP = 8, PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728 so we should only call getAllReadonly() if it makes sense
109
- // pendingPartialWithdrawals comes from EIP-7002 smart contract where it takes fee so it's more likely than not validator is in correct condition to withdraw
110
- // also we may break early if withdrawableEpoch > epoch
111
- const allPendingPartialWithdrawals =
112
- stateElectra.pendingPartialWithdrawals.length <= MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP
113
- ? stateElectra.pendingPartialWithdrawals.getAllReadonly()
114
- : null;
115
-
116
- // EIP-7002: Execution layer triggerable withdrawals
117
- for (let i = 0; i < stateElectra.pendingPartialWithdrawals.length; i++) {
118
- const withdrawal = allPendingPartialWithdrawals
119
- ? allPendingPartialWithdrawals[i]
120
- : stateElectra.pendingPartialWithdrawals.getReadonly(i);
121
- if (withdrawal.withdrawableEpoch > epoch || withdrawals.length === MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP) {
122
- break;
123
- }
124
-
125
- const validator = validators.getReadonly(withdrawal.validatorIndex);
126
- const totalWithdrawn = withdrawnBalances.getOrDefault(withdrawal.validatorIndex);
127
- const balance = state.balances.get(withdrawal.validatorIndex) - totalWithdrawn;
128
-
129
- if (
130
- validator.exitEpoch === FAR_FUTURE_EPOCH &&
131
- validator.effectiveBalance >= MIN_ACTIVATION_BALANCE &&
132
- balance > MIN_ACTIVATION_BALANCE
133
- ) {
134
- const balanceOverMinActivationBalance = BigInt(balance - MIN_ACTIVATION_BALANCE);
135
- const withdrawableBalance =
136
- balanceOverMinActivationBalance < withdrawal.amount ? balanceOverMinActivationBalance : withdrawal.amount;
137
- withdrawals.push({
138
- index: withdrawalIndex,
139
- validatorIndex: withdrawal.validatorIndex,
140
- address: validator.withdrawalCredentials.subarray(12),
141
- amount: withdrawableBalance,
142
- });
143
- withdrawalIndex++;
144
- withdrawnBalances.set(withdrawal.validatorIndex, totalWithdrawn + Number(withdrawableBalance));
145
- }
146
- processedPartialWithdrawalsCount++;
147
- }
148
- }
149
-
150
- const bound = Math.min(validators.length, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP);
151
- let n = 0;
152
- // Just run a bounded loop max iterating over all withdrawals
153
- // however breaks out once we have MAX_WITHDRAWALS_PER_PAYLOAD
154
- for (n = 0; n < bound; n++) {
155
- // Get next validator in turn
156
- const validatorIndex = (nextWithdrawalValidatorIndex + n) % validators.length;
157
-
158
- const validator = validators.getReadonly(validatorIndex);
159
- const withdrawnBalance = withdrawnBalances.getOrDefault(validatorIndex);
160
- const balance = isPostElectra
161
- ? // Deduct partially withdrawn balance already queued above
162
- balances.get(validatorIndex) - withdrawnBalance
163
- : balances.get(validatorIndex);
164
- const {withdrawableEpoch, withdrawalCredentials, effectiveBalance} = validator;
165
- const hasWithdrawableCredentials = isPostElectra
166
- ? hasExecutionWithdrawalCredential(withdrawalCredentials)
167
- : hasEth1WithdrawalCredential(withdrawalCredentials);
168
- // early skip for balance = 0 as its now more likely that validator has exited/slashed with
169
- // balance zero than not have withdrawal credentials set
170
- if (balance === 0 || !hasWithdrawableCredentials) {
171
- continue;
172
- }
173
-
174
- // capella full withdrawal
175
- if (withdrawableEpoch <= epoch) {
176
- withdrawals.push({
177
- index: withdrawalIndex,
178
- validatorIndex,
179
- address: validator.withdrawalCredentials.subarray(12),
180
- amount: BigInt(balance),
181
- });
182
- withdrawalIndex++;
183
- withdrawnBalances.set(validatorIndex, withdrawnBalance + balance);
184
- } else if (
185
- effectiveBalance === (isPostElectra ? getMaxEffectiveBalance(withdrawalCredentials) : MAX_EFFECTIVE_BALANCE) &&
186
- balance > effectiveBalance
187
- ) {
188
- // capella partial withdrawal
189
- const partialAmount = balance - effectiveBalance;
190
- withdrawals.push({
191
- index: withdrawalIndex,
192
- validatorIndex,
193
- address: validator.withdrawalCredentials.subarray(12),
194
- amount: BigInt(partialAmount),
195
- });
196
- withdrawalIndex++;
197
- withdrawnBalances.set(validatorIndex, withdrawnBalance + partialAmount);
198
- }
199
-
200
- // Break if we have enough to pack the block
201
- if (withdrawals.length >= MAX_WITHDRAWALS_PER_PAYLOAD) {
202
- break;
203
- }
204
- }
205
-
206
- return {withdrawals, sampledValidators: n, processedPartialWithdrawalsCount};
207
- }
@@ -1,98 +0,0 @@
1
- import {
2
- EFFECTIVE_BALANCE_INCREMENT,
3
- EPOCHS_PER_SLASHINGS_VECTOR,
4
- ForkSeq,
5
- MIN_SLASHING_PENALTY_QUOTIENT,
6
- MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR,
7
- MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX,
8
- MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA,
9
- PROPOSER_REWARD_QUOTIENT,
10
- PROPOSER_WEIGHT,
11
- TIMELY_TARGET_FLAG_INDEX,
12
- WEIGHT_DENOMINATOR,
13
- WHISTLEBLOWER_REWARD_QUOTIENT,
14
- WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA,
15
- } from "@lodestar/params";
16
- import {ValidatorIndex} from "@lodestar/types";
17
- import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
18
- import {decreaseBalance, increaseBalance} from "../util/index.js";
19
- import {initiateValidatorExit} from "./initiateValidatorExit.js";
20
-
21
- /** Same to https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/specs/altair/beacon-chain.md#has_flag */
22
- const TIMELY_TARGET = 1 << TIMELY_TARGET_FLAG_INDEX;
23
-
24
- export function slashValidator(
25
- fork: ForkSeq,
26
- state: CachedBeaconStateAllForks,
27
- slashedIndex: ValidatorIndex,
28
- whistleblowerIndex?: ValidatorIndex
29
- ): void {
30
- const {epochCtx} = state;
31
- const {epoch, effectiveBalanceIncrements} = epochCtx;
32
- const validator = state.validators.get(slashedIndex);
33
-
34
- // TODO: Bellatrix initiateValidatorExit validators.update() with the one below
35
- initiateValidatorExit(fork, state, validator);
36
-
37
- validator.slashed = true;
38
- validator.withdrawableEpoch = Math.max(validator.withdrawableEpoch, epoch + EPOCHS_PER_SLASHINGS_VECTOR);
39
-
40
- const {effectiveBalance} = validator;
41
-
42
- // state.slashings is initially a Gwei (BigInt) vector, however since Nov 2023 it's converted to UintNum64 (number) vector in the state transition because:
43
- // - state.slashings[nextEpoch % EPOCHS_PER_SLASHINGS_VECTOR] is reset per epoch in processSlashingsReset()
44
- // - max slashed validators per epoch is SLOTS_PER_EPOCH * MAX_ATTESTER_SLASHINGS * MAX_VALIDATORS_PER_COMMITTEE which is 32 * 2 * 2048 = 131072 on mainnet
45
- // - with that and 32_000_000_000 MAX_EFFECTIVE_BALANCE or 2048_000_000_000 MAX_EFFECTIVE_BALANCE_ELECTRA, it still fits in a number given that Math.floor(Number.MAX_SAFE_INTEGER / 32_000_000_000) = 281474
46
- // - we don't need to compute the total slashings from state.slashings, it's handled by totalSlashingsByIncrement in EpochCache
47
- const slashingIndex = epoch % EPOCHS_PER_SLASHINGS_VECTOR;
48
- state.slashings.set(slashingIndex, (state.slashings.get(slashingIndex) ?? 0) + effectiveBalance);
49
- epochCtx.totalSlashingsByIncrement += effectiveBalanceIncrements[slashedIndex];
50
-
51
- const minSlashingPenaltyQuotient =
52
- fork === ForkSeq.phase0
53
- ? MIN_SLASHING_PENALTY_QUOTIENT
54
- : fork === ForkSeq.altair
55
- ? MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR
56
- : fork < ForkSeq.electra // no change from bellatrix to deneb
57
- ? MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX
58
- : MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA;
59
- decreaseBalance(state, slashedIndex, Math.floor(effectiveBalance / minSlashingPenaltyQuotient));
60
-
61
- // apply proposer and whistleblower rewards
62
- const whistleblowerReward =
63
- fork < ForkSeq.electra
64
- ? Math.floor(effectiveBalance / WHISTLEBLOWER_REWARD_QUOTIENT)
65
- : Math.floor(effectiveBalance / WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA);
66
- const proposerReward =
67
- fork === ForkSeq.phase0
68
- ? Math.floor(whistleblowerReward / PROPOSER_REWARD_QUOTIENT)
69
- : Math.floor((whistleblowerReward * PROPOSER_WEIGHT) / WEIGHT_DENOMINATOR);
70
-
71
- const proposerIndex = epochCtx.getBeaconProposer(state.slot);
72
- if (whistleblowerIndex === undefined || !Number.isSafeInteger(whistleblowerIndex)) {
73
- // Call increaseBalance() once with `(whistleblowerReward - proposerReward) + proposerReward`
74
- increaseBalance(state, proposerIndex, whistleblowerReward);
75
- state.proposerRewards.slashing += whistleblowerReward;
76
- } else {
77
- increaseBalance(state, proposerIndex, proposerReward);
78
- increaseBalance(state, whistleblowerIndex, whistleblowerReward - proposerReward);
79
- state.proposerRewards.slashing += proposerReward;
80
- }
81
-
82
- // TODO: describe issue. Compute progressive target balances
83
- // if a validator is slashed, lookup their participation and remove from the cumulative values
84
- if (fork >= ForkSeq.altair) {
85
- const {previousEpochParticipation, currentEpochParticipation} = state as CachedBeaconStateAltair;
86
-
87
- if ((previousEpochParticipation.get(slashedIndex) & TIMELY_TARGET) === TIMELY_TARGET) {
88
- state.epochCtx.previousTargetUnslashedBalanceIncrements -= Math.floor(
89
- effectiveBalance / EFFECTIVE_BALANCE_INCREMENT
90
- );
91
- }
92
- if ((currentEpochParticipation.get(slashedIndex) & TIMELY_TARGET) === TIMELY_TARGET) {
93
- state.epochCtx.currentTargetUnslashedBalanceIncrements -= Math.floor(
94
- effectiveBalance / EFFECTIVE_BALANCE_INCREMENT
95
- );
96
- }
97
- }
98
- }
@@ -1,9 +0,0 @@
1
- export interface ProcessBlockOpts {
2
- verifySignatures?: boolean;
3
- }
4
-
5
- export enum ProposerRewardType {
6
- attestation = "attestation",
7
- syncAggregate = "sync_aggregate",
8
- slashing = "slashing",
9
- }
@@ -1,39 +0,0 @@
1
- import {EFFECTIVE_BALANCE_INCREMENT} from "@lodestar/params";
2
- import {BeaconStateAllForks} from "../types.js";
3
-
4
- /**
5
- * Alias to allow easier refactoring.
6
- */
7
- export type EffectiveBalanceIncrements = Uint16Array;
8
-
9
- /** Helper to prevent re-writting tests downstream if we change Uint16Array to number[] */
10
- export function getEffectiveBalanceIncrementsZeroed(len: number): EffectiveBalanceIncrements {
11
- return new Uint16Array(len);
12
- }
13
-
14
- /**
15
- * effectiveBalanceIncrements length will always be equal or greater than validatorCount. The
16
- * getEffectiveBalanceIncrementsByteLen() modulo is used to reduce the frequency at which its Uint16Array is recreated.
17
- * if effectiveBalanceIncrements has length greater than validatorCount it's not a problem since those values would
18
- * never be accessed.
19
- */
20
- export function getEffectiveBalanceIncrementsWithLen(validatorCount: number): EffectiveBalanceIncrements {
21
- // TODO: Research what's the best number to minimize both memory cost and copy costs
22
- const byteLen = 1024 * Math.ceil(validatorCount / 1024);
23
-
24
- return new Uint16Array(byteLen);
25
- }
26
-
27
- /**
28
- * Shows how EffectiveBalanceIncrements is meant to be populated.
29
- * In practice this function should not be used, since it more efficient to loop the validators array once and do
30
- * more tasks than only populating effectiveBalanceIncrements
31
- */
32
- export function getEffectiveBalanceIncrements(state: BeaconStateAllForks): EffectiveBalanceIncrements {
33
- const validatorsArr = state.validators.getAllReadonlyValues();
34
- const effectiveBalanceIncrements = new Uint16Array(validatorsArr.length);
35
- for (let i = 0; i < validatorsArr.length; i++) {
36
- effectiveBalanceIncrements[i] = Math.floor(validatorsArr[i].effectiveBalance / EFFECTIVE_BALANCE_INCREMENT);
37
- }
38
- return effectiveBalanceIncrements;
39
- }