@lodestar/beacon-node 1.47.0-dev.cec7fd63e3 → 1.47.0-dev.d477ac6ef7

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 (356) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +47 -18
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +25 -2
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts +2 -1
  8. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  9. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  10. package/lib/api/impl/events/index.d.ts +1 -1
  11. package/lib/api/impl/events/index.d.ts.map +1 -1
  12. package/lib/api/impl/events/index.js +12 -3
  13. package/lib/api/impl/events/index.js.map +1 -1
  14. package/lib/api/impl/lodestar/index.js +1 -1
  15. package/lib/api/impl/lodestar/index.js.map +1 -1
  16. package/lib/api/impl/validator/index.d.ts.map +1 -1
  17. package/lib/api/impl/validator/index.js +232 -49
  18. package/lib/api/impl/validator/index.js.map +1 -1
  19. package/lib/api/impl/validator/utils.js +1 -1
  20. package/lib/api/impl/validator/utils.js.map +1 -1
  21. package/lib/api/rest/base.d.ts.map +1 -1
  22. package/lib/api/rest/base.js +7 -0
  23. package/lib/api/rest/base.js.map +1 -1
  24. package/lib/chain/archiveStore/archiveStore.js +1 -1
  25. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  26. package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -1
  27. package/lib/chain/archiveStore/historicalState/metrics.js +21 -0
  28. package/lib/chain/archiveStore/historicalState/metrics.js.map +1 -1
  29. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  30. package/lib/chain/blocks/importBlock.js +2 -7
  31. package/lib/chain/blocks/importBlock.js.map +1 -1
  32. package/lib/chain/blocks/importExecutionPayload.d.ts +3 -2
  33. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  34. package/lib/chain/blocks/importExecutionPayload.js +11 -9
  35. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  36. package/lib/chain/blocks/index.d.ts.map +1 -1
  37. package/lib/chain/blocks/index.js +21 -13
  38. package/lib/chain/blocks/index.js.map +1 -1
  39. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts +2 -1
  40. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -1
  41. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +6 -2
  42. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.map +1 -1
  43. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +14 -5
  44. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  45. package/lib/chain/blocks/payloadEnvelopeInput/types.js +5 -0
  46. package/lib/chain/blocks/payloadEnvelopeInput/types.js.map +1 -1
  47. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  48. package/lib/chain/blocks/verifyBlock.js +5 -2
  49. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  50. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  51. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +22 -12
  52. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  53. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts +2 -2
  54. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts.map +1 -1
  55. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js +2 -2
  56. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js.map +1 -1
  57. package/lib/chain/bls/index.d.ts +1 -1
  58. package/lib/chain/bls/index.d.ts.map +1 -1
  59. package/lib/chain/bls/interface.d.ts +5 -5
  60. package/lib/chain/bls/interface.d.ts.map +1 -1
  61. package/lib/chain/bls/multithread/index.d.ts +5 -11
  62. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  63. package/lib/chain/bls/multithread/index.js +116 -101
  64. package/lib/chain/bls/multithread/index.js.map +1 -1
  65. package/lib/chain/bls/multithread/jobItem.d.ts +5 -19
  66. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -1
  67. package/lib/chain/bls/multithread/jobItem.js +10 -65
  68. package/lib/chain/bls/multithread/jobItem.js.map +1 -1
  69. package/lib/chain/bls/multithread/types.d.ts +29 -8
  70. package/lib/chain/bls/multithread/types.d.ts.map +1 -1
  71. package/lib/chain/bls/multithread/types.js +12 -0
  72. package/lib/chain/bls/multithread/types.js.map +1 -1
  73. package/lib/chain/bls/multithread/utils.d.ts +4 -0
  74. package/lib/chain/bls/multithread/utils.d.ts.map +1 -1
  75. package/lib/chain/bls/multithread/utils.js +10 -0
  76. package/lib/chain/bls/multithread/utils.js.map +1 -1
  77. package/lib/chain/bls/multithread/worker.js +49 -23
  78. package/lib/chain/bls/multithread/worker.js.map +1 -1
  79. package/lib/chain/bls/singleThread.d.ts +4 -10
  80. package/lib/chain/bls/singleThread.d.ts.map +1 -1
  81. package/lib/chain/bls/singleThread.js +8 -45
  82. package/lib/chain/bls/singleThread.js.map +1 -1
  83. package/lib/chain/bls/utils.d.ts +4 -4
  84. package/lib/chain/bls/utils.d.ts.map +1 -1
  85. package/lib/chain/bls/utils.js +18 -19
  86. package/lib/chain/bls/utils.js.map +1 -1
  87. package/lib/chain/chain.d.ts +9 -4
  88. package/lib/chain/chain.d.ts.map +1 -1
  89. package/lib/chain/chain.js +22 -8
  90. package/lib/chain/chain.js.map +1 -1
  91. package/lib/chain/errors/blockError.d.ts +1 -0
  92. package/lib/chain/errors/blockError.d.ts.map +1 -1
  93. package/lib/chain/errors/blockError.js +6 -1
  94. package/lib/chain/errors/blockError.js.map +1 -1
  95. package/lib/chain/errors/proposerPreferences.d.ts +6 -0
  96. package/lib/chain/errors/proposerPreferences.d.ts.map +1 -1
  97. package/lib/chain/errors/proposerPreferences.js +1 -0
  98. package/lib/chain/errors/proposerPreferences.js.map +1 -1
  99. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  100. package/lib/chain/forkChoice/index.js +4 -0
  101. package/lib/chain/forkChoice/index.js.map +1 -1
  102. package/lib/chain/interface.d.ts +8 -4
  103. package/lib/chain/interface.d.ts.map +1 -1
  104. package/lib/chain/interface.js.map +1 -1
  105. package/lib/chain/opPools/aggregatedAttestationPool.js +1 -1
  106. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  107. package/lib/chain/opPools/attestationPool.d.ts +1 -1
  108. package/lib/chain/opPools/attestationPool.d.ts.map +1 -1
  109. package/lib/chain/opPools/attestationPool.js +1 -1
  110. package/lib/chain/opPools/attestationPool.js.map +1 -1
  111. package/lib/chain/opPools/deferredVoluntaryExitPool.d.ts +16 -0
  112. package/lib/chain/opPools/deferredVoluntaryExitPool.d.ts.map +1 -0
  113. package/lib/chain/opPools/deferredVoluntaryExitPool.js +57 -0
  114. package/lib/chain/opPools/deferredVoluntaryExitPool.js.map +1 -0
  115. package/lib/chain/opPools/executionPayloadBidPool.d.ts +7 -2
  116. package/lib/chain/opPools/executionPayloadBidPool.d.ts.map +1 -1
  117. package/lib/chain/opPools/executionPayloadBidPool.js +4 -4
  118. package/lib/chain/opPools/executionPayloadBidPool.js.map +1 -1
  119. package/lib/chain/opPools/index.d.ts +2 -1
  120. package/lib/chain/opPools/index.d.ts.map +1 -1
  121. package/lib/chain/opPools/index.js +1 -0
  122. package/lib/chain/opPools/index.js.map +1 -1
  123. package/lib/chain/opPools/payloadAttestationPool.js +3 -3
  124. package/lib/chain/opPools/payloadAttestationPool.js.map +1 -1
  125. package/lib/chain/opPools/syncCommitteeMessagePool.js +1 -1
  126. package/lib/chain/opPools/syncCommitteeMessagePool.js.map +1 -1
  127. package/lib/chain/opPools/syncContributionAndProofPool.js +1 -1
  128. package/lib/chain/opPools/syncContributionAndProofPool.js.map +1 -1
  129. package/lib/chain/opPools/utils.d.ts +1 -1
  130. package/lib/chain/opPools/utils.d.ts.map +1 -1
  131. package/lib/chain/opPools/utils.js +1 -1
  132. package/lib/chain/opPools/utils.js.map +1 -1
  133. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  134. package/lib/chain/prepareNextSlot.js +24 -6
  135. package/lib/chain/prepareNextSlot.js.map +1 -1
  136. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  137. package/lib/chain/produceBlock/computeNewStateRoot.js +3 -25
  138. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  139. package/lib/chain/produceBlock/produceBlockBody.js +1 -1
  140. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  141. package/lib/chain/regen/interface.d.ts +5 -2
  142. package/lib/chain/regen/interface.d.ts.map +1 -1
  143. package/lib/chain/regen/interface.js +3 -0
  144. package/lib/chain/regen/interface.js.map +1 -1
  145. package/lib/chain/regen/queued.d.ts +2 -2
  146. package/lib/chain/regen/queued.d.ts.map +1 -1
  147. package/lib/chain/regen/queued.js +5 -5
  148. package/lib/chain/regen/queued.js.map +1 -1
  149. package/lib/chain/seenCache/seenAttesters.d.ts +9 -5
  150. package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
  151. package/lib/chain/seenCache/seenAttesters.js +25 -4
  152. package/lib/chain/seenCache/seenAttesters.js.map +1 -1
  153. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +28 -1
  154. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  155. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +121 -13
  156. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  157. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +5 -1
  158. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  159. package/lib/chain/stateCache/fifoBlockStateCache.js +6 -0
  160. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  161. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +47 -5
  162. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  163. package/lib/chain/stateCache/persistentCheckpointsCache.js +117 -7
  164. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  165. package/lib/chain/stateCache/types.d.ts +3 -3
  166. package/lib/chain/stateCache/types.d.ts.map +1 -1
  167. package/lib/chain/validation/attestation.d.ts.map +1 -1
  168. package/lib/chain/validation/attestation.js +1 -4
  169. package/lib/chain/validation/attestation.js.map +1 -1
  170. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  171. package/lib/chain/validation/attesterSlashing.js +1 -1
  172. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  173. package/lib/chain/validation/block.d.ts.map +1 -1
  174. package/lib/chain/validation/block.js +40 -10
  175. package/lib/chain/validation/block.js.map +1 -1
  176. package/lib/chain/validation/executionPayloadBid.d.ts +13 -3
  177. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  178. package/lib/chain/validation/executionPayloadBid.js +147 -12
  179. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  180. package/lib/chain/validation/executionPayloadEnvelope.js +1 -1
  181. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  182. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  183. package/lib/chain/validation/payloadAttestationMessage.js +5 -14
  184. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  185. package/lib/chain/validation/proposerPreferences.d.ts +1 -1
  186. package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
  187. package/lib/chain/validation/proposerPreferences.js +13 -4
  188. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  189. package/lib/chain/validation/proposerSlashing.js +1 -1
  190. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  191. package/lib/chain/validation/voluntaryExit.d.ts +9 -1
  192. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  193. package/lib/chain/validation/voluntaryExit.js +46 -1
  194. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  195. package/lib/execution/builder/apiClient.d.ts +64 -0
  196. package/lib/execution/builder/apiClient.d.ts.map +1 -0
  197. package/lib/execution/builder/apiClient.js +184 -0
  198. package/lib/execution/builder/apiClient.js.map +1 -0
  199. package/lib/execution/builder/validateBid.d.ts +22 -0
  200. package/lib/execution/builder/validateBid.d.ts.map +1 -0
  201. package/lib/execution/builder/validateBid.js +111 -0
  202. package/lib/execution/builder/validateBid.js.map +1 -0
  203. package/lib/metrics/metrics/lodestar.d.ts +91 -23
  204. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  205. package/lib/metrics/metrics/lodestar.js +172 -55
  206. package/lib/metrics/metrics/lodestar.js.map +1 -1
  207. package/lib/network/gossip/topic.d.ts +13 -0
  208. package/lib/network/gossip/topic.d.ts.map +1 -1
  209. package/lib/network/gossip/topic.js +37 -0
  210. package/lib/network/gossip/topic.js.map +1 -1
  211. package/lib/network/libp2p/index.d.ts.map +1 -1
  212. package/lib/network/libp2p/index.js +10 -2
  213. package/lib/network/libp2p/index.js.map +1 -1
  214. package/lib/network/network.d.ts.map +1 -1
  215. package/lib/network/network.js +23 -43
  216. package/lib/network/network.js.map +1 -1
  217. package/lib/network/processor/constants.d.ts +7 -0
  218. package/lib/network/processor/constants.d.ts.map +1 -0
  219. package/lib/network/processor/constants.js +7 -0
  220. package/lib/network/processor/constants.js.map +1 -0
  221. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  222. package/lib/network/processor/gossipHandlers.js +13 -4
  223. package/lib/network/processor/gossipHandlers.js.map +1 -1
  224. package/lib/network/processor/gossipQueues/indexed.d.ts.map +1 -1
  225. package/lib/network/processor/gossipQueues/indexed.js +0 -1
  226. package/lib/network/processor/gossipQueues/indexed.js.map +1 -1
  227. package/lib/network/processor/index.d.ts +3 -0
  228. package/lib/network/processor/index.d.ts.map +1 -1
  229. package/lib/network/processor/index.js +52 -23
  230. package/lib/network/processor/index.js.map +1 -1
  231. package/lib/network/reqresp/score.d.ts.map +1 -1
  232. package/lib/network/reqresp/score.js +5 -11
  233. package/lib/network/reqresp/score.js.map +1 -1
  234. package/lib/network/util.d.ts +0 -1
  235. package/lib/network/util.d.ts.map +1 -1
  236. package/lib/network/util.js +0 -4
  237. package/lib/network/util.js.map +1 -1
  238. package/lib/node/deferredVoluntaryExitPublisher.d.ts +15 -0
  239. package/lib/node/deferredVoluntaryExitPublisher.d.ts.map +1 -0
  240. package/lib/node/deferredVoluntaryExitPublisher.js +38 -0
  241. package/lib/node/deferredVoluntaryExitPublisher.js.map +1 -0
  242. package/lib/node/nodejs.d.ts +2 -1
  243. package/lib/node/nodejs.d.ts.map +1 -1
  244. package/lib/node/nodejs.js +7 -0
  245. package/lib/node/nodejs.js.map +1 -1
  246. package/lib/sync/range/batch.d.ts +23 -5
  247. package/lib/sync/range/batch.d.ts.map +1 -1
  248. package/lib/sync/range/batch.js +61 -22
  249. package/lib/sync/range/batch.js.map +1 -1
  250. package/lib/sync/range/chain.d.ts +2 -1
  251. package/lib/sync/range/chain.d.ts.map +1 -1
  252. package/lib/sync/range/chain.js +32 -12
  253. package/lib/sync/range/chain.js.map +1 -1
  254. package/lib/sync/range/range.js +1 -1
  255. package/lib/sync/range/range.js.map +1 -1
  256. package/lib/sync/types.d.ts +32 -0
  257. package/lib/sync/types.d.ts.map +1 -1
  258. package/lib/sync/types.js +33 -0
  259. package/lib/sync/types.js.map +1 -1
  260. package/lib/sync/unknownBlock.d.ts +15 -2
  261. package/lib/sync/unknownBlock.d.ts.map +1 -1
  262. package/lib/sync/unknownBlock.js +220 -61
  263. package/lib/sync/unknownBlock.js.map +1 -1
  264. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  265. package/lib/sync/utils/downloadByRange.js +16 -11
  266. package/lib/sync/utils/downloadByRange.js.map +1 -1
  267. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  268. package/lib/sync/utils/downloadByRoot.js +3 -1
  269. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  270. package/package.json +35 -35
  271. package/src/api/impl/beacon/blocks/index.ts +55 -21
  272. package/src/api/impl/beacon/pool/index.ts +27 -2
  273. package/src/api/impl/beacon/state/utils.ts +2 -1
  274. package/src/api/impl/events/index.ts +12 -4
  275. package/src/api/impl/lodestar/index.ts +1 -1
  276. package/src/api/impl/validator/index.ts +285 -49
  277. package/src/api/impl/validator/utils.ts +1 -1
  278. package/src/api/rest/base.ts +7 -0
  279. package/src/chain/archiveStore/archiveStore.ts +1 -1
  280. package/src/chain/archiveStore/historicalState/metrics.ts +22 -0
  281. package/src/chain/blocks/importBlock.ts +1 -6
  282. package/src/chain/blocks/importExecutionPayload.ts +12 -11
  283. package/src/chain/blocks/index.ts +25 -13
  284. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +8 -2
  285. package/src/chain/blocks/payloadEnvelopeInput/types.ts +17 -4
  286. package/src/chain/blocks/verifyBlock.ts +5 -2
  287. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +25 -16
  288. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +1 -9
  289. package/src/chain/bls/index.ts +1 -1
  290. package/src/chain/bls/interface.ts +7 -3
  291. package/src/chain/bls/multithread/index.ts +148 -120
  292. package/src/chain/bls/multithread/jobItem.ts +12 -82
  293. package/src/chain/bls/multithread/types.ts +33 -8
  294. package/src/chain/bls/multithread/utils.ts +11 -0
  295. package/src/chain/bls/multithread/worker.ts +85 -27
  296. package/src/chain/bls/singleThread.ts +11 -55
  297. package/src/chain/bls/utils.ts +23 -24
  298. package/src/chain/chain.ts +25 -7
  299. package/src/chain/errors/blockError.ts +8 -2
  300. package/src/chain/errors/proposerPreferences.ts +7 -0
  301. package/src/chain/forkChoice/index.ts +4 -0
  302. package/src/chain/interface.ts +8 -3
  303. package/src/chain/opPools/aggregatedAttestationPool.ts +1 -1
  304. package/src/chain/opPools/attestationPool.ts +1 -1
  305. package/src/chain/opPools/deferredVoluntaryExitPool.ts +65 -0
  306. package/src/chain/opPools/executionPayloadBidPool.ts +13 -7
  307. package/src/chain/opPools/index.ts +2 -1
  308. package/src/chain/opPools/payloadAttestationPool.ts +3 -3
  309. package/src/chain/opPools/syncCommitteeMessagePool.ts +1 -1
  310. package/src/chain/opPools/syncContributionAndProofPool.ts +1 -1
  311. package/src/chain/opPools/utils.ts +1 -1
  312. package/src/chain/prepareNextSlot.ts +24 -6
  313. package/src/chain/produceBlock/computeNewStateRoot.ts +3 -38
  314. package/src/chain/produceBlock/produceBlockBody.ts +1 -1
  315. package/src/chain/regen/interface.ts +5 -2
  316. package/src/chain/regen/queued.ts +5 -5
  317. package/src/chain/seenCache/seenAttesters.ts +31 -5
  318. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +143 -14
  319. package/src/chain/stateCache/fifoBlockStateCache.ts +8 -1
  320. package/src/chain/stateCache/persistentCheckpointsCache.ts +133 -8
  321. package/src/chain/stateCache/types.ts +3 -3
  322. package/src/chain/validation/attestation.ts +1 -7
  323. package/src/chain/validation/attesterSlashing.ts +1 -8
  324. package/src/chain/validation/block.ts +43 -10
  325. package/src/chain/validation/executionPayloadBid.ts +168 -14
  326. package/src/chain/validation/executionPayloadEnvelope.ts +0 -1
  327. package/src/chain/validation/payloadAttestationMessage.ts +6 -17
  328. package/src/chain/validation/proposerPreferences.ts +15 -5
  329. package/src/chain/validation/proposerSlashing.ts +1 -1
  330. package/src/chain/validation/voluntaryExit.ts +59 -2
  331. package/src/execution/builder/apiClient.ts +244 -0
  332. package/src/execution/builder/validateBid.ts +166 -0
  333. package/src/metrics/metrics/lodestar.ts +187 -61
  334. package/src/network/gossip/topic.ts +38 -0
  335. package/src/network/libp2p/index.ts +11 -2
  336. package/src/network/network.ts +29 -54
  337. package/src/network/processor/constants.ts +6 -0
  338. package/src/network/processor/gossipHandlers.ts +15 -2
  339. package/src/network/processor/gossipQueues/indexed.ts +0 -1
  340. package/src/network/processor/index.ts +67 -30
  341. package/src/network/reqresp/score.ts +5 -11
  342. package/src/network/util.ts +0 -5
  343. package/src/node/deferredVoluntaryExitPublisher.ts +54 -0
  344. package/src/node/nodejs.ts +10 -1
  345. package/src/sync/range/batch.ts +83 -28
  346. package/src/sync/range/chain.ts +35 -13
  347. package/src/sync/range/range.ts +1 -1
  348. package/src/sync/types.ts +36 -1
  349. package/src/sync/unknownBlock.ts +258 -68
  350. package/src/sync/utils/downloadByRange.ts +21 -12
  351. package/src/sync/utils/downloadByRoot.ts +3 -1
  352. package/lib/chain/bls/maybeBatch.d.ts +0 -12
  353. package/lib/chain/bls/maybeBatch.d.ts.map +0 -1
  354. package/lib/chain/bls/maybeBatch.js +0 -35
  355. package/lib/chain/bls/maybeBatch.js.map +0 -1
  356. package/src/chain/bls/maybeBatch.ts +0 -45
