@lodestar/beacon-node 1.38.0 → 1.39.0-dev.2fe8de2346

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 (365) 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/api/impl/beacon/state/index.d.ts.map +1 -1
  4. package/lib/api/impl/beacon/state/index.js +4 -5
  5. package/lib/api/impl/beacon/state/index.js.map +1 -1
  6. package/lib/api/impl/validator/index.js +1 -1
  7. package/lib/api/impl/validator/index.js.map +1 -1
  8. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  9. package/lib/chain/blocks/verifyBlock.js +1 -21
  10. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  11. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +1 -6
  12. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  13. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +10 -131
  14. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  15. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  16. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  17. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
  18. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  19. package/lib/chain/chain.d.ts +1 -4
  20. package/lib/chain/chain.d.ts.map +1 -1
  21. package/lib/chain/chain.js +6 -26
  22. package/lib/chain/chain.js.map +1 -1
  23. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  24. package/lib/chain/forkChoice/index.js +3 -3
  25. package/lib/chain/forkChoice/index.js.map +1 -1
  26. package/lib/chain/initState.d.ts +1 -14
  27. package/lib/chain/initState.d.ts.map +1 -1
  28. package/lib/chain/initState.js +1 -62
  29. package/lib/chain/initState.js.map +1 -1
  30. package/lib/chain/interface.d.ts +0 -2
  31. package/lib/chain/interface.d.ts.map +1 -1
  32. package/lib/chain/interface.js.map +1 -1
  33. package/lib/chain/options.d.ts +0 -4
  34. package/lib/chain/options.d.ts.map +1 -1
  35. package/lib/chain/options.js +0 -2
  36. package/lib/chain/options.js.map +1 -1
  37. package/lib/chain/prepareNextSlot.d.ts +0 -4
  38. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  39. package/lib/chain/prepareNextSlot.js +2 -22
  40. package/lib/chain/prepareNextSlot.js.map +1 -1
  41. package/lib/chain/produceBlock/produceBlockBody.d.ts +2 -22
  42. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  43. package/lib/chain/produceBlock/produceBlockBody.js +30 -96
  44. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  45. package/lib/chain/rewards/attestationsRewards.d.ts +3 -3
  46. package/lib/chain/rewards/attestationsRewards.d.ts.map +1 -1
  47. package/lib/chain/rewards/attestationsRewards.js +4 -4
  48. package/lib/chain/rewards/attestationsRewards.js.map +1 -1
  49. package/lib/chain/rewards/syncCommitteeRewards.d.ts +2 -2
  50. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +1 -1
  51. package/lib/chain/rewards/syncCommitteeRewards.js +1 -2
  52. package/lib/chain/rewards/syncCommitteeRewards.js.map +1 -1
  53. package/lib/chain/validation/attesterSlashing.js +2 -2
  54. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  55. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  56. package/lib/chain/validation/blobSidecar.js +2 -2
  57. package/lib/chain/validation/blobSidecar.js.map +1 -1
  58. package/lib/chain/validation/block.d.ts.map +1 -1
  59. package/lib/chain/validation/block.js +3 -3
  60. package/lib/chain/validation/block.js.map +1 -1
  61. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  62. package/lib/chain/validation/dataColumnSidecar.js +2 -2
  63. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  64. package/lib/chain/validation/proposerSlashing.js +1 -1
  65. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  66. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  67. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  68. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -3
  69. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  70. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  71. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  72. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  73. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  74. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  75. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  76. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +3 -3
  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 +4 -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 +1 -7
  86. package/lib/db/beacon.d.ts.map +1 -1
  87. package/lib/db/beacon.js +1 -12
  88. package/lib/db/beacon.js.map +1 -1
  89. package/lib/db/buckets.d.ts +0 -6
  90. package/lib/db/buckets.d.ts.map +1 -1
  91. package/lib/db/buckets.js +6 -7
  92. package/lib/db/buckets.js.map +1 -1
  93. package/lib/db/interface.d.ts +1 -7
  94. package/lib/db/interface.d.ts.map +1 -1
  95. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  96. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  97. package/lib/db/repositories/index.d.ts +0 -3
  98. package/lib/db/repositories/index.d.ts.map +1 -1
  99. package/lib/db/repositories/index.js +0 -3
  100. package/lib/db/repositories/index.js.map +1 -1
  101. package/lib/execution/engine/http.d.ts +5 -13
  102. package/lib/execution/engine/http.d.ts.map +1 -1
  103. package/lib/execution/engine/http.js +6 -15
  104. package/lib/execution/engine/http.js.map +1 -1
  105. package/lib/execution/engine/index.d.ts.map +1 -1
  106. package/lib/execution/engine/index.js +1 -1
  107. package/lib/execution/engine/index.js.map +1 -1
  108. package/lib/execution/engine/interface.d.ts +1 -1
  109. package/lib/execution/engine/interface.d.ts.map +1 -1
  110. package/lib/execution/engine/interface.js.map +1 -1
  111. package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.d.ts +1 -1
  112. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -0
  113. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -0
  114. package/lib/execution/engine/jwt.d.ts.map +1 -0
  115. package/lib/execution/engine/jwt.js.map +1 -0
  116. package/lib/execution/engine/mock.d.ts +2 -6
  117. package/lib/execution/engine/mock.d.ts.map +1 -1
  118. package/lib/execution/engine/mock.js +4 -15
  119. package/lib/execution/engine/mock.js.map +1 -1
  120. package/lib/execution/engine/payloadIdCache.d.ts +1 -1
  121. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
  122. package/lib/execution/engine/types.d.ts +1 -1
  123. package/lib/execution/engine/types.d.ts.map +1 -1
  124. package/lib/execution/engine/types.js +1 -1
  125. package/lib/execution/engine/types.js.map +1 -1
  126. package/lib/execution/engine/utils.d.ts +64 -2
  127. package/lib/execution/engine/utils.d.ts.map +1 -1
  128. package/lib/execution/engine/utils.js +91 -2
  129. package/lib/execution/engine/utils.js.map +1 -1
  130. package/lib/index.d.ts +1 -2
  131. package/lib/index.d.ts.map +1 -1
  132. package/lib/index.js +1 -2
  133. package/lib/index.js.map +1 -1
  134. package/lib/metrics/metrics/lodestar.d.ts +0 -49
  135. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  136. package/lib/metrics/metrics/lodestar.js +0 -134
  137. package/lib/metrics/metrics/lodestar.js.map +1 -1
  138. package/lib/network/core/events.d.ts +1 -1
  139. package/lib/network/core/events.d.ts.map +1 -1
  140. package/lib/network/core/events.js +1 -1
  141. package/lib/network/core/events.js.map +1 -1
  142. package/lib/network/events.d.ts +6 -1
  143. package/lib/network/events.d.ts.map +1 -1
  144. package/lib/network/events.js +7 -1
  145. package/lib/network/events.js.map +1 -1
  146. package/lib/node/nodejs.d.ts.map +1 -1
  147. package/lib/node/nodejs.js +0 -9
  148. package/lib/node/nodejs.js.map +1 -1
  149. package/lib/node/notifier.d.ts.map +1 -1
  150. package/lib/node/notifier.js +6 -22
  151. package/lib/node/notifier.js.map +1 -1
  152. package/lib/node/options.d.ts +0 -2
  153. package/lib/node/options.d.ts.map +1 -1
  154. package/lib/node/options.js +0 -2
  155. package/lib/node/options.js.map +1 -1
  156. package/lib/node/utils/interop/deposits.d.ts +2 -1
  157. package/lib/node/utils/interop/deposits.d.ts.map +1 -1
  158. package/lib/node/utils/interop/deposits.js.map +1 -1
  159. package/lib/node/utils/interop/state.d.ts +1 -1
  160. package/lib/node/utils/interop/state.d.ts.map +1 -1
  161. package/lib/node/utils/state.d.ts +1 -7
  162. package/lib/node/utils/state.d.ts.map +1 -1
  163. package/lib/node/utils/state.js +1 -14
  164. package/lib/node/utils/state.js.map +1 -1
  165. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  166. package/lib/sync/backfill/backfill.js +4 -2
  167. package/lib/sync/backfill/backfill.js.map +1 -1
  168. package/lib/sync/backfill/verify.d.ts +2 -2
  169. package/lib/sync/backfill/verify.d.ts.map +1 -1
  170. package/lib/sync/backfill/verify.js +3 -3
  171. package/lib/sync/backfill/verify.js.map +1 -1
  172. package/lib/util/workerEvents.d.ts +1 -6
  173. package/lib/util/workerEvents.d.ts.map +1 -1
  174. package/lib/util/workerEvents.js +8 -8
  175. package/lib/util/workerEvents.js.map +1 -1
  176. package/package.json +14 -21
  177. package/src/api/impl/beacon/blocks/utils.ts +1 -1
  178. package/src/api/impl/beacon/state/index.ts +4 -5
  179. package/src/api/impl/validator/index.ts +1 -1
  180. package/src/chain/blocks/verifyBlock.ts +2 -24
  181. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +11 -170
  182. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -2
  183. package/src/chain/chain.ts +5 -30
  184. package/src/chain/forkChoice/index.ts +2 -3
  185. package/src/chain/initState.ts +1 -97
  186. package/src/chain/interface.ts +0 -2
  187. package/src/chain/options.ts +0 -6
  188. package/src/chain/prepareNextSlot.ts +2 -29
  189. package/src/chain/produceBlock/produceBlockBody.ts +31 -130
  190. package/src/chain/rewards/attestationsRewards.ts +6 -5
  191. package/src/chain/rewards/syncCommitteeRewards.ts +2 -2
  192. package/src/chain/validation/attesterSlashing.ts +2 -2
  193. package/src/chain/validation/blobSidecar.ts +10 -2
  194. package/src/chain/validation/block.ts +2 -3
  195. package/src/chain/validation/dataColumnSidecar.ts +6 -1
  196. package/src/chain/validation/proposerSlashing.ts +1 -1
  197. package/src/chain/validation/signatureSets/contributionAndProof.ts +3 -2
  198. package/src/chain/validation/signatureSets/syncCommittee.ts +3 -1
  199. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +4 -2
  200. package/src/chain/validation/syncCommittee.ts +1 -1
  201. package/src/chain/validation/syncCommitteeContributionAndProof.ts +4 -5
  202. package/src/chain/validation/voluntaryExit.ts +1 -1
  203. package/src/db/beacon.ts +0 -15
  204. package/src/db/buckets.ts +6 -7
  205. package/src/db/interface.ts +0 -13
  206. package/src/db/repositories/index.ts +0 -3
  207. package/src/execution/engine/http.ts +12 -21
  208. package/src/execution/engine/index.ts +1 -1
  209. package/src/execution/engine/interface.ts +1 -1
  210. package/src/{eth1/provider → execution/engine}/jsonRpcHttpClient.ts +1 -1
  211. package/src/execution/engine/mock.ts +4 -17
  212. package/src/execution/engine/payloadIdCache.ts +1 -1
  213. package/src/execution/engine/types.ts +9 -9
  214. package/src/execution/engine/utils.ts +111 -5
  215. package/src/index.ts +1 -2
  216. package/src/metrics/metrics/lodestar.ts +0 -144
  217. package/src/network/core/events.ts +1 -1
  218. package/src/network/events.ts +7 -1
  219. package/src/node/nodejs.ts +0 -9
  220. package/src/node/notifier.ts +7 -29
  221. package/src/node/options.ts +0 -3
  222. package/src/node/utils/interop/deposits.ts +3 -1
  223. package/src/node/utils/interop/state.ts +1 -1
  224. package/src/node/utils/state.ts +3 -18
  225. package/src/sync/backfill/backfill.ts +9 -2
  226. package/src/sync/backfill/verify.ts +8 -2
  227. package/src/util/workerEvents.ts +9 -8
  228. package/lib/chain/genesis/genesis.d.ts +0 -51
  229. package/lib/chain/genesis/genesis.d.ts.map +0 -1
  230. package/lib/chain/genesis/genesis.js +0 -123
  231. package/lib/chain/genesis/genesis.js.map +0 -1
  232. package/lib/chain/genesis/interface.d.ts +0 -13
  233. package/lib/chain/genesis/interface.d.ts.map +0 -1
  234. package/lib/chain/genesis/interface.js +0 -2
  235. package/lib/chain/genesis/interface.js.map +0 -1
  236. package/lib/db/repositories/depositDataRoot.d.ts +0 -22
  237. package/lib/db/repositories/depositDataRoot.d.ts.map +0 -1
  238. package/lib/db/repositories/depositDataRoot.js +0 -62
  239. package/lib/db/repositories/depositDataRoot.js.map +0 -1
  240. package/lib/db/repositories/depositEvent.d.ts +0 -13
  241. package/lib/db/repositories/depositEvent.d.ts.map +0 -1
  242. package/lib/db/repositories/depositEvent.js +0 -27
  243. package/lib/db/repositories/depositEvent.js.map +0 -1
  244. package/lib/db/repositories/eth1Data.d.ts +0 -13
  245. package/lib/db/repositories/eth1Data.d.ts.map +0 -1
  246. package/lib/db/repositories/eth1Data.js +0 -26
  247. package/lib/db/repositories/eth1Data.js.map +0 -1
  248. package/lib/db/single/index.d.ts +0 -3
  249. package/lib/db/single/index.d.ts.map +0 -1
  250. package/lib/db/single/index.js +0 -3
  251. package/lib/db/single/index.js.map +0 -1
  252. package/lib/db/single/preGenesisState.d.ts +0 -16
  253. package/lib/db/single/preGenesisState.d.ts.map +0 -1
  254. package/lib/db/single/preGenesisState.js +0 -29
  255. package/lib/db/single/preGenesisState.js.map +0 -1
  256. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts +0 -14
  257. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts.map +0 -1
  258. package/lib/db/single/preGenesisStateLastProcessedBlock.js +0 -27
  259. package/lib/db/single/preGenesisStateLastProcessedBlock.js.map +0 -1
  260. package/lib/eth1/errors.d.ts +0 -66
  261. package/lib/eth1/errors.d.ts.map +0 -1
  262. package/lib/eth1/errors.js +0 -27
  263. package/lib/eth1/errors.js.map +0 -1
  264. package/lib/eth1/eth1DataCache.d.ts +0 -19
  265. package/lib/eth1/eth1DataCache.d.ts.map +0 -1
  266. package/lib/eth1/eth1DataCache.js +0 -19
  267. package/lib/eth1/eth1DataCache.js.map +0 -1
  268. package/lib/eth1/eth1DepositDataTracker.d.ts +0 -80
  269. package/lib/eth1/eth1DepositDataTracker.d.ts.map +0 -1
  270. package/lib/eth1/eth1DepositDataTracker.js +0 -317
  271. package/lib/eth1/eth1DepositDataTracker.js.map +0 -1
  272. package/lib/eth1/eth1DepositsCache.d.ts +0 -42
  273. package/lib/eth1/eth1DepositsCache.d.ts.map +0 -1
  274. package/lib/eth1/eth1DepositsCache.js +0 -119
  275. package/lib/eth1/eth1DepositsCache.js.map +0 -1
  276. package/lib/eth1/eth1MergeBlockTracker.d.ts +0 -65
  277. package/lib/eth1/eth1MergeBlockTracker.d.ts.map +0 -1
  278. package/lib/eth1/eth1MergeBlockTracker.js +0 -262
  279. package/lib/eth1/eth1MergeBlockTracker.js.map +0 -1
  280. package/lib/eth1/index.d.ts +0 -46
  281. package/lib/eth1/index.d.ts.map +0 -1
  282. package/lib/eth1/index.js +0 -121
  283. package/lib/eth1/index.js.map +0 -1
  284. package/lib/eth1/interface.d.ts +0 -112
  285. package/lib/eth1/interface.d.ts.map +0 -1
  286. package/lib/eth1/interface.js +0 -8
  287. package/lib/eth1/interface.js.map +0 -1
  288. package/lib/eth1/options.d.ts +0 -22
  289. package/lib/eth1/options.d.ts.map +0 -1
  290. package/lib/eth1/options.js +0 -8
  291. package/lib/eth1/options.js.map +0 -1
  292. package/lib/eth1/provider/eth1Provider.d.ts +0 -39
  293. package/lib/eth1/provider/eth1Provider.d.ts.map +0 -1
  294. package/lib/eth1/provider/eth1Provider.js +0 -147
  295. package/lib/eth1/provider/eth1Provider.js.map +0 -1
  296. package/lib/eth1/provider/jsonRpcHttpClient.d.ts.map +0 -1
  297. package/lib/eth1/provider/jsonRpcHttpClient.js.map +0 -1
  298. package/lib/eth1/provider/jwt.d.ts.map +0 -1
  299. package/lib/eth1/provider/jwt.js.map +0 -1
  300. package/lib/eth1/provider/utils.d.ts +0 -65
  301. package/lib/eth1/provider/utils.d.ts.map +0 -1
  302. package/lib/eth1/provider/utils.js +0 -120
  303. package/lib/eth1/provider/utils.js.map +0 -1
  304. package/lib/eth1/stream.d.ts +0 -15
  305. package/lib/eth1/stream.d.ts.map +0 -1
  306. package/lib/eth1/stream.js +0 -54
  307. package/lib/eth1/stream.js.map +0 -1
  308. package/lib/eth1/utils/depositContract.d.ts +0 -14
  309. package/lib/eth1/utils/depositContract.d.ts.map +0 -1
  310. package/lib/eth1/utils/depositContract.js +0 -33
  311. package/lib/eth1/utils/depositContract.js.map +0 -1
  312. package/lib/eth1/utils/deposits.d.ts +0 -8
  313. package/lib/eth1/utils/deposits.d.ts.map +0 -1
  314. package/lib/eth1/utils/deposits.js +0 -47
  315. package/lib/eth1/utils/deposits.js.map +0 -1
  316. package/lib/eth1/utils/eth1Data.d.ts +0 -22
  317. package/lib/eth1/utils/eth1Data.d.ts.map +0 -1
  318. package/lib/eth1/utils/eth1Data.js +0 -77
  319. package/lib/eth1/utils/eth1Data.js.map +0 -1
  320. package/lib/eth1/utils/eth1DepositEvent.d.ts +0 -7
  321. package/lib/eth1/utils/eth1DepositEvent.d.ts.map +0 -1
  322. package/lib/eth1/utils/eth1DepositEvent.js +0 -13
  323. package/lib/eth1/utils/eth1DepositEvent.js.map +0 -1
  324. package/lib/eth1/utils/eth1Vote.d.ts +0 -17
  325. package/lib/eth1/utils/eth1Vote.d.ts.map +0 -1
  326. package/lib/eth1/utils/eth1Vote.js +0 -111
  327. package/lib/eth1/utils/eth1Vote.js.map +0 -1
  328. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts +0 -9
  329. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts.map +0 -1
  330. package/lib/eth1/utils/groupDepositEventsByBlock.js +0 -17
  331. package/lib/eth1/utils/groupDepositEventsByBlock.js.map +0 -1
  332. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts +0 -10
  333. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts.map +0 -1
  334. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js +0 -14
  335. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js.map +0 -1
  336. package/src/chain/genesis/genesis.ts +0 -190
  337. package/src/chain/genesis/interface.ts +0 -14
  338. package/src/db/repositories/depositDataRoot.ts +0 -80
  339. package/src/db/repositories/depositEvent.ts +0 -32
  340. package/src/db/repositories/eth1Data.ts +0 -33
  341. package/src/db/single/index.ts +0 -2
  342. package/src/db/single/preGenesisState.ts +0 -37
  343. package/src/db/single/preGenesisStateLastProcessedBlock.ts +0 -34
  344. package/src/eth1/errors.ts +0 -40
  345. package/src/eth1/eth1DataCache.ts +0 -26
  346. package/src/eth1/eth1DepositDataTracker.ts +0 -410
  347. package/src/eth1/eth1DepositsCache.ts +0 -141
  348. package/src/eth1/eth1MergeBlockTracker.ts +0 -328
  349. package/src/eth1/index.ts +0 -157
  350. package/src/eth1/interface.ts +0 -131
  351. package/src/eth1/options.ts +0 -28
  352. package/src/eth1/provider/eth1Provider.ts +0 -229
  353. package/src/eth1/provider/utils.ts +0 -136
  354. package/src/eth1/stream.ts +0 -75
  355. package/src/eth1/utils/depositContract.ts +0 -37
  356. package/src/eth1/utils/deposits.ts +0 -70
  357. package/src/eth1/utils/eth1Data.ts +0 -100
  358. package/src/eth1/utils/eth1DepositEvent.ts +0 -12
  359. package/src/eth1/utils/eth1Vote.ts +0 -142
  360. package/src/eth1/utils/groupDepositEventsByBlock.ts +0 -19
  361. package/src/eth1/utils/optimizeNextBlockDiffForGenesis.ts +0 -18
  362. /package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.js +0 -0
  363. /package/lib/{eth1/provider → execution/engine}/jwt.d.ts +0 -0
  364. /package/lib/{eth1/provider → execution/engine}/jwt.js +0 -0
  365. /package/src/{eth1/provider → execution/engine}/jwt.ts +0 -0
