@lodestar/beacon-node 1.39.0-dev.d4a47659a5 → 1.39.0-dev.e5f0c23f31

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 (360) hide show
  1. package/README.md +1 -1
  2. package/lib/api/impl/beacon/blocks/utils.js +1 -1
  3. package/lib/api/impl/beacon/blocks/utils.js.map +1 -1
  4. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  5. package/lib/chain/blocks/verifyBlock.js +1 -1
  6. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  7. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  8. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +4 -2
  9. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  10. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -1
  11. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  12. package/lib/chain/blocks/verifyBlocksSignatures.js +3 -2
  13. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  14. package/lib/chain/chain.d.ts +8 -12
  15. package/lib/chain/chain.d.ts.map +1 -1
  16. package/lib/chain/chain.js +23 -47
  17. package/lib/chain/chain.js.map +1 -1
  18. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  19. package/lib/chain/forkChoice/index.js +3 -3
  20. package/lib/chain/forkChoice/index.js.map +1 -1
  21. package/lib/chain/initState.d.ts +1 -14
  22. package/lib/chain/initState.d.ts.map +1 -1
  23. package/lib/chain/initState.js +1 -62
  24. package/lib/chain/initState.js.map +1 -1
  25. package/lib/chain/interface.d.ts +4 -9
  26. package/lib/chain/interface.d.ts.map +1 -1
  27. package/lib/chain/interface.js.map +1 -1
  28. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -4
  29. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  30. package/lib/chain/opPools/aggregatedAttestationPool.js +4 -4
  31. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  32. package/lib/chain/opPools/opPool.d.ts +3 -0
  33. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  34. package/lib/chain/opPools/opPool.js +9 -8
  35. package/lib/chain/opPools/opPool.js.map +1 -1
  36. package/lib/chain/prepareNextSlot.d.ts +0 -4
  37. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  38. package/lib/chain/prepareNextSlot.js +1 -21
  39. package/lib/chain/prepareNextSlot.js.map +1 -1
  40. package/lib/chain/produceBlock/produceBlockBody.d.ts +0 -1
  41. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  42. package/lib/chain/produceBlock/produceBlockBody.js +8 -11
  43. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  44. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +4 -1
  45. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  46. package/lib/chain/stateCache/persistentCheckpointsCache.js +4 -2
  47. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  48. package/lib/chain/validation/aggregateAndProof.js +9 -0
  49. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  50. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  51. package/lib/chain/validation/attesterSlashing.js +1 -1
  52. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  53. package/lib/chain/validation/block.d.ts.map +1 -1
  54. package/lib/chain/validation/block.js +3 -3
  55. package/lib/chain/validation/block.js.map +1 -1
  56. package/lib/chain/validation/blsToExecutionChange.js +1 -1
  57. package/lib/chain/validation/proposerSlashing.js +1 -1
  58. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  59. package/lib/chain/validation/signatureSets/aggregateAndProof.js +1 -1
  60. package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
  61. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -1
  62. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  63. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  64. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  65. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -1
  66. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  67. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  68. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  69. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -1
  70. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  71. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  72. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  73. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -1
  74. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  75. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -2
  76. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  77. package/lib/chain/validation/syncCommittee.js +1 -1
  78. package/lib/chain/validation/syncCommittee.js.map +1 -1
  79. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  80. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  81. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  82. package/lib/chain/validation/voluntaryExit.js +1 -1
  83. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  84. package/lib/db/beacon.d.ts +3 -7
  85. package/lib/db/beacon.d.ts.map +1 -1
  86. package/lib/db/beacon.js +33 -12
  87. package/lib/db/beacon.js.map +1 -1
  88. package/lib/db/buckets.d.ts +12 -6
  89. package/lib/db/buckets.d.ts.map +1 -1
  90. package/lib/db/buckets.js +6 -1
  91. package/lib/db/buckets.js.map +1 -1
  92. package/lib/db/interface.d.ts +2 -7
  93. package/lib/db/interface.d.ts.map +1 -1
  94. package/lib/db/repositories/index.d.ts +0 -3
  95. package/lib/db/repositories/index.d.ts.map +1 -1
  96. package/lib/db/repositories/index.js +0 -3
  97. package/lib/db/repositories/index.js.map +1 -1
  98. package/lib/execution/engine/http.d.ts +1 -1
  99. package/lib/execution/engine/http.d.ts.map +1 -1
  100. package/lib/execution/engine/http.js +2 -3
  101. package/lib/execution/engine/http.js.map +1 -1
  102. package/lib/execution/engine/index.d.ts.map +1 -1
  103. package/lib/execution/engine/index.js +1 -1
  104. package/lib/execution/engine/index.js.map +1 -1
  105. package/lib/execution/engine/interface.d.ts +1 -1
  106. package/lib/execution/engine/interface.d.ts.map +1 -1
  107. package/lib/execution/engine/interface.js.map +1 -1
  108. package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.d.ts +1 -1
  109. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -0
  110. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -0
  111. package/lib/execution/engine/jwt.d.ts.map +1 -0
  112. package/lib/execution/engine/jwt.js.map +1 -0
  113. package/lib/execution/engine/mock.d.ts.map +1 -1
  114. package/lib/execution/engine/mock.js +1 -1
  115. package/lib/execution/engine/mock.js.map +1 -1
  116. package/lib/execution/engine/payloadIdCache.d.ts +1 -1
  117. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
  118. package/lib/execution/engine/types.d.ts +1 -1
  119. package/lib/execution/engine/types.d.ts.map +1 -1
  120. package/lib/execution/engine/types.js +1 -1
  121. package/lib/execution/engine/types.js.map +1 -1
  122. package/lib/execution/engine/utils.d.ts +64 -2
  123. package/lib/execution/engine/utils.d.ts.map +1 -1
  124. package/lib/execution/engine/utils.js +91 -2
  125. package/lib/execution/engine/utils.js.map +1 -1
  126. package/lib/index.d.ts +1 -2
  127. package/lib/index.d.ts.map +1 -1
  128. package/lib/index.js +1 -2
  129. package/lib/index.js.map +1 -1
  130. package/lib/metrics/metrics/lodestar.d.ts +0 -35
  131. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  132. package/lib/metrics/metrics/lodestar.js +0 -90
  133. package/lib/metrics/metrics/lodestar.js.map +1 -1
  134. package/lib/network/peers/discover.d.ts.map +1 -1
  135. package/lib/network/peers/discover.js.map +1 -1
  136. package/lib/node/nodejs.d.ts +6 -3
  137. package/lib/node/nodejs.d.ts.map +1 -1
  138. package/lib/node/nodejs.js +13 -10
  139. package/lib/node/nodejs.js.map +1 -1
  140. package/lib/node/notifier.d.ts.map +1 -1
  141. package/lib/node/notifier.js +9 -6
  142. package/lib/node/notifier.js.map +1 -1
  143. package/lib/node/options.d.ts +0 -2
  144. package/lib/node/options.d.ts.map +1 -1
  145. package/lib/node/options.js +0 -2
  146. package/lib/node/options.js.map +1 -1
  147. package/lib/node/utils/interop/deposits.d.ts +2 -1
  148. package/lib/node/utils/interop/deposits.d.ts.map +1 -1
  149. package/lib/node/utils/interop/deposits.js.map +1 -1
  150. package/lib/node/utils/interop/state.d.ts +1 -1
  151. package/lib/node/utils/interop/state.d.ts.map +1 -1
  152. package/lib/node/utils/state.d.ts +1 -7
  153. package/lib/node/utils/state.d.ts.map +1 -1
  154. package/lib/node/utils/state.js +1 -14
  155. package/lib/node/utils/state.js.map +1 -1
  156. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  157. package/lib/sync/backfill/backfill.js +2 -4
  158. package/lib/sync/backfill/backfill.js.map +1 -1
  159. package/lib/sync/backfill/verify.d.ts +1 -1
  160. package/lib/sync/backfill/verify.d.ts.map +1 -1
  161. package/lib/sync/backfill/verify.js +2 -2
  162. package/lib/sync/backfill/verify.js.map +1 -1
  163. package/package.json +28 -26
  164. package/src/api/impl/beacon/blocks/utils.ts +1 -1
  165. package/src/chain/blocks/verifyBlock.ts +1 -0
  166. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -2
  167. package/src/chain/blocks/verifyBlocksSignatures.ts +13 -3
  168. package/src/chain/chain.ts +33 -56
  169. package/src/chain/forkChoice/index.ts +3 -2
  170. package/src/chain/initState.ts +1 -97
  171. package/src/chain/interface.ts +4 -8
  172. package/src/chain/opPools/aggregatedAttestationPool.ts +7 -7
  173. package/src/chain/opPools/opPool.ts +8 -8
  174. package/src/chain/prepareNextSlot.ts +1 -28
  175. package/src/chain/produceBlock/produceBlockBody.ts +8 -12
  176. package/src/chain/stateCache/persistentCheckpointsCache.ts +15 -2
  177. package/src/chain/validation/aggregateAndProof.ts +12 -0
  178. package/src/chain/validation/attesterSlashing.ts +6 -1
  179. package/src/chain/validation/block.ts +3 -2
  180. package/src/chain/validation/blsToExecutionChange.ts +1 -1
  181. package/src/chain/validation/proposerSlashing.ts +6 -1
  182. package/src/chain/validation/signatureSets/aggregateAndProof.ts +1 -1
  183. package/src/chain/validation/signatureSets/contributionAndProof.ts +3 -1
  184. package/src/chain/validation/signatureSets/syncCommittee.ts +3 -1
  185. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +3 -1
  186. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -1
  187. package/src/chain/validation/syncCommittee.ts +1 -1
  188. package/src/chain/validation/syncCommitteeContributionAndProof.ts +8 -3
  189. package/src/chain/validation/voluntaryExit.ts +1 -1
  190. package/src/db/beacon.ts +38 -16
  191. package/src/db/buckets.ts +12 -7
  192. package/src/db/interface.ts +2 -13
  193. package/src/db/repositories/index.ts +0 -3
  194. package/src/execution/engine/http.ts +8 -9
  195. package/src/execution/engine/index.ts +1 -1
  196. package/src/execution/engine/interface.ts +1 -1
  197. package/src/{eth1/provider → execution/engine}/jsonRpcHttpClient.ts +1 -1
  198. package/src/execution/engine/mock.ts +1 -2
  199. package/src/execution/engine/payloadIdCache.ts +1 -1
  200. package/src/execution/engine/types.ts +9 -9
  201. package/src/execution/engine/utils.ts +111 -5
  202. package/src/index.ts +1 -2
  203. package/src/metrics/metrics/lodestar.ts +0 -92
  204. package/src/network/peers/discover.ts +3 -3
  205. package/src/node/nodejs.ts +20 -11
  206. package/src/node/notifier.ts +13 -7
  207. package/src/node/options.ts +0 -3
  208. package/src/node/utils/interop/deposits.ts +3 -1
  209. package/src/node/utils/interop/state.ts +1 -1
  210. package/src/node/utils/state.ts +3 -18
  211. package/src/sync/backfill/backfill.ts +8 -3
  212. package/src/sync/backfill/verify.ts +2 -1
  213. package/lib/chain/genesis/genesis.d.ts +0 -51
  214. package/lib/chain/genesis/genesis.d.ts.map +0 -1
  215. package/lib/chain/genesis/genesis.js +0 -123
  216. package/lib/chain/genesis/genesis.js.map +0 -1
  217. package/lib/chain/genesis/interface.d.ts +0 -13
  218. package/lib/chain/genesis/interface.d.ts.map +0 -1
  219. package/lib/chain/genesis/interface.js +0 -2
  220. package/lib/chain/genesis/interface.js.map +0 -1
  221. package/lib/chain/rewards/attestationsRewards.d.ts +0 -7
  222. package/lib/chain/rewards/attestationsRewards.d.ts.map +0 -1
  223. package/lib/chain/rewards/attestationsRewards.js +0 -112
  224. package/lib/chain/rewards/attestationsRewards.js.map +0 -1
  225. package/lib/chain/rewards/blockRewards.d.ts +0 -14
  226. package/lib/chain/rewards/blockRewards.d.ts.map +0 -1
  227. package/lib/chain/rewards/blockRewards.js +0 -94
  228. package/lib/chain/rewards/blockRewards.js.map +0 -1
  229. package/lib/chain/rewards/syncCommitteeRewards.d.ts +0 -6
  230. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +0 -1
  231. package/lib/chain/rewards/syncCommitteeRewards.js +0 -36
  232. package/lib/chain/rewards/syncCommitteeRewards.js.map +0 -1
  233. package/lib/db/repositories/depositDataRoot.d.ts +0 -22
  234. package/lib/db/repositories/depositDataRoot.d.ts.map +0 -1
  235. package/lib/db/repositories/depositDataRoot.js +0 -62
  236. package/lib/db/repositories/depositDataRoot.js.map +0 -1
  237. package/lib/db/repositories/depositEvent.d.ts +0 -13
  238. package/lib/db/repositories/depositEvent.d.ts.map +0 -1
  239. package/lib/db/repositories/depositEvent.js +0 -27
  240. package/lib/db/repositories/depositEvent.js.map +0 -1
  241. package/lib/db/repositories/eth1Data.d.ts +0 -13
  242. package/lib/db/repositories/eth1Data.d.ts.map +0 -1
  243. package/lib/db/repositories/eth1Data.js +0 -26
  244. package/lib/db/repositories/eth1Data.js.map +0 -1
  245. package/lib/db/single/index.d.ts +0 -3
  246. package/lib/db/single/index.d.ts.map +0 -1
  247. package/lib/db/single/index.js +0 -3
  248. package/lib/db/single/index.js.map +0 -1
  249. package/lib/db/single/preGenesisState.d.ts +0 -16
  250. package/lib/db/single/preGenesisState.d.ts.map +0 -1
  251. package/lib/db/single/preGenesisState.js +0 -29
  252. package/lib/db/single/preGenesisState.js.map +0 -1
  253. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts +0 -14
  254. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts.map +0 -1
  255. package/lib/db/single/preGenesisStateLastProcessedBlock.js +0 -27
  256. package/lib/db/single/preGenesisStateLastProcessedBlock.js.map +0 -1
  257. package/lib/eth1/errors.d.ts +0 -66
  258. package/lib/eth1/errors.d.ts.map +0 -1
  259. package/lib/eth1/errors.js +0 -27
  260. package/lib/eth1/errors.js.map +0 -1
  261. package/lib/eth1/eth1DataCache.d.ts +0 -19
  262. package/lib/eth1/eth1DataCache.d.ts.map +0 -1
  263. package/lib/eth1/eth1DataCache.js +0 -19
  264. package/lib/eth1/eth1DataCache.js.map +0 -1
  265. package/lib/eth1/eth1DepositDataTracker.d.ts +0 -80
  266. package/lib/eth1/eth1DepositDataTracker.d.ts.map +0 -1
  267. package/lib/eth1/eth1DepositDataTracker.js +0 -317
  268. package/lib/eth1/eth1DepositDataTracker.js.map +0 -1
  269. package/lib/eth1/eth1DepositsCache.d.ts +0 -42
  270. package/lib/eth1/eth1DepositsCache.d.ts.map +0 -1
  271. package/lib/eth1/eth1DepositsCache.js +0 -119
  272. package/lib/eth1/eth1DepositsCache.js.map +0 -1
  273. package/lib/eth1/index.d.ts +0 -31
  274. package/lib/eth1/index.d.ts.map +0 -1
  275. package/lib/eth1/index.js +0 -71
  276. package/lib/eth1/index.js.map +0 -1
  277. package/lib/eth1/interface.d.ts +0 -74
  278. package/lib/eth1/interface.d.ts.map +0 -1
  279. package/lib/eth1/interface.js +0 -8
  280. package/lib/eth1/interface.js.map +0 -1
  281. package/lib/eth1/options.d.ts +0 -22
  282. package/lib/eth1/options.d.ts.map +0 -1
  283. package/lib/eth1/options.js +0 -8
  284. package/lib/eth1/options.js.map +0 -1
  285. package/lib/eth1/provider/eth1Provider.d.ts +0 -39
  286. package/lib/eth1/provider/eth1Provider.d.ts.map +0 -1
  287. package/lib/eth1/provider/eth1Provider.js +0 -147
  288. package/lib/eth1/provider/eth1Provider.js.map +0 -1
  289. package/lib/eth1/provider/jsonRpcHttpClient.d.ts.map +0 -1
  290. package/lib/eth1/provider/jsonRpcHttpClient.js.map +0 -1
  291. package/lib/eth1/provider/jwt.d.ts.map +0 -1
  292. package/lib/eth1/provider/jwt.js.map +0 -1
  293. package/lib/eth1/provider/utils.d.ts +0 -65
  294. package/lib/eth1/provider/utils.d.ts.map +0 -1
  295. package/lib/eth1/provider/utils.js +0 -120
  296. package/lib/eth1/provider/utils.js.map +0 -1
  297. package/lib/eth1/stream.d.ts +0 -15
  298. package/lib/eth1/stream.d.ts.map +0 -1
  299. package/lib/eth1/stream.js +0 -54
  300. package/lib/eth1/stream.js.map +0 -1
  301. package/lib/eth1/utils/depositContract.d.ts +0 -14
  302. package/lib/eth1/utils/depositContract.d.ts.map +0 -1
  303. package/lib/eth1/utils/depositContract.js +0 -33
  304. package/lib/eth1/utils/depositContract.js.map +0 -1
  305. package/lib/eth1/utils/deposits.d.ts +0 -8
  306. package/lib/eth1/utils/deposits.d.ts.map +0 -1
  307. package/lib/eth1/utils/deposits.js +0 -47
  308. package/lib/eth1/utils/deposits.js.map +0 -1
  309. package/lib/eth1/utils/eth1Data.d.ts +0 -22
  310. package/lib/eth1/utils/eth1Data.d.ts.map +0 -1
  311. package/lib/eth1/utils/eth1Data.js +0 -77
  312. package/lib/eth1/utils/eth1Data.js.map +0 -1
  313. package/lib/eth1/utils/eth1DepositEvent.d.ts +0 -7
  314. package/lib/eth1/utils/eth1DepositEvent.d.ts.map +0 -1
  315. package/lib/eth1/utils/eth1DepositEvent.js +0 -13
  316. package/lib/eth1/utils/eth1DepositEvent.js.map +0 -1
  317. package/lib/eth1/utils/eth1Vote.d.ts +0 -17
  318. package/lib/eth1/utils/eth1Vote.d.ts.map +0 -1
  319. package/lib/eth1/utils/eth1Vote.js +0 -111
  320. package/lib/eth1/utils/eth1Vote.js.map +0 -1
  321. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts +0 -9
  322. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts.map +0 -1
  323. package/lib/eth1/utils/groupDepositEventsByBlock.js +0 -17
  324. package/lib/eth1/utils/groupDepositEventsByBlock.js.map +0 -1
  325. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts +0 -10
  326. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts.map +0 -1
  327. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js +0 -14
  328. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js.map +0 -1
  329. package/src/chain/genesis/genesis.ts +0 -190
  330. package/src/chain/genesis/interface.ts +0 -14
  331. package/src/chain/rewards/attestationsRewards.ts +0 -197
  332. package/src/chain/rewards/blockRewards.ts +0 -150
  333. package/src/chain/rewards/syncCommitteeRewards.ts +0 -58
  334. package/src/db/repositories/depositDataRoot.ts +0 -80
  335. package/src/db/repositories/depositEvent.ts +0 -32
  336. package/src/db/repositories/eth1Data.ts +0 -33
  337. package/src/db/single/index.ts +0 -2
  338. package/src/db/single/preGenesisState.ts +0 -37
  339. package/src/db/single/preGenesisStateLastProcessedBlock.ts +0 -34
  340. package/src/eth1/errors.ts +0 -40
  341. package/src/eth1/eth1DataCache.ts +0 -26
  342. package/src/eth1/eth1DepositDataTracker.ts +0 -410
  343. package/src/eth1/eth1DepositsCache.ts +0 -141
  344. package/src/eth1/index.ts +0 -94
  345. package/src/eth1/interface.ts +0 -87
  346. package/src/eth1/options.ts +0 -28
  347. package/src/eth1/provider/eth1Provider.ts +0 -229
  348. package/src/eth1/provider/utils.ts +0 -136
  349. package/src/eth1/stream.ts +0 -75
  350. package/src/eth1/utils/depositContract.ts +0 -37
  351. package/src/eth1/utils/deposits.ts +0 -70
  352. package/src/eth1/utils/eth1Data.ts +0 -100
  353. package/src/eth1/utils/eth1DepositEvent.ts +0 -12
  354. package/src/eth1/utils/eth1Vote.ts +0 -142
  355. package/src/eth1/utils/groupDepositEventsByBlock.ts +0 -19
  356. package/src/eth1/utils/optimizeNextBlockDiffForGenesis.ts +0 -18
  357. /package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.js +0 -0
  358. /package/lib/{eth1/provider → execution/engine}/jwt.d.ts +0 -0
  359. /package/lib/{eth1/provider → execution/engine}/jwt.js +0 -0
  360. /package/src/{eth1/provider → execution/engine}/jwt.ts +0 -0
