@aztec/p2p 0.0.1-commit.d3ec352c → 0.0.1-commit.d6f2b3f94

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 (533) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +4 -3
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +4 -4
  4. package/dest/client/factory.d.ts +5 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +47 -14
  7. package/dest/client/interface.d.ts +49 -18
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +42 -46
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +565 -257
  12. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
  13. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
  14. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
  15. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
  16. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
  17. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
  18. package/dest/config.d.ts +27 -9
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +26 -15
  21. package/dest/index.d.ts +2 -1
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +109 -76
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.js +436 -3
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +529 -289
  30. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  31. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/index.js +1 -2
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/mocks.js +17 -13
  36. package/dest/mem_pools/index.d.ts +3 -2
  37. package/dest/mem_pools/index.d.ts.map +1 -1
  38. package/dest/mem_pools/index.js +1 -1
  39. package/dest/mem_pools/instrumentation.d.ts +7 -1
  40. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  41. package/dest/mem_pools/instrumentation.js +31 -13
  42. package/dest/mem_pools/interface.d.ts +6 -7
  43. package/dest/mem_pools/interface.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
  45. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -335
  47. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
  48. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  49. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
  50. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
  51. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
  53. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  54. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  56. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  57. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  59. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  60. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
  62. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  63. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  65. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  66. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  68. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  69. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool/index.js +0 -1
  71. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  72. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool/priority.js +6 -1
  74. package/dest/mem_pools/tx_pool/tx_pool.d.ts +8 -4
  75. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  77. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +25 -20
  79. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  80. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  81. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  82. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  83. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  84. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  85. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +87 -0
  86. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  87. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +180 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  92. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  93. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  94. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  95. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  96. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  97. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  98. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  99. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  100. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  101. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  102. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  103. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  104. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  105. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  106. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  107. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  108. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  109. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  110. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  111. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  112. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  113. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  114. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  115. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  116. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  117. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  118. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  119. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  120. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  121. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  122. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  123. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  124. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +93 -0
  125. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  126. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +127 -0
  127. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  128. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  129. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  130. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  131. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  132. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  133. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  134. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  135. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  136. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  137. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  138. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +751 -0
  139. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  140. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  141. package/dest/msg_validators/attestation_validator/attestation_validator.js +52 -19
  142. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -7
  143. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  144. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
  145. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  146. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  147. package/dest/msg_validators/clock_tolerance.js +37 -0
  148. package/dest/msg_validators/index.d.ts +2 -2
  149. package/dest/msg_validators/index.d.ts.map +1 -1
  150. package/dest/msg_validators/index.js +1 -1
  151. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  152. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  153. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  154. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  155. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  156. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  157. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  158. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  159. package/dest/msg_validators/proposal_validator/index.js +3 -0
  160. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  161. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  162. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  163. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  164. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  165. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  166. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
  167. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  168. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  169. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  170. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  171. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
  172. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  173. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  174. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  175. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  176. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  177. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
  178. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  179. package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
  180. package/dest/msg_validators/tx_validator/factory.d.ts +9 -4
  181. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  182. package/dest/msg_validators/tx_validator/factory.js +22 -12
  183. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  184. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  185. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  186. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  187. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  188. package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
  189. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  190. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  191. package/dest/msg_validators/tx_validator/index.js +1 -0
  192. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
  193. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  194. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  195. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  196. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  197. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  198. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  199. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  200. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  201. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  202. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  203. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +22 -5
  204. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  205. package/dest/msg_validators/tx_validator/timestamp_validator.js +4 -4
  206. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  207. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  208. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  209. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  210. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  211. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  212. package/dest/services/data_store.d.ts +1 -1
  213. package/dest/services/data_store.d.ts.map +1 -1
  214. package/dest/services/data_store.js +10 -6
  215. package/dest/services/discv5/discV5_service.js +1 -1
  216. package/dest/services/dummy_service.d.ts +26 -2
  217. package/dest/services/dummy_service.d.ts.map +1 -1
  218. package/dest/services/dummy_service.js +48 -0
  219. package/dest/services/encoding.d.ts +2 -2
  220. package/dest/services/encoding.d.ts.map +1 -1
  221. package/dest/services/encoding.js +9 -8
  222. package/dest/services/gossipsub/index.d.ts +3 -0
  223. package/dest/services/gossipsub/index.d.ts.map +1 -0
  224. package/dest/services/gossipsub/index.js +2 -0
  225. package/dest/services/gossipsub/scoring.d.ts +21 -3
  226. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  227. package/dest/services/gossipsub/scoring.js +24 -7
  228. package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
  229. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  230. package/dest/services/gossipsub/topic_score_params.js +324 -0
  231. package/dest/services/index.d.ts +2 -1
  232. package/dest/services/index.d.ts.map +1 -1
  233. package/dest/services/index.js +1 -0
  234. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  235. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  236. package/dest/services/libp2p/instrumentation.js +30 -72
  237. package/dest/services/libp2p/libp2p_service.d.ts +108 -36
  238. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  239. package/dest/services/libp2p/libp2p_service.js +978 -320
  240. package/dest/services/peer-manager/metrics.d.ts +7 -2
  241. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  242. package/dest/services/peer-manager/metrics.js +33 -21
  243. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  244. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  245. package/dest/services/peer-manager/peer_manager.js +4 -12
  246. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  247. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  248. package/dest/services/peer-manager/peer_scoring.js +32 -6
  249. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  250. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  251. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  252. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  253. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  254. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  255. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  256. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  257. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  258. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  259. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  260. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  261. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  262. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  263. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  264. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  265. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  266. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  267. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  268. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  269. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  270. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  271. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  272. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  273. package/dest/services/reqresp/constants.d.ts +12 -0
  274. package/dest/services/reqresp/constants.d.ts.map +1 -0
  275. package/dest/services/reqresp/constants.js +7 -0
  276. package/dest/services/reqresp/interface.d.ts +13 -2
  277. package/dest/services/reqresp/interface.d.ts.map +1 -1
  278. package/dest/services/reqresp/interface.js +16 -2
  279. package/dest/services/reqresp/metrics.d.ts +6 -5
  280. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  281. package/dest/services/reqresp/metrics.js +17 -21
  282. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  283. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  284. package/dest/services/reqresp/protocols/auth.js +2 -2
  285. package/dest/services/reqresp/protocols/block.js +1 -1
  286. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  287. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  288. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  289. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  290. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  291. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  292. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +30 -7
  293. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  294. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +60 -14
  295. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  296. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  297. package/dest/services/reqresp/protocols/status.js +4 -1
  298. package/dest/services/reqresp/protocols/tx.d.ts +8 -3
  299. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  300. package/dest/services/reqresp/protocols/tx.js +20 -0
  301. package/dest/services/reqresp/reqresp.d.ts +6 -1
  302. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  303. package/dest/services/reqresp/reqresp.js +471 -50
  304. package/dest/services/service.d.ts +53 -3
  305. package/dest/services/service.d.ts.map +1 -1
  306. package/dest/services/tx_collection/config.d.ts +10 -1
  307. package/dest/services/tx_collection/config.d.ts.map +1 -1
  308. package/dest/services/tx_collection/config.js +26 -2
  309. package/dest/services/tx_collection/fast_tx_collection.d.ts +7 -4
  310. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  311. package/dest/services/tx_collection/fast_tx_collection.js +34 -13
  312. package/dest/services/tx_collection/file_store_tx_collection.d.ts +44 -0
  313. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  314. package/dest/services/tx_collection/file_store_tx_collection.js +118 -0
  315. package/dest/services/tx_collection/file_store_tx_source.d.ts +27 -0
  316. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  317. package/dest/services/tx_collection/file_store_tx_source.js +57 -0
  318. package/dest/services/tx_collection/index.d.ts +3 -1
  319. package/dest/services/tx_collection/index.d.ts.map +1 -1
  320. package/dest/services/tx_collection/index.js +2 -0
  321. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  322. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  323. package/dest/services/tx_collection/instrumentation.js +10 -13
  324. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  325. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  326. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  327. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -1
  328. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  329. package/dest/services/tx_collection/slow_tx_collection.js +48 -19
  330. package/dest/services/tx_collection/tx_collection.d.ts +21 -11
  331. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  332. package/dest/services/tx_collection/tx_collection.js +63 -7
  333. package/dest/services/tx_collection/tx_collection_sink.d.ts +15 -6
  334. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  335. package/dest/services/tx_collection/tx_collection_sink.js +13 -7
  336. package/dest/services/tx_file_store/config.d.ts +16 -0
  337. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  338. package/dest/services/tx_file_store/config.js +22 -0
  339. package/dest/services/tx_file_store/index.d.ts +4 -0
  340. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  341. package/dest/services/tx_file_store/index.js +3 -0
  342. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  343. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  344. package/dest/services/tx_file_store/instrumentation.js +29 -0
  345. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  346. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  347. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  348. package/dest/services/tx_provider.d.ts +6 -5
  349. package/dest/services/tx_provider.d.ts.map +1 -1
  350. package/dest/services/tx_provider.js +16 -6
  351. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  352. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  353. package/dest/services/tx_provider_instrumentation.js +14 -14
  354. package/dest/test-helpers/index.d.ts +3 -1
  355. package/dest/test-helpers/index.d.ts.map +1 -1
  356. package/dest/test-helpers/index.js +2 -0
  357. package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
  358. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  359. package/dest/test-helpers/mock-pubsub.d.ts +27 -1
  360. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  361. package/dest/test-helpers/mock-pubsub.js +97 -2
  362. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  363. package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
  364. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  365. package/dest/test-helpers/reqresp-nodes.js +2 -1
  366. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  367. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  368. package/dest/test-helpers/test_tx_provider.js +41 -0
  369. package/dest/test-helpers/testbench-utils.d.ts +158 -0
  370. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  371. package/dest/test-helpers/testbench-utils.js +360 -0
  372. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  373. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  374. package/dest/testbench/p2p_client_testbench_worker.js +219 -124
  375. package/dest/testbench/worker_client_manager.d.ts +51 -6
  376. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  377. package/dest/testbench/worker_client_manager.js +226 -39
  378. package/package.json +16 -16
  379. package/src/bootstrap/bootstrap.ts +7 -4
  380. package/src/client/factory.ts +80 -29
  381. package/src/client/interface.ts +57 -17
  382. package/src/client/p2p_client.ts +229 -295
  383. package/src/client/test/tx_proposal_collector/README.md +227 -0
  384. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  385. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  386. package/src/config.ts +50 -20
  387. package/src/index.ts +1 -0
  388. package/src/mem_pools/attestation_pool/attestation_pool.ts +502 -78
  389. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +614 -322
  390. package/src/mem_pools/attestation_pool/index.ts +9 -2
  391. package/src/mem_pools/attestation_pool/mocks.ts +21 -15
  392. package/src/mem_pools/index.ts +4 -1
  393. package/src/mem_pools/instrumentation.ts +39 -14
  394. package/src/mem_pools/interface.ts +5 -7
  395. package/src/mem_pools/tx_pool/README.md +270 -0
  396. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +362 -367
  397. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
  398. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
  399. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  400. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  401. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
  402. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  403. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  404. package/src/mem_pools/tx_pool/index.ts +0 -1
  405. package/src/mem_pools/tx_pool/priority.ts +8 -1
  406. package/src/mem_pools/tx_pool/tx_pool.ts +8 -3
  407. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +18 -13
  408. package/src/mem_pools/tx_pool_v2/README.md +259 -0
  409. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  410. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  411. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +234 -0
  412. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  413. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  414. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  415. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  416. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  417. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  418. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  419. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  420. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  421. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  422. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  423. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  424. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +207 -0
  425. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  426. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  427. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  428. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +895 -0
  429. package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
  430. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +21 -18
  431. package/src/msg_validators/clock_tolerance.ts +51 -0
  432. package/src/msg_validators/index.ts +1 -1
  433. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  434. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  435. package/src/msg_validators/proposal_validator/index.ts +3 -0
  436. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  437. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  438. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
  439. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  440. package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
  441. package/src/msg_validators/tx_validator/data_validator.ts +18 -6
  442. package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
  443. package/src/msg_validators/tx_validator/factory.ts +65 -24
  444. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  445. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  446. package/src/msg_validators/tx_validator/index.ts +1 -0
  447. package/src/msg_validators/tx_validator/metadata_validator.ts +19 -8
  448. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  449. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  450. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  451. package/src/msg_validators/tx_validator/timestamp_validator.ts +25 -15
  452. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  453. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  454. package/src/services/data_store.ts +10 -7
  455. package/src/services/discv5/discV5_service.ts +1 -1
  456. package/src/services/dummy_service.ts +63 -0
  457. package/src/services/encoding.ts +8 -7
  458. package/src/services/gossipsub/README.md +626 -0
  459. package/src/services/gossipsub/index.ts +2 -0
  460. package/src/services/gossipsub/scoring.ts +29 -5
  461. package/src/services/gossipsub/topic_score_params.ts +451 -0
  462. package/src/services/index.ts +1 -0
  463. package/src/services/libp2p/instrumentation.ts +32 -73
  464. package/src/services/libp2p/libp2p_service.ts +647 -307
  465. package/src/services/peer-manager/metrics.ts +39 -21
  466. package/src/services/peer-manager/peer_manager.ts +5 -4
  467. package/src/services/peer-manager/peer_scoring.ts +28 -4
  468. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  469. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  470. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  471. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  472. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  473. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  474. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  475. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  476. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  477. package/src/services/reqresp/constants.ts +14 -0
  478. package/src/services/reqresp/interface.ts +30 -2
  479. package/src/services/reqresp/metrics.ts +36 -27
  480. package/src/services/reqresp/protocols/auth.ts +2 -2
  481. package/src/services/reqresp/protocols/block.ts +1 -1
  482. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  483. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +35 -12
  484. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +75 -10
  485. package/src/services/reqresp/protocols/status.ts +7 -4
  486. package/src/services/reqresp/protocols/tx.ts +23 -2
  487. package/src/services/reqresp/reqresp.ts +79 -22
  488. package/src/services/service.ts +63 -4
  489. package/src/services/tx_collection/config.ts +42 -2
  490. package/src/services/tx_collection/fast_tx_collection.ts +44 -19
  491. package/src/services/tx_collection/file_store_tx_collection.ts +152 -0
  492. package/src/services/tx_collection/file_store_tx_source.ts +70 -0
  493. package/src/services/tx_collection/index.ts +6 -0
  494. package/src/services/tx_collection/instrumentation.ts +5 -13
  495. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  496. package/src/services/tx_collection/slow_tx_collection.ts +55 -26
  497. package/src/services/tx_collection/tx_collection.ts +85 -19
  498. package/src/services/tx_collection/tx_collection_sink.ts +17 -7
  499. package/src/services/tx_file_store/config.ts +37 -0
  500. package/src/services/tx_file_store/index.ts +3 -0
  501. package/src/services/tx_file_store/instrumentation.ts +36 -0
  502. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  503. package/src/services/tx_provider.ts +27 -11
  504. package/src/services/tx_provider_instrumentation.ts +24 -14
  505. package/src/test-helpers/index.ts +2 -0
  506. package/src/test-helpers/make-test-p2p-clients.ts +3 -3
  507. package/src/test-helpers/mock-pubsub.ts +134 -4
  508. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  509. package/src/test-helpers/reqresp-nodes.ts +3 -2
  510. package/src/test-helpers/test_tx_provider.ts +64 -0
  511. package/src/test-helpers/testbench-utils.ts +422 -0
  512. package/src/testbench/p2p_client_testbench_worker.ts +339 -120
  513. package/src/testbench/worker_client_manager.ts +304 -42
  514. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -37
  515. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  516. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -213
  517. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -30
  518. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  519. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -219
  520. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
  521. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  522. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -239
  523. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  524. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  525. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  526. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  527. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  528. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  529. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -298
  530. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -287
  531. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -285
  532. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  533. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -36,6 +36,7 @@ import {
36
36
  type ReqRespSubProtocolValidators,
37
37
  type SubProtocolMap,
38
38
  responseFromBuffer,
39
+ subProtocolSizeCalculators,
39
40
  } from './interface.js';
