@lodestar/beacon-node 1.35.0-dev.b42a298a7c → 1.35.0-dev.ba92bd8a88

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 (884) hide show
  1. package/lib/api/impl/api.d.ts.map +1 -0
  2. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -0
  3. package/lib/api/impl/beacon/blocks/utils.d.ts.map +1 -0
  4. package/lib/api/impl/beacon/index.d.ts.map +1 -0
  5. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -0
  6. package/lib/api/impl/beacon/rewards/index.d.ts.map +1 -0
  7. package/lib/api/impl/beacon/state/index.d.ts.map +1 -0
  8. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -0
  9. package/lib/api/impl/config/constants.d.ts.map +1 -0
  10. package/lib/api/impl/config/index.d.ts.map +1 -0
  11. package/lib/api/impl/debug/index.d.ts.map +1 -0
  12. package/lib/api/impl/errors.d.ts.map +1 -0
  13. package/lib/api/impl/events/index.d.ts.map +1 -0
  14. package/lib/api/impl/index.d.ts.map +1 -0
  15. package/lib/api/impl/lightclient/index.d.ts.map +1 -0
  16. package/lib/api/impl/lodestar/index.d.ts.map +1 -0
  17. package/lib/api/impl/node/index.d.ts.map +1 -0
  18. package/lib/api/impl/node/utils.d.ts.map +1 -0
  19. package/lib/api/impl/proof/index.d.ts.map +1 -0
  20. package/lib/api/impl/types.d.ts.map +1 -0
  21. package/lib/api/impl/utils.d.ts.map +1 -0
  22. package/lib/api/impl/validator/index.d.ts.map +1 -0
  23. package/lib/api/impl/validator/utils.d.ts.map +1 -0
  24. package/lib/api/index.d.ts.map +1 -0
  25. package/lib/api/options.d.ts.map +1 -0
  26. package/lib/api/rest/activeSockets.d.ts.map +1 -0
  27. package/lib/api/rest/base.d.ts.map +1 -0
  28. package/lib/api/rest/index.d.ts.map +1 -0
  29. package/lib/api/rest/swaggerUI.d.ts.map +1 -0
  30. package/lib/bun-wrappers/prometheus-gc-stats.d.ts.map +1 -0
  31. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -0
  32. package/lib/chain/GetBlobsTracker.d.ts.map +1 -0
  33. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -0
  34. package/lib/chain/archiveStore/constants.d.ts.map +1 -0
  35. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -0
  36. package/lib/chain/archiveStore/historicalState/historicalStateRegen.d.ts.map +1 -0
  37. package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -0
  38. package/lib/chain/archiveStore/historicalState/types.d.ts.map +1 -0
  39. package/lib/chain/archiveStore/historicalState/worker.d.ts.map +1 -0
  40. package/lib/chain/archiveStore/historicalState/worker.js +1 -1
  41. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  42. package/lib/chain/archiveStore/index.d.ts.map +1 -0
  43. package/lib/chain/archiveStore/interface.d.ts.map +1 -0
  44. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -0
  45. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -0
  46. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -0
  47. package/lib/chain/archiveStore/utils/updateBackfillRange.d.ts.map +1 -0
  48. package/lib/chain/balancesCache.d.ts.map +1 -0
  49. package/lib/chain/beaconProposerCache.d.ts.map +1 -0
  50. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -0
  51. package/lib/chain/blocks/blockInput/errors.d.ts.map +1 -0
  52. package/lib/chain/blocks/blockInput/index.d.ts.map +1 -0
  53. package/lib/chain/blocks/blockInput/types.d.ts.map +1 -0
  54. package/lib/chain/blocks/blockInput/utils.d.ts.map +1 -0
  55. package/lib/chain/blocks/importBlock.d.ts.map +1 -0
  56. package/lib/chain/blocks/index.d.ts.map +1 -0
  57. package/lib/chain/blocks/types.d.ts.map +1 -0
  58. package/lib/chain/blocks/utils/blowfishBanner.d.ts.map +1 -0
  59. package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -0
  60. package/lib/chain/blocks/utils/checkpoint.d.ts.map +1 -0
  61. package/lib/chain/blocks/utils/giraffeBanner.d.ts.map +1 -0
  62. package/lib/chain/blocks/utils/ownBanner.d.ts.map +1 -0
  63. package/lib/chain/blocks/utils/pandaMergeTransitionBanner.d.ts.map +1 -0
  64. package/lib/chain/blocks/utils/zebraBanner.d.ts.map +1 -0
  65. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -0
  66. package/lib/chain/blocks/verifyBlocksDataAvailability.d.ts.map +1 -0
  67. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -0
  68. package/lib/chain/blocks/verifyBlocksSanityChecks.d.ts.map +1 -0
  69. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -0
  70. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -0
  71. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -0
  72. package/lib/chain/bls/index.d.ts.map +1 -0
  73. package/lib/chain/bls/interface.d.ts.map +1 -0
  74. package/lib/chain/bls/maybeBatch.d.ts.map +1 -0
  75. package/lib/chain/bls/multithread/index.d.ts.map +1 -0
  76. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -0
  77. package/lib/chain/bls/multithread/poolSize.d.ts.map +1 -0
  78. package/lib/chain/bls/multithread/types.d.ts.map +1 -0
  79. package/lib/chain/bls/multithread/utils.d.ts.map +1 -0
  80. package/lib/chain/bls/multithread/worker.d.ts.map +1 -0
  81. package/lib/chain/bls/singleThread.d.ts.map +1 -0
  82. package/lib/chain/bls/utils.d.ts.map +1 -0
  83. package/lib/chain/chain.d.ts.map +1 -0
  84. package/lib/chain/emitter.d.ts +2 -2
  85. package/lib/chain/emitter.d.ts.map +1 -0
  86. package/lib/chain/errors/attestationError.d.ts.map +1 -0
  87. package/lib/chain/errors/attesterSlashingError.d.ts.map +1 -0
  88. package/lib/chain/errors/blobSidecarError.d.ts.map +1 -0
  89. package/lib/chain/errors/blockError.d.ts.map +1 -0
  90. package/lib/chain/errors/blsToExecutionChangeError.d.ts.map +1 -0
  91. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -0
  92. package/lib/chain/errors/gossipValidation.d.ts.map +1 -0
  93. package/lib/chain/errors/index.d.ts.map +1 -0
  94. package/lib/chain/errors/lightClientError.d.ts.map +1 -0
  95. package/lib/chain/errors/proposerSlashingError.d.ts.map +1 -0
  96. package/lib/chain/errors/syncCommitteeError.d.ts.map +1 -0
  97. package/lib/chain/errors/voluntaryExitError.d.ts.map +1 -0
  98. package/lib/chain/forkChoice/index.d.ts.map +1 -0
  99. package/lib/chain/genesis/genesis.d.ts.map +1 -0
  100. package/lib/chain/genesis/interface.d.ts.map +1 -0
  101. package/lib/chain/index.d.ts.map +1 -0
  102. package/lib/chain/initState.d.ts.map +1 -0
  103. package/lib/chain/interface.d.ts.map +1 -0
  104. package/lib/chain/lightClient/index.d.ts.map +1 -0
  105. package/lib/chain/lightClient/proofs.d.ts.map +1 -0
  106. package/lib/chain/lightClient/types.d.ts.map +1 -0
  107. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -0
  108. package/lib/chain/opPools/attestationPool.d.ts.map +1 -0
  109. package/lib/chain/opPools/index.d.ts.map +1 -0
  110. package/lib/chain/opPools/opPool.d.ts.map +1 -0
  111. package/lib/chain/opPools/syncCommitteeMessagePool.d.ts.map +1 -0
  112. package/lib/chain/opPools/syncContributionAndProofPool.d.ts.map +1 -0
  113. package/lib/chain/opPools/types.d.ts.map +1 -0
  114. package/lib/chain/opPools/utils.d.ts.map +1 -0
  115. package/lib/chain/options.d.ts.map +1 -0
  116. package/lib/chain/prepareNextSlot.d.ts.map +1 -0
  117. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -0
  118. package/lib/chain/produceBlock/index.d.ts.map +1 -0
  119. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -0
  120. package/lib/chain/produceBlock/validateBlobsAndKzgCommitments.d.ts.map +1 -0
  121. package/lib/chain/regen/errors.d.ts.map +1 -0
  122. package/lib/chain/regen/index.d.ts.map +1 -0
  123. package/lib/chain/regen/interface.d.ts.map +1 -0
  124. package/lib/chain/regen/queued.d.ts.map +1 -0
  125. package/lib/chain/regen/regen.d.ts.map +1 -0
  126. package/lib/chain/reprocess.d.ts.map +1 -0
  127. package/lib/chain/rewards/attestationsRewards.d.ts.map +1 -0
  128. package/lib/chain/rewards/blockRewards.d.ts.map +1 -0
  129. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +1 -0
  130. package/lib/chain/seenCache/index.d.ts.map +1 -0
  131. package/lib/chain/seenCache/seenAggregateAndProof.d.ts.map +1 -0
  132. package/lib/chain/seenCache/seenAttestationData.d.ts.map +1 -0
  133. package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -0
  134. package/lib/chain/seenCache/seenBlockAttesters.d.ts.map +1 -0
  135. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -0
  136. package/lib/chain/seenCache/seenCommittee.d.ts.map +1 -0
  137. package/lib/chain/seenCache/seenCommitteeContribution.d.ts.map +1 -0
  138. package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -0
  139. package/lib/chain/serializeState.d.ts.map +1 -0
  140. package/lib/chain/shufflingCache.d.ts.map +1 -0
  141. package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +1 -0
  142. package/lib/chain/stateCache/datastore/db.d.ts.map +1 -0
  143. package/lib/chain/stateCache/datastore/file.d.ts.map +1 -0
  144. package/lib/chain/stateCache/datastore/index.d.ts.map +1 -0
  145. package/lib/chain/stateCache/datastore/types.d.ts.map +1 -0
  146. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -0
  147. package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +1 -0
  148. package/lib/chain/stateCache/index.d.ts.map +1 -0
  149. package/lib/chain/stateCache/mapMetrics.d.ts.map +1 -0
  150. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -0
  151. package/lib/chain/stateCache/types.d.ts.map +1 -0
  152. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -0
  153. package/lib/chain/validation/attestation.d.ts.map +1 -0
  154. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -0
  155. package/lib/chain/validation/blobSidecar.d.ts.map +1 -0
  156. package/lib/chain/validation/block.d.ts.map +1 -0
  157. package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -0
  158. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -0
  159. package/lib/chain/validation/index.d.ts.map +1 -0
  160. package/lib/chain/validation/lightClientFinalityUpdate.d.ts.map +1 -0
  161. package/lib/chain/validation/lightClientOptimisticUpdate.d.ts.map +1 -0
  162. package/lib/chain/validation/proposerSlashing.d.ts.map +1 -0
  163. package/lib/chain/validation/signatureSets/aggregateAndProof.d.ts.map +1 -0
  164. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -0
  165. package/lib/chain/validation/signatureSets/index.d.ts.map +1 -0
  166. package/lib/chain/validation/signatureSets/selectionProof.d.ts.map +1 -0
  167. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -0
  168. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -0
  169. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -0
  170. package/lib/chain/validation/syncCommittee.d.ts.map +1 -0
  171. package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -0
  172. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -0
  173. package/lib/chain/validatorMonitor.d.ts.map +1 -0
  174. package/lib/constants/constants.d.ts.map +1 -0
  175. package/lib/constants/index.d.ts.map +1 -0
  176. package/lib/constants/network.d.ts.map +1 -0
  177. package/lib/db/beacon.d.ts.map +1 -0
  178. package/lib/db/buckets.d.ts +4 -4
  179. package/lib/db/buckets.d.ts.map +1 -0
  180. package/lib/db/buckets.js +4 -4
  181. package/lib/db/buckets.js.map +1 -1
  182. package/lib/db/index.d.ts.map +1 -0
  183. package/lib/db/interface.d.ts.map +1 -0
  184. package/lib/db/options.d.ts.map +1 -0
  185. package/lib/db/repositories/attesterSlashing.d.ts.map +1 -0
  186. package/lib/db/repositories/backfilledRanges.d.ts.map +1 -0
  187. package/lib/db/repositories/blobSidecars.d.ts.map +1 -0
  188. package/lib/db/repositories/blobSidecars.js +1 -1
  189. package/lib/db/repositories/blobSidecars.js.map +1 -1
  190. package/lib/db/repositories/blobSidecarsArchive.d.ts.map +1 -0
  191. package/lib/db/repositories/blobSidecarsArchive.js +1 -1
  192. package/lib/db/repositories/blobSidecarsArchive.js.map +1 -1
  193. package/lib/db/repositories/block.d.ts.map +1 -0
  194. package/lib/db/repositories/blockArchive.d.ts.map +1 -0
  195. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  196. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -0
  197. package/lib/db/repositories/blsToExecutionChange.d.ts.map +1 -0
  198. package/lib/db/repositories/checkpointState.d.ts.map +1 -0
  199. package/lib/db/repositories/dataColumnSidecar.d.ts.map +1 -0
  200. package/lib/db/repositories/dataColumnSidecar.js +1 -1
  201. package/lib/db/repositories/dataColumnSidecar.js.map +1 -1
  202. package/lib/db/repositories/dataColumnSidecarArchive.d.ts.map +1 -0
  203. package/lib/db/repositories/dataColumnSidecarArchive.js +1 -1
  204. package/lib/db/repositories/dataColumnSidecarArchive.js.map +1 -1
  205. package/lib/db/repositories/depositDataRoot.d.ts.map +1 -0
  206. package/lib/db/repositories/depositEvent.d.ts.map +1 -0
  207. package/lib/db/repositories/eth1Data.d.ts.map +1 -0
  208. package/lib/db/repositories/index.d.ts.map +1 -0
  209. package/lib/db/repositories/lightclientBestUpdate.d.ts.map +1 -0
  210. package/lib/db/repositories/lightclientCheckpointHeader.d.ts.map +1 -0
  211. package/lib/db/repositories/lightclientSyncCommittee.d.ts.map +1 -0
  212. package/lib/db/repositories/lightclientSyncCommitteeWitness.d.ts.map +1 -0
  213. package/lib/db/repositories/proposerSlashing.d.ts.map +1 -0
  214. package/lib/db/repositories/stateArchive.d.ts.map +1 -0
  215. package/lib/db/repositories/stateArchiveIndex.d.ts.map +1 -0
  216. package/lib/db/repositories/voluntaryExit.d.ts.map +1 -0
  217. package/lib/db/single/index.d.ts.map +1 -0
  218. package/lib/db/single/preGenesisState.d.ts.map +1 -0
  219. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts.map +1 -0
  220. package/lib/eth1/errors.d.ts.map +1 -0
  221. package/lib/eth1/eth1DataCache.d.ts.map +1 -0
  222. package/lib/eth1/eth1DepositDataTracker.d.ts.map +1 -0
  223. package/lib/eth1/eth1DepositsCache.d.ts.map +1 -0
  224. package/lib/eth1/eth1MergeBlockTracker.d.ts.map +1 -0
  225. package/lib/eth1/index.d.ts.map +1 -0
  226. package/lib/eth1/interface.d.ts.map +1 -0
  227. package/lib/eth1/options.d.ts.map +1 -0
  228. package/lib/eth1/provider/eth1Provider.d.ts.map +1 -0
  229. package/lib/eth1/provider/jsonRpcHttpClient.d.ts.map +1 -0
  230. package/lib/eth1/provider/jwt.d.ts.map +1 -0
  231. package/lib/eth1/provider/utils.d.ts.map +1 -0
  232. package/lib/eth1/stream.d.ts.map +1 -0
  233. package/lib/eth1/utils/depositContract.d.ts.map +1 -0
  234. package/lib/eth1/utils/deposits.d.ts.map +1 -0
  235. package/lib/eth1/utils/eth1Data.d.ts.map +1 -0
  236. package/lib/eth1/utils/eth1DepositEvent.d.ts.map +1 -0
  237. package/lib/eth1/utils/eth1Vote.d.ts.map +1 -0
  238. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts.map +1 -0
  239. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts.map +1 -0
  240. package/lib/execution/builder/cache.d.ts.map +1 -0
  241. package/lib/execution/builder/http.d.ts.map +1 -0
  242. package/lib/execution/builder/index.d.ts.map +1 -0
  243. package/lib/execution/builder/interface.d.ts.map +1 -0
  244. package/lib/execution/builder/utils.d.ts.map +1 -0
  245. package/lib/execution/engine/disabled.d.ts.map +1 -0
  246. package/lib/execution/engine/http.d.ts.map +1 -0
  247. package/lib/execution/engine/index.d.ts.map +1 -0
  248. package/lib/execution/engine/interface.d.ts.map +1 -0
  249. package/lib/execution/engine/mock.d.ts.map +1 -0
  250. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -0
  251. package/lib/execution/engine/types.d.ts.map +1 -0
  252. package/lib/execution/engine/utils.d.ts.map +1 -0
  253. package/lib/execution/index.d.ts.map +1 -0
  254. package/lib/index.d.ts.map +1 -0
  255. package/lib/metrics/index.d.ts.map +1 -0
  256. package/lib/metrics/metrics/beacon.d.ts.map +1 -0
  257. package/lib/metrics/metrics/lodestar.d.ts.map +1 -0
  258. package/lib/metrics/metrics.d.ts.map +1 -0
  259. package/lib/metrics/nodeJsMetrics.d.ts.map +1 -0
  260. package/lib/metrics/options.d.ts.map +1 -0
  261. package/lib/metrics/server/http.d.ts.map +1 -0
  262. package/lib/metrics/server/index.d.ts.map +1 -0
  263. package/lib/metrics/utils/avgMinMax.d.ts.map +1 -0
  264. package/lib/metrics/utils/gauge.d.ts.map +1 -0
  265. package/lib/metrics/utils/registryMetricCreator.d.ts.map +1 -0
  266. package/lib/monitoring/clientStats.d.ts.map +1 -0
  267. package/lib/monitoring/index.d.ts.map +1 -0
  268. package/lib/monitoring/options.d.ts.map +1 -0
  269. package/lib/monitoring/properties.d.ts.map +1 -0
  270. package/lib/monitoring/service.d.ts.map +1 -0
  271. package/lib/monitoring/system.d.ts.map +1 -0
  272. package/lib/monitoring/types.d.ts.map +1 -0
  273. package/lib/network/core/events.d.ts.map +1 -0
  274. package/lib/network/core/index.d.ts.map +1 -0
  275. package/lib/network/core/metrics.d.ts.map +1 -0
  276. package/lib/network/core/networkCore.d.ts.map +1 -0
  277. package/lib/network/core/networkCoreWorker.d.ts.map +1 -0
  278. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -0
  279. package/lib/network/core/types.d.ts.map +1 -0
  280. package/lib/network/discv5/index.d.ts.map +1 -0
  281. package/lib/network/discv5/types.d.ts.map +1 -0
  282. package/lib/network/discv5/utils.d.ts.map +1 -0
  283. package/lib/network/discv5/worker.d.ts.map +1 -0
  284. package/lib/network/events.d.ts.map +1 -0
  285. package/lib/network/forks.d.ts.map +1 -0
  286. package/lib/network/gossip/constants.d.ts.map +1 -0
  287. package/lib/network/gossip/encoding.d.ts.map +1 -0
  288. package/lib/network/gossip/errors.d.ts.map +1 -0
  289. package/lib/network/gossip/gossipsub.d.ts +1 -0
  290. package/lib/network/gossip/gossipsub.d.ts.map +1 -0
  291. package/lib/network/gossip/gossipsub.js +35 -16
  292. package/lib/network/gossip/gossipsub.js.map +1 -1
  293. package/lib/network/gossip/index.d.ts.map +1 -0
  294. package/lib/network/gossip/interface.d.ts.map +1 -0
  295. package/lib/network/gossip/metrics.d.ts +15 -7
  296. package/lib/network/gossip/metrics.d.ts.map +1 -0
  297. package/lib/network/gossip/metrics.js +16 -6
  298. package/lib/network/gossip/metrics.js.map +1 -1
  299. package/lib/network/gossip/scoringParameters.d.ts.map +1 -0
  300. package/lib/network/gossip/topic.d.ts.map +1 -0
  301. package/lib/network/index.d.ts.map +1 -0
  302. package/lib/network/interface.d.ts.map +1 -0
  303. package/lib/network/libp2p/error.d.ts.map +1 -0
  304. package/lib/network/libp2p/index.d.ts.map +1 -0
  305. package/lib/network/metadata.d.ts.map +1 -0
  306. package/lib/network/metadata.js +2 -1
  307. package/lib/network/metadata.js.map +1 -1
  308. package/lib/network/network.d.ts.map +1 -0
  309. package/lib/network/network.js +2 -4
  310. package/lib/network/network.js.map +1 -1
  311. package/lib/network/networkConfig.d.ts.map +1 -0
  312. package/lib/network/options.d.ts.map +1 -0
  313. package/lib/network/peers/client.d.ts.map +1 -0
  314. package/lib/network/peers/datastore.d.ts.map +1 -0
  315. package/lib/network/peers/discover.d.ts.map +1 -0
  316. package/lib/network/peers/index.d.ts.map +1 -0
  317. package/lib/network/peers/peerManager.d.ts.map +1 -0
  318. package/lib/network/peers/peersData.d.ts.map +1 -0
  319. package/lib/network/peers/score/constants.d.ts.map +1 -0
  320. package/lib/network/peers/score/index.d.ts.map +1 -0
  321. package/lib/network/peers/score/interface.d.ts.map +1 -0
  322. package/lib/network/peers/score/score.d.ts.map +1 -0
  323. package/lib/network/peers/score/store.d.ts.map +1 -0
  324. package/lib/network/peers/score/utils.d.ts.map +1 -0
  325. package/lib/network/peers/utils/assertPeerRelevance.d.ts.map +1 -0
  326. package/lib/network/peers/utils/enrSubnetsDeserialize.d.ts.map +1 -0
  327. package/lib/network/peers/utils/getConnectedPeerIds.d.ts.map +1 -0
  328. package/lib/network/peers/utils/index.d.ts.map +1 -0
  329. package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -0
  330. package/lib/network/peers/utils/subnetMap.d.ts.map +1 -0
  331. package/lib/network/processor/aggregatorTracker.d.ts.map +1 -0
  332. package/lib/network/processor/extractSlotRootFns.d.ts.map +1 -0
  333. package/lib/network/processor/gossipHandlers.d.ts.map +1 -0
  334. package/lib/network/processor/gossipQueues/index.d.ts.map +1 -0
  335. package/lib/network/processor/gossipQueues/indexed.d.ts.map +1 -0
  336. package/lib/network/processor/gossipQueues/linear.d.ts.map +1 -0
  337. package/lib/network/processor/gossipQueues/types.d.ts.map +1 -0
  338. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -0
  339. package/lib/network/processor/index.d.ts +1 -1
  340. package/lib/network/processor/index.d.ts.map +1 -0
  341. package/lib/network/processor/index.js +2 -3
  342. package/lib/network/processor/index.js.map +1 -1
  343. package/lib/network/processor/types.d.ts.map +1 -0
  344. package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -0
  345. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -0
  346. package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts.map +1 -0
  347. package/lib/network/reqresp/handlers/blobSidecarsByRange.d.ts.map +1 -0
  348. package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts.map +1 -0
  349. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -0
  350. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -0
  351. package/lib/network/reqresp/handlers/index.d.ts.map +1 -0
  352. package/lib/network/reqresp/handlers/lightClientBootstrap.d.ts.map +1 -0
  353. package/lib/network/reqresp/handlers/lightClientFinalityUpdate.d.ts.map +1 -0
  354. package/lib/network/reqresp/handlers/lightClientOptimisticUpdate.d.ts.map +1 -0
  355. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.d.ts.map +1 -0
  356. package/lib/network/reqresp/index.d.ts.map +1 -0
  357. package/lib/network/reqresp/interface.d.ts.map +1 -0
  358. package/lib/network/reqresp/protocols.d.ts.map +1 -0
  359. package/lib/network/reqresp/rateLimit.d.ts.map +1 -0
  360. package/lib/network/reqresp/score.d.ts.map +1 -0
  361. package/lib/network/reqresp/types.d.ts.map +1 -0
  362. package/lib/network/reqresp/utils/collect.d.ts.map +1 -0
  363. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -0
  364. package/lib/network/reqresp/utils/dataColumnResponseValidation.d.ts.map +1 -0
  365. package/lib/network/statusCache.d.ts.map +1 -0
  366. package/lib/network/subnets/attnetsService.d.ts.map +1 -0
  367. package/lib/network/subnets/index.d.ts.map +1 -0
  368. package/lib/network/subnets/interface.d.ts.map +1 -0
  369. package/lib/network/subnets/syncnetsService.d.ts.map +1 -0
  370. package/lib/network/subnets/util.d.ts.map +1 -0
  371. package/lib/network/util.d.ts.map +1 -0
  372. package/lib/node/index.d.ts.map +1 -0
  373. package/lib/node/nodejs.d.ts.map +1 -0
  374. package/lib/node/notifier.d.ts.map +1 -0
  375. package/lib/node/options.d.ts.map +1 -0
  376. package/lib/node/utils/interop/deposits.d.ts.map +1 -0
  377. package/lib/node/utils/interop/state.d.ts.map +1 -0
  378. package/lib/node/utils/lightclient.d.ts.map +1 -0
  379. package/lib/node/utils/state.d.ts.map +1 -0
  380. package/lib/sync/backfill/backfill.d.ts.map +1 -0
  381. package/lib/sync/backfill/errors.d.ts.map +1 -0
  382. package/lib/sync/backfill/index.d.ts.map +1 -0
  383. package/lib/sync/backfill/verify.d.ts.map +1 -0
  384. package/lib/sync/constants.d.ts.map +1 -0
  385. package/lib/sync/index.d.ts.map +1 -0
  386. package/lib/sync/interface.d.ts.map +1 -0
  387. package/lib/sync/options.d.ts.map +1 -0
  388. package/lib/sync/range/batch.d.ts.map +1 -0
  389. package/lib/sync/range/chain.d.ts.map +1 -0
  390. package/lib/sync/range/range.d.ts.map +1 -0
  391. package/lib/sync/range/utils/batches.d.ts.map +1 -0
  392. package/lib/sync/range/utils/chainTarget.d.ts.map +1 -0
  393. package/lib/sync/range/utils/hashBlocks.d.ts.map +1 -0
  394. package/lib/sync/range/utils/index.d.ts.map +1 -0
  395. package/lib/sync/range/utils/peerBalancer.d.ts.map +1 -0
  396. package/lib/sync/range/utils/updateChains.d.ts.map +1 -0
  397. package/lib/sync/sync.d.ts.map +1 -0
  398. package/lib/sync/types.d.ts +0 -1
  399. package/lib/sync/types.d.ts.map +1 -0
  400. package/lib/sync/types.js.map +1 -1
  401. package/lib/sync/unknownBlock.d.ts.map +1 -0
  402. package/lib/sync/unknownBlock.js +12 -14
  403. package/lib/sync/unknownBlock.js.map +1 -1
  404. package/lib/sync/utils/downloadByRange.d.ts.map +1 -0
  405. package/lib/sync/utils/downloadByRoot.d.ts +3 -1
  406. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -0
  407. package/lib/sync/utils/downloadByRoot.js +32 -5
  408. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  409. package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -0
  410. package/lib/sync/utils/remoteSyncType.d.ts.map +1 -0
  411. package/lib/util/address.d.ts.map +1 -0
  412. package/lib/util/array.d.ts.map +1 -0
  413. package/lib/util/asyncIterableToEvents.d.ts.map +1 -0
  414. package/lib/util/binarySearch.d.ts.map +1 -0
  415. package/lib/util/bitArray.d.ts.map +1 -0
  416. package/lib/util/blobs.d.ts.map +1 -0
  417. package/lib/util/blobs.js +5 -3
  418. package/lib/util/blobs.js.map +1 -1
  419. package/lib/util/bufferPool.d.ts.map +1 -0
  420. package/lib/util/bytes.d.ts.map +1 -0
  421. package/lib/util/chunkify.d.ts.map +1 -0
  422. package/lib/util/clock.d.ts.map +1 -0
  423. package/lib/util/dataColumns.d.ts.map +1 -0
  424. package/lib/util/dependentRoot.d.ts.map +1 -0
  425. package/lib/util/enum.d.ts.map +1 -0
  426. package/lib/util/error.d.ts.map +1 -0
  427. package/lib/util/eventLoop.d.ts.map +1 -0
  428. package/lib/util/execution.d.ts.map +1 -0
  429. package/lib/util/file.d.ts.map +1 -0
  430. package/lib/util/forkChoice.d.ts.map +1 -0
  431. package/lib/util/forkName.d.ts.map +1 -0
  432. package/lib/util/graffiti.d.ts.map +1 -0
  433. package/lib/util/hex.d.ts.map +1 -0
  434. package/lib/util/index.d.ts.map +1 -0
  435. package/lib/util/ip.d.ts.map +1 -0
  436. package/lib/util/itTrigger.d.ts.map +1 -0
  437. package/lib/util/kzg.d.ts.map +1 -0
  438. package/lib/util/map.d.ts.map +1 -0
  439. package/lib/util/metadata.d.ts.map +1 -0
  440. package/lib/util/multifork.d.ts.map +1 -0
  441. package/lib/util/numpy.d.ts.map +1 -0
  442. package/lib/util/peerId.d.ts.map +1 -0
  443. package/lib/util/profile.d.ts.map +1 -0
  444. package/lib/util/promises.d.ts.map +1 -0
  445. package/lib/util/queue/errors.d.ts.map +1 -0
  446. package/lib/util/queue/fnQueue.d.ts.map +1 -0
  447. package/lib/util/queue/index.d.ts.map +1 -0
  448. package/lib/util/queue/itemQueue.d.ts.map +1 -0
  449. package/lib/util/queue/options.d.ts.map +1 -0
  450. package/lib/util/serializedCache.d.ts.map +1 -0
  451. package/lib/util/set.d.ts.map +1 -0
  452. package/lib/util/shuffle.d.ts.map +1 -0
  453. package/lib/util/sortBy.d.ts.map +1 -0
  454. package/lib/util/sszBytes.d.ts.map +1 -0
  455. package/lib/util/strictEvents.d.ts.map +1 -0
  456. package/lib/util/time.d.ts.map +1 -0
  457. package/lib/util/timeSeries.d.ts.map +1 -0
  458. package/lib/util/types.d.ts.map +1 -0
  459. package/lib/util/workerEvents.d.ts.map +1 -0
  460. package/lib/util/wrapError.d.ts.map +1 -0
  461. package/package.json +18 -20
  462. package/src/api/impl/api.ts +26 -0
  463. package/src/api/impl/beacon/blocks/index.ts +744 -0
  464. package/src/api/impl/beacon/blocks/utils.ts +75 -0
  465. package/src/api/impl/beacon/index.ts +35 -0
  466. package/src/api/impl/beacon/pool/index.ts +314 -0
  467. package/src/api/impl/beacon/rewards/index.ts +30 -0
  468. package/src/api/impl/beacon/state/index.ts +406 -0
  469. package/src/api/impl/beacon/state/utils.ts +189 -0
  470. package/src/api/impl/config/constants.ts +127 -0
  471. package/src/api/impl/config/index.ts +59 -0
  472. package/src/api/impl/debug/index.ts +131 -0
  473. package/src/api/impl/errors.ts +50 -0
  474. package/src/api/impl/events/index.ts +33 -0
  475. package/src/api/impl/index.ts +6 -0
  476. package/src/api/impl/lightclient/index.ts +64 -0
  477. package/src/api/impl/lodestar/index.ts +257 -0
  478. package/src/api/impl/node/index.ts +88 -0
  479. package/src/api/impl/node/utils.ts +51 -0
  480. package/src/api/impl/proof/index.ts +60 -0
  481. package/src/api/impl/types.ts +17 -0
  482. package/src/api/impl/utils.ts +25 -0
  483. package/src/api/impl/validator/index.ts +1538 -0
  484. package/src/api/impl/validator/utils.ts +85 -0
  485. package/src/api/index.ts +2 -0
  486. package/src/api/options.ts +16 -0
  487. package/src/api/rest/activeSockets.ts +109 -0
  488. package/src/api/rest/base.ts +216 -0
  489. package/src/api/rest/index.ts +63 -0
  490. package/src/api/rest/swaggerUI.ts +80 -0
  491. package/src/bun-wrappers/prometheus-gc-stats.ts +7 -0
  492. package/src/chain/ColumnReconstructionTracker.ts +90 -0
  493. package/src/chain/GetBlobsTracker.ts +115 -0
  494. package/src/chain/archiveStore/archiveStore.ts +222 -0
  495. package/src/chain/archiveStore/constants.ts +5 -0
  496. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +116 -0
  497. package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +68 -0
  498. package/src/chain/archiveStore/historicalState/metrics.ts +214 -0
  499. package/src/chain/archiveStore/historicalState/types.ts +41 -0
  500. package/src/chain/archiveStore/historicalState/worker.ts +77 -0
  501. package/src/chain/archiveStore/index.ts +3 -0
  502. package/src/chain/archiveStore/interface.ts +75 -0
  503. package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +138 -0
  504. package/src/chain/archiveStore/utils/archiveBlocks.ts +437 -0
  505. package/src/chain/archiveStore/utils/pruneHistory.ts +56 -0
  506. package/src/chain/archiveStore/utils/updateBackfillRange.ts +50 -0
  507. package/src/chain/balancesCache.ts +52 -0
  508. package/src/chain/beaconProposerCache.ts +43 -0
  509. package/src/chain/blocks/blockInput/blockInput.ts +851 -0
  510. package/src/chain/blocks/blockInput/errors.ts +48 -0
  511. package/src/chain/blocks/blockInput/index.ts +4 -0
  512. package/src/chain/blocks/blockInput/types.ts +145 -0
  513. package/src/chain/blocks/blockInput/utils.ts +21 -0
  514. package/src/chain/blocks/importBlock.ts +603 -0
  515. package/src/chain/blocks/index.ts +179 -0
  516. package/src/chain/blocks/types.ts +101 -0
  517. package/src/chain/blocks/utils/blowfishBanner.ts +28 -0
  518. package/src/chain/blocks/utils/chainSegment.ts +29 -0
  519. package/src/chain/blocks/utils/checkpoint.ts +25 -0
  520. package/src/chain/blocks/utils/giraffeBanner.ts +30 -0
  521. package/src/chain/blocks/utils/ownBanner.ts +20 -0
  522. package/src/chain/blocks/utils/pandaMergeTransitionBanner.ts +43 -0
  523. package/src/chain/blocks/utils/zebraBanner.ts +45 -0
  524. package/src/chain/blocks/verifyBlock.ts +242 -0
  525. package/src/chain/blocks/verifyBlocksDataAvailability.ts +34 -0
  526. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +438 -0
  527. package/src/chain/blocks/verifyBlocksSanityChecks.ts +129 -0
  528. package/src/chain/blocks/verifyBlocksSignatures.ts +105 -0
  529. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +114 -0
  530. package/src/chain/blocks/writeBlockInputToDb.ts +128 -0
  531. package/src/chain/bls/index.ts +4 -0
  532. package/src/chain/bls/interface.ts +68 -0
  533. package/src/chain/bls/maybeBatch.ts +45 -0
  534. package/src/chain/bls/multithread/index.ts +582 -0
  535. package/src/chain/bls/multithread/jobItem.ts +119 -0
  536. package/src/chain/bls/multithread/poolSize.ts +16 -0
  537. package/src/chain/bls/multithread/types.ts +38 -0
  538. package/src/chain/bls/multithread/utils.ts +19 -0
  539. package/src/chain/bls/multithread/worker.ts +114 -0
  540. package/src/chain/bls/singleThread.ts +87 -0
  541. package/src/chain/bls/utils.ts +30 -0
  542. package/src/chain/chain.ts +1365 -0
  543. package/src/chain/emitter.ts +113 -0
  544. package/src/chain/errors/attestationError.ts +194 -0
  545. package/src/chain/errors/attesterSlashingError.ts +11 -0
  546. package/src/chain/errors/blobSidecarError.ts +60 -0
  547. package/src/chain/errors/blockError.ts +166 -0
  548. package/src/chain/errors/blsToExecutionChangeError.ts +13 -0
  549. package/src/chain/errors/dataColumnSidecarError.ts +80 -0
  550. package/src/chain/errors/gossipValidation.ts +20 -0
  551. package/src/chain/errors/index.ts +10 -0
  552. package/src/chain/errors/lightClientError.ts +30 -0
  553. package/src/chain/errors/proposerSlashingError.ts +11 -0
  554. package/src/chain/errors/syncCommitteeError.ts +36 -0
  555. package/src/chain/errors/voluntaryExitError.ts +13 -0
  556. package/src/chain/forkChoice/index.ts +112 -0
  557. package/src/chain/genesis/genesis.ts +190 -0
  558. package/src/chain/genesis/interface.ts +14 -0
  559. package/src/chain/index.ts +6 -0
  560. package/src/chain/initState.ts +221 -0
  561. package/src/chain/interface.ts +280 -0
  562. package/src/chain/lightClient/index.ts +764 -0
  563. package/src/chain/lightClient/proofs.ts +85 -0
  564. package/src/chain/lightClient/types.ts +33 -0
  565. package/src/chain/opPools/aggregatedAttestationPool.ts +1063 -0
  566. package/src/chain/opPools/attestationPool.ts +283 -0
  567. package/src/chain/opPools/index.ts +5 -0
  568. package/src/chain/opPools/opPool.ts +462 -0
  569. package/src/chain/opPools/syncCommitteeMessagePool.ts +167 -0
  570. package/src/chain/opPools/syncContributionAndProofPool.ts +240 -0
  571. package/src/chain/opPools/types.ts +35 -0
  572. package/src/chain/opPools/utils.ts +65 -0
  573. package/src/chain/options.ts +138 -0
  574. package/src/chain/prepareNextSlot.ts +277 -0
  575. package/src/chain/produceBlock/computeNewStateRoot.ts +55 -0
  576. package/src/chain/produceBlock/index.ts +2 -0
  577. package/src/chain/produceBlock/produceBlockBody.ts +797 -0
  578. package/src/chain/produceBlock/validateBlobsAndKzgCommitments.ts +54 -0
  579. package/src/chain/regen/errors.ts +30 -0
  580. package/src/chain/regen/index.ts +4 -0
  581. package/src/chain/regen/interface.ts +93 -0
  582. package/src/chain/regen/queued.ts +317 -0
  583. package/src/chain/regen/regen.ts +424 -0
  584. package/src/chain/reprocess.ts +161 -0
  585. package/src/chain/rewards/attestationsRewards.ts +196 -0
  586. package/src/chain/rewards/blockRewards.ts +150 -0
  587. package/src/chain/rewards/syncCommitteeRewards.ts +58 -0
  588. package/src/chain/seenCache/index.ts +5 -0
  589. package/src/chain/seenCache/seenAggregateAndProof.ts +120 -0
  590. package/src/chain/seenCache/seenAttestationData.ts +145 -0
  591. package/src/chain/seenCache/seenAttesters.ts +58 -0
  592. package/src/chain/seenCache/seenBlockAttesters.ts +18 -0
  593. package/src/chain/seenCache/seenBlockProposers.ts +48 -0
  594. package/src/chain/seenCache/seenCommittee.ts +43 -0
  595. package/src/chain/seenCache/seenCommitteeContribution.ts +104 -0
  596. package/src/chain/seenCache/seenGossipBlockInput.ts +373 -0
  597. package/src/chain/serializeState.ts +32 -0
  598. package/src/chain/shufflingCache.ts +238 -0
  599. package/src/chain/stateCache/blockStateCacheImpl.ts +150 -0
  600. package/src/chain/stateCache/datastore/db.ts +36 -0
  601. package/src/chain/stateCache/datastore/file.ts +53 -0
  602. package/src/chain/stateCache/datastore/index.ts +2 -0
  603. package/src/chain/stateCache/datastore/types.ts +13 -0
  604. package/src/chain/stateCache/fifoBlockStateCache.ts +208 -0
  605. package/src/chain/stateCache/inMemoryCheckpointsCache.ts +198 -0
  606. package/src/chain/stateCache/index.ts +3 -0
  607. package/src/chain/stateCache/mapMetrics.ts +52 -0
  608. package/src/chain/stateCache/persistentCheckpointsCache.ts +835 -0
  609. package/src/chain/stateCache/types.ts +86 -0
  610. package/src/chain/validation/aggregateAndProof.ts +258 -0
  611. package/src/chain/validation/attestation.ts +885 -0
  612. package/src/chain/validation/attesterSlashing.ts +61 -0
  613. package/src/chain/validation/blobSidecar.ts +301 -0
  614. package/src/chain/validation/block.ts +188 -0
  615. package/src/chain/validation/blsToExecutionChange.ts +61 -0
  616. package/src/chain/validation/dataColumnSidecar.ts +381 -0
  617. package/src/chain/validation/index.ts +9 -0
  618. package/src/chain/validation/lightClientFinalityUpdate.ts +45 -0
  619. package/src/chain/validation/lightClientOptimisticUpdate.ts +67 -0
  620. package/src/chain/validation/proposerSlashing.ts +54 -0
  621. package/src/chain/validation/signatureSets/aggregateAndProof.ts +38 -0
  622. package/src/chain/validation/signatureSets/contributionAndProof.ts +27 -0
  623. package/src/chain/validation/signatureSets/index.ts +6 -0
  624. package/src/chain/validation/signatureSets/selectionProof.ts +27 -0
  625. package/src/chain/validation/signatureSets/syncCommittee.ts +22 -0
  626. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +18 -0
  627. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +27 -0
  628. package/src/chain/validation/syncCommittee.ts +165 -0
  629. package/src/chain/validation/syncCommitteeContributionAndProof.ts +122 -0
  630. package/src/chain/validation/voluntaryExit.ts +58 -0
  631. package/src/chain/validatorMonitor.ts +1299 -0
  632. package/src/constants/constants.ts +15 -0
  633. package/src/constants/index.ts +2 -0
  634. package/src/constants/network.ts +52 -0
  635. package/src/db/beacon.ts +113 -0
  636. package/src/db/buckets.ts +80 -0
  637. package/src/db/index.ts +2 -0
  638. package/src/db/interface.ts +76 -0
  639. package/src/db/options.ts +7 -0
  640. package/src/db/repositories/attesterSlashing.ts +38 -0
  641. package/src/db/repositories/backfilledRanges.ts +29 -0
  642. package/src/db/repositories/blobSidecars.ts +37 -0
  643. package/src/db/repositories/blobSidecarsArchive.ts +28 -0
  644. package/src/db/repositories/block.ts +33 -0
  645. package/src/db/repositories/blockArchive.ts +170 -0
  646. package/src/db/repositories/blockArchiveIndex.ts +45 -0
  647. package/src/db/repositories/blsToExecutionChange.ts +16 -0
  648. package/src/db/repositories/checkpointState.ts +31 -0
  649. package/src/db/repositories/dataColumnSidecar.ts +49 -0
  650. package/src/db/repositories/dataColumnSidecarArchive.ts +56 -0
  651. package/src/db/repositories/depositDataRoot.ts +80 -0
  652. package/src/db/repositories/depositEvent.ts +32 -0
  653. package/src/db/repositories/eth1Data.ts +33 -0
  654. package/src/db/repositories/index.ts +20 -0
  655. package/src/db/repositories/lightclientBestUpdate.ts +41 -0
  656. package/src/db/repositories/lightclientCheckpointHeader.ts +32 -0
  657. package/src/db/repositories/lightclientSyncCommittee.ts +16 -0
  658. package/src/db/repositories/lightclientSyncCommitteeWitness.ts +77 -0
  659. package/src/db/repositories/proposerSlashing.ts +15 -0
  660. package/src/db/repositories/stateArchive.ts +69 -0
  661. package/src/db/repositories/stateArchiveIndex.ts +18 -0
  662. package/src/db/repositories/voluntaryExit.ts +15 -0
  663. package/src/db/single/index.ts +2 -0
  664. package/src/db/single/preGenesisState.ts +37 -0
  665. package/src/db/single/preGenesisStateLastProcessedBlock.ts +34 -0
  666. package/src/eth1/errors.ts +40 -0
  667. package/src/eth1/eth1DataCache.ts +26 -0
  668. package/src/eth1/eth1DepositDataTracker.ts +410 -0
  669. package/src/eth1/eth1DepositsCache.ts +141 -0
  670. package/src/eth1/eth1MergeBlockTracker.ts +328 -0
  671. package/src/eth1/index.ts +157 -0
  672. package/src/eth1/interface.ts +131 -0
  673. package/src/eth1/options.ts +28 -0
  674. package/src/eth1/provider/eth1Provider.ts +229 -0
  675. package/src/eth1/provider/jsonRpcHttpClient.ts +390 -0
  676. package/src/eth1/provider/jwt.ts +36 -0
  677. package/src/eth1/provider/utils.ts +136 -0
  678. package/src/eth1/stream.ts +75 -0
  679. package/src/eth1/utils/depositContract.ts +37 -0
  680. package/src/eth1/utils/deposits.ts +70 -0
  681. package/src/eth1/utils/eth1Data.ts +100 -0
  682. package/src/eth1/utils/eth1DepositEvent.ts +12 -0
  683. package/src/eth1/utils/eth1Vote.ts +142 -0
  684. package/src/eth1/utils/groupDepositEventsByBlock.ts +19 -0
  685. package/src/eth1/utils/optimizeNextBlockDiffForGenesis.ts +18 -0
  686. package/src/execution/builder/cache.ts +39 -0
  687. package/src/execution/builder/http.ts +229 -0
  688. package/src/execution/builder/index.ts +27 -0
  689. package/src/execution/builder/interface.ts +49 -0
  690. package/src/execution/builder/utils.ts +19 -0
  691. package/src/execution/engine/disabled.ts +35 -0
  692. package/src/execution/engine/http.ts +644 -0
  693. package/src/execution/engine/index.ts +63 -0
  694. package/src/execution/engine/interface.ts +199 -0
  695. package/src/execution/engine/mock.ts +493 -0
  696. package/src/execution/engine/payloadIdCache.ts +54 -0
  697. package/src/execution/engine/types.ts +640 -0
  698. package/src/execution/engine/utils.ts +136 -0
  699. package/src/execution/index.ts +4 -0
  700. package/src/index.ts +20 -0
  701. package/src/metrics/index.ts +4 -0
  702. package/src/metrics/metrics/beacon.ts +390 -0
  703. package/src/metrics/metrics/lodestar.ts +1870 -0
  704. package/src/metrics/metrics.ts +43 -0
  705. package/src/metrics/nodeJsMetrics.ts +19 -0
  706. package/src/metrics/options.ts +22 -0
  707. package/src/metrics/server/http.ts +114 -0
  708. package/src/metrics/server/index.ts +1 -0
  709. package/src/metrics/utils/avgMinMax.ts +87 -0
  710. package/src/metrics/utils/gauge.ts +22 -0
  711. package/src/metrics/utils/registryMetricCreator.ts +41 -0
  712. package/src/monitoring/clientStats.ts +297 -0
  713. package/src/monitoring/index.ts +2 -0
  714. package/src/monitoring/options.ts +19 -0
  715. package/src/monitoring/properties.ts +152 -0
  716. package/src/monitoring/service.ts +235 -0
  717. package/src/monitoring/system.ts +146 -0
  718. package/src/monitoring/types.ts +21 -0
  719. package/src/network/core/events.ts +59 -0
  720. package/src/network/core/index.ts +3 -0
  721. package/src/network/core/metrics.ts +304 -0
  722. package/src/network/core/networkCore.ts +599 -0
  723. package/src/network/core/networkCoreWorker.ts +176 -0
  724. package/src/network/core/networkCoreWorkerHandler.ts +284 -0
  725. package/src/network/core/types.ts +119 -0
  726. package/src/network/discv5/index.ts +132 -0
  727. package/src/network/discv5/types.ts +74 -0
  728. package/src/network/discv5/utils.ts +50 -0
  729. package/src/network/discv5/worker.ts +137 -0
  730. package/src/network/events.ts +51 -0
  731. package/src/network/forks.ts +94 -0
  732. package/src/network/gossip/constants.ts +15 -0
  733. package/src/network/gossip/encoding.ts +111 -0
  734. package/src/network/gossip/errors.ts +7 -0
  735. package/src/network/gossip/gossipsub.ts +384 -0
  736. package/src/network/gossip/index.ts +4 -0
  737. package/src/network/gossip/interface.ts +215 -0
  738. package/src/network/gossip/metrics.ts +71 -0
  739. package/src/network/gossip/scoringParameters.ts +333 -0
  740. package/src/network/gossip/topic.ts +332 -0
  741. package/src/network/index.ts +8 -0
  742. package/src/network/interface.ts +134 -0
  743. package/src/network/libp2p/error.ts +55 -0
  744. package/src/network/libp2p/index.ts +153 -0
  745. package/src/network/metadata.ts +162 -0
  746. package/src/network/network.ts +767 -0
  747. package/src/network/networkConfig.ts +12 -0
  748. package/src/network/options.ts +70 -0
  749. package/src/network/peers/client.ts +29 -0
  750. package/src/network/peers/datastore.ts +188 -0
  751. package/src/network/peers/discover.ts +647 -0
  752. package/src/network/peers/index.ts +2 -0
  753. package/src/network/peers/peerManager.ts +899 -0
  754. package/src/network/peers/peersData.ts +65 -0
  755. package/src/network/peers/score/constants.ts +34 -0
  756. package/src/network/peers/score/index.ts +4 -0
  757. package/src/network/peers/score/interface.ts +74 -0
  758. package/src/network/peers/score/score.ts +200 -0
  759. package/src/network/peers/score/store.ts +95 -0
  760. package/src/network/peers/score/utils.ts +37 -0
  761. package/src/network/peers/utils/assertPeerRelevance.ts +99 -0
  762. package/src/network/peers/utils/enrSubnetsDeserialize.ts +27 -0
  763. package/src/network/peers/utils/getConnectedPeerIds.ts +33 -0
  764. package/src/network/peers/utils/index.ts +4 -0
  765. package/src/network/peers/utils/prioritizePeers.ts +627 -0
  766. package/src/network/peers/utils/subnetMap.ts +88 -0
  767. package/src/network/processor/aggregatorTracker.ts +38 -0
  768. package/src/network/processor/extractSlotRootFns.ts +64 -0
  769. package/src/network/processor/gossipHandlers.ts +951 -0
  770. package/src/network/processor/gossipQueues/index.ts +114 -0
  771. package/src/network/processor/gossipQueues/indexed.ts +219 -0
  772. package/src/network/processor/gossipQueues/linear.ts +162 -0
  773. package/src/network/processor/gossipQueues/types.ts +57 -0
  774. package/src/network/processor/gossipValidatorFn.ts +142 -0
  775. package/src/network/processor/index.ts +496 -0
  776. package/src/network/processor/types.ts +27 -0
  777. package/src/network/reqresp/ReqRespBeaconNode.ts +373 -0
  778. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +101 -0
  779. package/src/network/reqresp/handlers/beaconBlocksByRoot.ts +49 -0
  780. package/src/network/reqresp/handlers/blobSidecarsByRange.ts +114 -0
  781. package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +62 -0
  782. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +144 -0
  783. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +88 -0
  784. package/src/network/reqresp/handlers/index.ts +78 -0
  785. package/src/network/reqresp/handlers/lightClientBootstrap.ts +31 -0
  786. package/src/network/reqresp/handlers/lightClientFinalityUpdate.ts +21 -0
  787. package/src/network/reqresp/handlers/lightClientOptimisticUpdate.ts +21 -0
  788. package/src/network/reqresp/handlers/lightClientUpdatesByRange.ts +39 -0
  789. package/src/network/reqresp/index.ts +2 -0
  790. package/src/network/reqresp/interface.ts +45 -0
  791. package/src/network/reqresp/protocols.ts +146 -0
  792. package/src/network/reqresp/rateLimit.ts +112 -0
  793. package/src/network/reqresp/score.ts +70 -0
  794. package/src/network/reqresp/types.ts +174 -0
  795. package/src/network/reqresp/utils/collect.ts +84 -0
  796. package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +57 -0
  797. package/src/network/reqresp/utils/dataColumnResponseValidation.ts +99 -0
  798. package/src/network/statusCache.ts +17 -0
  799. package/src/network/subnets/attnetsService.ts +385 -0
  800. package/src/network/subnets/index.ts +2 -0
  801. package/src/network/subnets/interface.ts +66 -0
  802. package/src/network/subnets/syncnetsService.ts +147 -0
  803. package/src/network/subnets/util.ts +63 -0
  804. package/src/network/util.ts +29 -0
  805. package/src/node/index.ts +2 -0
  806. package/src/node/nodejs.ts +349 -0
  807. package/src/node/notifier.ts +206 -0
  808. package/src/node/options.ts +51 -0
  809. package/src/node/utils/interop/deposits.ts +53 -0
  810. package/src/node/utils/interop/state.ts +59 -0
  811. package/src/node/utils/lightclient.ts +7 -0
  812. package/src/node/utils/state.ts +37 -0
  813. package/src/sync/backfill/backfill.ts +893 -0
  814. package/src/sync/backfill/errors.ts +23 -0
  815. package/src/sync/backfill/index.ts +1 -0
  816. package/src/sync/backfill/verify.ts +58 -0
  817. package/src/sync/constants.ts +71 -0
  818. package/src/sync/index.ts +2 -0
  819. package/src/sync/interface.ts +55 -0
  820. package/src/sync/options.ts +45 -0
  821. package/src/sync/range/batch.ts +455 -0
  822. package/src/sync/range/chain.ts +715 -0
  823. package/src/sync/range/range.ts +354 -0
  824. package/src/sync/range/utils/batches.ts +119 -0
  825. package/src/sync/range/utils/chainTarget.ts +62 -0
  826. package/src/sync/range/utils/hashBlocks.ts +27 -0
  827. package/src/sync/range/utils/index.ts +5 -0
  828. package/src/sync/range/utils/peerBalancer.ts +184 -0
  829. package/src/sync/range/utils/updateChains.ts +66 -0
  830. package/src/sync/sync.ts +290 -0
  831. package/src/sync/types.ts +57 -0
  832. package/src/sync/unknownBlock.ts +859 -0
  833. package/src/sync/utils/downloadByRange.ts +808 -0
  834. package/src/sync/utils/downloadByRoot.ts +560 -0
  835. package/src/sync/utils/pendingBlocksTree.ts +97 -0
  836. package/src/sync/utils/remoteSyncType.ts +144 -0
  837. package/src/util/address.ts +3 -0
  838. package/src/util/array.ts +311 -0
  839. package/src/util/asyncIterableToEvents.ts +164 -0
  840. package/src/util/binarySearch.ts +48 -0
  841. package/src/util/bitArray.ts +84 -0
  842. package/src/util/blobs.ts +210 -0
  843. package/src/util/bufferPool.ts +95 -0
  844. package/src/util/bytes.ts +11 -0
  845. package/src/util/chunkify.ts +27 -0
  846. package/src/util/clock.ts +204 -0
  847. package/src/util/dataColumns.ts +415 -0
  848. package/src/util/dependentRoot.ts +47 -0
  849. package/src/util/enum.ts +17 -0
  850. package/src/util/error.ts +56 -0
  851. package/src/util/eventLoop.ts +22 -0
  852. package/src/util/execution.ts +223 -0
  853. package/src/util/file.ts +52 -0
  854. package/src/util/forkChoice.ts +5 -0
  855. package/src/util/forkName.ts +20 -0
  856. package/src/util/graffiti.ts +39 -0
  857. package/src/util/hex.ts +9 -0
  858. package/src/util/index.ts +2 -0
  859. package/src/util/ip.ts +6 -0
  860. package/src/util/itTrigger.ts +49 -0
  861. package/src/util/kzg.ts +3 -0
  862. package/src/util/map.ts +77 -0
  863. package/src/util/metadata.ts +22 -0
  864. package/src/util/multifork.ts +69 -0
  865. package/src/util/numpy.ts +8 -0
  866. package/src/util/peerId.ts +16 -0
  867. package/src/util/profile.ts +54 -0
  868. package/src/util/promises.ts +14 -0
  869. package/src/util/queue/errors.ts +14 -0
  870. package/src/util/queue/fnQueue.ts +16 -0
  871. package/src/util/queue/index.ts +4 -0
  872. package/src/util/queue/itemQueue.ts +128 -0
  873. package/src/util/queue/options.ts +37 -0
  874. package/src/util/serializedCache.ts +20 -0
  875. package/src/util/set.ts +62 -0
  876. package/src/util/shuffle.ts +21 -0
  877. package/src/util/sortBy.ts +19 -0
  878. package/src/util/sszBytes.ts +481 -0
  879. package/src/util/strictEvents.ts +8 -0
  880. package/src/util/time.ts +13 -0
  881. package/src/util/timeSeries.ts +118 -0
  882. package/src/util/types.ts +31 -0
  883. package/src/util/workerEvents.ts +142 -0
  884. package/src/util/wrapError.ts +27 -0
