@lodestar/beacon-node 1.50.0-dev.456b75a81e → 1.50.0-dev.4b00f7bf39

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 (389) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +13 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/index.js +13 -0
  6. package/lib/api/impl/beacon/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/index.js +28 -6
  9. package/lib/api/impl/beacon/state/index.js.map +1 -1
  10. package/lib/api/impl/debug/index.d.ts.map +1 -1
  11. package/lib/api/impl/debug/index.js +26 -18
  12. package/lib/api/impl/debug/index.js.map +1 -1
  13. package/lib/api/impl/validator/index.d.ts +1 -0
  14. package/lib/api/impl/validator/index.d.ts.map +1 -1
  15. package/lib/api/impl/validator/index.js +80 -18
  16. package/lib/api/impl/validator/index.js.map +1 -1
  17. package/lib/chain/ColumnReconstructionTracker.d.ts +0 -2
  18. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  19. package/lib/chain/ColumnReconstructionTracker.js +4 -5
  20. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  21. package/lib/chain/archiveStore/archiveStore.d.ts +5 -0
  22. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  23. package/lib/chain/archiveStore/archiveStore.js +14 -24
  24. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  25. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +2 -2
  26. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  27. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -7
  28. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  29. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js +1 -1
  30. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js.map +1 -1
  31. package/lib/chain/archiveStore/historicalState/types.d.ts +2 -2
  32. package/lib/chain/archiveStore/historicalState/types.d.ts.map +1 -1
  33. package/lib/chain/archiveStore/historicalState/worker.js +1 -1
  34. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  35. package/lib/chain/archiveStore/interface.d.ts +1 -1
  36. package/lib/chain/archiveStore/interface.d.ts.map +1 -1
  37. package/lib/chain/archiveStore/utils/pruneHistory.d.ts +1 -1
  38. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  39. package/lib/chain/archiveStore/utils/pruneHistory.js +2 -1
  40. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  41. package/lib/chain/beaconProposerCache.d.ts +6 -0
  42. package/lib/chain/beaconProposerCache.d.ts.map +1 -1
  43. package/lib/chain/beaconProposerCache.js +16 -0
  44. package/lib/chain/beaconProposerCache.js.map +1 -1
  45. package/lib/chain/blocks/blockInput/blockInput.d.ts +1 -1
  46. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  47. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  48. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  49. package/lib/chain/blocks/importBlock.js +21 -12
  50. package/lib/chain/blocks/importBlock.js.map +1 -1
  51. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
  52. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  53. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  54. package/lib/chain/blocks/verifyBlock.js +7 -7
  55. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  56. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts +2 -1
  57. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  58. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +5 -4
  59. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  60. package/lib/chain/chain.d.ts +10 -5
  61. package/lib/chain/chain.d.ts.map +1 -1
  62. package/lib/chain/chain.js +105 -35
  63. package/lib/chain/chain.js.map +1 -1
  64. package/lib/chain/emitter.d.ts +7 -1
  65. package/lib/chain/emitter.d.ts.map +1 -1
  66. package/lib/chain/emitter.js +5 -0
  67. package/lib/chain/emitter.js.map +1 -1
  68. package/lib/chain/errors/envelopeReconstructionError.d.ts +5 -0
  69. package/lib/chain/errors/envelopeReconstructionError.d.ts.map +1 -1
  70. package/lib/chain/errors/envelopeReconstructionError.js +2 -0
  71. package/lib/chain/errors/envelopeReconstructionError.js.map +1 -1
  72. package/lib/chain/errors/gossipValidation.d.ts +1 -0
  73. package/lib/chain/errors/gossipValidation.d.ts.map +1 -1
  74. package/lib/chain/errors/gossipValidation.js +1 -0
  75. package/lib/chain/errors/gossipValidation.js.map +1 -1
  76. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  77. package/lib/chain/forkChoice/index.js +2 -0
  78. package/lib/chain/forkChoice/index.js.map +1 -1
  79. package/lib/chain/interface.d.ts +6 -3
  80. package/lib/chain/interface.d.ts.map +1 -1
  81. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -2
  82. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  83. package/lib/chain/opPools/aggregatedAttestationPool.js +30 -8
  84. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  85. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  86. package/lib/chain/opPools/opPool.js +1 -23
  87. package/lib/chain/opPools/opPool.js.map +1 -1
  88. package/lib/chain/opPools/proposerPreferencesPool.d.ts +8 -4
  89. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
  90. package/lib/chain/opPools/proposerPreferencesPool.js +27 -12
  91. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
  92. package/lib/chain/opPools/utils.d.ts +11 -0
  93. package/lib/chain/opPools/utils.d.ts.map +1 -1
  94. package/lib/chain/opPools/utils.js +22 -0
  95. package/lib/chain/opPools/utils.js.map +1 -1
  96. package/lib/chain/options.d.ts +2 -1
  97. package/lib/chain/options.d.ts.map +1 -1
  98. package/lib/chain/options.js +1 -1
  99. package/lib/chain/options.js.map +1 -1
  100. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  101. package/lib/chain/prepareNextSlot.js +20 -8
  102. package/lib/chain/prepareNextSlot.js.map +1 -1
  103. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  104. package/lib/chain/produceBlock/computeNewStateRoot.js +1 -1
  105. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  106. package/lib/chain/produceBlock/produceBlockBody.d.ts +11 -1
  107. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  108. package/lib/chain/produceBlock/produceBlockBody.js +54 -36
  109. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  110. package/lib/chain/regen/regen.d.ts +2 -0
  111. package/lib/chain/regen/regen.d.ts.map +1 -1
  112. package/lib/chain/regen/regen.js +10 -4
  113. package/lib/chain/regen/regen.js.map +1 -1
  114. package/lib/chain/reprocess.d.ts +2 -1
  115. package/lib/chain/reprocess.d.ts.map +1 -1
  116. package/lib/chain/reprocess.js +2 -1
  117. package/lib/chain/reprocess.js.map +1 -1
  118. package/lib/chain/seenCache/seenGossipBlockInput.d.ts +7 -0
  119. package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -1
  120. package/lib/chain/seenCache/seenGossipBlockInput.js +22 -1
  121. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  122. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +9 -2
  123. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  124. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +23 -13
  125. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  126. package/lib/chain/shufflingCache.d.ts +18 -8
  127. package/lib/chain/shufflingCache.d.ts.map +1 -1
  128. package/lib/chain/shufflingCache.js +72 -18
  129. package/lib/chain/shufflingCache.js.map +1 -1
  130. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  131. package/lib/chain/stateCache/persistentCheckpointsCache.js +1 -1
  132. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  133. package/lib/chain/validatorMonitor.d.ts +5 -1
  134. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  135. package/lib/chain/validatorMonitor.js +70 -58
  136. package/lib/chain/validatorMonitor.js.map +1 -1
  137. package/lib/constants/constants.d.ts +1 -0
  138. package/lib/constants/constants.d.ts.map +1 -1
  139. package/lib/constants/constants.js +1 -0
  140. package/lib/constants/constants.js.map +1 -1
  141. package/lib/db/beacon.d.ts +4 -1
  142. package/lib/db/beacon.d.ts.map +1 -1
  143. package/lib/db/beacon.js +6 -1
  144. package/lib/db/beacon.js.map +1 -1
  145. package/lib/db/buckets.d.ts +3 -1
  146. package/lib/db/buckets.d.ts.map +1 -1
  147. package/lib/db/buckets.js +2 -0
  148. package/lib/db/buckets.js.map +1 -1
  149. package/lib/db/interface.d.ts +4 -1
  150. package/lib/db/interface.d.ts.map +1 -1
  151. package/lib/db/repositories/blockArchive.js +2 -2
  152. package/lib/db/repositories/blockArchive.js.map +1 -1
  153. package/lib/db/repositories/blockArchiveIndex.d.ts +3 -3
  154. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  155. package/lib/db/repositories/blockArchiveIndex.js +1 -2
  156. package/lib/db/repositories/blockArchiveIndex.js.map +1 -1
  157. package/lib/db/repositories/earliestAvailableSlot.d.ts +11 -0
  158. package/lib/db/repositories/earliestAvailableSlot.d.ts.map +1 -0
  159. package/lib/db/repositories/earliestAvailableSlot.js +19 -0
  160. package/lib/db/repositories/earliestAvailableSlot.js.map +1 -0
  161. package/lib/db/repositories/index.d.ts +1 -0
  162. package/lib/db/repositories/index.d.ts.map +1 -1
  163. package/lib/db/repositories/index.js +1 -0
  164. package/lib/db/repositories/index.js.map +1 -1
  165. package/lib/db/repositories/proposerPreferences.d.ts +14 -0
  166. package/lib/db/repositories/proposerPreferences.d.ts.map +1 -0
  167. package/lib/db/repositories/proposerPreferences.js +21 -0
  168. package/lib/db/repositories/proposerPreferences.js.map +1 -0
  169. package/lib/execution/engine/blobVersionedHashes.d.ts +9 -0
  170. package/lib/execution/engine/blobVersionedHashes.d.ts.map +1 -0
  171. package/lib/execution/engine/blobVersionedHashes.js +74 -0
  172. package/lib/execution/engine/blobVersionedHashes.js.map +1 -0
  173. package/lib/execution/engine/disabled.d.ts +0 -2
  174. package/lib/execution/engine/disabled.d.ts.map +1 -1
  175. package/lib/execution/engine/disabled.js +0 -6
  176. package/lib/execution/engine/disabled.js.map +1 -1
  177. package/lib/execution/engine/http.d.ts +46 -16
  178. package/lib/execution/engine/http.d.ts.map +1 -1
  179. package/lib/execution/engine/http.js +236 -213
  180. package/lib/execution/engine/http.js.map +1 -1
  181. package/lib/execution/engine/index.d.ts +3 -2
  182. package/lib/execution/engine/index.d.ts.map +1 -1
  183. package/lib/execution/engine/index.js +33 -8
  184. package/lib/execution/engine/index.js.map +1 -1
  185. package/lib/execution/engine/interface.d.ts +2 -4
  186. package/lib/execution/engine/interface.d.ts.map +1 -1
  187. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
  188. package/lib/execution/engine/jsonRpcHttpClient.js +14 -4
  189. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
  190. package/lib/execution/engine/jsonRpcTransport.d.ts +25 -0
  191. package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -0
  192. package/lib/execution/engine/jsonRpcTransport.js +158 -0
  193. package/lib/execution/engine/jsonRpcTransport.js.map +1 -0
  194. package/lib/execution/engine/mock.d.ts +0 -2
  195. package/lib/execution/engine/mock.d.ts.map +1 -1
  196. package/lib/execution/engine/mock.js +0 -8
  197. package/lib/execution/engine/mock.js.map +1 -1
  198. package/lib/execution/engine/restHttpClient.d.ts +71 -0
  199. package/lib/execution/engine/restHttpClient.d.ts.map +1 -0
  200. package/lib/execution/engine/restHttpClient.js +201 -0
  201. package/lib/execution/engine/restHttpClient.js.map +1 -0
  202. package/lib/execution/engine/restTransport.d.ts +48 -0
  203. package/lib/execution/engine/restTransport.d.ts.map +1 -0
  204. package/lib/execution/engine/restTransport.js +411 -0
  205. package/lib/execution/engine/restTransport.js.map +1 -0
  206. package/lib/execution/engine/sszTypes.d.ts +1261 -0
  207. package/lib/execution/engine/sszTypes.d.ts.map +1 -0
  208. package/lib/execution/engine/sszTypes.js +216 -0
  209. package/lib/execution/engine/sszTypes.js.map +1 -0
  210. package/lib/execution/engine/transport.d.ts +39 -0
  211. package/lib/execution/engine/transport.d.ts.map +1 -0
  212. package/lib/execution/engine/transport.js +2 -0
  213. package/lib/execution/engine/transport.js.map +1 -0
  214. package/lib/execution/engine/transportMetrics.d.ts +5 -1
  215. package/lib/execution/engine/transportMetrics.d.ts.map +1 -1
  216. package/lib/execution/engine/types.d.ts +2 -8
  217. package/lib/execution/engine/types.d.ts.map +1 -1
  218. package/lib/execution/engine/types.js +31 -63
  219. package/lib/execution/engine/types.js.map +1 -1
  220. package/lib/execution/engine/utils.d.ts.map +1 -1
  221. package/lib/execution/engine/utils.js +9 -2
  222. package/lib/execution/engine/utils.js.map +1 -1
  223. package/lib/metrics/metrics/lodestar.d.ts +14 -0
  224. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  225. package/lib/metrics/metrics/lodestar.js +29 -1
  226. package/lib/metrics/metrics/lodestar.js.map +1 -1
  227. package/lib/metrics/metrics.d.ts +7 -3
  228. package/lib/metrics/metrics.d.ts.map +1 -1
  229. package/lib/metrics/metrics.js +4 -4
  230. package/lib/metrics/metrics.js.map +1 -1
  231. package/lib/network/core/events.d.ts +5 -1
  232. package/lib/network/core/events.d.ts.map +1 -1
  233. package/lib/network/core/events.js +8 -0
  234. package/lib/network/core/events.js.map +1 -1
  235. package/lib/network/gossip/topic.d.ts +0 -14
  236. package/lib/network/gossip/topic.d.ts.map +1 -1
  237. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  238. package/lib/network/processor/gossipHandlers.js +63 -64
  239. package/lib/network/processor/gossipHandlers.js.map +1 -1
  240. package/lib/network/processor/gossipValidatorFn.d.ts +4 -2
  241. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  242. package/lib/network/processor/gossipValidatorFn.js +6 -2
  243. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  244. package/lib/network/processor/index.d.ts +8 -0
  245. package/lib/network/processor/index.d.ts.map +1 -1
  246. package/lib/network/processor/index.js +52 -5
  247. package/lib/network/processor/index.js.map +1 -1
  248. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +1 -1
  249. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
  250. package/lib/network/reqresp/rateLimit.js +2 -2
  251. package/lib/network/reqresp/rateLimit.js.map +1 -1
  252. package/lib/network/subnets/attnetsService.d.ts.map +1 -1
  253. package/lib/network/subnets/attnetsService.js +3 -1
  254. package/lib/network/subnets/attnetsService.js.map +1 -1
  255. package/lib/node/nodejs.d.ts +3 -1
  256. package/lib/node/nodejs.d.ts.map +1 -1
  257. package/lib/node/nodejs.js +27 -4
  258. package/lib/node/nodejs.js.map +1 -1
  259. package/lib/node/notifier.d.ts.map +1 -1
  260. package/lib/node/notifier.js +12 -13
  261. package/lib/node/notifier.js.map +1 -1
  262. package/lib/node/options.d.ts +3 -2
  263. package/lib/node/options.d.ts.map +1 -1
  264. package/lib/node/options.js +2 -2
  265. package/lib/node/options.js.map +1 -1
  266. package/lib/sync/range/batch.d.ts +11 -5
  267. package/lib/sync/range/batch.d.ts.map +1 -1
  268. package/lib/sync/range/batch.js +21 -17
  269. package/lib/sync/range/batch.js.map +1 -1
  270. package/lib/sync/range/chain.d.ts +4 -4
  271. package/lib/sync/range/chain.d.ts.map +1 -1
  272. package/lib/sync/range/chain.js +12 -6
  273. package/lib/sync/range/chain.js.map +1 -1
  274. package/lib/sync/range/range.d.ts.map +1 -1
  275. package/lib/sync/range/range.js +75 -29
  276. package/lib/sync/range/range.js.map +1 -1
  277. package/lib/sync/unknownBlock.d.ts +5 -2
  278. package/lib/sync/unknownBlock.d.ts.map +1 -1
  279. package/lib/sync/unknownBlock.js +52 -26
  280. package/lib/sync/unknownBlock.js.map +1 -1
  281. package/lib/sync/utils/downloadByRange.d.ts +38 -14
  282. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  283. package/lib/sync/utils/downloadByRange.js +84 -39
  284. package/lib/sync/utils/downloadByRange.js.map +1 -1
  285. package/lib/util/asyncIterableToEvents.d.ts +10 -2
  286. package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
  287. package/lib/util/asyncIterableToEvents.js +29 -3
  288. package/lib/util/asyncIterableToEvents.js.map +1 -1
  289. package/lib/util/clock.d.ts.map +1 -1
  290. package/lib/util/clock.js +3 -4
  291. package/lib/util/clock.js.map +1 -1
  292. package/lib/util/execution.d.ts +9 -11
  293. package/lib/util/execution.d.ts.map +1 -1
  294. package/lib/util/execution.js +5 -1
  295. package/lib/util/execution.js.map +1 -1
  296. package/lib/util/metadata.d.ts.map +1 -1
  297. package/lib/util/metadata.js +2 -1
  298. package/lib/util/metadata.js.map +1 -1
  299. package/lib/util/sszBytes.d.ts +2 -2
  300. package/lib/util/sszBytes.d.ts.map +1 -1
  301. package/lib/util/sszBytes.js +22 -14
  302. package/lib/util/sszBytes.js.map +1 -1
  303. package/package.json +18 -17
  304. package/src/api/impl/beacon/blocks/index.ts +17 -7
  305. package/src/api/impl/beacon/index.ts +15 -0
  306. package/src/api/impl/beacon/state/index.ts +43 -6
  307. package/src/api/impl/debug/index.ts +28 -19
  308. package/src/api/impl/validator/index.ts +102 -21
  309. package/src/chain/ColumnReconstructionTracker.ts +4 -6
  310. package/src/chain/archiveStore/archiveStore.ts +19 -25
  311. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +5 -7
  312. package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +1 -1
  313. package/src/chain/archiveStore/historicalState/types.ts +2 -2
  314. package/src/chain/archiveStore/historicalState/worker.ts +1 -2
  315. package/src/chain/archiveStore/interface.ts +1 -1
  316. package/src/chain/archiveStore/utils/pruneHistory.ts +4 -1
  317. package/src/chain/beaconProposerCache.ts +19 -1
  318. package/src/chain/blocks/blockInput/blockInput.ts +1 -1
  319. package/src/chain/blocks/importBlock.ts +25 -11
  320. package/src/chain/blocks/payloadEnvelopeInput/types.ts +2 -1
  321. package/src/chain/blocks/verifyBlock.ts +8 -6
  322. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +6 -3
  323. package/src/chain/chain.ts +135 -37
  324. package/src/chain/emitter.ts +7 -1
  325. package/src/chain/errors/envelopeReconstructionError.ts +3 -0
  326. package/src/chain/errors/gossipValidation.ts +1 -0
  327. package/src/chain/forkChoice/index.ts +2 -0
  328. package/src/chain/interface.ts +7 -3
  329. package/src/chain/opPools/aggregatedAttestationPool.ts +34 -10
  330. package/src/chain/opPools/opPool.ts +1 -31
  331. package/src/chain/opPools/proposerPreferencesPool.ts +34 -11
  332. package/src/chain/opPools/utils.ts +31 -0
  333. package/src/chain/options.ts +3 -3
  334. package/src/chain/prepareNextSlot.ts +28 -9
  335. package/src/chain/produceBlock/computeNewStateRoot.ts +10 -3
  336. package/src/chain/produceBlock/produceBlockBody.ts +86 -40
  337. package/src/chain/regen/regen.ts +12 -4
  338. package/src/chain/reprocess.ts +2 -1
  339. package/src/chain/seenCache/seenGossipBlockInput.ts +25 -1
  340. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +31 -13
  341. package/src/chain/shufflingCache.ts +84 -22
  342. package/src/chain/stateCache/persistentCheckpointsCache.ts +4 -1
  343. package/src/chain/validatorMonitor.ts +82 -61
  344. package/src/constants/constants.ts +1 -0
  345. package/src/db/beacon.ts +6 -0
  346. package/src/db/buckets.ts +2 -0
  347. package/src/db/interface.ts +4 -0
  348. package/src/db/repositories/blockArchive.ts +2 -2
  349. package/src/db/repositories/blockArchiveIndex.ts +2 -3
  350. package/src/db/repositories/earliestAvailableSlot.ts +19 -0
  351. package/src/db/repositories/index.ts +1 -0
  352. package/src/db/repositories/proposerPreferences.ts +23 -0
  353. package/src/execution/engine/blobVersionedHashes.ts +72 -0
  354. package/src/execution/engine/disabled.ts +0 -8
  355. package/src/execution/engine/http.ts +304 -300
  356. package/src/execution/engine/index.ts +42 -7
  357. package/src/execution/engine/interface.ts +2 -6
  358. package/src/execution/engine/jsonRpcHttpClient.ts +12 -5
  359. package/src/execution/engine/jsonRpcTransport.ts +247 -0
  360. package/src/execution/engine/mock.ts +1 -19
  361. package/src/execution/engine/restHttpClient.ts +269 -0
  362. package/src/execution/engine/restTransport.ts +575 -0
  363. package/src/execution/engine/sszTypes.ts +354 -0
  364. package/src/execution/engine/transport.ts +61 -0
  365. package/src/execution/engine/transportMetrics.ts +2 -1
  366. package/src/execution/engine/types.ts +42 -90
  367. package/src/execution/engine/utils.ts +12 -2
  368. package/src/metrics/metrics/lodestar.ts +30 -1
  369. package/src/metrics/metrics.ts +21 -6
  370. package/src/network/core/events.ts +16 -1
  371. package/src/network/processor/gossipHandlers.ts +94 -77
  372. package/src/network/processor/gossipValidatorFn.ts +12 -2
  373. package/src/network/processor/index.ts +58 -5
  374. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +1 -1
  375. package/src/network/reqresp/rateLimit.ts +2 -2
  376. package/src/network/subnets/attnetsService.ts +8 -3
  377. package/src/node/nodejs.ts +35 -3
  378. package/src/node/notifier.ts +14 -13
  379. package/src/node/options.ts +10 -1
  380. package/src/sync/range/batch.ts +25 -19
  381. package/src/sync/range/chain.ts +15 -8
  382. package/src/sync/range/range.ts +76 -30
  383. package/src/sync/unknownBlock.ts +65 -27
  384. package/src/sync/utils/downloadByRange.ts +123 -58
  385. package/src/util/asyncIterableToEvents.ts +44 -5
  386. package/src/util/clock.ts +3 -4
  387. package/src/util/execution.ts +16 -8
  388. package/src/util/metadata.ts +2 -1
  389. package/src/util/sszBytes.ts +25 -12