40
41
  import { ReqRespMetrics } from './metrics.js';
41
42
  import {
@@ -111,6 +112,13 @@ export class ReqResp implements ReqRespInterface {
111
112
  return this.metrics.tracer;
112
113
  }
113
114
 
115
+ /**
116
+ * Get the connection sampler instance
117
+ */
118
+ getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'> {
119
+ return this.connectionSampler;
120
+ }
121
+
114
122
  /**
115
123
  * Start the reqresp service
116
124
  */
@@ -212,6 +220,14 @@ export class ReqResp implements ReqRespInterface {
212
220
  const responseValidator = this.subProtocolValidators[subProtocol] ?? DEFAULT_SUB_PROTOCOL_VALIDATORS[subProtocol];
213
221
  const responses: InstanceType<SubProtocolMap[SubProtocol]['response']>[] = new Array(requests.length);
214
222
  const requestBuffers = requests.map(req => req.toBuffer());
223
+ const isEmptyResponse = (value: unknown): boolean => {
224
+ // Some responses serialize to a non-empty buffer even when they contain no items (e.g., empty TxArray).
225
+ if (!value || typeof value !== 'object') {
226
+ return false;
227
+ }
228
+ const length = (value as { length?: number }).length;
229
+ return typeof length === 'number' && length === 0;
230
+ };
215
231
 
216
232
  const requestFunction = async (signal: AbortSignal) => {
217
233
  // Track which requests still need to be processed
@@ -252,7 +268,9 @@ export class ReqResp implements ReqRespInterface {
252
268
  for (const requestIndex of pendingRequestIndices) {
253
269
  const peer = batchSampler.getPeerForRequest(requestIndex);
254
270
  if (!peer) {
255
- break;
271
+ // No peer available for this specific index (all peers exhausted for it)
272
+ // Skip this index for now - it stays in pendingRequestIndices for retry
273
+ continue;
256
274
  }
257
275
  const peerAsString = peer.toString();
258
276
  if (!requestBatches.has(peerAsString)) {
@@ -271,6 +289,12 @@ export class ReqResp implements ReqRespInterface {
271
289
  });
272
290
  }
273
291
 
292
+ // If no requests could be assigned (all peers exhausted for all indices), exit early
293
+ if (requestBatches.size === 0) {
294
+ this.logger.warn('No peers available for any pending request indices, stopping batch request');
295
+ break;
296
+ }
297
+
274
298
  // Make parallel requests for each peer's batch
275
299
  // A batch entry will look something like this:
276
300
  // PeerId0: [0, 1, 2, 3]
@@ -282,38 +306,61 @@ export class ReqResp implements ReqRespInterface {
282
306
  const batchResults = await Promise.all(
283
307
  Array.from(requestBatches.entries()).map(async ([peerAsString, { peerId: peer, indices }]) => {
284
308
  try {
309
+ const markIndexFailed = (index: number) => batchSampler.markPeerFailedForIndex(peer, index);
285
310
  // Requests all going to the same peer are sent synchronously
286
311
  const peerResults: { index: number; response: InstanceType<SubProtocolMap[SubProtocol]['response']> }[] =
287
312
  [];
313
+ let shouldReplacePeer = false;
314
+ const handleFailure = (status: ReqRespStatus, index: number) => {
315
+ this.logger.warn(
316
+ `Request to peer ${peerAsString} failed with status ${prettyPrintReqRespStatus(status)}`,
317
+ );
318
+ markIndexFailed(index);
319
+ return status === ReqRespStatus.RATE_LIMIT_EXCEEDED;
320
+ };
321
+
288
322
  for (const index of indices) {
289
- this.logger.trace(`Sending request ${index} to peer ${peerAsString}`);
323
+ this.logger.info(`Sending request ${index} to peer ${peerAsString}`);
290
324
  const response = await this.sendRequestToPeer(peer, subProtocol, requestBuffers[index]);
291
325
 
292
326
  // Check the status of the response buffer
293
327
  if (response.status !== ReqRespStatus.SUCCESS) {
294
- this.logger.debug(
295
- `Request to peer ${peerAsString} failed with status ${prettyPrintReqRespStatus(response.status)}`,
296
- );
297
-
298
- // If we hit a rate limit or some failure, we remove the peer and return the results,
299
- // they will be split among remaining peers and the new sampled peer
300
- batchSampler.removePeerAndReplace(peer);
301
- return { peer, results: peerResults };
328
+ shouldReplacePeer = handleFailure(response.status, index);
329
+ if (shouldReplacePeer) {
330
+ break;
331
+ }
332
+ continue;
302
333
  }
303
334
 
304
- if (response && response.data.length > 0) {
305
- const object = responseFromBuffer(subProtocol, response.data);
306
- const isValid = await responseValidator(requests[index], object, peer);
335
+ if (response.data.length === 0) {
336
+ markIndexFailed(index);
337
+ continue;
338
+ }
307
339
 
308
- if (isValid) {
309
- peerResults.push({ index, response: object });
310
- }
340
+ const object = responseFromBuffer(subProtocol, response.data);
341
+ if (isEmptyResponse(object)) {
342
+ markIndexFailed(index);
343
+ continue;
311
344
  }
345
+
346
+ const isValid = await responseValidator(requests[index], object, peer);
347
+ if (!isValid) {
348
+ markIndexFailed(index);
349
+ continue;
350
+ }
351
+
352
+ peerResults.push({ index, response: object });
353
+ }
354
+
355
+ // If peer had a hard failure (rate limit), replace it for future iterations
356
+ if (shouldReplacePeer) {
357
+ this.logger.warn(`Peer ${peerAsString} hit a hard failure, removing from sampler`);
358
+ batchSampler.removePeerAndReplace(peer);
312
359
  }
313
360
 
314
361
  return { peer, results: peerResults };
315
362
  } catch (error) {
316
- this.logger.debug(`Failed batch request to peer ${peerAsString}:`, error);
363
+ this.logger.warn(`Failed batch request to peer ${peerAsString}:`, error);
317
364
  batchSampler.removePeerAndReplace(peer);
318
365
  return { peer, results: [] };
319
366
  }
@@ -334,7 +381,7 @@ export class ReqResp implements ReqRespInterface {
334
381
  }
335
382
 
336
383
  if (retryAttempts >= maxRetryAttempts) {
337
- this.logger.debug(`Max retry attempts ${maxRetryAttempts} reached for batch request`);
384
+ this.logger.warn(`Max retry attempts ${maxRetryAttempts} reached for batch request`);
338
385
  }
339
386
 
340
387
  return responses;
@@ -347,7 +394,7 @@ export class ReqResp implements ReqRespInterface {
347
394
  () => new CollectiveReqRespTimeoutError(),
348
395
  );
349
396
  } catch (e: any) {
350
- this.logger.debug(`${e.message} | subProtocol: ${subProtocol}`);
397
+ this.logger.warn(`${e.message} | subProtocol: ${subProtocol}`);
351
398
  return [];
352
399
  }
353
400
  }
@@ -391,6 +438,9 @@ export class ReqResp implements ReqRespInterface {
391
438
  try {
392
439
  this.metrics.recordRequestSent(subProtocol);
393
440
 
441
+ // Calculate expected response size based on the request payload
442
+ const expectedSizeKb = subProtocolSizeCalculators[subProtocol](payload);
443
+
394
444
  this.logger.trace(`Sending request to peer ${peerId.toString()} on sub protocol ${subProtocol}`);
395
445
  stream = await this.connectionSampler.dialProtocol(peerId, subProtocol, dialTimeout);
396
446
  this.logger.trace(
@@ -398,17 +448,21 @@ export class ReqResp implements ReqRespInterface {
398
448
  );
399
449
 
400
450
  const timeoutErr = new IndividualReqRespTimeoutError();
451
+ // Create a wrapper to pass the expected size to readMessage
452
+ const readMessageWithSizeLimit = (source: AsyncIterable<Uint8ArrayList>) =>
453
+ this.readMessage(source, expectedSizeKb);
401
454
  const [_, resp] = await executeTimeout(
402
455
  signal =>
403
456
  Promise.all([
404
457
  pipeline([payload], stream!.sink, { signal }),
405
- pipeline(stream!.source, this.readMessage.bind(this), { signal }),
458
+ pipeline(stream!.source, readMessageWithSizeLimit, { signal }),
406
459
  ]),
407
460
  this.individualRequestTimeoutMs,
408
461
  () => timeoutErr,
409
462
  );
410
463
  return resp;
411
464
  } catch (e: any) {
465
+ this.logger.warn(`SUBPROTOCOL: ${subProtocol}\n`, e);
412
466
  // On error we immediately abort the stream, this is preferred way,
413
467
  // because it signals to the sender that error happened, whereas
414
468
  // closing the stream only closes our side and is much slower
@@ -463,8 +517,11 @@ export class ReqResp implements ReqRespInterface {
463
517
  * The message is split into two components
464
518
  * - The first chunk should contain a control byte, indicating the status of the response see `ReqRespStatus`
465
519
  * - The second chunk should contain the response data
520
+ *
521
+ * @param source - The async iterable source of data chunks
522
+ * @param maxSizeKb - Optional maximum expected size in KB for the decompressed response
466
523
  */
467
- private async readMessage(source: AsyncIterable<Uint8ArrayList>): Promise<ReqRespResponse> {
524
+ private async readMessage(source: AsyncIterable<Uint8ArrayList>, maxSizeKb?: number): Promise<ReqRespResponse> {
468
525
  let status: ReqRespStatus | undefined;
469
526
  const chunks: Uint8Array[] = [];
470
527
 
@@ -489,7 +546,7 @@ export class ReqResp implements ReqRespInterface {
489
546
  }
490
547
 
491
548
  const messageData = Buffer.concat(chunks);
492
- const message: Buffer = this.snappyTransform.inboundTransformData(messageData);
549
+ const message: Buffer = this.snappyTransform.inboundTransformData(messageData, undefined, maxSizeKb);
493
550
 
494
551
  return {
495
552
  status: status ?? ReqRespStatus.UNKNOWN,
@@ -1,12 +1,14 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
3
  import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
3
- import type { BlockAttestation, BlockProposal, Gossipable } from '@aztec/stdlib/p2p';
4
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore, Gossipable } from '@aztec/stdlib/p2p';
4
5
  import type { Tx } from '@aztec/stdlib/tx';
5
6
 
6
7
  import type { PeerId } from '@libp2p/interface';
7
8
  import type { ENR } from '@nethermindeth/enr';
8
9
  import type EventEmitter from 'events';
9
10
 
11
+ import type { BatchTxRequesterLibP2PService } from './reqresp/batch-tx-requester/interface.js';
10
12
  import type { P2PReqRespConfig } from './reqresp/config.js';
11
13
  import type { StatusMessage } from './reqresp/index.js';
12
14
  import type {
@@ -22,13 +24,52 @@ export enum PeerDiscoveryState {
22
24
  STOPPED = 'stopped',
23
25
  }
24
26
 
25
- export type P2PBlockReceivedCallback = (
26
- block: BlockProposal,
27
+ /**
28
+ * Callback for when a block proposal is received.
29
+ * Validators validate but DO NOT attest to individual blocks - attestations are only for checkpoints.
30
+ * @returns true if the proposal is valid, false otherwise
31
+ */
32
+ export type P2PBlockReceivedCallback = (block: BlockProposal, sender: PeerId) => Promise<boolean>;
33
+
34
+ /**
35
+ * Callback for when a checkpoint proposal is received.
36
+ * The checkpoint proposal is passed as CheckpointProposalCore (without lastBlock) since
37
+ * the lastBlock is extracted and stored separately as a BlockProposal, and the block
38
+ * callback is invoked and awaited before this checkpoint callback.
39
+ */
40
+ export type P2PCheckpointReceivedCallback = (
41
+ checkpoint: CheckpointProposalCore,
27
42
  sender: PeerId,
28
- ) => Promise<BlockAttestation[] | undefined>;
43
+ ) => Promise<CheckpointAttestation[] | undefined>;
29
44
 
30
45
  export type AuthReceivedCallback = (peerId: PeerId, authRequest: AuthRequest) => Promise<AuthResponse | undefined>;
31
46
 
47
+ /** Minimal info passed to the duplicate proposal callback. */
48
+ export type DuplicateProposalInfo = {
49
+ slot: SlotNumber;
50
+ proposer: EthAddress;
51
+ type: 'checkpoint' | 'block';
52
+ };
53
+
54
+ /**
55
+ * Callback for when a duplicate proposal is detected (equivocation).
56
+ * Invoked on the first duplicate (when count goes from 1 to 2).
57
+ */
58
+ export type P2PDuplicateProposalCallback = (info: DuplicateProposalInfo) => void;
59
+
60
+ /** Minimal info passed to the duplicate attestation callback. */
61
+ export type DuplicateAttestationInfo = {
62
+ slot: SlotNumber;
63
+ attester: EthAddress;
64
+ };
65
+
66
+ /**
67
+ * Callback for when a duplicate attestation is detected (equivocation).
68
+ * A validator signing attestations for different proposals at the same slot.
69
+ * Invoked on the first duplicate (when count goes from 1 to 2).
70
+ */
71
+ export type P2PDuplicateAttestationCallback = (info: DuplicateAttestationInfo) => void;
72
+
32
73
  /**
33
74
  * The interface for a P2P service implementation.
34
75
  */
@@ -70,6 +111,21 @@ export interface P2PService {
70
111
  // Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
71
112
  registerBlockReceivedCallback(callback: P2PBlockReceivedCallback): void;
72
113
 
114
+ registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback): void;
115
+
116
+ /**
117
+ * Registers a callback invoked when a duplicate proposal is detected (equivocation).
118
+ * The callback is triggered on the first duplicate (when count goes from 1 to 2).
119
+ */
120
+ registerDuplicateProposalCallback(callback: P2PDuplicateProposalCallback): void;
121
+
122
+ /**
123
+ * Registers a callback invoked when a duplicate attestation is detected (equivocation).
124
+ * A validator signing attestations for different proposals at the same slot.
125
+ * The callback is triggered on the first duplicate (when count goes from 1 to 2).
126
+ */
127
+ registerDuplicateAttestationCallback(callback: P2PDuplicateAttestationCallback): void;
128
+
73
129
  getEnr(): ENR | undefined;
74
130
 
75
131
  getPeers(includePending?: boolean): PeerInfo[];
@@ -88,6 +144,9 @@ export interface P2PService {
88
144
 
89
145
  /** If node running this P2P stack is validator, passes in validator address to P2P layer */
90
146
  registerThisValidatorAddresses(address: EthAddress[]): void;
147
+
148
+ /** Get BatchTxRequester service dependencies */
149
+ getBatchTxRequesterService(): BatchTxRequesterLibP2PService;
91
150
  }
92
151
 
93
152
  /**
@@ -1,5 +1,12 @@
1
- import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
2
- import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/server';
1
+ import {
2
+ type ConfigMappingsType,
3
+ booleanConfigHelper,
4
+ enumConfigHelper,
5
+ numberConfigHelper,
6
+ } from '@aztec/foundation/config';
7
+ import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
8
+
9
+ export type MissingTxsCollectorType = 'new' | 'old';
3
10
 
4
11
  export type TxCollectionConfig = {
5
12
  /** How long to wait before starting reqresp for fast collection */
@@ -22,6 +29,14 @@ export type TxCollectionConfig = {
22
29
  txCollectionFastMaxParallelRequestsPerNode: number;
23
30
  /** Maximum number of transactions to request from a node in a single batch */
24
31
  txCollectionNodeRpcMaxBatchSize: number;
32
+ /** Which collector implementation to use for missing txs collection */
33
+ txCollectionMissingTxsCollectorType: MissingTxsCollectorType;
34
+ /** A comma-separated list of file store URLs (s3://, gs://, file://, http://) for tx collection */
35
+ txCollectionFileStoreUrls: string[];
36
+ /** Delay in ms before file store collection starts after slow collection is triggered */
37
+ txCollectionFileStoreSlowDelayMs: number;
38
+ /** Delay in ms before file store collection starts after fast collection is triggered */
39
+ txCollectionFileStoreFastDelayMs: number;
25
40
  };
26
41
 
27
42
  export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
@@ -81,4 +96,29 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
81
96
  description: 'Maximum number of transactions to request from a node in a single batch',
82
97
  ...numberConfigHelper(MAX_RPC_TXS_LEN),
83
98
  },
99
+ txCollectionMissingTxsCollectorType: {
100
+ env: 'TX_COLLECTION_MISSING_TXS_COLLECTOR_TYPE',
101
+ description: 'Which collector implementation to use for missing txs collection (new or old)',
102
+ ...enumConfigHelper(['new', 'old'] as const, 'new'),
103
+ },
104
+ txCollectionFileStoreUrls: {
105
+ env: 'TX_COLLECTION_FILE_STORE_URLS',
106
+ description: 'A comma-separated list of file store URLs (s3://, gs://, file://, http://) for tx collection',
107
+ parseEnv: (val: string) =>
108
+ val
109
+ .split(',')
110
+ .map(url => url.trim())
111
+ .filter(url => url.length > 0),
112
+ defaultValue: [],
113
+ },
114
+ txCollectionFileStoreSlowDelayMs: {
115
+ env: 'TX_COLLECTION_FILE_STORE_SLOW_DELAY_MS',
116
+ description: 'Delay before file store collection starts after slow collection',
117
+ ...numberConfigHelper(24_000),
118
+ },
119
+ txCollectionFileStoreFastDelayMs: {
120
+ env: 'TX_COLLECTION_FILE_STORE_FAST_DELAY_MS',
121
+ description: 'Delay before file store collection starts after fast collection',
122
+ ...numberConfigHelper(2_000),
123
+ },
84
124
  };
@@ -2,7 +2,6 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { times } from '@aztec/foundation/collection';
3
3
  import { AbortError, TimeoutError } from '@aztec/foundation/error';
4
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
5
- import { boundInclusive } from '@aztec/foundation/number';
6
5
  import { promiseWithResolvers } from '@aztec/foundation/promise';
7
6
  import { sleep } from '@aztec/foundation/sleep';
8
7
  import { DateProvider, elapsed } from '@aztec/foundation/timer';
@@ -12,25 +11,40 @@ import { type Tx, TxHash } from '@aztec/stdlib/tx';
12
11
 
13
12
  import type { PeerId } from '@libp2p/interface';
14
13
 
15
- import { type ReqRespInterface, ReqRespSubProtocol } from '../reqresp/interface.js';
16
- import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
14
+ import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
15
+ import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
17
16
  import type { TxCollectionConfig } from './config.js';
17
+ import {
18
+ BatchTxRequesterCollector,
19
+ type MissingTxsCollector,
20
+ SendBatchRequestCollector,
21
+ } from './proposal_tx_collector.js';
18
22
  import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
19
- import type { TxCollectionSink } from './tx_collection_sink.js';
23
+ import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
20
24
  import type { TxSource } from './tx_source.js';
21
25
 
22
26
  export class FastTxCollection {
23
27
  // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
24
28
  protected requests: Set<FastCollectionRequest> = new Set();
29
+ private missingTxsCollector: MissingTxsCollector;
25
30
 
26
31
  constructor(
27
- private reqResp: Pick<ReqRespInterface, 'sendBatchRequest'>,
32
+ p2pService: BatchTxRequesterLibP2PService,
28
33
  private nodes: TxSource[],
29
34
  private txCollectionSink: TxCollectionSink,
30
35
  private config: TxCollectionConfig,
31
36
  private dateProvider: DateProvider = new DateProvider(),
32
37
  private log: Logger = createLogger('p2p:tx_collection_service'),
33
- ) {}
38
+ missingTxsCollector?: MissingTxsCollector,
39
+ ) {
40
+ const batchTxRequesterConfig = this.config as Partial<BatchTxRequesterConfig>;
41
+ const missingTxsCollectorType = this.config.txCollectionMissingTxsCollectorType;
42
+ this.missingTxsCollector =
43
+ missingTxsCollector ??
44
+ (missingTxsCollectorType === 'old'
45
+ ? new SendBatchRequestCollector(p2pService)
46
+ : new BatchTxRequesterCollector(p2pService, log, dateProvider, undefined, batchTxRequesterConfig));
47
+ }
34
48
 
35
49
  public async stop() {
36
50
  this.requests.forEach(request => request.promise.reject(new AbortError(`Stopped collection service`)));
@@ -63,7 +77,7 @@ export class FastTxCollection {
63
77
  // This promise is used to await for the collection to finish during the main collectFast method.
64
78
  // It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
65
79
  const promise = promiseWithResolvers<void>();
66
- setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
80
+ const timeoutTimer = setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
67
81
 
68
82
  const request: FastCollectionRequest = {
69
83
  ...input,
@@ -75,6 +89,7 @@ export class FastTxCollection {
75
89
  };
76
90
 
77
91
  const [duration] = await elapsed(() => this.collectFast(request, { ...opts }));
92
+ clearTimeout(timeoutTimer);
78
93
 
79
94
  this.log.verbose(
80
95
  `Collected ${request.foundTxs.size} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
@@ -220,6 +235,7 @@ export class FastTxCollection {
220
235
  method: 'fast-node-rpc',
221
236
  ...request.blockInfo,
222
237
  },
238
+ this.getAddContext(request),
223
239
  );
224
240
 
225
241
  // Clear from the active requests the txs we just requested
@@ -241,8 +257,6 @@ export class FastTxCollection {
241
257
  private async collectFastViaReqResp(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
242
258
  const timeoutMs = +request.deadline - this.dateProvider.now();
243
259
  const pinnedPeer = opts.pinnedPeer;
244
- const maxPeers = boundInclusive(Math.ceil(request.missingTxHashes.size / 2), 8, 32);
245
- const maxRetryAttempts = 5;
246
260
  const blockInfo = request.blockInfo;
247
261
  const slotNumber = blockInfo.slotNumber;
248
262
  if (timeoutMs < 100) {
@@ -261,19 +275,21 @@ export class FastTxCollection {
261
275
  try {
262
276
  await this.txCollectionSink.collect(
263
277
  async txHashes => {
264
- const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
265
- ReqRespSubProtocol.TX,
266
- chunkTxHashesRequest(txHashes),
267
- pinnedPeer,
268
- timeoutMs,
269
- maxPeers,
270
- maxRetryAttempts,
271
- );
272
-
273
- return txs.flat();
278
+ if (request.type === 'proposal') {
279
+ return await this.missingTxsCollector.collectTxs(txHashes, request.blockProposal, pinnedPeer, timeoutMs);
280
+ } else if (request.type === 'block') {
281
+ const blockTxsSource = {
282
+ txHashes: request.block.body.txEffects.map(e => e.txHash),
283
+ archive: request.block.archive.root,
284
+ };
285
+ return await this.missingTxsCollector.collectTxs(txHashes, blockTxsSource, pinnedPeer, timeoutMs);
286
+ } else {
287
+ throw new Error(`Unknown request type: ${(request as any).type}`);
288
+ }
274
289
  },
275
290
  Array.from(request.missingTxHashes).map(txHash => TxHash.fromString(txHash)),
276
291
  { description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
292
+ this.getAddContext(request),
277
293
  );
278
294
  } catch (err) {
279
295
  this.log.error(`Error sending fast reqresp request for txs`, err, {
@@ -283,6 +299,15 @@ export class FastTxCollection {
283
299
  }
284
300
  }
285
301
 
302
+ /** Returns the TxAddContext for the given request, used by the sink to add txs to the pool correctly. */
303
+ private getAddContext(request: FastCollectionRequest): TxAddContext {
304
+ if (request.type === 'proposal') {
305
+ return { type: 'proposal', blockHeader: request.blockProposal.blockHeader };
306
+ } else {
307
+ return { type: 'mined', block: request.block };
308
+ }
309
+ }
310
+
286
311
  /**
287
312
  * Handle txs by marking them as found for the requests that are waiting for them, and resolves the request if all its txs have been found.
288
313
  * Called internally and from the main tx collection manager whenever the tx pool emits a tx-added event.
@@ -0,0 +1,152 @@
1
+ import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { FifoMemoryQueue } from '@aztec/foundation/queue';
3
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
4
+
5
+ import type { FileStoreTxSource } from './file_store_tx_source.js';
6
+ import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
7
+
8
+ // Internal constants (not configurable by node operators)
9
+ const FILE_STORE_DOWNLOAD_CONCURRENCY = 5; // Max concurrent downloads
10
+
11
+ /**
12
+ * Collects txs from file stores as a fallback after P2P methods have been tried.
13
+ * Runs in parallel to slow/fast collection. The delay before starting file store
14
+ * collection is managed by the TxCollection orchestrator, not this class.
15
+ */
16
+ export class FileStoreTxCollection {
17
+ /** Map from tx hash to add context for txs queued for download. */
18
+ private pendingTxs = new Map<string, TxAddContext>();
19
+
20
+ /**
21
+ * Tracks tx hashes found elsewhere, even before startCollecting is called.
22
+ * Needed because the orchestrator delays startCollecting via a real sleep, but foundTxs
23
+ * may arrive during that delay — before the hashes are added to pendingTxs.
24
+ */
25
+ private foundTxHashes = new Set<string>();
26
+
27
+ /** Queue of tx hashes to be downloaded. */
28
+ private downloadQueue = new FifoMemoryQueue<TxHash>();
29
+
30
+ /** Worker promises for concurrent downloads. */
31
+ private workers: Promise<void>[] = [];
32
+
33
+ /** Whether the collection has been started. */
34
+ private started = false;
35
+
36
+ constructor(
37
+ private readonly fileStoreSources: FileStoreTxSource[],
38
+ private readonly txCollectionSink: TxCollectionSink,
39
+ private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
40
+ ) {}
41
+
42
+ /** Starts the file store collection workers. */
43
+ public start() {
44
+ if (this.fileStoreSources.length === 0) {
45
+ this.log.debug('No file store sources configured, skipping file store collection');
46
+ return;
47
+ }
48
+
49
+ this.started = true;
50
+ this.downloadQueue = new FifoMemoryQueue<TxHash>();
51
+
52
+ // Start concurrent download workers
53
+ for (let i = 0; i < FILE_STORE_DOWNLOAD_CONCURRENCY; i++) {
54
+ this.workers.push(this.downloadQueue.process(txHash => this.processDownload(txHash)));
55
+ }
56
+
57
+ this.log.info(`Started file store tx collection with ${this.fileStoreSources.length} sources`, {
58
+ sources: this.fileStoreSources.map(s => s.getInfo()),
59
+ concurrency: FILE_STORE_DOWNLOAD_CONCURRENCY,
60
+ });
61
+ }
62
+
63
+ /** Stops all collection activity. */
64
+ public async stop() {
65
+ if (!this.started) {
66
+ return;
67
+ }
68
+ this.started = false;
69
+ this.downloadQueue.end();
70
+ await Promise.all(this.workers);
71
+ this.workers = [];
72
+ this.pendingTxs.clear();
73
+ this.foundTxHashes.clear();
74
+ }
75
+
76
+ /** Remove the given tx hashes from pending. */
77
+ public stopCollecting(txHashes: TxHash[]) {
78
+ for (const txHash of txHashes) {
79
+ const hashStr = txHash.toString();
80
+ this.pendingTxs.delete(hashStr);
81
+ }
82
+ }
83
+
84
+ /** Clears all pending state. Items already in the download queue will still be processed but won't be re-queued. */
85
+ public clearPending() {
86
+ this.pendingTxs.clear();
87
+ this.foundTxHashes.clear();
88
+ }
89
+
90
+ /** Queue the given tx hashes for file store collection. */
91
+ public startCollecting(txHashes: TxHash[], context: TxAddContext) {
92
+ for (const txHash of txHashes) {
93
+ const hashStr = txHash.toString();
94
+ if (!this.pendingTxs.has(hashStr) && !this.foundTxHashes.has(hashStr)) {
95
+ this.pendingTxs.set(hashStr, context);
96
+ this.downloadQueue.put(txHash);
97
+ }
98
+ }
99
+ }
100
+
101
+ /** Stop tracking txs that were found elsewhere. */
102
+ public foundTxs(txs: Tx[]) {
103
+ for (const tx of txs) {
104
+ const hashStr = tx.getTxHash().toString();
105
+ this.pendingTxs.delete(hashStr);
106
+ this.foundTxHashes.add(hashStr);
107
+ }
108
+ }
109
+
110
+ /** Processes a single tx hash from the download queue. */
111
+ private async processDownload(txHash: TxHash) {
112
+ const hashStr = txHash.toString();
113
+ const context = this.pendingTxs.get(hashStr);
114
+
115
+ // Skip if already found by another method
116
+ if (!context) {
117
+ return;
118
+ }
119
+
120
+ await this.downloadTx(txHash, context);
121
+ this.pendingTxs.delete(hashStr);
122
+ }
123
+
124
+ /** Attempt to download a tx from file stores (round-robin). */
125
+ private async downloadTx(txHash: TxHash, context: TxAddContext) {
126
+ const startIndex = Math.floor(Math.random() * this.fileStoreSources.length);
127
+ for (let i = startIndex; i < startIndex + this.fileStoreSources.length; i++) {
128
+ const source = this.fileStoreSources[i % this.fileStoreSources.length];
129
+
130
+ try {
131
+ const result = await this.txCollectionSink.collect(
132
+ hashes => source.getTxsByHash(hashes),
133
+ [txHash],
134
+ {
135
+ description: `file-store ${source.getInfo()}`,
136
+ method: 'file-store',
137
+ fileStore: source.getInfo(),
138
+ },
139
+ context,
140
+ );
141
+
142
+ if (result.txs.length > 0) {
143
+ return;
144
+ }
145
+ } catch (err) {
146
+ this.log.trace(`Failed to download tx ${txHash} from ${source.getInfo()}`, { err });
147
+ }
148
+ }
149
+
150
+ this.log.trace(`Tx ${txHash} not found in any file store`);
151
+ }
152
+ }