@lodestar/beacon-node 1.39.1 → 1.40.0-dev.193b2e2047

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 (434) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +8 -18
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/state/utils.d.ts +2 -7
  5. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  6. package/lib/api/impl/beacon/state/utils.js +0 -12
  7. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  8. package/lib/api/impl/config/constants.d.ts +3 -0
  9. package/lib/api/impl/config/constants.d.ts.map +1 -1
  10. package/lib/api/impl/config/constants.js +5 -1
  11. package/lib/api/impl/config/constants.js.map +1 -1
  12. package/lib/api/impl/debug/index.d.ts +1 -1
  13. package/lib/api/impl/debug/index.d.ts.map +1 -1
  14. package/lib/api/impl/debug/index.js +3 -6
  15. package/lib/api/impl/debug/index.js.map +1 -1
  16. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  17. package/lib/api/impl/lodestar/index.js +6 -3
  18. package/lib/api/impl/lodestar/index.js.map +1 -1
  19. package/lib/api/impl/proof/index.d.ts.map +1 -1
  20. package/lib/api/impl/proof/index.js +1 -2
  21. package/lib/api/impl/proof/index.js.map +1 -1
  22. package/lib/api/impl/validator/index.d.ts.map +1 -1
  23. package/lib/api/impl/validator/index.js +10 -11
  24. package/lib/api/impl/validator/index.js.map +1 -1
  25. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  26. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -3
  27. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  28. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  29. package/lib/chain/archiveStore/utils/archiveBlocks.js +23 -14
  30. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  31. package/lib/chain/blocks/blockInput/blockInput.d.ts +2 -0
  32. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  33. package/lib/chain/blocks/blockInput/blockInput.js +6 -0
  34. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  35. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  36. package/lib/chain/blocks/importBlock.js +14 -9
  37. package/lib/chain/blocks/importBlock.js.map +1 -1
  38. package/lib/chain/blocks/index.d.ts.map +1 -1
  39. package/lib/chain/blocks/index.js +0 -14
  40. package/lib/chain/blocks/index.js.map +1 -1
  41. package/lib/chain/blocks/types.d.ts +0 -2
  42. package/lib/chain/blocks/types.d.ts.map +1 -1
  43. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  44. package/lib/chain/blocks/verifyBlock.js +9 -9
  45. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  46. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  47. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  48. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
  49. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  50. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  51. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +1 -0
  52. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  53. package/lib/chain/blocks/writeBlockInputToDb.d.ts +1 -4
  54. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
  55. package/lib/chain/blocks/writeBlockInputToDb.js +20 -28
  56. package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
  57. package/lib/chain/bls/multithread/index.d.ts +3 -1
  58. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  59. package/lib/chain/bls/multithread/index.js +5 -3
  60. package/lib/chain/bls/multithread/index.js.map +1 -1
  61. package/lib/chain/bls/multithread/jobItem.d.ts +2 -2
  62. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -1
  63. package/lib/chain/bls/multithread/jobItem.js +2 -2
  64. package/lib/chain/bls/multithread/jobItem.js.map +1 -1
  65. package/lib/chain/bls/singleThread.d.ts +4 -2
  66. package/lib/chain/bls/singleThread.d.ts.map +1 -1
  67. package/lib/chain/bls/singleThread.js +4 -2
  68. package/lib/chain/bls/singleThread.js.map +1 -1
  69. package/lib/chain/bls/utils.d.ts +2 -2
  70. package/lib/chain/bls/utils.d.ts.map +1 -1
  71. package/lib/chain/bls/utils.js +9 -6
  72. package/lib/chain/bls/utils.js.map +1 -1
  73. package/lib/chain/chain.d.ts +24 -6
  74. package/lib/chain/chain.d.ts.map +1 -1
  75. package/lib/chain/chain.js +196 -21
  76. package/lib/chain/chain.js.map +1 -1
  77. package/lib/chain/errors/attestationError.d.ts +14 -1
  78. package/lib/chain/errors/attestationError.d.ts.map +1 -1
  79. package/lib/chain/errors/attestationError.js +8 -0
  80. package/lib/chain/errors/attestationError.js.map +1 -1
  81. package/lib/chain/errors/executionPayloadBid.d.ts +48 -0
  82. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -0
  83. package/lib/chain/errors/executionPayloadBid.js +15 -0
  84. package/lib/chain/errors/executionPayloadBid.js.map +1 -0
  85. package/lib/chain/errors/executionPayloadEnvelope.d.ts +48 -0
  86. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -0
  87. package/lib/chain/errors/executionPayloadEnvelope.js +16 -0
  88. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -0
  89. package/lib/chain/errors/index.d.ts +3 -0
  90. package/lib/chain/errors/index.d.ts.map +1 -1
  91. package/lib/chain/errors/index.js +3 -0
  92. package/lib/chain/errors/index.js.map +1 -1
  93. package/lib/chain/errors/payloadAttestation.d.ts +34 -0
  94. package/lib/chain/errors/payloadAttestation.d.ts.map +1 -0
  95. package/lib/chain/errors/payloadAttestation.js +13 -0
  96. package/lib/chain/errors/payloadAttestation.js.map +1 -0
  97. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  98. package/lib/chain/forkChoice/index.js +18 -0
  99. package/lib/chain/forkChoice/index.js.map +1 -1
  100. package/lib/chain/initState.d.ts +1 -1
  101. package/lib/chain/initState.d.ts.map +1 -1
  102. package/lib/chain/initState.js +5 -3
  103. package/lib/chain/initState.js.map +1 -1
  104. package/lib/chain/interface.d.ts +23 -5
  105. package/lib/chain/interface.d.ts.map +1 -1
  106. package/lib/chain/interface.js.map +1 -1
  107. package/lib/chain/lightClient/proofs.d.ts.map +1 -1
  108. package/lib/chain/lightClient/proofs.js +0 -2
  109. package/lib/chain/lightClient/proofs.js.map +1 -1
  110. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +5 -9
  111. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  112. package/lib/chain/opPools/aggregatedAttestationPool.js +12 -141
  113. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  114. package/lib/chain/opPools/executionPayloadBidPool.d.ts +21 -0
  115. package/lib/chain/opPools/executionPayloadBidPool.d.ts.map +1 -0
  116. package/lib/chain/opPools/executionPayloadBidPool.js +57 -0
  117. package/lib/chain/opPools/executionPayloadBidPool.js.map +1 -0
  118. package/lib/chain/opPools/index.d.ts +2 -0
  119. package/lib/chain/opPools/index.d.ts.map +1 -1
  120. package/lib/chain/opPools/index.js +2 -0
  121. package/lib/chain/opPools/index.js.map +1 -1
  122. package/lib/chain/opPools/opPool.js +5 -8
  123. package/lib/chain/opPools/opPool.js.map +1 -1
  124. package/lib/chain/opPools/payloadAttestationPool.d.ts +24 -0
  125. package/lib/chain/opPools/payloadAttestationPool.d.ts.map +1 -0
  126. package/lib/chain/opPools/payloadAttestationPool.js +109 -0
  127. package/lib/chain/opPools/payloadAttestationPool.js.map +1 -0
  128. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  129. package/lib/chain/prepareNextSlot.js +9 -10
  130. package/lib/chain/prepareNextSlot.js.map +1 -1
  131. package/lib/chain/produceBlock/produceBlockBody.d.ts +3 -2
  132. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  133. package/lib/chain/produceBlock/produceBlockBody.js +6 -4
  134. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  135. package/lib/chain/regen/interface.d.ts +4 -13
  136. package/lib/chain/regen/interface.d.ts.map +1 -1
  137. package/lib/chain/regen/interface.js +1 -1
  138. package/lib/chain/regen/interface.js.map +1 -1
  139. package/lib/chain/regen/queued.d.ts +5 -9
  140. package/lib/chain/regen/queued.d.ts.map +1 -1
  141. package/lib/chain/regen/queued.js +16 -40
  142. package/lib/chain/regen/queued.js.map +1 -1
  143. package/lib/chain/regen/regen.d.ts +4 -8
  144. package/lib/chain/regen/regen.d.ts.map +1 -1
  145. package/lib/chain/regen/regen.js +16 -33
  146. package/lib/chain/regen/regen.js.map +1 -1
  147. package/lib/chain/seenCache/index.d.ts +3 -1
  148. package/lib/chain/seenCache/index.d.ts.map +1 -1
  149. package/lib/chain/seenCache/index.js +3 -1
  150. package/lib/chain/seenCache/index.js.map +1 -1
  151. package/lib/chain/seenCache/seenAttesters.d.ts +5 -0
  152. package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
  153. package/lib/chain/seenCache/seenAttesters.js +5 -0
  154. package/lib/chain/seenCache/seenAttesters.js.map +1 -1
  155. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +12 -0
  156. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -0
  157. package/lib/chain/seenCache/seenExecutionPayloadBids.js +30 -0
  158. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -0
  159. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.d.ts +15 -0
  160. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.d.ts.map +1 -0
  161. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.js +28 -0
  162. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.js.map +1 -0
  163. package/lib/chain/shufflingCache.d.ts +16 -11
  164. package/lib/chain/shufflingCache.d.ts.map +1 -1
  165. package/lib/chain/shufflingCache.js +47 -41
  166. package/lib/chain/shufflingCache.js.map +1 -1
  167. package/lib/chain/stateCache/blockStateCacheImpl.d.ts +1 -2
  168. package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +1 -1
  169. package/lib/chain/stateCache/blockStateCacheImpl.js +2 -2
  170. package/lib/chain/stateCache/blockStateCacheImpl.js.map +1 -1
  171. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +1 -2
  172. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  173. package/lib/chain/stateCache/fifoBlockStateCache.js +4 -4
  174. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  175. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts +4 -5
  176. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +1 -1
  177. package/lib/chain/stateCache/inMemoryCheckpointsCache.js +9 -10
  178. package/lib/chain/stateCache/inMemoryCheckpointsCache.js.map +1 -1
  179. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +5 -6
  180. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  181. package/lib/chain/stateCache/persistentCheckpointsCache.js +17 -17
  182. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  183. package/lib/chain/stateCache/types.d.ts +5 -6
  184. package/lib/chain/stateCache/types.d.ts.map +1 -1
  185. package/lib/chain/stateCache/types.js.map +1 -1
  186. package/lib/chain/validation/aggregateAndProof.js +35 -14
  187. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  188. package/lib/chain/validation/attestation.d.ts +2 -2
  189. package/lib/chain/validation/attestation.d.ts.map +1 -1
  190. package/lib/chain/validation/attestation.js +28 -9
  191. package/lib/chain/validation/attestation.js.map +1 -1
  192. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  193. package/lib/chain/validation/attesterSlashing.js +2 -2
  194. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  195. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  196. package/lib/chain/validation/blobSidecar.js +3 -3
  197. package/lib/chain/validation/blobSidecar.js.map +1 -1
  198. package/lib/chain/validation/block.d.ts.map +1 -1
  199. package/lib/chain/validation/block.js +7 -4
  200. package/lib/chain/validation/block.js.map +1 -1
  201. package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -1
  202. package/lib/chain/validation/blsToExecutionChange.js +9 -2
  203. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  204. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  205. package/lib/chain/validation/dataColumnSidecar.js +3 -3
  206. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  207. package/lib/chain/validation/executionPayloadBid.d.ts +5 -0
  208. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -0
  209. package/lib/chain/validation/executionPayloadBid.js +104 -0
  210. package/lib/chain/validation/executionPayloadBid.js.map +1 -0
  211. package/lib/chain/validation/executionPayloadEnvelope.d.ts +5 -0
  212. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -0
  213. package/lib/chain/validation/executionPayloadEnvelope.js +89 -0
  214. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -0
  215. package/lib/chain/validation/payloadAttestationMessage.d.ts +9 -0
  216. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -0
  217. package/lib/chain/validation/payloadAttestationMessage.js +72 -0
  218. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -0
  219. package/lib/chain/validation/proposerSlashing.js +3 -2
  220. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  221. package/lib/chain/validation/signatureSets/aggregateAndProof.d.ts +2 -3
  222. package/lib/chain/validation/signatureSets/aggregateAndProof.d.ts.map +1 -1
  223. package/lib/chain/validation/signatureSets/aggregateAndProof.js +8 -3
  224. package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
  225. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  226. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  227. package/lib/chain/validation/signatureSets/contributionAndProof.js +3 -3
  228. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  229. package/lib/chain/validation/signatureSets/selectionProof.d.ts +2 -3
  230. package/lib/chain/validation/signatureSets/selectionProof.d.ts.map +1 -1
  231. package/lib/chain/validation/signatureSets/selectionProof.js +8 -3
  232. package/lib/chain/validation/signatureSets/selectionProof.js.map +1 -1
  233. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  234. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  235. package/lib/chain/validation/signatureSets/syncCommittee.js +3 -3
  236. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  237. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +1 -2
  238. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  239. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  240. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  241. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  242. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  243. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +3 -3
  244. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  245. package/lib/chain/validation/syncCommittee.js +1 -1
  246. package/lib/chain/validation/syncCommittee.js.map +1 -1
  247. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  248. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -5
  249. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  250. package/lib/chain/validation/voluntaryExit.js +1 -1
  251. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  252. package/lib/chain/validatorMonitor.d.ts +2 -0
  253. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  254. package/lib/chain/validatorMonitor.js +42 -3
  255. package/lib/chain/validatorMonitor.js.map +1 -1
  256. package/lib/db/repositories/checkpointState.d.ts +2 -6
  257. package/lib/db/repositories/checkpointState.d.ts.map +1 -1
  258. package/lib/db/repositories/checkpointState.js +3 -16
  259. package/lib/db/repositories/checkpointState.js.map +1 -1
  260. package/lib/db/repositories/stateArchive.d.ts +9 -9
  261. package/lib/db/repositories/stateArchive.d.ts.map +1 -1
  262. package/lib/db/repositories/stateArchive.js +6 -21
  263. package/lib/db/repositories/stateArchive.js.map +1 -1
  264. package/lib/execution/engine/mock.d.ts +9 -6
  265. package/lib/execution/engine/mock.d.ts.map +1 -1
  266. package/lib/execution/engine/mock.js +34 -7
  267. package/lib/execution/engine/mock.js.map +1 -1
  268. package/lib/index.d.ts +1 -1
  269. package/lib/index.d.ts.map +1 -1
  270. package/lib/index.js +1 -1
  271. package/lib/index.js.map +1 -1
  272. package/lib/metrics/metrics/lodestar.d.ts +28 -6
  273. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  274. package/lib/metrics/metrics/lodestar.js +67 -17
  275. package/lib/metrics/metrics/lodestar.js.map +1 -1
  276. package/lib/network/gossip/interface.d.ts +20 -2
  277. package/lib/network/gossip/interface.d.ts.map +1 -1
  278. package/lib/network/gossip/interface.js +3 -0
  279. package/lib/network/gossip/interface.js.map +1 -1
  280. package/lib/network/gossip/scoringParameters.d.ts.map +1 -1
  281. package/lib/network/gossip/scoringParameters.js +38 -2
  282. package/lib/network/gossip/scoringParameters.js.map +1 -1
  283. package/lib/network/gossip/topic.d.ts +77 -1
  284. package/lib/network/gossip/topic.d.ts.map +1 -1
  285. package/lib/network/gossip/topic.js +20 -0
  286. package/lib/network/gossip/topic.js.map +1 -1
  287. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  288. package/lib/network/processor/gossipHandlers.js +34 -3
  289. package/lib/network/processor/gossipHandlers.js.map +1 -1
  290. package/lib/network/processor/gossipQueues/index.d.ts.map +1 -1
  291. package/lib/network/processor/gossipQueues/index.js +16 -0
  292. package/lib/network/processor/gossipQueues/index.js.map +1 -1
  293. package/lib/network/processor/index.d.ts.map +1 -1
  294. package/lib/network/processor/index.js +3 -0
  295. package/lib/network/processor/index.js.map +1 -1
  296. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  297. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +2 -4
  298. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  299. package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts +1 -2
  300. package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts.map +1 -1
  301. package/lib/network/reqresp/handlers/beaconBlocksByRoot.js +5 -26
  302. package/lib/network/reqresp/handlers/beaconBlocksByRoot.js.map +1 -1
  303. package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts +1 -2
  304. package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts.map +1 -1
  305. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +5 -7
  306. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
  307. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  308. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -2
  309. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  310. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
  311. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -5
  312. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  313. package/lib/network/reqresp/handlers/index.js +2 -2
  314. package/lib/network/reqresp/handlers/index.js.map +1 -1
  315. package/lib/network/reqresp/utils/dataColumnResponseValidation.js +1 -1
  316. package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
  317. package/lib/node/nodejs.d.ts.map +1 -1
  318. package/lib/node/nodejs.js +17 -2
  319. package/lib/node/nodejs.js.map +1 -1
  320. package/lib/sync/backfill/backfill.js +2 -2
  321. package/lib/sync/backfill/backfill.js.map +1 -1
  322. package/lib/sync/backfill/verify.d.ts +1 -2
  323. package/lib/sync/backfill/verify.d.ts.map +1 -1
  324. package/lib/sync/backfill/verify.js +2 -2
  325. package/lib/sync/backfill/verify.js.map +1 -1
  326. package/lib/sync/range/chain.d.ts.map +1 -1
  327. package/lib/sync/range/chain.js +0 -1
  328. package/lib/sync/range/chain.js.map +1 -1
  329. package/lib/sync/range/range.d.ts.map +1 -1
  330. package/lib/sync/range/range.js +0 -3
  331. package/lib/sync/range/range.js.map +1 -1
  332. package/lib/sync/unknownBlock.d.ts.map +1 -1
  333. package/lib/sync/unknownBlock.js +0 -3
  334. package/lib/sync/unknownBlock.js.map +1 -1
  335. package/lib/util/sszBytes.js +1 -1
  336. package/lib/util/sszBytes.js.map +1 -1
  337. package/package.json +15 -15
  338. package/src/api/impl/beacon/blocks/index.ts +8 -18
  339. package/src/api/impl/beacon/state/utils.ts +2 -22
  340. package/src/api/impl/config/constants.ts +8 -0
  341. package/src/api/impl/debug/index.ts +2 -6
  342. package/src/api/impl/lodestar/index.ts +7 -4
  343. package/src/api/impl/proof/index.ts +1 -2
  344. package/src/api/impl/validator/index.ts +13 -14
  345. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +5 -3
  346. package/src/chain/archiveStore/utils/archiveBlocks.ts +25 -14
  347. package/src/chain/blocks/blockInput/blockInput.ts +8 -0
  348. package/src/chain/blocks/importBlock.ts +15 -9
  349. package/src/chain/blocks/index.ts +0 -19
  350. package/src/chain/blocks/types.ts +0 -2
  351. package/src/chain/blocks/verifyBlock.ts +9 -12
  352. package/src/chain/blocks/verifyBlocksSignatures.ts +4 -12
  353. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +1 -0
  354. package/src/chain/blocks/writeBlockInputToDb.ts +24 -30
  355. package/src/chain/bls/multithread/index.ts +7 -4
  356. package/src/chain/bls/multithread/jobItem.ts +7 -3
  357. package/src/chain/bls/singleThread.ts +5 -3
  358. package/src/chain/bls/utils.ts +15 -7
  359. package/src/chain/chain.ts +225 -32
  360. package/src/chain/errors/attestationError.ts +11 -1
  361. package/src/chain/errors/executionPayloadBid.ts +35 -0
  362. package/src/chain/errors/executionPayloadEnvelope.ts +34 -0
  363. package/src/chain/errors/index.ts +3 -0
  364. package/src/chain/errors/payloadAttestation.ts +25 -0
  365. package/src/chain/forkChoice/index.ts +19 -0
  366. package/src/chain/initState.ts +5 -3
  367. package/src/chain/interface.ts +34 -3
  368. package/src/chain/lightClient/proofs.ts +0 -2
  369. package/src/chain/opPools/aggregatedAttestationPool.ts +19 -191
  370. package/src/chain/opPools/executionPayloadBidPool.ts +77 -0
  371. package/src/chain/opPools/index.ts +2 -0
  372. package/src/chain/opPools/opPool.ts +5 -7
  373. package/src/chain/opPools/payloadAttestationPool.ts +157 -0
  374. package/src/chain/prepareNextSlot.ts +8 -12
  375. package/src/chain/produceBlock/produceBlockBody.ts +13 -6
  376. package/src/chain/regen/interface.ts +3 -17
  377. package/src/chain/regen/queued.ts +17 -56
  378. package/src/chain/regen/regen.ts +16 -42
  379. package/src/chain/seenCache/index.ts +3 -1
  380. package/src/chain/seenCache/seenAttesters.ts +5 -0
  381. package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -0
  382. package/src/chain/seenCache/seenExecutionPayloadEnvelope.ts +34 -0
  383. package/src/chain/shufflingCache.ts +67 -50
  384. package/src/chain/stateCache/blockStateCacheImpl.ts +2 -3
  385. package/src/chain/stateCache/fifoBlockStateCache.ts +4 -5
  386. package/src/chain/stateCache/inMemoryCheckpointsCache.ts +9 -15
  387. package/src/chain/stateCache/persistentCheckpointsCache.ts +17 -25
  388. package/src/chain/stateCache/types.ts +5 -10
  389. package/src/chain/validation/aggregateAndProof.ts +36 -14
  390. package/src/chain/validation/attestation.ts +36 -19
  391. package/src/chain/validation/attesterSlashing.ts +9 -7
  392. package/src/chain/validation/blobSidecar.ts +2 -7
  393. package/src/chain/validation/block.ts +8 -4
  394. package/src/chain/validation/blsToExecutionChange.ts +9 -7
  395. package/src/chain/validation/dataColumnSidecar.ts +2 -7
  396. package/src/chain/validation/executionPayloadBid.ts +141 -0
  397. package/src/chain/validation/executionPayloadEnvelope.ts +122 -0
  398. package/src/chain/validation/payloadAttestationMessage.ts +109 -0
  399. package/src/chain/validation/proposerSlashing.ts +3 -7
  400. package/src/chain/validation/signatureSets/aggregateAndProof.ts +9 -14
  401. package/src/chain/validation/signatureSets/contributionAndProof.ts +2 -4
  402. package/src/chain/validation/signatureSets/selectionProof.ts +9 -9
  403. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -4
  404. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -3
  405. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -4
  406. package/src/chain/validation/syncCommittee.ts +1 -1
  407. package/src/chain/validation/syncCommitteeContributionAndProof.ts +3 -5
  408. package/src/chain/validation/voluntaryExit.ts +1 -1
  409. package/src/chain/validatorMonitor.ts +52 -3
  410. package/src/db/repositories/checkpointState.ts +3 -19
  411. package/src/db/repositories/stateArchive.ts +13 -27
  412. package/src/execution/engine/mock.ts +40 -13
  413. package/src/index.ts +1 -1
  414. package/src/metrics/metrics/lodestar.ts +68 -17
  415. package/src/network/gossip/interface.ts +17 -0
  416. package/src/network/gossip/scoringParameters.ts +44 -2
  417. package/src/network/gossip/topic.ts +21 -0
  418. package/src/network/processor/gossipHandlers.ts +48 -3
  419. package/src/network/processor/gossipQueues/index.ts +16 -0
  420. package/src/network/processor/index.ts +3 -0
  421. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +2 -4
  422. package/src/network/reqresp/handlers/beaconBlocksByRoot.ts +5 -32
  423. package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +5 -9
  424. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +5 -2
  425. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -5
  426. package/src/network/reqresp/handlers/index.ts +2 -2
  427. package/src/network/reqresp/utils/dataColumnResponseValidation.ts +1 -1
  428. package/src/node/nodejs.ts +18 -3
  429. package/src/sync/backfill/backfill.ts +2 -2
  430. package/src/sync/backfill/verify.ts +2 -3
  431. package/src/sync/range/chain.ts +0 -1
  432. package/src/sync/range/range.ts +0 -3
  433. package/src/sync/unknownBlock.ts +0 -3
  434. package/src/util/sszBytes.ts +1 -1