@@ -0,0 +1,354 @@
1
+ import {
2
+ BitVectorType,
3
+ ByteListType,
4
+ CompositeType,
5
+ CompositeView,
6
+ CompositeViewDU,
7
+ ContainerType,
8
+ ListCompositeType,
9
+ ValueOf,
10
+ } from "@chainsafe/ssz";
11
+ import {CELLS_PER_EXT_BLOB, ForkName, ForkPostBellatrix, MAX_BYTES_PER_TRANSACTION} from "@lodestar/params";
12
+ import {ssz} from "@lodestar/types";
13
+
14
+ /**
15
+ * SSZ containers of the REST engine API, per execution-apis `src/engine/refactor-ssz.md`
16
+ * at 5bcdc34a477b10af278c079525374e6a4046f291.
17
+ *
18
+ * Execution payloads, withdrawals and blobs bundles are shared with the consensus types since
19
+ * they serialize identically. Everything else is transport-only and therefore defined here.
20
+ */
21
+
22
+ const MAX_EXECUTION_REQUESTS_PER_PAYLOAD = 256;
23
+ const MAX_BYTES_PER_EXECUTION_REQUEST = MAX_BYTES_PER_TRANSACTION;
24
+ const MAX_BAL_BYTES = MAX_BYTES_PER_TRANSACTION;
25
+ const MAX_ERROR_BYTES = 1024;
26
+ export const MAX_BODIES_REQUEST = 32;
27
+ export const MAX_BLOBS_REQUEST = 128;
28
+
29
+ /** `Optional[T]` is `List[T, 1]` on the wire, the ssz library's `OptionalType` is a different encoding */
30
+ function Optional<T extends CompositeType<ValueOf<T>, CompositeView<T>, CompositeViewDU<T>>>(
31
+ type: T
32
+ ): ListCompositeType<T> {
33
+ return new ListCompositeType(type, 1);
34
+ }
35
+
36
+ const {Bytes8, Bytes32, Bytes48, ExecutionAddress, Root, Uint8, UintBn64, UintBn256, UintNum64} = ssz;
37
+
38
+ const ExecutionRequestsList = new ListCompositeType(
39
+ new ByteListType(MAX_BYTES_PER_EXECUTION_REQUEST),
40
+ MAX_EXECUTION_REQUESTS_PER_PAYLOAD
41
+ );
42
+
43
+ export const PayloadStatus = new ContainerType(
44
+ {
45
+ status: Uint8,
46
+ latestValidHash: Optional(Bytes32),
47
+ validationError: Optional(new ByteListType(MAX_ERROR_BYTES)),
48
+ },
49
+ {typeName: "PayloadStatus"}
50
+ );
51
+
52
+ export const ForkchoiceState = new ContainerType(
53
+ {
54
+ headBlockHash: Bytes32,
55
+ safeBlockHash: Bytes32,
56
+ finalizedBlockHash: Bytes32,
57
+ },
58
+ {typeName: "ForkchoiceState"}
59
+ );
60
+
61
+ export const ForkchoiceUpdateResponse = new ContainerType(
62
+ {
63
+ payloadStatus: PayloadStatus,
64
+ payloadId: Optional(Bytes8),
65
+ },
66
+ {typeName: "ForkchoiceUpdateResponse"}
67
+ );
68
+
69
+ export const PayloadAttributesBellatrix = new ContainerType(
70
+ {
71
+ timestamp: UintNum64,
72
+ prevRandao: Bytes32,
73
+ suggestedFeeRecipient: ExecutionAddress,
74
+ },
75
+ {typeName: "PayloadAttributes"}
76
+ );
77
+
78
+ export const PayloadAttributesCapella = new ContainerType(
79
+ {
80
+ ...PayloadAttributesBellatrix.fields,
81
+ withdrawals: ssz.capella.Withdrawals,
82
+ },
83
+ {typeName: "PayloadAttributes"}
84
+ );
85
+
86
+ export const PayloadAttributesDeneb = new ContainerType(
87
+ {
88
+ ...PayloadAttributesCapella.fields,
89
+ parentBeaconBlockRoot: Root,
90
+ },
91
+ {typeName: "PayloadAttributes"}
92
+ );
93
+
94
+ export const PayloadAttributesGloas = new ContainerType(
95
+ {
96
+ ...PayloadAttributesDeneb.fields,
97
+ slotNumber: UintNum64,
98
+ targetGasLimit: UintBn64,
99
+ },
100
+ {typeName: "PayloadAttributes"}
101
+ );
102
+
103
+ const CustodyColumns = new BitVectorType(CELLS_PER_EXT_BLOB);
104
+
105
+ function ForkchoiceUpdateType<T extends CompositeType<ValueOf<T>, CompositeView<T>, CompositeViewDU<T>>>(
106
+ payloadAttributes: T
107
+ ) {
108
+ return new ContainerType(
109
+ {
110
+ forkchoiceState: ForkchoiceState,
111
+ payloadAttributes: Optional(payloadAttributes),
112
+ },
113
+ {typeName: "ForkchoiceUpdate"}
114
+ );
115
+ }
116
+
117
+ export const ForkchoiceUpdateBellatrix = ForkchoiceUpdateType(PayloadAttributesBellatrix);
118
+ export const ForkchoiceUpdateCapella = ForkchoiceUpdateType(PayloadAttributesCapella);
119
+ export const ForkchoiceUpdateDeneb = ForkchoiceUpdateType(PayloadAttributesDeneb);
120
+ export const ForkchoiceUpdateGloas = new ContainerType(
121
+ {
122
+ ...ForkchoiceUpdateType(PayloadAttributesGloas).fields,
123
+ custodyColumns: Optional(CustodyColumns),
124
+ },
125
+ {typeName: "ForkchoiceUpdate"}
126
+ );
127
+
128
+ export const ExecutionPayloadEnvelopeBellatrix = new ContainerType(
129
+ {payload: ssz.bellatrix.ExecutionPayload},
130
+ {typeName: "ExecutionPayloadEnvelope"}
131
+ );
132
+ export const ExecutionPayloadEnvelopeCapella = new ContainerType(
133
+ {payload: ssz.capella.ExecutionPayload},
134
+ {typeName: "ExecutionPayloadEnvelope"}
135
+ );
136
+ export const ExecutionPayloadEnvelopeDeneb = new ContainerType(
137
+ {
138
+ payload: ssz.deneb.ExecutionPayload,
139
+ parentBeaconBlockRoot: Root,
140
+ },
141
+ {typeName: "ExecutionPayloadEnvelope"}
142
+ );
143
+ export const ExecutionPayloadEnvelopeElectra = new ContainerType(
144
+ {
145
+ payload: ssz.electra.ExecutionPayload,
146
+ parentBeaconBlockRoot: Root,
147
+ executionRequests: ExecutionRequestsList,
148
+ },
149
+ {typeName: "ExecutionPayloadEnvelope"}
150
+ );
151
+ export const ExecutionPayloadEnvelopeGloas = new ContainerType(
152
+ {
153
+ payload: ssz.gloas.ExecutionPayload,
154
+ parentBeaconBlockRoot: Root,
155
+ executionRequests: ExecutionRequestsList,
156
+ },
157
+ {typeName: "ExecutionPayloadEnvelope"}
158
+ );
159
+
160
+ export const BuiltPayloadBellatrix = new ContainerType(
161
+ {
162
+ payload: ssz.bellatrix.ExecutionPayload,
163
+ blockValue: UintBn256,
164
+ },
165
+ {typeName: "BuiltPayload"}
166
+ );
167
+ export const BuiltPayloadCapella = new ContainerType(
168
+ {
169
+ payload: ssz.capella.ExecutionPayload,
170
+ blockValue: UintBn256,
171
+ },
172
+ {typeName: "BuiltPayload"}
173
+ );
174
+ export const BuiltPayloadDeneb = new ContainerType(
175
+ {
176
+ payload: ssz.deneb.ExecutionPayload,
177
+ blockValue: UintBn256,
178
+ blobsBundle: ssz.deneb.BlobsBundle,
179
+ shouldOverrideBuilder: ssz.Boolean,
180
+ },
181
+ {typeName: "BuiltPayload"}
182
+ );
183
+ export const BuiltPayloadElectra = new ContainerType(
184
+ {
185
+ payload: ssz.electra.ExecutionPayload,
186
+ blockValue: UintBn256,
187
+ blobsBundle: ssz.deneb.BlobsBundle,
188
+ executionRequests: ExecutionRequestsList,
189
+ shouldOverrideBuilder: ssz.Boolean,
190
+ },
191
+ {typeName: "BuiltPayload"}
192
+ );
193
+ export const BuiltPayloadFulu = new ContainerType(
194
+ {
195
+ payload: ssz.fulu.ExecutionPayload,
196
+ blockValue: UintBn256,
197
+ blobsBundle: ssz.fulu.BlobsBundle,
198
+ executionRequests: ExecutionRequestsList,
199
+ shouldOverrideBuilder: ssz.Boolean,
200
+ },
201
+ {typeName: "BuiltPayload"}
202
+ );
203
+ export const BuiltPayloadGloas = new ContainerType(
204
+ {
205
+ payload: ssz.gloas.ExecutionPayload,
206
+ blockValue: UintBn256,
207
+ blobsBundle: ssz.fulu.BlobsBundle,
208
+ executionRequests: ExecutionRequestsList,
209
+ shouldOverrideBuilder: ssz.Boolean,
210
+ },
211
+ {typeName: "BuiltPayload"}
212
+ );
213
+
214
+ export const ExecutionPayloadBodyBellatrix = new ContainerType(
215
+ {transactions: ssz.bellatrix.Transactions},
216
+ {typeName: "ExecutionPayloadBody"}
217
+ );
218
+ export const ExecutionPayloadBodyCapella = new ContainerType(
219
+ {
220
+ transactions: ssz.bellatrix.Transactions,
221
+ withdrawals: ssz.capella.Withdrawals,
222
+ },
223
+ {typeName: "ExecutionPayloadBody"}
224
+ );
225
+ export const ExecutionPayloadBodyGloas = new ContainerType(
226
+ {
227
+ transactions: ssz.bellatrix.Transactions,
228
+ withdrawals: ssz.capella.Withdrawals,
229
+ blockAccessList: new ByteListType(MAX_BAL_BYTES),
230
+ },
231
+ {typeName: "ExecutionPayloadBody"}
232
+ );
233
+
234
+ function BodiesResponseType<T extends CompositeType<ValueOf<T>, CompositeView<T>, CompositeViewDU<T>>>(body: T) {
235
+ const BodyEntry = new ContainerType({available: ssz.Boolean, body}, {typeName: "BodyEntry"});
236
+ return new ContainerType(
237
+ {entries: new ListCompositeType(BodyEntry, MAX_BODIES_REQUEST)},
238
+ {typeName: "BodiesResponse"}
239
+ );
240
+ }
241
+
242
+ export const BodiesResponseBellatrix = BodiesResponseType(ExecutionPayloadBodyBellatrix);
243
+ export const BodiesResponseCapella = BodiesResponseType(ExecutionPayloadBodyCapella);
244
+ export const BodiesResponseGloas = BodiesResponseType(ExecutionPayloadBodyGloas);
245
+
246
+ export const BodiesByHashRequest = new ContainerType(
247
+ {blockHashes: new ListCompositeType(Bytes32, MAX_BODIES_REQUEST)},
248
+ {typeName: "BodiesByHashRequest"}
249
+ );
250
+
251
+ export const BlobsRequest = new ContainerType(
252
+ {versionedHashes: new ListCompositeType(Bytes32, MAX_BLOBS_REQUEST)},
253
+ {typeName: "BlobsRequest"}
254
+ );
255
+
256
+ const BlobAndProofV1 = new ContainerType(
257
+ {
258
+ blob: ssz.deneb.Blob,
259
+ proof: Bytes48,
260
+ },
261
+ {typeName: "BlobAndProofV1"}
262
+ );
263
+
264
+ const BlobAndProofV2 = new ContainerType(
265
+ {
266
+ blob: ssz.deneb.Blob,
267
+ proofs: new ListCompositeType(Bytes48, CELLS_PER_EXT_BLOB),
268
+ },
269
+ {typeName: "BlobAndProofV2"}
270
+ );
271
+
272
+ function BlobsResponseType<T extends CompositeType<ValueOf<T>, CompositeView<T>, CompositeViewDU<T>>>(contents: T) {
273
+ const BlobEntry = new ContainerType({available: ssz.Boolean, contents}, {typeName: "BlobEntry"});
274
+ return new ContainerType({entries: new ListCompositeType(BlobEntry, MAX_BLOBS_REQUEST)}, {typeName: "BlobsResponse"});
275
+ }
276
+
277
+ export const BlobsV1Response = BlobsResponseType(BlobAndProofV1);
278
+ export const BlobsV2Response = BlobsResponseType(BlobAndProofV2);
279
+
280
+ const bellatrix = {
281
+ PayloadAttributes: PayloadAttributesBellatrix,
282
+ ForkchoiceUpdate: ForkchoiceUpdateBellatrix,
283
+ ExecutionPayloadEnvelope: ExecutionPayloadEnvelopeBellatrix,
284
+ BuiltPayload: BuiltPayloadBellatrix,
285
+ BodiesResponse: BodiesResponseBellatrix,
286
+ };
287
+
288
+ const capella = {
289
+ PayloadAttributes: PayloadAttributesCapella,
290
+ ForkchoiceUpdate: ForkchoiceUpdateCapella,
291
+ ExecutionPayloadEnvelope: ExecutionPayloadEnvelopeCapella,
292
+ BuiltPayload: BuiltPayloadCapella,
293
+ BodiesResponse: BodiesResponseCapella,
294
+ };
295
+
296
+ const deneb = {
297
+ PayloadAttributes: PayloadAttributesDeneb,
298
+ ForkchoiceUpdate: ForkchoiceUpdateDeneb,
299
+ ExecutionPayloadEnvelope: ExecutionPayloadEnvelopeDeneb,
300
+ BuiltPayload: BuiltPayloadDeneb,
301
+ BodiesResponse: BodiesResponseCapella,
302
+ };
303
+
304
+ const electra = {
305
+ ...deneb,
306
+ ExecutionPayloadEnvelope: ExecutionPayloadEnvelopeElectra,
307
+ BuiltPayload: BuiltPayloadElectra,
308
+ };
309
+
310
+ const fulu = {
311
+ ...electra,
312
+ BuiltPayload: BuiltPayloadFulu,
313
+ };
314
+
315
+ const gloas = {
316
+ PayloadAttributes: PayloadAttributesGloas,
317
+ ForkchoiceUpdate: ForkchoiceUpdateGloas,
318
+ ExecutionPayloadEnvelope: ExecutionPayloadEnvelopeGloas,
319
+ BuiltPayload: BuiltPayloadGloas,
320
+ BodiesResponse: BodiesResponseGloas,
321
+ };
322
+
323
+ export const engineSszTypes = {
324
+ [ForkName.bellatrix]: bellatrix,
325
+ [ForkName.capella]: capella,
326
+ [ForkName.deneb]: deneb,
327
+ [ForkName.electra]: electra,
328
+ [ForkName.fulu]: fulu,
329
+ [ForkName.gloas]: gloas,
330
+ [ForkName.heze]: gloas,
331
+ };
332
+
333
+ export type PayloadStatusSsz = ValueOf<typeof PayloadStatus>;
334
+
335
+ /** Fork names accepted in the `Eth-Execution-Version` header */
336
+ export type ExecutionForkName = "paris" | "shanghai" | "cancun" | "prague" | "osaka" | "amsterdam";
337
+
338
+ /** Heze has no execution fork name in the spec yet, auto mode serves it over JSON-RPC and ssz mode fails the call */
339
+ export const executionForkName: Record<ForkPostBellatrix, ExecutionForkName | null> = {
340
+ [ForkName.bellatrix]: "paris",
341
+ [ForkName.capella]: "shanghai",
342
+ [ForkName.deneb]: "cancun",
343
+ [ForkName.electra]: "prague",
344
+ [ForkName.fulu]: "osaka",
345
+ [ForkName.gloas]: "amsterdam",
346
+ [ForkName.heze]: null,
347
+ };
348
+
349
+ export enum PayloadStatusCode {
350
+ VALID = 0,
351
+ INVALID = 1,
352
+ SYNCING = 2,
353
+ ACCEPTED = 3,
354
+ }
@@ -0,0 +1,61 @@
1
+ import {ForkName} from "@lodestar/params";
2
+ import {BlobsBundle, ExecutionPayload, ExecutionRequests, Root, RootHex, Wei} from "@lodestar/types";
3
+ import {BlobAndProof} from "@lodestar/types/deneb";
4
+ import {BlobAndProofV2} from "@lodestar/types/fulu";
5
+ import {ClientVersion, ExecutionPayloadStatus, PayloadAttributes, PayloadId, VersionedHashes} from "./interface.js";
6
+ import {JsonRpcHttpClientEventEmitter} from "./jsonRpcHttpClient.js";
7
+ import {ExecutionPayloadBodyV2} from "./types.js";
8
+
9
+ export type PayloadStatusResult = {
10
+ status: ExecutionPayloadStatus;
11
+ latestValidHash: RootHex | null;
12
+ validationError: string | null;
13
+ };
14
+
15
+ export type ForkchoiceUpdatedResult = {
16
+ payloadStatus: PayloadStatusResult;
17
+ payloadId: PayloadId | null;
18
+ };
19
+
20
+ export type GetPayloadResult = {
21
+ executionPayload: ExecutionPayload;
22
+ executionPayloadValue: Wei;
23
+ blobsBundle?: BlobsBundle;
24
+ executionRequests?: ExecutionRequests;
25
+ shouldOverrideBuilder?: boolean;
26
+ };
27
+
28
+ /**
29
+ * Wire-level access to the engine API of the execution client. Implementations only translate
30
+ * between Lodestar types and the encoding of their transport, `ExecutionEngineHttp` owns request
31
+ * ordering, engine state and result interpretation.
32
+ */
33
+ export interface IEngineTransport {
34
+ readonly emitter: JsonRpcHttpClientEventEmitter;
35
+
36
+ newPayload(
37
+ fork: ForkName,
38
+ executionPayload: ExecutionPayload,
39
+ versionedHashes?: VersionedHashes,
40
+ parentBeaconBlockRoot?: Root,
41
+ executionRequests?: ExecutionRequests
42
+ ): Promise<PayloadStatusResult>;
43
+
44
+ forkchoiceUpdated(
45
+ fork: ForkName,
46
+ headBlockHash: RootHex,
47
+ safeBlockHash: RootHex,
48
+ finalizedBlockHash: RootHex,
49
+ payloadAttributes?: PayloadAttributes
50
+ ): Promise<ForkchoiceUpdatedResult>;
51
+
52
+ getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult>;
53
+
54
+ getPayloadBodiesByHashV2(blockHashes: RootHex[]): Promise<(ExecutionPayloadBodyV2 | null)[]>;
55
+
56
+ getBlobsV1(versionedHashes: VersionedHashes): Promise<(BlobAndProof | null)[]>;
57
+
58
+ getBlobsV2(versionedHashes: VersionedHashes, buffers?: Uint8Array[]): Promise<BlobAndProofV2[] | null>;
59
+
60
+ getClientVersion(clientVersion: ClientVersion): Promise<ClientVersion[]>;
61
+ }
@@ -1,4 +1,4 @@
1
- import {Counter} from "@lodestar/utils";
1
+ import {Counter, Histogram} from "@lodestar/utils";
2
2
 