@@ -0,0 +1,1365 @@
1
+ import path from "node:path";
2
+ import {PrivateKey} from "@libp2p/interface";
3
+ import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
4
+ import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
5
+ import {BeaconConfig} from "@lodestar/config";
6
+ import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice";
7
+ import {LoggerNode} from "@lodestar/logger/node";
8
+ import {EFFECTIVE_BALANCE_INCREMENT, GENESIS_SLOT, SLOTS_PER_EPOCH, isForkPostElectra} from "@lodestar/params";
9
+ import {
10
+ BeaconStateAllForks,
11
+ BeaconStateElectra,
12
+ CachedBeaconStateAllForks,
13
+ EffectiveBalanceIncrements,
14
+ EpochShuffling,
15
+ Index2PubkeyCache,
16
+ computeAnchorCheckpoint,
17
+ computeEndSlotAtEpoch,
18
+ computeEpochAtSlot,
19
+ computeStartSlotAtEpoch,
20
+ createCachedBeaconState,
21
+ getEffectiveBalanceIncrementsZeroInactive,
22
+ getEffectiveBalancesFromStateBytes,
23
+ isCachedBeaconState,
24
+ processSlots,
25
+ } from "@lodestar/state-transition";
26
+ import {
27
+ BeaconBlock,
28
+ BlindedBeaconBlock,
29
+ BlindedBeaconBlockBody,
30
+ Epoch,
31
+ Root,
32
+ RootHex,
33
+ SignedBeaconBlock,
34
+ Slot,
35
+ Status,
36
+ UintNum64,
37
+ ValidatorIndex,
38
+ Wei,
39
+ isBlindedBeaconBlock,
40
+ } from "@lodestar/types";
41
+ import {Logger, fromHex, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
42
+ import {ProcessShutdownCallback} from "@lodestar/validator";
43
+ import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
44
+ import {IBeaconDb} from "../db/index.js";
45
+ import {IEth1ForBlockProduction} from "../eth1/index.js";
46
+ import {BuilderStatus} from "../execution/builder/http.js";
47
+ import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
48
+ import {Metrics} from "../metrics/index.js";
49
+ import {computeNodeIdFromPrivateKey} from "../network/subnets/interface.js";
50
+ import {BufferPool} from "../util/bufferPool.js";
51
+ import {Clock, ClockEvent, IClock} from "../util/clock.js";
52
+ import {CustodyConfig, getValidatorsCustodyRequirement} from "../util/dataColumns.js";
53
+ import {ensureDir, writeIfNotExist} from "../util/file.js";
54
+ import {isOptimisticBlock} from "../util/forkChoice.js";
55
+ import {SerializedCache} from "../util/serializedCache.js";
56
+ import {ArchiveStore} from "./archiveStore/archiveStore.js";
57
+ import {CheckpointBalancesCache} from "./balancesCache.js";
58
+ import {BeaconProposerCache} from "./beaconProposerCache.js";
59
+ import {IBlockInput} from "./blocks/blockInput/index.js";
60
+ import {BlockProcessor, ImportBlockOpts} from "./blocks/index.js";
61
+ import {BlsMultiThreadWorkerPool, BlsSingleThreadVerifier, IBlsVerifier} from "./bls/index.js";
62
+ import {ColumnReconstructionTracker} from "./ColumnReconstructionTracker.js";
63
+ import {ChainEvent, ChainEventEmitter} from "./emitter.js";
64
+ import {ForkchoiceCaller, initializeForkChoice} from "./forkChoice/index.js";
65
+ import {GetBlobsTracker} from "./GetBlobsTracker.js";
66
+ import {CommonBlockBody, FindHeadFnName, IBeaconChain, ProposerPreparationData, StateGetOpts} from "./interface.js";
67
+ import {LightClientServer} from "./lightClient/index.js";
68
+ import {
69
+ AggregatedAttestationPool,
70
+ AttestationPool,
71
+ OpPool,
72
+ SyncCommitteeMessagePool,
73
+ SyncContributionAndProofPool,
74
+ } from "./opPools/index.js";
75
+ import {IChainOptions} from "./options.js";
76
+ import {PrepareNextSlotScheduler} from "./prepareNextSlot.js";
77
+ import {computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js";
78
+ import {AssembledBlockType, BlockType, ProduceResult} from "./produceBlock/index.js";
79
+ import {BlockAttributes, produceBlockBody, produceCommonBlockBody} from "./produceBlock/produceBlockBody.js";
80
+ import {QueuedStateRegenerator, RegenCaller} from "./regen/index.js";
81
+ import {ReprocessController} from "./reprocess.js";
82
+ import {AttestationsRewards, computeAttestationsRewards} from "./rewards/attestationsRewards.js";
83
+ import {BlockRewards, computeBlockRewards} from "./rewards/blockRewards.js";
84
+ import {SyncCommitteeRewards, computeSyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js";
85
+ import {
86
+ SeenAggregators,
87
+ SeenAttesters,
88
+ SeenBlockProposers,
89
+ SeenContributionAndProof,
90
+ SeenSyncCommitteeMessages,
91
+ } from "./seenCache/index.js";
92
+ import {SeenAggregatedAttestations} from "./seenCache/seenAggregateAndProof.js";
93
+ import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js";
94
+ import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js";
95
+ import {SeenBlockInput} from "./seenCache/seenGossipBlockInput.js";
96
+ import {ShufflingCache} from "./shufflingCache.js";
97
+ import {BlockStateCacheImpl} from "./stateCache/blockStateCacheImpl.js";
98
+ import {DbCPStateDatastore} from "./stateCache/datastore/db.js";
99
+ import {FileCPStateDatastore} from "./stateCache/datastore/file.js";
100
+ import {FIFOBlockStateCache} from "./stateCache/fifoBlockStateCache.js";
101
+ import {InMemoryCheckpointStateCache} from "./stateCache/inMemoryCheckpointsCache.js";
102
+ import {PersistentCheckpointStateCache} from "./stateCache/persistentCheckpointsCache.js";
103
+ import {ValidatorMonitor} from "./validatorMonitor.js";
104
+
105
+ /**
106
+ * The maximum number of cached produced results to keep in memory.
107
+ *
108
+ * Arbitrary constant. Blobs and payloads should be consumed immediately in the same slot
109
+ * they are produced. A value of 1 would probably be sufficient. However it's sensible to
110
+ * allow some margin if the node overloads.
111
+ */
112
+ const DEFAULT_MAX_CACHED_PRODUCED_RESULTS = 4;
113
+
114
+ export class BeaconChain implements IBeaconChain {
115
+ readonly genesisTime: UintNum64;
116
+ readonly genesisValidatorsRoot: Root;
117
+ readonly eth1: IEth1ForBlockProduction;
118
+ readonly executionEngine: IExecutionEngine;
119
+ readonly executionBuilder?: IExecutionBuilder;
120
+ // Expose config for convenience in modularized functions
121
+ readonly config: BeaconConfig;
122
+ readonly custodyConfig: CustodyConfig;
123
+ readonly logger: Logger;
124
+ readonly metrics: Metrics | null;
125
+ readonly validatorMonitor: ValidatorMonitor | null;
126
+ readonly bufferPool: BufferPool | null;
127
+
128
+ readonly anchorStateLatestBlockSlot: Slot;
129
+
130
+ readonly bls: IBlsVerifier;
131
+ readonly forkChoice: IForkChoice;
132
+ readonly clock: IClock;
133
+ readonly emitter: ChainEventEmitter;
134
+ readonly regen: QueuedStateRegenerator;
135
+ readonly lightClientServer?: LightClientServer;
136
+ readonly reprocessController: ReprocessController;
137
+ readonly archiveStore: ArchiveStore;
138
+
139
+ // Ops pool
140
+ readonly attestationPool: AttestationPool;
141
+ readonly aggregatedAttestationPool: AggregatedAttestationPool;
142
+ readonly syncCommitteeMessagePool: SyncCommitteeMessagePool;
143
+ readonly syncContributionAndProofPool;
144
+ readonly opPool = new OpPool();
145
+
146
+ // Gossip seen cache
147
+ readonly seenAttesters = new SeenAttesters();
148
+ readonly seenAggregators = new SeenAggregators();
149
+ readonly seenAggregatedAttestations: SeenAggregatedAttestations;
150
+ readonly seenBlockProposers = new SeenBlockProposers();
151
+ readonly seenSyncCommitteeMessages = new SeenSyncCommitteeMessages();
152
+ readonly seenContributionAndProof: SeenContributionAndProof;
153
+ readonly seenAttestationDatas: SeenAttestationDatas;
154
+ readonly seenBlockInputCache: SeenBlockInput;
155
+ // Seen cache for liveness checks
156
+ readonly seenBlockAttesters = new SeenBlockAttesters();
157
+
158
+ // Global state caches
159
+ readonly pubkey2index: PubkeyIndexMap;
160
+ readonly index2pubkey: Index2PubkeyCache;
161
+
162
+ readonly beaconProposerCache: BeaconProposerCache;
163
+ readonly checkpointBalancesCache: CheckpointBalancesCache;
164
+ readonly shufflingCache: ShufflingCache;
165
+
166
+ /**
167
+ * Cache produced results (ExecutionPayload, DA Data) from the local execution so that we can send
168
+ * and get signed/published blinded versions which beacon node can
169
+ * assemble into full blocks before publishing to the network.
170
+ */
171
+ readonly blockProductionCache = new Map<RootHex, ProduceResult>();
172
+
173
+ readonly blacklistedBlocks: Map<RootHex, Slot | null>;
174
+
175
+ readonly serializedCache: SerializedCache;
176
+
177
+ readonly getBlobsTracker: GetBlobsTracker;
178
+ readonly columnReconstructionTracker: ColumnReconstructionTracker;
179
+
180
+ readonly opts: IChainOptions;
181
+
182
+ protected readonly blockProcessor: BlockProcessor;
183
+ protected readonly db: IBeaconDb;
184
+ private abortController = new AbortController();
185
+ private processShutdownCallback: ProcessShutdownCallback;
186
+ private _earliestAvailableSlot: Slot;
187
+
188
+ get earliestAvailableSlot(): Slot {
189
+ return this._earliestAvailableSlot;
190
+ }
191
+
192
+ set earliestAvailableSlot(slot: Slot) {
193
+ if (this._earliestAvailableSlot !== slot) {
194
+ this._earliestAvailableSlot = slot;
195
+ this.emitter.emit(ChainEvent.updateStatus);
196
+ }
197
+ }
198
+
199
+ constructor(
200
+ opts: IChainOptions,
201
+ {
202
+ privateKey,
203
+ config,
204
+ db,
205
+ dbName,
206
+ dataDir,
207
+ logger,
208
+ processShutdownCallback,
209
+ clock,
210
+ metrics,
211
+ validatorMonitor,
212
+ anchorState,
213
+ eth1,
214
+ executionEngine,
215
+ executionBuilder,
216
+ }: {
217
+ privateKey: PrivateKey;
218
+ config: BeaconConfig;
219
+ db: IBeaconDb;
220
+ dbName: string;
221
+ dataDir: string;
222
+ logger: Logger;
223
+ processShutdownCallback: ProcessShutdownCallback;
224
+ /** Used for testing to supply fake clock */
225
+ clock?: IClock;
226
+ metrics: Metrics | null;
227
+ validatorMonitor: ValidatorMonitor | null;
228
+ anchorState: BeaconStateAllForks;
229
+ eth1: IEth1ForBlockProduction;
230
+ executionEngine: IExecutionEngine;
231
+ executionBuilder?: IExecutionBuilder;
232
+ }
233
+ ) {
234
+ this.opts = opts;
235
+ this.config = config;
236
+ this.db = db;
237
+ this.logger = logger;
238
+ this.processShutdownCallback = processShutdownCallback;
239
+ this.metrics = metrics;
240
+ this.validatorMonitor = validatorMonitor;
241
+ this.genesisTime = anchorState.genesisTime;
242
+ this.anchorStateLatestBlockSlot = anchorState.latestBlockHeader.slot;
243
+ this.genesisValidatorsRoot = anchorState.genesisValidatorsRoot;
244
+ this.eth1 = eth1;
245
+ this.executionEngine = executionEngine;
246
+ this.executionBuilder = executionBuilder;
247
+ const signal = this.abortController.signal;
248
+ const emitter = new ChainEventEmitter();
249
+ // by default, verify signatures on both main threads and worker threads
250
+ const bls = opts.blsVerifyAllMainThread
251
+ ? new BlsSingleThreadVerifier({metrics})
252
+ : new BlsMultiThreadWorkerPool(opts, {logger, metrics});
253
+
254
+ if (!clock) clock = new Clock({config, genesisTime: this.genesisTime, signal});
255
+
256
+ this.blacklistedBlocks = new Map((opts.blacklistedBlocks ?? []).map((hex) => [hex, null]));
257
+ const preAggregateCutOffTime = (2 / 3) * this.config.SECONDS_PER_SLOT;
258
+ this.attestationPool = new AttestationPool(
259
+ config,
260
+ clock,
261
+ preAggregateCutOffTime,
262
+ this.opts?.preaggregateSlotDistance,
263
+ metrics
264
+ );
265
+ this.aggregatedAttestationPool = new AggregatedAttestationPool(this.config, metrics);
266
+ this.syncCommitteeMessagePool = new SyncCommitteeMessagePool(
267
+ clock,
268
+ preAggregateCutOffTime,
269
+ this.opts?.preaggregateSlotDistance
270
+ );
271
+ this.syncContributionAndProofPool = new SyncContributionAndProofPool(clock, metrics, logger);
272
+
273
+ this.seenAggregatedAttestations = new SeenAggregatedAttestations(metrics);
274
+ this.seenContributionAndProof = new SeenContributionAndProof(metrics);
275
+ this.seenAttestationDatas = new SeenAttestationDatas(metrics, this.opts?.attDataCacheSlotDistance);
276
+
277
+ const nodeId = computeNodeIdFromPrivateKey(privateKey);
278
+ const initialCustodyGroupCount =
279
+ opts.initialCustodyGroupCount ?? (opts.supernode ? config.NUMBER_OF_CUSTODY_GROUPS : config.CUSTODY_REQUIREMENT);
280
+ this.metrics?.peerDas.targetCustodyGroupCount.set(initialCustodyGroupCount);
281
+ this.custodyConfig = new CustodyConfig({
282
+ nodeId,
283
+ config,
284
+ initialCustodyGroupCount,
285
+ });
286
+
287
+ this.beaconProposerCache = new BeaconProposerCache(opts);
288
+ this.checkpointBalancesCache = new CheckpointBalancesCache();
289
+ this.seenBlockInputCache = new SeenBlockInput({
290
+ config,
291
+ custodyConfig: this.custodyConfig,
292
+ clock,
293
+ chainEvents: emitter,
294
+ signal,
295
+ metrics,
296
+ logger,
297
+ });
298
+
299
+ // Restore state caches
300
+ // anchorState may already by a CachedBeaconState. If so, don't create the cache again, since deserializing all
301
+ // pubkeys takes ~30 seconds for 350k keys (mainnet 2022Q2).
302
+ // When the BeaconStateCache is created in eth1 genesis builder it may be incorrect. Until we can ensure that
303
+ // it's safe to re-use _ANY_ BeaconStateCache, this option is disabled by default and only used in tests.
304
+ const cachedState =
305
+ isCachedBeaconState(anchorState) && opts.skipCreateStateCacheIfAvailable
306
+ ? anchorState
307
+ : createCachedBeaconState(anchorState, {
308
+ config,
309
+ pubkey2index: new PubkeyIndexMap(),
310
+ index2pubkey: [],
311
+ });
312
+ this._earliestAvailableSlot = cachedState.slot;
313
+
314
+ this.shufflingCache = cachedState.epochCtx.shufflingCache = new ShufflingCache(metrics, logger, this.opts, [
315
+ {
316
+ shuffling: cachedState.epochCtx.previousShuffling,
317
+ decisionRoot: cachedState.epochCtx.previousDecisionRoot,
318
+ },
319
+ {
320
+ shuffling: cachedState.epochCtx.currentShuffling,
321
+ decisionRoot: cachedState.epochCtx.currentDecisionRoot,
322
+ },
323
+ {
324
+ shuffling: cachedState.epochCtx.nextShuffling,
325
+ decisionRoot: cachedState.epochCtx.nextDecisionRoot,
326
+ },
327
+ ]);
328
+
329
+ // Persist single global instance of state caches
330
+ this.pubkey2index = cachedState.epochCtx.pubkey2index;
331
+ this.index2pubkey = cachedState.epochCtx.index2pubkey;
332
+
333
+ const fileDataStore = opts.nHistoricalStatesFileDataStore ?? true;
334
+ const blockStateCache = this.opts.nHistoricalStates
335
+ ? new FIFOBlockStateCache(this.opts, {metrics})
336
+ : new BlockStateCacheImpl({metrics});
337
+ this.bufferPool = this.opts.nHistoricalStates
338
+ ? new BufferPool(anchorState.type.tree_serializedSize(anchorState.node), metrics)
339
+ : null;
340
+ const checkpointStateCache = this.opts.nHistoricalStates
341
+ ? new PersistentCheckpointStateCache(
342
+ {
343
+ metrics,
344
+ logger,
345
+ clock,
346
+ blockStateCache,
347
+ bufferPool: this.bufferPool,
348
+ datastore: fileDataStore
349
+ ? // debug option if we want to investigate any issues with the DB
350
+ new FileCPStateDatastore(dataDir)
351
+ : // production option
352
+ new DbCPStateDatastore(this.db),
353
+ },
354
+ this.opts
355
+ )
356
+ : new InMemoryCheckpointStateCache({metrics});
357
+ const {checkpoint} = computeAnchorCheckpoint(config, anchorState);
358
+ blockStateCache.add(cachedState);
359
+ blockStateCache.setHeadState(cachedState);
360
+ checkpointStateCache.add(checkpoint, cachedState);
361
+
362
+ const forkChoice = initializeForkChoice(
363
+ config,
364
+ emitter,
365
+ clock.currentSlot,
366
+ cachedState,
367
+ opts,
368
+ this.justifiedBalancesGetter.bind(this),
369
+ metrics,
370
+ logger
371
+ );
372
+ const regen = new QueuedStateRegenerator({
373
+ config,
374
+ forkChoice,
375
+ blockStateCache,
376
+ checkpointStateCache,
377
+ db,
378
+ metrics,
379
+ validatorMonitor,
380
+ logger,
381
+ emitter,
382
+ signal,
383
+ });
384
+
385
+ if (!opts.disableLightClientServer) {
386
+ this.lightClientServer = new LightClientServer(opts, {config, db, metrics, emitter, logger});
387
+ }
388
+
389
+ this.reprocessController = new ReprocessController(this.metrics);
390
+
391
+ this.blockProcessor = new BlockProcessor(this, metrics, opts, signal);
392
+
393
+ this.forkChoice = forkChoice;
394
+ this.clock = clock;
395
+ this.regen = regen;
396
+ this.bls = bls;
397
+ this.emitter = emitter;
398
+
399
+ this.serializedCache = new SerializedCache();
400
+
401
+ this.getBlobsTracker = new GetBlobsTracker({
402
+ logger,
403
+ executionEngine: this.executionEngine,
404
+ emitter,
405
+ metrics,
406
+ config,
407
+ });
408
+ this.columnReconstructionTracker = new ColumnReconstructionTracker({
409
+ logger,
410
+ emitter,
411
+ metrics,
412
+ config,
413
+ });
414
+
415
+ this.archiveStore = new ArchiveStore(
416
+ {db, chain: this, logger: logger as LoggerNode, metrics},
417
+ {...opts, dbName, anchorState: {finalizedCheckpoint: anchorState.finalizedCheckpoint}},
418
+ signal
419
+ );
420
+
421
+ // Stop polling eth1 data if anchor state is in Electra AND deposit_requests_start_index is reached
422
+ const anchorStateFork = this.config.getForkName(anchorState.slot);
423
+ if (isForkPostElectra(anchorStateFork)) {
424
+ const {eth1DepositIndex, depositRequestsStartIndex} = anchorState as BeaconStateElectra;
425
+ if (eth1DepositIndex === Number(depositRequestsStartIndex)) {
426
+ this.eth1.stopPollingEth1Data();
427
+ }
428
+ }
429
+
430
+ // always run PrepareNextSlotScheduler except for fork_choice spec tests
431
+ if (!opts?.disablePrepareNextSlot) {
432
+ new PrepareNextSlotScheduler(this, this.config, metrics, this.logger, signal);
433
+ }
434
+
435
+ if (metrics) {
436
+ metrics.clockSlot.addCollect(() => this.onScrapeMetrics(metrics));
437
+ }
438
+
439
+ // Event handlers. emitter is created internally and dropped on close(). Not need to .removeListener()
440
+ clock.addListener(ClockEvent.slot, this.onClockSlot.bind(this));
441
+ clock.addListener(ClockEvent.epoch, this.onClockEpoch.bind(this));
442
+ emitter.addListener(ChainEvent.forkChoiceFinalized, this.onForkChoiceFinalized.bind(this));
443
+ emitter.addListener(ChainEvent.forkChoiceJustified, this.onForkChoiceJustified.bind(this));
444
+ }
445
+
446
+ async init(): Promise<void> {
447
+ await this.archiveStore.init();
448
+ await this.loadFromDisk();
449
+ }
450
+
451
+ async close(): Promise<void> {
452
+ await this.archiveStore.close();
453
+ await this.bls.close();
454
+ this.abortController.abort();
455
+ }
456
+
457
+ seenBlock(blockRoot: RootHex): boolean {
458
+ return this.seenBlockInputCache.has(blockRoot) || this.forkChoice.hasBlockHex(blockRoot);
459
+ }
460
+
461
+ regenCanAcceptWork(): boolean {
462
+ return this.regen.canAcceptWork();
463
+ }
464
+
465
+ blsThreadPoolCanAcceptWork(): boolean {
466
+ return this.bls.canAcceptWork();
467
+ }
468
+
469
+ validatorSeenAtEpoch(index: ValidatorIndex, epoch: Epoch): boolean {
470
+ // Caller must check that epoch is not older that current epoch - 1
471
+ // else the caches for that epoch may already be pruned.
472
+
473
+ return (
474
+ // Dedicated cache for liveness checks, registers attesters seen through blocks.
475
+ // Note: this check should be cheaper + overlap with counting participants of aggregates from gossip.
476
+ this.seenBlockAttesters.isKnown(epoch, index) ||
477
+ //
478
+ // Re-use gossip caches. Populated on validation of gossip + API messages
479
+ // seenAttesters = single signer of unaggregated attestations
480
+ this.seenAttesters.isKnown(epoch, index) ||
481
+ // seenAggregators = single aggregator index, not participants of the aggregate
482
+ this.seenAggregators.isKnown(epoch, index) ||
483
+ // seenBlockProposers = single block proposer
484
+ this.seenBlockProposers.seenAtEpoch(epoch, index)
485
+ );
486
+ }
487
+
488
+ /** Populate in-memory caches with persisted data. Call at least once on startup */
489
+ async loadFromDisk(): Promise<void> {
490
+ await this.regen.init();
491
+ await this.opPool.fromPersisted(this.db);
492
+ }
493
+
494
+ /** Persist in-memory data to the DB. Call at least once before stopping the process */
495
+ async persistToDisk(): Promise<void> {
496
+ await this.archiveStore.persistToDisk();
497
+ await this.opPool.toPersisted(this.db);
498
+ }
499
+
500
+ getHeadState(): CachedBeaconStateAllForks {
501
+ // head state should always exist
502
+ const head = this.forkChoice.getHead();
503
+ const headState = this.regen.getClosestHeadState(head);
504
+ if (!headState) {
505
+ throw Error(`headState does not exist for head root=${head.blockRoot} slot=${head.slot}`);
506
+ }
507
+ return headState;
508
+ }
509
+
510
+ async getHeadStateAtCurrentEpoch(regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
511
+ return this.getHeadStateAtEpoch(this.clock.currentEpoch, regenCaller);
512
+ }
513
+
514
+ async getHeadStateAtEpoch(epoch: Epoch, regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
515
+ // using getHeadState() means we'll use checkpointStateCache if it's available
516
+ const headState = this.getHeadState();
517
+ // head state is in the same epoch, or we pulled up head state already from past epoch
518
+ if (epoch <= computeEpochAtSlot(headState.slot)) {
519
+ // should go to this most of the time
520
+ return headState;
521
+ }
522
+ // only use regen queue if necessary, it'll cache in checkpointStateCache if regen gets through epoch transition
523
+ const head = this.forkChoice.getHead();
524
+ const startSlot = computeStartSlotAtEpoch(epoch);
525
+ return this.regen.getBlockSlotState(head.blockRoot, startSlot, {dontTransferCache: true}, regenCaller);
526
+ }
527
+
528
+ async getStateBySlot(
529
+ slot: Slot,
530
+ opts?: StateGetOpts
531
+ ): Promise<{state: BeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null> {
532
+ const finalizedBlock = this.forkChoice.getFinalizedBlock();
533
+
534
+ if (slot < finalizedBlock.slot) {
535
+ // request for finalized state not supported in this API
536
+ // fall back to caller to look in db or getHistoricalStateBySlot
537
+ return null;
538
+ }
539
+
540
+ if (opts?.allowRegen) {
541
+ // Find closest canonical block to slot, then trigger regen
542
+ const block = this.forkChoice.getCanonicalBlockClosestLteSlot(slot) ?? finalizedBlock;
543
+ const state = await this.regen.getBlockSlotState(
544
+ block.blockRoot,
545
+ slot,
546
+ {dontTransferCache: true},
547
+ RegenCaller.restApi
548
+ );
549
+ return {
550
+ state,
551
+ executionOptimistic: isOptimisticBlock(block),
552
+ finalized: slot === finalizedBlock.slot && finalizedBlock.slot !== GENESIS_SLOT,
553
+ };
554
+ }
555
+
556
+ // Just check if state is already in the cache. If it's not dialed to the correct slot,
557
+ // do not bother in advancing the state. restApiCanTriggerRegen == false means do no work
558
+ const block = this.forkChoice.getCanonicalBlockAtSlot(slot);
559
+ if (!block) {
560
+ return null;
561
+ }
562
+
563
+ const state = this.regen.getStateSync(block.stateRoot);
564
+ return (
565
+ state && {
566
+ state,
567
+ executionOptimistic: isOptimisticBlock(block),
568
+ finalized: slot === finalizedBlock.slot && finalizedBlock.slot !== GENESIS_SLOT,
569
+ }
570
+ );
571
+ }
572
+
573
+ async getHistoricalStateBySlot(
574
+ slot: number
575
+ ): Promise<{state: Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
576
+ if (!this.opts.serveHistoricalState) {
577
+ throw Error("Historical state regen is not enabled, set --serveHistoricalState to fetch this data");
578
+ }
579
+
580
+ return this.archiveStore.getHistoricalStateBySlot(slot);
581
+ }
582
+
583
+ async getStateByStateRoot(
584
+ stateRoot: RootHex,
585
+ opts?: StateGetOpts
586
+ ): Promise<{state: BeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null> {
587
+ if (opts?.allowRegen) {
588
+ const state = await this.regen.getState(stateRoot, RegenCaller.restApi);
589
+ const block = this.forkChoice.getBlock(state.latestBlockHeader.hashTreeRoot());
590
+ const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
591
+ return {
592
+ state,
593
+ executionOptimistic: block != null && isOptimisticBlock(block),
594
+ finalized: state.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
595
+ };
596
+ }
597
+
598
+ // TODO: This can only fulfill requests for a very narrow set of roots.
599
+ // - very recent states that happen to be in the cache
600
+ // - 1 every 100s of states that are persisted in the archive state
601
+
602
+ // TODO: This is very inneficient for debug requests of serialized content, since it deserializes to serialize again
603
+ const cachedStateCtx = this.regen.getStateSync(stateRoot);
604
+ if (cachedStateCtx) {
605
+ const block = this.forkChoice.getBlock(cachedStateCtx.latestBlockHeader.hashTreeRoot());
606
+ const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
607
+ return {
608
+ state: cachedStateCtx,
609
+ executionOptimistic: block != null && isOptimisticBlock(block),
610
+ finalized: cachedStateCtx.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
611
+ };
612
+ }
613
+
614
+ const data = await this.db.stateArchive.getByRoot(fromHex(stateRoot));
615
+ return data && {state: data, executionOptimistic: false, finalized: true};
616
+ }
617
+
618
+ getStateByCheckpoint(
619
+ checkpoint: CheckpointWithHex
620
+ ): {state: BeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null {
621
+ // finalized or justified checkpoint states maynot be available with PersistentCheckpointStateCache, use getCheckpointStateOrBytes() api to get Uint8Array
622
+ const cachedStateCtx = this.regen.getCheckpointStateSync(checkpoint);
623
+ if (cachedStateCtx) {
624
+ const block = this.forkChoice.getBlock(cachedStateCtx.latestBlockHeader.hashTreeRoot());
625
+ const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
626
+ return {
627
+ state: cachedStateCtx,
628
+ executionOptimistic: block != null && isOptimisticBlock(block),
629
+ finalized: cachedStateCtx.epochCtx.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
630
+ };
631
+ }
632
+
633
+ return null;
634
+ }
635
+
636
+ async getStateOrBytesByCheckpoint(
637
+ checkpoint: CheckpointWithHex
638
+ ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
639
+ const cachedStateCtx = await this.regen.getCheckpointStateOrBytes(checkpoint);
640
+ if (cachedStateCtx) {
641
+ const block = this.forkChoice.getBlock(checkpoint.root);
642
+ const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
643
+ return {
644
+ state: cachedStateCtx,
645
+ executionOptimistic: block != null && isOptimisticBlock(block),
646
+ finalized: checkpoint.epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH,
647
+ };
648
+ }
649
+
650
+ return null;
651
+ }
652
+
653
+ async getCanonicalBlockAtSlot(
654
+ slot: Slot
655
+ ): Promise<{block: SignedBeaconBlock; executionOptimistic: boolean; finalized: boolean} | null> {
656
+ const finalizedBlock = this.forkChoice.getFinalizedBlock();
657
+ if (slot > finalizedBlock.slot) {
658
+ // Unfinalized slot, attempt to find in fork-choice
659
+ const block = this.forkChoice.getCanonicalBlockAtSlot(slot);
660
+ if (block) {
661
+ const data = await this.db.block.get(fromHex(block.blockRoot));
662
+ if (data) {
663
+ return {block: data, executionOptimistic: isOptimisticBlock(block), finalized: false};
664
+ }
665
+ }
666
+ // A non-finalized slot expected to be found in the hot db, could be archived during
667
+ // this function runtime, so if not found in the hot db, fallback to the cold db
668
+ // TODO: Add a lock to the archiver to have determinstic behaviour on where are blocks
669
+ }
670
+
671
+ const data = await this.db.blockArchive.get(slot);
672
+ return data && {block: data, executionOptimistic: false, finalized: true};
673
+ }
674
+
675
+ async getBlockByRoot(
676
+ root: string
677
+ ): Promise<{block: SignedBeaconBlock; executionOptimistic: boolean; finalized: boolean} | null> {
678
+ const block = this.forkChoice.getBlockHex(root);
679
+ if (block) {
680
+ const data = await this.db.block.get(fromHex(root));
681
+ if (data) {
682
+ return {block: data, executionOptimistic: isOptimisticBlock(block), finalized: false};
683
+ }
684
+ // If block is not found in hot db, try cold db since there could be an archive cycle happening
685
+ // TODO: Add a lock to the archiver to have deterministic behavior on where are blocks
686
+ }
687
+
688
+ const data = await this.db.blockArchive.getByRoot(fromHex(root));
689
+ return data && {block: data, executionOptimistic: false, finalized: true};
690
+ }
691
+
692
+ async produceCommonBlockBody(blockAttributes: BlockAttributes): Promise<CommonBlockBody> {
693
+ const {slot, parentBlockRoot} = blockAttributes;
694
+ const state = await this.regen.getBlockSlotState(
695
+ toRootHex(parentBlockRoot),
696
+ slot,
697
+ {dontTransferCache: true},
698
+ RegenCaller.produceBlock
699
+ );
700
+
701
+ // TODO: To avoid breaking changes for metric define this attribute
702
+ const blockType = BlockType.Full;
703
+
704
+ return produceCommonBlockBody.call(this, blockType, state, blockAttributes);
705
+ }
706
+
707
+ produceBlock(blockAttributes: BlockAttributes & {commonBlockBodyPromise: Promise<CommonBlockBody>}): Promise<{
708
+ block: BeaconBlock;
709
+ executionPayloadValue: Wei;
710
+ consensusBlockValue: Wei;
711
+ shouldOverrideBuilder?: boolean;
712
+ }> {
713
+ return this.produceBlockWrapper<BlockType.Full>(BlockType.Full, blockAttributes);
714
+ }
715
+
716
+ produceBlindedBlock(blockAttributes: BlockAttributes & {commonBlockBodyPromise: Promise<CommonBlockBody>}): Promise<{
717
+ block: BlindedBeaconBlock;
718
+ executionPayloadValue: Wei;
719
+ consensusBlockValue: Wei;
720
+ }> {
721
+ return this.produceBlockWrapper<BlockType.Blinded>(BlockType.Blinded, blockAttributes);
722
+ }
723
+
724
+ async produceBlockWrapper<T extends BlockType>(
725
+ blockType: T,
726
+ {
727
+ randaoReveal,
728
+ graffiti,
729
+ slot,
730
+ feeRecipient,
731
+ commonBlockBodyPromise,
732
+ parentBlockRoot,
733
+ parentSlot,
734
+ }: BlockAttributes & {commonBlockBodyPromise: Promise<CommonBlockBody>}
735
+ ): Promise<{
736
+ block: AssembledBlockType<T>;
737
+ executionPayloadValue: Wei;
738
+ consensusBlockValue: Wei;
739
+ shouldOverrideBuilder?: boolean;
740
+ }> {
741
+ const state = await this.regen.getBlockSlotState(
742
+ toRootHex(parentBlockRoot),
743
+ slot,
744
+ {dontTransferCache: true},
745
+ RegenCaller.produceBlock
746
+ );
747
+ const proposerIndex = state.epochCtx.getBeaconProposer(slot);
748
+ const proposerPubKey = state.epochCtx.index2pubkey[proposerIndex].toBytes();
749
+
750
+ const {body, produceResult, executionPayloadValue, shouldOverrideBuilder} = await produceBlockBody.call(
751
+ this,
752
+ blockType,
753
+ state,
754
+ {
755
+ randaoReveal,
756
+ graffiti,
757
+ slot,
758
+ feeRecipient,
759
+ parentSlot,
760
+ parentBlockRoot,
761
+ proposerIndex,
762
+ proposerPubKey,
763
+ commonBlockBodyPromise,
764
+ }
765
+ );
766
+
767
+ // The hashtree root computed here for debug log will get cached and hence won't introduce additional delays
768
+ const bodyRoot =
769
+ produceResult.type === BlockType.Full
770
+ ? this.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(body)
771
+ : this.config
772
+ .getPostBellatrixForkTypes(slot)
773
+ .BlindedBeaconBlockBody.hashTreeRoot(body as BlindedBeaconBlockBody);
774
+ this.logger.debug("Computing block post state from the produced body", {
775
+ slot,
776
+ bodyRoot: toRootHex(bodyRoot),
777
+ blockType,
778
+ });
779
+
780
+ const block = {
781
+ slot,
782
+ proposerIndex,
783
+ parentRoot: parentBlockRoot,
784
+ stateRoot: ZERO_HASH,
785
+ body,
786
+ } as AssembledBlockType<T>;
787
+
788
+ const {newStateRoot, proposerReward} = computeNewStateRoot(this.metrics, state, block);
789
+ block.stateRoot = newStateRoot;
790
+ const blockRoot =
791
+ produceResult.type === BlockType.Full
792
+ ? this.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block)
793
+ : this.config.getPostBellatrixForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block as BlindedBeaconBlock);
794
+ const blockRootHex = toRootHex(blockRoot);
795
+
796
+ // Track the produced block for consensus broadcast validations, later validation, etc.
797
+ this.blockProductionCache.set(blockRootHex, produceResult);
798
+ this.metrics?.blockProductionCacheSize.set(this.blockProductionCache.size);
799
+
800
+ return {block, executionPayloadValue, consensusBlockValue: gweiToWei(proposerReward), shouldOverrideBuilder};
801
+ }
802
+
803
+ async processBlock(block: IBlockInput, opts?: ImportBlockOpts): Promise<void> {
804
+ return this.blockProcessor.processBlocksJob([block], opts);
805
+ }
806
+
807
+ async processChainSegment(blocks: IBlockInput[], opts?: ImportBlockOpts): Promise<void> {
808
+ return this.blockProcessor.processBlocksJob(blocks, opts);
809
+ }
810
+
811
+ getStatus(): Status {
812
+ const head = this.forkChoice.getHead();
813
+ const finalizedCheckpoint = this.forkChoice.getFinalizedCheckpoint();
814
+ const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
815
+ return {
816
+ // fork_digest: The node's ForkDigest (compute_fork_digest(current_fork_version, genesis_validators_root)) where
817
+ // - current_fork_version is the fork version at the node's current epoch defined by the wall-clock time (not necessarily the epoch to which the node is sync)
818
+ // - genesis_validators_root is the static Root found in state.genesis_validators_root
819
+ // - epoch of fork boundary is used to get blob parameters of current Blob Parameter Only (BPO) fork
820
+ forkDigest: this.config.forkBoundary2ForkDigest(boundary),
821
+ // finalized_root: state.finalized_checkpoint.root for the state corresponding to the head block (Note this defaults to Root(b'\x00' * 32) for the genesis finalized checkpoint).
822
+ finalizedRoot: finalizedCheckpoint.epoch === GENESIS_EPOCH ? ZERO_HASH : finalizedCheckpoint.root,
823
+ finalizedEpoch: finalizedCheckpoint.epoch,
824
+ // TODO: PERFORMANCE: Memoize to prevent re-computing every time
825
+ headRoot: fromHex(head.blockRoot),
826
+ headSlot: head.slot,
827
+ earliestAvailableSlot: this._earliestAvailableSlot,
828
+ };
829
+ }
830
+
831
+ recomputeForkChoiceHead(caller: ForkchoiceCaller): ProtoBlock {
832
+ this.metrics?.forkChoice.requests.inc();
833
+ const timer = this.metrics?.forkChoice.findHead.startTimer({caller});
834
+
835
+ try {
836
+ return this.forkChoice.updateAndGetHead({mode: UpdateHeadOpt.GetCanonicalHead}).head;
837
+ } catch (e) {
838
+ this.metrics?.forkChoice.errors.inc({entrypoint: UpdateHeadOpt.GetCanonicalHead});
839
+ throw e;
840
+ } finally {
841
+ timer?.();
842
+ }
843
+ }
844
+
845
+ predictProposerHead(slot: Slot): ProtoBlock {
846
+ this.metrics?.forkChoice.requests.inc();
847
+ const timer = this.metrics?.forkChoice.findHead.startTimer({caller: FindHeadFnName.predictProposerHead});
848
+ const secFromSlot = this.clock.secFromSlot(slot);
849
+
850
+ try {
851
+ return this.forkChoice.updateAndGetHead({mode: UpdateHeadOpt.GetPredictedProposerHead, secFromSlot, slot}).head;
852
+ } catch (e) {
853
+ this.metrics?.forkChoice.errors.inc({entrypoint: UpdateHeadOpt.GetPredictedProposerHead});
854
+ throw e;
855
+ } finally {
856
+ timer?.();
857
+ }
858
+ }
859
+
860
+ getProposerHead(slot: Slot): ProtoBlock {
861
+ this.metrics?.forkChoice.requests.inc();
862
+ const timer = this.metrics?.forkChoice.findHead.startTimer({caller: FindHeadFnName.getProposerHead});
863
+ const secFromSlot = this.clock.secFromSlot(slot);
864
+
865
+ try {
866
+ const {head, isHeadTimely, notReorgedReason} = this.forkChoice.updateAndGetHead({
867
+ mode: UpdateHeadOpt.GetProposerHead,
868
+ secFromSlot,
869
+ slot,
870
+ });
871
+
872
+ if (isHeadTimely && notReorgedReason !== undefined) {
873
+ this.metrics?.forkChoice.notReorgedReason.inc({reason: notReorgedReason});
874
+ }
875
+ return head;
876
+ } catch (e) {
877
+ this.metrics?.forkChoice.errors.inc({entrypoint: UpdateHeadOpt.GetProposerHead});
878
+ throw e;
879
+ } finally {
880
+ timer?.();
881
+ }
882
+ }
883
+
884
+ /**
885
+ * Returns Promise that resolves either on block found or once 1 slot passes.
886
+ * Used to handle unknown block root for both unaggregated and aggregated attestations.
887
+ * @returns true if blockFound
888
+ */
889
+ waitForBlock(slot: Slot, root: RootHex): Promise<boolean> {
890
+ return this.reprocessController.waitForBlockOfAttestation(slot, root);
891
+ }
892
+
893
+ persistBlock(data: BeaconBlock | BlindedBeaconBlock, suffix?: string): void {
894
+ const slot = data.slot;
895
+ if (isBlindedBeaconBlock(data)) {
896
+ const sszType = this.config.getPostBellatrixForkTypes(slot).BlindedBeaconBlock;
897
+ void this.persistSszObject("BlindedBeaconBlock", sszType.serialize(data), sszType.hashTreeRoot(data), suffix);
898
+ } else {
899
+ const sszType = this.config.getForkTypes(slot).BeaconBlock;
900
+ void this.persistSszObject("BeaconBlock", sszType.serialize(data), sszType.hashTreeRoot(data), suffix);
901
+ }
902
+ }
903
+
904
+ /**
905
+ * Invalid state root error is critical and it causes the node to stale most of the time so we want to always
906
+ * persist preState, postState and block for further investigation.
907
+ */
908
+ async persistInvalidStateRoot(
909
+ preState: CachedBeaconStateAllForks,
910
+ postState: CachedBeaconStateAllForks,
911
+ block: SignedBeaconBlock
912
+ ): Promise<void> {
913
+ const blockSlot = block.message.slot;
914
+ const blockType = this.config.getForkTypes(blockSlot).SignedBeaconBlock;
915
+ const postStateRoot = postState.hashTreeRoot();
916
+ const logStr = `slot_${blockSlot}_invalid_state_root_${toRootHex(postStateRoot)}`;
917
+ await Promise.all([
918
+ this.persistSszObject(
919
+ `SignedBeaconBlock_slot_${blockSlot}`,
920
+ blockType.serialize(block),
921
+ blockType.hashTreeRoot(block),
922
+ `${logStr}_block`
923
+ ),
924
+ this.persistSszObject(
925
+ `preState_slot_${preState.slot}_${preState.type.typeName}`,
926
+ preState.serialize(),
927
+ preState.hashTreeRoot(),
928
+ `${logStr}_pre_state`
929
+ ),
930
+ this.persistSszObject(
931
+ `postState_slot_${postState.slot}_${postState.type.typeName}`,
932
+ postState.serialize(),
933
+ postState.hashTreeRoot(),
934
+ `${logStr}_post_state`
935
+ ),
936
+ ]);
937
+ }
938
+
939
+ persistInvalidSszValue<T>(type: Type<T>, sszObject: T, suffix?: string): void {
940
+ if (this.opts.persistInvalidSszObjects) {
941
+ void this.persistSszObject(type.typeName, type.serialize(sszObject), type.hashTreeRoot(sszObject), suffix);
942
+ }
943
+ }
944
+
945
+ persistInvalidSszBytes(typeName: string, sszBytes: Uint8Array, suffix?: string): void {
946
+ if (this.opts.persistInvalidSszObjects) {
947
+ void this.persistSszObject(typeName, sszBytes, sszBytes, suffix);
948
+ }
949
+ }
950
+
951
+ persistInvalidSszView(view: TreeView<CompositeTypeAny>, suffix?: string): void {
952
+ if (this.opts.persistInvalidSszObjects) {
953
+ void this.persistSszObject(view.type.typeName, view.serialize(), view.hashTreeRoot(), suffix);
954
+ }
955
+ }
956
+
957
+ /**
958
+ * Regenerate state for attestation verification, this does not happen with default chain option of maxSkipSlots = 32 .
959
+ * However, need to handle just in case. Lodestar doesn't support multiple regen state requests for attestation verification
960
+ * at the same time, bounded inside "ShufflingCache.insertPromise()" function.
961
+ * Leave this function in chain instead of attestatation verification code to make sure we're aware of its performance impact.
962
+ */
963
+ async regenStateForAttestationVerification(
964
+ attEpoch: Epoch,
965
+ shufflingDependentRoot: RootHex,
966
+ attHeadBlock: ProtoBlock,
967
+ regenCaller: RegenCaller
968
+ ): Promise<EpochShuffling> {
969
+ // this is to prevent multiple calls to get shuffling for the same epoch and dependent root
970
+ // any subsequent calls of the same epoch and dependent root will wait for this promise to resolve
971
+ this.shufflingCache.insertPromise(attEpoch, shufflingDependentRoot);
972
+ const blockEpoch = computeEpochAtSlot(attHeadBlock.slot);
973
+
974
+ let state: CachedBeaconStateAllForks;
975
+ if (blockEpoch < attEpoch - 1) {
976
+ // thanks to one epoch look ahead, we don't need to dial up to attEpoch
977
+ const targetSlot = computeStartSlotAtEpoch(attEpoch - 1);
978
+ this.metrics?.gossipAttestation.useHeadBlockStateDialedToTargetEpoch.inc({caller: regenCaller});
979
+ state = await this.regen.getBlockSlotState(
980
+ attHeadBlock.blockRoot,
981
+ targetSlot,
982
+ {dontTransferCache: true},
983
+ regenCaller
984
+ );
985
+ } else if (blockEpoch > attEpoch) {
986
+ // should not happen, handled inside attestation verification code
987
+ throw Error(`Block epoch ${blockEpoch} is after attestation epoch ${attEpoch}`);
988
+ } else {
989
+ // should use either current or next shuffling of head state
990
+ // it's not likely to hit this since these shufflings are cached already
991
+ // so handle just in case
992
+ this.metrics?.gossipAttestation.useHeadBlockState.inc({caller: regenCaller});
993
+ state = await this.regen.getState(attHeadBlock.stateRoot, regenCaller);
994
+ }
995
+
996
+ // should always be the current epoch of the active context so no need to await a result from the ShufflingCache
997
+ return state.epochCtx.getShufflingAtEpoch(attEpoch);
998
+ }
999
+
1000
+ /**
1001
+ * `ForkChoice.onBlock` must never throw for a block that is valid with respect to the network
1002
+ * `justifiedBalancesGetter()` must never throw and it should always return a state.
1003
+ * @param blockState state that declares justified checkpoint `checkpoint`
1004
+ */
1005
+ private justifiedBalancesGetter(
1006
+ checkpoint: CheckpointWithHex,
1007
+ blockState: CachedBeaconStateAllForks
1008
+ ): EffectiveBalanceIncrements {
1009
+ this.metrics?.balancesCache.requests.inc();
1010
+
1011
+ const effectiveBalances = this.checkpointBalancesCache.get(checkpoint);
1012
+ if (effectiveBalances) {
1013
+ return effectiveBalances;
1014
+ }
1015
+ // not expected, need metrics
1016
+ this.metrics?.balancesCache.misses.inc();
1017
+ this.logger.debug("checkpointBalances cache miss", {
1018
+ epoch: checkpoint.epoch,
1019
+ root: checkpoint.rootHex,
1020
+ });
1021
+
1022
+ const {state, stateId, shouldWarn} = this.closestJustifiedBalancesStateToCheckpoint(checkpoint, blockState);
1023
+ this.metrics?.balancesCache.closestStateResult.inc({stateId});
1024
+ if (shouldWarn) {
1025
+ this.logger.warn("currentJustifiedCheckpoint state not avail, using closest state", {
1026
+ checkpointEpoch: checkpoint.epoch,
1027
+ checkpointRoot: checkpoint.rootHex,
1028
+ stateId,
1029
+ stateSlot: state.slot,
1030
+ stateRoot: toRootHex(state.hashTreeRoot()),
1031
+ });
1032
+ }
1033
+
1034
+ return getEffectiveBalanceIncrementsZeroInactive(state);
1035
+ }
1036
+
1037
+ /**
1038
+ * - Assumptions + invariant this function is based on:
1039
+ * - Our cache can only persist X states at once to prevent OOM
1040
+ * - Some old states (including to-be justified checkpoint) may / must be dropped from the cache
1041
+ * - Thus, there is no guarantee that the state for a justified checkpoint will be available in the cache
1042
+ * @param blockState state that declares justified checkpoint `checkpoint`
1043
+ */
1044
+ private closestJustifiedBalancesStateToCheckpoint(
1045
+ checkpoint: CheckpointWithHex,
1046
+ blockState: CachedBeaconStateAllForks
1047
+ ): {state: CachedBeaconStateAllForks; stateId: string; shouldWarn: boolean} {
1048
+ const state = this.regen.getCheckpointStateSync(checkpoint);
1049
+ if (state) {
1050
+ return {state, stateId: "checkpoint_state", shouldWarn: false};
1051
+ }
1052
+
1053
+ // Check if blockState is in the same epoch, not need to iterate the fork-choice then
1054
+ if (computeEpochAtSlot(blockState.slot) === checkpoint.epoch) {
1055
+ return {state: blockState, stateId: "block_state_same_epoch", shouldWarn: true};
1056
+ }
1057
+
1058
+ // Find a state in the same branch of checkpoint at same epoch. Balances should exactly the same
1059
+ for (const descendantBlock of this.forkChoice.forwardIterateDescendants(checkpoint.rootHex)) {
1060
+ if (computeEpochAtSlot(descendantBlock.slot) === checkpoint.epoch) {
1061
+ const descendantBlockState = this.regen.getStateSync(descendantBlock.stateRoot);
1062
+ if (descendantBlockState) {
1063
+ return {state: descendantBlockState, stateId: "descendant_state_same_epoch", shouldWarn: true};
1064
+ }
1065
+ }
1066
+ }
1067
+
1068
+ // Check if blockState is in the next epoch, not need to iterate the fork-choice then
1069
+ if (computeEpochAtSlot(blockState.slot) === checkpoint.epoch + 1) {
1070
+ return {state: blockState, stateId: "block_state_next_epoch", shouldWarn: true};
1071
+ }
1072
+
1073
+ // Find a state in the same branch of checkpoint at a latter epoch. Balances are not the same, but should be close
1074
+ // Note: must call .forwardIterateDescendants() again since nodes are not sorted
1075
+ for (const descendantBlock of this.forkChoice.forwardIterateDescendants(checkpoint.rootHex)) {
1076
+ if (computeEpochAtSlot(descendantBlock.slot) > checkpoint.epoch) {
1077
+ const descendantBlockState = this.regen.getStateSync(descendantBlock.stateRoot);
1078
+ if (descendantBlockState) {
1079
+ return {state: blockState, stateId: "descendant_state_latter_epoch", shouldWarn: true};
1080
+ }
1081
+ }
1082
+ }
1083
+
1084
+ // If there's no state available in the same branch of checkpoint use blockState regardless of its epoch
1085
+ return {state: blockState, stateId: "block_state_any_epoch", shouldWarn: true};
1086
+ }
1087
+
1088
+ private async persistSszObject(prefix: string, bytes: Uint8Array, root: Uint8Array, logStr?: string): Promise<void> {
1089
+ const now = new Date();
1090
+ // yyyy-MM-dd
1091
+ const dateStr = now.toISOString().split("T")[0];
1092
+
1093
+ // by default store to lodestar_archive of current dir
1094
+ const dirpath = path.join(this.opts.persistInvalidSszObjectsDir ?? "invalid_ssz_objects", dateStr);
1095
+ const filepath = path.join(dirpath, `${prefix}_${toRootHex(root)}.ssz`);
1096
+
1097
+ await ensureDir(dirpath);
1098
+
1099
+ // as of Feb 17 2022 there are a lot of duplicate files stored with different date suffixes
1100
+ // remove date suffixes in file name, and check duplicate to avoid redundant persistence
1101
+ await writeIfNotExist(filepath, bytes);
1102
+
1103
+ this.logger.debug("Persisted invalid ssz object", {id: logStr, filepath});
1104
+ }
1105
+
1106
+ private onScrapeMetrics(metrics: Metrics): void {
1107
+ // aggregatedAttestationPool tracks metrics on its own
1108
+ metrics.opPool.attestationPool.size.set(this.attestationPool.getAttestationCount());
1109
+ metrics.opPool.attesterSlashingPoolSize.set(this.opPool.attesterSlashingsSize);
1110
+ metrics.opPool.proposerSlashingPoolSize.set(this.opPool.proposerSlashingsSize);
1111
+ metrics.opPool.voluntaryExitPoolSize.set(this.opPool.voluntaryExitsSize);
1112
+ metrics.opPool.syncCommitteeMessagePoolSize.set(this.syncCommitteeMessagePool.size);
1113
+ // syncContributionAndProofPool tracks metrics on its own
1114
+ metrics.opPool.blsToExecutionChangePoolSize.set(this.opPool.blsToExecutionChangeSize);
1115
+ metrics.chain.blacklistedBlocks.set(this.blacklistedBlocks.size);
1116
+
1117
+ const headState = this.getHeadState();
1118
+ const fork = this.config.getForkName(headState.slot);
1119
+
1120
+ if (isForkPostElectra(fork)) {
1121
+ const headStateElectra = headState as BeaconStateElectra;
1122
+ metrics.pendingDeposits.set(headStateElectra.pendingDeposits.length);
1123
+ metrics.pendingPartialWithdrawals.set(headStateElectra.pendingPartialWithdrawals.length);
1124
+ metrics.pendingConsolidations.set(headStateElectra.pendingConsolidations.length);
1125
+ }
1126
+ }
1127
+
1128
+ private onClockSlot(slot: Slot): void {
1129
+ this.logger.verbose("Clock slot", {slot});
1130
+
1131
+ // CRITICAL UPDATE
1132
+ if (this.forkChoice.irrecoverableError) {
1133
+ this.processShutdownCallback(this.forkChoice.irrecoverableError);
1134
+ }
1135
+
1136
+ this.forkChoice.updateTime(slot);
1137
+ this.metrics?.clockSlot.set(slot);
1138
+
1139
+ this.attestationPool.prune(slot);
1140
+ this.aggregatedAttestationPool.prune(slot);
1141
+ this.syncCommitteeMessagePool.prune(slot);
1142
+ this.seenSyncCommitteeMessages.prune(slot);
1143
+ this.seenAttestationDatas.onSlot(slot);
1144
+ this.reprocessController.onSlot(slot);
1145
+
1146
+ // Prune old cached block production artifacts, those are only useful on their slot
1147
+ pruneSetToMax(this.blockProductionCache, this.opts.maxCachedProducedRoots ?? DEFAULT_MAX_CACHED_PRODUCED_RESULTS);
1148
+ this.metrics?.blockProductionCacheSize.set(this.blockProductionCache.size);
1149
+
1150
+ const metrics = this.metrics;
1151
+ if (metrics && (slot + 1) % SLOTS_PER_EPOCH === 0) {
1152
+ // On the last slot of the epoch
1153
+ sleep((1000 * this.config.SECONDS_PER_SLOT) / 2)
1154
+ .then(() => this.validatorMonitor?.onceEveryEndOfEpoch(this.getHeadState()))
1155
+ .catch((e) => {
1156
+ if (!isErrorAborted(e)) this.logger.error("Error on validator monitor onceEveryEndOfEpoch", {slot}, e);
1157
+ });
1158
+ }
1159
+ }
1160
+
1161
+ private onClockEpoch(epoch: Epoch): void {
1162
+ this.metrics?.clockEpoch.set(epoch);
1163
+
1164
+ this.seenAttesters.prune(epoch);
1165
+ this.seenAggregators.prune(epoch);
1166
+ this.seenAggregatedAttestations.prune(epoch);
1167
+ this.seenBlockAttesters.prune(epoch);
1168
+ this.beaconProposerCache.prune(epoch);
1169
+
1170
+ // Poll for merge block in the background to speed-up block production. Only if:
1171
+ // - after BELLATRIX_FORK_EPOCH
1172
+ // - Beacon node synced
1173
+ // - head state not isMergeTransitionComplete
1174
+ if (this.config.BELLATRIX_FORK_EPOCH - epoch < 1) {
1175
+ const head = this.forkChoice.getHead();
1176
+ if (epoch - computeEpochAtSlot(head.slot) < 5 && head.executionStatus === ExecutionStatus.PreMerge) {
1177
+ this.eth1.startPollingMergeBlock();
1178
+ }
1179
+ }
1180
+ }
1181
+
1182
+ protected onNewHead(head: ProtoBlock): void {
1183
+ this.syncContributionAndProofPool.prune(head.slot);
1184
+ this.seenContributionAndProof.prune(head.slot);
1185
+ }
1186
+
1187
+ private onForkChoiceJustified(this: BeaconChain, cp: CheckpointWithHex): void {
1188
+ this.logger.verbose("Fork choice justified", {epoch: cp.epoch, root: cp.rootHex});
1189
+ }
1190
+
1191
+ private async onForkChoiceFinalized(this: BeaconChain, cp: CheckpointWithHex): Promise<void> {
1192
+ this.logger.verbose("Fork choice finalized", {epoch: cp.epoch, root: cp.rootHex});
1193
+ this.seenBlockProposers.prune(computeStartSlotAtEpoch(cp.epoch));
1194
+
1195
+ // Update validator custody to account for effective balance changes
1196
+ await this.updateValidatorsCustodyRequirement(cp);
1197
+
1198
+ // TODO: Improve using regen here
1199
+ const {blockRoot, stateRoot, slot} = this.forkChoice.getHead();
1200
+ const headState = this.regen.getStateSync(stateRoot);
1201
+ const headBlock = await this.db.block.get(fromHex(blockRoot));
1202
+ if (headBlock == null) {
1203
+ throw Error(`Head block ${slot} ${headBlock} is not available in database`);
1204
+ }
1205
+
1206
+ if (headState) {
1207
+ this.opPool.pruneAll(headBlock, headState);
1208
+ }
1209
+
1210
+ if (headState === null) {
1211
+ this.logger.verbose("Head state is null");
1212
+ }
1213
+ }
1214
+
1215
+ async updateBeaconProposerData(epoch: Epoch, proposers: ProposerPreparationData[]): Promise<void> {
1216
+ const previousValidatorCount = this.beaconProposerCache.getValidatorIndices().length;
1217
+
1218
+ for (const proposer of proposers) {
1219
+ this.beaconProposerCache.add(epoch, proposer);
1220
+ }
1221
+
1222
+ const newValidatorCount = this.beaconProposerCache.getValidatorIndices().length;
1223
+
1224
+ // Only update validator custody if we discovered new validators
1225
+ if (newValidatorCount > previousValidatorCount) {
1226
+ const finalizedCheckpoint = this.forkChoice.getFinalizedCheckpoint();
1227
+ await this.updateValidatorsCustodyRequirement(finalizedCheckpoint);
1228
+ }
1229
+ }
1230
+
1231
+ private async updateValidatorsCustodyRequirement(finalizedCheckpoint: CheckpointWithHex): Promise<void> {
1232
+ if (this.opts.supernode) {
1233
+ // Disable dynamic custody updates for supernodes since they must maintain custody
1234
+ // of all custody groups regardless of validator effective balances
1235
+ return;
1236
+ }
1237
+
1238
+ // Validators attached to the node
1239
+ const validatorIndices = this.beaconProposerCache.getValidatorIndices();
1240
+
1241
+ // Update custody requirement based on finalized state
1242
+ let effectiveBalances: number[];
1243
+ const effectiveBalanceIncrements = this.checkpointBalancesCache.get(finalizedCheckpoint);
1244
+ if (effectiveBalanceIncrements) {
1245
+ effectiveBalances = validatorIndices.map(
1246
+ (index) => (effectiveBalanceIncrements[index] ?? 0) * EFFECTIVE_BALANCE_INCREMENT
1247
+ );
1248
+ } else {
1249
+ // If there's no cached effective balances, get the state from disk and parse them out
1250
+ this.logger.debug("No cached finalized effective balances to update target custody group count", {
1251
+ finalizedEpoch: finalizedCheckpoint.epoch,
1252
+ finalizedRoot: finalizedCheckpoint.rootHex,
1253
+ });
1254
+
1255
+ const stateOrBytes = (await this.getStateOrBytesByCheckpoint(finalizedCheckpoint))?.state;
1256
+ if (!stateOrBytes) {
1257
+ // If even the state is not available, we cannot update the custody group count
1258
+ this.logger.debug("No finalized state or bytes available to update target custody group count", {
1259
+ finalizedEpoch: finalizedCheckpoint.epoch,
1260
+ finalizedRoot: finalizedCheckpoint.rootHex,
1261
+ });
1262
+ return;
1263
+ }
1264
+
1265
+ if (stateOrBytes instanceof Uint8Array) {
1266
+ effectiveBalances = getEffectiveBalancesFromStateBytes(this.config, stateOrBytes, validatorIndices);
1267
+ } else {
1268
+ effectiveBalances = validatorIndices.map((index) => stateOrBytes.validators.get(index).effectiveBalance ?? 0);
1269
+ }
1270
+ }
1271
+
1272
+ const targetCustodyGroupCount = getValidatorsCustodyRequirement(this.config, effectiveBalances);
1273
+ // Only update if target is increased
1274
+ if (targetCustodyGroupCount > this.custodyConfig.targetCustodyGroupCount) {
1275
+ this.custodyConfig.updateTargetCustodyGroupCount(targetCustodyGroupCount);
1276
+ this.metrics?.peerDas.targetCustodyGroupCount.set(targetCustodyGroupCount);
1277
+ this.logger.verbose("Updated target custody group count", {
1278
+ finalizedEpoch: finalizedCheckpoint.epoch,
1279
+ validatorCount: validatorIndices.length,
1280
+ targetCustodyGroupCount,
1281
+ });
1282
+ this.emitter.emit(ChainEvent.updateTargetCustodyGroupCount, targetCustodyGroupCount);
1283
+ }
1284
+ }
1285
+
1286
+ updateBuilderStatus(clockSlot: Slot): void {
1287
+ const executionBuilder = this.executionBuilder;
1288
+ if (executionBuilder) {
1289
+ const {faultInspectionWindow, allowedFaults} = executionBuilder;
1290
+ const slotsPresent = this.forkChoice.getSlotsPresent(clockSlot - faultInspectionWindow);
1291
+ const previousStatus = executionBuilder.status;
1292
+ const shouldEnable = slotsPresent >= Math.min(faultInspectionWindow - allowedFaults, clockSlot);
1293
+
1294
+ executionBuilder.updateStatus(shouldEnable ? BuilderStatus.enabled : BuilderStatus.circuitBreaker);
1295
+ // The status changed we should log
1296
+ const status = executionBuilder.status;
1297
+ const builderLog = {
1298
+ status,
1299
+ slotsPresent,
1300
+ faultInspectionWindow,
1301
+ allowedFaults,
1302
+ };
1303
+ if (status !== previousStatus) {
1304
+ this.logger.info("External builder status updated", builderLog);
1305
+ } else {
1306
+ this.logger.verbose("External builder status", builderLog);
1307
+ }
1308
+ }
1309
+ }
1310
+
1311
+ async getBlockRewards(block: BeaconBlock | BlindedBeaconBlock): Promise<BlockRewards> {
1312
+ let preState = this.regen.getPreStateSync(block);
1313
+
1314
+ if (preState === null) {
1315
+ throw Error(`Pre-state is unavailable given block's parent root ${toRootHex(block.parentRoot)}`);
1316
+ }
1317
+
1318
+ preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1319
+
1320
+ const postState = this.regen.getStateSync(toRootHex(block.stateRoot)) ?? undefined;
1321
+
1322
+ return computeBlockRewards(block, preState.clone(), postState?.clone());
1323
+ }
1324
+
1325
+ async getAttestationsRewards(
1326
+ epoch: Epoch,
1327
+ validatorIds?: (ValidatorIndex | string)[]
1328
+ ): Promise<{rewards: AttestationsRewards; executionOptimistic: boolean; finalized: boolean}> {
1329
+ // We use end slot of (epoch + 1) to ensure we have seen all attestations. On-time or late. Any late attestation beyond this slot is not considered
1330
+ const slot = computeEndSlotAtEpoch(epoch + 1);
1331
+ const stateResult = await this.getStateBySlot(slot, {allowRegen: false}); // No regen if state not in cache
1332
+
1333
+ if (stateResult === null) {
1334
+ throw Error(`State is unavailable for slot ${slot}`);
1335
+ }
1336
+
1337
+ const {executionOptimistic, finalized} = stateResult;
1338
+ const stateRoot = toRootHex(stateResult.state.hashTreeRoot());
1339
+
1340
+ const cachedState = this.regen.getStateSync(stateRoot);
1341
+
1342
+ if (cachedState === null) {
1343
+ throw Error(`State is not in cache for slot ${slot}`);
1344
+ }
1345
+
1346
+ const rewards = await computeAttestationsRewards(epoch, cachedState, this.config, validatorIds);
1347
+
1348
+ return {rewards, executionOptimistic, finalized};
1349
+ }
1350
+
1351
+ async getSyncCommitteeRewards(
1352
+ block: BeaconBlock | BlindedBeaconBlock,
1353
+ validatorIds?: (ValidatorIndex | string)[]
1354
+ ): Promise<SyncCommitteeRewards> {
1355
+ let preState = this.regen.getPreStateSync(block);
1356
+
1357
+ if (preState === null) {
1358
+ throw Error(`Pre-state is unavailable given block's parent root ${toRootHex(block.parentRoot)}`);
1359
+ }
1360
+
1361
+ preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1362
+
1363
+ return computeSyncCommitteeRewards(block, preState.clone(), validatorIds);
1364
+ }
1365
+ }