@@ -11,7 +11,7 @@ import {
11
11
  processSlots,
12
12
  stateTransition,
13
13
  } from "@lodestar/state-transition";
14
- import {BeaconBlock, RootHex, SignedBeaconBlock, Slot, phase0} from "@lodestar/types";
14
+ import {BeaconBlock, RootHex, SignedBeaconBlock, Slot} from "@lodestar/types";
15
15
  import {Logger, fromHex, toRootHex} from "@lodestar/utils";
16
16
  import {IBeaconDb} from "../../db/index.js";
17
17
  import {Metrics} from "../../metrics/index.js";
@@ -74,24 +74,11 @@ export class StateRegenerator implements IStateRegeneratorInternal {
74
74
  // We may have the checkpoint state with parent root inside the checkpoint state cache
75
75
  // through gossip validation.
76
76
  if (parentEpoch < blockEpoch) {
77
- return this.getCheckpointState({root: block.parentRoot, epoch: blockEpoch}, opts, regenCaller, allowDiskReload);
77
+ return this.getBlockSlotState(parentBlock, block.slot, opts, regenCaller, allowDiskReload);
78
78
  }
79
79
 
80
80
  // Otherwise, get the state normally.
81
- return this.getState(parentBlock.stateRoot, regenCaller, opts, allowDiskReload);
82
- }
83
-
84
- /**
85
- * Get state after block `cp.root` dialed forward to first slot of `cp.epoch`
86
- */
87
- async getCheckpointState(
88
- cp: phase0.Checkpoint,
89
- opts: StateRegenerationOpts,
90
- regenCaller: RegenCaller,
91
- allowDiskReload = false
92
- ): Promise<CachedBeaconStateAllForks> {
93
- const checkpointStartSlot = computeStartSlotAtEpoch(cp.epoch);
94
- return this.getBlockSlotState(toRootHex(cp.root), checkpointStartSlot, opts, regenCaller, allowDiskReload);
81
+ return this.getState(parentBlock.stateRoot, regenCaller, allowDiskReload);
95
82
  }