@@ -144,13 +144,20 @@ export class FIFOBlockStateCache implements BlockStateCache {
144
144
  return this.cache.size;
145
145
  }
146
146
 
147
+ /**
148
+ * On a checkpoint event, prune the cache while keeping the head state.
149
+ */
150
+ onCheckpoint(headStateRootHex: string): void {
151
+ this.prune(headStateRootHex);
152
+ }
153
+
147
154
  /**
148
155
  * Prune the cache from tail to keep the most recent n states consistently.
149
156
  * The tail of the list is the oldest state, in case regen adds back the same state,
150
157
  * it should stay next to head so that it won't be pruned right away.
151
158
  * The FIFO cache helps with this.
152
159
  */
153
- prune(lastAddedKey: string): void {
160
+ private prune(lastAddedKey: string): void {
154
161
  while (this.keyOrder.length > this.maxStates) {
155
162
  const key = this.keyOrder.last();
156
163
  // it does not make sense to prune the last added state
@@ -14,7 +14,11 @@ import {BlockStateCache, CacheItemType, CheckpointHex, CheckpointStateCache} fro
14
14
  export type PersistentCheckpointStateCacheOpts = {
15
15
  /** Keep max n state epochs in memory, persist the rest to disk */
16
16
  maxCPStateEpochsInMemory?: number;
17
- /** Keep max n state epochs on disk */
17
+ /**
18
+ * On-disk retention of persisted checkpoint states. Selects one of two modes:
19
+ * - `Infinity` (default) -> tiered retention mode
20
+ * - any finite `n` (>= 0) -> legacy flat retention (keep the last n dense epochs)
21
+ */
18
22
  maxCPStateEpochsOnDisk?: number;
19
23
  };
20
24
 
@@ -64,6 +68,18 @@ export const DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY = 3;
64
68
  */
65
69
  export const DEFAULT_MAX_CP_STATE_ON_DISK = Infinity;
66
70
 
71
+ // CP_STATE_TIER_BASE = spacing multiplier per tier AND per-tier capacity. Deciding capacity == base
72
+ // so that a full tier[n] always holds exactly ONE epoch aligned to tier[n+1]
73
+ // given tier[n] has span = 16 ^ n and tier[n+1] has span = 16 ^ (n+1)
74
+ // why 16?
75
+ // - tier 0 is the dense hot-regen window; it must exceed regen's MAX_EPOCH_TO_PROCESS (=5).
76
+ // - with a full 4 tiers = 64 epochs, we can cover ~ a year of continuous non-finality, and it'll grow very slowly after that
77
+ // - tier0 spans 16 epochs ≈ 1.7h, this is more than enough to handle reorg
78
+ // - tier1 spans 256 epochs ≈ 1.1d, ie we store 16 epochs of the previous day
79
+ // - tier2 spans 4096 epochs ≈ 18d, ie we store 16 epochs of the last ~2.5 weeks
80
+ // - tier3 spans 65536ep ≈ 291d, ie we store 16 epochs of the last 0.8 year
81
+ export const CP_STATE_TIER_BASE = 16;
82
+
67
83
  // TODO GLOAS: re-evaluate this timing
68
84
  const PROCESS_CHECKPOINT_STATES_BPS = 6667;
69
85
 
@@ -112,6 +128,19 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
112
128
  private preComputedCheckpointHits: number | null = null;
113
129
  private readonly maxEpochsInMemory: number;
114
130
  private readonly maxEpochsOnDisk: number;
131
+ /**
132
+ * Persist checkpoint states (epoch + root) by tiers
133
+ *
134
+ * ╔═════════ tier 2 ══════════╦═══════ tier 1 ═══════╦═══ tier 0 (dense) ══╗
135
+ * finalizedEpoch -> ║ keep 1 epoch per 256 ║ keep 1 epoch per 16 ║ keep every epoch ║ -> head
136
+ * ║ x·······x·······x······ ║ x···x···x···x··· ║ xxxxxxxxxxxxxxxxx ║
137
+ * ╚═══════════════════════════╩══════════════════════╩═════════════════════╝
138
+ *
139
+ * starting from tier 1, all epochs must be aligned to the finalized epoch
140
+ */
141
+ private persistentTiers: Map<Epoch, Set<RootHex>>[] = [new Map()];
142
+ private finalizedEpoch: Epoch = 0;
143
+ private justifiedEpoch: Epoch = 0;
115
144
  private readonly datastore: CPStateDatastore;
116
145
  private readonly blockStateCache: BlockStateCache;
117
146
  private readonly bufferPool?: BufferPool;
@@ -152,6 +181,13 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
152
181
  metrics.cpStateCache.size.set({type: CacheItemType.inMemory}, inMemoryCount);
153
182
  metrics.cpStateCache.epochSize.set({type: CacheItemType.persisted}, persistentEpochs.size);
154
183
  metrics.cpStateCache.epochSize.set({type: CacheItemType.inMemory}, memoryEpochs.size);
184
+
185
+ for (let tier = 0; tier < this.persistentTiers.length; tier++) {
186
+ let states = 0;
187
+ for (const roots of this.persistentTiers[tier].values()) states += roots.size;
188
+ metrics.cpStateCache.persistentTierEpochs.set({tier}, this.persistentTiers[tier].size);
189
+ metrics.cpStateCache.persistentTierStates.set({tier}, states);
190
+ }
155
191
  });
156
192
  }