3
3
  /**
4
4
  * Common metrics type for both json rpc and ssz transport.
@@ -6,4 +6,5 @@ import {Counter} from "@lodestar/utils";
6
6
  export type EngineTransportMetrics = {
7
7
  requestBytes: Counter<{routeId: string}>;
8
8
  responseBytes: Counter<{routeId: string}>;
9
+ responseParseTime: Histogram<{routeId: string; encoding: "json" | "ssz"}>;
9
10
  };
@@ -1,3 +1,4 @@
1
+ import {Type} from "@chainsafe/ssz";
1
2
  import {
2
3
  BUILDER_DEPOSIT_REQUEST_TYPE,
3
4
  BUILDER_EXIT_REQUEST_TYPE,
@@ -20,7 +21,6 @@ import {
20
21
  bellatrix,
21
22
  capella,
22
23
  deneb,
23
- electra,
24
24
  gloas,
25
25
  ssz,
26
26
  } from "@lodestar/types";
@@ -88,15 +88,8 @@ export type EngineApiRpcParamTypes = {
88
88
  /**
89
89
  * 1. Array of DATA - Array of block_hash field values of the ExecutionPayload structure
90
90
  * */
91
- engine_getPayloadBodiesByHashV1: DATA[][];
92
91
  engine_getPayloadBodiesByHashV2: DATA[][];
