@lodestar/beacon-node 1.41.0 → 1.42.0-dev.04e52d162f

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 (474) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +36 -17
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.js +1 -1
  5. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  6. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  7. package/lib/api/impl/beacon/state/index.js +27 -32
  8. package/lib/api/impl/beacon/state/index.js.map +1 -1
  9. package/lib/api/impl/beacon/state/utils.d.ts +6 -6
  10. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  11. package/lib/api/impl/beacon/state/utils.js +7 -10
  12. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  13. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  14. package/lib/api/impl/lodestar/index.js +4 -6
  15. package/lib/api/impl/lodestar/index.js.map +1 -1
  16. package/lib/api/impl/proof/index.d.ts.map +1 -1
  17. package/lib/api/impl/proof/index.js +2 -6
  18. package/lib/api/impl/proof/index.js.map +1 -1
  19. package/lib/api/impl/validator/index.d.ts.map +1 -1
  20. package/lib/api/impl/validator/index.js +32 -28
  21. package/lib/api/impl/validator/index.js.map +1 -1
  22. package/lib/api/impl/validator/utils.d.ts +2 -2
  23. package/lib/api/impl/validator/utils.d.ts.map +1 -1
  24. package/lib/api/impl/validator/utils.js +3 -3
  25. package/lib/api/impl/validator/utils.js.map +1 -1
  26. package/lib/chain/archiveStore/archiveStore.d.ts +0 -1
  27. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  28. package/lib/chain/archiveStore/archiveStore.js +1 -9
  29. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  30. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +3 -7
  31. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  32. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +8 -26
  33. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  34. package/lib/chain/archiveStore/historicalState/historicalStateRegen.d.ts +2 -2
  35. package/lib/chain/archiveStore/historicalState/historicalStateRegen.d.ts.map +1 -1
  36. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js +1 -0
  37. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js.map +1 -1
  38. package/lib/chain/archiveStore/historicalState/types.d.ts +2 -0
  39. package/lib/chain/archiveStore/historicalState/types.d.ts.map +1 -1
  40. package/lib/chain/archiveStore/historicalState/types.js.map +1 -1
  41. package/lib/chain/archiveStore/historicalState/worker.js +1 -3
  42. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  43. package/lib/chain/archiveStore/interface.d.ts +5 -4
  44. package/lib/chain/archiveStore/interface.d.ts.map +1 -1
  45. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts +4 -4
  46. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
  47. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +4 -1
  48. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
  49. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  50. package/lib/chain/archiveStore/utils/archiveBlocks.js +38 -0
  51. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  52. package/lib/chain/balancesCache.d.ts +2 -2
  53. package/lib/chain/balancesCache.d.ts.map +1 -1
  54. package/lib/chain/balancesCache.js +4 -4
  55. package/lib/chain/balancesCache.js.map +1 -1
  56. package/lib/chain/blocks/blockInput/types.d.ts +4 -3
  57. package/lib/chain/blocks/blockInput/types.d.ts.map +1 -1
  58. package/lib/chain/blocks/blockInput/types.js +1 -0
  59. package/lib/chain/blocks/blockInput/types.js.map +1 -1
  60. package/lib/chain/blocks/importBlock.d.ts +3 -3
  61. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  62. package/lib/chain/blocks/importBlock.js +48 -28
  63. package/lib/chain/blocks/importBlock.js.map +1 -1
  64. package/lib/chain/blocks/importExecutionPayload.d.ts +48 -0
  65. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -0
  66. package/lib/chain/blocks/importExecutionPayload.js +167 -0
  67. package/lib/chain/blocks/importExecutionPayload.js.map +1 -0
  68. package/lib/chain/blocks/index.d.ts.map +1 -1
  69. package/lib/chain/blocks/index.js +3 -2
  70. package/lib/chain/blocks/index.js.map +1 -1
  71. package/lib/chain/blocks/payloadEnvelopeInput/index.d.ts +3 -0
  72. package/lib/chain/blocks/payloadEnvelopeInput/index.d.ts.map +1 -0
  73. package/lib/chain/blocks/payloadEnvelopeInput/index.js +3 -0
  74. package/lib/chain/blocks/payloadEnvelopeInput/index.js.map +1 -0
  75. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts +80 -0
  76. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -0
  77. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +248 -0
  78. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.map +1 -0
  79. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +29 -0
  80. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -0
  81. package/lib/chain/blocks/payloadEnvelopeInput/types.js +11 -0
  82. package/lib/chain/blocks/payloadEnvelopeInput/types.js.map +1 -0
  83. package/lib/chain/blocks/payloadEnvelopeProcessor.d.ts +15 -0
  84. package/lib/chain/blocks/payloadEnvelopeProcessor.d.ts.map +1 -0
  85. package/lib/chain/blocks/payloadEnvelopeProcessor.js +46 -0
  86. package/lib/chain/blocks/payloadEnvelopeProcessor.js.map +1 -0
  87. package/lib/chain/blocks/types.d.ts +28 -15
  88. package/lib/chain/blocks/types.d.ts.map +1 -1
  89. package/lib/chain/blocks/types.js.map +1 -1
  90. package/lib/chain/blocks/utils/checkpoint.d.ts +2 -2
  91. package/lib/chain/blocks/utils/checkpoint.d.ts.map +1 -1
  92. package/lib/chain/blocks/utils/checkpoint.js.map +1 -1
  93. package/lib/chain/blocks/verifyBlock.d.ts +2 -2
  94. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  95. package/lib/chain/blocks/verifyBlock.js +4 -4
  96. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  97. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +5 -5
  98. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  99. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +4 -4
  100. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  101. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  102. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  103. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
  104. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  105. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts +3 -3
  106. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  107. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +3 -3
  108. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  109. package/lib/chain/blocks/writePayloadEnvelopeInputToDb.d.ts +12 -0
  110. package/lib/chain/blocks/writePayloadEnvelopeInputToDb.d.ts.map +1 -0
  111. package/lib/chain/blocks/writePayloadEnvelopeInputToDb.js +40 -0
  112. package/lib/chain/blocks/writePayloadEnvelopeInputToDb.js.map +1 -0
  113. package/lib/chain/chain.d.ts +22 -17
  114. package/lib/chain/chain.d.ts.map +1 -1
  115. package/lib/chain/chain.js +90 -48
  116. package/lib/chain/chain.js.map +1 -1
  117. package/lib/chain/emitter.d.ts +2 -2
  118. package/lib/chain/emitter.d.ts.map +1 -1
  119. package/lib/chain/errors/blockError.d.ts +4 -4
  120. package/lib/chain/errors/blockError.d.ts.map +1 -1
  121. package/lib/chain/errors/executionPayloadEnvelope.d.ts +12 -2
  122. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  123. package/lib/chain/errors/executionPayloadEnvelope.js +3 -1
  124. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  125. package/lib/chain/forkChoice/index.d.ts +4 -4
  126. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  127. package/lib/chain/forkChoice/index.js +27 -33
  128. package/lib/chain/forkChoice/index.js.map +1 -1
  129. package/lib/chain/initState.d.ts +2 -2
  130. package/lib/chain/initState.d.ts.map +1 -1
  131. package/lib/chain/initState.js +1 -1
  132. package/lib/chain/initState.js.map +1 -1
  133. package/lib/chain/interface.d.ts +19 -17
  134. package/lib/chain/interface.d.ts.map +1 -1
  135. package/lib/chain/lightClient/index.d.ts +2 -2
  136. package/lib/chain/lightClient/index.d.ts.map +1 -1
  137. package/lib/chain/lightClient/index.js +4 -4
  138. package/lib/chain/lightClient/index.js.map +1 -1
  139. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +6 -6
  140. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  141. package/lib/chain/opPools/aggregatedAttestationPool.js +10 -13
  142. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  143. package/lib/chain/opPools/opPool.d.ts +3 -3
  144. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  145. package/lib/chain/opPools/opPool.js +7 -7
  146. package/lib/chain/opPools/opPool.js.map +1 -1
  147. package/lib/chain/opPools/utils.d.ts +2 -2
  148. package/lib/chain/opPools/utils.d.ts.map +1 -1
  149. package/lib/chain/opPools/utils.js +2 -2
  150. package/lib/chain/opPools/utils.js.map +1 -1
  151. package/lib/chain/options.d.ts +1 -0
  152. package/lib/chain/options.d.ts.map +1 -1
  153. package/lib/chain/options.js +1 -0
  154. package/lib/chain/options.js.map +1 -1
  155. package/lib/chain/prepareNextSlot.d.ts +2 -2
  156. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  157. package/lib/chain/prepareNextSlot.js +9 -5
  158. package/lib/chain/prepareNextSlot.js.map +1 -1
  159. package/lib/chain/produceBlock/computeNewStateRoot.d.ts +4 -4
  160. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  161. package/lib/chain/produceBlock/computeNewStateRoot.js +8 -4
  162. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  163. package/lib/chain/produceBlock/produceBlockBody.d.ts +5 -5
  164. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  165. package/lib/chain/produceBlock/produceBlockBody.js +13 -17
  166. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  167. package/lib/chain/regen/errors.d.ts +11 -1
  168. package/lib/chain/regen/errors.d.ts.map +1 -1
  169. package/lib/chain/regen/errors.js +2 -0
  170. package/lib/chain/regen/errors.js.map +1 -1
  171. package/lib/chain/regen/interface.d.ts +22 -14
  172. package/lib/chain/regen/interface.d.ts.map +1 -1
  173. package/lib/chain/regen/interface.js +2 -0
  174. package/lib/chain/regen/interface.js.map +1 -1
  175. package/lib/chain/regen/queued.d.ts +20 -15
  176. package/lib/chain/regen/queued.d.ts.map +1 -1
  177. package/lib/chain/regen/queued.js +40 -8
  178. package/lib/chain/regen/queued.js.map +1 -1
  179. package/lib/chain/regen/regen.d.ts +11 -5
  180. package/lib/chain/regen/regen.d.ts.map +1 -1
  181. package/lib/chain/regen/regen.js +38 -11
  182. package/lib/chain/regen/regen.js.map +1 -1
  183. package/lib/chain/seenCache/index.d.ts +1 -1
  184. package/lib/chain/seenCache/index.d.ts.map +1 -1
  185. package/lib/chain/seenCache/index.js +1 -1
  186. package/lib/chain/seenCache/index.js.map +1 -1
  187. package/lib/chain/seenCache/seenGossipBlockInput.js +2 -2
  188. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  189. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +38 -0
  190. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -0
  191. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +76 -0
  192. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -0
  193. package/lib/chain/serializeState.d.ts +2 -2
  194. package/lib/chain/serializeState.d.ts.map +1 -1
  195. package/lib/chain/serializeState.js +1 -1
  196. package/lib/chain/serializeState.js.map +1 -1
  197. package/lib/chain/shufflingCache.d.ts +2 -2
  198. package/lib/chain/shufflingCache.d.ts.map +1 -1
  199. package/lib/chain/shufflingCache.js +3 -4
  200. package/lib/chain/shufflingCache.js.map +1 -1
  201. package/lib/chain/stateCache/datastore/db.d.ts +4 -5
  202. package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
  203. package/lib/chain/stateCache/datastore/db.js +32 -10
  204. package/lib/chain/stateCache/datastore/db.js.map +1 -1
  205. package/lib/chain/stateCache/datastore/file.d.ts +1 -1
  206. package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
  207. package/lib/chain/stateCache/datastore/file.js +5 -5
  208. package/lib/chain/stateCache/datastore/file.js.map +1 -1
  209. package/lib/chain/stateCache/datastore/types.d.ts +1 -1
  210. package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
  211. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +13 -10
  212. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  213. package/lib/chain/stateCache/fifoBlockStateCache.js +8 -3
  214. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  215. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +36 -17
  216. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  217. package/lib/chain/stateCache/persistentCheckpointsCache.js +228 -134
  218. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  219. package/lib/chain/stateCache/types.d.ts +23 -16
  220. package/lib/chain/stateCache/types.d.ts.map +1 -1
  221. package/lib/chain/stateCache/types.js.map +1 -1
  222. package/lib/chain/validation/attesterSlashing.js +3 -3
  223. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  224. package/lib/chain/validation/blobSidecar.js +1 -1
  225. package/lib/chain/validation/blobSidecar.js.map +1 -1
  226. package/lib/chain/validation/block.d.ts.map +1 -1
  227. package/lib/chain/validation/block.js +3 -3
  228. package/lib/chain/validation/block.js.map +1 -1
  229. package/lib/chain/validation/blsToExecutionChange.js +2 -2
  230. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  231. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  232. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  233. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  234. package/lib/chain/validation/executionPayloadBid.js +4 -4
  235. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  236. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  237. package/lib/chain/validation/executionPayloadEnvelope.js +29 -19
  238. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  239. package/lib/chain/validation/lightClientFinalityUpdate.js +1 -1
  240. package/lib/chain/validation/lightClientFinalityUpdate.js.map +1 -1
  241. package/lib/chain/validation/lightClientOptimisticUpdate.js +1 -1
  242. package/lib/chain/validation/lightClientOptimisticUpdate.js.map +1 -1
  243. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  244. package/lib/chain/validation/payloadAttestationMessage.js +1 -2
  245. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  246. package/lib/chain/validation/proposerSlashing.js +1 -1
  247. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  248. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  249. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  250. package/lib/chain/validation/signatureSets/contributionAndProof.js +1 -1
  251. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  252. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  253. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  254. package/lib/chain/validation/signatureSets/syncCommittee.js +1 -1
  255. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  256. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
  257. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  258. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  259. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  260. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  261. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -1
  262. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  263. package/lib/chain/validation/syncCommittee.d.ts +4 -4
  264. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  265. package/lib/chain/validation/syncCommittee.js +13 -12
  266. package/lib/chain/validation/syncCommittee.js.map +1 -1
  267. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  268. package/lib/chain/validation/syncCommitteeContributionAndProof.js +1 -1
  269. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  270. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  271. package/lib/chain/validation/voluntaryExit.js +3 -3
  272. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  273. package/lib/chain/validatorMonitor.d.ts +5 -4
  274. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  275. package/lib/chain/validatorMonitor.js +13 -8
  276. package/lib/chain/validatorMonitor.js.map +1 -1
  277. package/lib/execution/engine/interface.d.ts +2 -2
  278. package/lib/metrics/metrics/lodestar.d.ts +40 -4
  279. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  280. package/lib/metrics/metrics/lodestar.js +93 -15
  281. package/lib/metrics/metrics/lodestar.js.map +1 -1
  282. package/lib/network/gossip/encoding.d.ts.map +1 -1
  283. package/lib/network/gossip/encoding.js +15 -0
  284. package/lib/network/gossip/encoding.js.map +1 -1
  285. package/lib/network/interface.d.ts +4 -2
  286. package/lib/network/interface.d.ts.map +1 -1
  287. package/lib/network/libp2p/index.d.ts.map +1 -1
  288. package/lib/network/libp2p/index.js +5 -0
  289. package/lib/network/libp2p/index.js.map +1 -1
  290. package/lib/network/network.d.ts +4 -2
  291. package/lib/network/network.d.ts.map +1 -1
  292. package/lib/network/network.js +11 -5
  293. package/lib/network/network.js.map +1 -1
  294. package/lib/network/processor/extractSlotRootFns.d.ts +1 -1
  295. package/lib/network/processor/extractSlotRootFns.d.ts.map +1 -1
  296. package/lib/network/processor/extractSlotRootFns.js +15 -5
  297. package/lib/network/processor/extractSlotRootFns.js.map +1 -1
  298. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  299. package/lib/network/processor/gossipHandlers.js +39 -9
  300. package/lib/network/processor/gossipHandlers.js.map +1 -1
  301. package/lib/network/processor/index.d.ts +12 -7
  302. package/lib/network/processor/index.d.ts.map +1 -1
  303. package/lib/network/processor/index.js +99 -78
  304. package/lib/network/processor/index.js.map +1 -1
  305. package/lib/network/reqresp/ReqRespBeaconNode.d.ts +1 -1
  306. package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
  307. package/lib/network/reqresp/ReqRespBeaconNode.js +10 -1
  308. package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
  309. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts +8 -0
  310. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -0
  311. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +69 -0
  312. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -0
  313. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts +6 -0
  314. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -0
  315. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +28 -0
  316. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -0
  317. package/lib/network/reqresp/handlers/index.d.ts.map +1 -1
  318. package/lib/network/reqresp/handlers/index.js +11 -1
  319. package/lib/network/reqresp/handlers/index.js.map +1 -1
  320. package/lib/network/reqresp/protocols.d.ts +2 -0
  321. package/lib/network/reqresp/protocols.d.ts.map +1 -1
  322. package/lib/network/reqresp/protocols.js +10 -0
  323. package/lib/network/reqresp/protocols.js.map +1 -1
  324. package/lib/network/reqresp/rateLimit.d.ts.map +1 -1
  325. package/lib/network/reqresp/rateLimit.js +8 -0
  326. package/lib/network/reqresp/rateLimit.js.map +1 -1
  327. package/lib/network/reqresp/score.d.ts.map +1 -1
  328. package/lib/network/reqresp/score.js +2 -0
  329. package/lib/network/reqresp/score.js.map +1 -1
  330. package/lib/network/reqresp/types.d.ts +8 -2
  331. package/lib/network/reqresp/types.d.ts.map +1 -1
  332. package/lib/network/reqresp/types.js +7 -1
  333. package/lib/network/reqresp/types.js.map +1 -1
  334. package/lib/node/nodejs.d.ts +2 -2
  335. package/lib/node/nodejs.d.ts.map +1 -1
  336. package/lib/node/nodejs.js +1 -4
  337. package/lib/node/nodejs.js.map +1 -1
  338. package/lib/node/notifier.d.ts.map +1 -1
  339. package/lib/node/notifier.js +3 -3
  340. package/lib/node/notifier.js.map +1 -1
  341. package/lib/sync/backfill/backfill.d.ts +3 -3
  342. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  343. package/lib/sync/backfill/backfill.js +3 -3
  344. package/lib/sync/backfill/backfill.js.map +1 -1
  345. package/lib/sync/constants.d.ts +1 -1
  346. package/lib/sync/constants.js +1 -1
  347. package/lib/sync/unknownBlock.d.ts +3 -9
  348. package/lib/sync/unknownBlock.d.ts.map +1 -1
  349. package/lib/sync/unknownBlock.js +8 -41
  350. package/lib/sync/unknownBlock.js.map +1 -1
  351. package/lib/util/sszBytes.d.ts +4 -1
  352. package/lib/util/sszBytes.d.ts.map +1 -1
  353. package/lib/util/sszBytes.js +69 -12
  354. package/lib/util/sszBytes.js.map +1 -1
  355. package/lib/util/types.d.ts +2 -0
  356. package/lib/util/types.d.ts.map +1 -1
  357. package/lib/util/types.js +1 -0
  358. package/lib/util/types.js.map +1 -1
  359. package/package.json +16 -16
  360. package/src/api/impl/beacon/blocks/index.ts +37 -18
  361. package/src/api/impl/beacon/pool/index.ts +1 -1
  362. package/src/api/impl/beacon/state/index.ts +29 -41
  363. package/src/api/impl/beacon/state/utils.ts +13 -27
  364. package/src/api/impl/lodestar/index.ts +4 -8
  365. package/src/api/impl/proof/index.ts +2 -9
  366. package/src/api/impl/validator/index.ts +35 -43
  367. package/src/api/impl/validator/utils.ts +4 -7
  368. package/src/chain/archiveStore/archiveStore.ts +1 -10
  369. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +10 -39
  370. package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +2 -1
  371. package/src/chain/archiveStore/historicalState/types.ts +2 -0
  372. package/src/chain/archiveStore/historicalState/worker.ts +1 -4
  373. package/src/chain/archiveStore/interface.ts +5 -4
  374. package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +8 -5
  375. package/src/chain/archiveStore/utils/archiveBlocks.ts +59 -1
  376. package/src/chain/balancesCache.ts +5 -11
  377. package/src/chain/blocks/blockInput/types.ts +4 -3
  378. package/src/chain/blocks/importBlock.ts +69 -32
  379. package/src/chain/blocks/importExecutionPayload.ts +247 -0
  380. package/src/chain/blocks/index.ts +3 -2
  381. package/src/chain/blocks/payloadEnvelopeInput/index.ts +2 -0
  382. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +336 -0
  383. package/src/chain/blocks/payloadEnvelopeInput/types.ts +33 -0
  384. package/src/chain/blocks/payloadEnvelopeProcessor.ts +61 -0
  385. package/src/chain/blocks/types.ts +34 -15
  386. package/src/chain/blocks/utils/checkpoint.ts +2 -2
  387. package/src/chain/blocks/verifyBlock.ts +5 -10
  388. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -14
  389. package/src/chain/blocks/verifyBlocksSignatures.ts +4 -4
  390. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +6 -8
  391. package/src/chain/blocks/writePayloadEnvelopeInputToDb.ts +55 -0
  392. package/src/chain/chain.ts +134 -81
  393. package/src/chain/emitter.ts +2 -2
  394. package/src/chain/errors/blockError.ts +4 -4
  395. package/src/chain/errors/executionPayloadEnvelope.ts +6 -2
  396. package/src/chain/forkChoice/index.ts +33 -52
  397. package/src/chain/initState.ts +7 -2
  398. package/src/chain/interface.ts +20 -18
  399. package/src/chain/lightClient/index.ts +9 -22
  400. package/src/chain/opPools/aggregatedAttestationPool.ts +15 -21
  401. package/src/chain/opPools/opPool.ts +13 -14
  402. package/src/chain/opPools/utils.ts +4 -4
  403. package/src/chain/options.ts +2 -0
  404. package/src/chain/prepareNextSlot.ts +12 -10
  405. package/src/chain/produceBlock/computeNewStateRoot.ts +11 -10
  406. package/src/chain/produceBlock/produceBlockBody.ts +23 -50
  407. package/src/chain/regen/errors.ts +6 -1
  408. package/src/chain/regen/interface.ts +22 -18
  409. package/src/chain/regen/queued.ts +59 -27
  410. package/src/chain/regen/regen.ts +52 -23
  411. package/src/chain/seenCache/index.ts +1 -1
  412. package/src/chain/seenCache/seenGossipBlockInput.ts +2 -2
  413. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +106 -0
  414. package/src/chain/serializeState.ts +3 -3
  415. package/src/chain/shufflingCache.ts +5 -7
  416. package/src/chain/stateCache/datastore/db.ts +33 -10
  417. package/src/chain/stateCache/datastore/file.ts +6 -5
  418. package/src/chain/stateCache/datastore/types.ts +3 -2
  419. package/src/chain/stateCache/fifoBlockStateCache.ts +17 -11
  420. package/src/chain/stateCache/persistentCheckpointsCache.ts +266 -172
  421. package/src/chain/stateCache/types.ts +22 -16
  422. package/src/chain/validation/attesterSlashing.ts +3 -3
  423. package/src/chain/validation/blobSidecar.ts +1 -1
  424. package/src/chain/validation/block.ts +2 -4
  425. package/src/chain/validation/blsToExecutionChange.ts +2 -2
  426. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  427. package/src/chain/validation/executionPayloadBid.ts +3 -7
  428. package/src/chain/validation/executionPayloadEnvelope.ts +36 -29
  429. package/src/chain/validation/lightClientFinalityUpdate.ts +1 -1
  430. package/src/chain/validation/lightClientOptimisticUpdate.ts +1 -1
  431. package/src/chain/validation/payloadAttestationMessage.ts +2 -4
  432. package/src/chain/validation/proposerSlashing.ts +1 -1
  433. package/src/chain/validation/signatureSets/contributionAndProof.ts +2 -7
  434. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -7
  435. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -2
  436. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -7
  437. package/src/chain/validation/syncCommittee.ts +21 -20
  438. package/src/chain/validation/syncCommitteeContributionAndProof.ts +5 -10
  439. package/src/chain/validation/voluntaryExit.ts +3 -7
  440. package/src/chain/validatorMonitor.ts +23 -12
  441. package/src/execution/engine/interface.ts +2 -2
  442. package/src/metrics/metrics/lodestar.ts +100 -19
  443. package/src/network/gossip/encoding.ts +16 -0
  444. package/src/network/interface.ts +15 -2
  445. package/src/network/libp2p/index.ts +5 -0
  446. package/src/network/network.ts +34 -6
  447. package/src/network/processor/extractSlotRootFns.ts +19 -6
  448. package/src/network/processor/gossipHandlers.ts +45 -8
  449. package/src/network/processor/index.ts +110 -89
  450. package/src/network/reqresp/ReqRespBeaconNode.ts +14 -1
  451. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +94 -0
  452. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +43 -0
  453. package/src/network/reqresp/handlers/index.ts +12 -0
  454. package/src/network/reqresp/protocols.ts +12 -0
  455. package/src/network/reqresp/rateLimit.ts +18 -0
  456. package/src/network/reqresp/score.ts +2 -0
  457. package/src/network/reqresp/types.ts +13 -0
  458. package/src/node/nodejs.ts +3 -5
  459. package/src/node/notifier.ts +4 -10
  460. package/src/sync/backfill/backfill.ts +4 -4
  461. package/src/sync/constants.ts +1 -1
  462. package/src/sync/unknownBlock.ts +10 -50
  463. package/src/util/sszBytes.ts +90 -10
  464. package/src/util/types.ts +6 -0
  465. package/lib/chain/archiveStore/utils/archivePayloads.d.ts +0 -7
  466. package/lib/chain/archiveStore/utils/archivePayloads.d.ts.map +0 -1
  467. package/lib/chain/archiveStore/utils/archivePayloads.js +0 -10
  468. package/lib/chain/archiveStore/utils/archivePayloads.js.map +0 -1
  469. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.d.ts +0 -15
  470. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.d.ts.map +0 -1
  471. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.js +0 -28
  472. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.js.map +0 -1
  473. package/src/chain/archiveStore/utils/archivePayloads.ts +0 -15
  474. package/src/chain/seenCache/seenExecutionPayloadEnvelope.ts +0 -34