157
193
  this.logger = logger;
@@ -407,10 +443,77 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
407
443
  }
408
444
 
409
445
  /**
410
- * This is just to conform to the old implementation
446
+ * This is called on every checkpoint event to refresh the pinned finalized/justified epochs.
411
447
  */
412
- prune(): void {
413
- // do nothing
448
+ onCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void {
449
+ this.finalizedEpoch = finalizedEpoch;
450
+ this.justifiedEpoch = justifiedEpoch;
451
+ }
452
+
453
+ /**
454
+ * This is called right after we persist a checkpoint state.
455
+ */
456
+ private async onPersist(epoch: Epoch, rootHex: RootHex): Promise<void> {
457
+ let roots = this.persistentTiers[0].get(epoch);
458
+ if (roots === undefined) {
459
+ roots = new Set<RootHex>();
460
+ this.persistentTiers[0].set(epoch, roots);
461
+ }
462
+ roots.add(rootHex);
463
+ await this.prunePersistentTier(0);
464
+ }
465
+
466
+ /**
467
+ * When tier `n` overflows (> CP_STATE_TIER_BASE epochs), evict its oldest epoch and either promote it to tier `n + 1` (if aligned there) or delete it.
468
+ *
469
+ * before: persistentTiers[n] = { ..., e_old }
470
+ * persistentTiers[n+1] = { ... }
471
+ *
472
+ * after, if e_old aligns to n+1: | after, if e_old does NOT align to n+1:
473
+ * persistentTiers[n] = { ... } | persistentTiers[n] = { ... }
474
+ * persistentTiers[n+1] = { ..., e_old } | e_old and all its roots deleted from disk
475
+ *
476
+ * Since pruning a tier[n] may push an item at tier[n+1], we must call the function recursively.
477
+ */
478
+ private async prunePersistentTier(tier: number): Promise<void> {
479
+ const tierMap = this.persistentTiers[tier];
480
+ while (tierMap.size > CP_STATE_TIER_BASE) {
481
+ // Evict the oldest epoch, but never the pinned justified epoch
482
+ const oldestEpoch = Math.min(...Array.from(tierMap.keys()).filter((epoch) => epoch !== this.justifiedEpoch));
483
+ const roots = tierMap.get(oldestEpoch) as Set<RootHex>;
484
+ tierMap.delete(oldestEpoch);
485
+
486
+ const rootHexes = Array.from(roots).join(",");
487
+ // `>= finalizedEpoch` guards the transient window where an epoch below the (fork-choice)
488
+ // finalized epoch has not yet been removed by pruneFinalized: its offset would be negative
489
+ // and JS `%` could spuriously report it as aligned. Such epochs are stale -> delete.
490
+ if (oldestEpoch >= this.finalizedEpoch && this.alignedForTier(oldestEpoch, tier + 1)) {
491
+ if (this.persistentTiers[tier + 1] === undefined) {
492
+ this.persistentTiers[tier + 1] = new Map<Epoch, Set<RootHex>>();
493
+ }
494
+ this.persistentTiers[tier + 1].set(oldestEpoch, roots);
495
+ this.logger.verbose("Migrated persistent checkpoint states to lower tier", {
496
+ epoch: oldestEpoch,
497
+ fromTier: tier,
498
+ toTier: tier + 1,
499
+ rootHexes,
500
+ });
501
+ await this.prunePersistentTier(tier + 1);
502
+ } else {
503
+ // the oldest epoch is not aligned to the next tier
504
+ await this.deleteAllEpochItems(oldestEpoch)
505
+ .then(() => this.logger.verbose("Pruned checkpoint states from disk", {epoch: oldestEpoch, tier, rootHexes}))
506
+ .catch((e) => this.logger.debug("Error delete all epoch items", {epoch: oldestEpoch, tier}, e as Error));
507
+ }
508
+ }
509
+ }
510
+
511
+ /**
512
+ * Starting from tier[1], it must be aligned to the finalized epoch
513
+ * ie given finalized epoch F, tier[n] only epochs of F + n*16, n = 1,2,3...
514
+ */
515
+ private alignedForTier(epoch: Epoch, tier: number): boolean {
516
+ return (epoch - this.finalizedEpoch) % CP_STATE_TIER_BASE ** tier === 0;
414
517
  }
415
518
 
416
519
  /**
@@ -598,9 +701,16 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
598
701
  return seedBlockState;
599
702
  }
600
703
 
601
- clear(): void {
602
- this.cache.clear();
603
- this.epochIndex.clear();
704
+ async clear(): Promise<void> {
705
+ // deleteAllEpochItems removes every root of an epoch from disk and clears the cache
706
+ await Promise.all(
707
+ Array.from(this.epochIndex.keys()).map((epoch) =>
708
+ this.deleteAllEpochItems(epoch).catch((e) =>
709
+ this.logger.debug("Error delete all epoch items on clear", {epoch}, e as Error)
710
+ )
711
+ )
712
+ );
713
+ this.persistentTiers = [new Map()];
604
714
  }
605
715
 
606
716
  /** ONLY FOR DEBUGGING PURPOSES. For lodestar debug API */
@@ -743,12 +853,18 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
743
853
  }