93
92
 
94
- /**
95
- * 1. start: QUANTITY, 64 bits - Starting block number
96
- * 2. count: QUANTITY, 64 bits - Number of blocks to return
97
- */
98
- engine_getPayloadBodiesByRangeV1: [start: QUANTITY, count: QUANTITY];
99
-
100
93
  /**
101
94
  * Object - Instance of ClientVersion
102
95
  */
@@ -148,11 +141,8 @@ export type EngineApiRpcReturnTypes = {
148
141
  engine_getPayloadV5: ExecutionPayloadResponse;
149
142
  engine_getPayloadV6: ExecutionPayloadResponse;
150
143
 
151
- engine_getPayloadBodiesByHashV1: (ExecutionPayloadBodyRpc | null)[];
152
144
  engine_getPayloadBodiesByHashV2: (ExecutionPayloadBodyV2Rpc | null)[];
153
145
 
154
- engine_getPayloadBodiesByRangeV1: (ExecutionPayloadBodyRpc | null)[];
155
-
156
146
  engine_getClientVersionV1: ClientVersionRpc[];
157
147
 
158
148
  engine_getBlobsV1: (BlobAndProofRpc | null)[];
@@ -511,63 +501,15 @@ export function deserializeWithdrawal(serialized: WithdrawalRpc): capella.Withdr
511
501
  }