@@ -50,12 +50,25 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
50
50
  var e = new Error(message);
51
51
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
52
  });
53
- import { computeStartSlotAtEpoch, getBlockRootAtSlot, loadCachedBeaconState, } from "@lodestar/state-transition";
53
+ import { computeStartSlotAtEpoch } from "@lodestar/state-transition";
54
54
  import { MapDef, fromHex, sleep, toHex, toRootHex } from "@lodestar/utils";
55
55
  import { AllocSource } from "../../util/bufferPool.js";
56
56
  import { serializeState } from "../serializeState.js";
57
57
  import { MapTracker } from "./mapMetrics.js";
58
58
  import { CacheItemType } from "./types.js";
59
+ /** Bitmask for tracking which payload variants exist per root in the epochIndex */
60
+ var PayloadAvailability;
61
+ (function (PayloadAvailability) {
62
+ PayloadAvailability[PayloadAvailability["NOT_PRESENT"] = 1] = "NOT_PRESENT";
63
+ PayloadAvailability[PayloadAvailability["PRESENT"] = 2] = "PRESENT";
64
+ })(PayloadAvailability || (PayloadAvailability = {}));
65
+ const PAYLOAD_AVAILABILITY_ALL = [PayloadAvailability.NOT_PRESENT, PayloadAvailability.PRESENT];
66
+ function toPayloadAvailability(payloadPresent) {
67
+ return payloadPresent ? PayloadAvailability.PRESENT : PayloadAvailability.NOT_PRESENT;
68
+ }
69
+ function fromPayloadAvailability(flag) {
70
+ return flag === PayloadAvailability.PRESENT;
71
+ }
59
72
  /**
60
73
  * Before n-historical states, lodestar keeps all checkpoint states since finalized
61
74
  * Since Sep 2024, lodestar stores 3 most recent checkpoint states in memory and the rest on disk. The finalized state
@@ -105,8 +118,8 @@ const PROCESS_CHECKPOINT_STATES_BPS = 6667;
105
118
  */