744
854
  // overwrite cpKey, this means the state is deleted from memory
745
855
  this.cache.set(cpKey, {type: CacheItemType.persisted, value: persistedKey});
856
+ if (this.isTieredMode) {
857
+ await this.onPersist(epoch, rootHex);
858
+ }
746
859
  } else {
747
860
  if (persistedKey) {
748
861
  // persisted file will be eventually deleted by the archive task
749
862
  // this also means the state is deleted from memory
750
863
  this.cache.set(cpKey, {type: CacheItemType.persisted, value: persistedKey});
751
864
  // do not update epochIndex
865
+ if (this.isTieredMode) {
866
+ await this.onPersist(epoch, rootHex);
867
+ }
752
868
  } else {
753
869
  // delete the state from memory
754
870
  this.cache.delete(cpKey);
@@ -790,6 +906,10 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
790
906
  this.cache.delete(key);
791
907
  }
792
908
  this.epochIndex.delete(epoch);
909
+ // keep the on-disk retention tiers in sync so they never drift from epochIndex
910
+ for (const tierMap of this.persistentTiers) {
911
+ tierMap.delete(epoch);
912
+ }
793
913
  this.logger.verbose("Pruned checkpoint states for epoch", {
794
914
  epoch,
795
915
  persistCount,
@@ -798,7 +918,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
798
918
  }
799
919
 
800
920
  /**
801
- * Prune persisted checkpoint states from disk.
921
+ * Legacy flat-window on-disk pruning, used only when a `maxEpochsOnDisk` is configured.
802
922
  * Note that this should handle all possible errors and not throw.
803
923
  */
804
924
  private prunePersistedStates(): void {
@@ -842,6 +962,11 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
842
962
 
843
963
  return null;
844
964
  }
965
+
966
+ /** Tiered pruning is active with the default `Infinity` on-disk cap; a finite cap uses the flat path */
967
+ private get isTieredMode(): boolean {
968
+ return this.maxEpochsOnDisk === Infinity;
969
+ }
845
970
  }
846
971
 
847
972
  export function toCheckpointHex(checkpoint: phase0.Checkpoint): CheckpointHex {
@@ -29,7 +29,7 @@ export interface BlockStateCache {
29
29
  getSeedState(): IBeaconStateView;
30
30
  clear(): void;
31
31
  size: number;
32
- prune(headStateRootHex: RootHex): void;
32
+ onCheckpoint(headStateRootHex: RootHex): void;
33
33
  dumpSummary(): routes.lodestar.StateCacheItem[];
34
34
  /** Expose beacon states stored in cache. Use with caution */
35
35
  getStates(): IterableIterator<IBeaconStateView>;
@@ -65,9 +65,9 @@ export interface CheckpointStateCache {
65
65
  getLatest(rootHex: RootHex, maxEpoch: Epoch): IBeaconStateView | null;
66
66
  getOrReloadLatest(rootHex: RootHex, maxEpoch: Epoch): Promise<IBeaconStateView | null>;
67
67
  updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null;
68
- prune(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void;
68
+ onCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void;
69
69
  processState(blockRootHex: RootHex, state: IBeaconStateView): Promise<number>;
70
- clear(): void;
70
+ clear(): Promise<void>;
71
71
  dumpSummary(): routes.lodestar.StateCacheItem[];
72
72
  /** Expose beacon states stored in cache. Use with caution */
73
73
  getStates(): IterableIterator<IBeaconStateView>;
@@ -142,13 +142,7 @@ export async function validateGossipAttestationsSameAttData(
142
142
  const batchableBls = signatureSets.length >= chain.opts.minSameMessageSignatureSetsToBatch;
143
143
  if (batchableBls) {
144
144
  // all signature sets should have same signing root since we filtered in network processor
145
- signatureValids = await chain.bls.verifySignatureSetsSameMessage(
146
- signatureSets.map((set) => {
147
- const publicKey = chain.pubkeyCache.getOrThrow(set.index);
148
- return {publicKey, signature: set.signature};
149
- }),
150
- signatureSets[0].signingRoot
151
- );
145
+ signatureValids = await chain.bls.verifySignatureSetsSameMessage(signatureSets, signatureSets[0].signingRoot);
152
146
  } else {
153
147
  // don't want to block the main thread if there are too few signatures
154
148
  signatureValids = await Promise.all(
@@ -44,14 +44,7 @@ export async function validateAttesterSlashing(
44
44
  // [REJECT] All of the conditions within process_attester_slashing pass validation.
45
45
  try {
46
46
  // verifySignature = false, verified in batch below
47
- assertValidAttesterSlashing(
48
- chain.config,
49
- chain.pubkeyCache,
50
- state.slot,
51
- state.validatorCount,
52
- attesterSlashing,
53
- false
54
- );
47
+ assertValidAttesterSlashing(chain.config, state.slot, state.validatorCount, attesterSlashing, false);
55
48
  } catch (e) {
56
49
  throw new AttesterSlashingError(GossipAction.REJECT, {
57
50
  code: AttesterSlashingErrorCode.INVALID,
@@ -12,6 +12,7 @@ import {
12
12
  MAX_PROPOSER_SLASHINGS,
13
13
  MAX_VOLUNTARY_EXITS,
14
14
  MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD,
15
+ MIN_SEED_LOOKAHEAD,
15
16
  isForkPostBellatrix,
16
17
  isForkPostDeneb,
17
18
  isForkPostGloas,
@@ -249,26 +250,58 @@ export async function validateGossipBlock(
249
250
  // This requires execution engine integration to verify the parent block hash
250
251
  }
251
252
 
252
- // use getPreState to reload state if needed. It also checks for whether the current finalized checkpoint is an ancestor of the block.
253
- // As a result, we throw an IGNORE (whereas the spec says we should REJECT for this scenario).
253
+ // For gossip forwarding we only need the state to check the block's proposer index.
254
+ // If the state cannot be regenerated we throw an IGNORE (whereas the spec says we should REJECT for the
255
+ // finalized-ancestor scenario, which is already guarded by the parentBlock lookup above).
254
256
  // this is something we should change this in the future to make the code airtight to the spec.
255
257
  // [IGNORE] The block's parent (defined by block.parent_root) has been seen (via both gossip and non-gossip sources) (a client MAY queue blocks for processing once the parent block is retrieved).
256
258
  // [REJECT] The block's parent (defined by block.parent_root) passes validation.
257
- const blockState = await chain.regen
258
- .getPreState(block, {dontTransferCache: true}, RegenCaller.validateGossipBlock)
259
- .catch(() => {
260
- throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.PARENT_BLOCK_UNKNOWN, parentRoot});
259
+ const canUseParentState = blockEpoch - computeEpochAtSlot(parentBlock.slot) <= MIN_SEED_LOOKAHEAD;
260
+
261
+ const getValidationState = async () => {
262
+ const getPreState = () =>
263
+ chain.regen.getPreState(block, {dontTransferCache: true}, RegenCaller.validateGossipBlock);
264
+ if (canUseParentState) {
265
+ try {
266
+ const parentState = await chain.regen.getState(parentBlock.stateRoot, RegenCaller.validateGossipBlock);
267
+ chain.metrics?.gossipBlock.preStateSource.inc({source: "parentState"});
268
+ return parentState;
269
+ } catch {
270
+ // if parent state is not in memory, we fall back to disk reload / dial-forward
271
+ chain.metrics?.gossipBlock.preStateSource.inc({source: "fallbackPreState"});
272
+ chain.logger.debug("Parent state not in memory, falling back to getPreState for gossip block validation", {
273
+ slot: blockSlot,
274
+ root: blockRoot,
275
+ parentSlot: parentBlock.slot,
276
+ parentRoot,
277
+ });
278
+ return getPreState();
279
+ }
280
+ }
281
+ // parent is >1 epoch behind (deep skip) → beyond proposer-lookahead range, must dial forward
282
+ chain.metrics?.gossipBlock.preStateSource.inc({source: "preState"});
283
+ chain.logger.debug("Cannot use parent state for gossip block validation, dialing forward via getPreState", {
284
+ slot: blockSlot,
285
+ root: blockRoot,
286
+ parentSlot: parentBlock.slot,
287
+ parentRoot,
261
288
  });
289
+ return getPreState();
290
+ };
291
+
292
+ const state = await getValidationState().catch(() => {
293
+ throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.PARENT_BLOCK_UNKNOWN, parentRoot});
294
+ });
262
295
 
263
296
  // in forky condition, make sure to populate ShufflingCache with regened state
264
- chain.shufflingCache.processState(blockState);
297
+ chain.shufflingCache.processState(state);
265
298
 
266
299
  // [REJECT] The block's execution payload timestamp is correct with respect to the slot
267
300
  // -- i.e. execution_payload.timestamp == compute_timestamp_at_slot(state, block.slot).
268
301
  if (isForkPostBellatrix(fork) && !isForkPostGloas(fork)) {
269
302
  if (!isExecutionBlockBodyType(block.body)) throw Error("Not execution block body type");
270
303
  const executionPayload = block.body.executionPayload;
271
- if (isStatePostBellatrix(blockState) && blockState.isExecutionStateType && blockState.isExecutionEnabled(block)) {
304
+ if (isStatePostBellatrix(state) && state.isExecutionStateType && state.isExecutionEnabled(block)) {
272
305
  const expectedTimestamp = computeTimeAtSlot(config, blockSlot, chain.genesisTime);
273
306
  if (executionPayload.timestamp !== computeTimeAtSlot(config, blockSlot, chain.genesisTime)) {
274
307
  throw new BlockGossipError(GossipAction.REJECT, {
@@ -281,7 +314,7 @@ export async function validateGossipBlock(
281
314
  }
282
315
 
283
316
  // [REJECT] The proposer index is a valid validator index
284
- if (proposerIndex >= blockState.validatorCount) {
317
+ if (proposerIndex >= state.validatorCount) {
285
318
  throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.UNKNOWN_PROPOSER, proposerIndex});
286
319
  }
287
320
 
@@ -293,7 +326,7 @@ export async function validateGossipBlock(
293
326
  // shuffling (defined by parent_root/slot). If the proposer_index cannot immediately be verified against the expected
294
327
  // shuffling, the block MAY be queued for later processing while proposers for the block's branch are calculated --
295
328
  // in such a case do not REJECT, instead IGNORE this message.
296
- if (blockState.getBeaconProposer(blockSlot) !== proposerIndex) {
329
+ if (state.getBeaconProposer(blockSlot) !== proposerIndex) {
297
330
  throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.INCORRECT_PROPOSER, proposerIndex});
298
331
  }
299
332
 
@@ -1,5 +1,4 @@
1
- import {PublicKey} from "@chainsafe/blst";
2
- import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
1
+ import {ProtoBlock} from "@lodestar/fork-choice";
3
2
  import {PAYLOAD_BUILDER_VERSION} from "@lodestar/params";
4
3
  import {
5
4
  computeEpochAtSlot,
@@ -47,11 +46,12 @@ function getMinBidValue(currentHighestBid: number): number {
47
46
  /**
48
47
  * Check whether a bid builds on one of the paths compatible with the local head branch.
49
48
  *
50
- * Building directly on the parent is allowed for proposer-boost reorgs outside epoch boundaries.
49
+ * Building directly on the parent is allowed for proposer-boost reorgs, including at epoch
50
+ * boundaries when the head is weak enough that a reorg onto the strong parent is predicted.
51
51
  * Otherwise the bid must build on the local head's full or empty payload variant, as selected for its slot.
52
52
  */
53
53
  function isBidCompatibleWithHead(
54
- forkChoice: IForkChoice,
54
+ chain: IBeaconChain,
55
55
  head: ProtoBlock,
56
56
  bidSlot: Slot,
57
57
  bidParentBlockRoot: RootHex,
@@ -61,9 +61,13 @@ function isBidCompatibleWithHead(
61
61
  const buildsOnParentPayload = bidParentBlockHash === head.parentBlockHash;
62
62
 
63
63
  if (buildsOnParentBlock && buildsOnParentPayload) {
64
- // The spec allows this at epoch boundaries, but Lodestar does not propagate these bids because validating
65
- // them requires an epoch transition for a parent state that cannot be used for proposer-boost reorgs.
66
- return !isStartSlotOfEpoch(bidSlot);
64
+ if (!isStartSlotOfEpoch(bidSlot)) {
65
+ return true;
66
+ }
67
+ // Epoch-boundary reorgs are allowed, but only propagate the bid if its parent matches the block
68
+ // we predict a proposer would reorg onto — predictProposerHead returns the strong parent only
69
+ // when the head is weak.
70
+ return chain.predictProposerHead().blockRoot === bidParentBlockRoot;
67
71
  }
68
72
 
69
73
  if (bidParentBlockRoot !== head.blockRoot) {
@@ -72,18 +76,168 @@ function isBidCompatibleWithHead(
72
76
 
73
77
  const buildsOnHeadPayload = bidParentBlockHash === head.executionPayloadBlockHash;
74
78
 
75
- if (forkChoice.shouldBuildOnFull(head, bidSlot)) {
79
+ if (chain.forkChoice.shouldBuildOnFull(head, bidSlot)) {
76
80
  return buildsOnHeadPayload;
77
81
  }
78
82
 
79
83
  return buildsOnParentPayload;
80
84
  }
81
85
 
86
+ /**
87
+ * Validation for bids submitted via the API by the operator's own builder.
88
+ *
89
+ * Only non-transient checks are applied: slot later than parent, zero execution payment, blob
90
+ * commitment count, builder eligibility, version and balance coverage, prev_randao, and signature.
91
+ * Transient gossip rules (head compatibility, first bid per tuple, value increment, proposer
92
+ * preferences) are not applied, since those only limit forwarding of peers' messages and the
93
+ * builder may legitimately bid on a branch this node does not consider head.
94
+ *
95
+ * Throws on any failed check. Also throws if the bid's parent block is unknown or its state is
96
+ * unavailable, since the checks cannot be evaluated against the parent branch.
97
+ */
82
98
  export async function validateApiExecutionPayloadBid(
83
99
  chain: IBeaconChain,
84
100
  signedExecutionPayloadBid: gloas.SignedExecutionPayloadBid
85
- ): Promise<{proposerIndex: ValidatorIndex}> {
86
- return validateExecutionPayloadBid(chain, signedExecutionPayloadBid);
101
+ ): Promise<void> {
102
+ const bid = signedExecutionPayloadBid.message;
103
+ const bidParentBlockRoot = toRootHex(bid.parentBlockRoot);
104
+
105
+ // [IGNORE] `bid.slot` is the current slot, or the next slot (`bid.slot - 1` is current), allowing for `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
106
+ if (
107
+ !chain.clock.isCurrentSlotGivenGossipDisparity(bid.slot) &&
108
+ !chain.clock.isCurrentSlotGivenGossipDisparity(bid.slot - 1)
109
+ ) {
110
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
111
+ code: ExecutionPayloadBidErrorCode.INVALID_SLOT,
112
+ builderIndex: bid.builderIndex,
113
+ slot: bid.slot,
114
+ });
115
+ }
116
+
117
+ // [IGNORE] `bid.parent_block_root` is the hash tree root of a known beacon block in fork choice.
118
+ // Moved earlier than the spec ordering so we can derive the proposer dependent root for the
119
+ // proposer-preferences lookup below from a known fork-choice block.
120
+ const parentBlock = chain.forkChoice.getBlockHexDefaultStatus(bidParentBlockRoot);
121
+ if (parentBlock === null) {
122
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
123
+ code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT,
124
+ parentBlockRoot: bidParentBlockRoot,
125
+ });
126
+ }
127
+
128
+ // [REJECT] The bid is for a higher slot than its parent block -- i.e.
129
+ // validate that `bid.slot` is greater than the slot of the block with root
130
+ // `bid.parent_block_root`.
131
+ if (bid.slot <= parentBlock.slot) {
132
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
133
+ code: ExecutionPayloadBidErrorCode.NOT_LATER_THAN_PARENT,
134
+ parentSlot: parentBlock.slot,
135
+ slot: bid.slot,
136
+ });
137
+ }
138
+
139
+ // [REJECT] `bid.execution_payment` is zero.
140
+ if (bid.executionPayment !== 0n) {
141
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
142
+ code: ExecutionPayloadBidErrorCode.NON_ZERO_EXECUTION_PAYMENT,
143
+ builderIndex: bid.builderIndex,
144
+ executionPayment: bid.executionPayment,
145
+ });
146
+ }
147
+
148
+ // [REJECT] The length of KZG commitments is less than or equal to the limitation defined in the
149
+ // consensus layer -- i.e. validate that
150
+ // `len(bid.blob_kzg_commitments) <= get_blob_parameters(compute_epoch_at_slot(bid.slot)).max_blobs_per_block`.
151
+ const blobKzgCommitmentsLen = bid.blobKzgCommitments.length;
152
+ const maxBlobsPerBlock = chain.config.getMaxBlobsPerBlock(computeEpochAtSlot(bid.slot));
153
+ if (blobKzgCommitmentsLen > maxBlobsPerBlock) {
154
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
155
+ code: ExecutionPayloadBidErrorCode.TOO_MANY_KZG_COMMITMENTS,
156
+ blobKzgCommitmentsLen,
157
+ commitmentLimit: maxBlobsPerBlock,
158
+ });
159
+ }
160
+
161
+ const state = await chain.regen
162
+ .getBlockSlotState(parentBlock, bid.slot, {dontTransferCache: true}, RegenCaller.validateApiExecutionPayloadBid)
163
+ .catch(() => {
164
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
165
+ code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT,
166
+ parentBlockRoot: bidParentBlockRoot,
167
+ });
168
+ });
169
+
170
+ if (!isStatePostGloas(state)) {
171
+ throw new Error(`Expected gloas+ state for execution payload bid validation, got fork=${state.forkName}`);
172
+ }
173
+
174
+ // [REJECT] `bid.builder_index` is within bounds -- i.e. `bid.builder_index < len(state.builders)`.
175
+ // `state.getBuilder` returns a lazy SSZ `getReadonly` view that is not bounds-checked eagerly; an
176
+ // out-of-range index only throws (`LeafNode has no right node`) on deferred field access (e.g. inside
177
+ // `isActiveBuilder`), escaping a try/catch around `getBuilder`. Check the length explicitly instead.
178
+ if (bid.builderIndex >= state.getBuildersLength()) {
179
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
180
+ code: ExecutionPayloadBidErrorCode.BUILDER_NOT_ELIGIBLE,
181
+ builderIndex: bid.builderIndex,
182
+ });
183
+ }
184
+
185
+ // [REJECT] `bid.builder_index` is a valid/active builder index -- i.e.
186
+ // `is_active_builder(state, bid.builder_index)` returns `True`.
187
+ const builder = state.getBuilder(bid.builderIndex);
188
+ if (!isActiveBuilder(builder, state.finalizedCheckpoint.epoch)) {
189
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
190
+ code: ExecutionPayloadBidErrorCode.BUILDER_NOT_ELIGIBLE,
191
+ builderIndex: bid.builderIndex,
192
+ });
193
+ }
194
+
195
+ // [REJECT] The builder version is `PAYLOAD_BUILDER_VERSION` -- i.e.
196
+ // `state.builders[bid.builder_index].version == PAYLOAD_BUILDER_VERSION`.
197
+ if (builder.version !== PAYLOAD_BUILDER_VERSION) {
198
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
199
+ code: ExecutionPayloadBidErrorCode.INVALID_BUILDER_VERSION,
200
+ builderIndex: bid.builderIndex,
201
+ version: builder.version,
202
+ expectedVersion: PAYLOAD_BUILDER_VERSION,
203
+ });
204
+ }
205
+
206
+ // [IGNORE] `bid.value` is less or equal than the builder's excess balance --
207
+ // i.e. `can_builder_cover_bid(state, builder_index, amount)` returns `True`.
208
+ if (!state.canBuilderCoverBid(bid.builderIndex, bid.value)) {
209
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
210
+ code: ExecutionPayloadBidErrorCode.BID_TOO_HIGH,
211
+ bidValue: bid.value,
212
+ builderBalance: builder.balance,
213
+ });
214
+ }
215
+
216
+ // [REJECT] `bid.prev_randao` is the correct RANDAO mix -- i.e. validate that
217
+ // `bid.prev_randao == get_randao_mix(parent_state, get_current_epoch(parent_state))`.
218
+ const randaoMix = state.getRandaoMix(computeEpochAtSlot(state.slot));
219
+ if (!byteArrayEquals(bid.prevRandao, randaoMix)) {
220
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
221
+ code: ExecutionPayloadBidErrorCode.INVALID_PREV_RANDAO,
222
+ builderIndex: bid.builderIndex,
223
+ bidPrevRandao: toHex(bid.prevRandao),
224
+ expectedPrevRandao: toHex(randaoMix),
225
+ });
226
+ }
227
+
228
+ // [REJECT] `signed_execution_payload_bid.signature` is valid with respect to the `bid.builder_index`.
229
+ const signatureSet = createSingleSignatureSetFromComponents(
230
+ builder.pubkey,
231
+ getExecutionPayloadBidSigningRoot(chain.config, bid),
232
+ signedExecutionPayloadBid.signature
233
+ );
234
+ if (!(await chain.bls.verifySignatureSets([signatureSet]))) {
235
+ throw new ExecutionPayloadBidError(GossipAction.REJECT, {
236
+ code: ExecutionPayloadBidErrorCode.INVALID_SIGNATURE,
237
+ builderIndex: bid.builderIndex,
238
+ slot: bid.slot,
239
+ });
240
+ }
87
241
  }
