@lodestar/beacon-node 1.39.1 → 1.40.0-dev.1020f27ca9

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 (441) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +15 -25
  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 +16 -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/ColumnReconstructionTracker.d.ts +2 -0
  26. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  27. package/lib/chain/ColumnReconstructionTracker.js +7 -3
  28. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  29. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  30. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -3
  31. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  32. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  33. package/lib/chain/archiveStore/utils/archiveBlocks.js +23 -14
  34. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  35. package/lib/chain/blocks/blockInput/blockInput.d.ts +2 -0
  36. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  37. package/lib/chain/blocks/blockInput/blockInput.js +6 -0
  38. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  39. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  40. package/lib/chain/blocks/importBlock.js +14 -9
  41. package/lib/chain/blocks/importBlock.js.map +1 -1
  42. package/lib/chain/blocks/index.d.ts.map +1 -1
  43. package/lib/chain/blocks/index.js +0 -14
  44. package/lib/chain/blocks/index.js.map +1 -1
  45. package/lib/chain/blocks/types.d.ts +0 -2
  46. package/lib/chain/blocks/types.d.ts.map +1 -1
  47. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  48. package/lib/chain/blocks/verifyBlock.js +9 -9
  49. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  50. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  51. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  52. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
  53. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  54. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  55. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +1 -0
  56. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  57. package/lib/chain/blocks/writeBlockInputToDb.d.ts +1 -4
  58. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
  59. package/lib/chain/blocks/writeBlockInputToDb.js +20 -28
  60. package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
  61. package/lib/chain/bls/multithread/index.d.ts +3 -1
  62. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  63. package/lib/chain/bls/multithread/index.js +5 -3
  64. package/lib/chain/bls/multithread/index.js.map +1 -1
  65. package/lib/chain/bls/multithread/jobItem.d.ts +2 -2
  66. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -1
  67. package/lib/chain/bls/multithread/jobItem.js +2 -2
  68. package/lib/chain/bls/multithread/jobItem.js.map +1 -1
  69. package/lib/chain/bls/singleThread.d.ts +4 -2
  70. package/lib/chain/bls/singleThread.d.ts.map +1 -1
  71. package/lib/chain/bls/singleThread.js +4 -2
  72. package/lib/chain/bls/singleThread.js.map +1 -1
  73. package/lib/chain/bls/utils.d.ts +2 -2
  74. package/lib/chain/bls/utils.d.ts.map +1 -1
  75. package/lib/chain/bls/utils.js +9 -6
  76. package/lib/chain/bls/utils.js.map +1 -1
  77. package/lib/chain/chain.d.ts +24 -6
  78. package/lib/chain/chain.d.ts.map +1 -1
  79. package/lib/chain/chain.js +201 -25
  80. package/lib/chain/chain.js.map +1 -1
  81. package/lib/chain/errors/attestationError.d.ts +14 -1
  82. package/lib/chain/errors/attestationError.d.ts.map +1 -1
  83. package/lib/chain/errors/attestationError.js +8 -0
  84. package/lib/chain/errors/attestationError.js.map +1 -1
  85. package/lib/chain/errors/executionPayloadBid.d.ts +48 -0
  86. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -0
  87. package/lib/chain/errors/executionPayloadBid.js +15 -0
  88. package/lib/chain/errors/executionPayloadBid.js.map +1 -0
  89. package/lib/chain/errors/executionPayloadEnvelope.d.ts +48 -0
  90. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -0
  91. package/lib/chain/errors/executionPayloadEnvelope.js +16 -0
  92. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -0
  93. package/lib/chain/errors/index.d.ts +3 -0
  94. package/lib/chain/errors/index.d.ts.map +1 -1
  95. package/lib/chain/errors/index.js +3 -0
  96. package/lib/chain/errors/index.js.map +1 -1
  97. package/lib/chain/errors/payloadAttestation.d.ts +34 -0
  98. package/lib/chain/errors/payloadAttestation.d.ts.map +1 -0
  99. package/lib/chain/errors/payloadAttestation.js +13 -0
  100. package/lib/chain/errors/payloadAttestation.js.map +1 -0
  101. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  102. package/lib/chain/forkChoice/index.js +18 -0
  103. package/lib/chain/forkChoice/index.js.map +1 -1
  104. package/lib/chain/initState.d.ts +1 -1
  105. package/lib/chain/initState.d.ts.map +1 -1
  106. package/lib/chain/initState.js +5 -3
  107. package/lib/chain/initState.js.map +1 -1
  108. package/lib/chain/interface.d.ts +23 -5
  109. package/lib/chain/interface.d.ts.map +1 -1
  110. package/lib/chain/interface.js.map +1 -1
  111. package/lib/chain/lightClient/proofs.d.ts.map +1 -1
  112. package/lib/chain/lightClient/proofs.js +0 -2
  113. package/lib/chain/lightClient/proofs.js.map +1 -1
  114. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +5 -9
  115. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  116. package/lib/chain/opPools/aggregatedAttestationPool.js +12 -141
  117. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  118. package/lib/chain/opPools/executionPayloadBidPool.d.ts +21 -0
  119. package/lib/chain/opPools/executionPayloadBidPool.d.ts.map +1 -0
  120. package/lib/chain/opPools/executionPayloadBidPool.js +57 -0
  121. package/lib/chain/opPools/executionPayloadBidPool.js.map +1 -0
  122. package/lib/chain/opPools/index.d.ts +2 -0
  123. package/lib/chain/opPools/index.d.ts.map +1 -1
  124. package/lib/chain/opPools/index.js +2 -0
  125. package/lib/chain/opPools/index.js.map +1 -1
  126. package/lib/chain/opPools/opPool.js +5 -8
  127. package/lib/chain/opPools/opPool.js.map +1 -1
  128. package/lib/chain/opPools/payloadAttestationPool.d.ts +24 -0
  129. package/lib/chain/opPools/payloadAttestationPool.d.ts.map +1 -0
  130. package/lib/chain/opPools/payloadAttestationPool.js +109 -0
  131. package/lib/chain/opPools/payloadAttestationPool.js.map +1 -0
  132. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  133. package/lib/chain/prepareNextSlot.js +9 -10
  134. package/lib/chain/prepareNextSlot.js.map +1 -1
  135. package/lib/chain/produceBlock/produceBlockBody.d.ts +3 -2
  136. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  137. package/lib/chain/produceBlock/produceBlockBody.js +6 -4
  138. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  139. package/lib/chain/regen/interface.d.ts +4 -13
  140. package/lib/chain/regen/interface.d.ts.map +1 -1
  141. package/lib/chain/regen/interface.js +1 -1
  142. package/lib/chain/regen/interface.js.map +1 -1
  143. package/lib/chain/regen/queued.d.ts +5 -9
  144. package/lib/chain/regen/queued.d.ts.map +1 -1
  145. package/lib/chain/regen/queued.js +16 -40
  146. package/lib/chain/regen/queued.js.map +1 -1
  147. package/lib/chain/regen/regen.d.ts +6 -8
  148. package/lib/chain/regen/regen.d.ts.map +1 -1
  149. package/lib/chain/regen/regen.js +20 -34
  150. package/lib/chain/regen/regen.js.map +1 -1
  151. package/lib/chain/seenCache/index.d.ts +3 -1
  152. package/lib/chain/seenCache/index.d.ts.map +1 -1
  153. package/lib/chain/seenCache/index.js +3 -1
  154. package/lib/chain/seenCache/index.js.map +1 -1
  155. package/lib/chain/seenCache/seenAttesters.d.ts +5 -0
  156. package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
  157. package/lib/chain/seenCache/seenAttesters.js +5 -0
  158. package/lib/chain/seenCache/seenAttesters.js.map +1 -1
  159. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +12 -0
  160. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -0
  161. package/lib/chain/seenCache/seenExecutionPayloadBids.js +30 -0
  162. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -0
  163. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.d.ts +15 -0
  164. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.d.ts.map +1 -0
  165. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.js +28 -0
  166. package/lib/chain/seenCache/seenExecutionPayloadEnvelope.js.map +1 -0
  167. package/lib/chain/seenCache/seenGossipBlockInput.js +1 -1
  168. package/lib/chain/shufflingCache.d.ts +16 -11
  169. package/lib/chain/shufflingCache.d.ts.map +1 -1
  170. package/lib/chain/shufflingCache.js +47 -41
  171. package/lib/chain/shufflingCache.js.map +1 -1
  172. package/lib/chain/stateCache/blockStateCacheImpl.d.ts +1 -2
  173. package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +1 -1
  174. package/lib/chain/stateCache/blockStateCacheImpl.js +2 -2
  175. package/lib/chain/stateCache/blockStateCacheImpl.js.map +1 -1
  176. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +1 -2
  177. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  178. package/lib/chain/stateCache/fifoBlockStateCache.js +4 -4
  179. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  180. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts +4 -5
  181. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +1 -1
  182. package/lib/chain/stateCache/inMemoryCheckpointsCache.js +9 -10
  183. package/lib/chain/stateCache/inMemoryCheckpointsCache.js.map +1 -1
  184. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +5 -6
  185. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  186. package/lib/chain/stateCache/persistentCheckpointsCache.js +17 -17
  187. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  188. package/lib/chain/stateCache/types.d.ts +5 -6
  189. package/lib/chain/stateCache/types.d.ts.map +1 -1
  190. package/lib/chain/stateCache/types.js.map +1 -1
  191. package/lib/chain/validation/aggregateAndProof.js +35 -14
  192. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  193. package/lib/chain/validation/attestation.d.ts +2 -2
  194. package/lib/chain/validation/attestation.d.ts.map +1 -1
  195. package/lib/chain/validation/attestation.js +28 -9
  196. package/lib/chain/validation/attestation.js.map +1 -1
  197. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  198. package/lib/chain/validation/attesterSlashing.js +2 -2
  199. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  200. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  201. package/lib/chain/validation/blobSidecar.js +3 -3
  202. package/lib/chain/validation/blobSidecar.js.map +1 -1
  203. package/lib/chain/validation/block.d.ts.map +1 -1
  204. package/lib/chain/validation/block.js +7 -4
  205. package/lib/chain/validation/block.js.map +1 -1
  206. package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -1
  207. package/lib/chain/validation/blsToExecutionChange.js +9 -2
  208. package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
  209. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  210. package/lib/chain/validation/dataColumnSidecar.js +3 -3
  211. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  212. package/lib/chain/validation/executionPayloadBid.d.ts +5 -0
  213. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -0
  214. package/lib/chain/validation/executionPayloadBid.js +104 -0
  215. package/lib/chain/validation/executionPayloadBid.js.map +1 -0
  216. package/lib/chain/validation/executionPayloadEnvelope.d.ts +5 -0
  217. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -0
  218. package/lib/chain/validation/executionPayloadEnvelope.js +89 -0
  219. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -0
  220. package/lib/chain/validation/payloadAttestationMessage.d.ts +9 -0
  221. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -0
  222. package/lib/chain/validation/payloadAttestationMessage.js +72 -0
  223. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -0
  224. package/lib/chain/validation/proposerSlashing.js +3 -2
  225. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  226. package/lib/chain/validation/signatureSets/aggregateAndProof.d.ts +2 -3
  227. package/lib/chain/validation/signatureSets/aggregateAndProof.d.ts.map +1 -1
  228. package/lib/chain/validation/signatureSets/aggregateAndProof.js +8 -3
  229. package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
  230. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  231. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  232. package/lib/chain/validation/signatureSets/contributionAndProof.js +3 -3
  233. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  234. package/lib/chain/validation/signatureSets/selectionProof.d.ts +2 -3
  235. package/lib/chain/validation/signatureSets/selectionProof.d.ts.map +1 -1
  236. package/lib/chain/validation/signatureSets/selectionProof.js +8 -3
  237. package/lib/chain/validation/signatureSets/selectionProof.js.map +1 -1
  238. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  239. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  240. package/lib/chain/validation/signatureSets/syncCommittee.js +3 -3
  241. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  242. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +1 -2
  243. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  244. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  245. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  246. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  247. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  248. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +3 -3
  249. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  250. package/lib/chain/validation/syncCommittee.js +1 -1
  251. package/lib/chain/validation/syncCommittee.js.map +1 -1
  252. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
  253. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -5
  254. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  255. package/lib/chain/validation/voluntaryExit.js +1 -1
  256. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  257. package/lib/chain/validatorMonitor.d.ts +2 -0
  258. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  259. package/lib/chain/validatorMonitor.js +49 -7
  260. package/lib/chain/validatorMonitor.js.map +1 -1
  261. package/lib/db/repositories/checkpointState.d.ts +2 -6
  262. package/lib/db/repositories/checkpointState.d.ts.map +1 -1
  263. package/lib/db/repositories/checkpointState.js +3 -16
  264. package/lib/db/repositories/checkpointState.js.map +1 -1
  265. package/lib/db/repositories/stateArchive.d.ts +9 -9
  266. package/lib/db/repositories/stateArchive.d.ts.map +1 -1
  267. package/lib/db/repositories/stateArchive.js +6 -21
  268. package/lib/db/repositories/stateArchive.js.map +1 -1
  269. package/lib/execution/engine/mock.d.ts +9 -6
  270. package/lib/execution/engine/mock.d.ts.map +1 -1
  271. package/lib/execution/engine/mock.js +34 -7
  272. package/lib/execution/engine/mock.js.map +1 -1
  273. package/lib/index.d.ts +1 -1
  274. package/lib/index.d.ts.map +1 -1
  275. package/lib/index.js +1 -1
  276. package/lib/index.js.map +1 -1
  277. package/lib/metrics/metrics/lodestar.d.ts +28 -6
  278. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  279. package/lib/metrics/metrics/lodestar.js +67 -17
  280. package/lib/metrics/metrics/lodestar.js.map +1 -1
  281. package/lib/network/gossip/interface.d.ts +20 -2
  282. package/lib/network/gossip/interface.d.ts.map +1 -1
  283. package/lib/network/gossip/interface.js +3 -0
  284. package/lib/network/gossip/interface.js.map +1 -1
  285. package/lib/network/gossip/scoringParameters.d.ts.map +1 -1
  286. package/lib/network/gossip/scoringParameters.js +38 -2
  287. package/lib/network/gossip/scoringParameters.js.map +1 -1
  288. package/lib/network/gossip/topic.d.ts +77 -1
  289. package/lib/network/gossip/topic.d.ts.map +1 -1
  290. package/lib/network/gossip/topic.js +20 -0
  291. package/lib/network/gossip/topic.js.map +1 -1
  292. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  293. package/lib/network/processor/gossipHandlers.js +34 -3
  294. package/lib/network/processor/gossipHandlers.js.map +1 -1
  295. package/lib/network/processor/gossipQueues/index.d.ts.map +1 -1
  296. package/lib/network/processor/gossipQueues/index.js +16 -0
  297. package/lib/network/processor/gossipQueues/index.js.map +1 -1
  298. package/lib/network/processor/index.d.ts.map +1 -1
  299. package/lib/network/processor/index.js +3 -0
  300. package/lib/network/processor/index.js.map +1 -1
  301. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  302. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +2 -4
  303. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  304. package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts +1 -2
  305. package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts.map +1 -1
  306. package/lib/network/reqresp/handlers/beaconBlocksByRoot.js +5 -26
  307. package/lib/network/reqresp/handlers/beaconBlocksByRoot.js.map +1 -1
  308. package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts +1 -2
  309. package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts.map +1 -1
  310. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +5 -7
  311. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
  312. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  313. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -2
  314. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  315. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
  316. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -5
  317. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  318. package/lib/network/reqresp/handlers/index.js +2 -2
  319. package/lib/network/reqresp/handlers/index.js.map +1 -1
  320. package/lib/network/reqresp/utils/dataColumnResponseValidation.js +1 -1
  321. package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
  322. package/lib/node/nodejs.d.ts.map +1 -1
  323. package/lib/node/nodejs.js +17 -2
  324. package/lib/node/nodejs.js.map +1 -1
  325. package/lib/sync/backfill/backfill.js +2 -2
  326. package/lib/sync/backfill/backfill.js.map +1 -1
  327. package/lib/sync/backfill/verify.d.ts +1 -2
  328. package/lib/sync/backfill/verify.d.ts.map +1 -1
  329. package/lib/sync/backfill/verify.js +2 -2
  330. package/lib/sync/backfill/verify.js.map +1 -1
  331. package/lib/sync/range/chain.d.ts.map +1 -1
  332. package/lib/sync/range/chain.js +0 -1
  333. package/lib/sync/range/chain.js.map +1 -1
  334. package/lib/sync/range/range.d.ts.map +1 -1
  335. package/lib/sync/range/range.js +0 -3
  336. package/lib/sync/range/range.js.map +1 -1
  337. package/lib/sync/unknownBlock.d.ts.map +1 -1
  338. package/lib/sync/unknownBlock.js +0 -3
  339. package/lib/sync/unknownBlock.js.map +1 -1
  340. package/lib/util/sszBytes.js +1 -1
  341. package/lib/util/sszBytes.js.map +1 -1
  342. package/package.json +15 -15
  343. package/src/api/impl/beacon/blocks/index.ts +17 -25
  344. package/src/api/impl/beacon/state/utils.ts +2 -22
  345. package/src/api/impl/config/constants.ts +8 -0
  346. package/src/api/impl/debug/index.ts +2 -6
  347. package/src/api/impl/lodestar/index.ts +19 -4
  348. package/src/api/impl/proof/index.ts +1 -2
  349. package/src/api/impl/validator/index.ts +13 -14
  350. package/src/chain/ColumnReconstructionTracker.ts +8 -4
  351. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +5 -3
  352. package/src/chain/archiveStore/utils/archiveBlocks.ts +25 -14
  353. package/src/chain/blocks/blockInput/blockInput.ts +8 -0
  354. package/src/chain/blocks/importBlock.ts +15 -9
  355. package/src/chain/blocks/index.ts +0 -19
  356. package/src/chain/blocks/types.ts +0 -2
  357. package/src/chain/blocks/verifyBlock.ts +9 -12
  358. package/src/chain/blocks/verifyBlocksSignatures.ts +4 -12
  359. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +1 -0
  360. package/src/chain/blocks/writeBlockInputToDb.ts +24 -30
  361. package/src/chain/bls/multithread/index.ts +7 -4
  362. package/src/chain/bls/multithread/jobItem.ts +7 -3
  363. package/src/chain/bls/singleThread.ts +5 -3
  364. package/src/chain/bls/utils.ts +15 -7
  365. package/src/chain/chain.ts +230 -36
  366. package/src/chain/errors/attestationError.ts +11 -1
  367. package/src/chain/errors/executionPayloadBid.ts +35 -0
  368. package/src/chain/errors/executionPayloadEnvelope.ts +34 -0
  369. package/src/chain/errors/index.ts +3 -0
  370. package/src/chain/errors/payloadAttestation.ts +25 -0
  371. package/src/chain/forkChoice/index.ts +19 -0
  372. package/src/chain/initState.ts +5 -3
  373. package/src/chain/interface.ts +34 -3
  374. package/src/chain/lightClient/proofs.ts +0 -2
  375. package/src/chain/opPools/aggregatedAttestationPool.ts +19 -191
  376. package/src/chain/opPools/executionPayloadBidPool.ts +77 -0
  377. package/src/chain/opPools/index.ts +2 -0
  378. package/src/chain/opPools/opPool.ts +5 -7
  379. package/src/chain/opPools/payloadAttestationPool.ts +157 -0
  380. package/src/chain/prepareNextSlot.ts +8 -12
  381. package/src/chain/produceBlock/produceBlockBody.ts +13 -6
  382. package/src/chain/regen/interface.ts +3 -17
  383. package/src/chain/regen/queued.ts +17 -56
  384. package/src/chain/regen/regen.ts +22 -43
  385. package/src/chain/seenCache/index.ts +3 -1
  386. package/src/chain/seenCache/seenAttesters.ts +5 -0
  387. package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -0
  388. package/src/chain/seenCache/seenExecutionPayloadEnvelope.ts +34 -0
  389. package/src/chain/seenCache/seenGossipBlockInput.ts +1 -1
  390. package/src/chain/shufflingCache.ts +67 -50
  391. package/src/chain/stateCache/blockStateCacheImpl.ts +2 -3
  392. package/src/chain/stateCache/fifoBlockStateCache.ts +4 -5
  393. package/src/chain/stateCache/inMemoryCheckpointsCache.ts +9 -15
  394. package/src/chain/stateCache/persistentCheckpointsCache.ts +17 -25
  395. package/src/chain/stateCache/types.ts +5 -10
  396. package/src/chain/validation/aggregateAndProof.ts +36 -14
  397. package/src/chain/validation/attestation.ts +36 -19
  398. package/src/chain/validation/attesterSlashing.ts +9 -7
  399. package/src/chain/validation/blobSidecar.ts +2 -7
  400. package/src/chain/validation/block.ts +8 -4
  401. package/src/chain/validation/blsToExecutionChange.ts +9 -7
  402. package/src/chain/validation/dataColumnSidecar.ts +2 -7
  403. package/src/chain/validation/executionPayloadBid.ts +141 -0
  404. package/src/chain/validation/executionPayloadEnvelope.ts +122 -0
  405. package/src/chain/validation/payloadAttestationMessage.ts +109 -0
  406. package/src/chain/validation/proposerSlashing.ts +3 -7
  407. package/src/chain/validation/signatureSets/aggregateAndProof.ts +9 -14
  408. package/src/chain/validation/signatureSets/contributionAndProof.ts +2 -4
  409. package/src/chain/validation/signatureSets/selectionProof.ts +9 -9
  410. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -4
  411. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -3
  412. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -4
  413. package/src/chain/validation/syncCommittee.ts +1 -1
  414. package/src/chain/validation/syncCommitteeContributionAndProof.ts +3 -5
  415. package/src/chain/validation/voluntaryExit.ts +1 -1
  416. package/src/chain/validatorMonitor.ts +62 -8
  417. package/src/db/repositories/checkpointState.ts +3 -19
  418. package/src/db/repositories/stateArchive.ts +13 -27
  419. package/src/execution/engine/mock.ts +40 -13
  420. package/src/index.ts +1 -1
  421. package/src/metrics/metrics/lodestar.ts +68 -17
  422. package/src/network/gossip/interface.ts +17 -0
  423. package/src/network/gossip/scoringParameters.ts +44 -2
  424. package/src/network/gossip/topic.ts +21 -0
  425. package/src/network/processor/gossipHandlers.ts +48 -3
  426. package/src/network/processor/gossipQueues/index.ts +16 -0
  427. package/src/network/processor/index.ts +3 -0
  428. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +2 -4
  429. package/src/network/reqresp/handlers/beaconBlocksByRoot.ts +5 -32
  430. package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +5 -9
  431. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +5 -2
  432. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -5
  433. package/src/network/reqresp/handlers/index.ts +2 -2
  434. package/src/network/reqresp/utils/dataColumnResponseValidation.ts +1 -1
  435. package/src/node/nodejs.ts +18 -3
  436. package/src/sync/backfill/backfill.ts +2 -2
  437. package/src/sync/backfill/verify.ts +2 -3
  438. package/src/sync/range/chain.ts +0 -1
  439. package/src/sync/range/range.ts +0 -3
  440. package/src/sync/unknownBlock.ts +0 -3
  441. package/src/util/sszBytes.ts +1 -1