@@ -1,190 +0,0 @@
1
- import {Tree, toGindex} from "@chainsafe/persistent-merkle-tree";
2
- import {BeaconConfig, ChainForkConfig} from "@lodestar/config";
3
- import {GENESIS_EPOCH, GENESIS_SLOT} from "@lodestar/params";
4
- import {
5
- BeaconStateAllForks,
6
- CachedBeaconStateAllForks,
7
- applyDeposits,
8
- applyEth1BlockHash,
9
- applyTimestamp,
10
- createCachedBeaconState,
11
- createEmptyEpochCacheImmutableData,
12
- getActiveValidatorIndices,
13
- getGenesisBeaconState,
14
- getTemporaryBlockHeader,
15
- } from "@lodestar/state-transition";
16
- import {phase0, ssz} from "@lodestar/types";
17
- import {Logger} from "@lodestar/utils";
18
- import {DepositTree} from "../../db/repositories/depositDataRoot.js";
19
- import {IEth1Provider} from "../../eth1/index.js";
20
- import {IEth1StreamParams} from "../../eth1/interface.js";
21
- import {getDepositsAndBlockStreamForGenesis, getDepositsStream} from "../../eth1/stream.js";
22
- import {GenesisResult, IGenesisBuilder} from "./interface.js";
23
-
24
- export type GenesisBuilderKwargs = {
25
- config: ChainForkConfig;
26
- eth1Provider: IEth1Provider;
27
- logger: Logger;
28
-
29
- /** Use to restore pending progress */
30
- pendingStatus?: {
31
- state: BeaconStateAllForks;
32
- depositTree: DepositTree;
33
- lastProcessedBlockNumber: number;
34
- };
35
-
36
- signal?: AbortSignal;
37
- maxBlocksPerPoll?: number;
38
- };
39
-
40
- export class GenesisBuilder implements IGenesisBuilder {
41
- // Expose state to persist on error
42
- readonly state: CachedBeaconStateAllForks;
43
- readonly depositTree: DepositTree;
44
- /** Is null if no block has been processed yet */
45
- lastProcessedBlockNumber: number | null = null;
46
-
47
- private readonly config: BeaconConfig;
48
- private readonly eth1Provider: IEth1Provider;
49
- private readonly logger: Logger;
50
- private readonly signal?: AbortSignal;
51
- private readonly eth1Params: IEth1StreamParams;
52
- private readonly depositCache = new Set<number>();
53
- private readonly fromBlock: number;
54
- private readonly logEvery = 30 * 1000;
55
- private lastLog = 0;
56
- /** Current count of active validators in the state */
57
- private activatedValidatorCount: number;
58
-
59
- constructor({config, eth1Provider, logger, signal, pendingStatus, maxBlocksPerPoll}: GenesisBuilderKwargs) {
60
- // at genesis builder, there is no genesis validator so we don't have a real BeaconConfig
61
- // but we need BeaconConfig to temporarily create CachedBeaconState, the cast here is safe since we don't use any getDomain here
62
- // the use of state as CachedBeaconState is just for convenient, GenesisResult returns TreeView anyway
63
- this.eth1Provider = eth1Provider;
64
- this.logger = logger;
65
- this.signal = signal;
66
- this.eth1Params = {
67
- ...config,
68
- maxBlocksPerPoll: maxBlocksPerPoll ?? 10000,
69
- };
70
-
71
- let stateView: BeaconStateAllForks;
72
-
73
- if (pendingStatus) {
74
- this.logger.info("Restoring pending genesis state", {block: pendingStatus.lastProcessedBlockNumber});
75
- stateView = pendingStatus.state;
76
- this.depositTree = pendingStatus.depositTree;
77
- this.fromBlock = Math.max(pendingStatus.lastProcessedBlockNumber + 1, this.eth1Provider.deployBlock);
78
- } else {
79
- stateView = getGenesisBeaconState(
80
- config,
81
- ssz.phase0.Eth1Data.defaultValue(),
82
- getTemporaryBlockHeader(config, config.getForkTypes(GENESIS_SLOT).BeaconBlock.defaultValue())
83
- );
84
- this.depositTree = ssz.phase0.DepositDataRootList.defaultViewDU();
85
- this.fromBlock = this.eth1Provider.deployBlock;
86
- }
87
-
88
- // TODO - PENDING: Ensure EpochCacheImmutableData is created only once
89
- this.state = createCachedBeaconState(stateView, createEmptyEpochCacheImmutableData(config, stateView));
90
- this.config = this.state.config;
91
- this.activatedValidatorCount = getActiveValidatorIndices(stateView, GENESIS_EPOCH).length;
92
- }
93
-
94
- /**
95
- * Get eth1 deposit events and blocks and apply to this.state until we found genesis.
96
- */
97
- async waitForGenesis(): Promise<GenesisResult> {
98
- await this.eth1Provider.validateContract();
99
-
100
- // Load data from data from this.db.depositData, this.db.depositDataRoot
101
- // And start from a more recent fromBlock
102
- const blockNumberValidatorGenesis = await this.waitForGenesisValidators();
103
-
104
- const depositsAndBlocksStream = getDepositsAndBlockStreamForGenesis(
105
- blockNumberValidatorGenesis,
106
- this.eth1Provider,
107
- this.eth1Params,
108
- this.signal
109
- );
110
-
111
- for await (const [depositEvents, block] of depositsAndBlocksStream) {
112
- this.applyDeposits(depositEvents);
113
- applyTimestamp(this.config, this.state, block.timestamp);
114
- applyEth1BlockHash(this.state, block.blockHash);
115
- this.lastProcessedBlockNumber = block.blockNumber;
116
-
117
- if (
118
- this.state.genesisTime >= this.config.MIN_GENESIS_TIME &&
119
- this.activatedValidatorCount >= this.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
120
- ) {
121
- this.logger.info("Found genesis state", {blockNumber: block.blockNumber});
122
- return {
123
- state: this.state,
124
- depositTree: this.depositTree,
125
- block,
126
- };
127
- }
128
-
129
- this.throttledLog(`Waiting for min genesis time ${block.timestamp} / ${this.config.MIN_GENESIS_TIME}`);
130
- }
131
-
132
- throw Error("depositsStream stopped without a valid genesis state");
133
- }
134
-
135
- /**
136
- * First phase of waiting for genesis.
137
- * Stream deposits events in batches as big as possible without querying block data
138
- * @returns Block number at which there are enough active validators is state for genesis
139
- */
140
- private async waitForGenesisValidators(): Promise<number> {
141
- const depositsStream = getDepositsStream(this.fromBlock, this.eth1Provider, this.eth1Params, this.signal);
142
-
143
- for await (const {depositEvents, blockNumber} of depositsStream) {
144
- this.applyDeposits(depositEvents);
145
- this.lastProcessedBlockNumber = blockNumber;
146
-
147
- if (this.activatedValidatorCount >= this.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT) {
148
- this.logger.info("Found enough genesis validators", {blockNumber});
149
- return blockNumber;
150
- }
151
-
152
- this.throttledLog(
153
- `Found ${this.state.validators.length} / ${this.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT} validators to genesis`
154
- );
155
- }
156
-
157
- throw Error("depositsStream stopped without a valid genesis state");
158
- }
159
-
160
- private applyDeposits(depositEvents: phase0.DepositEvent[]): void {
161
- const newDeposits = depositEvents
162
- .filter((depositEvent) => !this.depositCache.has(depositEvent.index))
163
- .map((depositEvent) => {
164
- this.depositCache.add(depositEvent.index);
165
- this.depositTree.push(ssz.phase0.DepositData.hashTreeRoot(depositEvent.depositData));
166
- const gindex = toGindex(this.depositTree.type.depth, BigInt(depositEvent.index));
167
-
168
- // Apply changes from the push above
169
- this.depositTree.commit();
170
- const depositTreeNode = this.depositTree.node;
171
- return {
172
- proof: new Tree(depositTreeNode).getSingleProof(gindex),
173
- data: depositEvent.depositData,
174
- };
175
- });
176
-
177
- const {activatedValidatorCount} = applyDeposits(this.config, this.state, newDeposits, this.depositTree);
178
- this.activatedValidatorCount += activatedValidatorCount;
179
-
180
- // TODO: If necessary persist deposits here to this.db.depositData, this.db.depositDataRoot
181
- }
182
-
183
- /** Throttle genesis generation status log to prevent spamming */
184
- private throttledLog(message: string): void {
185
- if (Date.now() - this.lastLog > this.logEvery) {
186
- this.lastLog = Date.now();
187
- this.logger.info(message);
188
- }
189
- }
190
- }
@@ -1,14 +0,0 @@
1
- import {CompositeViewDU, VectorCompositeType} from "@chainsafe/ssz";
2
- import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
3
- import {ssz} from "@lodestar/types";
4
- import {Eth1Block} from "../../eth1/interface.js";
5
-
6
- export type GenesisResult = {
7
- state: CachedBeaconStateAllForks;
8
- depositTree: CompositeViewDU<VectorCompositeType<typeof ssz.Root>>;
9
- block: Eth1Block;
10
- };
11
-
12
- export interface IGenesisBuilder {
13
- waitForGenesis: () => Promise<GenesisResult>;
14
- }
@@ -1,197 +0,0 @@
1
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
2
- import {routes} from "@lodestar/api";
3
- import {
4
- EFFECTIVE_BALANCE_INCREMENT,
5
- ForkName,
6
- INACTIVITY_PENALTY_QUOTIENT_ALTAIR,
7
- MAX_EFFECTIVE_BALANCE,
8
- MAX_EFFECTIVE_BALANCE_ELECTRA,
9
- PARTICIPATION_FLAG_WEIGHTS,
10
- TIMELY_HEAD_FLAG_INDEX,
11
- TIMELY_SOURCE_FLAG_INDEX,
12
- TIMELY_TARGET_FLAG_INDEX,
13
- WEIGHT_DENOMINATOR,
14
- isForkPostElectra,
15
- } from "@lodestar/params";
16
- import {
17
- CachedBeaconStateAllForks,
18
- CachedBeaconStateAltair,
19
- EpochTransitionCache,
20
- FLAG_ELIGIBLE_ATTESTER,
21
- FLAG_PREV_HEAD_ATTESTER_UNSLASHED,
22
- FLAG_PREV_SOURCE_ATTESTER_UNSLASHED,
23
- FLAG_PREV_TARGET_ATTESTER_UNSLASHED,
24
- beforeProcessEpoch,
25
- hasMarkers,
26
- isInInactivityLeak,
27
- } from "@lodestar/state-transition";
28
- import {ValidatorIndex} from "@lodestar/types";
29
- import {fromHex} from "@lodestar/utils";
30
-
31
- export type AttestationsRewards = routes.beacon.AttestationsRewards;
32
- type IdealAttestationsReward = routes.beacon.IdealAttestationsReward;
33
- type TotalAttestationsReward = routes.beacon.TotalAttestationsReward;
34
- /** Attestations penalty with respect to effective balance in Gwei */
35
- type AttestationsPenalty = {target: number; source: number; effectiveBalance: number};
36
-
37
- const defaultAttestationsReward = {head: 0, target: 0, source: 0, inclusionDelay: 0, inactivity: 0};
38
- const defaultAttestationsPenalty = {target: 0, source: 0};
39
-
40
- export async function computeAttestationsRewards(
41
- pubkey2index: PubkeyIndexMap,
42
- state: CachedBeaconStateAllForks,
43
- validatorIds?: (ValidatorIndex | string)[]
44
- ): Promise<AttestationsRewards> {
45
- const fork = state.config.getForkName(state.slot);
46
- if (fork === ForkName.phase0) {
47
- throw Error("Unsupported fork. Attestations rewards calculation is not available in phase0");
48
- }
49
-
50
- const stateAltair = state as CachedBeaconStateAltair;
51
- const transitionCache = beforeProcessEpoch(stateAltair);
52
-
53
- const [idealRewards, penalties] = computeIdealAttestationsRewardsAndPenaltiesAltair(stateAltair, transitionCache);
54
- const totalRewards = computeTotalAttestationsRewardsAltair(
55
- pubkey2index,
56
- stateAltair,
57
- transitionCache,
58
- idealRewards,
59
- penalties,
60
- validatorIds
61
- );
62
-
63
- return {idealRewards, totalRewards};
64
- }
65
-
66
- function computeIdealAttestationsRewardsAndPenaltiesAltair(
67
- state: CachedBeaconStateAllForks,
68
- transitionCache: EpochTransitionCache
69
- ): [IdealAttestationsReward[], AttestationsPenalty[]] {
70
- const baseRewardPerIncrement = transitionCache.baseRewardPerIncrement;
71
- const activeBalanceByIncrement = transitionCache.totalActiveStakeByIncrement;
72
- const fork = state.config.getForkName(state.slot);
73
- const maxEffectiveBalance = isForkPostElectra(fork) ? MAX_EFFECTIVE_BALANCE_ELECTRA : MAX_EFFECTIVE_BALANCE;
74
- const maxEffectiveBalanceByIncrement = Math.floor(maxEffectiveBalance / EFFECTIVE_BALANCE_INCREMENT);
75
-
76
- const idealRewards = Array.from({length: maxEffectiveBalanceByIncrement + 1}, (_, effectiveBalanceByIncrement) => ({
77
- ...defaultAttestationsReward,
78
- effectiveBalance: effectiveBalanceByIncrement * EFFECTIVE_BALANCE_INCREMENT,
79
- }));
80
-
81
- const attestationsPenalties: AttestationsPenalty[] = Array.from(
82
- {length: maxEffectiveBalanceByIncrement + 1},
83
- (_, effectiveBalanceByIncrement) => ({
84
- ...defaultAttestationsPenalty,
85
- effectiveBalance: effectiveBalanceByIncrement * EFFECTIVE_BALANCE_INCREMENT,
86
- })
87
- );
88
-
89
- for (let i = 0; i < PARTICIPATION_FLAG_WEIGHTS.length; i++) {
90
- const weight = PARTICIPATION_FLAG_WEIGHTS[i];
91
-
92
- let unslashedStakeByIncrement: number;
93
- let flagName: keyof IdealAttestationsReward;
94
-
95
- switch (i) {
96
- case TIMELY_SOURCE_FLAG_INDEX: {
97
- unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.sourceStakeByIncrement;
98
- flagName = "source";
99
- break;
100
- }
101
- case TIMELY_TARGET_FLAG_INDEX: {
102
- unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.targetStakeByIncrement;
103
- flagName = "target";
104
- break;
105
- }
106
- case TIMELY_HEAD_FLAG_INDEX: {
107
- unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.headStakeByIncrement;
108
- flagName = "head";
109
- break;
110
- }
111
- default: {
112
- throw Error(`Unable to retrieve unslashed stake. Unknown participation flag index: ${i}`);
113
- }
114
- }
115
-
116
- for (
117
- let effectiveBalanceByIncrement = 0;
118
- effectiveBalanceByIncrement <= maxEffectiveBalanceByIncrement;
119
- effectiveBalanceByIncrement++
120
- ) {
121
- const baseReward = effectiveBalanceByIncrement * baseRewardPerIncrement;
122
- const rewardNumerator = baseReward * weight * unslashedStakeByIncrement;
123
- // Both idealReward and penalty are rounded to nearest integer. Loss of precision is minimal as unit is gwei
124
- const idealReward = Math.round(rewardNumerator / activeBalanceByIncrement / WEIGHT_DENOMINATOR);
125
- const penalty = Math.round((baseReward * weight) / WEIGHT_DENOMINATOR); // Positive number indicates penalty
126
-
127
- const idealAttestationsReward = idealRewards[effectiveBalanceByIncrement];
128
- idealAttestationsReward[flagName] = isInInactivityLeak(state) ? 0 : idealReward; // No attestations rewards during inactivity leak
129
-
130
- if (flagName !== "head") {
131
- const attestationPenalty = attestationsPenalties[effectiveBalanceByIncrement];
132
- attestationPenalty[flagName] = penalty;
133
- }
134
- }
135
- }
136
-
137
- return [idealRewards, attestationsPenalties];
138
- }
139
-
140
- // Same calculation as `getRewardsAndPenaltiesAltair` but returns the breakdown of rewards instead of aggregated
141
- function computeTotalAttestationsRewardsAltair(
142
- pubkey2index: PubkeyIndexMap,
143
- state: CachedBeaconStateAltair,
144
- transitionCache: EpochTransitionCache,
145
- idealRewards: IdealAttestationsReward[],
146
- penalties: AttestationsPenalty[],
147
- validatorIds: (ValidatorIndex | string)[] = []
148
- ): TotalAttestationsReward[] {
149
- const rewards = [];
150
- const {flags} = transitionCache;
151
- const {epochCtx, config} = state;
152
- const validatorIndices = validatorIds
153
- .map((id) => (typeof id === "number" ? id : pubkey2index.get(fromHex(id))))
154
- .filter((index) => index !== undefined); // Validator indices to include in the result
155
-
156
- const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;
157
-
158
- for (let i = 0; i < flags.length; i++) {
159
- if (validatorIndices.length && !validatorIndices.includes(i)) {
160
- continue;
161
- }
162
-
163
- const flag = flags[i];
164
- if (!hasMarkers(flag, FLAG_ELIGIBLE_ATTESTER)) {
165
- continue;
166
- }
167
-
168
- const effectiveBalanceIncrement = epochCtx.effectiveBalanceIncrements[i];
169
-
170
- const currentRewards = {...defaultAttestationsReward, validatorIndex: i};
171
-
172
- if (hasMarkers(flag, FLAG_PREV_SOURCE_ATTESTER_UNSLASHED)) {
173
- currentRewards.source = idealRewards[effectiveBalanceIncrement].source;
174
- } else {
175
- currentRewards.source = penalties[effectiveBalanceIncrement].source * -1; // Negative reward to indicate penalty
176
- }
177
-
178
- if (hasMarkers(flag, FLAG_PREV_TARGET_ATTESTER_UNSLASHED)) {
179
- currentRewards.target = idealRewards[effectiveBalanceIncrement].target;
180
- } else {
181
- currentRewards.target = penalties[effectiveBalanceIncrement].target * -1;
182
-
183
- // Also incur inactivity penalty if not voting target correctly
184
- const inactivityPenaltyNumerator =
185
- effectiveBalanceIncrement * EFFECTIVE_BALANCE_INCREMENT * state.inactivityScores.get(i);
186
- currentRewards.inactivity = Math.floor(inactivityPenaltyNumerator / inactivityPenaltyDenominator) * -1;
187
- }
188
-
189
- if (hasMarkers(flag, FLAG_PREV_HEAD_ATTESTER_UNSLASHED)) {
190
- currentRewards.head = idealRewards[effectiveBalanceIncrement].head;
191
- }
192
-
193
- rewards.push(currentRewards);
194
- }
195
-
196
- return rewards;
197
- }
@@ -1,150 +0,0 @@
1
- import {routes} from "@lodestar/api";
2
- import {
3
- ForkName,
4
- WHISTLEBLOWER_REWARD_QUOTIENT,
5
- WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA,
6
- isForkPostElectra,
7
- } from "@lodestar/params";
8
- import {
9
- CachedBeaconStateAllForks,
10
- CachedBeaconStateAltair,
11
- CachedBeaconStatePhase0,
12
- getAttesterSlashableIndices,
13
- processAttestationsAltair,
14
- } from "@lodestar/state-transition";
15
- import {BeaconBlock, altair, phase0} from "@lodestar/types";
16
-
17
- export type BlockRewards = routes.beacon.BlockRewards;
18
- type SubRewardValue = number; // All reward values should be integer
19
-
20
- /**
21
- * Calculate total proposer block rewards given block and the beacon state of the same slot before the block is applied (preState)
22
- * postState can be passed in to read reward cache if available
23
- * Standard (Non MEV) rewards for proposing a block consists of:
24
- * 1) Including attestations from (beacon) committee
25
- * 2) Including attestations from sync committee
26
- * 3) Reporting slashable behaviours from proposer and attester
27
- */
28
- export async function computeBlockRewards(
29
- block: BeaconBlock,
30
- preState: CachedBeaconStateAllForks,
31
- postState?: CachedBeaconStateAllForks
32
- ): Promise<BlockRewards> {
33
- const fork = preState.config.getForkName(block.slot);
34
- const {attestations: cachedAttestationsReward = 0, syncAggregate: cachedSyncAggregateReward = 0} =
35
- postState?.proposerRewards ?? {};
36
- let blockAttestationReward = cachedAttestationsReward;
37
- let syncAggregateReward = cachedSyncAggregateReward;
38
-
39
- if (blockAttestationReward === 0) {
40
- blockAttestationReward =
41
- fork === ForkName.phase0
42
- ? computeBlockAttestationRewardPhase0(block as phase0.BeaconBlock, preState as CachedBeaconStatePhase0)
43
- : computeBlockAttestationRewardAltair(block as altair.BeaconBlock, preState as CachedBeaconStateAltair);
44
- }
45
-
46
- if (syncAggregateReward === 0) {
47
- syncAggregateReward = computeSyncAggregateReward(block as altair.BeaconBlock, preState as CachedBeaconStateAltair);
48
- }
49
-
50
- const blockProposerSlashingReward = computeBlockProposerSlashingReward(fork, block, preState);
51
- const blockAttesterSlashingReward = computeBlockAttesterSlashingReward(fork, block, preState);
52
-
53
- const total =
54
- blockAttestationReward + syncAggregateReward + blockProposerSlashingReward + blockAttesterSlashingReward;
55
-
56
- return {
57
- proposerIndex: block.proposerIndex,
58
- total,
59
- attestations: blockAttestationReward,
60
- syncAggregate: syncAggregateReward,
61
- proposerSlashings: blockProposerSlashingReward,
62
- attesterSlashings: blockAttesterSlashingReward,
63
- };
64
- }
65
-
66
- /**
67
- * TODO: Calculate rewards received by block proposer for including attestations.
68
- */
69
- function computeBlockAttestationRewardPhase0(
70
- _block: phase0.BeaconBlock,
71
- _preState: CachedBeaconStatePhase0
72
- ): SubRewardValue {
73
- throw new Error("Unsupported fork! Block attestation reward calculation is not available in phase0");
74
- }
75
-
76
- /**
77
- * Calculate rewards received by block proposer for including attestations since Altair.
78
- * Reuses `processAttestationsAltair()`. Has dependency on RewardCache
79
- */
80
- function computeBlockAttestationRewardAltair(
81
- block: altair.BeaconBlock,
82
- preState: CachedBeaconStateAltair
83
- ): SubRewardValue {
84
- const fork = preState.config.getForkSeq(block.slot);
85
- const {attestations} = block.body;
86
-
87
- processAttestationsAltair(fork, preState, attestations, false);
88
-
89
- return preState.proposerRewards.attestations;
90
- }
91
-
92
- function computeSyncAggregateReward(block: altair.BeaconBlock, preState: CachedBeaconStateAltair): SubRewardValue {
93
- if (block.body.syncAggregate !== undefined) {
94
- const {syncCommitteeBits} = block.body.syncAggregate;
95
- const {syncProposerReward} = preState.epochCtx;
96
-
97
- return syncCommitteeBits.getTrueBitIndexes().length * Math.floor(syncProposerReward); // syncProposerReward should already be integer
98
- }
99
-
100
- return 0; // phase0 block does not have syncAggregate
101
- }
102
-
103
- /**
104
- * Calculate rewards received by block proposer for including proposer slashings.
105
- * All proposer slashing rewards go to block proposer and none to whistleblower as of Deneb
106
- */
107
- function computeBlockProposerSlashingReward(
108
- fork: ForkName,
109
- block: BeaconBlock,
110
- state: CachedBeaconStateAllForks
111
- ): SubRewardValue {
112
- let proposerSlashingReward = 0;
113
-
114
- for (const proposerSlashing of block.body.proposerSlashings) {
115
- const offendingProposerIndex = proposerSlashing.signedHeader1.message.proposerIndex;
116
- const offendingProposerBalance = state.validators.getReadonly(offendingProposerIndex).effectiveBalance;
117
- const whistleblowerRewardQuotient = isForkPostElectra(fork)
118
- ? WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA
119
- : WHISTLEBLOWER_REWARD_QUOTIENT;
120
-
121
- proposerSlashingReward += Math.floor(offendingProposerBalance / whistleblowerRewardQuotient);
122
- }
123
-
124
- return proposerSlashingReward;
125
- }
126
-
127
- /**
128
- * Calculate rewards received by block proposer for including attester slashings.
129
- * All attester slashing rewards go to block proposer and none to whistleblower as of Deneb
130
- */
131
- function computeBlockAttesterSlashingReward(
132
- fork: ForkName,
133
- block: BeaconBlock,
134
- preState: CachedBeaconStateAllForks
135
- ): SubRewardValue {
136
- let attesterSlashingReward = 0;
137
-
138
- for (const attesterSlashing of block.body.attesterSlashings) {
139
- for (const offendingAttesterIndex of getAttesterSlashableIndices(attesterSlashing)) {
140
- const offendingAttesterBalance = preState.validators.getReadonly(offendingAttesterIndex).effectiveBalance;
141
- const whistleblowerRewardQuotient = isForkPostElectra(fork)
142
- ? WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA
143
- : WHISTLEBLOWER_REWARD_QUOTIENT;
144
-
145
- attesterSlashingReward += Math.floor(offendingAttesterBalance / whistleblowerRewardQuotient);
146
- }
147
- }
148
-
149
- return attesterSlashingReward;
150
- }
@@ -1,58 +0,0 @@
1
- import {routes} from "@lodestar/api";
2
- import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
3
- import {CachedBeaconStateAllForks, CachedBeaconStateAltair, Index2PubkeyCache} from "@lodestar/state-transition";
4
- import {BeaconBlock, ValidatorIndex, altair} from "@lodestar/types";
5
-
6
- export type SyncCommitteeRewards = routes.beacon.SyncCommitteeRewards;
7
- type BalanceRecord = {val: number}; // Use val for convenient way to increment/decrement balance
8
-
9
- export async function computeSyncCommitteeRewards(
10
- index2pubkey: Index2PubkeyCache,
11
- block: BeaconBlock,
12
- preState: CachedBeaconStateAllForks,
13
- validatorIds: (ValidatorIndex | string)[] = []
14
- ): Promise<SyncCommitteeRewards> {
15
- const fork = preState.config.getForkName(block.slot);
16
- if (fork === ForkName.phase0) {
17
- throw Error("Cannot get sync rewards as phase0 block does not have sync committee");
18
- }
19
-
20
- const altairBlock = block as altair.BeaconBlock;
21
- const preStateAltair = preState as CachedBeaconStateAltair;
22
-
23
- // Bound syncCommitteeValidatorIndices in case it goes beyond SYNC_COMMITTEE_SIZE just to be safe
24
- const syncCommitteeValidatorIndices = preStateAltair.epochCtx.currentSyncCommitteeIndexed.validatorIndices.slice(
25
- 0,
26
- SYNC_COMMITTEE_SIZE
27
- );
28
- const {syncParticipantReward} = preStateAltair.epochCtx;
29
- const {syncCommitteeBits} = altairBlock.body.syncAggregate;
30
-
31
- // Use balance of each committee as starting point such that we cap the penalty to avoid balance dropping below 0
32
- const balances: Map<ValidatorIndex, BalanceRecord> = new Map();
33
- for (const i of syncCommitteeValidatorIndices) {
34
- balances.set(i, {val: preStateAltair.balances.get(i)});
35
- }
36
-
37
- for (const i of syncCommitteeValidatorIndices) {
38
- const balanceRecord = balances.get(i) as BalanceRecord;
39
- if (syncCommitteeBits.get(i)) {
40
- // Positive rewards for participants
41
- balanceRecord.val += syncParticipantReward;
42
- } else {
43
- // Negative rewards for non participants
44
- balanceRecord.val = Math.max(0, balanceRecord.val - syncParticipantReward);
45
- }
46
- }
47
-
48
- const rewards = Array.from(balances, ([validatorIndex, v]) => ({validatorIndex, reward: v.val}));
49
-
50
- if (validatorIds.length) {
51
- const filtersSet = new Set(validatorIds);
52
- return rewards.filter(
53
- (reward) => filtersSet.has(reward.validatorIndex) || filtersSet.has(index2pubkey[reward.validatorIndex].toHex())
54
- );
55
- }
56
-
57
- return rewards;
58
- }
@@ -1,80 +0,0 @@
1
- import {ByteVectorType, CompositeViewDU, ListCompositeType} from "@chainsafe/ssz";
2
- import {ChainForkConfig} from "@lodestar/config";
3
- import {Db, KeyValue, Repository} from "@lodestar/db";
4
- import {Root, ssz} from "@lodestar/types";
5
- import {bytesToInt} from "@lodestar/utils";
6
- import {Bucket, getBucketNameByValue} from "../buckets.js";
7
-
8
- // TODO: Review where is best to put this type
9
- export type DepositTree = CompositeViewDU<ListCompositeType<ByteVectorType>>;
10
-
11
- export class DepositDataRootRepository extends Repository<number, Root> {
12
- private depositRootTree?: DepositTree;
13
-
14
- constructor(config: ChainForkConfig, db: Db) {
15
- const bucket = Bucket.index_depositDataRoot;
16
- super(config, db, bucket, ssz.Root, getBucketNameByValue(bucket));
17
- }
18
-
19
- decodeKey(data: Buffer): number {
20
- return bytesToInt(super.decodeKey(data) as unknown as Uint8Array, "be");
21
- }
22
-
23
- // depositDataRoots stored by depositData index
24
- getId(_value: Root): number {
25
- throw new Error("Unable to create depositIndex from root");
26
- }
27
-
28
- async put(index: number, value: Root): Promise<void> {
29
- await super.put(index, value);
30
- await this.depositRootTreeSet(index, value);
31
- }
32
-
33
- async batchPut(items: KeyValue<number, Root>[]): Promise<void> {
34
- await super.batchPut(items);
35
- for (const {key, value} of items) {
36
- await this.depositRootTreeSet(key, value);
37
- }
38
- }
39
-
40
- async putList(roots: Root[]): Promise<void> {
41
- await this.batchPut(roots.map((root, index) => ({key: index, value: root})));
42
- }
43
-
44
- async batchPutValues(values: {index: number; root: Root}[]): Promise<void> {
45
- await this.batchPut(
46
- values.map(({index, root}) => ({
47
- key: index,
48
- value: root,
49
- }))
50
- );
51
- }
52
-
53
- async getDepositRootTree(): Promise<DepositTree> {
54
- if (!this.depositRootTree) {
55
- const values = await this.values();
56
- this.depositRootTree = ssz.phase0.DepositDataRootList.toViewDU(values);
57
- }
58
- return this.depositRootTree;
59
- }
60
-
61
- async getDepositRootTreeAtIndex(depositIndex: number): Promise<DepositTree> {
62
- const depositRootTree = await this.getDepositRootTree();
63
- return depositRootTree.sliceTo(depositIndex);
64
- }
65
-
66
- private async depositRootTreeSet(index: number, value: Uint8Array): Promise<void> {
67
- const depositRootTree = await this.getDepositRootTree();
68
-
69
- // TODO: Review and fix properly
70
- if (index > depositRootTree.length) {
71
- throw Error(`Error setting depositRootTree index ${index} > length ${depositRootTree.length}`);
72
- }
73
-
74
- if (index === depositRootTree.length) {
75
- depositRootTree.push(value);
76
- } else {
77
- depositRootTree.set(index, value);
78
- }
79
- }
80
- }