88
242
 
89
243
  export async function validateGossipExecutionPayloadBid(
@@ -115,7 +269,7 @@ async function validateExecutionPayloadBid(
115
269
 
116
270
  // [IGNORE] The bid is compatible with the current head branch.
117
271
  const head = chain.forkChoice.getHead();
118
- if (!isBidCompatibleWithHead(chain.forkChoice, head, bid.slot, bidParentBlockRoot, bidParentBlockHash)) {
272
+ if (!isBidCompatibleWithHead(chain, head, bid.slot, bidParentBlockRoot, bidParentBlockHash)) {
119
273
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
120
274
  code: ExecutionPayloadBidErrorCode.INCOMPATIBLE_WITH_HEAD,
121
275
  slot: bid.slot,
@@ -314,11 +468,11 @@ async function validateExecutionPayloadBid(
314
468
  // increment, see https://github.com/ethereum/consensus-specs/pull/4831. This prevents spam
315
469
  // from builders submitting numerous bids with minimal value increments.
316
470
  const bestBid = chain.executionPayloadBidPool.getBestBid(bid.slot, bidParentBlockHash, bidParentBlockRoot);
317
- if (bestBid !== null && bid.value < getMinBidValue(bestBid.message.value)) {
471
+ if (bestBid !== null && bid.value < getMinBidValue(bestBid.signedBid.message.value)) {
318
472
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
319
473
  code: ExecutionPayloadBidErrorCode.BID_TOO_LOW,
320
474
  bidValue: bid.value,
321
- currentHighestBid: bestBid.message.value,
475
+ currentHighestBid: bestBid.signedBid.message.value,
322
476
  });
323
477
  }
324
478
  // [IGNORE] `bid.value` is less or equal than the builder's excess balance --
@@ -345,7 +499,7 @@ async function validateExecutionPayloadBid(
345
499
 
346
500
  // [REJECT] `signed_execution_payload_bid.signature` is valid with respect to the `bid.builder_index`.
347
501
  const signatureSet = createSingleSignatureSetFromComponents(
348
- PublicKey.fromBytes(builder.pubkey),
502
+ builder.pubkey,
349
503
  getExecutionPayloadBidSigningRoot(chain.config, bid),
350
504
  signedExecutionPayloadBid.signature
351
505
  );
@@ -170,7 +170,6 @@ async function validateExecutionPayloadEnvelope(
170
170
  // by `verify_execution_payload_envelope_signature`.
171
171
  const signatureSet = getExecutionPayloadEnvelopeSignatureSet(
172
172
  chain.config,
173
- chain.pubkeyCache,
174
173
  blockState,
175
174
  executionPayloadEnvelope,
176
175
  payloadInput.proposerIndex