@@ -11,13 +11,14 @@ 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";
18
18
  import {nextEventLoop} from "../../util/eventLoop.js";
19
19
  import {getCheckpointFromState} from "../blocks/utils/checkpoint.js";
20
20
  import {ChainEvent, ChainEventEmitter} from "../emitter.js";
21
+ import {SeenBlockInput} from "../seenCache/seenGossipBlockInput.js";
21
22
  import {BlockStateCache, CheckpointStateCache} from "../stateCache/types.js";
22
23
  import {ValidatorMonitor} from "../validatorMonitor.js";
23
24
  import {RegenError, RegenErrorCode} from "./errors.js";
@@ -28,6 +29,7 @@ export type RegenModules = {
28
29
  forkChoice: IForkChoice;
29
30
  blockStateCache: BlockStateCache;
30
31
  checkpointStateCache: CheckpointStateCache;
32
+ seenBlockInputCache: SeenBlockInput;
31
33
  config: ChainForkConfig;
32
34
  emitter: ChainEventEmitter;
33
35
  logger: Logger;
@@ -74,24 +76,11 @@ export class StateRegenerator implements IStateRegeneratorInternal {
74
76
  // We may have the checkpoint state with parent root inside the checkpoint state cache
75
77
  // through gossip validation.
76
78
  if (parentEpoch < blockEpoch) {
77
- return this.getCheckpointState({root: block.parentRoot, epoch: blockEpoch}, opts, regenCaller, allowDiskReload);
79
+ return this.getBlockSlotState(parentBlock, block.slot, opts, regenCaller, allowDiskReload);
78
80
  }
79
81
 
80
82
  // 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);
83
+ return this.getState(parentBlock.stateRoot, regenCaller, allowDiskReload);
95
84
  }
96
85
 
97
86
  /**
@@ -99,20 +88,12 @@ export class StateRegenerator implements IStateRegeneratorInternal {
99
88
  * - allowDiskReload should be used with care, as it will cause the state to be reloaded from disk
100
89
  */
101
90
  async getBlockSlotState(
102
- blockRoot: RootHex,
91
+ block: ProtoBlock,
103
92
  slot: Slot,
104
93
  opts: StateRegenerationOpts,
105
94
  regenCaller: RegenCaller,
106
95
  allowDiskReload = false
107
96
  ): 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
97
  if (slot < block.slot) {
117
98
  throw new RegenError({
118
99
  code: RegenErrorCode.SLOT_BEFORE_BLOCK_SLOT,
@@ -121,11 +102,12 @@ export class StateRegenerator implements IStateRegeneratorInternal {
121
102
  });
122
103
  }
123
104
 
105
+ const {blockRoot} = block;
124
106
  const {checkpointStateCache} = this.modules;
125
107
  const epoch = computeEpochAtSlot(slot);
126
108
  const latestCheckpointStateCtx = allowDiskReload
127
- ? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch, opts)
128
- : checkpointStateCache.getLatest(blockRoot, epoch, opts);
109
+ ? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch)
110
+ : checkpointStateCache.getLatest(blockRoot, epoch);
129
111
 