96
83
 
97
84
  /**
@@ -99,20 +86,12 @@ export class StateRegenerator implements IStateRegeneratorInternal {
99
86
  * - allowDiskReload should be used with care, as it will cause the state to be reloaded from disk
100
87
  */
101
88
  async getBlockSlotState(
102
- blockRoot: RootHex,
89
+ block: ProtoBlock,
103
90
  slot: Slot,
104
91
  opts: StateRegenerationOpts,
105
92
  regenCaller: RegenCaller,
106
93
  allowDiskReload = false
107
94
  ): Promise<CachedBeaconStateAllForks> {
108
- const block = this.modules.forkChoice.getBlockHex(blockRoot);
109
- if (!block) {
110
- throw new RegenError({
111
- code: RegenErrorCode.BLOCK_NOT_IN_FORKCHOICE,
112
- blockRoot,
113
- });
114
- }
115
-
116
95
  if (slot < block.slot) {
117
96
  throw new RegenError({
118
97
  code: RegenErrorCode.SLOT_BEFORE_BLOCK_SLOT,
@@ -121,11 +100,12 @@ export class StateRegenerator implements IStateRegeneratorInternal {
121
100
  });
122
101
  }
123
102
 
103
+ const {blockRoot} = block;
124
104
  const {checkpointStateCache} = this.modules;
125
105
  const epoch = computeEpochAtSlot(slot);
126
106
  const latestCheckpointStateCtx = allowDiskReload
127
- ? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch, opts)
128
- : checkpointStateCache.getLatest(blockRoot, epoch, opts);
107
+ ? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch)
108
+ : checkpointStateCache.getLatest(blockRoot, epoch);
129
109
 