512
502
 
513
503
  /**
514
- * Prepend a single-byte requestType to requestsBytes
504
+ * Serialize requests prefixed with a single-byte requestType in one allocation
515
505
  */
516
- function prefixRequests(requestsBytes: Uint8Array, requestType: ExecutionRequestType): Uint8Array {
517
- const prefixedRequests = new Uint8Array(1 + requestsBytes.length);
518
- prefixedRequests[0] = requestType;
519
- prefixedRequests.set(requestsBytes, 1);
520
-
521
- return prefixedRequests;
522
- }
523
-
524
- function serializeDepositRequests(depositRequests: electra.DepositRequests): DepositRequestsRpc {
525
- const requestsBytes = ssz.electra.DepositRequests.serialize(depositRequests);
526
- return bytesToData(prefixRequests(requestsBytes, DEPOSIT_REQUEST_TYPE));
527
- }
528
-
529
- function deserializeDepositRequests(serialized: DepositRequestsRpc): electra.DepositRequests {
530
- return ssz.electra.DepositRequests.deserialize(dataToBytes(serialized, null));
531
- }
532
-
533
- function serializeWithdrawalRequests(withdrawalRequests: electra.WithdrawalRequests): WithdrawalRequestsRpc {
534
- const requestsBytes = ssz.electra.WithdrawalRequests.serialize(withdrawalRequests);
535
- return bytesToData(prefixRequests(requestsBytes, WITHDRAWAL_REQUEST_TYPE));
536
- }
537
-
538
- function deserializeWithdrawalRequests(serialized: WithdrawalRequestsRpc): electra.WithdrawalRequests {
539
- return ssz.electra.WithdrawalRequests.deserialize(dataToBytes(serialized, null));
540
- }
541
-
542
- function serializeConsolidationRequests(
543
- consolidationRequests: electra.ConsolidationRequests
544
- ): ConsolidationRequestsRpc {
545
- const requestsBytes = ssz.electra.ConsolidationRequests.serialize(consolidationRequests);
546
- return bytesToData(prefixRequests(requestsBytes, CONSOLIDATION_REQUEST_TYPE));
547
- }
548
-
549
- function deserializeConsolidationRequests(serialized: ConsolidationRequestsRpc): electra.ConsolidationRequests {
550
- return ssz.electra.ConsolidationRequests.deserialize(dataToBytes(serialized, null));
551
- }
506
+ function serializePrefixedRequests<T>(type: Type<T>, requests: T, requestType: ExecutionRequestType): Uint8Array {
507
+ const uint8Array = new Uint8Array(1 + type.value_serializedSize(requests));
508
+ const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength);
509
+ uint8Array[0] = requestType;
510
+ type.value_serializeToBytes({uint8Array, dataView}, 1, requests);
552
511
 