106
119
  export class PersistentCheckpointStateCache {
107
120
  cache;
108
- /** Epoch -> Set<blockRoot> */
109
- epochIndex = new MapDef(() => new Set());
121
+ /** Epoch -> Map<blockRoot, PayloadAvailability bitmask> */
122
+ epochIndex = new MapDef(() => new Map());
110
123
  config;
111
124
  metrics;
112
125
  logger;
@@ -188,15 +201,20 @@ export class PersistentCheckpointStateCache {
188
201
  */
189
202
  async getOrReload(cp) {
190
203
  const stateOrStateBytesData = await this.getStateOrLoadDb(cp);
191
- if (stateOrStateBytesData === null || isCachedBeaconState(stateOrStateBytesData)) {
204
+ if (stateOrStateBytesData === null || isBeaconStateView(stateOrStateBytesData)) {
192
205
  return stateOrStateBytesData ?? null;
193
206
  }
194
207
  const { persistedKey, stateBytes } = stateOrStateBytesData;
195
- const logMeta = { persistedKey: toHex(persistedKey) };
208
+ const logMeta = {
209
+ epoch: cp.epoch,
210
+ rootHex: cp.rootHex,
211
+ payloadPresent: cp.payloadPresent,
212
+ persistedKey: toHex(persistedKey),
213
+ };
196
214
  this.logger.debug("Reload: read state successful", logMeta);
197
215
  this.metrics?.cpStateCache.stateReloadSecFromSlot.observe(this.clock?.secFromSlot(this.clock?.currentSlot ?? 0) ?? 0);
198
216
  const seedState = this.findSeedStateToReload(cp);
199
- this.metrics?.cpStateCache.stateReloadEpochDiff.observe(Math.abs(seedState.epochCtx.epoch - cp.epoch));
217
+ this.metrics?.cpStateCache.stateReloadEpochDiff.observe(Math.abs(seedState.epoch - cp.epoch));
200
218
  this.logger.debug("Reload: found seed state", { ...logMeta, seedSlot: seedState.slot });
201
219
  try {
202
220
  const env_1 = { stack: [], error: void 0, hasError: false };
@@ -209,18 +227,15 @@ export class PersistentCheckpointStateCache {
209
227
  if (validatorsBytes == null) {
210
228
  // fallback logic in case we can't use the buffer pool
211
229
  this.metrics?.cpStateCache.stateReloadValidatorsSerializeAllocCount.inc();
212
- validatorsBytes = seedState.validators.serialize();
230
+ validatorsBytes = seedState.serializeValidators();
213
231
  }
214
232
  sszTimer?.();
215
233
  const timer = this.metrics?.cpStateCache.stateReloadDuration.startTimer();
216
- const newCachedState = loadCachedBeaconState(seedState, stateBytes, {}, validatorsBytes);
234
+ const newCachedState = seedState.loadOtherState(stateBytes, validatorsBytes);
217
235
  // hashTreeRoot() calls the commit() inside
218
236
  // there is no modification inside the state, it's just that we want to compute and cache all roots
219
237
  const stateRoot = toRootHex(newCachedState.hashTreeRoot());
220
238
  timer?.();
221
- // load all cache in order for consumers (usually regen.getState()) to process blocks faster
222
- newCachedState.validators.getAllReadonlyValues();
223
- newCachedState.balances.getAll();
224
239
  this.logger.debug("Reload: cached state load successful", {
225
240
  ...logMeta,
226
241
  stateSlot: newCachedState.slot,
@@ -230,7 +245,7 @@ export class PersistentCheckpointStateCache {
230
245
  // only remove persisted state once we reload successfully
231
246
  const cpKey = toCacheKey(cp);
232
247
  this.cache.set(cpKey, { type: CacheItemType.inMemory, state: newCachedState, persistedKey });
233
- this.epochIndex.getOrDefault(cp.epoch).add(cp.rootHex);
248
+ this.addToEpochIndex(cp.epoch, cp.rootHex, cp.payloadPresent);
234
249
  // don't prune from memory here, call it at the last 1/3 of slot 0 of an epoch
235
250
  return newCachedState;
236
251
  }
@@ -252,7 +267,7 @@ export class PersistentCheckpointStateCache {
252
267
  */
253
268
  async getStateOrBytes(cp) {
254
269
  const stateOrLoadedState = await this.getStateOrLoadDb(cp);
255
- if (stateOrLoadedState === null || isCachedBeaconState(stateOrLoadedState)) {
270
+ if (stateOrLoadedState === null || isBeaconStateView(stateOrLoadedState)) {
256
271
  return stateOrLoadedState;
257
272
  }
258
273
  return stateOrLoadedState.stateBytes;
@@ -306,9 +321,11 @@ export class PersistentCheckpointStateCache {
306
321
  }
307
322
  /**
308
323
  * Add a state of a checkpoint to this cache, prune from memory if necessary.
324
+ * @param payloadPresent - For Gloas: true if this is payload state, false if block state.
325
+ * Always true for pre-Gloas.
309
326
  */
310
- add(cp, state) {
311
- const cpHex = toCheckpointHex(cp);
327
+ add(cp, state, payloadPresent) {
328
+ const cpHex = toCheckpointHexPayload(cp, payloadPresent);
312
329
  const key = toCacheKey(cpHex);
313
330
  const cacheItem = this.cache.get(key);
314
331
  this.metrics?.cpStateCache.adds.inc();
@@ -319,27 +336,32 @@ export class PersistentCheckpointStateCache {
319
336
  this.logger.verbose("Added checkpoint state to memory but a persisted key existed", {
320
337
  epoch: cp.epoch,
321
338
  rootHex: cpHex.rootHex,
339
+ payloadPresent,
322
340
  persistedKey: toHex(persistedKey),
323
341
  });
324
342
  }
325
343
  else {
326
344
  this.cache.set(key, { type: CacheItemType.inMemory, state });
327
- this.logger.verbose("Added checkpoint state to memory", { epoch: cp.epoch, rootHex: cpHex.rootHex });
345
+ this.logger.verbose("Added checkpoint state to memory", {
346
+ epoch: cp.epoch,
347
+ rootHex: cpHex.rootHex,
348
+ payloadPresent,
349
+ });
328
350
  }
329
- this.epochIndex.getOrDefault(cp.epoch).add(cpHex.rootHex);
351
+ this.addToEpochIndex(cp.epoch, cpHex.rootHex, cpHex.payloadPresent);
330
352
  this.prunePersistedStates();
331
353
  }
332
354
  /**
333
355
  * Searches in-memory state for the latest cached state with a `root` without reload, starting with `epoch` and descending
334
356
  */
335
- getLatest(rootHex, maxEpoch) {
357
+ getLatest(rootHex, maxEpoch, payloadPresent) {
336
358
  // sort epochs in descending order, only consider epochs lte `epoch`
337
359
  const epochs = Array.from(this.epochIndex.keys())
338
360
  .sort((a, b) => b - a)
339
361
  .filter((e) => e <= maxEpoch);
340
362
  for (const epoch of epochs) {
341
- if (this.epochIndex.get(epoch)?.has(rootHex)) {
342
- const inMemoryClonedState = this.get({ rootHex, epoch });
363
+ if (this.hasPayloadVariant(epoch, rootHex, payloadPresent)) {
364
+ const inMemoryClonedState = this.get({ rootHex, epoch, payloadPresent });
343
365
  if (inMemoryClonedState) {
344
366
  return inMemoryClonedState;
345
367
  }
@@ -354,33 +376,35 @@ export class PersistentCheckpointStateCache {
354
376
  * - Get block for processing
355
377
  * - Regen head state
356
378
  */
357
- async getOrReloadLatest(rootHex, maxEpoch) {
379
+ async getOrReloadLatest(rootHex, maxEpoch, payloadPresent) {
358
380
  // sort epochs in descending order, only consider epochs lte `epoch`
359
381
  const epochs = Array.from(this.epochIndex.keys())
360
382
  .sort((a, b) => b - a)
361
383
  .filter((e) => e <= maxEpoch);
362
384
  for (const epoch of epochs) {
363
- if (this.epochIndex.get(epoch)?.has(rootHex)) {
385
+ if (this.hasPayloadVariant(epoch, rootHex, payloadPresent)) {
364
386
  try {
365
- const state = await this.getOrReload({ rootHex, epoch });
387
+ const state = await this.getOrReload({ rootHex, epoch, payloadPresent });
366
388
  if (state) {
367
389
  return state;
368
390
  }
369
391
  }
370
392
  catch (e) {
371
- this.logger.debug("Error get or reload state", { epoch, rootHex }, e);
393
+ this.logger.debug("Error get or reload state", { epoch, rootHex, payloadPresent }, e);
372
394
  }
373
395
  }
374
396
  }
375
397
  return null;
376
398
  }
377
399
  /**
378
- * Update the precomputed checkpoint and return the number of his for the
400
+ * Update the precomputed checkpoint and return the number of hits for the
379
401
  * previous one (if any).
402
+ * @param payloadPresent - For Gloas: true if head block has FULL payload, false if EMPTY.
403
+ * Always true for pre-Gloas.
380
404
  */
381
- updatePreComputedCheckpoint(rootHex, epoch) {
405
+ updatePreComputedCheckpoint(rootHex, epoch, payloadPresent) {
382
406
  const previousHits = this.preComputedCheckpointHits;
383
- this.preComputedCheckpoint = toCacheKey({ rootHex, epoch });
407
+ this.preComputedCheckpoint = toCacheKey({ rootHex, epoch, payloadPresent });
384
408
  this.preComputedCheckpointHits = 0;
385
409
  return previousHits;
386
410
  }
@@ -449,6 +473,9 @@ export class PersistentCheckpointStateCache {
449
473
  * - 2 then we'll persist {root: b2, epoch n-2} checkpoint state to disk, there are also 2 checkpoint states in memory at epoch n, same to the above (maxEpochsInMemory=1)
450
474
  *
451
475
  * As of Mar 2024, it takes <=350ms to persist a holesky state on fast server
476
+ *
477
+ * For Gloas: Processes both block state and payload state variants together. The decision of which roots to persist/prune
478
+ * is based on root canonicality (from state's view), not payload presence. Both variants are managed as a unit.
452
479
  */
453
480
  async processState(blockRootHex, state) {
454
481
  let persistCount = 0;
@@ -523,30 +550,34 @@ export class PersistentCheckpointStateCache {
523
550
  if (firstState !== null) {
524
551
  return firstState;
525
552
  }
526
- for (const rootHex of this.epochIndex.get(epoch) || []) {
527
- const cpKey = toCacheKey({ rootHex, epoch });
528
- const cacheItem = this.cache.get(cpKey);
529
- if (cacheItem === undefined) {
530
- // should not happen
531
- continue;
532
- }
533
- if (isInMemoryCacheItem(cacheItem)) {
534
- const { state } = cacheItem;
535
- if (firstState === null) {
536
- firstState = state;
553
+ for (const [rootHex, bitmask] of this.epochIndex.get(epoch) || []) {
554
+ for (const flag of PAYLOAD_AVAILABILITY_ALL) {
555
+ if (!(bitmask & flag))
556
+ continue;
557
+ const payloadPresent = fromPayloadAvailability(flag);
558
+ const cpKey = toCacheKey({ rootHex, epoch, payloadPresent });
559
+ const cacheItem = this.cache.get(cpKey);
560
+ if (cacheItem === undefined) {
561
+ continue;
537
562
  }
538
- const cpLog = { cpEpoch: epoch, cpRoot: rootHex };
539
- try {
540
- // amongst states of the same epoch, choose the one with the same view of reloadedCp
541
- if (reloadedCpSlot < state.slot &&
542
- toRootHex(getBlockRootAtSlot(state, reloadedCpSlot)) === reloadedCp.rootHex) {
543
- this.logger.verbose("Reload: use checkpoint state as seed state", { ...cpLog, ...logCtx });
544
- return state;
563
+ if (isInMemoryCacheItem(cacheItem)) {
564
+ const { state } = cacheItem;
565
+ if (firstState === null) {
566
+ firstState = state;
567
+ }
568
+ const cpLog = { cpEpoch: epoch, cpRoot: rootHex, payloadPresent };
569
+ try {
570
+ // amongst states of the same epoch, choose the one with the same view of reloadedCp
571
+ if (reloadedCpSlot < state.slot &&
572
+ toRootHex(state.getBlockRootAtSlot(reloadedCpSlot)) === reloadedCp.rootHex) {
573
+ this.logger.verbose("Reload: use checkpoint state as seed state", { ...cpLog, ...logCtx });
574
+ return state;
575
+ }
576
+ }
577
+ catch (e) {
578
+ // getBlockRootAtSlot may throw error
579
+ this.logger.debug("Error finding checkpoint state to reload", { ...cpLog, ...logCtx }, e);
545
580
  }
546
- }
547
- catch (e) {
548
- // getBlockRootAtSlot may throw error
549
- this.logger.debug("Error finding checkpoint state to reload", { ...cpLog, ...logCtx }, e);
550
581
  }
551
582
  }
552
583
  }
@@ -560,6 +591,31 @@ export class PersistentCheckpointStateCache {
560
591
  this.cache.clear();
561
592
  this.epochIndex.clear();
562
593
  }
594
+ addToEpochIndex(epoch, rootHex, payloadPresent) {
595
+ const rootMap = this.epochIndex.getOrDefault(epoch);
596
+ rootMap.set(rootHex, (rootMap.get(rootHex) ?? 0) | toPayloadAvailability(payloadPresent));
597
+ }
598
+ removeFromEpochIndex(epoch, rootHex, payloadPresent) {
599
+ const rootMap = this.epochIndex.get(epoch);
600
+ if (rootMap === undefined)
601
+ return;
602
+ const existing = rootMap.get(rootHex);
603
+ if (existing === undefined)
604
+ return;
605
+ const updated = existing & ~toPayloadAvailability(payloadPresent);
606
+ if (updated === 0) {
607
+ rootMap.delete(rootHex);
608
+ if (rootMap.size === 0) {
609
+ this.epochIndex.delete(epoch);
610
+ }
611
+ }
612
+ else {
613
+ rootMap.set(rootHex, updated);
614
+ }
615
+ }
616
+ hasPayloadVariant(epoch, rootHex, payloadPresent) {
617
+ return Boolean((this.epochIndex.get(epoch)?.get(rootHex) ?? 0) & toPayloadAvailability(payloadPresent));
618
+ }
563
619
  /** ONLY FOR DEBUGGING PURPOSES. For lodestar debug API */
564
620
  dumpSummary() {
565
621
  return Array.from(this.cache.keys()).map((key) => {
@@ -624,79 +680,85 @@ export class PersistentCheckpointStateCache {
624
680
  async processPastEpoch(blockRootHex, state, epoch) {
625
681
  let persistCount = 0;
626
682
  const epochBoundarySlot = computeStartSlotAtEpoch(epoch);
627
- const epochBoundaryRoot = epochBoundarySlot === state.slot ? fromHex(blockRootHex) : getBlockRootAtSlot(state, epochBoundarySlot);
683
+ const epochBoundaryRoot = epochBoundarySlot === state.slot ? fromHex(blockRootHex) : state.getBlockRootAtSlot(epochBoundarySlot);
628
684
  const epochBoundaryHex = toRootHex(epochBoundaryRoot);
629
- const prevEpochRoot = toRootHex(getBlockRootAtSlot(state, epochBoundarySlot - 1));
685
+ const prevEpochRoot = toRootHex(state.getBlockRootAtSlot(epochBoundarySlot - 1));
630
686
  // for each epoch, usually there are 2 rootHexes respective to the 2 checkpoint states: Previous Root Checkpoint State and Current Root Checkpoint State
631
- const cpRootHexes = this.epochIndex.get(epoch) ?? [];
687
+ const cpRootHexMap = this.epochIndex.get(epoch) ?? new Map();
632
688
  const persistedRootHexes = new Set();
633
689
  // 1) if there is no CRCS, persist PRCS (block 0 of epoch is skipped). In this case prevEpochRoot === epochBoundaryHex
634
690
  // 2) if there are PRCS and CRCS, persist CRCS => persist CRCS
635
691
  // => this is simplified to always persist epochBoundaryHex
636
692
  persistedRootHexes.add(epochBoundaryHex);
637
693
  // 3) persist any states with unknown roots to this state
638
- for (const rootHex of cpRootHexes) {
694
+ for (const rootHex of cpRootHexMap.keys()) {
639
695
  if (rootHex !== epochBoundaryHex && rootHex !== prevEpochRoot) {
640
696
  persistedRootHexes.add(rootHex);
641
697
  }
642
698
  }
643
- for (const rootHex of cpRootHexes) {
644
- const cpKey = toCacheKey({ epoch: epoch, rootHex });
645
- const cacheItem = this.cache.get(cpKey);
646
- if (cacheItem !== undefined && isInMemoryCacheItem(cacheItem)) {
647
- let { persistedKey } = cacheItem;
648
- const { state } = cacheItem;
649
- const logMeta = {
650
- stateSlot: state.slot,
651
- rootHex,
652
- epochBoundaryHex,
653
- persistedKey: persistedKey ? toHex(persistedKey) : "",
654
- };
655
- if (persistedRootHexes.has(rootHex)) {
656
- if (persistedKey) {
657
- // we don't care if the checkpoint state is already persisted
658
- this.logger.verbose("Pruned checkpoint state from memory but no need to persist", logMeta);
659
- }
660
- else {
661
- // persist and do not update epochIndex
662
- this.metrics?.cpStateCache.statePersistSecFromSlot.observe(this.clock?.secFromSlot(this.clock?.currentSlot ?? 0) ?? 0);
663
- const cpPersist = { epoch: epoch, root: fromHex(rootHex) };
664
- // It's not sustainable to allocate ~240MB for each state every epoch, so we use buffer pool to reuse the memory.
665
- // As monitored on holesky as of Jan 2024:
666
- // - This does not increase heap allocation while gc time is the same
667
- // - It helps stabilize persist time and save ~300ms in average (1.5s vs 1.2s)
668
- // - It also helps the state reload to save ~500ms in average (4.3s vs 3.8s)
669
- // - Also `serializeState.test.ts` perf test shows a lot of differences allocating ~240MB once vs per state serialization
670
- const timer = this.metrics?.stateSerializeDuration.startTimer({
671
- source: AllocSource.PERSISTENT_CHECKPOINTS_CACHE_STATE,
672
- });
673
- persistedKey = await serializeState(state, AllocSource.PERSISTENT_CHECKPOINTS_CACHE_STATE, (stateBytes) => {
674
- timer?.();
675
- return this.datastore.write(cpPersist, stateBytes);
676
- }, this.bufferPool);
677
- persistCount++;
678
- this.logger.verbose("Pruned checkpoint state from memory and persisted to disk", {
679
- ...logMeta,
680
- persistedKey: toHex(persistedKey),
681
- });
682
- }
683
- // overwrite cpKey, this means the state is deleted from memory
684
- this.cache.set(cpKey, { type: CacheItemType.persisted, value: persistedKey });
685
- }
686
- else {
687
- if (persistedKey) {
688
- // persisted file will be eventually deleted by the archive task
689
- // this also means the state is deleted from memory
699
+ for (const [rootHex, bitmask] of cpRootHexMap) {
700
+ for (const flag of PAYLOAD_AVAILABILITY_ALL) {
701
+ if (!(bitmask & flag))
702
+ continue;
703
+ const payloadPresent = fromPayloadAvailability(flag);
704
+ const cpKey = toCacheKey({ epoch: epoch, rootHex, payloadPresent });
705
+ const cacheItem = this.cache.get(cpKey);
706
+ if (cacheItem !== undefined && isInMemoryCacheItem(cacheItem)) {
707
+ let { persistedKey } = cacheItem;
708
+ const { state } = cacheItem;
709
+ const logMeta = {
710
+ stateSlot: state.slot,
711
+ rootHex,
712
+ payloadPresent,
713
+ epochBoundaryHex,
714
+ persistedKey: persistedKey ? toHex(persistedKey) : "",
715
+ };
716
+ if (persistedRootHexes.has(rootHex)) {
717
+ if (persistedKey) {
718
+ // we don't care if the checkpoint state is already persisted
719
+ this.logger.verbose("Pruned checkpoint state from memory but no need to persist", logMeta);
720
+ }
721
+ else {
722
+ // persist and do not update epochIndex
723
+ this.metrics?.cpStateCache.statePersistSecFromSlot.observe(this.clock?.secFromSlot(this.clock?.currentSlot ?? 0) ?? 0);
724
+ const cpPersist = { epoch: epoch, root: fromHex(rootHex) };
725
+ // It's not sustainable to allocate ~240MB for each state every epoch, so we use buffer pool to reuse the memory.
726
+ // As monitored on holesky as of Jan 2024:
727
+ // - This does not increase heap allocation while gc time is the same
728
+ // - It helps stabilize persist time and save ~300ms in average (1.5s vs 1.2s)
729
+ // - It also helps the state reload to save ~500ms in average (4.3s vs 3.8s)
730
+ // - Also `serializeState.test.ts` perf test shows a lot of differences allocating ~240MB once vs per state serialization
731
+ const timer = this.metrics?.stateSerializeDuration.startTimer({
732
+ source: AllocSource.PERSISTENT_CHECKPOINTS_CACHE_STATE,
733
+ });
734
+ persistedKey = await serializeState(state, AllocSource.PERSISTENT_CHECKPOINTS_CACHE_STATE, (stateBytes) => {
735
+ timer?.();
736
+ return this.datastore.write(cpPersist, stateBytes, payloadPresent);
737
+ }, this.bufferPool);
738
+ persistCount++;
739
+ this.logger.verbose("Pruned checkpoint state from memory and persisted to disk", {
740
+ ...logMeta,
741
+ persistedKey: toHex(persistedKey),
742
+ });
743
+ }
744
+ // overwrite cpKey, this means the state is deleted from memory
690
745
  this.cache.set(cpKey, { type: CacheItemType.persisted, value: persistedKey });
691
- // do not update epochIndex
692
746
  }
693
747
  else {
694
- // delete the state from memory
695
- this.cache.delete(cpKey);
696
- this.epochIndex.get(epoch)?.delete(rootHex);
748
+ if (persistedKey) {
749
+ // persisted file will be eventually deleted by the archive task
750
+ // this also means the state is deleted from memory
751
+ this.cache.set(cpKey, { type: CacheItemType.persisted, value: persistedKey });
752
+ // do not update epochIndex
753
+ }
754
+ else {
755
+ // delete the state from memory
756
+ this.cache.delete(cpKey);
757
+ this.removeFromEpochIndex(epoch, rootHex, payloadPresent);
758
+ }
759
+ this.metrics?.cpStateCache.statePruneFromMemoryCount.inc();
760
+ this.logger.verbose("Pruned checkpoint state from memory", logMeta);
697
761
  }
698
- this.metrics?.cpStateCache.statePruneFromMemoryCount.inc();
699
- this.logger.verbose("Pruned checkpoint state from memory", logMeta);
700
762
  }
701
763
  }
702
764
  }
@@ -707,25 +769,38 @@ export class PersistentCheckpointStateCache {
707
769
  */
708
770
  async deleteAllEpochItems(epoch) {
709
771
  let persistCount = 0;
710
- const rootHexes = this.epochIndex.get(epoch) || [];
711
- for (const rootHex of rootHexes) {
712
- const key = toCacheKey({ rootHex, epoch });
713
- const cacheItem = this.cache.get(key);
714
- if (cacheItem) {
715
- const persistedKey = isPersistedCacheItem(cacheItem) ? cacheItem.value : cacheItem.persistedKey;
716
- if (persistedKey) {
717
- await this.datastore.remove(persistedKey);
718
- persistCount++;
719
- this.metrics?.cpStateCache.persistedStateRemoveCount.inc();
772
+ const rootHexMap = this.epochIndex.get(epoch) || new Map();
773
+ for (const [rootHex, bitmask] of rootHexMap) {
774
+ for (const flag of PAYLOAD_AVAILABILITY_ALL) {
775
+ if (!(bitmask & flag))
776
+ continue;
777
+ const payloadPresent = fromPayloadAvailability(flag);
778
+ const key = toCacheKey({ rootHex, epoch, payloadPresent });
779
+ const cacheItem = this.cache.get(key);
780
+ if (cacheItem) {
781
+ const persistedKey = isPersistedCacheItem(cacheItem) ? cacheItem.value : cacheItem.persistedKey;
782
+ if (persistedKey) {
783
+ await this.datastore.remove(persistedKey);
784
+ persistCount++;
785
+ this.metrics?.cpStateCache.persistedStateRemoveCount.inc();
786
+ }
720
787
  }
788
+ this.cache.delete(key);
789
+ this.logger.verbose("Pruned checkpoint state", {
790
+ epoch,
791
+ rootHex,
792
+ payloadPresent,
793
+ type: cacheItem ? (isPersistedCacheItem(cacheItem) ? "persisted" : "in-memory") : "missing",
794
+ });
721
795
  }
722
- this.cache.delete(key);
723
796
  }
724
797
  this.epochIndex.delete(epoch);
725
- this.logger.verbose("Pruned checkpoint states for epoch", {
798
+ this.logger.verbose("Pruned all checkpoint states for epoch", {
726
799
  epoch,
727
800
  persistCount,
728
- rootHexes: Array.from(rootHexes).join(","),
801
+ items: Array.from(rootHexMap.entries())
802
+ .flatMap(([rootHex, bitmask]) => PAYLOAD_AVAILABILITY_ALL.filter((f) => bitmask & f).map((f) => `${rootHex}:${fromPayloadAvailability(f)}`))
803
+ .join(","),
729
804
  });
730
805
  }
731
806
  /**
@@ -752,43 +827,65 @@ export class PersistentCheckpointStateCache {
752
827
  * This is 2x - 3x faster than allocating memory every time.
753
828
  */
754
829
  serializeStateValidators(state) {
755
- const type = state.type.fields.validators;
756
- const size = type.tree_serializedSize(state.validators.node);
830
+ const size = state.serializedValidatorsSize();
757
831
  if (this.bufferPool) {
758
832
  const bufferWithKey = this.bufferPool.alloc(size, AllocSource.PERSISTENT_CHECKPOINTS_CACHE_VALIDATORS);
759
833
  if (bufferWithKey) {
760
834
  const validatorsBytes = bufferWithKey.buffer;
761
835
  const dataView = new DataView(validatorsBytes.buffer, validatorsBytes.byteOffset, validatorsBytes.byteLength);
762
- state.validators.serializeToBytes({ uint8Array: validatorsBytes, dataView }, 0);
836
+ state.serializeValidatorsToBytes({ uint8Array: validatorsBytes, dataView }, 0);
763
837
  return bufferWithKey;
764
838
  }
765
839
  }
766
840
  return null;
767
841
  }
768
842
  }
769
- export function toCheckpointHex(checkpoint) {
843
+ export function toCheckpointHexPayload(checkpoint, payloadPresent) {
770
844
  return {
771
845
  epoch: checkpoint.epoch,
772
846
  rootHex: toRootHex(checkpoint.root),
847
+ payloadPresent,
848
+ };
849
+ }
850
+ /**
851
+ * Convert fork-choice CheckpointWithPayloadStatus to beacon-node CheckpointHexPayload.
852
+ * Maps PayloadStatus enum to boolean payloadPresent.
853
+ * @throws Error if checkpoint has PENDING payload status (ambiguous which variant to use)
854
+ */
855
+ export function fcCheckpointToHexPayload(checkpoint) {
856
+ const PayloadStatus = { PENDING: 0, EMPTY: 1, FULL: 2 };
857
+ if (checkpoint.payloadStatus === PayloadStatus.PENDING) {
858
+ throw Error(`Cannot convert checkpoint with PENDING payload status at epoch ${checkpoint.epoch} root ${checkpoint.rootHex}`);
859
+ }
860
+ return {
861
+ epoch: checkpoint.epoch,
862
+ rootHex: checkpoint.rootHex,
863
+ payloadPresent: checkpoint.payloadStatus === PayloadStatus.FULL,
773
864
  };
774
865
  }
775
866
  export function toCheckpointKey(cp) {
776
- return `${cp.rootHex}:${cp.epoch}`;
867
+ return `${cp.rootHex}:${cp.epoch}:${cp.payloadPresent}`;
777
868
  }
869
+ /**
870
+ * Convert checkpoint to cache key string.
871
+ * Format: `{rootHex}_{epoch}_{payloadPresent}`
872
+ */
778
873
  function toCacheKey(cp) {
779
- if (isCheckpointHex(cp)) {
780
- return `${cp.rootHex}_${cp.epoch}`;
781
- }
782
- return `${toRootHex(cp.root)}_${cp.epoch}`;
874
+ return `${cp.rootHex}_${cp.epoch}_${cp.payloadPresent}`;
783
875
  }
784
876
  function fromCacheKey(key) {
785
- const [rootHex, epoch] = key.split("_");
877
+ const parts = key.split("_");
878
+ const rootHex = parts[0];
879
+ const epoch = Number(parts[1]);
880
+ // For backward compatibility with old format (rootHex_epoch), default to true
881
+ const payloadPresent = parts.length > 2 ? parts[2] === "true" : true;
786
882
  return {
787
883
  rootHex,
788
- epoch: Number(epoch),
884
+ epoch,
885
+ payloadPresent,
789
886
  };
790
887
  }
791
- function isCachedBeaconState(stateOrBytes) {
888
+ function isBeaconStateView(stateOrBytes) {
792
889
  return stateOrBytes.slot !== undefined;
793
890
  }
794
891
  function isInMemoryCacheItem(cacheItem) {
@@ -797,7 +894,4 @@ function isInMemoryCacheItem(cacheItem) {
797
894
  function isPersistedCacheItem(cacheItem) {
798
895
  return cacheItem.type === CacheItemType.persisted;
799
896
  }
800
- function isCheckpointHex(cp) {
801
- return cp.rootHex !== undefined;
802
- }
803
897
  //# sourceMappingURL=persistentCheckpointsCache.js.map