130
112
  // If a checkpoint state exists with the given checkpoint root, it either is in requested epoch
131
113
  // or needs to have empty slots processed until the requested epoch
@@ -136,7 +118,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
136
118
  // Otherwise, use the fork choice to get the stateRoot from block at the checkpoint root
137
119
  // regenerate that state,
138
120
  // then process empty slots until the requested epoch
139
- const blockStateCtx = await this.getState(block.stateRoot, regenCaller, opts, allowDiskReload);
121
+ const blockStateCtx = await this.getState(block.stateRoot, regenCaller, allowDiskReload);
140
122
  return processSlotsByCheckpoint(this.modules, blockStateCtx, slot, regenCaller, opts);
141
123
  }
142
124
 
@@ -148,23 +130,15 @@ export class StateRegenerator implements IStateRegeneratorInternal {
148
130
  async getState(
149
131
  stateRoot: RootHex,
150
132
  caller: RegenCaller,
151
- opts?: StateRegenerationOpts,
152
133
  // internal option, don't want to expose to external caller
153
134
  allowDiskReload = false
154
135
  ): Promise<CachedBeaconStateAllForks> {
155
136
  // Trivial case, state at stateRoot is already cached
156
- const cachedStateCtx = this.modules.blockStateCache.get(stateRoot, opts);
137
+ const cachedStateCtx = this.modules.blockStateCache.get(stateRoot);
157
138
  if (cachedStateCtx) {
158
139
  return cachedStateCtx;
159
140
  }
160
141
 
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
142
  // Otherwise we have to use the fork choice to traverse backwards, block by block,
169
143
  // searching the state caches
170
144
  // then replay blocks forward to the desired stateRoot
@@ -179,7 +153,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
179
153
  const getSeedStateTimer = this.modules.metrics?.regenGetState.getSeedState.startTimer({caller});
180
154
  // iterateAncestorBlocks only returns ancestor blocks, not the block itself
181
155
  for (const b of this.modules.forkChoice.iterateAncestorBlocks(block.blockRoot)) {
182
- state = this.modules.blockStateCache.get(b.stateRoot, opts);
156
+ state = this.modules.blockStateCache.get(b.stateRoot);
183
157
  if (state) {
184
158
  break;
185
159
  }
@@ -187,8 +161,8 @@ export class StateRegenerator implements IStateRegeneratorInternal {
187
161
  if (!lastBlockToReplay) continue;
188
162
  const epoch = computeEpochAtSlot(lastBlockToReplay.slot - 1);
189
163
  state = allowDiskReload
190
- ? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch, opts)
191
- : checkpointStateCache.getLatest(b.blockRoot, epoch, opts);
164
+ ? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch)
165
+ : checkpointStateCache.getLatest(b.blockRoot, epoch);
192
166
  if (state) {
193
167
  break;
194
168
  }
@@ -219,7 +193,10 @@ export class StateRegenerator implements IStateRegeneratorInternal {
219
193
  const protoBlocksAsc = blocksToReplay.reverse();
220
194
  for (const [i, protoBlock] of protoBlocksAsc.entries()) {
221
195
  replaySlots[i] = protoBlock.slot;
222
- blockPromises[i] = this.modules.db.block.get(fromHex(protoBlock.blockRoot));
196
+ const blockInput = this.modules.seenBlockInputCache.get(protoBlock.blockRoot);
197
+ blockPromises[i] = blockInput?.hasBlock()
198
+ ? Promise.resolve(blockInput.getBlock())
199
+ : this.modules.db.block.get(fromHex(protoBlock.blockRoot));
223
200
  }
224
201
 
225
202
  const logCtx = {stateRoot, caller, replaySlots: replaySlots.join(",")};
@@ -255,6 +232,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
255
232
  try {
256
233
  // Only advances state trusting block's signture and hashes.
257
234
  // We are only running the state transition to get a specific state's data.
235
+ // stateTransition() does the clone() inside, transfer cache to make the regen faster
258
236
  state = stateTransition(
259
237
  state,
260
238
  block,
@@ -265,6 +243,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
265
243
  verifyStateRoot: false,
266
244
  verifyProposer: false,
267
245
  verifySignatures: false,
246
+ dontTransferCache: false,
268
247
  },
269
248
  this.modules
270
249
  );
@@ -390,8 +369,8 @@ export async function processSlotsToNearestCheckpoint(
390
369
  const checkpointState = postState;
391
370
  const cp = getCheckpointFromState(checkpointState);
392
371
  checkpointStateCache.add(cp, checkpointState);
393
- // consumers should not mutate or get the transfered cache
394
- emitter?.emit(ChainEvent.checkpoint, cp, checkpointState.clone(true));
372
+ // consumers should not mutate state ever
373
+ emitter?.emit(ChainEvent.checkpoint, cp, checkpointState);
395
374
 
396
375
  if (count >= 1) {
397
376
  // 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
+ }
@@ -379,7 +379,7 @@ export class SeenBlockInput {
379
379
  let itemsToDelete = this.blockInputs.size - MAX_BLOCK_INPUT_CACHE_SIZE;
380
380
 
381
381
  if (itemsToDelete > 0) {
382
- const sorted = [...this.blockInputs.entries()].sort((a, b) => b[1].slot - a[1].slot);
382
+ const sorted = [...this.blockInputs.entries()].sort((a, b) => a[1].slot - b[1].slot);
383
383
  for (const [rootHex] of sorted) {
384
384
  this.blockInputs.delete(rootHex);
385
385
  itemsToDelete--;
@@ -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;