@lodestar/beacon-node 1.39.0-dev.b37f2bd1bd → 1.39.0-dev.c151a164f2

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 (338) hide show
  1. package/lib/api/impl/beacon/blocks/utils.js +1 -1
  2. package/lib/api/impl/beacon/blocks/utils.js.map +1 -1
  3. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  4. package/lib/chain/blocks/verifyBlock.js +1 -1
  5. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  6. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -1
  7. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  8. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
  9. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  10. package/lib/chain/chain.d.ts +1 -4
  11. package/lib/chain/chain.d.ts.map +1 -1
  12. package/lib/chain/chain.js +8 -16
  13. package/lib/chain/chain.js.map +1 -1
  14. package/lib/chain/initState.d.ts +1 -14
  15. package/lib/chain/initState.d.ts.map +1 -1
  16. package/lib/chain/initState.js +1 -62
  17. package/lib/chain/initState.js.map +1 -1
  18. package/lib/chain/interface.d.ts +0 -2
  19. package/lib/chain/interface.d.ts.map +1 -1
  20. package/lib/chain/interface.js.map +1 -1
  21. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -4
  22. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  23. package/lib/chain/opPools/aggregatedAttestationPool.js +4 -4
  24. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  25. package/lib/chain/opPools/opPool.d.ts +3 -0
  26. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  27. package/lib/chain/opPools/opPool.js +9 -8
  28. package/lib/chain/opPools/opPool.js.map +1 -1
  29. package/lib/chain/prepareNextSlot.d.ts +0 -4
  30. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  31. package/lib/chain/prepareNextSlot.js +1 -21
  32. package/lib/chain/prepareNextSlot.js.map +1 -1
  33. package/lib/chain/produceBlock/produceBlockBody.d.ts +0 -1
  34. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  35. package/lib/chain/produceBlock/produceBlockBody.js +8 -11
  36. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  37. package/lib/chain/rewards/attestationsRewards.d.ts +2 -1
  38. package/lib/chain/rewards/attestationsRewards.d.ts.map +1 -1
  39. package/lib/chain/rewards/attestationsRewards.js +8 -8
  40. package/lib/chain/rewards/attestationsRewards.js.map +1 -1
  41. package/lib/chain/rewards/blockRewards.d.ts +2 -1
  42. package/lib/chain/rewards/blockRewards.d.ts.map +1 -1
  43. package/lib/chain/rewards/blockRewards.js +5 -5
  44. package/lib/chain/rewards/blockRewards.js.map +1 -1
  45. package/lib/chain/rewards/syncCommitteeRewards.d.ts +2 -1
  46. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +1 -1
  47. package/lib/chain/rewards/syncCommitteeRewards.js +2 -2
  48. package/lib/chain/rewards/syncCommitteeRewards.js.map +1 -1
  49. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +4 -1
  50. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  51. package/lib/chain/stateCache/persistentCheckpointsCache.js +4 -2
  52. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  53. package/lib/chain/validation/attesterSlashing.js +1 -1
  54. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  55. package/lib/chain/validation/block.js +1 -1
  56. package/lib/chain/validation/block.js.map +1 -1
  57. package/lib/chain/validation/blsToExecutionChange.js +1 -1
  58. package/lib/chain/validation/proposerSlashing.js +1 -1
  59. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  60. package/lib/chain/validation/signatureSets/aggregateAndProof.js +1 -1
  61. package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
  62. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -1
  63. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  64. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  65. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  66. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -1
  67. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  68. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  69. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  70. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -1
  71. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  72. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  73. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  74. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -1
  75. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  76. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -2
  77. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  78. package/lib/chain/validation/syncCommittee.js +1 -1
  79. package/lib/chain/validation/syncCommittee.js.map +1 -1
  80. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  81. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  82. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  83. package/lib/chain/validation/voluntaryExit.js +1 -1
  84. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  85. package/lib/db/beacon.d.ts +3 -7
  86. package/lib/db/beacon.d.ts.map +1 -1
  87. package/lib/db/beacon.js +33 -12
  88. package/lib/db/beacon.js.map +1 -1
  89. package/lib/db/buckets.d.ts +12 -6
  90. package/lib/db/buckets.d.ts.map +1 -1
  91. package/lib/db/buckets.js +6 -1
  92. package/lib/db/buckets.js.map +1 -1
  93. package/lib/db/interface.d.ts +2 -7
  94. package/lib/db/interface.d.ts.map +1 -1
  95. package/lib/db/repositories/index.d.ts +0 -3
  96. package/lib/db/repositories/index.d.ts.map +1 -1
  97. package/lib/db/repositories/index.js +0 -3
  98. package/lib/db/repositories/index.js.map +1 -1
  99. package/lib/execution/engine/http.d.ts +1 -1
  100. package/lib/execution/engine/http.d.ts.map +1 -1
  101. package/lib/execution/engine/http.js +2 -3
  102. package/lib/execution/engine/http.js.map +1 -1
  103. package/lib/execution/engine/index.d.ts.map +1 -1
  104. package/lib/execution/engine/index.js +1 -1
  105. package/lib/execution/engine/index.js.map +1 -1
  106. package/lib/execution/engine/interface.d.ts +1 -1
  107. package/lib/execution/engine/interface.d.ts.map +1 -1
  108. package/lib/execution/engine/interface.js.map +1 -1
  109. package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.d.ts +1 -1
  110. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -0
  111. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -0
  112. package/lib/execution/engine/jwt.d.ts.map +1 -0
  113. package/lib/execution/engine/jwt.js.map +1 -0
  114. package/lib/execution/engine/mock.d.ts.map +1 -1
  115. package/lib/execution/engine/mock.js +1 -1
  116. package/lib/execution/engine/mock.js.map +1 -1
  117. package/lib/execution/engine/payloadIdCache.d.ts +1 -1
  118. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
  119. package/lib/execution/engine/types.d.ts +1 -1
  120. package/lib/execution/engine/types.d.ts.map +1 -1
  121. package/lib/execution/engine/types.js +1 -1
  122. package/lib/execution/engine/types.js.map +1 -1
  123. package/lib/execution/engine/utils.d.ts +64 -2
  124. package/lib/execution/engine/utils.d.ts.map +1 -1
  125. package/lib/execution/engine/utils.js +91 -2
  126. package/lib/execution/engine/utils.js.map +1 -1
  127. package/lib/index.d.ts +1 -2
  128. package/lib/index.d.ts.map +1 -1
  129. package/lib/index.js +1 -2
  130. package/lib/index.js.map +1 -1
  131. package/lib/metrics/metrics/lodestar.d.ts +0 -35
  132. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  133. package/lib/metrics/metrics/lodestar.js +0 -90
  134. package/lib/metrics/metrics/lodestar.js.map +1 -1
  135. package/lib/node/nodejs.d.ts.map +1 -1
  136. package/lib/node/nodejs.js +10 -9
  137. package/lib/node/nodejs.js.map +1 -1
  138. package/lib/node/options.d.ts +0 -2
  139. package/lib/node/options.d.ts.map +1 -1
  140. package/lib/node/options.js +0 -2
  141. package/lib/node/options.js.map +1 -1
  142. package/lib/node/utils/interop/deposits.d.ts +2 -1
  143. package/lib/node/utils/interop/deposits.d.ts.map +1 -1
  144. package/lib/node/utils/interop/deposits.js.map +1 -1
  145. package/lib/node/utils/interop/state.d.ts +1 -1
  146. package/lib/node/utils/interop/state.d.ts.map +1 -1
  147. package/lib/node/utils/state.d.ts +1 -7
  148. package/lib/node/utils/state.d.ts.map +1 -1
  149. package/lib/node/utils/state.js +1 -14
  150. package/lib/node/utils/state.js.map +1 -1
  151. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  152. package/lib/sync/backfill/backfill.js +2 -4
  153. package/lib/sync/backfill/backfill.js.map +1 -1
  154. package/lib/sync/backfill/verify.d.ts +1 -1
  155. package/lib/sync/backfill/verify.d.ts.map +1 -1
  156. package/lib/sync/backfill/verify.js +2 -2
  157. package/lib/sync/backfill/verify.js.map +1 -1
  158. package/package.json +14 -20
  159. package/src/api/impl/beacon/blocks/utils.ts +1 -1
  160. package/src/chain/blocks/verifyBlock.ts +1 -0
  161. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -1
  162. package/src/chain/chain.ts +7 -19
  163. package/src/chain/initState.ts +1 -97
  164. package/src/chain/interface.ts +0 -2
  165. package/src/chain/opPools/aggregatedAttestationPool.ts +7 -7
  166. package/src/chain/opPools/opPool.ts +8 -8
  167. package/src/chain/prepareNextSlot.ts +1 -28
  168. package/src/chain/produceBlock/produceBlockBody.ts +8 -12
  169. package/src/chain/rewards/attestationsRewards.ts +13 -4
  170. package/src/chain/rewards/blockRewards.ts +6 -3
  171. package/src/chain/rewards/syncCommitteeRewards.ts +3 -1
  172. package/src/chain/stateCache/persistentCheckpointsCache.ts +15 -2
  173. package/src/chain/validation/attesterSlashing.ts +1 -1
  174. package/src/chain/validation/block.ts +1 -1
  175. package/src/chain/validation/blsToExecutionChange.ts +1 -1
  176. package/src/chain/validation/proposerSlashing.ts +1 -1
  177. package/src/chain/validation/signatureSets/aggregateAndProof.ts +1 -1
  178. package/src/chain/validation/signatureSets/contributionAndProof.ts +3 -1
  179. package/src/chain/validation/signatureSets/syncCommittee.ts +3 -1
  180. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +3 -1
  181. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -1
  182. package/src/chain/validation/syncCommittee.ts +1 -1
  183. package/src/chain/validation/syncCommitteeContributionAndProof.ts +8 -3
  184. package/src/chain/validation/voluntaryExit.ts +1 -1
  185. package/src/db/beacon.ts +38 -16
  186. package/src/db/buckets.ts +12 -7
  187. package/src/db/interface.ts +2 -13
  188. package/src/db/repositories/index.ts +0 -3
  189. package/src/execution/engine/http.ts +8 -9
  190. package/src/execution/engine/index.ts +1 -1
  191. package/src/execution/engine/interface.ts +1 -1
  192. package/src/{eth1/provider → execution/engine}/jsonRpcHttpClient.ts +1 -1
  193. package/src/execution/engine/mock.ts +1 -2
  194. package/src/execution/engine/payloadIdCache.ts +1 -1
  195. package/src/execution/engine/types.ts +9 -9
  196. package/src/execution/engine/utils.ts +111 -5
  197. package/src/index.ts +1 -2
  198. package/src/metrics/metrics/lodestar.ts +0 -92
  199. package/src/node/nodejs.ts +11 -9
  200. package/src/node/options.ts +0 -3
  201. package/src/node/utils/interop/deposits.ts +3 -1
  202. package/src/node/utils/interop/state.ts +1 -1
  203. package/src/node/utils/state.ts +3 -18
  204. package/src/sync/backfill/backfill.ts +8 -3
  205. package/src/sync/backfill/verify.ts +3 -1
  206. package/lib/chain/genesis/genesis.d.ts +0 -51
  207. package/lib/chain/genesis/genesis.d.ts.map +0 -1
  208. package/lib/chain/genesis/genesis.js +0 -123
  209. package/lib/chain/genesis/genesis.js.map +0 -1
  210. package/lib/chain/genesis/interface.d.ts +0 -13
  211. package/lib/chain/genesis/interface.d.ts.map +0 -1
  212. package/lib/chain/genesis/interface.js +0 -2
  213. package/lib/chain/genesis/interface.js.map +0 -1
  214. package/lib/db/repositories/depositDataRoot.d.ts +0 -22
  215. package/lib/db/repositories/depositDataRoot.d.ts.map +0 -1
  216. package/lib/db/repositories/depositDataRoot.js +0 -62
  217. package/lib/db/repositories/depositDataRoot.js.map +0 -1
  218. package/lib/db/repositories/depositEvent.d.ts +0 -13
  219. package/lib/db/repositories/depositEvent.d.ts.map +0 -1
  220. package/lib/db/repositories/depositEvent.js +0 -27
  221. package/lib/db/repositories/depositEvent.js.map +0 -1
  222. package/lib/db/repositories/eth1Data.d.ts +0 -13
  223. package/lib/db/repositories/eth1Data.d.ts.map +0 -1
  224. package/lib/db/repositories/eth1Data.js +0 -26
  225. package/lib/db/repositories/eth1Data.js.map +0 -1
  226. package/lib/db/single/index.d.ts +0 -3
  227. package/lib/db/single/index.d.ts.map +0 -1
  228. package/lib/db/single/index.js +0 -3
  229. package/lib/db/single/index.js.map +0 -1
  230. package/lib/db/single/preGenesisState.d.ts +0 -16
  231. package/lib/db/single/preGenesisState.d.ts.map +0 -1
  232. package/lib/db/single/preGenesisState.js +0 -29
  233. package/lib/db/single/preGenesisState.js.map +0 -1
  234. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts +0 -14
  235. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts.map +0 -1
  236. package/lib/db/single/preGenesisStateLastProcessedBlock.js +0 -27
  237. package/lib/db/single/preGenesisStateLastProcessedBlock.js.map +0 -1
  238. package/lib/eth1/errors.d.ts +0 -66
  239. package/lib/eth1/errors.d.ts.map +0 -1
  240. package/lib/eth1/errors.js +0 -27
  241. package/lib/eth1/errors.js.map +0 -1
  242. package/lib/eth1/eth1DataCache.d.ts +0 -19
  243. package/lib/eth1/eth1DataCache.d.ts.map +0 -1
  244. package/lib/eth1/eth1DataCache.js +0 -19
  245. package/lib/eth1/eth1DataCache.js.map +0 -1
  246. package/lib/eth1/eth1DepositDataTracker.d.ts +0 -80
  247. package/lib/eth1/eth1DepositDataTracker.d.ts.map +0 -1
  248. package/lib/eth1/eth1DepositDataTracker.js +0 -317
  249. package/lib/eth1/eth1DepositDataTracker.js.map +0 -1
  250. package/lib/eth1/eth1DepositsCache.d.ts +0 -42
  251. package/lib/eth1/eth1DepositsCache.d.ts.map +0 -1
  252. package/lib/eth1/eth1DepositsCache.js +0 -119
  253. package/lib/eth1/eth1DepositsCache.js.map +0 -1
  254. package/lib/eth1/index.d.ts +0 -31
  255. package/lib/eth1/index.d.ts.map +0 -1
  256. package/lib/eth1/index.js +0 -71
  257. package/lib/eth1/index.js.map +0 -1
  258. package/lib/eth1/interface.d.ts +0 -74
  259. package/lib/eth1/interface.d.ts.map +0 -1
  260. package/lib/eth1/interface.js +0 -8
  261. package/lib/eth1/interface.js.map +0 -1
  262. package/lib/eth1/options.d.ts +0 -22
  263. package/lib/eth1/options.d.ts.map +0 -1
  264. package/lib/eth1/options.js +0 -8
  265. package/lib/eth1/options.js.map +0 -1
  266. package/lib/eth1/provider/eth1Provider.d.ts +0 -39
  267. package/lib/eth1/provider/eth1Provider.d.ts.map +0 -1
  268. package/lib/eth1/provider/eth1Provider.js +0 -147
  269. package/lib/eth1/provider/eth1Provider.js.map +0 -1
  270. package/lib/eth1/provider/jsonRpcHttpClient.d.ts.map +0 -1
  271. package/lib/eth1/provider/jsonRpcHttpClient.js.map +0 -1
  272. package/lib/eth1/provider/jwt.d.ts.map +0 -1
  273. package/lib/eth1/provider/jwt.js.map +0 -1
  274. package/lib/eth1/provider/utils.d.ts +0 -65
  275. package/lib/eth1/provider/utils.d.ts.map +0 -1
  276. package/lib/eth1/provider/utils.js +0 -120
  277. package/lib/eth1/provider/utils.js.map +0 -1
  278. package/lib/eth1/stream.d.ts +0 -15
  279. package/lib/eth1/stream.d.ts.map +0 -1
  280. package/lib/eth1/stream.js +0 -54
  281. package/lib/eth1/stream.js.map +0 -1
  282. package/lib/eth1/utils/depositContract.d.ts +0 -14
  283. package/lib/eth1/utils/depositContract.d.ts.map +0 -1
  284. package/lib/eth1/utils/depositContract.js +0 -33
  285. package/lib/eth1/utils/depositContract.js.map +0 -1
  286. package/lib/eth1/utils/deposits.d.ts +0 -8
  287. package/lib/eth1/utils/deposits.d.ts.map +0 -1
  288. package/lib/eth1/utils/deposits.js +0 -47
  289. package/lib/eth1/utils/deposits.js.map +0 -1
  290. package/lib/eth1/utils/eth1Data.d.ts +0 -22
  291. package/lib/eth1/utils/eth1Data.d.ts.map +0 -1
  292. package/lib/eth1/utils/eth1Data.js +0 -77
  293. package/lib/eth1/utils/eth1Data.js.map +0 -1
  294. package/lib/eth1/utils/eth1DepositEvent.d.ts +0 -7
  295. package/lib/eth1/utils/eth1DepositEvent.d.ts.map +0 -1
  296. package/lib/eth1/utils/eth1DepositEvent.js +0 -13
  297. package/lib/eth1/utils/eth1DepositEvent.js.map +0 -1
  298. package/lib/eth1/utils/eth1Vote.d.ts +0 -17
  299. package/lib/eth1/utils/eth1Vote.d.ts.map +0 -1
  300. package/lib/eth1/utils/eth1Vote.js +0 -111
  301. package/lib/eth1/utils/eth1Vote.js.map +0 -1
  302. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts +0 -9
  303. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts.map +0 -1
  304. package/lib/eth1/utils/groupDepositEventsByBlock.js +0 -17
  305. package/lib/eth1/utils/groupDepositEventsByBlock.js.map +0 -1
  306. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts +0 -10
  307. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts.map +0 -1
  308. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js +0 -14
  309. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js.map +0 -1
  310. package/src/chain/genesis/genesis.ts +0 -190
  311. package/src/chain/genesis/interface.ts +0 -14
  312. package/src/db/repositories/depositDataRoot.ts +0 -80
  313. package/src/db/repositories/depositEvent.ts +0 -32
  314. package/src/db/repositories/eth1Data.ts +0 -33
  315. package/src/db/single/index.ts +0 -2
  316. package/src/db/single/preGenesisState.ts +0 -37
  317. package/src/db/single/preGenesisStateLastProcessedBlock.ts +0 -34
  318. package/src/eth1/errors.ts +0 -40
  319. package/src/eth1/eth1DataCache.ts +0 -26
  320. package/src/eth1/eth1DepositDataTracker.ts +0 -410
  321. package/src/eth1/eth1DepositsCache.ts +0 -141
  322. package/src/eth1/index.ts +0 -94
  323. package/src/eth1/interface.ts +0 -87
  324. package/src/eth1/options.ts +0 -28
  325. package/src/eth1/provider/eth1Provider.ts +0 -229
  326. package/src/eth1/provider/utils.ts +0 -136
  327. package/src/eth1/stream.ts +0 -75
  328. package/src/eth1/utils/depositContract.ts +0 -37
  329. package/src/eth1/utils/deposits.ts +0 -70
  330. package/src/eth1/utils/eth1Data.ts +0 -100
  331. package/src/eth1/utils/eth1DepositEvent.ts +0 -12
  332. package/src/eth1/utils/eth1Vote.ts +0 -142
  333. package/src/eth1/utils/groupDepositEventsByBlock.ts +0 -19
  334. package/src/eth1/utils/optimizeNextBlockDiffForGenesis.ts +0 -18
  335. /package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.js +0 -0
  336. /package/lib/{eth1/provider → execution/engine}/jwt.d.ts +0 -0
  337. /package/lib/{eth1/provider → execution/engine}/jwt.js +0 -0
  338. /package/src/{eth1/provider → execution/engine}/jwt.ts +0 -0