@@ -1,410 +0,0 @@
1
- import {ChainForkConfig} from "@lodestar/config";
2
- import {
3
- BeaconStateAllForks,
4
- CachedBeaconStateAllForks,
5
- CachedBeaconStateElectra,
6
- becomesNewEth1Data,
7
- } from "@lodestar/state-transition";
8
- import {phase0, ssz} from "@lodestar/types";
9
- import {ErrorAborted, Logger, TimeoutError, fromHex, isErrorAborted, sleep} from "@lodestar/utils";
10
- import {IBeaconDb} from "../db/index.js";
11
- import {Metrics} from "../metrics/index.js";
12
- import {Eth1DataCache} from "./eth1DataCache.js";
13
- import {Eth1DepositsCache} from "./eth1DepositsCache.js";
14
- import {Eth1DataAndDeposits, EthJsonRpcBlockRaw, IEth1Provider} from "./interface.js";
15
- import {Eth1Options} from "./options.js";
16
- import {parseEth1Block} from "./provider/eth1Provider.js";
17
- import {HttpRpcError} from "./provider/jsonRpcHttpClient.js";
18
- import {isJsonRpcTruncatedError} from "./provider/utils.js";
19
- import {getDeposits} from "./utils/deposits.js";
20
- import {getEth1VotesToConsider, pickEth1Vote} from "./utils/eth1Vote.js";
21
-
22
- const MAX_BLOCKS_PER_BLOCK_QUERY = 1000;
23
- const MIN_BLOCKS_PER_BLOCK_QUERY = 10;
24
-
25
- const MAX_BLOCKS_PER_LOG_QUERY = 1000;
26
- const MIN_BLOCKS_PER_LOG_QUERY = 10;
27
-
28
- /** Eth1 blocks happen every 14s approx, not need to update too often once synced */
29
- const AUTO_UPDATE_PERIOD_MS = 60 * 1000;
30
- /** Prevent infinite loops */
31
- const MIN_UPDATE_PERIOD_MS = 1 * 1000;
32
- /** Milliseconds to wait after getting 429 Too Many Requests */
33
- const RATE_LIMITED_WAIT_MS = 30 * 1000;
34
- /** Min time to wait on auto update loop on unknown error */
35
- const MIN_WAIT_ON_ERROR_MS = 1 * 1000;
36
-
37
- /** Number of blocks to download if the node detects it is lagging behind due to an inaccurate
38
- relationship between block-number-based follow distance and time-based follow distance. */
39
- const ETH1_FOLLOW_DISTANCE_DELTA_IF_SLOW = 32;
40
-
41
- /** The absolute minimum follow distance to enforce when downloading catchup batches, from LH */
42
- const ETH_MIN_FOLLOW_DISTANCE = 64;
43
-
44
- export type Eth1DepositDataTrackerModules = {
45
- config: ChainForkConfig;
46
- db: IBeaconDb;
47
- metrics: Metrics | null;
48
- logger: Logger;
49
- signal: AbortSignal;
50
- };
51
-
52
- /**
53
- * Main class handling eth1 data fetching, processing and storing
54
- * Upon instantiation, starts fetching deposits and blocks at regular intervals
55
- */
56
- export class Eth1DepositDataTracker {
57
- private config: ChainForkConfig;
58
- private logger: Logger;
59
- private signal: AbortSignal;
60
- private readonly metrics: Metrics | null;
61
-
62
- // Internal modules, state
63
- private depositsCache: Eth1DepositsCache;
64
- private eth1DataCache: Eth1DataCache;
65
- private lastProcessedDepositBlockNumber: number | null = null;
66
-
67
- /** Dynamically adjusted follow distance */
68
- private eth1FollowDistance: number;
69
- /** Dynamically adjusted batch size to fetch deposit logs */
70
- private eth1GetBlocksBatchSizeDynamic = MAX_BLOCKS_PER_BLOCK_QUERY;
71
- /** Dynamically adjusted batch size to fetch deposit logs */
72
- private eth1GetLogsBatchSizeDynamic = MAX_BLOCKS_PER_LOG_QUERY;
73
- private readonly forcedEth1DataVote: phase0.Eth1Data | null;
74
- /** To stop `runAutoUpdate()` in addition to AbortSignal */
75
- private stopPolling: boolean;
76
-
77
- constructor(
78
- opts: Eth1Options,
79
- {config, db, metrics, logger, signal}: Eth1DepositDataTrackerModules,
80
- private readonly eth1Provider: IEth1Provider
81
- ) {
82
- this.config = config;
83
- this.metrics = metrics;
84
- this.logger = logger;
85
- this.signal = signal;
86
- this.eth1Provider = eth1Provider;
87
- this.depositsCache = new Eth1DepositsCache(opts, config, db);
88
- this.eth1DataCache = new Eth1DataCache(config, db);
89
- this.eth1FollowDistance = config.ETH1_FOLLOW_DISTANCE;
90
- this.stopPolling = false;
91
-
92
- this.forcedEth1DataVote = opts.forcedEth1DataVote
93
- ? ssz.phase0.Eth1Data.deserialize(fromHex(opts.forcedEth1DataVote))
94
- : null;
95
-
96
- if (opts.depositContractDeployBlock === undefined) {
97
- this.logger.warn("No depositContractDeployBlock provided");
98
- }
99
-
100
- if (metrics) {
101
- // Set constant value once
102
- metrics?.eth1.eth1FollowDistanceSecondsConfig.set(config.SECONDS_PER_ETH1_BLOCK * config.ETH1_FOLLOW_DISTANCE);
103
- metrics.eth1.eth1FollowDistanceDynamic.addCollect(() => {
104
- metrics.eth1.eth1FollowDistanceDynamic.set(this.eth1FollowDistance);
105
- metrics.eth1.eth1GetBlocksBatchSizeDynamic.set(this.eth1GetBlocksBatchSizeDynamic);
106
- metrics.eth1.eth1GetLogsBatchSizeDynamic.set(this.eth1GetLogsBatchSizeDynamic);
107
- });
108
- }
109
-
110
- if (opts.enabled) {
111
- this.runAutoUpdate().catch((e: Error) => {
112
- if (!(e instanceof ErrorAborted)) {
113
- this.logger.error("Error on eth1 loop", {}, e);
114
- }
115
- });
116
- }
117
- }
118
-
119
- isPollingEth1Data(): boolean {
120
- return !this.stopPolling;
121
- }
122
-
123
- stopPollingEth1Data(): void {
124
- this.stopPolling = true;
125
- }
126
-
127
- /**
128
- * Return eth1Data and deposits ready for block production for a given state
129
- */
130
- async getEth1DataAndDeposits(state: CachedBeaconStateAllForks): Promise<Eth1DataAndDeposits> {
131
- if (
132
- state.epochCtx.isPostElectra() &&
133
- state.eth1DepositIndex >= (state as CachedBeaconStateElectra).depositRequestsStartIndex
134
- ) {
135
- // No need to poll eth1Data since Electra deprecates the mechanism after depositRequestsStartIndex is reached
136
- return {eth1Data: state.eth1Data, deposits: []};
137
- }
138
- const eth1Data = this.forcedEth1DataVote ?? (await this.getEth1Data(state));
139
- const deposits = await this.getDeposits(state, eth1Data);
140
- return {eth1Data, deposits};
141
- }
142
-
143
- /**
144
- * Returns an eth1Data vote for a given state.
145
- * Requires internal caches to be updated regularly to return good results
146
- */
147
- private async getEth1Data(state: BeaconStateAllForks): Promise<phase0.Eth1Data> {
148
- try {
149
- const eth1VotesToConsider = await getEth1VotesToConsider(
150
- this.config,
151
- state,
152
- this.eth1DataCache.get.bind(this.eth1DataCache)
153
- );
154
- return pickEth1Vote(state, eth1VotesToConsider);
155
- } catch (e) {
156
- // Note: In case there's a DB issue, don't stop a block proposal. Just vote for current eth1Data
157
- this.logger.error("CRITICAL: Error reading valid votes, voting for current eth1Data", {}, e as Error);
158
- return state.eth1Data;
159
- }
160
- }
161
-
162
- /**
163
- * Returns deposits to be included for a given state and eth1Data vote.
164
- * Requires internal caches to be updated regularly to return good results
165
- */
166
- private async getDeposits(
167
- state: CachedBeaconStateAllForks,
168
- eth1DataVote: phase0.Eth1Data
169
- ): Promise<phase0.Deposit[]> {
170
- // No new deposits have to be included, continue
171
- if (eth1DataVote.depositCount === state.eth1DepositIndex) {
172
- return [];
173
- }
174
-
175
- // TODO: Review if this is optimal
176
- // Convert to view first to hash once and compare hashes
177
- const eth1DataVoteView = ssz.phase0.Eth1Data.toViewDU(eth1DataVote);
178
-
179
- // Eth1 data may change due to the vote included in this block
180
- const newEth1Data = becomesNewEth1Data(state, eth1DataVoteView) ? eth1DataVoteView : state.eth1Data;
181
- return getDeposits(state, newEth1Data, this.depositsCache.get.bind(this.depositsCache));
182
- }
183
-
184
- /**
185
- * Abortable async setInterval that runs its callback once at max between `ms` at minimum
186
- */
187
- private async runAutoUpdate(): Promise<void> {
188
- let lastRunMs = 0;
189
-
190
- while (!this.signal.aborted && !this.stopPolling) {
191
- lastRunMs = Date.now();
192
-
193
- try {
194
- const hasCaughtUp = await this.update();
195
-
196
- this.metrics?.eth1.depositTrackerIsCaughtup.set(hasCaughtUp ? 1 : 0);
197
-
198
- if (hasCaughtUp) {
199
- const sleepTimeMs = Math.max(AUTO_UPDATE_PERIOD_MS + lastRunMs - Date.now(), MIN_UPDATE_PERIOD_MS);
200
- await sleep(sleepTimeMs, this.signal);
201
- }
202
- } catch (e) {
203
- this.metrics?.eth1.depositTrackerUpdateErrors.inc(1);
204
-
205
- // From Infura: 429 Too Many Requests
206
- if (e instanceof HttpRpcError && e.status === 429) {
207
- this.logger.debug("Eth1 provider rate limited", {}, e);
208
- await sleep(RATE_LIMITED_WAIT_MS, this.signal);
209
- // only log error if state switched from online to some other state
210
- } else if (!isErrorAborted(e)) {
211
- await sleep(MIN_WAIT_ON_ERROR_MS, this.signal);
212
- }
213
- }
214
- }
215
- }
216
-
217
- /**
218
- * Update the deposit and block cache, returning an error if either fail
219
- * @returns true if it has catched up to the remote follow block
220
- */
221
- private async update(): Promise<boolean> {
222
- const remoteHighestBlock = await this.eth1Provider.getBlockNumber();
223
- this.metrics?.eth1.remoteHighestBlock.set(remoteHighestBlock);
224
-
225
- const remoteFollowBlock = remoteHighestBlock - this.eth1FollowDistance;
226
-
227
- // If remoteFollowBlock is not at or beyond deployBlock, there is no need to
228
- // fetch and track any deposit data yet
229
- if (remoteFollowBlock < (this.eth1Provider.deployBlock ?? 0)) return true;
230
-
231
- const hasCaughtUpDeposits = await this.updateDepositCache(remoteFollowBlock);
232
- const hasCaughtUpBlocks = await this.updateBlockCache(remoteFollowBlock);
233
- return hasCaughtUpDeposits && hasCaughtUpBlocks;
234
- }
235
-
236
- /**
237
- * Fetch deposit events from remote eth1 node up to follow-distance block
238
- * @returns true if it has catched up to the remote follow block
239
- */
240
- private async updateDepositCache(remoteFollowBlock: number): Promise<boolean> {
241
- const lastProcessedDepositBlockNumber = await this.getLastProcessedDepositBlockNumber();
242
- // The DB may contain deposits from a different chain making lastProcessedDepositBlockNumber > current chain tip
243
- // The Math.min() fixes those rare scenarios where fromBlock > toBlock
244
- const fromBlock = Math.min(remoteFollowBlock, this.getFromBlockToFetch(lastProcessedDepositBlockNumber));
245
- const toBlock = Math.min(remoteFollowBlock, fromBlock + this.eth1GetLogsBatchSizeDynamic - 1);
246
-
247
- let depositEvents: phase0.DepositEvent[];
248
- try {
249
- depositEvents = await this.eth1Provider.getDepositEvents(fromBlock, toBlock);
250
- // Increase the batch size linearly even if we scale down exponentially (half each time)
251
- this.eth1GetLogsBatchSizeDynamic = Math.min(
252
- MAX_BLOCKS_PER_LOG_QUERY,
253
- this.eth1GetLogsBatchSizeDynamic + MIN_BLOCKS_PER_LOG_QUERY
254
- );
255
- } catch (e) {
256
- if (isJsonRpcTruncatedError(e as Error) || e instanceof TimeoutError) {
257
- this.eth1GetLogsBatchSizeDynamic = Math.max(
258
- MIN_BLOCKS_PER_LOG_QUERY,
259
- Math.floor(this.eth1GetLogsBatchSizeDynamic / 2)
260
- );
261
- }
262
- throw e;
263
- }
264
-
265
- this.logger.verbose("Fetched deposits", {depositCount: depositEvents.length, fromBlock, toBlock});
266
- this.metrics?.eth1.depositEventsFetched.inc(depositEvents.length);
267
-
268
- await this.depositsCache.add(depositEvents);
269
- // Store the `toBlock` since that block may not contain
270
- this.lastProcessedDepositBlockNumber = toBlock;
271
- this.metrics?.eth1.lastProcessedDepositBlockNumber.set(toBlock);
272
-
273
- return toBlock >= remoteFollowBlock;
274
- }
275
-
276
- /**
277
- * Fetch block headers from a remote eth1 node up to follow-distance block
278
- *
279
- * depositRoot and depositCount are inferred from already fetched deposits.
280
- * Calling get_deposit_root() and the smart contract for a non-latest block requires an
281
- * archive node, something most users don't have access too.
282
- * @returns true if it has catched up to the remote follow timestamp
283
- */
284
- private async updateBlockCache(remoteFollowBlock: number): Promise<boolean> {
285
- const lastCachedBlock = await this.eth1DataCache.getHighestCachedBlockNumber();
286
- // lastProcessedDepositBlockNumber sets the upper bound of the possible block range to fetch in this update
287
- const lastProcessedDepositBlockNumber = await this.getLastProcessedDepositBlockNumber();
288
- // lowestEventBlockNumber set a lower bound of possible block range to fetch in this update
289
- const lowestEventBlockNumber = await this.depositsCache.getLowestDepositEventBlockNumber();
290
-
291
- // We are all caught up if:
292
- // 1. If lowestEventBlockNumber is null = no deposits have been fetch or found yet.
293
- // So there's not useful blocks to fetch until at least 1 deposit is found.
294
- // 2. If the remoteFollowBlock is behind the lowestEventBlockNumber. This can happen
295
- // if the EL's data was wiped and restarted. Not exiting here would other wise
296
- // cause a NO_DEPOSITS_FOR_BLOCK_RANGE error
297
- if (
298
- lowestEventBlockNumber === null ||
299
- lastProcessedDepositBlockNumber === null ||
300
- remoteFollowBlock < lowestEventBlockNumber
301
- ) {
302
- return true;
303
- }
304
-
305
- // Cap the upper limit of fromBlock with remoteFollowBlock in case deployBlock is set to a different network value
306
- const fromBlock = Math.min(
307
- remoteFollowBlock,
308
- // Fetch from the last cached block or the lowest known deposit block number
309
- Math.max(this.getFromBlockToFetch(lastCachedBlock), lowestEventBlockNumber)
310
- );
311
- const toBlock = Math.min(
312
- remoteFollowBlock,
313
- fromBlock + this.eth1GetBlocksBatchSizeDynamic - 1, // Block range is inclusive
314
- lastProcessedDepositBlockNumber
315
- );
316
-
317
- let blocksRaw: EthJsonRpcBlockRaw[];
318
- try {
319
- blocksRaw = await this.eth1Provider.getBlocksByNumber(fromBlock, toBlock);
320
- // Increase the batch size linearly even if we scale down exponentially (half each time)
321
- this.eth1GetBlocksBatchSizeDynamic = Math.min(
322
- MAX_BLOCKS_PER_BLOCK_QUERY,
323
- this.eth1GetBlocksBatchSizeDynamic + MIN_BLOCKS_PER_BLOCK_QUERY
324
- );
325
- } catch (e) {
326
- if (isJsonRpcTruncatedError(e as Error) || e instanceof TimeoutError) {
327
- this.eth1GetBlocksBatchSizeDynamic = Math.max(
328
- MIN_BLOCKS_PER_BLOCK_QUERY,
329
- Math.floor(this.eth1GetBlocksBatchSizeDynamic / 2)
330
- );
331
- }
332
- throw e;
333
- }
334
- const blocks = blocksRaw.map(parseEth1Block);
335
-
336
- this.logger.verbose("Fetched eth1 blocks", {blockCount: blocks.length, fromBlock, toBlock});
337
- this.metrics?.eth1.blocksFetched.inc(blocks.length);
338
- this.metrics?.eth1.lastFetchedBlockBlockNumber.set(toBlock);
339
- const lastBlock = blocks.at(-1);
340
- if (lastBlock) {
341
- this.metrics?.eth1.lastFetchedBlockTimestamp.set(lastBlock.timestamp);
342
- }
343
-
344
- const eth1Datas = await this.depositsCache.getEth1DataForBlocks(blocks, lastProcessedDepositBlockNumber);
345
- await this.eth1DataCache.add(eth1Datas);
346
-
347
- // Note: ETH1_FOLLOW_DISTANCE_SECONDS = ETH1_FOLLOW_DISTANCE * SECONDS_PER_ETH1_BLOCK
348
- // Deposit tracker must fetch blocks and deposits up to ETH1_FOLLOW_DISTANCE_SECONDS,
349
- // measured in time not blocks. To vote on valid votes it must populate up to the time based follow distance.
350
- // If it assumes SECONDS_PER_ETH1_BLOCK but block times are:
351
- // - slower: Cache will not contain all blocks
352
- // - faster: Cache will contain all required blocks + some ahead of timed follow distance
353
- //
354
- // For mainnet we must fetch blocks up until block.timestamp < now - 28672 sec. Based on follow distance:
355
- // Block times | actual follow distance
356
- // 14 | 2048
357
- // 20 | 1434
358
- // 30 | 956
359
- // 60 | 478
360
- //
361
- // So if after fetching the block at ETH1_FOLLOW_DISTANCE, but it's timestamp is not greater than
362
- // ETH1_FOLLOW_DISTANCE_SECONDS, reduce the ETH1_FOLLOW_DISTANCE by a small delta and fetch more blocks.
363
- // Otherwise if the last fetched block if above ETH1_FOLLOW_DISTANCE_SECONDS, reduce ETH1_FOLLOW_DISTANCE.
364
-
365
- if (toBlock < remoteFollowBlock) {
366
- return false;
367
- }
368
-
369
- if (!lastBlock) {
370
- return true;
371
- }
372
-
373
- const remoteFollowBlockTimestamp =
374
- Math.round(Date.now() / 1000) - this.config.SECONDS_PER_ETH1_BLOCK * this.config.ETH1_FOLLOW_DISTANCE;
375
- const blockAfterTargetTimestamp = blocks.find((block) => block.timestamp >= remoteFollowBlockTimestamp);
376
-
377
- if (blockAfterTargetTimestamp) {
378
- // Catched up to target timestamp, increase eth1FollowDistance. Limit max config.ETH1_FOLLOW_DISTANCE.
379
- // If the block that's right above the timestamp has been fetched now, use it to compute the precise delta.
380
- const delta = Math.max(lastBlock.blockNumber - blockAfterTargetTimestamp.blockNumber, 1);
381
- this.eth1FollowDistance = Math.min(this.eth1FollowDistance + delta, this.config.ETH1_FOLLOW_DISTANCE);
382
-
383
- return true;
384
- }
385
- // Blocks are slower than expected, reduce eth1FollowDistance. Limit min CATCHUP_MIN_FOLLOW_DISTANCE
386
- const delta =
387
- this.eth1FollowDistance -
388
- Math.max(this.eth1FollowDistance - ETH1_FOLLOW_DISTANCE_DELTA_IF_SLOW, ETH_MIN_FOLLOW_DISTANCE);
389
- this.eth1FollowDistance = this.eth1FollowDistance - delta;
390
-
391
- // Even if the blocks are slow, when we are all caught up as there is no
392
- // further possibility to reduce follow distance, we need to call it quits
393
- // for now, else it leads to an incessant poll on the EL
394
- return delta === 0;
395
- }
396
-
397
- private getFromBlockToFetch(lastCachedBlock: number | null): number {
398
- if (lastCachedBlock === null) {
399
- return this.eth1Provider.deployBlock ?? 0;
400
- }
401
- return lastCachedBlock + 1;
402
- }
403
-
404
- private async getLastProcessedDepositBlockNumber(): Promise<number | null> {
405
- if (this.lastProcessedDepositBlockNumber === null) {
406
- this.lastProcessedDepositBlockNumber = await this.depositsCache.getHighestDepositEventBlockNumber();
407
- }
408
- return this.lastProcessedDepositBlockNumber;
409
- }
410
- }
@@ -1,141 +0,0 @@
1
- import {byteArrayEquals} from "@chainsafe/ssz";
2
- import {ChainForkConfig} from "@lodestar/config";
3
- import {FilterOptions} from "@lodestar/db";
4
- import {phase0, ssz} from "@lodestar/types";
5
- import {IBeaconDb} from "../db/index.js";
6
- import {Eth1Error, Eth1ErrorCode} from "./errors.js";
7
- import {Eth1Block} from "./interface.js";
8
- import {getDepositsWithProofs} from "./utils/deposits.js";
9
- import {getEth1DataForBlocks} from "./utils/eth1Data.js";
10
- import {assertConsecutiveDeposits} from "./utils/eth1DepositEvent.js";
11
-
12
- export class Eth1DepositsCache {
13
- unsafeAllowDepositDataOverwrite: boolean;
14
- db: IBeaconDb;
15
- config: ChainForkConfig;
16
-
17
- constructor(opts: {unsafeAllowDepositDataOverwrite?: boolean}, config: ChainForkConfig, db: IBeaconDb) {
18
- this.config = config;
19
- this.db = db;
20
- this.unsafeAllowDepositDataOverwrite = opts.unsafeAllowDepositDataOverwrite ?? false;
21
- }
22
-
23
- /**
24
- * Returns a list of `Deposit` objects, within the given deposit index `range`.
25
- *
26
- * The `depositCount` is used to generate the proofs for the `Deposits`. For example, if we
27
- * have 100 proofs, but the Ethereum Consensus chain only acknowledges 50 of them, we must produce our
28
- * proofs with respect to a tree size of 50.
29
- */
30
- async get(indexRange: FilterOptions<number>, eth1Data: phase0.Eth1Data): Promise<phase0.Deposit[]> {
31
- const depositEvents = await this.db.depositEvent.values(indexRange);
32
- const depositRootTree = await this.db.depositDataRoot.getDepositRootTree();
33
- return getDepositsWithProofs(depositEvents, depositRootTree, eth1Data);
34
- }
35
-
36
- /**
37
- * Add log to cache
38
- * This function enforces that `logs` are imported one-by-one with consecutive indexes
39
- */
40
- async add(depositEvents: phase0.DepositEvent[]): Promise<void> {
41
- assertConsecutiveDeposits(depositEvents);
42
-
43
- const lastLog = await this.db.depositEvent.lastValue();
44
- const firstEvent = depositEvents[0];
45
-
46
- // Check, validate and skip if we got any deposit events already present in DB
47
- // This can happen if the remote eth1/EL resets its head in these four scenarios:
48
- // 1. Remote eth1/EL resynced/restarted from head behind its previous head pre-merge
49
- // 2. In a post merge scenario, Lodestar restarted from finalized state from DB which
50
- // generally is a few epochs behind the last synced head. This causes eth1 tracker to reset
51
- // and refetch the deposits as the lodestar syncs further along (Post merge there is 1-1
52
- // correspondence between EL and CL blocks)
53
- // 3. The EL reorged beyond the eth1 follow distance.
54
- //
55
- // While 1. & 2. are benign and we handle them below by checking if the duplicate log fetched
56
- // is same as one written in DB. Refer to this issue for some data dump of how this happens
57
- // https://github.com/ChainSafe/lodestar/issues/3674
58
- //
59
- // If the duplicate log fetched is not same as written in DB then its probablu scenario 3.
60
- // which would be a catastrophic event for the network (or we messed up real bad!!!).
61
- //
62
- // So we provide for a way to overwrite this log without deleting full db via
63
- // --unsafeAllowDepositDataOverwrite cli flag which will just overwrite the previous tracker data
64
- // if any. This option as indicated by its name is unsafe and to be only used if you know what
65
- // you are doing.
66
- if (lastLog !== null && firstEvent !== undefined) {
67
- const newIndex = firstEvent.index;
68
- const lastLogIndex = lastLog.index;
69
-
70
- if (!this.unsafeAllowDepositDataOverwrite && firstEvent.index <= lastLog.index) {
71
- // lastLogIndex - newIndex + 1 events are duplicate since this is a consecutive log
72
- // as asserted by assertConsecutiveDeposits. Splice those events out from depositEvents.
73
- const skipEvents = depositEvents.splice(0, lastLogIndex - newIndex + 1);
74
- // After splicing skipEvents will contain duplicate events to be checked and validated
75
- // and rest of the remaining events in depositEvents could be safely written to DB and
76
- // move the tracker along.
77
- for (const depositEvent of skipEvents) {
78
- const prevDBSerializedEvent = await this.db.depositEvent.getBinary(depositEvent.index);
79
- if (!prevDBSerializedEvent) {
80
- throw new Eth1Error({code: Eth1ErrorCode.MISSING_DEPOSIT_LOG, newIndex, lastLogIndex});
81
- }
82
- const serializedEvent = ssz.phase0.DepositEvent.serialize(depositEvent);
83
- if (!byteArrayEquals(prevDBSerializedEvent, serializedEvent)) {
84
- throw new Eth1Error({code: Eth1ErrorCode.DUPLICATE_DISTINCT_LOG, newIndex, lastLogIndex});
85
- }
86
- }
87
- } else if (newIndex > lastLogIndex + 1) {
88
- // deposit events need to be consective, the way we fetch our tracker. If the deposit event
89
- // is not consecutive it means either our tracker, or the corresponding eth1/EL
90
- // node or the database has messed up. All these failures are critical and the tracker
91
- // shouldn't proceed without the resolution of this error.
92
- throw new Eth1Error({code: Eth1ErrorCode.NON_CONSECUTIVE_LOGS, newIndex, lastLogIndex});
93
- }
94
- }
95
-
96
- const depositRoots = depositEvents.map((depositEvent) => ({
97
- index: depositEvent.index,
98
- root: ssz.phase0.DepositData.hashTreeRoot(depositEvent.depositData),
99
- }));
100
-
101
- // Store events after verifying that data is consecutive
102
- // depositDataRoot will throw if adding non consecutive roots
103
- await this.db.depositDataRoot.batchPutValues(depositRoots);
104
- await this.db.depositEvent.batchPutValues(depositEvents);
105
- }
106
-
107
- /**
108
- * Appends partial eth1 data (depositRoot, depositCount) in a block range (inclusive)
109
- * Returned array is sequential and ascending in blockNumber
110
- * @param fromBlock
111
- * @param toBlock
112
- */
113
- async getEth1DataForBlocks(
114
- blocks: Eth1Block[],
115
- lastProcessedDepositBlockNumber: number | null
116
- ): Promise<(phase0.Eth1Data & Eth1Block)[]> {
117
- const highestBlock = blocks.at(-1)?.blockNumber;
118
- return getEth1DataForBlocks(
119
- blocks,
120
- this.db.depositEvent.valuesStream({lte: highestBlock, reverse: true}),
121
- await this.db.depositDataRoot.getDepositRootTree(),
122
- lastProcessedDepositBlockNumber
123
- );
124
- }
125
-
126
- /**
127
- * Returns the highest blockNumber stored in DB if any
128
- */
129
- async getHighestDepositEventBlockNumber(): Promise<number | null> {
130
- const latestEvent = await this.db.depositEvent.lastValue();
131
- return latestEvent?.blockNumber || null;
132
- }
133
-
134
- /**
135
- * Returns the lowest blockNumber stored in DB if any
136
- */
137
- async getLowestDepositEventBlockNumber(): Promise<number | null> {
138
- const firstEvent = await this.db.depositEvent.firstValue();
139
- return firstEvent?.blockNumber || null;
140
- }
141
- }