@lodestar/beacon-node 1.52.0-dev.2252a15492 → 1.52.0-dev.263ed9ded6

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 (338) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +22 -8
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +4 -2
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.js +2 -1
  9. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  10. package/lib/api/impl/debug/index.d.ts.map +1 -1
  11. package/lib/api/impl/debug/index.js +6 -2
  12. package/lib/api/impl/debug/index.js.map +1 -1
  13. package/lib/api/impl/validator/index.d.ts.map +1 -1
  14. package/lib/api/impl/validator/index.js +87 -48
  15. package/lib/api/impl/validator/index.js.map +1 -1
  16. package/lib/chain/ColumnReconstructionTracker.d.ts +4 -0
  17. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  18. package/lib/chain/ColumnReconstructionTracker.js +4 -0
  19. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  20. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  21. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
  22. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  23. package/lib/chain/archiveStore/utils/archiveBlocks.js +1 -1
  24. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  25. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  26. package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
  27. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  28. package/lib/chain/blocks/importExecutionPayload.d.ts +1 -1
  29. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  30. package/lib/chain/blocks/importExecutionPayload.js +9 -3
  31. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  32. package/lib/chain/blocks/index.d.ts.map +1 -1
  33. package/lib/chain/blocks/index.js +3 -17
  34. package/lib/chain/blocks/index.js.map +1 -1
  35. package/lib/chain/chain.d.ts +7 -6
  36. package/lib/chain/chain.d.ts.map +1 -1
  37. package/lib/chain/chain.js +80 -41
  38. package/lib/chain/chain.js.map +1 -1
  39. package/lib/chain/errors/attestationError.d.ts +15 -1
  40. package/lib/chain/errors/attestationError.d.ts.map +1 -1
  41. package/lib/chain/errors/attestationError.js +8 -0
  42. package/lib/chain/errors/attestationError.js.map +1 -1
  43. package/lib/chain/errors/executionPayloadBid.d.ts +14 -3
  44. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  45. package/lib/chain/errors/executionPayloadBid.js +3 -1
  46. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  47. package/lib/chain/errors/executionPayloadEnvelope.d.ts +55 -0
  48. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  49. package/lib/chain/errors/executionPayloadEnvelope.js +8 -0
  50. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  51. package/lib/chain/interface.d.ts +1 -1
  52. package/lib/chain/interface.d.ts.map +1 -1
  53. package/lib/chain/lightClient/index.d.ts +13 -6
  54. package/lib/chain/lightClient/index.d.ts.map +1 -1
  55. package/lib/chain/lightClient/index.js +95 -115
  56. package/lib/chain/lightClient/index.js.map +1 -1
  57. package/lib/chain/opPools/opPool.js +6 -6
  58. package/lib/chain/opPools/opPool.js.map +1 -1
  59. package/lib/chain/prepareNextSlot.d.ts +45 -0
  60. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  61. package/lib/chain/prepareNextSlot.js +265 -69
  62. package/lib/chain/prepareNextSlot.js.map +1 -1
  63. package/lib/chain/produceBlock/produceBlockBody.d.ts +6 -2
  64. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  65. package/lib/chain/produceBlock/produceBlockBody.js +54 -64
  66. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  67. package/lib/chain/seenCache/seenAttesters.d.ts +1 -0
  68. package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
  69. package/lib/chain/seenCache/seenAttesters.js +1 -1
  70. package/lib/chain/seenCache/seenAttesters.js.map +1 -1
  71. package/lib/chain/seenCache/seenBlockAttesters.d.ts +8 -2
  72. package/lib/chain/seenCache/seenBlockAttesters.d.ts.map +1 -1
  73. package/lib/chain/seenCache/seenBlockAttesters.js +43 -6
  74. package/lib/chain/seenCache/seenBlockAttesters.js.map +1 -1
  75. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +13 -4
  76. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
  77. package/lib/chain/seenCache/seenExecutionPayloadBids.js +13 -12
  78. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
  79. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
  80. package/lib/chain/validation/aggregateAndProof.js +24 -7
  81. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  82. package/lib/chain/validation/attestation.d.ts.map +1 -1
  83. package/lib/chain/validation/attestation.js +32 -16
  84. package/lib/chain/validation/attestation.js.map +1 -1
  85. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  86. package/lib/chain/validation/attesterSlashing.js +4 -2
  87. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  88. package/lib/chain/validation/block.d.ts.map +1 -1
  89. package/lib/chain/validation/block.js +9 -1
  90. package/lib/chain/validation/block.js.map +1 -1
  91. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  92. package/lib/chain/validation/executionPayloadBid.js +58 -43
  93. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  94. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  95. package/lib/chain/validation/executionPayloadEnvelope.js +100 -9
  96. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  97. package/lib/chain/validation/payloadAttestationMessage.js +11 -2
  98. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  99. package/lib/chain/validation/proposerSlashing.js +4 -2
  100. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  101. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  102. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  103. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  104. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  105. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  106. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  107. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  108. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  109. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
  110. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  111. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  112. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  113. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  114. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  115. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +2 -2
  116. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  117. package/lib/chain/validation/syncCommittee.d.ts +1 -1
  118. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  119. package/lib/chain/validation/syncCommittee.js +5 -5
  120. package/lib/chain/validation/syncCommittee.js.map +1 -1
  121. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  122. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  123. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  124. package/lib/chain/validation/voluntaryExit.js +39 -6
  125. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  126. package/lib/chain/validatorMonitor.js +43 -43
  127. package/lib/chain/validatorMonitor.js.map +1 -1
  128. package/lib/execution/engine/blockHash.d.ts +12 -0
  129. package/lib/execution/engine/blockHash.d.ts.map +1 -0
  130. package/lib/execution/engine/blockHash.js +17 -0
  131. package/lib/execution/engine/blockHash.js.map +1 -0
  132. package/lib/execution/engine/http.d.ts +2 -2
  133. package/lib/execution/engine/http.d.ts.map +1 -1
  134. package/lib/execution/engine/http.js +13 -7
  135. package/lib/execution/engine/http.js.map +1 -1
  136. package/lib/execution/engine/interface.d.ts +16 -3
  137. package/lib/execution/engine/interface.d.ts.map +1 -1
  138. package/lib/execution/engine/interface.js +11 -0
  139. package/lib/execution/engine/interface.js.map +1 -1
  140. package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
  141. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
  142. package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
  143. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
  144. package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
  145. package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
  146. package/lib/execution/engine/jsonRpcTransport.js +4 -4
  147. package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
  148. package/lib/execution/engine/mock.d.ts.map +1 -1
  149. package/lib/execution/engine/mock.js +6 -6
  150. package/lib/execution/engine/mock.js.map +1 -1
  151. package/lib/execution/engine/payloadIdCache.d.ts +6 -1
  152. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
  153. package/lib/execution/engine/payloadIdCache.js +7 -2
  154. package/lib/execution/engine/payloadIdCache.js.map +1 -1
  155. package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
  156. package/lib/execution/engine/restHttpClient.js +9 -5
  157. package/lib/execution/engine/restHttpClient.js.map +1 -1
  158. package/lib/execution/engine/restTransport.d.ts +2 -2
  159. package/lib/execution/engine/restTransport.d.ts.map +1 -1
  160. package/lib/execution/engine/restTransport.js +4 -4
  161. package/lib/execution/engine/restTransport.js.map +1 -1
  162. package/lib/execution/engine/signal.d.ts +6 -0
  163. package/lib/execution/engine/signal.d.ts.map +1 -0
  164. package/lib/execution/engine/signal.js +24 -0
  165. package/lib/execution/engine/signal.js.map +1 -0
  166. package/lib/execution/engine/transport.d.ts +2 -2
  167. package/lib/execution/engine/transport.d.ts.map +1 -1
  168. package/lib/index.d.ts +1 -1
  169. package/lib/index.d.ts.map +1 -1
  170. package/lib/index.js +1 -1
  171. package/lib/index.js.map +1 -1
  172. package/lib/metrics/metrics/beacon.d.ts +5 -0
  173. package/lib/metrics/metrics/beacon.d.ts.map +1 -1
  174. package/lib/metrics/metrics/beacon.js +5 -0
  175. package/lib/metrics/metrics/beacon.js.map +1 -1
  176. package/lib/metrics/metrics/lodestar.d.ts +1 -0
  177. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  178. package/lib/metrics/metrics/lodestar.js +5 -0
  179. package/lib/metrics/metrics/lodestar.js.map +1 -1
  180. package/lib/network/core/events.d.ts +6 -2
  181. package/lib/network/core/events.d.ts.map +1 -1
  182. package/lib/network/core/events.js +9 -0
  183. package/lib/network/core/events.js.map +1 -1
  184. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  185. package/lib/network/core/networkCoreWorkerHandler.js +3 -2
  186. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  187. package/lib/network/gossip/gossipsub.d.ts +1 -0
  188. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  189. package/lib/network/gossip/gossipsub.js +5 -2
  190. package/lib/network/gossip/gossipsub.js.map +1 -1
  191. package/lib/network/gossip/topic.d.ts +1 -7
  192. package/lib/network/gossip/topic.d.ts.map +1 -1
  193. package/lib/network/gossip/topic.js +0 -13
  194. package/lib/network/gossip/topic.js.map +1 -1
  195. package/lib/network/network.d.ts.map +1 -1
  196. package/lib/network/network.js +12 -7
  197. package/lib/network/network.js.map +1 -1
  198. package/lib/network/peers/peerManager.d.ts.map +1 -1
  199. package/lib/network/peers/peerManager.js +22 -2
  200. package/lib/network/peers/peerManager.js.map +1 -1
  201. package/lib/network/peers/utils/prioritizePeers.d.ts +2 -0
  202. package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
  203. package/lib/network/peers/utils/prioritizePeers.js +11 -2
  204. package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
  205. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  206. package/lib/network/processor/gossipHandlers.js +19 -6
  207. package/lib/network/processor/gossipHandlers.js.map +1 -1
  208. package/lib/network/processor/index.d.ts.map +1 -1
  209. package/lib/network/processor/index.js +4 -2
  210. package/lib/network/processor/index.js.map +1 -1
  211. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -1
  212. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  213. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
  214. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  215. package/lib/sync/range/batch.d.ts +10 -0
  216. package/lib/sync/range/batch.d.ts.map +1 -1
  217. package/lib/sync/range/batch.js +29 -0
  218. package/lib/sync/range/batch.js.map +1 -1
  219. package/lib/sync/range/chain.d.ts +17 -2
  220. package/lib/sync/range/chain.d.ts.map +1 -1
  221. package/lib/sync/range/chain.js +60 -20
  222. package/lib/sync/range/chain.js.map +1 -1
  223. package/lib/sync/range/range.d.ts.map +1 -1
  224. package/lib/sync/range/range.js +44 -3
  225. package/lib/sync/range/range.js.map +1 -1
  226. package/lib/sync/range/utils/batches.d.ts +20 -4
  227. package/lib/sync/range/utils/batches.d.ts.map +1 -1
  228. package/lib/sync/range/utils/batches.js +31 -13
  229. package/lib/sync/range/utils/batches.js.map +1 -1
  230. package/lib/sync/range/utils/peerBalancer.d.ts +1 -1
  231. package/lib/sync/range/utils/peerBalancer.d.ts.map +1 -1
  232. package/lib/sync/range/utils/peerBalancer.js +5 -2
  233. package/lib/sync/range/utils/peerBalancer.js.map +1 -1
  234. package/lib/sync/types.d.ts +14 -1
  235. package/lib/sync/types.d.ts.map +1 -1
  236. package/lib/sync/types.js +2 -0
  237. package/lib/sync/types.js.map +1 -1
  238. package/lib/sync/unknownBlock.d.ts +28 -1
  239. package/lib/sync/unknownBlock.d.ts.map +1 -1
  240. package/lib/sync/unknownBlock.js +340 -27
  241. package/lib/sync/unknownBlock.js.map +1 -1
  242. package/lib/sync/utils/downloadByRange.d.ts +22 -1
  243. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  244. package/lib/sync/utils/downloadByRange.js +55 -25
  245. package/lib/sync/utils/downloadByRange.js.map +1 -1
  246. package/lib/sync/utils/downloadByRoot.d.ts +24 -2
  247. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  248. package/lib/sync/utils/downloadByRoot.js +48 -5
  249. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  250. package/lib/util/asyncIterableToEvents.d.ts +20 -3
  251. package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
  252. package/lib/util/asyncIterableToEvents.js +76 -20
  253. package/lib/util/asyncIterableToEvents.js.map +1 -1
  254. package/lib/util/dataColumns.d.ts +1 -1
  255. package/lib/util/dataColumns.d.ts.map +1 -1
  256. package/lib/util/dataColumns.js +4 -1
  257. package/lib/util/dataColumns.js.map +1 -1
  258. package/lib/util/eventLoop.d.ts +3 -3
  259. package/lib/util/eventLoop.d.ts.map +1 -1
  260. package/lib/util/eventLoop.js +3 -3
  261. package/lib/util/eventLoop.js.map +1 -1
  262. package/package.json +27 -27
  263. package/src/api/impl/beacon/blocks/index.ts +24 -8
  264. package/src/api/impl/beacon/pool/index.ts +10 -8
  265. package/src/api/impl/beacon/state/utils.ts +2 -1
  266. package/src/api/impl/debug/index.ts +6 -2
  267. package/src/api/impl/validator/index.ts +122 -66
  268. package/src/chain/ColumnReconstructionTracker.ts +5 -0
  269. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
  270. package/src/chain/archiveStore/utils/archiveBlocks.ts +1 -1
  271. package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
  272. package/src/chain/blocks/importExecutionPayload.ts +9 -2
  273. package/src/chain/blocks/index.ts +3 -31
  274. package/src/chain/chain.ts +112 -78
  275. package/src/chain/errors/attestationError.ts +11 -1
  276. package/src/chain/errors/executionPayloadBid.ts +15 -2
  277. package/src/chain/errors/executionPayloadEnvelope.ts +58 -0
  278. package/src/chain/interface.ts +1 -1
  279. package/src/chain/lightClient/index.ts +108 -142
  280. package/src/chain/opPools/opPool.ts +6 -6
  281. package/src/chain/prepareNextSlot.ts +347 -89
  282. package/src/chain/produceBlock/produceBlockBody.ts +69 -80
  283. package/src/chain/seenCache/seenAttesters.ts +1 -1
  284. package/src/chain/seenCache/seenBlockAttesters.ts +48 -6
  285. package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
  286. package/src/chain/validation/aggregateAndProof.ts +24 -9
  287. package/src/chain/validation/attestation.ts +31 -20
  288. package/src/chain/validation/attesterSlashing.ts +4 -2
  289. package/src/chain/validation/block.ts +9 -1
  290. package/src/chain/validation/executionPayloadBid.ts +75 -50
  291. package/src/chain/validation/executionPayloadEnvelope.ts +115 -8
  292. package/src/chain/validation/payloadAttestationMessage.ts +12 -2
  293. package/src/chain/validation/proposerSlashing.ts +4 -2
  294. package/src/chain/validation/signatureSets/contributionAndProof.ts +4 -6
  295. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -3
  296. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -3
  297. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -3
  298. package/src/chain/validation/syncCommittee.ts +3 -5
  299. package/src/chain/validation/syncCommitteeContributionAndProof.ts +3 -3
  300. package/src/chain/validation/voluntaryExit.ts +44 -6
  301. package/src/chain/validatorMonitor.ts +43 -43
  302. package/src/execution/engine/blockHash.ts +27 -0
  303. package/src/execution/engine/http.ts +18 -10
  304. package/src/execution/engine/interface.ts +18 -3
  305. package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
  306. package/src/execution/engine/jsonRpcTransport.ts +8 -4
  307. package/src/execution/engine/mock.ts +13 -8
  308. package/src/execution/engine/payloadIdCache.ts +12 -4
  309. package/src/execution/engine/restHttpClient.ts +17 -11
  310. package/src/execution/engine/restTransport.ts +5 -4
  311. package/src/execution/engine/signal.ts +28 -0
  312. package/src/execution/engine/transport.ts +3 -2
  313. package/src/index.ts +6 -1
  314. package/src/metrics/metrics/beacon.ts +9 -0
  315. package/src/metrics/metrics/lodestar.ts +5 -0
  316. package/src/network/core/events.ts +12 -0
  317. package/src/network/core/networkCoreWorkerHandler.ts +6 -2
  318. package/src/network/gossip/gossipsub.ts +6 -2
  319. package/src/network/gossip/topic.ts +1 -14
  320. package/src/network/network.ts +12 -8
  321. package/src/network/peers/peerManager.ts +26 -2
  322. package/src/network/peers/utils/prioritizePeers.ts +14 -1
  323. package/src/network/processor/gossipHandlers.ts +25 -13
  324. package/src/network/processor/index.ts +7 -2
  325. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +1 -1
  326. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
  327. package/src/sync/range/batch.ts +33 -0
  328. package/src/sync/range/chain.ts +72 -17
  329. package/src/sync/range/range.ts +57 -3
  330. package/src/sync/range/utils/batches.ts +38 -13
  331. package/src/sync/range/utils/peerBalancer.ts +4 -1
  332. package/src/sync/types.ts +13 -0
  333. package/src/sync/unknownBlock.ts +389 -29
  334. package/src/sync/utils/downloadByRange.ts +89 -29
  335. package/src/sync/utils/downloadByRoot.ts +75 -7
  336. package/src/util/asyncIterableToEvents.ts +100 -21
  337. package/src/util/dataColumns.ts +4 -1
  338. package/src/util/eventLoop.ts +3 -3