@@ -1,87 +0,0 @@
1
- import {BeaconConfig} from "@lodestar/config";
2
- import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
3
- import {phase0} from "@lodestar/types";
4
-
5
- export type EthJsonRpcBlockRaw = {
6
- /** the block number. null when its pending block. `"0x1b4"` */
7
- number: string;
8
- /** 32 Bytes - hash of the block. null when its pending block. `"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae"` */
9
- hash: string;
10
- /** 32 Bytes - hash of the parent block. `"0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54"` */
11
- parentHash: string;
12
- /**
13
- * integer of the total difficulty of the chain until this block. `"0x78ed983323d"`.
14
- * Current mainnet value is 0x684de10dc5c03f006b6, 75 bits so requires a bigint.
15
- */
16
- totalDifficulty: string;
17
- /** the unix timestamp for when the block was collated. `"0x55ba467c"` */
18
- timestamp: string;
19
- };
20
-
21
- export interface IEth1Provider {
22
- deployBlock: number;
23
- getBlockNumber(): Promise<number>;
24
- /** Returns HTTP code 200 + value=null if block is not found */
25
- getBlockByNumber(blockNumber: number | "latest"): Promise<EthJsonRpcBlockRaw | null>;
26
- /** Returns HTTP code 200 + value=null if block is not found */
27
- getBlockByHash(blockHashHex: string): Promise<EthJsonRpcBlockRaw | null>;
28
- /** null returns are ignored, may return a different number of blocks than expected */
29
- getBlocksByNumber(fromBlock: number, toBlock: number): Promise<EthJsonRpcBlockRaw[]>;
30
- getDepositEvents(fromBlock: number, toBlock: number): Promise<phase0.DepositEvent[]>;
31
- validateContract(): Promise<void>;
32
- getState(): Eth1ProviderState;
33
- }
34
-
35
- export enum Eth1ProviderState {
36
- ONLINE = "ONLINE",
37
- OFFLINE = "OFFLINE",
38
- ERROR = "ERROR",
39
- AUTH_FAILED = "AUTH_FAILED",
40
- }
41
-
42
- export type Eth1DataAndDeposits = {
43
- eth1Data: phase0.Eth1Data;
44
- deposits: phase0.Deposit[];
45
- };
46
-
47
- export interface IEth1ForBlockProduction {
48
- getEth1DataAndDeposits(state: CachedBeaconStateAllForks): Promise<Eth1DataAndDeposits>;
49
-
50
- isPollingEth1Data(): boolean;
51
-
52
- /**
53
- * Should stop polling eth1Data after a Electra block is finalized AND deposit_requests_start_index is reached
54
- */
55
- stopPollingEth1Data(): void;
56
- }
57
-
58
- /** Different Eth1Block from phase0.Eth1Block with blockHash */
59
- export type Eth1Block = {
60
- blockHash: Uint8Array;
61
- blockNumber: number;
62
- timestamp: number;
63
- };
64
-
65
- export type BatchDepositEvents = {
66
- depositEvents: phase0.DepositEvent[];
67
- blockNumber: number;
68
- };
69
-
70
- export type Eth1Streamer = {
71
- getDepositsStream(fromBlock: number): AsyncGenerator<BatchDepositEvents>;
72
- getDepositsAndBlockStreamForGenesis(fromBlock: number): AsyncGenerator<[phase0.DepositEvent[], phase0.Eth1Block]>;
73
- };
74
-
75
- export type IEth1StreamParams = Pick<
76
- BeaconConfig,
77
- "ETH1_FOLLOW_DISTANCE" | "MIN_GENESIS_TIME" | "GENESIS_DELAY" | "SECONDS_PER_ETH1_BLOCK"
78
- > & {
79
- maxBlocksPerPoll: number;
80
- };
81
-
82
- export type IJson = string | number | boolean | undefined | IJson[] | {[key: string]: IJson};
83
-
84
- export interface RpcPayload<P = IJson[]> {
85
- method: string;
86
- params: P;
87
- }
@@ -1,28 +0,0 @@
1
- export type Eth1Options = {
2
- enabled?: boolean;
3
- disableEth1DepositDataTracker?: boolean;
4
- providerUrls?: string[];
5
- /**
6
- * jwtSecretHex is the jwt secret if the eth1 modules should ping the jwt auth
7
- * protected engine endpoints.
8
- */
9
- jwtSecretHex?: string;
10
- jwtId?: string;
11
- jwtVersion?: string;
12
- depositContractDeployBlock?: number;
13
- unsafeAllowDepositDataOverwrite?: boolean;
14
- /**
15
- * Vote for a specific eth1_data regardless of validity and existing votes.
16
- * hex encoded ssz serialized Eth1Data type.
17
- */
18
- forcedEth1DataVote?: string;
19
- };
20
-
21
- export const DEFAULT_PROVIDER_URLS = ["http://localhost:8545"];
22
-
23
- export const defaultEth1Options: Eth1Options = {
24
- enabled: true,
25
- providerUrls: DEFAULT_PROVIDER_URLS,
26
- depositContractDeployBlock: 0,
27
- unsafeAllowDepositDataOverwrite: false,
28
- };
@@ -1,229 +0,0 @@
1
- import {ChainConfig} from "@lodestar/config";
2
- import {Logger} from "@lodestar/logger";
3
- import {phase0} from "@lodestar/types";
4
- import {
5
- FetchError,
6
- createElapsedTimeTracker,
7
- fromHex,
8
- isErrorAborted,
9
- isFetchError,
10
- toHex,
11
- toPrintableUrl,
12
- } from "@lodestar/utils";
13
- import {HTTP_CONNECTION_ERROR_CODES, HTTP_FATAL_ERROR_CODES} from "../../execution/engine/utils.js";
14
- import {isValidAddress} from "../../util/address.js";
15
- import {linspace} from "../../util/numpy.js";
16
- import {Eth1Block, Eth1ProviderState, EthJsonRpcBlockRaw, IEth1Provider} from "../interface.js";
17
- import {DEFAULT_PROVIDER_URLS, Eth1Options} from "../options.js";
18
- import {depositEventTopics, parseDepositLog} from "../utils/depositContract.js";
19
- import {
20
- ErrorJsonRpcResponse,
21
- HttpRpcError,
22
- JsonRpcHttpClient,
23
- JsonRpcHttpClientEvent,
24
- JsonRpcHttpClientMetrics,
25
- ReqOpts,
26
- } from "./jsonRpcHttpClient.js";
27
- import {dataToBytes, isJsonRpcTruncatedError, numToQuantity, quantityToNum} from "./utils.js";
28
-
29
- /**
30
- * Binds return types to Ethereum JSON RPC methods
31
- */
32
- type EthJsonRpcReturnTypes = {
33
- eth_getBlockByNumber: EthJsonRpcBlockRaw | null;
34
- eth_getBlockByHash: EthJsonRpcBlockRaw | null;
35
- eth_blockNumber: string;
36
- eth_getCode: string;
37
- eth_getLogs: {
38
- removed: boolean;
39
- logIndex: string;
40
- transactionIndex: string;
41
- transactionHash: string;
42
- blockHash: string;
43
- blockNumber: string;
44
- address: string;
45
- data: string;
46
- topics: string[];
47
- }[];
48
- };
49
-
50
- // Define static options once to prevent extra allocations
51
- const getBlocksByNumberOpts: ReqOpts = {routeId: "getBlockByNumber_batched"};
52
- const getBlockByNumberOpts: ReqOpts = {routeId: "getBlockByNumber"};
53
- const getBlockByHashOpts: ReqOpts = {routeId: "getBlockByHash"};
54
- const getBlockNumberOpts: ReqOpts = {routeId: "getBlockNumber"};
55
- const getLogsOpts: ReqOpts = {routeId: "getLogs"};
56
-
57
- const isOneMinutePassed = createElapsedTimeTracker({minElapsedTime: 60_000});
58
-
59
- export class Eth1Provider implements IEth1Provider {
60
- readonly deployBlock: number;
61
- private readonly depositContractAddress: string;
62
- private readonly rpc: JsonRpcHttpClient;
63
- // The default state is ONLINE, it will be updated to offline if we receive a http error
64
- private state: Eth1ProviderState = Eth1ProviderState.ONLINE;
65
- private logger?: Logger;
66
-
67
- constructor(
68
- config: Pick<ChainConfig, "DEPOSIT_CONTRACT_ADDRESS">,
69
- opts: Pick<Eth1Options, "depositContractDeployBlock" | "providerUrls" | "jwtSecretHex" | "jwtId" | "jwtVersion"> & {
70
- logger?: Logger;
71
- },
72
- signal?: AbortSignal,
73
- metrics?: JsonRpcHttpClientMetrics | null
74
- ) {
75
- this.logger = opts.logger;
76
- this.deployBlock = opts.depositContractDeployBlock ?? 0;
77
- this.depositContractAddress = toHex(config.DEPOSIT_CONTRACT_ADDRESS);
78
-
79
- const providerUrls = opts.providerUrls ?? DEFAULT_PROVIDER_URLS;
80
- this.rpc = new JsonRpcHttpClient(providerUrls, {
81
- signal,
82
- // Don't fallback with is truncated error. Throw early and let the retry on this class handle it
83
- shouldNotFallback: isJsonRpcTruncatedError,
84
- jwtSecret: opts.jwtSecretHex ? fromHex(opts.jwtSecretHex) : undefined,
85
- jwtId: opts.jwtId,
86
- jwtVersion: opts.jwtVersion,
87
- metrics: metrics,
88
- });
89
- this.logger?.info("Eth1 provider", {urls: providerUrls.map(toPrintableUrl).toString()});
90
-
91
- this.rpc.emitter.on(JsonRpcHttpClientEvent.RESPONSE, () => {
92
- const oldState = this.state;
93
- this.state = Eth1ProviderState.ONLINE;
94
-
95
- if (oldState !== Eth1ProviderState.ONLINE) {
96
- this.logger?.info("Eth1 provider is back online", {oldState, newState: this.state});
97
- }
98
- });
99
-
100
- this.rpc.emitter.on(JsonRpcHttpClientEvent.ERROR, ({error}) => {
101
- if (isErrorAborted(error)) {
102
- this.state = Eth1ProviderState.ONLINE;
103
- } else if ((error as unknown) instanceof HttpRpcError || (error as unknown) instanceof ErrorJsonRpcResponse) {
104
- this.state = Eth1ProviderState.ERROR;
105
- } else if (error && isFetchError(error) && HTTP_FATAL_ERROR_CODES.includes((error as FetchError).code)) {
106
- this.state = Eth1ProviderState.OFFLINE;
107
- } else if (error && isFetchError(error) && HTTP_CONNECTION_ERROR_CODES.includes((error as FetchError).code)) {
108
- this.state = Eth1ProviderState.AUTH_FAILED;
109
- }
110
-
111
- if (this.state !== Eth1ProviderState.ONLINE && isOneMinutePassed()) {
112
- this.logger?.error(
113
- "Eth1 provider error",
114
- {
115
- state: this.state,
116
- lastErrorAt: new Date(Date.now() - isOneMinutePassed.msSinceLastCall).toLocaleTimeString(),
117
- },
118
- error
119
- );
120
- }
121
- });
122
- }
123
-
124
- getState(): Eth1ProviderState {
125
- return this.state;
126
- }
127
-
128
- async validateContract(): Promise<void> {
129
- if (!isValidAddress(this.depositContractAddress)) {
130
- throw Error(`Invalid contract address: ${this.depositContractAddress}`);
131
- }
132
-
133
- const code = await this.getCode(this.depositContractAddress);
134
- if (!code || code === "0x") {
135
- throw new Error(`There is no deposit contract at given address: ${this.depositContractAddress}`);
136
- }
137
- }
138
-
139
- async getDepositEvents(fromBlock: number, toBlock: number): Promise<phase0.DepositEvent[]> {
140
- const logsRawArr = await this.getLogs({
141
- fromBlock,
142
- toBlock,
143
- address: this.depositContractAddress,
144
- topics: depositEventTopics,
145
- });
146
- return logsRawArr.flat(1).map((log) => parseDepositLog(log));
147
- }
148
-
149
- /**
150
- * Fetches an arbitrary array of block numbers in batch
151
- */
152
- async getBlocksByNumber(fromBlock: number, toBlock: number): Promise<EthJsonRpcBlockRaw[]> {
153
- const method = "eth_getBlockByNumber";
154
- const blocksArr = await this.rpc.fetchBatch<EthJsonRpcReturnTypes[typeof method]>(
155
- linspace(fromBlock, toBlock).map((blockNumber) => ({method, params: [numToQuantity(blockNumber), false]})),
156
- getBlocksByNumberOpts
157
- );
158
- const blocks: EthJsonRpcBlockRaw[] = [];
159
- for (const block of blocksArr.flat(1)) {
160
- if (block) blocks.push(block);
161
- }
162
- return blocks;
163
- }
164
-
165
- async getBlockByNumber(blockNumber: number | "latest"): Promise<EthJsonRpcBlockRaw | null> {
166
- const method = "eth_getBlockByNumber";
167
- const blockNumberHex = typeof blockNumber === "string" ? blockNumber : numToQuantity(blockNumber);
168
- return this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
169
- // false = include only transaction roots, not full objects
170
- {method, params: [blockNumberHex, false]},
171
- getBlockByNumberOpts
172
- );
173
- }
174
-
175
- async getBlockByHash(blockHashHex: string): Promise<EthJsonRpcBlockRaw | null> {
176
- const method = "eth_getBlockByHash";
177
- return this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
178
- // false = include only transaction roots, not full objects
179
- {method, params: [blockHashHex, false]},
180
- getBlockByHashOpts
181
- );
182
- }
183
-
184
- async getBlockNumber(): Promise<number> {
185
- const method = "eth_blockNumber";
186
- const blockNumberRaw = await this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
187
- {method, params: []},
188
- getBlockNumberOpts
189
- );
190
- return parseInt(blockNumberRaw, 16);
191
- }
192
-
193
- async getCode(address: string): Promise<string> {
194
- const method = "eth_getCode";
195
- return this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>({method, params: [address, "latest"]});
196
- }
197
-
198
- async getLogs(options: {
199
- fromBlock: number;
200
- toBlock: number;
201
- address: string;
202
- topics: string[];
203
- }): Promise<{blockNumber: number; data: string; topics: string[]}[]> {
204
- const method = "eth_getLogs";
205
- const hexOptions = {
206
- ...options,
207
- fromBlock: numToQuantity(options.fromBlock),
208
- toBlock: numToQuantity(options.toBlock),
209
- };
210
- const logsRaw = await this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
211
- {method, params: [hexOptions]},
212
- getLogsOpts
213
- );
214
- return logsRaw.map((logRaw) => ({
215
- blockNumber: parseInt(logRaw.blockNumber, 16),
216
- data: logRaw.data,
217
- topics: logRaw.topics,
218
- }));
219
- }
220
- }
221
-
222
- export function parseEth1Block(blockRaw: EthJsonRpcBlockRaw): Eth1Block {
223
- if (typeof blockRaw !== "object") throw Error("block is not an object");
224
- return {
225
- blockHash: dataToBytes(blockRaw.hash, 32),
226
- blockNumber: quantityToNum(blockRaw.number, "block.number"),
227
- timestamp: quantityToNum(blockRaw.timestamp, "block.timestamp"),
228
- };
229
- }
@@ -1,136 +0,0 @@
1
- import {RootHex} from "@lodestar/types";
2
- import {bigIntToBytes, bytesToBigInt, fromHex, fromHexInto, toHex} from "@lodestar/utils";
3
- import {ErrorParseJson} from "./jsonRpcHttpClient.js";
4
-
5
- /** QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API */
6
- export type QUANTITY = string;
7
- /** DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API */
8
- export type DATA = string;
9
-
10
- export const rootHexRegex = /^0x[a-fA-F0-9]{64}$/;
11
-
12
- export function numberToHex(n: number | bigint): string {
13
- return "0x" + n.toString(16);
14
- }
15
-
16
- export function isJsonRpcTruncatedError(error: Error): boolean {
17
- return (
18
- // Truncated responses usually get as 200 but since it's truncated the JSON will be invalid
19
- error instanceof ErrorParseJson ||
20
- // Otherwise guess Infura error message of too many events
21
- (error instanceof Error && error.message.includes("query returned more than 10000 results")) ||
22
- // Nethermind enforces limits on JSON RPC batch calls
23
- (error instanceof Error && error.message.toLowerCase().includes("batch size limit exceeded"))
24
- );
25
- }
26
-
27
- export function bytesToHex(bytes: Uint8Array): string {
28
- // Handle special case in Ethereum hex formating where hex values may include a single letter
29
- // 0x0, 0x1 are valid values
30
- if (bytes.length === 1 && bytes[0] <= 0xf) {
31
- return "0x" + bytes[0].toString(16);
32
- }
33
-
34
- return toHex(bytes);
35
- }
36
-
37
- /**
38
- * QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
39
- *
40
- * When encoding QUANTITIES (integers, numbers): encode as hex, prefix with “0x”, the most compact representation (slight exception: zero should be represented as “0x0”). Examples:
41
- * - 0x41 (65 in decimal)
42
- * - 0x400 (1024 in decimal)
43
- * - WRONG: 0x (should always have at least one digit - zero is “0x0”)
44
- * - WRONG: 0x0400 (no leading zeroes allowed)
45
- * - WRONG: ff (must be prefixed 0x)
46
- */
47
- export function numToQuantity(num: number | bigint): QUANTITY {
48
- return "0x" + num.toString(16);
49
- }
50
-
51
- /**
52
- * QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
53
- */
54
- export function quantityToNum(hex: QUANTITY, id = ""): number {
55
- const num = parseInt(hex, 16);
56
- if (Number.isNaN(num) || num < 0) throw Error(`Invalid hex decimal ${id} '${hex}'`);
57
- return num;
58
- }
59
-
60
- /**
61
- * QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API.
62
- * Typesafe fn to convert hex string to bigint. The BigInt constructor param is any
63
- */
64
- export function quantityToBigint(hex: QUANTITY, id = ""): bigint {
65
- try {
66
- return BigInt(hex);
67
- } catch (e) {
68
- throw Error(`Invalid hex bigint ${id} '${hex}': ${(e as Error).message}`);
69
- }
70
- }
71
-
72
- /**
73
- * QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API.
74
- */
75
- export function quantityToBytes(hex: QUANTITY): Uint8Array {
76
- const bn = quantityToBigint(hex);
77
- return bigIntToBytes(bn, 32, "le");
78
- }
79
-
80
- /**
81
- * QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API.
82
- * Compress a 32 ByteVector into a QUANTITY
83
- */
84
- export function bytesToQuantity(bytes: Uint8Array): QUANTITY {
85
- const bn = bytesToBigInt(bytes, "le");
86
- return numToQuantity(bn);
87
- }
88
-
89
- /**
90
- * DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
91
- *
92
- * When encoding UNFORMATTED DATA (byte arrays, account addresses, hashes, bytecode arrays): encode as hex, prefix with
93
- * “0x”, two hex digits per byte. Examples:
94
- *
95
- * - 0x41 (size 1, “A”)
96
- * - 0x004200 (size 3, “\0B\0”)
97
- * - 0x (size 0, “”)
98
- * - WRONG: 0xf0f0f (must be even number of digits)
99
- * - WRONG: 004200 (must be prefixed 0x)
100
- */
101
- export function bytesToData(bytes: Uint8Array): DATA {
102
- return toHex(bytes);
103
- }
104
-
105
- /**
106
- * DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
107
- */
108
- export function dataToBytes(hex: DATA, fixedLength: number | null): Uint8Array {
109
- try {
110
- const bytes = fromHex(hex);
111
- if (fixedLength != null && bytes.length !== fixedLength) {
112
- throw Error(`Wrong data length ${bytes.length} expected ${fixedLength}`);
113
- }
114
- return bytes;
115
- } catch (e) {
116
- (e as Error).message = `Invalid hex string: ${(e as Error).message}`;
117
- throw e;
118
- }
119
- }
120
-
121
- /**
122
- * Convert DATA into a preallocated buffer
123
- * fromHexInto will throw if buffer's length is not the same as the decoded hex length
124
- */
125
- export function dataIntoBytes(hex: DATA, buffer: Uint8Array): Uint8Array {
126
- fromHexInto(hex, buffer);
127
- return buffer;
128
- }
129
-
130
- /**
131
- * DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
132
- */
133
- export function dataToRootHex(hex: DATA, id = ""): RootHex {
134
- if (!rootHexRegex.test(hex)) throw Error(`Invalid hex root ${id} '${hex}'`);
135
- return hex;
136
- }
@@ -1,75 +0,0 @@
1
- import {phase0} from "@lodestar/types";
2
- import {sleep} from "@lodestar/utils";
3
- import {BatchDepositEvents, Eth1Block, IEth1Provider, IEth1StreamParams} from "./interface.js";
4
- import {parseEth1Block} from "./provider/eth1Provider.js";
5
- import {groupDepositEventsByBlock} from "./utils/groupDepositEventsByBlock.js";
6
- import {optimizeNextBlockDiffForGenesis} from "./utils/optimizeNextBlockDiffForGenesis.js";
7
-
8
- /**
9
- * Phase 1 of genesis building.
10
- * Not enough validators, only stream deposits
11
- * @param signal Abort stream returning after a while loop cycle. Aborts internal sleep
12
- */
13
- export async function* getDepositsStream(
14
- fromBlock: number,
15
- provider: IEth1Provider,
16
- params: IEth1StreamParams,
17
- signal?: AbortSignal
18
- ): AsyncGenerator<BatchDepositEvents> {
19
- fromBlock = Math.max(fromBlock, provider.deployBlock);
20
-
21
- while (true) {
22
- const remoteFollowBlock = await getRemoteFollowBlock(provider, params);
23
- const toBlock = Math.min(remoteFollowBlock, fromBlock + params.maxBlocksPerPoll);
24
- const logs = await provider.getDepositEvents(fromBlock, toBlock);
25
- for (const batchedDeposits of groupDepositEventsByBlock(logs)) {
26
- yield batchedDeposits;
27
- }
28
-
29
- fromBlock = toBlock;
30
-
31
- // If reached head, sleep for an eth1 block. Throws if signal is aborted
32
- await sleep(toBlock >= remoteFollowBlock ? params.SECONDS_PER_ETH1_BLOCK * 1000 : 10, signal);
33
- }
34
- }
35
-
36
- /**
37
- * Phase 2 of genesis building.
38
- * There are enough validators, stream deposits and blocks
39
- * @param signal Abort stream returning after a while loop cycle. Aborts internal sleep
40
- */
41
- export async function* getDepositsAndBlockStreamForGenesis(
42
- fromBlock: number,
43
- provider: IEth1Provider,
44
- params: IEth1StreamParams,
45
- signal?: AbortSignal
46
- ): AsyncGenerator<[phase0.DepositEvent[], Eth1Block]> {
47
- fromBlock = Math.max(fromBlock, provider.deployBlock);
48
- fromBlock = Math.min(fromBlock, await getRemoteFollowBlock(provider, params));
49
- let toBlock = fromBlock; // First, fetch only the first block
50
-
51
- while (true) {
52
- const [logs, blockRaw] = await Promise.all([
53
- provider.getDepositEvents(fromBlock, toBlock),
54
- provider.getBlockByNumber(toBlock),
55
- ]);
56
-
57
- if (!blockRaw) throw Error(`No block found for number ${toBlock}`);
58
- const block = parseEth1Block(blockRaw);
59
-
60
- yield [logs, block];
61
-
62
- const remoteFollowBlock = await getRemoteFollowBlock(provider, params);
63
- const nextBlockDiff = optimizeNextBlockDiffForGenesis(block, params);
64
- fromBlock = toBlock;
65
- toBlock = Math.min(remoteFollowBlock, fromBlock + Math.min(nextBlockDiff, params.maxBlocksPerPoll));
66
-
67
- // If reached head, sleep for an eth1 block. Throws if signal is aborted
68
- await sleep(toBlock >= remoteFollowBlock ? params.SECONDS_PER_ETH1_BLOCK * 1000 : 10, signal);
69
- }
70
- }
71
-
72
- async function getRemoteFollowBlock(provider: IEth1Provider, params: IEth1StreamParams): Promise<number> {
73
- const remoteHighestBlock = await provider.getBlockNumber();
74
- return Math.max(remoteHighestBlock - params.ETH1_FOLLOW_DISTANCE, 0);
75
- }
@@ -1,37 +0,0 @@
1
- import {Interface} from "@ethersproject/abi";
2
- import {phase0, ssz} from "@lodestar/types";
3
- import {fromHex} from "@lodestar/utils";
4
-
5
- const depositEventFragment =
6
- "event DepositEvent(bytes pubkey, bytes withdrawal_credentials, bytes amount, bytes signature, bytes index)";
7
-
8
- const depositContractInterface = new Interface([depositEventFragment]);
9
-
10
- /**
11
- * Precomputed topics of DepositEvent logs
12
- */
13
- export const depositEventTopics = [depositContractInterface.getEventTopic("DepositEvent")];
14
-
15
- /**
16
- * Parse DepositEvent log
17
- */
18
- export function parseDepositLog(log: {blockNumber: number; data: string; topics: string[]}): phase0.DepositEvent {
19
- const event = depositContractInterface.parseLog(log);
20
- const values = event.args;
21
- if (values === undefined) throw Error(`DepositEvent at ${log.blockNumber} has no values`);
22
- return {
23
- blockNumber: log.blockNumber,
24
- index: parseHexNumLittleEndian(values.index),
25
- depositData: {
26
- pubkey: fromHex(values.pubkey),
27
- withdrawalCredentials: fromHex(values.withdrawal_credentials),
28
- amount: parseHexNumLittleEndian(values.amount),
29
- signature: fromHex(values.signature),
30
- },
31
- };
32
- }
33
-
34
- function parseHexNumLittleEndian(hex: string): number {
35
- // Can't use parseInt() because amount is a hex string in little endian
36
- return ssz.UintNum64.deserialize(fromHex(hex));
37
- }
@@ -1,70 +0,0 @@
1
- import {Tree, toGindex} from "@chainsafe/persistent-merkle-tree";
2
- import {FilterOptions} from "@lodestar/db";
3
- import {CachedBeaconStateAllForks, getEth1DepositCount} from "@lodestar/state-transition";
4
- import {phase0, ssz} from "@lodestar/types";
5
- import {toRootHex} from "@lodestar/utils";
6
- import {DepositTree} from "../../db/repositories/depositDataRoot.js";
7
- import {Eth1Error, Eth1ErrorCode} from "../errors.js";
8
-
9
- export type DepositGetter<T> = (indexRange: FilterOptions<number>, eth1Data: phase0.Eth1Data) => Promise<T[]>;
10
-
11
- export async function getDeposits<T>(
12
- // eth1_deposit_index represents the next deposit index to be added
13
- state: CachedBeaconStateAllForks,
14
- eth1Data: phase0.Eth1Data,
15
- depositsGetter: DepositGetter<T>
16
- ): Promise<T[]> {
17
- const depositIndex = state.eth1DepositIndex;
18
- const depositCount = eth1Data.depositCount;
19
-
20
- if (depositIndex > depositCount) {
21
- throw new Eth1Error({code: Eth1ErrorCode.DEPOSIT_INDEX_TOO_HIGH, depositIndex, depositCount});
22
- }
23
-
24
- const depositsLen = getEth1DepositCount(state, eth1Data);
25
-
26
- if (depositsLen === 0) {
27
- return []; // If depositsLen === 0, we can return early since no deposit with be returned from depositsGetter
28
- }
29
-
30
- const indexRange = {gte: depositIndex, lt: depositIndex + depositsLen};
31
- const deposits = await depositsGetter(indexRange, eth1Data);
32
-
33
- if (deposits.length < depositsLen) {
34
- throw new Eth1Error({code: Eth1ErrorCode.NOT_ENOUGH_DEPOSITS, len: deposits.length, expectedLen: depositsLen});
35
- }
36
-
37
- if (deposits.length > depositsLen) {
38
- throw new Eth1Error({code: Eth1ErrorCode.TOO_MANY_DEPOSITS, len: deposits.length, expectedLen: depositsLen});
39
- }
40
-
41
- return deposits;
42
- }
43
-
44
- export function getDepositsWithProofs(
45
- depositEvents: phase0.DepositEvent[],
46
- depositRootTree: DepositTree,
47
- eth1Data: phase0.Eth1Data
48
- ): phase0.Deposit[] {
49
- // Get tree at this particular depositCount to compute correct proofs
50
- const viewAtDepositCount = depositRootTree.sliceTo(eth1Data.depositCount - 1);
51
-
52
- const depositRoot = viewAtDepositCount.hashTreeRoot();
53
-
54
- if (!ssz.Root.equals(depositRoot, eth1Data.depositRoot)) {
55
- throw new Eth1Error({
56
- code: Eth1ErrorCode.WRONG_DEPOSIT_ROOT,
57
- root: toRootHex(depositRoot),
58
- expectedRoot: toRootHex(eth1Data.depositRoot),
59
- });
60
- }
61
-
62
- // Already commited for .hashTreeRoot()
63
- const treeAtDepositCount = new Tree(viewAtDepositCount.node);
64
- const depositTreeDepth = viewAtDepositCount.type.depth;
65
-
66
- return depositEvents.map((log) => ({
67
- proof: treeAtDepositCount.getSingleProof(toGindex(depositTreeDepth, BigInt(log.index))),
68
- data: log.depositData,
69
- }));
70
- }