553
- function serializeBuilderDepositRequests(
554
- builderDepositRequests: gloas.BuilderDepositRequests
555
- ): BuilderDepositRequestsRpc {
556
- const requestsBytes = ssz.gloas.BuilderDepositRequests.serialize(builderDepositRequests);
557
- return bytesToData(prefixRequests(requestsBytes, BUILDER_DEPOSIT_REQUEST_TYPE));
558
- }
559
-
560
- function deserializeBuilderDepositRequests(serialized: BuilderDepositRequestsRpc): gloas.BuilderDepositRequests {
561
- return ssz.gloas.BuilderDepositRequests.deserialize(dataToBytes(serialized, null));
562
- }
563
-
564
- function serializeBuilderExitRequests(builderExitRequests: gloas.BuilderExitRequests): BuilderExitRequestsRpc {
565
- const requestsBytes = ssz.gloas.BuilderExitRequests.serialize(builderExitRequests);
566
- return bytesToData(prefixRequests(requestsBytes, BUILDER_EXIT_REQUEST_TYPE));
567
- }
568
-
569
- function deserializeBuilderExitRequests(serialized: BuilderExitRequestsRpc): gloas.BuilderExitRequests {
570
- return ssz.gloas.BuilderExitRequests.deserialize(dataToBytes(serialized, null));
512
+ return uint8Array;
571
513
  }