@@ -121,7 +121,12 @@ export function cacheByRangeResponses({
121
121
  parentPayload,
122
122
  custodyConfig,
123
123
  seenTimestampSec,
124
- }: CacheByRangeResponsesProps): {blocks: IBlockInput[]; payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null} {
124
+ }: CacheByRangeResponsesProps): {
125
+ blocks: IBlockInput[];
126
+ payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null;
127
+ /** First fulu column whose header signature differs from its cached block, no later column is added */
128
+ signatureMismatch: {blockInput: IBlockInput; columnSidecar: fulu.DataColumnSidecar} | null;
129
+ } {
125
130
  const source = BlockInputSource.byRange;
126
131
  const updatedBatchBlocks = new Map<Slot, IBlockInput>(batchBlocks.map((block) => [block.slot, block]));
127
132
 
@@ -217,6 +222,7 @@ export function cacheByRangeResponses({
217
222
  }
218
223
  }
219
224
 
225
+ let signatureMismatch: {blockInput: IBlockInput; columnSidecar: fulu.DataColumnSidecar} | null = null;
220
226
  for (const {blockRoot, columnSidecars} of responses.validatedColumnSidecars ?? []) {
221
227
  const firstColumn = columnSidecars[0];
222
228
  if (!firstColumn) {
@@ -264,6 +270,17 @@ export function cacheByRangeResponses({
264
270
  actual: existing.type,
265
271
  });
266
272
  }
273
+
274
+ // Honest sidecars carry the block signature. The cached block may be unverified, the caller decides which side
275
+ // is invalid. A different root is reported by addColumn.
276
+ if (
277
+ existing.blockRootHex === blockRootHex &&
278
+ !byteArrayEquals(existing.getBlock().signature, fuluColumns[0].signedBlockHeader.signature)
279
+ ) {
280
+ signatureMismatch = {blockInput: existing, columnSidecar: fuluColumns[0]};
281
+ break;
282
+ }
283
+
267
284
  for (const columnSidecar of fuluColumns) {
268
285
  // will throw if root hex does not match (meaning we are following the wrong chain)
269
286
  existing.addColumn(
@@ -279,7 +296,7 @@ export function cacheByRangeResponses({
279
296
  }
280
297
  }
281
298
 
282
- return {blocks: Array.from(updatedBatchBlocks.values()), payloadEnvelopes};
299
+ return {blocks: Array.from(updatedBatchBlocks.values()), payloadEnvelopes, signatureMismatch};
283
300
  }
284
301
 
285
302
  export async function downloadByRange({
@@ -468,6 +485,25 @@ export async function validateResponses({
468
485
  }
469
486
 
470
487
  if (!columnsRequest) {
488
+ // Same as the 0-block check below, for a post-Gloas batch outside the DA window where no columns are requested
489
+ const payloadEnvelopeCount = payloadEnvelopes?.length ?? 0;
490
+ if (
491
+ payloadEnvelopeCount > 0 &&
492
+ parentPayload === undefined &&
493
+ !validatedResponses.validatedBlocks?.length &&
494
+ !batchBlocks?.length
495
+ ) {
496
+ throw new DownloadByRangeError(
497
+ {
498
+ code: DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS,
499
+ ...requestsLogMeta({blocksRequest}),
500
+ columnSidecarCount: 0,
501
+ payloadEnvelopeCount,
502
+ },
503
+ "Envelopes returned without blocks in BeaconBlocksByRange response"
504
+ );
505
+ }
506
+
471
507
  // Only envelope and/or parent-by-root validation needed
472
508
  if (parentPayload !== undefined) {
473
509
  const parentValidated = await validateParentPayloadColumns(parentPayload, columnSidecars ?? [], peerDasMetrics);
@@ -490,14 +526,27 @@ export async function validateResponses({
490
526
  validatedResponses.validatedBlocks?.length ? validatedResponses.validatedBlocks : undefined
491
527
  );
492
528
 
529
+ // Epoch with 0 blocks: columns and envelopes only exist for a block, so data here means the peer withheld blocks or
530
+ // served junk. The parent payload is not requested either, Batch only does once it has blocks
493
531
  if (!blocksForDataValidation.length) {
494
- throw new DownloadByRangeError(
495
- {
496
- code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
497
- ...requestsLogMeta({columnsRequest}),
498
- },
499
- "No blocks in data request slot range to validate data response against"
500
- );
532
+ const columnSidecarCount = columnSidecars?.length ?? 0;
533
+ const payloadEnvelopeCount = payloadEnvelopes?.length ?? 0;
534
+ if (columnSidecarCount > 0 || payloadEnvelopeCount > 0) {
535
+ throw new DownloadByRangeError(
536
+ {
537
+ code: DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS,
538
+ ...requestsLogMeta({blocksRequest}),
539
+ columnSidecarCount,
540
+ payloadEnvelopeCount,
541
+ },
542
+ "Columns or envelopes returned without blocks in BeaconBlocksByRange response"
543
+ );
544
+ }
545
+
546
+ return {
547
+ result: {responses: validatedResponses, payloadEnvelopes: needsEnvelopeValidation ? new Map() : null},
548
+ warnings,
549
+ };
501
550
  }
502
551
 
503
552
  if (!columnSidecars) {
@@ -589,26 +638,19 @@ export function validateBlockByRangeResponse(
589
638
  ): WarnResult<ValidatedBlock[], DownloadByRangeError> {
590
639
  const {startSlot, count} = blocksRequest;
591
640
 
592
- // An error was thrown here by @twoeths in #8150 but it breaks for epochs with 0 blocks during chain
593
- // liveness issues. See comment https://github.com/ChainSafe/lodestar/issues/8147#issuecomment-3246434697
594
- // There are instances where clients return no blocks though. Need to monitor this via the warns to see
595
- // if what the correct behavior should be
641
+ // A 0-block response is accepted as correct, epochs with 0 blocks happen on devnets with poor liveness.
642
+ // If it was wrong, the next batch fails with an unknown parent and SyncChain handles it,
643
+ // see classifyProcessingFault()
596
644
  if (!blocks.length) {
597
- throw new DownloadByRangeError({
598
- code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
599
- ...requestsLogMeta({blocksRequest}),
600
- });
601
- // TODO: this was causing deadlock again. need to come back and fix this so that its possible to process through
602
- // an empty epoch for periods with poor liveness
603
- // return {
604
- // result: [],
605
- // warnings: [
606
- // new DownloadByRangeError({
607
- // code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
608
- // ...requestsLogMeta({blocksRequest}),
609
- // }),
610
- // ],
611
- // };
645
+ return {
646
+ result: [],
647
+ warnings: [
648
+ new DownloadByRangeError({
649
+ code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
650
+ ...requestsLogMeta({blocksRequest}),
651
+ }),
652
+ ],
653
+ };
612
654
  }
613
655
 
614
656
  if (blocks.length > count) {
@@ -895,7 +937,7 @@ export async function validateColumnsByRangeResponse(
895
937
  peerDasMetrics
896
938
  )
897
939
  : validateFuluBlockDataColumnSidecars(
898
- null, // do not pass chain here so we do not validate header signature
940
+ null, // skip BLS, cacheByRangeResponses matches the header signature against the block
899
941
  slot,
900
942
  blockRoot,
901
943
  blobCount,
@@ -978,6 +1020,8 @@ function requestsLogMeta({blocksRequest, columnsRequest}: DownloadByRangeRequest
978
1020
  export enum DownloadByRangeErrorCode {
979
1021
  MISSING_BLOCKS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_BLOCK_RESPONSE",
980
1022
  MISSING_COLUMNS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_COLUMNS_RESPONSE",
1023
+ /** Columns or envelopes were returned for a range with no blocks */
1024
+ DATA_WITHOUT_BLOCKS = "DOWNLOAD_BY_RANGE_ERROR_DATA_WITHOUT_BLOCKS",
981
1025
 
982
1026
  /** Error at the reqresp layer */
983
1027
  REQ_RESP_ERROR = "DOWNLOAD_BY_RANGE_ERROR_REQ_RESP_ERROR",
@@ -1009,6 +1053,8 @@ export enum DownloadByRangeErrorCode {
1009
1053
 
1010
1054
  /** Block segment + envelopes failed chain-segment linearity / FULL-chain checks */
1011
1055
  INVALID_CHAIN_SEGMENT = "DOWNLOAD_BY_RANGE_ERROR_INVALID_CHAIN_SEGMENT",
1056
+ /** A column header signature differs from a cached block whose proposer signature is invalid or unverifiable */
1057
+ INVALID_CACHED_BLOCK = "DOWNLOAD_BY_RANGE_ERROR_INVALID_CACHED_BLOCK",
1012
1058
  }
1013
1059
 
1014
1060
  export type DownloadByRangeErrorType =
@@ -1019,6 +1065,13 @@ export type DownloadByRangeErrorType =
1019
1065
  columnStartSlot?: number;
1020
1066
  columnCount?: number;
1021
1067
  }
1068
+ | {
1069
+ code: DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS;
1070
+ blockStartSlot?: number;
1071
+ blockCount?: number;
1072
+ columnSidecarCount: number;
1073
+ payloadEnvelopeCount: number;
1074
+ }
1022
1075
  | {
1023
1076
  code: DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS;
1024
1077
  slot: number;
@@ -1105,6 +1158,13 @@ export type DownloadByRangeErrorType =
1105
1158
  code: DownloadByRangeErrorCode.INVALID_CHAIN_SEGMENT;
1106
1159
  slot: Slot;
1107
1160
  reason: string;
1161
+ }
1162
+ | {
1163
+ code: DownloadByRangeErrorCode.INVALID_CACHED_BLOCK;
1164
+ slot: Slot;
1165
+ blockRoot: string;
1166
+ /** Set only when the block proposer signature is invalid */
1167
+ blockPeer?: PeerIdStr;
1108
1168
  };
1109
1169
 
1110
1170
  export class DownloadByRangeError extends LodestarError<DownloadByRangeErrorType> {}
@@ -1,7 +1,8 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {ForkPostFulu, ForkPostGloas, isForkPostFulu, isForkPostGloas} from "@lodestar/params";
4
- import {ColumnIndex, SignedBeaconBlock, Slot, fulu} from "@lodestar/types";
4
+ import {getBlockProposerSignatureSet} from "@lodestar/state-transition";
5
+ import {ColumnIndex, SignedBeaconBlock, Slot, ValidatorIndex, fulu} from "@lodestar/types";
5
6
  import {LodestarError, byteArrayEquals, fromHex, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
6
7
  import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
7
8
  import {BlockInputSource, IBlockInput} from "../../chain/blocks/blockInput/types.js";
@@ -30,10 +31,12 @@ export type FetchByRootCoreProps = {
30
31
  peerMeta: PeerSyncMeta;
31
32
  };
32
33
  export type FetchByRootProps = FetchByRootCoreProps & {
34
+ chain: IBeaconChain;
33
35
  cacheItem: BlockInputSyncCacheItem;
34
36
  blockRoot: Uint8Array;
35
37
  };
36
38
  export type FetchByRootAndValidateBlockProps = Omit<FetchByRootCoreProps, "peerMeta"> & {
39
+ chain: IBeaconChain;
37
40
  peerIdStr: PeerIdStr;
38
41
  blockRoot: Uint8Array;
39
42
  };
@@ -112,9 +115,8 @@ export async function downloadByRoot({
112
115
  });
113
116
  }
114
117
 
115
- const hasAllDataPreDownload = blockInput.hasBlockAndAllData();
116
-
117
- if (isBlockInputColumns(blockInput) && !hasAllDataPreDownload) {
118
+ // Like range sync, download every sampled column, half of them only counts as available for reconstruction
119
+ if (isBlockInputColumns(blockInput) && !blockInput.hasComputedAllData()) {
118
120
  // columnSidecars could be undefined if gossip resulted in full block+columns so we don't download any
119
121
  if (!columnSidecars) {
120
122
  throw new DownloadByRootError({
@@ -151,7 +153,10 @@ export async function downloadByRoot({
151
153
 
152
154
  let status: PendingBlockInputStatus;
153
155
  let timeSyncedSec: number | undefined;
154
- if (blockInput.hasBlockAndAllData()) {
156
+ if (
157
+ blockInput.hasBlock() &&
158
+ (isBlockInputColumns(blockInput) ? blockInput.hasComputedAllData() : blockInput.hasAllData())
159
+ ) {
155
160
  status = PendingBlockInputStatus.downloaded;
156
161
  timeSyncedSec = Date.now() / 1000;
157
162
  } else {
@@ -165,6 +170,8 @@ export async function downloadByRoot({
165
170
  timeSyncedSec,
166
171
  timeAddedSec: cacheItem.timeAddedSec,
167
172
  peerIdStrings: cacheItem.peerIdStrings,
173
+ retainedBy: isPendingBlockInput(cacheItem) ? cacheItem.retainedBy : undefined,
174
+ retainedBytes: isPendingBlockInput(cacheItem) ? cacheItem.retainedBytes : undefined,
168
175
  },
169
176
  warnings,
170
177
  };
@@ -188,6 +195,7 @@ export async function fetchByRoot({
188
195
  } else {
189
196
  block = await fetchAndValidateBlock({
190
197
  config,
198
+ chain,
191
199
  network,
192
200
  peerIdStr,
193
201
  blockRoot,
@@ -195,7 +203,7 @@ export async function fetchByRoot({
195
203
  }
196
204
 
197
205
  const forkName = config.getForkName(block.message.slot);
198
- if (!cacheItem.blockInput.hasAllData() && isBlockInputColumns(cacheItem.blockInput)) {
206
+ if (isBlockInputColumns(cacheItem.blockInput) && !cacheItem.blockInput.hasComputedAllData()) {
199
207
  columnSidecarResult = await fetchAndValidateColumns({
200
208
  config,
201
209
  chain,
@@ -210,6 +218,7 @@ export async function fetchByRoot({
210
218
  } else {
211
219
  block = await fetchAndValidateBlock({
212
220
  config,
221
+ chain,
213
222
  network,
214
223
  peerIdStr,
215
224
  blockRoot,
@@ -243,10 +252,11 @@ export async function fetchByRoot({
243
252
 
244
253
  export async function fetchAndValidateBlock({
245
254
  config,
255
+ chain,
246
256
  network,
247
257
  peerIdStr,
248
258
  blockRoot,
249
- }: Omit<FetchByRootAndValidateBlockProps, "chain">): Promise<SignedBeaconBlock> {
259
+ }: FetchByRootAndValidateBlockProps): Promise<SignedBeaconBlock> {
250
260
  const response = await network.sendBeaconBlocksByRoot(peerIdStr, [blockRoot]);
251
261
  const block = response.at(0);
252
262
  if (!block) {
@@ -268,6 +278,41 @@ export async function fetchAndValidateBlock({
268
278
  "block does not match requested root"
269
279
  );
270
280
  }
281
+
282
+ const blockRootHex = toRootHex(blockRoot);
283
+ const {slot, proposerIndex} = block.message;
284
+ // Before the signature check, honest peers serve the genesis block unsigned
285
+ const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
286
+ if (slot < finalizedSlot) {
287
+ throw new DownloadByRootError({
288
+ code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT,
289
+ peer: prettyPrintPeerIdStr(peerIdStr),
290
+ slot,
291
+ finalizedSlot,
292
+ blockRoot: blockRootHex,
293
+ });
294
+ }
295
+ if (proposerIndex >= chain.pubkeyCache.size) {
296
+ throw new DownloadByRootError({
297
+ code: DownloadByRootErrorCode.UNKNOWN_PROPOSER,
298
+ peer: prettyPrintPeerIdStr(peerIdStr),
299
+ slot,
300
+ blockRoot: blockRootHex,
301
+ proposerIndex,
302
+ });
303
+ }
304
+ // Not marked as verified, the block has not passed proposer or ancestry checks yet
305
+ if (!chain.seenBlockInputCache.isVerifiedProposerSignature(slot, blockRootHex, block.signature)) {
306
+ const signatureSet = getBlockProposerSignatureSet(chain.config, block);
307
+ if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: false}))) {
308
+ throw new DownloadByRootError({
309
+ code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID,
310
+ peer: prettyPrintPeerIdStr(peerIdStr),
311
+ slot,
312
+ blockRoot: blockRootHex,
313
+ });
314
+ }
315
+ }
271
316
  return block;
272
317
  }
273
318
 
@@ -374,6 +419,9 @@ export enum DownloadByRootErrorCode {
374
419
  INVALID_KZG_PROOF = "DOWNLOAD_BY_ROOT_ERROR_INVALID_KZG_PROOF",
375
420
  MISSING_BLOCK_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_BLOCK_RESPONSE",
376
421
  MISSING_COLUMN_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_COLUMN_RESPONSE",
422
+ BELOW_FINALIZED_SLOT = "DOWNLOAD_BY_ROOT_ERROR_BELOW_FINALIZED_SLOT",
423
+ UNKNOWN_PROPOSER = "DOWNLOAD_BY_ROOT_ERROR_UNKNOWN_PROPOSER",
424
+ PROPOSAL_SIGNATURE_INVALID = "DOWNLOAD_BY_ROOT_ERROR_PROPOSAL_SIGNATURE_INVALID",
377
425
  Z = "DOWNLOAD_BY_ROOT_ERROR_Z",
378
426
  }
379
427
  export type DownloadByRootErrorType =
@@ -423,6 +471,26 @@ export type DownloadByRootErrorType =
423
471
  code: DownloadByRootErrorCode.MISSING_COLUMN_RESPONSE;
424
472
  peer: string;
425
473
  blockRoot: string;
474
+ }
475
+ | {
476
+ code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT;
477
+ peer: string;
478
+ slot: Slot;
479
+ finalizedSlot: Slot;
480
+ blockRoot: string;
481
+ }
482
+ | {
483
+ code: DownloadByRootErrorCode.UNKNOWN_PROPOSER;
484
+ peer: string;
485
+ slot: Slot;
486
+ blockRoot: string;
487
+ proposerIndex: ValidatorIndex;
488
+ }
489
+ | {
490
+ code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID;
491
+ peer: string;
492
+ slot: Slot;
493
+ blockRoot: string;
426
494
  };
427
495
 
428
496
  export class DownloadByRootError extends LodestarError<DownloadByRootErrorType> {}
@@ -10,6 +10,11 @@ export type RequestCancelEvent = {
10
10
  id: number;
11
11
  };
12
12
 
13
+ export type ResponsePullEvent = {
14
+ id: number;
15
+ count: number;
16
+ };
17
+
13
18
  export enum IteratorEventType {
14
19
  next = "iterator.next",
15
20
  done = "iterator.done",
@@ -25,11 +30,22 @@ export type AsyncIterableEventBus<Args, Item> = {
25
30
  emitRequest(data: RequestEvent<Args>): void;
26
31
  emitRequestCancel(data: RequestCancelEvent): void;
27
32
  emitResponse(data: IteratorEvent<Item>): void;
33
+ emitResponsePull(data: ResponsePullEvent): void;
28
34
  onRequest(handler: (data: RequestEvent<Args>) => void): void;
29
35
  onRequestCancel(handler: (data: RequestCancelEvent) => void): void;
30
36
  onResponse(handler: (data: IteratorEvent<Item>) => void): void;
37
+ onResponsePull(handler: (data: ResponsePullEvent) => void): void;
31
38
  };
32
39
 
40
+ /**
41
+ * Credit window: the consumer grants this many items up front and refunds one per item it pulls, so the
42
+ * producer runs at most `window` (plus one in-flight) items ahead regardless of read speed. Bounds
43
+ * consumer-side buffering on the serving bridge. The requester bridge passes Infinity to stay eager: we
44
+ * buffer our own responses into an array anyway, and pacing the worker there only risks the libp2p read
45
+ * buffer overflowing. Must be >= 1.
46
+ */
47
+ export const RESP_BRIDGE_WINDOW = 2;
48
+
33
49
  type PendingItem<T> = {
34
50
  items: LinkedList<T>;
35
51
  done: boolean;
@@ -44,8 +60,15 @@ export class AsyncIterableBridgeCaller<Args, Item> {
44
60
  private readonly pending = new Map<number, PendingItem<Item>>();
45
61
 
46
62
  constructor(
47
- private readonly events: Pick<AsyncIterableEventBus<Args, Item>, "onResponse" | "emitRequest" | "emitRequestCancel">
63
+ private readonly events: Pick<
64
+ AsyncIterableEventBus<Args, Item>,
65
+ "onResponse" | "emitRequest" | "emitRequestCancel" | "emitResponsePull"
66
+ >,
67
+ private readonly window = RESP_BRIDGE_WINDOW
48
68
  ) {
69
+ if (window < 1) {
70
+ throw new Error(`AsyncIterableBridgeCaller window must be >= 1, got ${window}`);
71
+ }
49
72
  events.onResponse(this.onResponse.bind(this));
50
73
  }
51
74
 
@@ -71,12 +94,18 @@ export class AsyncIterableBridgeCaller<Args, Item> {
71
94
  callArgs,
72
95
  id,
73
96
  });
97
+ // Grant the initial window; next() refunds one credit per consumed item. An Infinity window
98
+ // grants unbounded credit up front so the producer never waits (requester bridge, see above).
99
+ self.events.emitResponsePull({id, count: self.window});
74
100
 
75
101
  return {
76
102
  async next() {
77
103
  while (true) {
78
104
  const item = req.items.shift();
79
105
  if (item !== null) {
106
+ if (self.window !== Infinity) {
107
+ self.events.emitResponsePull({id, count: 1});
108
+ }
80
109
  return {value: item, done: false};
81
110
  }
82
111
 
@@ -142,29 +171,52 @@ export class AsyncIterableBridgeCaller<Args, Item> {
142
171
  }
143
172
  }
144
173
 
174
+ type HandlerState<Item> = {
175
+ iterator: AsyncIterator<Item>;
176
+ credit: number;
177
+ cancelled: boolean;
178
+ onCredit: null | (() => void);
179
+ };
180
+
145
181
  export class AsyncIterableBridgeHandler<Args, Item> {
146
- private readonly iterators = new Map<number, AsyncIterator<Item>>();
182
+ private readonly states = new Map<number, HandlerState<Item>>();
147
183
 
148
184
  constructor(
149
- private readonly events: Pick<AsyncIterableEventBus<Args, Item>, "onRequest" | "onRequestCancel" | "emitResponse">,
185
+ private readonly events: Pick<
186
+ AsyncIterableEventBus<Args, Item>,
187
+ "onRequest" | "onRequestCancel" | "emitResponse" | "onResponsePull"
188
+ >,
150
189
  private readonly handler: (args: Args) => AsyncIterable<Item>
151
190
  ) {
152
191
  events.onRequest(this.onRequest.bind(this));
153
192
  events.onRequestCancel(this.onRequestCancel.bind(this));
193
+ events.onResponsePull(this.onResponsePull.bind(this));
154
194
  }
155
195
 
156
196
  get iteratingCount(): number {
157
- return this.iterators.size;
197
+ return this.states.size;
158
198
  }
159
199
 
160
200
  private async onRequest(data: RequestEvent<Args>): Promise<void> {
201
+ let state: HandlerState<Item> | undefined;
161
202
  try {
162
- const iterator = this.handler(data.callArgs)[Symbol.asyncIterator]();
163
- this.iterators.set(data.id, iterator);
203
+ state = {
204
+ iterator: this.handler(data.callArgs)[Symbol.asyncIterator](),
205
+ credit: 0,
206
+ cancelled: false,
207
+ onCredit: null,
208
+ };
209
+ this.states.set(data.id, state);
164
210
 
165
211
  while (true) {
166
- const result = await iterator.next();
167
- if (result.done) {
212
+ await this.waitForCredit(state);
213
+ if (state.cancelled) {
214
+ break;
215
+ }
216
+ state.credit--;
217
+
218
+ const result = await state.iterator.next();
219
+ if (result.done || state.cancelled) {
168
220
  break;
169
221
  }
170
222
 
@@ -175,29 +227,56 @@ export class AsyncIterableBridgeHandler<Args, Item> {
175
227
  });
176
228
  }
177
229
 
178
- this.events.emitResponse({
179
- type: IteratorEventType.done,
180
- id: data.id,
181
- });
230
+ if (!state.cancelled) {
231
+ this.events.emitResponse({
232
+ type: IteratorEventType.done,
233
+ id: data.id,
234
+ });
235
+ }
182
236
  } catch (e) {
183
- this.events.emitResponse({
184
- type: IteratorEventType.error,
185
- id: data.id,
186
- error: toThreadBoundaryError(e as Error),
187
- });
237
+ if (!state?.cancelled) {
238
+ this.events.emitResponse({
239
+ type: IteratorEventType.error,
240
+ id: data.id,
241
+ error: toThreadBoundaryError(e as Error),
242
+ });
243
+ }
188
244
  } finally {
189
- this.iterators.delete(data.id);
245
+ this.states.delete(data.id);
246
+ }
247
+ }
248
+
249
+ private waitForCredit(state: HandlerState<Item>): Promise<void> {
250
+ if (state.credit > 0 || state.cancelled) {
251
+ return Promise.resolve();
252
+ }
253
+ return new Promise<void>((resolve) => {
254
+ state.onCredit = resolve;
255
+ });
256
+ }
257
+
258
+ private onResponsePull(data: ResponsePullEvent): void {
259
+ const state = this.states.get(data.id);
260
+ if (!state) {
261
+ return;
190
262
  }
263
+ state.credit += data.count;
264
+ state.onCredit?.();
265
+ state.onCredit = null;
191
266
  }
192
267
 
193
268
  private onRequestCancel(data: RequestCancelEvent): void {
194
- const iterator = this.iterators.get(data.id);
195
- if (!iterator?.return) {
269
+ const state = this.states.get(data.id);
270
+ if (!state) {
196
271
  return;
197
272
  }
273
+ // Unblock the loop if it is parked on credit so it can observe the cancel and stop
274
+ state.cancelled = true;
275
+ state.onCredit?.();
276
+ state.onCredit = null;
198
277
 
199
278
  // An async generator queues return() behind the next() that is in flight, so at most one more
200
279
  // item is produced before its finally blocks run. Any error surfaces through that next() call.
201
- void iterator.return().catch(() => {});
280
+ void state.iterator.return?.().catch(() => {});
202
281
  }
203
282
  }
@@ -288,7 +288,7 @@ export function getBlobKzgCommitments(
288
288
  * each blob in the block, assemble the sidecars which can be distributed to peers.
289
289
  *
290
290
  * SPEC FUNCTION
291
- * https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.4/specs/fulu/validator.md#get_data_column_sidecars
291
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/fulu/validator.md#get_data_column_sidecars
292
292
  */
293
293
  export function getFuluDataColumnSidecars(
294
294
  signedBlockHeader: SignedBeaconBlockHeader,
@@ -299,6 +299,9 @@ export function getFuluDataColumnSidecars(
299
299
  if (cellsAndKzgProofs.length !== kzgCommitments.length) {
300
300
  throw Error("Invalid cellsAndKzgProofs length for getDataColumnSidecars");
301
301
  }
302
+ if (kzgCommitments.length === 0) {
303
+ return [];
304
+ }
302
305
 
303
306
  const sidecars: fulu.DataColumnSidecar[] = [];
304
307
  for (let columnIndex = 0; columnIndex < NUMBER_OF_COLUMNS; columnIndex++) {
@@ -22,9 +22,9 @@ export function callInNextEventLoop(callback: () => void): void {
22
22
  }
23
23
 
24
24
  /**
25
- * Schedules a callback for the `check` phase. Pending promise continuations run first,
26
- * and there is no 1ms timer delay.
25
+ * Schedules a callback for the `check` phase, after the `poll` phase handles ready I/O.
26
+ * Pending promise continuations run first, and there is no 1ms timer delay.
27
27
  */
28
- export function callImmediate(callback: () => void): void {
28
+ export function callAfterIO(callback: () => void): void {
29
29
  setImmediate(callback);
30
30
  }