130
110
  // If a checkpoint state exists with the given checkpoint root, it either is in requested epoch
131
111
  // or needs to have empty slots processed until the requested epoch
@@ -136,7 +116,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
136
116
  // Otherwise, use the fork choice to get the stateRoot from block at the checkpoint root
137
117
  // regenerate that state,
138
118
  // then process empty slots until the requested epoch
139
- const blockStateCtx = await this.getState(block.stateRoot, regenCaller, opts, allowDiskReload);
119
+ const blockStateCtx = await this.getState(block.stateRoot, regenCaller, allowDiskReload);
140
120
  return processSlotsByCheckpoint(this.modules, blockStateCtx, slot, regenCaller, opts);
141
121
  }
142
122
 
@@ -148,23 +128,15 @@ export class StateRegenerator implements IStateRegeneratorInternal {
148
128
  async getState(
149
129
  stateRoot: RootHex,
150
130
  caller: RegenCaller,
151
- opts?: StateRegenerationOpts,
152
131
  // internal option, don't want to expose to external caller
153
132
  allowDiskReload = false
154
133
  ): Promise<CachedBeaconStateAllForks> {
155
134
  // Trivial case, state at stateRoot is already cached
156
- const cachedStateCtx = this.modules.blockStateCache.get(stateRoot, opts);
135
+ const cachedStateCtx = this.modules.blockStateCache.get(stateRoot);
157
136
  if (cachedStateCtx) {
158
137
  return cachedStateCtx;
159
138
  }
160
139
 
161
- // in block gossip validation (getPreState() call), dontTransferCache is specified as true because we only want to transfer cache in verifyBlocksStateTransitionOnly()
162
- // but here we want to process blocks as fast as possible so force to transfer cache in this case
163
- if (opts && allowDiskReload) {
164
- // if there is no `opts` specified, it already means "false"
165
- opts.dontTransferCache = false;
166
- }
167
-
168
140
  // Otherwise we have to use the fork choice to traverse backwards, block by block,
169
141
  // searching the state caches
170
142
  // then replay blocks forward to the desired stateRoot
@@ -179,7 +151,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
179
151
  const getSeedStateTimer = this.modules.metrics?.regenGetState.getSeedState.startTimer({caller});
180
152
  // iterateAncestorBlocks only returns ancestor blocks, not the block itself
181
153
  for (const b of this.modules.forkChoice.iterateAncestorBlocks(block.blockRoot)) {
182
- state = this.modules.blockStateCache.get(b.stateRoot, opts);
154
+ state = this.modules.blockStateCache.get(b.stateRoot);
183
155
  if (state) {
184
156
  break;
185
157
  }
@@ -187,8 +159,8 @@ export class StateRegenerator implements IStateRegeneratorInternal {
187
159
  if (!lastBlockToReplay) continue;
188
160
  const epoch = computeEpochAtSlot(lastBlockToReplay.slot - 1);
189
161
  state = allowDiskReload
190
- ? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch, opts)
191
- : checkpointStateCache.getLatest(b.blockRoot, epoch, opts);
162
+ ? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch)
163
+ : checkpointStateCache.getLatest(b.blockRoot, epoch);
192
164
  if (state) {
193
165
  break;
194
166
  }
@@ -255,6 +227,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
255
227
  try {
256
228
  // Only advances state trusting block's signture and hashes.
257
229
  // We are only running the state transition to get a specific state's data.
230
+ // stateTransition() does the clone() inside, transfer cache to make the regen faster
258
231
  state = stateTransition(
259
232
  state,
260
233
  block,
@@ -265,6 +238,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
265
238
  verifyStateRoot: false,
266
239
  verifyProposer: false,
267
240
  verifySignatures: false,
241
+ dontTransferCache: false,
268
242
  },
269
243
  this.modules
270
244
  );
@@ -390,8 +364,8 @@ export async function processSlotsToNearestCheckpoint(
390
364
  const checkpointState = postState;
391
365
  const cp = getCheckpointFromState(checkpointState);
392
366
  checkpointStateCache.add(cp, checkpointState);
393
- // consumers should not mutate or get the transfered cache
394
- emitter?.emit(ChainEvent.checkpoint, cp, checkpointState.clone(true));
367
+ // consumers should not mutate state ever
368
+ emitter?.emit(ChainEvent.checkpoint, cp, checkpointState);
395
369
 
396
370
  if (count >= 1) {
397
371
  // in normal condition, we only process 1 epoch so never reach this
@@ -1,5 +1,7 @@
1
- export {SeenAggregators, SeenAttesters} from "./seenAttesters.js";
1
+ export {SeenAggregators, SeenAttesters, SeenPayloadAttesters} from "./seenAttesters.js";
2
2
  export {SeenBlockProposers} from "./seenBlockProposers.js";
3
3
  export {SeenSyncCommitteeMessages} from "./seenCommittee.js";
4
4
  export {SeenContributionAndProof} from "./seenCommitteeContribution.js";
5
+ export {SeenExecutionPayloadBids} from "./seenExecutionPayloadBids.js";
6
+ export {SeenExecutionPayloadEnvelopes} from "./seenExecutionPayloadEnvelope.js";
5
7
  export {SeenBlockInput} from "./seenGossipBlockInput.js";
@@ -56,3 +56,8 @@ export class SeenAttesters {
56
56
  * Keeps a cache to filter aggregated attestations from the same aggregators in the same epoch
57
57
  */
58
58
  export class SeenAggregators extends SeenAttesters {}
59
+
60
+ /**
61
+ * Keeps a cache to filter payload attestations from the same attesters in the same epoch
62
+ */
63
+ export class SeenPayloadAttesters extends SeenAttesters {}
@@ -0,0 +1,35 @@
1
+ import {BuilderIndex, Slot} from "@lodestar/types";
2
+ import {MapDef} from "@lodestar/utils";
3
+
4
+ /**
5
+ * TODO GLOAS: Revisit this value and add rational for choosing it
6
+ */
7
+ const SLOTS_RETAINED = 2;
8
+
9
+ /**
10
+ * Tracks execution payload bids we've already seen per (slot, builder).
11
+ */
12
+ export class SeenExecutionPayloadBids {
13
+ private readonly builderIndexesBySlot = new MapDef<Slot, Set<BuilderIndex>>(() => new Set<BuilderIndex>());
14
+ private lowestPermissibleSlot: Slot = 0;
15
+
16
+ isKnown(slot: Slot, builderIndex: BuilderIndex): boolean {
17
+ return this.builderIndexesBySlot.get(slot)?.has(builderIndex) === true;
18
+ }
19
+
20
+ add(slot: Slot, builderIndex: BuilderIndex): void {
21
+ if (slot < this.lowestPermissibleSlot) {
22
+ throw Error(`slot ${slot} < lowestPermissibleSlot ${this.lowestPermissibleSlot}`);
23
+ }
24
+ this.builderIndexesBySlot.getOrDefault(slot).add(builderIndex);
25
+ }
26
+
27
+ prune(currentSlot: Slot): void {
28
+ this.lowestPermissibleSlot = Math.max(currentSlot - SLOTS_RETAINED, 0);
29
+ for (const slot of this.builderIndexesBySlot.keys()) {
30
+ if (slot < this.lowestPermissibleSlot) {
31
+ this.builderIndexesBySlot.delete(slot);
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,34 @@
1
+ import {RootHex, Slot} from "@lodestar/types";
2
+
3
+ /**
4
+ * Cache to prevent processing multiple execution payload envelopes for the same block root.
5
+ * Only one builder qualifies to submit an execution payload for a given slot.
6
+ * We only keep track of envelopes of unfinalized slots.
7
+ * [IGNORE] The node has not seen another valid `SignedExecutionPayloadEnvelope` for this block root.
8
+ */
9
+ export class SeenExecutionPayloadEnvelopes {
10
+ private readonly slotByBlockRoot = new Map<RootHex, Slot>();
11
+ private finalizedSlot: Slot = 0;
12
+
13
+ isKnown(blockRoot: RootHex): boolean {
14
+ return this.slotByBlockRoot.has(blockRoot);
15
+ }
16
+
17
+ add(blockRoot: RootHex, slot: Slot): void {
18
+ if (slot < this.finalizedSlot) {
19
+ throw Error(`slot ${slot} < finalizedSlot ${this.finalizedSlot}`);
20
+ }
21
+
22
+ this.slotByBlockRoot.set(blockRoot, slot);
23
+ }
24
+
25
+ prune(finalizedSlot: Slot): void {
26
+ this.finalizedSlot = finalizedSlot;
27
+
28
+ for (const [blockRoot, slot] of this.slotByBlockRoot.entries()) {
29
+ if (slot < finalizedSlot) {
30
+ this.slotByBlockRoot.delete(blockRoot);
31
+ }
32
+ }
33
+ }
34
+ }
@@ -1,12 +1,12 @@
1
+ import {ForkSeq} from "@lodestar/params";
1
2
  import {
2
- BeaconStateAllForks,
3
+ CachedBeaconStateAllForks,
3
4
  EpochShuffling,
4
- IShufflingCache,
5
- ShufflingBuildProps,
6
- computeEpochShuffling,
7
- computeEpochShufflingAsync,
5
+ getAttestingIndices,
6
+ getBeaconCommittees,
7
+ getIndexedAttestation,
8
8
  } from "@lodestar/state-transition";
9
- import {Epoch, RootHex} from "@lodestar/types";
9
+ import {Attestation, CommitteeIndex, Epoch, IndexedAttestation, RootHex, Slot} from "@lodestar/types";
10
10
  import {LodestarError, Logger, MapDef, pruneSetToMax} from "@lodestar/utils";
11
11
  import {Metrics} from "../metrics/metrics.js";
12
12
 
@@ -53,7 +53,7 @@ export type ShufflingCacheOpts = {
53
53
  * - if a shuffling is not available (which does not happen with default chain option of maxSkipSlots = 32), track a promise to make sure we don't compute the same shuffling twice
54
54
  * - skip computing shuffling when loading state bytes from disk
55
55
  */
56
- export class ShufflingCache implements IShufflingCache {
56
+ export class ShufflingCache {
57
57
  /** LRU cache implemented as a map, pruned every time we add an item */
58
58
  private readonly itemsByDecisionRootByEpoch: MapDef<Epoch, Map<RootHex, CacheItem>> = new MapDef(
59
59
  () => new Map<RootHex, CacheItem>()
@@ -136,60 +136,76 @@ export class ShufflingCache implements IShufflingCache {
136
136
  }
137
137
 
138
138
  /**
139
- * Gets a cached shuffling via the epoch and decision root. If the shuffling is not
140
- * available it will build it synchronously and return the shuffling.
141
- *
142
- * NOTE: If a shuffling is already queued and not calculated it will build and resolve
143
- * the promise but the already queued build will happen at some later time
139
+ * Get a shuffling synchronously, return null if not present.
140
+ * The only time we have a promise cache item is when we regen shuffling for attestation, which never happens
141
+ * with default chain option.
144
142
  */
145
- getSync<T extends ShufflingBuildProps | undefined>(
146
- epoch: Epoch,
147
- decisionRoot: RootHex,
148
- buildProps?: T
149
- ): T extends ShufflingBuildProps ? EpochShuffling : EpochShuffling | null {
143
+ getSync(epoch: Epoch, decisionRoot: RootHex): EpochShuffling | null {
150
144
  const cacheItem = this.itemsByDecisionRootByEpoch.getOrDefault(epoch).get(decisionRoot);
151
- if (!cacheItem) {
145
+ if (cacheItem === undefined) {
152
146
  this.metrics?.shufflingCache.miss.inc();
153
- } else if (isShufflingCacheItem(cacheItem)) {
147
+ return null;
148
+ }
149
+
150
+ if (isShufflingCacheItem(cacheItem)) {
154
151
  this.metrics?.shufflingCache.hit.inc();
155
152
  return cacheItem.shuffling;
156
- } else if (buildProps) {
157
- // TODO: (@matthewkeil) This should possible log a warning??
158
- this.metrics?.shufflingCache.shufflingPromiseNotResolvedAndThrownAway.inc();
159
- } else {
160
- this.metrics?.shufflingCache.shufflingPromiseNotResolved.inc();
161
153
  }
162
154
 
163
- let shuffling: EpochShuffling | null = null;
164
- if (buildProps) {
165
- const timer = this.metrics?.shufflingCache.shufflingCalculationTime.startTimer({source: "getSync"});
166
- shuffling = computeEpochShuffling(buildProps.state, buildProps.activeIndices, epoch);
167
- timer?.();
168
- this.set(shuffling, decisionRoot);
169
- }
170
- return shuffling as T extends ShufflingBuildProps ? EpochShuffling : EpochShuffling | null;
155
+ return null;
171
156
  }
172
157
 
173
158
  /**
174
- * Queue asynchronous build for an EpochShuffling, triggered from state-transition
159
+ * Process a state to extract and cache all shufflings (previous, current, next).
160
+ * Uses the stored decision roots from epochCtx.
175
161
  */
176
- build(epoch: number, decisionRoot: string, state: BeaconStateAllForks, activeIndices: Uint32Array): void {
177
- this.insertPromise(epoch, decisionRoot);
178
- /**
179
- * TODO: (@matthewkeil) This will get replaced by a proper build queue and a worker to do calculations
180
- * on a NICE thread
181
- */
182
- const timer = this.metrics?.shufflingCache.shufflingCalculationTime.startTimer({source: "build"});
183
- computeEpochShufflingAsync(state, activeIndices, epoch)
184
- .then((shuffling) => {
185
- this.set(shuffling, decisionRoot);
186
- })
187
- .catch((err) =>
188
- this.logger?.error(`error building shuffling for epoch ${epoch} at decisionRoot ${decisionRoot}`, {}, err)
189
- )
190
- .finally(() => {
191
- timer?.();
162
+ processState(state: CachedBeaconStateAllForks): void {
163
+ const {epochCtx} = state;
164
+
165
+ // Cache previous shuffling
166
+ this.set(epochCtx.previousShuffling, epochCtx.previousDecisionRoot);
167
+
168
+ // Cache current shuffling
169
+ this.set(epochCtx.currentShuffling, epochCtx.currentDecisionRoot);
170
+
171
+ // Cache next shuffling
172
+ this.set(epochCtx.nextShuffling, epochCtx.nextDecisionRoot);
173
+ }
174
+
175
+ getIndexedAttestation(
176
+ epoch: number,
177
+ decisionRoot: string,
178
+ fork: ForkSeq,
179
+ attestation: Attestation
180
+ ): IndexedAttestation {
181
+ const shuffling = this.getShufflingOrThrow(epoch, decisionRoot);
182
+ return getIndexedAttestation(shuffling, fork, attestation);
183
+ }
184
+
185
+ getAttestingIndices(epoch: number, decisionRoot: string, fork: ForkSeq, attestation: Attestation): number[] {
186
+ const shuffling = this.getShufflingOrThrow(epoch, decisionRoot);
187
+ return getAttestingIndices(shuffling, fork, attestation);
188
+ }
189
+
190
+ getBeaconCommittee(epoch: number, decisionRoot: string, slot: Slot, index: CommitteeIndex): Uint32Array {
191
+ return this.getBeaconCommittees(epoch, decisionRoot, slot, [index])[0];
192
+ }
193
+
194
+ getBeaconCommittees(epoch: number, decisionRoot: string, slot: Slot, indices: CommitteeIndex[]): Uint32Array[] {
195
+ const shuffling = this.getShufflingOrThrow(epoch, decisionRoot);
196
+ return getBeaconCommittees(shuffling, slot, indices);
197
+ }
198
+
199
+ private getShufflingOrThrow(epoch: number, decisionRoot: string): EpochShuffling {
200
+ const shuffling = this.getSync(epoch, decisionRoot);
201
+ if (shuffling === null) {
202
+ throw new ShufflingCacheError({
203
+ code: ShufflingCacheErrorCode.NO_SHUFFLING_FOUND,
204
+ epoch,
205
+ decisionRoot,
192
206
  });
207
+ }
208
+ return shuffling;
193
209
  }
194
210
 
195
211
  /**
@@ -207,7 +223,8 @@ export class ShufflingCache implements IShufflingCache {
207
223
  (Date.now() - cacheItem.timeInsertedMs) / 1000
208
224
  );
209
225
  } else {
210
- this.metrics?.shufflingCache.shufflingBuiltMultipleTimes.inc();
226
+ this.metrics?.shufflingCache.shufflingSetMultipleTimes.inc();
227
+ return;
211
228
  }
212
229
  }
213
230
  // set the shuffling
@@ -3,7 +3,6 @@ import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
3
3
  import {Epoch, RootHex} from "@lodestar/types";
4
4
  import {toRootHex} from "@lodestar/utils";
5
5
  import {Metrics} from "../../metrics/index.js";
6
- import {StateRegenerationOpts} from "../regen/interface.js";
7
6
  import {MapTracker} from "./mapMetrics.js";
8
7
  import {BlockStateCache} from "./types.js";
9
8
 
@@ -39,7 +38,7 @@ export class BlockStateCacheImpl implements BlockStateCache {
39
38
  }
40
39
  }
41
40
 
42
- get(rootHex: RootHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null {
41
+ get(rootHex: RootHex): CachedBeaconStateAllForks | null {
43
42
  this.metrics?.lookups.inc();
44
43
  const item = this.head?.stateRoot === rootHex ? this.head.state : this.cache.get(rootHex);
45
44
  if (!item) {
@@ -49,7 +48,7 @@ export class BlockStateCacheImpl implements BlockStateCache {
49
48
  this.metrics?.hits.inc();
50
49
  this.metrics?.stateClonedCount.observe(item.clonedCount);
51
50
 
52
- return item.clone(opts?.dontTransferCache);
51
+ return item;
53
52
  }
54
53
 
55
54
  add(item: CachedBeaconStateAllForks): void {
@@ -4,7 +4,6 @@ import {RootHex} from "@lodestar/types";
4
4
  import {toRootHex} from "@lodestar/utils";
5
5
  import {Metrics} from "../../metrics/index.js";
6
6
  import {LinkedList} from "../../util/array.js";
7
- import {StateRegenerationOpts} from "../regen/interface.js";
8
7
  import {MapTracker} from "./mapMetrics.js";
9
8
  import {BlockStateCache} from "./types.js";
10
9
 
@@ -86,14 +85,14 @@ export class FIFOBlockStateCache implements BlockStateCache {
86
85
  }
87
86
 
88
87
  const firstState = firstValue.value;
89
- // don't transfer cache because consumer only use this cache to reload another state from disc
90
- return firstState.clone(true);
88
+ // consumers should not mutate the returned state
89
+ return firstState;
91
90
  }
92
91
 
93
92
  /**
94
93
  * Get a state from this cache given a state root hex.
95
94
  */
96
- get(rootHex: RootHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null {
95
+ get(rootHex: RootHex): CachedBeaconStateAllForks | null {
97
96
  this.metrics?.lookups.inc();
98
97
  const item = this.cache.get(rootHex);
99
98
  if (!item) {
@@ -103,7 +102,7 @@ export class FIFOBlockStateCache implements BlockStateCache {
103
102
  this.metrics?.hits.inc();
104
103
  this.metrics?.stateClonedCount.observe(item.clonedCount);
105
104
 
106
- return item.clone(opts?.dontTransferCache);
105
+ return item;
107
106
  }
108
107
 
109
108
  /**
@@ -3,7 +3,6 @@ import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
3
3
  import {Epoch, RootHex, phase0} from "@lodestar/types";
4
4
  import {MapDef, toRootHex} from "@lodestar/utils";
5
5
  import {Metrics} from "../../metrics/index.js";
6
- import {StateRegenerationOpts} from "../regen/interface.js";
7
6
  import {MapTracker} from "./mapMetrics.js";
8
7
  import {CacheItemType, CheckpointStateCache} from "./types.js";
9
8
 
@@ -42,21 +41,16 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache {
42
41
  this.maxEpochs = maxEpochs;
43
42
  }
44
43
 
45
- async getOrReload(cp: CheckpointHex, opts?: StateRegenerationOpts): Promise<CachedBeaconStateAllForks | null> {
46
- return this.get(cp, opts);
44
+ async getOrReload(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | null> {
45
+ return this.get(cp);
47
46
  }
48
47
 
49
48
  async getStateOrBytes(cp: CheckpointHex): Promise<Uint8Array | CachedBeaconStateAllForks | null> {
50
- // no need to transfer cache for this api
51
- return this.get(cp, {dontTransferCache: true});
49
+ return this.get(cp);
52
50
  }
53
51
 
54
- async getOrReloadLatest(
55
- rootHex: string,
56
- maxEpoch: number,
57
- opts?: StateRegenerationOpts
58
- ): Promise<CachedBeaconStateAllForks | null> {
59
- return this.getLatest(rootHex, maxEpoch, opts);
52
+ async getOrReloadLatest(rootHex: string, maxEpoch: number): Promise<CachedBeaconStateAllForks | null> {
53
+ return this.getLatest(rootHex, maxEpoch);
60
54
  }
61
55
 
62
56
  async processState(): Promise<number> {
@@ -64,7 +58,7 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache {
64
58
  return 0;
65
59
  }
66
60
 
67
- get(cp: CheckpointHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null {
61
+ get(cp: CheckpointHex): CachedBeaconStateAllForks | null {
68
62
  this.metrics?.lookups.inc();
69
63
  const cpKey = toCheckpointKey(cp);
70
64
  const item = this.cache.get(cpKey);
@@ -81,7 +75,7 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache {
81
75
 
82
76
  this.metrics?.stateClonedCount.observe(item.clonedCount);
83
77
 
84
- return item.clone(opts?.dontTransferCache);
78
+ return item;
85
79
  }
86
80
 
87
81
  add(cp: phase0.Checkpoint, item: CachedBeaconStateAllForks): void {
@@ -98,14 +92,14 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache {
98
92
  /**
99
93
  * Searches for the latest cached state with a `root`, starting with `epoch` and descending
100
94
  */
101
- getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null {
95
+ getLatest(rootHex: RootHex, maxEpoch: Epoch): CachedBeaconStateAllForks | null {
102
96
  // sort epochs in descending order, only consider epochs lte `epoch`
103
97
  const epochs = Array.from(this.epochIndex.keys())
104
98
  .sort((a, b) => b - a)
105
99
  .filter((e) => e <= maxEpoch);
106
100
  for (const epoch of epochs) {
107
101
  if (this.epochIndex.get(epoch)?.has(rootHex)) {
108
- return this.get({rootHex, epoch}, opts);
102
+ return this.get({rootHex, epoch});
109
103
  }
110
104
  }
111
105
  return null;
@@ -11,7 +11,6 @@ import {Logger, MapDef, fromHex, sleep, toHex, toRootHex} from "@lodestar/utils"
11
11
  import {Metrics} from "../../metrics/index.js";
12
12
  import {AllocSource, BufferPool, BufferWithKey} from "../../util/bufferPool.js";
13
13
  import {IClock} from "../../util/clock.js";
14
- import {StateRegenerationOpts} from "../regen/interface.js";
15
14
  import {serializeState} from "../serializeState.js";
16
15
  import {CPStateDatastore, DatastoreKey} from "./datastore/index.js";
17
16
  import {MapTracker} from "./mapMetrics.js";
@@ -204,10 +203,10 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
204
203
  * - Get block for processing
205
204
  * - Regen head state
206
205
  */
207
- async getOrReload(cp: CheckpointHex, opts?: StateRegenerationOpts): Promise<CachedBeaconStateAllForks | null> {
208
- const stateOrStateBytesData = await this.getStateOrLoadDb(cp, opts);
206
+ async getOrReload(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | null> {
207
+ const stateOrStateBytesData = await this.getStateOrLoadDb(cp);
209
208
  if (stateOrStateBytesData === null || isCachedBeaconState(stateOrStateBytesData)) {
210
- return stateOrStateBytesData?.clone(opts?.dontTransferCache) ?? null;
209
+ return stateOrStateBytesData ?? null;
211
210
  }
212
211
  const {persistedKey, stateBytes} = stateOrStateBytesData;
213
212
  const logMeta = {persistedKey: toHex(persistedKey)};
@@ -233,7 +232,8 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
233
232
  sszTimer?.();
234
233
  const timer = this.metrics?.cpStateCache.stateReloadDuration.startTimer();
235
234
  const newCachedState = loadCachedBeaconState(seedState, stateBytes, {}, validatorsBytes);
236
- newCachedState.commit();
235
+ // hashTreeRoot() calls the commit() inside
236
+ // there is no modification inside the state, it's just that we want to compute and cache all roots
237
237
  const stateRoot = toRootHex(newCachedState.hashTreeRoot());
238
238
  timer?.();
239
239
 
@@ -252,7 +252,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
252
252
  this.cache.set(cpKey, {type: CacheItemType.inMemory, state: newCachedState, persistedKey});
253
253
  this.epochIndex.getOrDefault(cp.epoch).add(cp.rootHex);
254
254
  // don't prune from memory here, call it at the last 1/3 of slot 0 of an epoch
255
- return newCachedState.clone(opts?.dontTransferCache);
255
+ return newCachedState;
256
256
  } catch (e) {
257
257
  this.logger.debug("Reload: error loading cached state", logMeta, e as Error);
258
258
  return null;
@@ -263,8 +263,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
263
263
  * Return either state or state bytes loaded from db.
264
264
  */
265
265
  async getStateOrBytes(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | Uint8Array | null> {
266
- // don't have to transfer cache for this specific api
267
- const stateOrLoadedState = await this.getStateOrLoadDb(cp, {dontTransferCache: true});
266
+ const stateOrLoadedState = await this.getStateOrLoadDb(cp);
268
267
  if (stateOrLoadedState === null || isCachedBeaconState(stateOrLoadedState)) {
269
268
  return stateOrLoadedState;
270
269
  }
@@ -274,12 +273,9 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
274
273
  /**
275
274
  * Return either state or state bytes with persisted key loaded from db.
276
275
  */
277
- async getStateOrLoadDb(
278
- cp: CheckpointHex,
279
- opts?: StateRegenerationOpts
280
- ): Promise<CachedBeaconStateAllForks | LoadedStateBytesData | null> {
276
+ async getStateOrLoadDb(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | LoadedStateBytesData | null> {
281
277
  const cpKey = toCacheKey(cp);
282
- const inMemoryState = this.get(cpKey, opts);
278
+ const inMemoryState = this.get(cpKey);
283
279
  if (inMemoryState) {
284
280
  return inMemoryState;
285
281
  }
@@ -308,7 +304,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
308
304
  /**
309
305
  * Similar to get() api without reloading from disk
310
306
  */
311
- get(cpOrKey: CheckpointHex | string, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null {
307
+ get(cpOrKey: CheckpointHex | string): CachedBeaconStateAllForks | null {
312
308
  this.metrics?.cpStateCache.lookups.inc();
313
309
  const cpKey = typeof cpOrKey === "string" ? cpOrKey : toCacheKey(cpOrKey);
314
310
  const cacheItem = this.cache.get(cpKey);
@@ -326,7 +322,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
326
322
  if (isInMemoryCacheItem(cacheItem)) {
327
323
  const {state} = cacheItem;
328
324
  this.metrics?.cpStateCache.stateClonedCount.observe(state.clonedCount);
329
- return state.clone(opts?.dontTransferCache);
325
+ return state;
330
326
  }
331
327
 
332
328
  return null;
@@ -360,14 +356,14 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
360
356
  /**
361
357
  * Searches in-memory state for the latest cached state with a `root` without reload, starting with `epoch` and descending
362
358
  */
363
- getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null {
359
+ getLatest(rootHex: RootHex, maxEpoch: Epoch): CachedBeaconStateAllForks | null {
364
360
  // sort epochs in descending order, only consider epochs lte `epoch`
365
361
  const epochs = Array.from(this.epochIndex.keys())
366
362
  .sort((a, b) => b - a)
367
363
  .filter((e) => e <= maxEpoch);
368
364
  for (const epoch of epochs) {
369
365
  if (this.epochIndex.get(epoch)?.has(rootHex)) {
370
- const inMemoryClonedState = this.get({rootHex, epoch}, opts);
366
+ const inMemoryClonedState = this.get({rootHex, epoch});
371
367
  if (inMemoryClonedState) {
372
368
  return inMemoryClonedState;
373
369
  }
@@ -383,11 +379,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
383
379
  * - Get block for processing
384
380
  * - Regen head state
385
381
  */
386
- async getOrReloadLatest(
387
- rootHex: RootHex,
388
- maxEpoch: Epoch,
389
- opts?: StateRegenerationOpts
390
- ): Promise<CachedBeaconStateAllForks | null> {
382
+ async getOrReloadLatest(rootHex: RootHex, maxEpoch: Epoch): Promise<CachedBeaconStateAllForks | null> {
391
383
  // sort epochs in descending order, only consider epochs lte `epoch`
392
384
  const epochs = Array.from(this.epochIndex.keys())
393
385
  .sort((a, b) => b - a)
@@ -395,9 +387,9 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
395
387
  for (const epoch of epochs) {
396
388
  if (this.epochIndex.get(epoch)?.has(rootHex)) {
397
389
  try {
398
- const clonedState = await this.getOrReload({rootHex, epoch}, opts);
399
- if (clonedState) {
400
- return clonedState;
390
+ const state = await this.getOrReload({rootHex, epoch});
391
+ if (state) {
392
+ return state;
401
393
  }
402
394
  } catch (e) {
403
395
  this.logger.debug("Error get or reload state", {epoch, rootHex}, e as Error);