572
514
 
573
515
  /**
@@ -577,62 +519,65 @@ function deserializeBuilderExitRequests(serialized: BuilderExitRequestsRpc): glo
577
519
  * Gloas extends the list with builder deposits (0x03) and builder exits (0x04) per
578
520
  * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.11/specs/gloas/beacon-chain.md#modified-get_execution_requests_list
579
521
  */
580
- export function serializeExecutionRequests(fork: ForkName, executionRequests: ExecutionRequests): ExecutionRequestsRpc {
522
+ export function serializeExecutionRequestsToBytes(fork: ForkName, executionRequests: ExecutionRequests): Uint8Array[] {
581
523
  const {deposits, withdrawals, consolidations} = executionRequests;
582
- const result: ExecutionRequestsRpc = [];
524
+ const result: Uint8Array[] = [];
583
525
 
584
526
  if (deposits.length !== 0) {
585
- result.push(serializeDepositRequests(deposits));
527
+ result.push(serializePrefixedRequests(ssz.electra.DepositRequests, deposits, DEPOSIT_REQUEST_TYPE));
586
528
  }
587
529
 
588
530
  if (withdrawals.length !== 0) {
589
- result.push(serializeWithdrawalRequests(withdrawals));
531
+ result.push(serializePrefixedRequests(ssz.electra.WithdrawalRequests, withdrawals, WITHDRAWAL_REQUEST_TYPE));
590
532
  }
591
533
 
592
534
  if (consolidations.length !== 0) {
593
- result.push(serializeConsolidationRequests(consolidations));
535
+ result.push(
536
+ serializePrefixedRequests(ssz.electra.ConsolidationRequests, consolidations, CONSOLIDATION_REQUEST_TYPE)
537
+ );
594
538
  }
595
539
 
596
540
  if (ForkSeq[fork] >= ForkSeq.gloas) {
597
541
  const {builderDeposits, builderExits} = executionRequests as gloas.ExecutionRequests;
598
542
 
599
543
  if (builderDeposits.length !== 0) {
600
- result.push(serializeBuilderDepositRequests(builderDeposits));
544
+ result.push(
545
+ serializePrefixedRequests(ssz.gloas.BuilderDepositRequests, builderDeposits, BUILDER_DEPOSIT_REQUEST_TYPE)
546
+ );
601
547
  }
602
548
 
603
549
  if (builderExits.length !== 0) {
604
- result.push(serializeBuilderExitRequests(builderExits));
550
+ result.push(serializePrefixedRequests(ssz.gloas.BuilderExitRequests, builderExits, BUILDER_EXIT_REQUEST_TYPE));
605
551
  }
606
552
  }
607
553
 
608
554
  return result;
609
555
  }
610
556
 
611
- export function deserializeExecutionRequests(fork: ForkName, serialized: ExecutionRequestsRpc): ExecutionRequests {
557
+ export function serializeExecutionRequests(fork: ForkName, executionRequests: ExecutionRequests): ExecutionRequestsRpc {
558
+ return serializeExecutionRequestsToBytes(fork, executionRequests).map(bytesToData);
559
+ }
560
+
561
+ export function deserializeExecutionRequestsFromBytes(fork: ForkName, serialized: Uint8Array[]): ExecutionRequests {
612
562
  const result: ExecutionRequests =
613
563
  ForkSeq[fork] >= ForkSeq.gloas
614
564
  ? {deposits: [], withdrawals: [], consolidations: [], builderDeposits: [], builderExits: []}
615
565
  : {deposits: [], withdrawals: [], consolidations: []};
616
566
 
617
- if (serialized.length === 0) {
618
- return result;
619
- }
620
-
621
567
  let prevRequestType: ExecutionRequestType | undefined;
622
568
 
623
- for (let prefixedRequests of serialized) {
624
- // Slice out 0x so it is easier to extract request type
625
- if (prefixedRequests.startsWith("0x")) {
626
- prefixedRequests = prefixedRequests.slice(2);
569
+ for (const prefixedRequests of serialized) {
570
+ if (prefixedRequests.length === 0) {
571
+ throw Error("Invalid request type, request must be prefixed with its type");
627
572
  }
628
573
 
629
- const currentRequestType = parseInt(prefixedRequests.substring(0, 2), 16);
574
+ const currentRequestType = prefixedRequests[0];
630
575
 
631
576
  if (!isExecutionRequestType(currentRequestType)) {
632
- throw Error(`Invalid request type currentRequestType=${prefixedRequests.substring(0, 2)}`);
577
+ throw Error(`Invalid request type currentRequestType=${currentRequestType}`);
633
578
  }
634
579
 
635
- const requests = prefixedRequests.slice(2);
580
+ const requests = prefixedRequests.subarray(1);
636
581
 
637
582
  if (requests.length === 0) {
638
583
  throw Error(
@@ -648,29 +593,29 @@ export function deserializeExecutionRequests(fork: ForkName, serialized: Executi
648
593
 
649
594
  switch (currentRequestType) {
650
595
  case DEPOSIT_REQUEST_TYPE: {
651
- result.deposits = deserializeDepositRequests(requests);
596
+ result.deposits = ssz.electra.DepositRequests.deserialize(requests);
652
597
  break;
653
598
  }
654
599
  case WITHDRAWAL_REQUEST_TYPE: {
655
- result.withdrawals = deserializeWithdrawalRequests(requests);
600
+ result.withdrawals = ssz.electra.WithdrawalRequests.deserialize(requests);
656
601
  break;
657
602
  }
658
603
  case CONSOLIDATION_REQUEST_TYPE: {
659
- result.consolidations = deserializeConsolidationRequests(requests);
604
+ result.consolidations = ssz.electra.ConsolidationRequests.deserialize(requests);
660
605
  break;
661
606
  }
662
607
  case BUILDER_DEPOSIT_REQUEST_TYPE: {
663
608
  if (ForkSeq[fork] < ForkSeq.gloas) {
664
609
  throw Error(`Builder deposit request is not supported pre-gloas fork=${fork}`);
665
610
  }
666
- (result as gloas.ExecutionRequests).builderDeposits = deserializeBuilderDepositRequests(requests);
611
+ (result as gloas.ExecutionRequests).builderDeposits = ssz.gloas.BuilderDepositRequests.deserialize(requests);
667
612
  break;
668
613
  }
669
614
  case BUILDER_EXIT_REQUEST_TYPE: {
670
615
  if (ForkSeq[fork] < ForkSeq.gloas) {
671
616
  throw Error(`Builder exit request is not supported pre-gloas fork=${fork}`);
672
617
  }
673
- (result as gloas.ExecutionRequests).builderExits = deserializeBuilderExitRequests(requests);
618
+ (result as gloas.ExecutionRequests).builderExits = ssz.gloas.BuilderExitRequests.deserialize(requests);
674
619
  break;
675
620
  }
676
621
  }
@@ -680,6 +625,13 @@ export function deserializeExecutionRequests(fork: ForkName, serialized: Executi
680
625
  return result;
681
626
  }
682
627
 
628
+ export function deserializeExecutionRequests(fork: ForkName, serialized: ExecutionRequestsRpc): ExecutionRequests {
629
+ return deserializeExecutionRequestsFromBytes(
630
+ fork,
631
+ serialized.map((data) => dataToBytes(data, null))
632
+ );
633
+ }
634
+
683
635
  export function deserializeExecutionPayloadBody(data: ExecutionPayloadBodyRpc | null): ExecutionPayloadBody | null {
684
636
  return data
685
637
  ? {