@lodestar/beacon-node 1.42.0-dev.7b5ce3932d → 1.42.0-dev.83dedda569

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 (348) hide show
  1. package/lib/api/impl/beacon/blocks/index.js +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  3. package/lib/api/impl/beacon/pool/index.js +1 -1
  4. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  5. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  6. package/lib/api/impl/beacon/state/index.js +27 -32
  7. package/lib/api/impl/beacon/state/index.js.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.d.ts +4 -4
  9. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  10. package/lib/api/impl/beacon/state/utils.js +7 -10
  11. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  12. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  13. package/lib/api/impl/lodestar/index.js +4 -6
  14. package/lib/api/impl/lodestar/index.js.map +1 -1
  15. package/lib/api/impl/proof/index.d.ts.map +1 -1
  16. package/lib/api/impl/proof/index.js +2 -6
  17. package/lib/api/impl/proof/index.js.map +1 -1
  18. package/lib/api/impl/validator/index.d.ts.map +1 -1
  19. package/lib/api/impl/validator/index.js +27 -27
  20. package/lib/api/impl/validator/index.js.map +1 -1
  21. package/lib/api/impl/validator/utils.d.ts +2 -2
  22. package/lib/api/impl/validator/utils.d.ts.map +1 -1
  23. package/lib/api/impl/validator/utils.js +3 -3
  24. package/lib/api/impl/validator/utils.js.map +1 -1
  25. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +2 -6
  26. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  27. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +3 -23
  28. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  29. package/lib/chain/archiveStore/historicalState/worker.js +1 -0
  30. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  31. package/lib/chain/balancesCache.d.ts +2 -2
  32. package/lib/chain/balancesCache.d.ts.map +1 -1
  33. package/lib/chain/balancesCache.js +4 -4
  34. package/lib/chain/balancesCache.js.map +1 -1
  35. package/lib/chain/blocks/blockInput/types.d.ts +1 -0
  36. package/lib/chain/blocks/blockInput/types.d.ts.map +1 -1
  37. package/lib/chain/blocks/blockInput/types.js +1 -0
  38. package/lib/chain/blocks/blockInput/types.js.map +1 -1
  39. package/lib/chain/blocks/importBlock.d.ts +3 -3
  40. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  41. package/lib/chain/blocks/importBlock.js +9 -9
  42. package/lib/chain/blocks/importBlock.js.map +1 -1
  43. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  44. package/lib/chain/blocks/importExecutionPayload.js +4 -5
  45. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  46. package/lib/chain/blocks/index.js +1 -1
  47. package/lib/chain/blocks/index.js.map +1 -1
  48. package/lib/chain/blocks/types.d.ts +2 -2
  49. package/lib/chain/blocks/types.d.ts.map +1 -1
  50. package/lib/chain/blocks/types.js.map +1 -1
  51. package/lib/chain/blocks/utils/checkpoint.d.ts +2 -2
  52. package/lib/chain/blocks/utils/checkpoint.d.ts.map +1 -1
  53. package/lib/chain/blocks/utils/checkpoint.js.map +1 -1
  54. package/lib/chain/blocks/verifyBlock.d.ts +2 -2
  55. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  56. package/lib/chain/blocks/verifyBlock.js +4 -4
  57. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  58. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +3 -3
  59. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  60. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +3 -3
  61. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  62. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  63. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  64. package/lib/chain/blocks/verifyBlocksSignatures.js +1 -1
  65. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  66. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts +3 -3
  67. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  68. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +3 -3
  69. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  70. package/lib/chain/chain.d.ts +12 -12
  71. package/lib/chain/chain.d.ts.map +1 -1
  72. package/lib/chain/chain.js +47 -39
  73. package/lib/chain/chain.js.map +1 -1
  74. package/lib/chain/emitter.d.ts +2 -2
  75. package/lib/chain/emitter.d.ts.map +1 -1
  76. package/lib/chain/errors/blockError.d.ts +4 -4
  77. package/lib/chain/errors/blockError.d.ts.map +1 -1
  78. package/lib/chain/forkChoice/index.d.ts +4 -4
  79. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  80. package/lib/chain/forkChoice/index.js +27 -23
  81. package/lib/chain/forkChoice/index.js.map +1 -1
  82. package/lib/chain/initState.d.ts +2 -2
  83. package/lib/chain/initState.d.ts.map +1 -1
  84. package/lib/chain/initState.js +1 -1
  85. package/lib/chain/initState.js.map +1 -1
  86. package/lib/chain/interface.d.ts +11 -12
  87. package/lib/chain/interface.d.ts.map +1 -1
  88. package/lib/chain/lightClient/index.d.ts +2 -2
  89. package/lib/chain/lightClient/index.d.ts.map +1 -1
  90. package/lib/chain/lightClient/index.js +4 -4
  91. package/lib/chain/lightClient/index.js.map +1 -1
  92. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +6 -6
  93. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  94. package/lib/chain/opPools/aggregatedAttestationPool.js +10 -13
  95. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  96. package/lib/chain/opPools/opPool.d.ts +3 -3
  97. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  98. package/lib/chain/opPools/opPool.js +7 -7
  99. package/lib/chain/opPools/opPool.js.map +1 -1
  100. package/lib/chain/opPools/utils.d.ts +2 -2
  101. package/lib/chain/opPools/utils.d.ts.map +1 -1
  102. package/lib/chain/opPools/utils.js +1 -1
  103. package/lib/chain/opPools/utils.js.map +1 -1
  104. package/lib/chain/prepareNextSlot.d.ts +2 -2
  105. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  106. package/lib/chain/prepareNextSlot.js +3 -3
  107. package/lib/chain/prepareNextSlot.js.map +1 -1
  108. package/lib/chain/produceBlock/computeNewStateRoot.d.ts +4 -4
  109. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  110. package/lib/chain/produceBlock/computeNewStateRoot.js +3 -4
  111. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  112. package/lib/chain/produceBlock/produceBlockBody.d.ts +5 -5
  113. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  114. package/lib/chain/produceBlock/produceBlockBody.js +12 -16
  115. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  116. package/lib/chain/regen/interface.d.ts +13 -13
  117. package/lib/chain/regen/interface.d.ts.map +1 -1
  118. package/lib/chain/regen/queued.d.ts +14 -14
  119. package/lib/chain/regen/queued.d.ts.map +1 -1
  120. package/lib/chain/regen/queued.js.map +1 -1
  121. package/lib/chain/regen/regen.d.ts +6 -5
  122. package/lib/chain/regen/regen.d.ts.map +1 -1
  123. package/lib/chain/regen/regen.js +6 -6
  124. package/lib/chain/regen/regen.js.map +1 -1
  125. package/lib/chain/serializeState.d.ts +2 -2
  126. package/lib/chain/serializeState.d.ts.map +1 -1
  127. package/lib/chain/serializeState.js +1 -1
  128. package/lib/chain/serializeState.js.map +1 -1
  129. package/lib/chain/shufflingCache.d.ts +2 -2
  130. package/lib/chain/shufflingCache.d.ts.map +1 -1
  131. package/lib/chain/shufflingCache.js +3 -4
  132. package/lib/chain/shufflingCache.js.map +1 -1
  133. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +6 -6
  134. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  135. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  136. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +11 -11
  137. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  138. package/lib/chain/stateCache/persistentCheckpointsCache.js +12 -16
  139. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  140. package/lib/chain/stateCache/types.d.ts +14 -14
  141. package/lib/chain/stateCache/types.d.ts.map +1 -1
  142. package/lib/chain/stateCache/types.js.map +1 -1
  143. package/lib/chain/validation/attesterSlashing.js +3 -3
  144. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  145. package/lib/chain/validation/blobSidecar.js +1 -1
  146. package/lib/chain/validation/blobSidecar.js.map +1 -1
  147. package/lib/chain/validation/block.d.ts.map +1 -1
  148. package/lib/chain/validation/block.js +3 -3
  149. package/lib/chain/validation/block.js.map +1 -1
  150. package/lib/chain/validation/blsToExecutionChange.js +2 -2
  151. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  152. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  153. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  154. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  155. package/lib/chain/validation/executionPayloadBid.js +4 -4
  156. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  157. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  158. package/lib/chain/validation/executionPayloadEnvelope.js +2 -3
  159. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  160. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  161. package/lib/chain/validation/payloadAttestationMessage.js +1 -2
  162. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  163. package/lib/chain/validation/proposerSlashing.js +1 -1
  164. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  165. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  166. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  167. package/lib/chain/validation/signatureSets/contributionAndProof.js +1 -1
  168. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  169. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  170. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  171. package/lib/chain/validation/signatureSets/syncCommittee.js +1 -1
  172. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  173. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
  174. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  175. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  176. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  177. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  178. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +1 -1
  179. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  180. package/lib/chain/validation/syncCommittee.d.ts +4 -4
  181. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  182. package/lib/chain/validation/syncCommittee.js +13 -12
  183. package/lib/chain/validation/syncCommittee.js.map +1 -1
  184. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  185. package/lib/chain/validation/syncCommitteeContributionAndProof.js +1 -1
  186. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  187. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  188. package/lib/chain/validation/voluntaryExit.js +3 -3
  189. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  190. package/lib/chain/validatorMonitor.d.ts +3 -3
  191. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  192. package/lib/chain/validatorMonitor.js +9 -7
  193. package/lib/chain/validatorMonitor.js.map +1 -1
  194. package/lib/metrics/metrics/lodestar.d.ts +12 -4
  195. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  196. package/lib/metrics/metrics/lodestar.js +19 -15
  197. package/lib/metrics/metrics/lodestar.js.map +1 -1
  198. package/lib/network/gossip/encoding.d.ts.map +1 -1
  199. package/lib/network/gossip/encoding.js +15 -0
  200. package/lib/network/gossip/encoding.js.map +1 -1
  201. package/lib/network/gossip/topic.d.ts +2 -729
  202. package/lib/network/gossip/topic.d.ts.map +1 -1
  203. package/lib/network/interface.d.ts +4 -2
  204. package/lib/network/interface.d.ts.map +1 -1
  205. package/lib/network/libp2p/index.d.ts.map +1 -1
  206. package/lib/network/libp2p/index.js +5 -0
  207. package/lib/network/libp2p/index.js.map +1 -1
  208. package/lib/network/network.d.ts +4 -2
  209. package/lib/network/network.d.ts.map +1 -1
  210. package/lib/network/network.js +9 -3
  211. package/lib/network/network.js.map +1 -1
  212. package/lib/network/processor/extractSlotRootFns.d.ts +1 -1
  213. package/lib/network/processor/extractSlotRootFns.js +1 -1
  214. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  215. package/lib/network/processor/gossipHandlers.js +9 -7
  216. package/lib/network/processor/gossipHandlers.js.map +1 -1
  217. package/lib/network/processor/index.d.ts +12 -7
  218. package/lib/network/processor/index.d.ts.map +1 -1
  219. package/lib/network/processor/index.js +99 -78
  220. package/lib/network/processor/index.js.map +1 -1
  221. package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
  222. package/lib/network/reqresp/ReqRespBeaconNode.js +9 -0
  223. package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
  224. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts +8 -0
  225. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -0
  226. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +69 -0
  227. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -0
  228. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts +6 -0
  229. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -0
  230. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +28 -0
  231. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -0
  232. package/lib/network/reqresp/handlers/index.d.ts.map +1 -1
  233. package/lib/network/reqresp/handlers/index.js +11 -1
  234. package/lib/network/reqresp/handlers/index.js.map +1 -1
  235. package/lib/network/reqresp/protocols.d.ts +2 -0
  236. package/lib/network/reqresp/protocols.d.ts.map +1 -1
  237. package/lib/network/reqresp/protocols.js +10 -0
  238. package/lib/network/reqresp/protocols.js.map +1 -1
  239. package/lib/network/reqresp/rateLimit.d.ts.map +1 -1
  240. package/lib/network/reqresp/rateLimit.js +8 -0
  241. package/lib/network/reqresp/rateLimit.js.map +1 -1
  242. package/lib/network/reqresp/score.d.ts.map +1 -1
  243. package/lib/network/reqresp/score.js +2 -0
  244. package/lib/network/reqresp/score.js.map +1 -1
  245. package/lib/network/reqresp/types.d.ts +8 -2
  246. package/lib/network/reqresp/types.d.ts.map +1 -1
  247. package/lib/network/reqresp/types.js +7 -1
  248. package/lib/network/reqresp/types.js.map +1 -1
  249. package/lib/node/nodejs.d.ts +2 -2
  250. package/lib/node/nodejs.d.ts.map +1 -1
  251. package/lib/node/nodejs.js +1 -4
  252. package/lib/node/nodejs.js.map +1 -1
  253. package/lib/node/notifier.d.ts.map +1 -1
  254. package/lib/node/notifier.js +3 -3
  255. package/lib/node/notifier.js.map +1 -1
  256. package/lib/sync/backfill/backfill.d.ts +2 -2
  257. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  258. package/lib/sync/backfill/backfill.js +2 -2
  259. package/lib/sync/backfill/backfill.js.map +1 -1
  260. package/lib/sync/unknownBlock.d.ts +3 -9
  261. package/lib/sync/unknownBlock.d.ts.map +1 -1
  262. package/lib/sync/unknownBlock.js +8 -41
  263. package/lib/sync/unknownBlock.js.map +1 -1
  264. package/lib/util/types.d.ts +2 -0
  265. package/lib/util/types.d.ts.map +1 -1
  266. package/lib/util/types.js +1 -0
  267. package/lib/util/types.js.map +1 -1
  268. package/package.json +16 -16
  269. package/src/api/impl/beacon/blocks/index.ts +1 -1
  270. package/src/api/impl/beacon/pool/index.ts +1 -1
  271. package/src/api/impl/beacon/state/index.ts +29 -41
  272. package/src/api/impl/beacon/state/utils.ts +11 -25
  273. package/src/api/impl/lodestar/index.ts +4 -8
  274. package/src/api/impl/proof/index.ts +2 -9
  275. package/src/api/impl/validator/index.ts +29 -41
  276. package/src/api/impl/validator/utils.ts +4 -7
  277. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +6 -36
  278. package/src/chain/archiveStore/historicalState/worker.ts +1 -0
  279. package/src/chain/balancesCache.ts +5 -11
  280. package/src/chain/blocks/blockInput/types.ts +1 -0
  281. package/src/chain/blocks/importBlock.ts +11 -14
  282. package/src/chain/blocks/importExecutionPayload.ts +6 -11
  283. package/src/chain/blocks/index.ts +1 -1
  284. package/src/chain/blocks/types.ts +2 -2
  285. package/src/chain/blocks/utils/checkpoint.ts +2 -2
  286. package/src/chain/blocks/verifyBlock.ts +5 -10
  287. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +5 -10
  288. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -3
  289. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +6 -8
  290. package/src/chain/chain.ts +75 -67
  291. package/src/chain/emitter.ts +2 -2
  292. package/src/chain/errors/blockError.ts +4 -4
  293. package/src/chain/forkChoice/index.ts +33 -42
  294. package/src/chain/initState.ts +7 -2
  295. package/src/chain/interface.ts +12 -13
  296. package/src/chain/lightClient/index.ts +9 -22
  297. package/src/chain/opPools/aggregatedAttestationPool.ts +15 -21
  298. package/src/chain/opPools/opPool.ts +13 -14
  299. package/src/chain/opPools/utils.ts +3 -3
  300. package/src/chain/prepareNextSlot.ts +6 -8
  301. package/src/chain/produceBlock/computeNewStateRoot.ts +6 -10
  302. package/src/chain/produceBlock/produceBlockBody.ts +22 -49
  303. package/src/chain/regen/interface.ts +13 -17
  304. package/src/chain/regen/queued.ts +16 -20
  305. package/src/chain/regen/regen.ts +16 -17
  306. package/src/chain/serializeState.ts +3 -3
  307. package/src/chain/shufflingCache.ts +5 -7
  308. package/src/chain/stateCache/fifoBlockStateCache.ts +7 -7
  309. package/src/chain/stateCache/persistentCheckpointsCache.ts +27 -42
  310. package/src/chain/stateCache/types.ts +14 -18
  311. package/src/chain/validation/attesterSlashing.ts +3 -3
  312. package/src/chain/validation/blobSidecar.ts +1 -1
  313. package/src/chain/validation/block.ts +2 -4
  314. package/src/chain/validation/blsToExecutionChange.ts +2 -2
  315. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  316. package/src/chain/validation/executionPayloadBid.ts +3 -7
  317. package/src/chain/validation/executionPayloadEnvelope.ts +2 -8
  318. package/src/chain/validation/payloadAttestationMessage.ts +2 -4
  319. package/src/chain/validation/proposerSlashing.ts +1 -1
  320. package/src/chain/validation/signatureSets/contributionAndProof.ts +2 -7
  321. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -7
  322. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -2
  323. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -7
  324. package/src/chain/validation/syncCommittee.ts +21 -20
  325. package/src/chain/validation/syncCommitteeContributionAndProof.ts +5 -10
  326. package/src/chain/validation/voluntaryExit.ts +3 -8
  327. package/src/chain/validatorMonitor.ts +12 -11
  328. package/src/metrics/metrics/lodestar.ts +23 -19
  329. package/src/network/gossip/encoding.ts +16 -0
  330. package/src/network/interface.ts +15 -2
  331. package/src/network/libp2p/index.ts +5 -0
  332. package/src/network/network.ts +32 -4
  333. package/src/network/processor/extractSlotRootFns.ts +1 -1
  334. package/src/network/processor/gossipHandlers.ts +9 -8
  335. package/src/network/processor/index.ts +110 -89
  336. package/src/network/reqresp/ReqRespBeaconNode.ts +13 -0
  337. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +94 -0
  338. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +43 -0
  339. package/src/network/reqresp/handlers/index.ts +12 -0
  340. package/src/network/reqresp/protocols.ts +12 -0
  341. package/src/network/reqresp/rateLimit.ts +18 -0
  342. package/src/network/reqresp/score.ts +2 -0
  343. package/src/network/reqresp/types.ts +13 -0
  344. package/src/node/nodejs.ts +3 -5
  345. package/src/node/notifier.ts +4 -10
  346. package/src/sync/backfill/backfill.ts +3 -3
  347. package/src/sync/unknownBlock.ts +10 -50
  348. package/src/util/types.ts +6 -0
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import {PrivateKey} from "@libp2p/interface";
3
- import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
3
+ import {Type} from "@chainsafe/ssz";
4
4
  import {BeaconConfig} from "@lodestar/config";
5
5
  import {
6
6
  CheckpointWithPayloadStatus,
@@ -14,30 +14,21 @@ import {LoggerNode} from "@lodestar/logger/node";
14
14
  import {
15
15
  BUILDER_INDEX_SELF_BUILD,
16
16
  EFFECTIVE_BALANCE_INCREMENT,
17
- ForkPostFulu,
17
+ type ForkPostFulu,
18
18
  GENESIS_SLOT,
19
19
  SLOTS_PER_EPOCH,
20
20
  isForkPostElectra,
21
21
  isForkPostGloas,
22
22
  } from "@lodestar/params";
23
23
  import {
24
- BeaconStateAllForks,
25
- BeaconStateElectra,
26
- CachedBeaconStateAllForks,
27
- CachedBeaconStateGloas,
28
24
  EffectiveBalanceIncrements,
29
25
  EpochShuffling,
26
+ IBeaconStateView,
30
27
  PubkeyCache,
31
- computeAnchorCheckpoint,
32
- computeAttestationsRewards,
33
- computeBlockRewards,
34
28
  computeEndSlotAtEpoch,
35
29
  computeEpochAtSlot,
36
30
  computeStartSlotAtEpoch,
37
- computeSyncCommitteeRewards,
38
- getEffectiveBalanceIncrementsZeroInactive,
39
31
  getEffectiveBalancesFromStateBytes,
40
- processSlots,
41
32
  } from "@lodestar/state-transition";
42
33
  import {
43
34
  BeaconBlock,
@@ -283,7 +274,7 @@ export class BeaconChain implements IBeaconChain {
283
274
  clock?: IClock;
284
275
  metrics: Metrics | null;
285
276
  validatorMonitor: ValidatorMonitor | null;
286
- anchorState: CachedBeaconStateAllForks;
277
+ anchorState: IBeaconStateView;
287
278
  isAnchorStateFinalized: boolean;
288
279
  executionEngine: IExecutionEngine;
289
280
  executionBuilder?: IExecutionBuilder;
@@ -359,16 +350,16 @@ export class BeaconChain implements IBeaconChain {
359
350
 
360
351
  this.shufflingCache = new ShufflingCache(metrics, logger, this.opts, [
361
352
  {
362
- shuffling: anchorState.epochCtx.previousShuffling,
363
- decisionRoot: anchorState.epochCtx.previousDecisionRoot,
353
+ shuffling: anchorState.getPreviousShuffling(),
354
+ decisionRoot: anchorState.previousDecisionRoot,
364
355
  },
365
356
  {
366
- shuffling: anchorState.epochCtx.currentShuffling,
367
- decisionRoot: anchorState.epochCtx.currentDecisionRoot,
357
+ shuffling: anchorState.getCurrentShuffling(),
358
+ decisionRoot: anchorState.currentDecisionRoot,
368
359
  },
369
360
  {
370
- shuffling: anchorState.epochCtx.nextShuffling,
371
- decisionRoot: anchorState.epochCtx.nextDecisionRoot,
361
+ shuffling: anchorState.getNextShuffling(),
362
+ decisionRoot: anchorState.nextDecisionRoot,
372
363
  },
373
364
  ]);
374
365
 
@@ -377,7 +368,7 @@ export class BeaconChain implements IBeaconChain {
377
368
 
378
369
  const fileDataStore = opts.nHistoricalStatesFileDataStore ?? true;
379
370
  const blockStateCache = new FIFOBlockStateCache(this.opts, {metrics});
380
- this.bufferPool = new BufferPool(anchorState.type.tree_serializedSize(anchorState.node), metrics);
371
+ this.bufferPool = new BufferPool(anchorState.serializedSize(), metrics);
381
372
 
382
373
  this.cpStateDatastore = fileDataStore ? new FileCPStateDatastore(dataDir) : new DbCPStateDatastore(this.db);
383
374
  const checkpointStateCache: CheckpointStateCache = new PersistentCheckpointStateCache(
@@ -393,10 +384,10 @@ export class BeaconChain implements IBeaconChain {
393
384
  this.opts
394
385
  );
395
386
 
396
- const {checkpoint} = computeAnchorCheckpoint(config, anchorState);
387
+ const {checkpoint} = anchorState.computeAnchorCheckpoint();
397
388
  blockStateCache.add(anchorState);
398
389
  blockStateCache.setHeadState(anchorState);
399
- const payloadPresent = getCheckpointPayloadStatus(anchorState, checkpoint.epoch) === PayloadStatus.FULL;
390
+ const payloadPresent = getCheckpointPayloadStatus(config, anchorState, checkpoint.epoch) === PayloadStatus.FULL;
400
391
  checkpointStateCache.add(checkpoint, anchorState, payloadPresent);
401
392
 
402
393
  const forkChoice = initializeForkChoice(
@@ -557,7 +548,7 @@ export class BeaconChain implements IBeaconChain {
557
548
  await this.opPool.toPersisted(this.db);
558
549
  }
559
550
 
560
- getHeadState(): CachedBeaconStateAllForks {
551
+ getHeadState(): IBeaconStateView {
561
552
  // head state should always exist
562
553
  const head = this.forkChoice.getHead();
563
554
  const headState = this.regen.getClosestHeadState(head);
@@ -567,11 +558,11 @@ export class BeaconChain implements IBeaconChain {
567
558
  return headState;
568
559
  }
569
560
 
570
- async getHeadStateAtCurrentEpoch(regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
561
+ async getHeadStateAtCurrentEpoch(regenCaller: RegenCaller): Promise<IBeaconStateView> {
571
562
  return this.getHeadStateAtEpoch(this.clock.currentEpoch, regenCaller);
572
563
  }
573
564
 
574
- async getHeadStateAtEpoch(epoch: Epoch, regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
565
+ async getHeadStateAtEpoch(epoch: Epoch, regenCaller: RegenCaller): Promise<IBeaconStateView> {
575
566
  // using getHeadState() means we'll use checkpointStateCache if it's available
576
567
  const headState = this.getHeadState();
577
568
  // head state is in the same epoch, or we pulled up head state already from past epoch
@@ -588,7 +579,7 @@ export class BeaconChain implements IBeaconChain {
588
579
  async getStateBySlot(
589
580
  slot: Slot,
590
581
  opts?: StateGetOpts
591
- ): Promise<{state: CachedBeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null> {
582
+ ): Promise<{state: IBeaconStateView; executionOptimistic: boolean; finalized: boolean} | null> {
592
583
  const finalizedBlock = this.forkChoice.getFinalizedBlock();
593
584
 
594
585
  if (slot < finalizedBlock.slot) {
@@ -638,15 +629,17 @@ export class BeaconChain implements IBeaconChain {
638
629
  async getStateByStateRoot(
639
630
  stateRoot: RootHex,
640
631
  opts?: StateGetOpts
641
- ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
632
+ ): Promise<{state: IBeaconStateView | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
642
633
  if (opts?.allowRegen) {
643
634
  const state = await this.regen.getState(stateRoot, RegenCaller.restApi);
644
- const block = this.forkChoice.getBlockDefaultStatus(state.latestBlockHeader.hashTreeRoot());
635
+ const block = this.forkChoice.getBlockDefaultStatus(
636
+ ssz.phase0.BeaconBlockHeader.hashTreeRoot(state.latestBlockHeader)
637
+ );
645
638
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
646
639
  return {
647
640
  state,
648
641
  executionOptimistic: block != null && isOptimisticBlock(block),
649
- finalized: state.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
642
+ finalized: state.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
650
643
  };
651
644
  }
652
645
 
@@ -657,12 +650,14 @@ export class BeaconChain implements IBeaconChain {
657
650
  // TODO: This is very inneficient for debug requests of serialized content, since it deserializes to serialize again
658
651
  const cachedStateCtx = this.regen.getStateSync(stateRoot);
659
652
  if (cachedStateCtx) {
660
- const block = this.forkChoice.getBlockDefaultStatus(cachedStateCtx.latestBlockHeader.hashTreeRoot());
653
+ const block = this.forkChoice.getBlockDefaultStatus(
654
+ ssz.phase0.BeaconBlockHeader.hashTreeRoot(cachedStateCtx.latestBlockHeader)
655
+ );
661
656
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
662
657
  return {
663
658
  state: cachedStateCtx,
664
659
  executionOptimistic: block != null && isOptimisticBlock(block),
665
- finalized: cachedStateCtx.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
660
+ finalized: cachedStateCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
666
661
  };
667
662
  }
668
663
 
@@ -689,17 +684,19 @@ export class BeaconChain implements IBeaconChain {
689
684
 
690
685
  getStateByCheckpoint(
691
686
  checkpoint: CheckpointWithPayloadStatus
692
- ): {state: BeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null {
687
+ ): {state: IBeaconStateView; executionOptimistic: boolean; finalized: boolean} | null {
693
688
  // finalized or justified checkpoint states maynot be available with PersistentCheckpointStateCache, use getCheckpointStateOrBytes() api to get Uint8Array
694
689
  const checkpointHexPayload = fcCheckpointToHexPayload(checkpoint);
695
690
  const cachedStateCtx = this.regen.getCheckpointStateSync(checkpointHexPayload);
696
691
  if (cachedStateCtx) {
697
- const block = this.forkChoice.getBlockDefaultStatus(cachedStateCtx.latestBlockHeader.hashTreeRoot());
692
+ const block = this.forkChoice.getBlockDefaultStatus(
693
+ ssz.phase0.BeaconBlockHeader.hashTreeRoot(cachedStateCtx.latestBlockHeader)
694
+ );
698
695
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
699
696
  return {
700
697
  state: cachedStateCtx,
701
698
  executionOptimistic: block != null && isOptimisticBlock(block),
702
- finalized: cachedStateCtx.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
699
+ finalized: cachedStateCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
703
700
  };
704
701
  }
705
702
 
@@ -708,7 +705,7 @@ export class BeaconChain implements IBeaconChain {
708
705
 
709
706
  async getStateOrBytesByCheckpoint(
710
707
  checkpoint: CheckpointWithPayloadStatus
711
- ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
708
+ ): Promise<{state: IBeaconStateView | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
712
709
  const checkpointHexPayload = fcCheckpointToHexPayload(checkpoint);
713
710
  const cachedStateCtx = await this.regen.getCheckpointStateOrBytes(checkpointHexPayload);
714
711
  if (cachedStateCtx) {
@@ -858,6 +855,24 @@ export class BeaconChain implements IBeaconChain {
858
855
  return null;
859
856
  }
860
857
 
858
+ async getSerializedExecutionPayloadEnvelope(blockSlot: Slot, blockRootHex: string): Promise<Uint8Array | null> {
859
+ const payloadInput = this.seenPayloadEnvelopeInputCache.get(blockRootHex);
860
+ if (payloadInput?.hasPayloadEnvelope()) {
861
+ const envelope = payloadInput.getPayloadEnvelope();
862
+ const serialized = this.serializedCache.get(envelope);
863
+ if (serialized) {
864
+ return serialized;
865
+ }
866
+ return ssz.gloas.SignedExecutionPayloadEnvelope.serialize(envelope);
867
+ }
868
+
869
+ return (
870
+ (await this.db.executionPayloadEnvelope.getBinary(fromHex(blockRootHex))) ??
871
+ (await this.db.executionPayloadEnvelopeArchive.getBinary(blockSlot)) ??
872
+ null
873
+ );
874
+ }
875
+
861
876
  async getDataColumnSidecars(blockSlot: Slot, blockRootHex: string): Promise<DataColumnSidecars> {
862
877
  const blockInput = this.seenBlockInputCache.get(blockRootHex);
863
878
  if (blockInput) {
@@ -952,14 +967,13 @@ export class BeaconChain implements IBeaconChain {
952
967
  consensusBlockValue: Wei;
953
968
  shouldOverrideBuilder?: boolean;
954
969
  }> {
955
- const fork = this.config.getForkName(slot);
956
970
  const state = await this.regen.getBlockSlotState(
957
971
  parentBlock,
958
972
  slot,
959
973
  {dontTransferCache: true},
960
974
  RegenCaller.produceBlock
961
975
  );
962
- const proposerIndex = state.epochCtx.getBeaconProposer(slot);
976
+ const proposerIndex = state.getBeaconProposer(slot);
963
977
  const proposerPubKey = this.pubkeyCache.getOrThrow(proposerIndex).toBytes();
964
978
 
965
979
  const {body, produceResult, executionPayloadValue, shouldOverrideBuilder} = await produceBlockBody.call(
@@ -981,7 +995,7 @@ export class BeaconChain implements IBeaconChain {
981
995
  // The hashtree root computed here for debug log will get cached and hence won't introduce additional delays
982
996
  const bodyRoot =
983
997
  produceResult.type === BlockType.Full
984
- ? sszTypesFor(fork).BeaconBlockBody.hashTreeRoot(body)
998
+ ? this.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(body)
985
999
  : this.config
986
1000
  .getPostBellatrixForkTypes(slot)
987
1001
  .BlindedBeaconBlockBody.hashTreeRoot(body as BlindedBeaconBlockBody);
@@ -1003,10 +1017,11 @@ export class BeaconChain implements IBeaconChain {
1003
1017
  block.stateRoot = newStateRoot;
1004
1018
  const blockRoot =
1005
1019
  produceResult.type === BlockType.Full
1006
- ? sszTypesFor(fork).BeaconBlock.hashTreeRoot(block)
1020
+ ? this.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block)
1007
1021
  : this.config.getPostBellatrixForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block as BlindedBeaconBlock);
1008
1022
  const blockRootHex = toRootHex(blockRoot);
1009
1023
 
1024
+ const fork = this.config.getForkName(slot);
1010
1025
  if (isForkPostGloas(fork)) {
1011
1026
  // TODO GLOAS: we should retire BlockType post-gloas, may need a new enum for self vs non-self built
1012
1027
  if (produceResult.type !== BlockType.Full) {
@@ -1022,7 +1037,7 @@ export class BeaconChain implements IBeaconChain {
1022
1037
  slot,
1023
1038
  stateRoot: ZERO_HASH,
1024
1039
  };
1025
- const envelopeStateRoot = computeEnvelopeStateRoot(this.metrics, postState as CachedBeaconStateGloas, envelope);
1040
+ const envelopeStateRoot = computeEnvelopeStateRoot(this.metrics, postState, envelope);
1026
1041
  gloasResult.envelopeStateRoot = envelopeStateRoot;
1027
1042
  }
1028
1043
 
@@ -1143,8 +1158,8 @@ export class BeaconChain implements IBeaconChain {
1143
1158
  * persist preState, postState and block for further investigation.
1144
1159
  */
1145
1160
  async persistInvalidStateRoot(
1146
- preState: CachedBeaconStateAllForks,
1147
- postState: CachedBeaconStateAllForks,
1161
+ preState: IBeaconStateView,
1162
+ postState: IBeaconStateView,
1148
1163
  block: SignedBeaconBlock
1149
1164
  ): Promise<void> {
1150
1165
  const blockSlot = block.message.slot;
@@ -1159,13 +1174,13 @@ export class BeaconChain implements IBeaconChain {
1159
1174
  `${logStr}_block`
1160
1175
  ),
1161
1176
  this.persistSszObject(
1162
- `preState_slot_${preState.slot}_${preState.type.typeName}`,
1177
+ `preState_slot_${preState.slot}_BeaconState`,
1163
1178
  preState.serialize(),
1164
1179
  preState.hashTreeRoot(),
1165
1180
  `${logStr}_pre_state`
1166
1181
  ),
1167
1182
  this.persistSszObject(
1168
- `postState_slot_${postState.slot}_${postState.type.typeName}`,
1183
+ `postState_slot_${postState.slot}_BeaconState`,
1169
1184
  postState.serialize(),
1170
1185
  postState.hashTreeRoot(),
1171
1186
  `${logStr}_post_state`
@@ -1185,12 +1200,6 @@ export class BeaconChain implements IBeaconChain {
1185
1200
  }
1186
1201
  }
1187
1202
 
1188
- persistInvalidSszView(view: TreeView<CompositeTypeAny>, suffix?: string): void {
1189
- if (this.opts.persistInvalidSszObjects) {
1190
- void this.persistSszObject(view.type.typeName, view.serialize(), view.hashTreeRoot(), suffix);
1191
- }
1192
- }
1193
-
1194
1203
  /**
1195
1204
  * Regenerate state for attestation verification, this does not happen with default chain option of maxSkipSlots = 32 .
1196
1205
  * However, need to handle just in case. Lodestar doesn't support multiple regen state requests for attestation verification
@@ -1208,7 +1217,7 @@ export class BeaconChain implements IBeaconChain {
1208
1217
  this.shufflingCache.insertPromise(attEpoch, shufflingDependentRoot);
1209
1218
  const blockEpoch = computeEpochAtSlot(attHeadBlock.slot);
1210
1219
 
1211
- let state: CachedBeaconStateAllForks;
1220
+ let state: IBeaconStateView;
1212
1221
  if (blockEpoch < attEpoch - 1) {
1213
1222
  // thanks to one epoch look ahead, we don't need to dial up to attEpoch
1214
1223
  const targetSlot = computeStartSlotAtEpoch(attEpoch - 1);
@@ -1226,7 +1235,7 @@ export class BeaconChain implements IBeaconChain {
1226
1235
  }
1227
1236
  // resolve the promise to unblock other calls of the same epoch and dependent root
1228
1237
  this.shufflingCache.processState(state);
1229
- return state.epochCtx.getShufflingAtEpoch(attEpoch);
1238
+ return state.getShufflingAtEpoch(attEpoch);
1230
1239
  }
1231
1240
 
1232
1241
  /**
@@ -1236,7 +1245,7 @@ export class BeaconChain implements IBeaconChain {
1236
1245
  */
1237
1246
  private justifiedBalancesGetter(
1238
1247
  checkpoint: CheckpointWithPayloadStatus,
1239
- blockState: CachedBeaconStateAllForks
1248
+ blockState: IBeaconStateView
1240
1249
  ): EffectiveBalanceIncrements {
1241
1250
  this.metrics?.balancesCache.requests.inc();
1242
1251
 
@@ -1263,7 +1272,7 @@ export class BeaconChain implements IBeaconChain {
1263
1272
  });
1264
1273
  }
1265
1274
 
1266
- return getEffectiveBalanceIncrementsZeroInactive(state);
1275
+ return state.getEffectiveBalanceIncrementsZeroInactive();
1267
1276
  }
1268
1277
 
1269
1278
  /**
@@ -1275,8 +1284,8 @@ export class BeaconChain implements IBeaconChain {
1275
1284
  */
1276
1285
  private closestJustifiedBalancesStateToCheckpoint(
1277
1286
  checkpoint: CheckpointWithPayloadStatus,
1278
- blockState: CachedBeaconStateAllForks
1279
- ): {state: CachedBeaconStateAllForks; stateId: string; shouldWarn: boolean} {
1287
+ blockState: IBeaconStateView
1288
+ ): {state: IBeaconStateView; stateId: string; shouldWarn: boolean} {
1280
1289
  const checkpointHexPayload = fcCheckpointToHexPayload(checkpoint);
1281
1290
  const state = this.regen.getCheckpointStateSync(checkpointHexPayload);
1282
1291
  if (state) {
@@ -1359,10 +1368,9 @@ export class BeaconChain implements IBeaconChain {
1359
1368
  const fork = this.config.getForkName(headState.slot);
1360
1369
 
1361
1370
  if (isForkPostElectra(fork)) {
1362
- const headStateElectra = headState as BeaconStateElectra;
1363
- metrics.pendingDeposits.set(headStateElectra.pendingDeposits.length);
1364
- metrics.pendingPartialWithdrawals.set(headStateElectra.pendingPartialWithdrawals.length);
1365
- metrics.pendingConsolidations.set(headStateElectra.pendingConsolidations.length);
1371
+ metrics.pendingDeposits.set(headState.pendingDepositsCount);
1372
+ metrics.pendingPartialWithdrawals.set(headState.pendingPartialWithdrawalsCount);
1373
+ metrics.pendingConsolidations.set(headState.pendingConsolidationsCount);
1366
1374
  }
1367
1375
  }
1368
1376
 
@@ -1426,7 +1434,7 @@ export class BeaconChain implements IBeaconChain {
1426
1434
  this.logger.verbose("Fork choice justified", {epoch: cp.epoch, root: cp.rootHex});
1427
1435
  }
1428
1436
 
1429
- private onCheckpoint(this: BeaconChain, _checkpoint: phase0.Checkpoint, state: CachedBeaconStateAllForks): void {
1437
+ private onCheckpoint(this: BeaconChain, _checkpoint: phase0.Checkpoint, state: IBeaconStateView): void {
1430
1438
  // Defer to not block other checkpoint event handlers, which can cause lightclient update delays
1431
1439
  callInNextEventLoop(() => {
1432
1440
  this.shufflingCache.processState(state);
@@ -1512,7 +1520,7 @@ export class BeaconChain implements IBeaconChain {
1512
1520
  if (stateOrBytes instanceof Uint8Array) {
1513
1521
  effectiveBalances = getEffectiveBalancesFromStateBytes(this.config, stateOrBytes, validatorIndices);
1514
1522
  } else {
1515
- effectiveBalances = validatorIndices.map((index) => stateOrBytes.validators.get(index).effectiveBalance ?? 0);
1523
+ effectiveBalances = validatorIndices.map((index) => stateOrBytes.getValidator(index).effectiveBalance ?? 0);
1516
1524
  }
1517
1525
  }
1518
1526
 
@@ -1562,11 +1570,11 @@ export class BeaconChain implements IBeaconChain {
1562
1570
  throw Error(`Pre-state is unavailable given block's parent root ${toRootHex(block.parentRoot)}`);
1563
1571
  }
1564
1572
 
1565
- preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1573
+ preState = preState.processSlots(block.slot); // Dial preState's slot to block.slot
1566
1574
 
1567
1575
  const proposerRewards = this.regen.getStateSync(toRootHex(block.stateRoot))?.proposerRewards ?? undefined;
1568
1576
 
1569
- return computeBlockRewards(this.config, block, preState, proposerRewards);
1577
+ return preState.computeBlockRewards(block, proposerRewards);
1570
1578
  }
1571
1579
 
1572
1580
  async getAttestationsRewards(
@@ -1590,7 +1598,7 @@ export class BeaconChain implements IBeaconChain {
1590
1598
  throw Error(`State is not in cache for slot ${slot}`);
1591
1599
  }
1592
1600
 
1593
- const rewards = await computeAttestationsRewards(this.config, this.pubkeyCache, cachedState, validatorIds);
1601
+ const rewards = await cachedState.computeAttestationsRewards(validatorIds);
1594
1602
 
1595
1603
  return {rewards, executionOptimistic, finalized};
1596
1604
  }
@@ -1605,8 +1613,8 @@ export class BeaconChain implements IBeaconChain {
1605
1613
  throw Error(`Pre-state is unavailable given block's parent root ${toRootHex(block.parentRoot)}`);
1606
1614
  }
1607
1615
 
1608
- preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1616
+ preState = preState.processSlots(block.slot); // Dial preState's slot to block.slot
1609
1617
 
1610
- return computeSyncCommitteeRewards(this.config, this.pubkeyCache, block, preState, validatorIds);
1618
+ return preState.computeSyncCommitteeRewards(block, validatorIds ?? []);
1611
1619
  }
1612
1620
  }
@@ -2,7 +2,7 @@ import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {routes} from "@lodestar/api";
4
4
  import {CheckpointWithPayloadStatus} from "@lodestar/fork-choice";
5
- import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
5
+ import {IBeaconStateView} from "@lodestar/state-transition";
6
6
  import {DataColumnSidecars, RootHex, deneb, phase0} from "@lodestar/types";
7
7
  import {PeerIdStr} from "../util/peerId.js";
8
8
  import {BlockInputSource, IBlockInput} from "./blocks/blockInput/types.js";
@@ -81,7 +81,7 @@ export type ChainEventData = {
81
81
  };
82
82
 
83
83
  export type IChainEvents = ApiEvents & {
84
- [ChainEvent.checkpoint]: (checkpoint: phase0.Checkpoint, state: CachedBeaconStateAllForks) => void;
84
+ [ChainEvent.checkpoint]: (checkpoint: phase0.Checkpoint, state: IBeaconStateView) => void;
85
85
 
86
86
  [ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithPayloadStatus) => void;
87
87
  [ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithPayloadStatus) => void;
@@ -1,4 +1,4 @@
1
- import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
1
+ import {IBeaconStateView} from "@lodestar/state-transition";
2
2
  import {RootHex, SignedBeaconBlock, Slot, ValidatorIndex} from "@lodestar/types";
3
3
  import {LodestarError, toRootHex} from "@lodestar/utils";
4
4
  import {ExecutionPayloadStatus} from "../../execution/engine/interface.js";
@@ -91,13 +91,13 @@ export type BlockErrorType =
91
91
  | {code: BlockErrorCode.INCORRECT_PROPOSER; proposerIndex: ValidatorIndex}
92
92
  | {code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID; blockSlot: Slot}
93
93
  | {code: BlockErrorCode.UNKNOWN_PROPOSER; proposerIndex: ValidatorIndex}
94
- | {code: BlockErrorCode.INVALID_SIGNATURE; state: CachedBeaconStateAllForks}
94
+ | {code: BlockErrorCode.INVALID_SIGNATURE; state: IBeaconStateView}
95
95
  | {
96
96
  code: BlockErrorCode.INVALID_STATE_ROOT;
97
97
  root: Uint8Array;
98
98
  expectedRoot: Uint8Array;
99
- preState: CachedBeaconStateAllForks;
100
- postState: CachedBeaconStateAllForks;
99
+ preState: IBeaconStateView;
100
+ postState: IBeaconStateView;
101
101
  }
102
102
  | {code: BlockErrorCode.NOT_FINALIZED_DESCENDANT; parentRoot: RootHex}
103
103
  | {code: BlockErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
@@ -10,18 +10,12 @@ import {
10
10
  ForkChoiceOpts as RawForkChoiceOpts,
11
11
  getCheckpointPayloadStatus,
12
12
  } from "@lodestar/fork-choice";
13
- import {ZERO_HASH_HEX} from "@lodestar/params";
13
+ import {ForkSeq, ZERO_HASH_HEX} from "@lodestar/params";
14
14
  import {
15
- CachedBeaconStateAllForks,
16
- CachedBeaconStateGloas,
17
15
  DataAvailabilityStatus,
18
- computeAnchorCheckpoint,
16
+ IBeaconStateView,
19
17
  computeEpochAtSlot,
20
18
  computeStartSlotAtEpoch,
21
- getBlockRootAtSlot,
22
- getEffectiveBalanceIncrementsZeroInactive,
23
- isExecutionStateType,
24
- isMergeTransitionComplete,
25
19
  } from "@lodestar/state-transition";
26
20
  import {Slot, ssz} from "@lodestar/types";
27
21
  import {Logger, toRootHex} from "@lodestar/utils";
@@ -46,7 +40,7 @@ export function initializeForkChoice(
46
40
  config: ChainForkConfig,
47
41
  emitter: ChainEventEmitter,
48
42
  currentSlot: Slot,
49
- state: CachedBeaconStateAllForks,
43
+ state: IBeaconStateView,
50
44
  isFinalizedState: boolean,
51
45
  opts: ForkChoiceOpts,
52
46
  justifiedBalancesGetter: JustifiedBalancesGetter,
@@ -83,13 +77,13 @@ export function initializeForkChoiceFromFinalizedState(
83
77
  config: ChainForkConfig,
84
78
  emitter: ChainEventEmitter,
85
79
  currentSlot: Slot,
86
- state: CachedBeaconStateAllForks,
80
+ state: IBeaconStateView,
87
81
  opts: ForkChoiceOpts,
88
82
  justifiedBalancesGetter: JustifiedBalancesGetter,
89
83
  metrics: Metrics | null,
90
84
  logger?: Logger
91
85
  ): ForkChoice {
92
- const {blockHeader, checkpoint} = computeAnchorCheckpoint(config, state);
86
+ const {blockHeader, checkpoint} = state.computeAnchorCheckpoint();
93
87
  const finalizedCheckpoint = {...checkpoint};
94
88
  const justifiedCheckpoint = {
95
89
  ...checkpoint,
@@ -100,19 +94,19 @@ export function initializeForkChoiceFromFinalizedState(
100
94
  epoch: checkpoint.epoch === 0 ? checkpoint.epoch : checkpoint.epoch + 1,
101
95
  };
102
96
 
103
- const justifiedBalances = getEffectiveBalanceIncrementsZeroInactive(state);
97
+ const justifiedBalances = state.getEffectiveBalanceIncrementsZeroInactive();
104
98
 
105
99
  // forkchoiceConstructor is only used for some test cases
106
100
  // production code use ForkChoice constructor directly
107
101
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
108
102
 
109
- const isForkPostGloas = (state as CachedBeaconStateGloas).latestBlockHash !== undefined;
103
+ const isForkPostGloas = computeEpochAtSlot(state.slot) >= config.GLOAS_FORK_EPOCH;
110
104
 
111
105
  // Determine justified checkpoint payload status
112
- const justifiedPayloadStatus = getCheckpointPayloadStatus(state, justifiedCheckpoint.epoch);
106
+ const justifiedPayloadStatus = getCheckpointPayloadStatus(config, state, justifiedCheckpoint.epoch);
113
107
 
114
108
  // Determine finalized checkpoint payload status
115
- const finalizedPayloadStatus = getCheckpointPayloadStatus(state, finalizedCheckpoint.epoch);
109
+ const finalizedPayloadStatus = getCheckpointPayloadStatus(config, state, finalizedCheckpoint.epoch);
116
110
 
117
111
  return new forkchoiceConstructor(
118
112
  config,
@@ -148,21 +142,23 @@ export function initializeForkChoiceFromFinalizedState(
148
142
  unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
149
143
  unrealizedFinalizedRoot: toRootHex(finalizedCheckpoint.root),
150
144
 
151
- ...(isExecutionStateType(state) && isMergeTransitionComplete(state)
145
+ ...(state.isExecutionStateType && state.isMergeTransitionComplete
152
146
  ? {
153
- executionPayloadBlockHash: toRootHex(state.latestExecutionPayloadHeader.blockHash),
154
- executionPayloadNumber: state.latestExecutionPayloadHeader.blockNumber,
147
+ executionPayloadBlockHash: toRootHex(state.latestBlockHash),
148
+ // TODO GLOAS: executionPayloadNumber is not tracked in BeaconState post-gloas (EIP-7732 removed
149
+ // latestExecutionPayloadHeader). Using 0 as unavailable fallback until a solution is found.
150
+ executionPayloadNumber: config.getForkSeq(state.slot) >= ForkSeq.gloas ? 0 : state.payloadBlockNumber,
155
151
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
156
152
  }
157
153
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
158
154
 
159
155
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
160
156
  payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL, // TODO GLOAS: Post-gloas how do we know if the checkpoint payload is FULL or EMPTY?
161
- parentBlockHash: isForkPostGloas ? toRootHex((state as CachedBeaconStateGloas).latestBlockHash) : null,
157
+ parentBlockHash: isForkPostGloas ? toRootHex(state.latestBlockHash) : null,
162
158
  },
163
159
  currentSlot
164
160
  ),
165
- state.validators.length,
161
+ state.validatorCount,
166
162
  metrics,
167
163
  opts,
168
164
  logger
@@ -176,15 +172,15 @@ export function initializeForkChoiceFromUnfinalizedState(
176
172
  config: ChainForkConfig,
177
173
  emitter: ChainEventEmitter,
178
174
  currentSlot: Slot,
179
- unfinalizedState: CachedBeaconStateAllForks,
175
+ unfinalizedState: IBeaconStateView,
180
176
  opts: ForkChoiceOpts,
181
177
  justifiedBalancesGetter: JustifiedBalancesGetter,
182
178
  metrics: Metrics | null,
183
179
  logger?: Logger
184
180
  ): ForkChoice {
185
- const {blockHeader} = computeAnchorCheckpoint(config, unfinalizedState);
186
- const finalizedCheckpoint = unfinalizedState.finalizedCheckpoint.toValue();
187
- const justifiedCheckpoint = unfinalizedState.currentJustifiedCheckpoint.toValue();
181
+ const {blockHeader} = unfinalizedState.computeAnchorCheckpoint();
182
+ const finalizedCheckpoint = unfinalizedState.finalizedCheckpoint;
183
+ const justifiedCheckpoint = unfinalizedState.currentJustifiedCheckpoint;
188
184
  const headRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader));
189
185
 
190
186
  const logCtx = {
@@ -200,14 +196,14 @@ export function initializeForkChoiceFromUnfinalizedState(
200
196
  logger?.warn("Initializing fork choice from unfinalized state", logCtx);
201
197
 
202
198
  // this is not the justified state, but there is no other ways to get justified balances
203
- const justifiedBalances = getEffectiveBalanceIncrementsZeroInactive(unfinalizedState);
199
+ const justifiedBalances = unfinalizedState.getEffectiveBalanceIncrementsZeroInactive();
204
200
 
205
- const isForkPostGloas = (unfinalizedState as CachedBeaconStateGloas).latestBlockHash !== undefined;
201
+ const isForkPostGloas = computeEpochAtSlot(unfinalizedState.slot) >= config.GLOAS_FORK_EPOCH;
206
202
 
207
203
  // For unfinalized state, use getCheckpointPayloadStatus to determine the correct status.
208
204
  // It checks state.execution_payload_availability to determine EMPTY vs FULL.
209
- const justifiedPayloadStatus = getCheckpointPayloadStatus(unfinalizedState, justifiedCheckpoint.epoch);
210
- const finalizedPayloadStatus = getCheckpointPayloadStatus(unfinalizedState, finalizedCheckpoint.epoch);
205
+ const justifiedPayloadStatus = getCheckpointPayloadStatus(config, unfinalizedState, justifiedCheckpoint.epoch);
206
+ const finalizedPayloadStatus = getCheckpointPayloadStatus(config, unfinalizedState, finalizedCheckpoint.epoch);
211
207
 
212
208
  const store = new ForkChoiceStore(
213
209
  currentSlot,
@@ -241,17 +237,20 @@ export function initializeForkChoiceFromUnfinalizedState(
241
237
  unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
242
238
  unrealizedFinalizedRoot: toRootHex(finalizedCheckpoint.root),
243
239
 
244
- ...(isExecutionStateType(unfinalizedState) && isMergeTransitionComplete(unfinalizedState)
240
+ ...(unfinalizedState.isExecutionStateType && unfinalizedState.isMergeTransitionComplete
245
241
  ? {
246
- executionPayloadBlockHash: toRootHex(unfinalizedState.latestExecutionPayloadHeader.blockHash),
247
- executionPayloadNumber: unfinalizedState.latestExecutionPayloadHeader.blockNumber,
242
+ executionPayloadBlockHash: toRootHex(unfinalizedState.latestBlockHash),
243
+ // TODO GLOAS: executionPayloadNumber is not tracked in BeaconState post-gloas (EIP-7732 removed
244
+ // latestExecutionPayloadHeader). Using 0 as unavailable fallback until a solution is found.
245
+ executionPayloadNumber:
246
+ config.getForkSeq(unfinalizedState.slot) >= ForkSeq.gloas ? 0 : unfinalizedState.payloadBlockNumber,
248
247
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
249
248
  }
250
249
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
251
250
 
252
251
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
253
252
  payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL, // TODO GLOAS: Post-gloas how do we know if the checkpoint payload is FULL or EMPTY?
254
- parentBlockHash: isForkPostGloas ? toRootHex((unfinalizedState as CachedBeaconStateGloas).latestBlockHash) : null,
253
+ parentBlockHash: isForkPostGloas ? toRootHex(unfinalizedState.latestBlockHash) : null,
255
254
  };
256
255
 
257
256
  const parentSlot = blockHeader.slot - 1;
@@ -265,7 +264,7 @@ export function initializeForkChoiceFromUnfinalizedState(
265
264
  // dummy data, we're not able to regen state before headBlock
266
265
  stateRoot: ZERO_HASH_HEX,
267
266
  blockRoot: headBlock.parentRoot,
268
- targetRoot: toRootHex(getBlockRootAtSlot(unfinalizedState, computeStartSlotAtEpoch(parentEpoch))),
267
+ targetRoot: toRootHex(unfinalizedState.getBlockRootAtSlot(computeStartSlotAtEpoch(parentEpoch))),
269
268
  };
270
269
 
271
270
  const justifiedBlock: ProtoBlock = {
@@ -303,13 +302,5 @@ export function initializeForkChoiceFromUnfinalizedState(
303
302
  // production code use ForkChoice constructor directly
304
303
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
305
304
 
306
- return new forkchoiceConstructor(
307
- config,
308
- store,
309
- protoArray,
310
- unfinalizedState.validators.length,
311
- metrics,
312
- opts,
313
- logger
314
- );
305
+ return new forkchoiceConstructor(config, store, protoArray, unfinalizedState.validatorCount, metrics, opts, logger);
315
306
  }
@@ -1,6 +1,11 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
2
  import {ZERO_HASH} from "@lodestar/params";
3
- import {BeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
3
+ import {
4
+ BeaconStateAllForks,
5
+ IBeaconStateView,
6
+ computeEpochAtSlot,
7
+ computeStartSlotAtEpoch,
8
+ } from "@lodestar/state-transition";
4
9
  import {SignedBeaconBlock, ssz} from "@lodestar/types";
5
10
  import {Logger, byteArrayEquals, toHex, toRootHex} from "@lodestar/utils";
6
11
  import {GENESIS_SLOT} from "../constants/index.js";
@@ -119,7 +124,7 @@ export async function checkAndPersistAnchorState(
119
124
  }
120
125
  }
121
126
 
122
- export function initBeaconMetrics(metrics: Metrics, state: BeaconStateAllForks): void {
127
+ export function initBeaconMetrics(metrics: Metrics, state: IBeaconStateView): void {
123
128
  metrics.headSlot.set(state.slot);
124
129
  metrics.previousJustifiedEpoch.set(state.previousJustifiedCheckpoint.epoch);
125
130
  metrics.currentJustifiedEpoch.set(state.currentJustifiedCheckpoint.epoch);