@aztec/p2p 0.0.1-commit.993d52e → 0.0.1-commit.9a89641

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 (473) hide show
  1. package/README.md +130 -3
  2. package/dest/bootstrap/bootstrap.d.ts +1 -1
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  4. package/dest/bootstrap/bootstrap.js +22 -6
  5. package/dest/client/factory.d.ts +5 -4
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +39 -16
  8. package/dest/client/interface.d.ts +52 -12
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +34 -19
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +120 -73
  13. package/dest/config.d.ts +160 -110
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +139 -49
  16. package/dest/errors/p2p-service.error.d.ts +9 -0
  17. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  18. package/dest/errors/p2p-service.error.js +10 -0
  19. package/dest/errors/reqresp.error.d.ts +9 -16
  20. package/dest/errors/reqresp.error.d.ts.map +1 -1
  21. package/dest/errors/reqresp.error.js +10 -17
  22. package/dest/index.d.ts +1 -2
  23. package/dest/index.d.ts.map +1 -1
  24. package/dest/index.js +0 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +101 -59
  26. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool.js +274 -197
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +224 -65
  31. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/mocks.js +6 -4
  34. package/dest/mem_pools/index.d.ts +1 -2
  35. package/dest/mem_pools/index.d.ts.map +1 -1
  36. package/dest/mem_pools/instrumentation.d.ts +12 -5
  37. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  38. package/dest/mem_pools/instrumentation.js +38 -17
  39. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
  40. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
  41. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
  42. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -3
  43. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +6 -6
  45. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  46. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -4
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
  49. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +3 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
  54. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  55. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  56. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +1 -1
  58. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +3 -4
  60. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +1 -1
  61. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +6 -7
  63. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +6 -5
  66. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +41 -9
  67. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  68. package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
  69. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +17 -8
  70. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  71. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +20 -7
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +15 -1
  73. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +55 -41
  75. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -4
  76. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  77. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +23 -6
  78. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +17 -3
  79. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  80. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +234 -120
  81. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
  82. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  83. package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
  84. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
  85. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  86. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  87. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +11 -5
  88. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
  90. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +11 -5
  91. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
  93. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +35 -10
  94. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/proposal_validator/proposal_validator.js +128 -56
  96. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  97. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
  99. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  100. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  101. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  102. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  103. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  104. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  105. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  106. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  107. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  108. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  109. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  110. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  111. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  112. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  113. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  114. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  115. package/dest/msg_validators/tx_validator/factory.d.ts +25 -7
  116. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  117. package/dest/msg_validators/tx_validator/factory.js +55 -16
  118. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  119. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  120. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  121. package/dest/msg_validators/tx_validator/gas_validator.d.ts +53 -7
  122. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  123. package/dest/msg_validators/tx_validator/gas_validator.js +88 -41
  124. package/dest/msg_validators/tx_validator/index.d.ts +4 -1
  125. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  126. package/dest/msg_validators/tx_validator/index.js +3 -0
  127. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  128. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  130. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  131. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  132. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  133. package/dest/msg_validators/tx_validator/timestamp_validator.js +1 -1
  134. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  135. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  136. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  137. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  138. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  139. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  140. package/dest/services/data_store.d.ts +1 -1
  141. package/dest/services/data_store.d.ts.map +1 -1
  142. package/dest/services/data_store.js +5 -5
  143. package/dest/services/discv5/discV5_service.d.ts +13 -2
  144. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  145. package/dest/services/discv5/discV5_service.js +119 -23
  146. package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
  147. package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
  148. package/dest/services/discv5/persisted_enr_store.js +145 -0
  149. package/dest/services/dummy_service.d.ts +15 -15
  150. package/dest/services/dummy_service.d.ts.map +1 -1
  151. package/dest/services/dummy_service.js +15 -16
  152. package/dest/services/encoding.d.ts +23 -6
  153. package/dest/services/encoding.d.ts.map +1 -1
  154. package/dest/services/encoding.js +32 -16
  155. package/dest/services/gossipsub/topic_score_params.d.ts +6 -12
  156. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  157. package/dest/services/gossipsub/topic_score_params.js +4 -14
  158. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  159. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  160. package/dest/services/libp2p/instrumentation.js +14 -0
  161. package/dest/services/libp2p/libp2p_service.d.ts +46 -47
  162. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  163. package/dest/services/libp2p/libp2p_service.js +460 -320
  164. package/dest/services/peer-manager/metrics.d.ts +3 -1
  165. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  166. package/dest/services/peer-manager/metrics.js +6 -0
  167. package/dest/services/peer-manager/peer_manager.d.ts +20 -3
  168. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  169. package/dest/services/peer-manager/peer_manager.js +83 -26
  170. package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
  171. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  172. package/dest/services/peer-manager/peer_scoring.js +102 -13
  173. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -8
  174. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  175. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +94 -122
  176. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +10 -6
  177. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  178. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  179. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  180. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  181. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  182. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  183. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  184. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  185. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  186. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  187. package/dest/services/reqresp/config.d.ts +15 -3
  188. package/dest/services/reqresp/config.d.ts.map +1 -1
  189. package/dest/services/reqresp/config.js +11 -0
  190. package/dest/services/reqresp/interface.d.ts +16 -18
  191. package/dest/services/reqresp/interface.d.ts.map +1 -1
  192. package/dest/services/reqresp/interface.js +10 -20
  193. package/dest/services/reqresp/metrics.d.ts +1 -1
  194. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  195. package/dest/services/reqresp/metrics.js +0 -1
  196. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  197. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  198. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  199. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  200. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  201. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
  202. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
  203. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  204. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
  205. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  206. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  207. package/dest/services/reqresp/protocols/index.js +0 -1
  208. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  209. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  210. package/dest/services/reqresp/protocols/tx.js +1 -3
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  212. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  213. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  214. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  215. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  216. package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
  217. package/dest/services/reqresp/reqresp.d.ts +7 -29
  218. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  219. package/dest/services/reqresp/reqresp.js +75 -216
  220. package/dest/services/service.d.ts +29 -12
  221. package/dest/services/service.d.ts.map +1 -1
  222. package/dest/services/tx_collection/config.d.ts +2 -23
  223. package/dest/services/tx_collection/config.d.ts.map +1 -1
  224. package/dest/services/tx_collection/config.js +2 -55
  225. package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
  226. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  227. package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
  228. package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
  229. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  230. package/dest/services/tx_collection/file_store_tx_source.js +39 -29
  231. package/dest/services/tx_collection/index.d.ts +2 -3
  232. package/dest/services/tx_collection/index.d.ts.map +1 -1
  233. package/dest/services/tx_collection/index.js +0 -1
  234. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  235. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  236. package/dest/services/tx_collection/instrumentation.js +0 -2
  237. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  238. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  239. package/dest/services/tx_collection/request_tracker.js +84 -0
  240. package/dest/services/tx_collection/tx_collection.d.ts +36 -55
  241. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  242. package/dest/services/tx_collection/tx_collection.js +275 -119
  243. package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
  244. package/dest/services/tx_collection/tx_collection_sink.js +2 -2
  245. package/dest/services/tx_collection/tx_source.d.ts +6 -5
  246. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  247. package/dest/services/tx_collection/tx_source.js +13 -8
  248. package/dest/services/tx_file_store/tx_file_store.d.ts +1 -3
  249. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  250. package/dest/services/tx_file_store/tx_file_store.js +4 -14
  251. package/dest/services/tx_provider.d.ts +3 -1
  252. package/dest/services/tx_provider.d.ts.map +1 -1
  253. package/dest/services/tx_provider.js +3 -0
  254. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  255. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  256. package/dest/test-helpers/make-test-p2p-clients.js +5 -2
  257. package/dest/test-helpers/mock-pubsub.d.ts +23 -9
  258. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  259. package/dest/test-helpers/mock-pubsub.js +44 -44
  260. package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
  261. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  262. package/dest/test-helpers/reqresp-nodes.js +16 -18
  263. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  264. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  265. package/dest/test-helpers/test_tx_provider.js +3 -0
  266. package/dest/test-helpers/testbench-utils.d.ts +15 -14
  267. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  268. package/dest/test-helpers/testbench-utils.js +51 -16
  269. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  270. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  271. package/dest/testbench/p2p_client_testbench_worker.js +104 -41
  272. package/dest/testbench/worker_client_manager.d.ts +12 -6
  273. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  274. package/dest/testbench/worker_client_manager.js +57 -11
  275. package/dest/util.d.ts +12 -7
  276. package/dest/util.d.ts.map +1 -1
  277. package/dest/util.js +35 -14
  278. package/dest/versioning.d.ts +3 -6
  279. package/dest/versioning.d.ts.map +1 -1
  280. package/dest/versioning.js +3 -24
  281. package/package.json +15 -16
  282. package/src/bootstrap/bootstrap.ts +17 -3
  283. package/src/client/factory.ts +62 -9
  284. package/src/client/interface.ts +48 -18
  285. package/src/client/p2p_client.ts +140 -106
  286. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  287. package/src/config.ts +241 -57
  288. package/src/errors/p2p-service.error.ts +11 -0
  289. package/src/errors/reqresp.error.ts +13 -19
  290. package/src/index.ts +0 -1
  291. package/src/mem_pools/attestation_pool/attestation_pool.ts +329 -243
  292. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +244 -69
  293. package/src/mem_pools/attestation_pool/mocks.ts +13 -8
  294. package/src/mem_pools/index.ts +0 -3
  295. package/src/mem_pools/instrumentation.ts +27 -17
  296. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
  297. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +7 -7
  298. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +4 -5
  299. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -2
  300. package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
  301. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -0
  302. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +1 -3
  303. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -7
  304. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +5 -6
  305. package/src/mem_pools/tx_pool_v2/interfaces.ts +40 -8
  306. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +35 -13
  307. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +62 -41
  308. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +36 -7
  309. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +260 -124
  310. package/src/msg_validators/attestation_validator/README.md +49 -0
  311. package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
  312. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
  313. package/src/msg_validators/proposal_validator/README.md +123 -0
  314. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
  315. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
  316. package/src/msg_validators/proposal_validator/proposal_validator.ts +150 -58
  317. package/src/msg_validators/tx_validator/README.md +17 -3
  318. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
  319. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  320. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  321. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  322. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  323. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  324. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  325. package/src/msg_validators/tx_validator/factory.ts +66 -9
  326. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  327. package/src/msg_validators/tx_validator/gas_validator.ts +117 -39
  328. package/src/msg_validators/tx_validator/index.ts +3 -0
  329. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  330. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  331. package/src/msg_validators/tx_validator/timestamp_validator.ts +1 -1
  332. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  333. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  334. package/src/services/data_store.ts +5 -13
  335. package/src/services/discv5/discV5_service.ts +126 -14
  336. package/src/services/discv5/persisted_enr_store.ts +158 -0
  337. package/src/services/dummy_service.ts +20 -39
  338. package/src/services/encoding.ts +35 -19
  339. package/src/services/gossipsub/README.md +33 -11
  340. package/src/services/gossipsub/topic_score_params.ts +9 -18
  341. package/src/services/libp2p/instrumentation.ts +14 -0
  342. package/src/services/libp2p/libp2p_service.ts +508 -358
  343. package/src/services/peer-manager/metrics.ts +7 -0
  344. package/src/services/peer-manager/peer_manager.ts +91 -25
  345. package/src/services/peer-manager/peer_scoring.ts +102 -8
  346. package/src/services/reqresp/README.md +194 -0
  347. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  348. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +91 -137
  349. package/src/services/reqresp/batch-tx-requester/interface.ts +13 -5
  350. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  351. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  352. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  353. package/src/services/reqresp/config.ts +19 -2
  354. package/src/services/reqresp/interface.ts +21 -47
  355. package/src/services/reqresp/metrics.ts +0 -1
  356. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  357. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
  358. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
  359. package/src/services/reqresp/protocols/index.ts +0 -1
  360. package/src/services/reqresp/protocols/tx.ts +1 -3
  361. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  362. package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
  363. package/src/services/reqresp/reqresp.ts +87 -260
  364. package/src/services/service.ts +35 -28
  365. package/src/services/tx_collection/config.ts +3 -80
  366. package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
  367. package/src/services/tx_collection/file_store_tx_source.ts +43 -31
  368. package/src/services/tx_collection/index.ts +1 -6
  369. package/src/services/tx_collection/instrumentation.ts +1 -7
  370. package/src/services/tx_collection/request_tracker.ts +127 -0
  371. package/src/services/tx_collection/tx_collection.ts +331 -176
  372. package/src/services/tx_collection/tx_collection_sink.ts +2 -2
  373. package/src/services/tx_collection/tx_source.ts +10 -8
  374. package/src/services/tx_file_store/tx_file_store.ts +5 -17
  375. package/src/services/tx_provider.ts +5 -0
  376. package/src/test-helpers/make-test-p2p-clients.ts +4 -1
  377. package/src/test-helpers/mock-pubsub.ts +46 -60
  378. package/src/test-helpers/reqresp-nodes.ts +13 -23
  379. package/src/test-helpers/test_tx_provider.ts +5 -0
  380. package/src/test-helpers/testbench-utils.ts +64 -28
  381. package/src/testbench/p2p_client_testbench_worker.ts +111 -57
  382. package/src/testbench/worker_client_manager.ts +72 -25
  383. package/src/util.ts +33 -18
  384. package/src/versioning.ts +3 -33
  385. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  386. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  387. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -304
  388. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  389. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  390. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  391. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  392. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  393. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  394. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  395. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  396. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  397. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  398. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  399. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  400. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  401. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  402. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  403. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  404. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  405. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  406. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  407. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  408. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  409. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  410. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  411. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  412. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  413. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  414. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  415. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  416. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  417. package/dest/mem_pools/tx_pool/index.js +0 -2
  418. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  419. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  420. package/dest/mem_pools/tx_pool/priority.js +0 -15
  421. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  422. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  423. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  424. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  425. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  426. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  427. package/dest/msg_validators/clock_tolerance.d.ts +0 -21
  428. package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
  429. package/dest/msg_validators/clock_tolerance.js +0 -37
  430. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -24
  431. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  432. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -378
  433. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  434. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  435. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  436. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  437. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  438. package/dest/services/reqresp/protocols/block.js +0 -32
  439. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -54
  440. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  441. package/dest/services/tx_collection/fast_tx_collection.js +0 -327
  442. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  443. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  444. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  445. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -49
  446. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  447. package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
  448. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
  449. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  450. package/dest/services/tx_collection/slow_tx_collection.js +0 -211
  451. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -345
  452. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  453. package/src/mem_pools/tx_pool/README.md +0 -270
  454. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  455. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  456. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  457. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  458. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  459. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  460. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  461. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  462. package/src/mem_pools/tx_pool/index.ts +0 -2
  463. package/src/mem_pools/tx_pool/priority.ts +0 -20
  464. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  465. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  466. package/src/msg_validators/clock_tolerance.ts +0 -51
  467. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -373
  468. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  469. package/src/services/reqresp/protocols/block.ts +0 -37
  470. package/src/services/tx_collection/fast_tx_collection.ts +0 -387
  471. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
  472. package/src/services/tx_collection/proposal_tx_collector.ts +0 -113
  473. package/src/services/tx_collection/slow_tx_collection.ts +0 -266
@@ -170,6 +170,37 @@ class BlockTxsResponse {
170
170
 
171
171
  The `BitVector` is a compact representation where each bit corresponds to a transaction index in the block proposal. This allows efficient capability advertisement without repeating full hashes.
172
172
 
173
+ ## Cancellation
174
+
175
+ All cancellation is managed by a single `RequestTracker` instance, shared across the entire collection
176
+ flow. The `RequestTracker` owns the deadline, tracks which txs are still missing, and exposes a
177
+ `cancellationToken` promise that resolves when the request should stop (deadline hit, all txs fetched,
178
+ or external `cancel()` call).
179
+
180
+ Cancellation propagates from the deepest stack level upward:
181
+
182
+ ```
183
+ RequestTracker.finish()
184
+ ├── resolves cancellationToken promise
185
+ │
186
+ ├── BatchTxRequester workers (deepest)
187
+ │ ├── shouldStop() checks requestTracker.cancelled → exit loop
188
+ │ ├── sleepClampedToDeadline races sleep vs cancellationToken → wakes
189
+ │ └── semaphore.acquire races vs cancellationToken → wakes
190
+ │ │
191
+ │ ▼ workers settle → txQueue.end() → generator returns
192
+ │
193
+ ├── Node collection loops
194
+ │ ├── notFinished() checks requestTracker.cancelled → exit loop
195
+ │ └── inter-retry sleep races vs cancellationToken → wakes
196
+ │ │
197
+ │ ▼ all node loops settle
198
+ │
199
+ └── collectFast (outermost)
200
+ awaits Promise.allSettled([reqresp, nodes]) → settles after inner tasks
201
+ finally: requestTracker.cancel() (idempotent), cleanup
202
+ ```
203
+
173
204
  ## Key Files
174
205
 
175
206
  | File | Description |
@@ -179,15 +210,16 @@ The `BitVector` is a compact representation where each bit corresponds to a tran
179
210
  | `peer_collection.ts` | Manages peer classification (dumb/smart/bad) and rate limiting |
180
211
  | `interface.ts` | Type definitions for dependencies |
181
212
  | `../protocols/block_txs/` | Wire protocol definitions (`BlockTxsRequest`, `BlockTxsResponse`, `BitVector`) |
213
+ | `../../tx_collection/request_tracker.ts` | Centralized deadline, missing tx tracking, and cancellation signal |
182
214
 
183
215
  ## Stopping Conditions
184
216
 
185
- The `BatchTxRequester` stops when any of these conditions are met:
217
+ The `BatchTxRequester` stops when any of these conditions are met, all managed by the `RequestTracker`:
186
218
 
187
- 1. **All transactions fetched** - Success!
188
- 2. **Deadline exceeded** - Timeout configured by caller
189
- 3. **Abort signal** - External cancellation
190
- 4. **No transactions to fetch** - Nothing was missing
219
+ 1. **All transactions fetched** - `markFetched()` removes the last missing tx, triggering `finish()`
220
+ 2. **Deadline exceeded** - `setTimeout` in `RequestTracker` fires, triggering `finish()`
221
+ 3. **External cancellation** - `RequestTracker.cancel()` called (e.g., from `stop()`, `stopCollectingForBlocksUpTo`)
222
+ 4. **No transactions to fetch** - Empty hash set at construction, `RequestTracker` finishes immediately
191
223
 
192
224
  ## Configuration
193
225
 
@@ -228,11 +260,15 @@ Request to peer fails
228
260
  ## Usage Example
229
261
 
230
262
  ```typescript
263
+ const requestTracker = RequestTracker.create(
264
+ missingTxHashes, // TxHash[] - what we need
265
+ new Date(Date.now() + 5_000), // deadline
266
+ );
267
+
231
268
  const requester = new BatchTxRequester(
232
- missingTxHashes, // TxHash[] - what we need
269
+ requestTracker, // IRequestTracker - tracks missing txs, deadline, and cancellation
233
270
  blockTxsSource, // BlockTxsSource - the proposal or block we need txs for
234
271
  pinnedPeer, // PeerId | undefined - peer expected to have the txs
235
- timeoutMs, // number - how long to try
236
272
  p2pService, // BatchTxRequesterLibP2PService
237
273
  );
238
274
 
@@ -273,6 +309,8 @@ const txs = await BatchTxRequester.collectAllTxs(requester.run());
273
309
  │ 1. Try RPC nodes first (fast) │ │ Periodic polling of RPC nodes │
274
310
  │ 2. Fall back to BatchTxRequester │ │ and peers for missing txs │
275
311
  │ │ │ │
312
+ │ Creates RequestTracker per │ │ │
313
+ │ request with deadline │ │ │
276
314
  └───────────────────┬───────────────┘ └─────────────────────────────────────┘
277
315
  │
278
316
  │ For 'proposal' and 'block' requests
@@ -281,6 +319,7 @@ const txs = await BatchTxRequester.collectAllTxs(requester.run());
281
319
  │ BatchTxRequester │
282
320
  │ │
283
321
  │ Aggressive parallel fetching from multiple peers │
322
+ │ Shares RequestTracker with FastTxCollection for unified cancellation │
284
323
  │ Uses BLOCK_TXS sub-protocol for efficient batching │
285
324
  └───────────────────┬─────────────────────────────────────────────────────────┘
286
325
  │
@@ -1,16 +1,15 @@
1
1
  import { chunkWrapAround } from '@aztec/foundation/collection';
2
- import { TimeoutError } from '@aztec/foundation/error';
3
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
3
  import { FifoMemoryQueue, type ISemaphore, Semaphore } from '@aztec/foundation/queue';
5
4
  import { sleep } from '@aztec/foundation/sleep';
6
- import { DateProvider, executeTimeout } from '@aztec/foundation/timer';
5
+ import { DateProvider } from '@aztec/foundation/timer';
7
6
  import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
8
- import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
7
+ import { Tx, TxArray, TxHash, type TxValidator } from '@aztec/stdlib/tx';
9
8
 
10
9
  import type { PeerId } from '@libp2p/interface';
11
- import { peerIdFromString } from '@libp2p/peer-id';
10
+ import { strict as assert } from 'assert';
12
11
 
13
- import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
12
+ import type { IRequestTracker } from '../../tx_collection/request_tracker.js';
14
13
  import { ReqRespSubProtocol } from '.././interface.js';
15
14
  import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
16
15
  import { ReqRespStatus } from '.././status.js';
@@ -23,7 +22,7 @@ import {
23
22
  import type { BatchTxRequesterLibP2PService, BatchTxRequesterOptions, ITxMetadataCollection } from './interface.js';
24
23
  import { MissingTxMetadataCollection } from './missing_txs.js';
25
24
  import { type IPeerCollection, PeerCollection } from './peer_collection.js';
26
- import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_validator.js';
25
+ import { createBatchRequestTxValidator } from './tx_validator.js';
27
26
 
28
27
  /*
29
28
  * Tries to fetch all missing transaction until deadline is hit.
@@ -43,39 +42,35 @@ import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_val
43
42
  * - Is the peer which was unable to send us successful response N times in a row
44
43
  * */
45
44
  export class BatchTxRequester {
45
+ private readonly requestTracker: IRequestTracker;
46
46
  private readonly blockTxsSource: BlockTxsSource;
47
47
  private readonly pinnedPeer: PeerId | undefined;
48
- private readonly timeoutMs: number;
49
48
  private readonly p2pService: BatchTxRequesterLibP2PService;
50
49
  private readonly logger: Logger;
51
- private readonly dateProvider: DateProvider;
52
50
  private readonly opts: BatchTxRequesterOptions;
53
51
  private readonly peers: IPeerCollection;
54
52
  private readonly txsMetadata: ITxMetadataCollection;
55
- private readonly deadline: number;
56
53
  private readonly smartRequesterSemaphore: ISemaphore;
57
54
  private readonly txQueue: FifoMemoryQueue<Tx>;
58
- private readonly txValidator: IBatchRequestTxValidator;
55
+ private readonly txValidator: TxValidator;
59
56
  private readonly smartParallelWorkerCount: number;
60
57
  private readonly dumbParallelWorkerCount: number;
61
58
  private readonly txBatchSize: number;
62
59
 
63
60
  constructor(
64
- missingTxsTracker: IMissingTxsTracker,
61
+ requestTracker: IRequestTracker,
65
62
  blockTxsSource: BlockTxsSource,
66
63
  pinnedPeer: PeerId | undefined,
67
- timeoutMs: number,
68
64
  p2pService: BatchTxRequesterLibP2PService,
69
65
  logger?: Logger,
70
66
  dateProvider?: DateProvider,
71
67
  opts?: BatchTxRequesterOptions,
72
68
  ) {
69
+ this.requestTracker = requestTracker;
73
70
  this.blockTxsSource = blockTxsSource;
74
71
  this.pinnedPeer = pinnedPeer;
75
- this.timeoutMs = timeoutMs;
76
72
  this.p2pService = p2pService;
77
73
  this.logger = logger ?? createLogger('p2p:reqresp_batch');
78
- this.dateProvider = dateProvider ?? new DateProvider();
79
74
  this.opts = opts ?? {};
80
75
 
81
76
  this.smartParallelWorkerCount =
@@ -83,65 +78,53 @@ export class BatchTxRequester {
83
78
  this.dumbParallelWorkerCount =
84
79
  this.opts.dumbParallelWorkerCount ?? DEFAULT_BATCH_TX_REQUESTER_DUMB_PARALLEL_WORKER_COUNT;
85
80
  this.txBatchSize = this.opts.txBatchSize ?? DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE;
86
- this.deadline = this.dateProvider.now() + this.timeoutMs;
87
81
  this.txQueue = new FifoMemoryQueue(this.logger);
88
- this.txValidator = this.opts.txValidator ?? new BatchRequestTxValidator(this.p2pService.txValidatorConfig);
82
+ this.txValidator = this.opts.txValidator ?? createBatchRequestTxValidator(this.p2pService.txValidatorConfig);
89
83
 
90
84
  if (this.opts.peerCollection) {
91
85
  this.peers = this.opts.peerCollection;
92
86
  } else {
93
- const initialPeers = this.p2pService.connectionSampler.getPeerListSortedByConnectionCountAsc();
94
87
  const badPeerThreshold = this.opts.badPeerThreshold ?? DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD;
95
88
  this.peers = new PeerCollection(
96
- initialPeers,
89
+ this.p2pService.connectionSampler,
97
90
  this.pinnedPeer,
98
- this.dateProvider,
91
+ dateProvider ?? new DateProvider(),
99
92
  badPeerThreshold,
100
93
  this.p2pService.peerScoring,
101
94
  );
102
95
  }
103
- this.txsMetadata = new MissingTxMetadataCollection(missingTxsTracker, this.txBatchSize);
96
+ this.txsMetadata = new MissingTxMetadataCollection(requestTracker, this.txBatchSize);
104
97
  this.smartRequesterSemaphore = this.opts.semaphore ?? new Semaphore(0);
105
98
  }
106
99
 
107
100
  /*
108
- * Fetches all missing transactions and yields them one by one
101
+ * Fetches all missing transactions and yields them one by one
109
102
  * */
110
103
  public async *run(): AsyncGenerator<Tx, Tx | undefined, unknown> {
111
- // Our timeout is represented in milliseconds but queue expects seconds
112
- // We also want to make sure we wait at least 1 second in case of very low timeouts
113
- const timeoutQueueAfter = Math.max(Math.ceil(this.timeoutMs / 1_000), 1);
114
104
  try {
115
105
  if (this.txsMetadata.getMissingTxHashes().size === 0) {
116
106
  return undefined;
117
107
  }
118
108
 
119
- // Start workers in background
120
- const workersPromise = executeTimeout(
121
- () => Promise.allSettled([this.smartRequester(), this.dumbRequester(), this.pinnedPeerRequester()]),
122
- this.timeoutMs,
123
- ).finally(() => {
109
+ // Start workers in background. Workers stop themselves via requestTracker.checkCancelled().
110
+ const workersPromise = Promise.allSettled([
111
+ this.smartRequester(),
112
+ this.dumbRequester(),
113
+ this.pinnedPeerRequester(),
114
+ ]).finally(() => {
124
115
  this.txQueue.end();
125
116
  });
126
117
 
118
+ // Yield txs as workers put them on the queue. The queue's end() drains remaining items
119
+ // before returning null, so we don't lose any txs.
127
120
  while (true) {
128
- const tx = await this.txQueue.get(timeoutQueueAfter);
121
+ const tx = await this.txQueue.get();
129
122
 
130
- // null indicates that the queue has ended
131
123
  if (tx === null) {
132
124
  break;
133
125
  }
134
126
 
135
127
  yield tx;
136
-
137
- if (this.shouldStop()) {
138
- // Drain queue before ending
139
- let remaining;
140
- while ((remaining = this.txQueue.getImmediate()) !== undefined) {
141
- yield remaining;
142
- }
143
- break;
144
- }
145
128
  }
146
129
 
147
130
  this.unlockSmartRequesterSemaphores();
@@ -227,7 +210,6 @@ export class BatchTxRequester {
227
210
  * Starts dumb worker loops
228
211
  * */
229
212
  private async dumbRequester() {
230
- const nextPeerIndex = this.makeRoundRobinIndexer();
231
213
  const nextBatchIndex = this.makeRoundRobinIndexer();
232
214
 
233
215
  // Chunk missing tx hashes into batches of txBatchSize, wrapping around to ensure no peer gets less than txBatchSize
@@ -263,15 +245,9 @@ export class BatchTxRequester {
263
245
  return { blockRequest, txs };
264
246
  };
265
247
 
266
- const nextPeer = () => {
267
- const peers = this.peers.getDumbPeersToQuery();
268
- const idx = nextPeerIndex(() => peers.length);
269
- return idx === undefined ? undefined : peerIdFromString(peers[idx]);
270
- };
271
-
272
- const workerCount = Math.min(this.dumbParallelWorkerCount, this.peers.getAllPeers().size);
248
+ const workerCount = this.dumbParallelWorkerCount;
273
249
  const workers = Array.from({ length: workerCount }, (_, index) =>
274
- this.dumbWorkerLoop(nextPeer, makeRequest, index + 1),
250
+ this.dumbWorkerLoop(this.peers.nextDumbPeerToQuery.bind(this.peers), makeRequest, index + 1),
275
251
  );
276
252
 
277
253
  await Promise.allSettled(workers);
@@ -332,14 +308,6 @@ export class BatchTxRequester {
332
308
  * Starts smart worker loops
333
309
  * */
334
310
  private async smartRequester() {
335
- const nextPeerIndex = this.makeRoundRobinIndexer();
336
-
337
- const nextPeer = () => {
338
- const peers = this.peers.getSmartPeersToQuery();
339
- const idx = nextPeerIndex(() => peers.length);
340
- return idx === undefined ? undefined : peerIdFromString(peers[idx]);
341
- };
342
-
343
311
  const makeRequest = (pid: PeerId) => {
344
312
  const txs = this.txsMetadata.getTxsToRequestFromThePeer(pid);
345
313
  const blockRequest = BlockTxsRequest.fromTxsSourceAndMissingTxs(this.blockTxsSource, txs);
@@ -350,9 +318,8 @@ export class BatchTxRequester {
350
318
  return { blockRequest, txs };
351
319
  };
352
320
 
353
- const workers = Array.from(
354
- { length: Math.min(this.smartParallelWorkerCount, this.peers.getAllPeers().size) },
355
- (_, index) => this.smartWorkerLoop(nextPeer, makeRequest, index + 1),
321
+ const workers = Array.from({ length: this.smartParallelWorkerCount }, (_, index) =>
322
+ this.smartWorkerLoop(this.peers.nextSmartPeerToQuery.bind(this.peers), makeRequest, index + 1),
356
323
  );
357
324
 
358
325
  await Promise.allSettled(workers);
@@ -378,7 +345,10 @@ export class BatchTxRequester {
378
345
  ) {
379
346
  try {
380
347
  this.logger.trace(`Smart worker ${workerIndex} started`);
381
- await executeTimeout((_: AbortSignal) => this.smartRequesterSemaphore.acquire(), this.timeoutMs);
348
+ await Promise.race([this.smartRequesterSemaphore.acquire(), this.requestTracker.cancellationToken]);
349
+ if (this.requestTracker.checkCancelled()) {
350
+ return;
351
+ }
382
352
  this.logger.trace(`Smart worker ${workerIndex} acquired semaphore`);
383
353
 
384
354
  while (!this.shouldStop()) {
@@ -387,30 +357,25 @@ export class BatchTxRequester {
387
357
  if (weRanOutOfPeersToQuery) {
388
358
  this.logger.debug(`Worker loop smart: No more peers to query`);
389
359
 
390
- // If there are no more dumb peers to query then none of our peers can become smart,
391
- // thus we can simply exit this worker
392
- const noMoreDumbPeersToQuery = this.peers.getDumbPeersToQuery().length === 0;
393
- if (noMoreDumbPeersToQuery) {
394
- // These might be either smart peers that will get unblocked after _some time_
395
- const nextSmartPeerDelay = this.peers.getNextSmartPeerAvailabilityDelayMs();
396
- const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
397
- if (thereAreSomeRateLimitedSmartPeers) {
398
- await this.sleepClampedToDeadline(nextSmartPeerDelay);
399
- continue;
400
- }
401
-
402
- this.logger.debug(`Worker loop smart: No more smart peers to query killing ${workerIndex}`);
403
- break;
360
+ // If we have rate limited peers wait for them.
361
+ const nextSmartPeerDelay = this.peers.getNextSmartPeerAvailabilityDelayMs();
362
+ const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
363
+ if (thereAreSomeRateLimitedSmartPeers) {
364
+ await this.sleepClampedToDeadline(nextSmartPeerDelay);
365
+ continue;
404
366
  }
405
367
 
406
- // Otherwise there are still some dumb peers that could become smart.
407
368
  // We end up here when all known smart peers became temporarily unavailable via combination of
408
369
  // (bad, in-flight, or rate-limited) or in some weird scenario all current smart peers turn bad which is permanent
409
- // but dumb peers still exist that could become smart.
370
+ // but there are dumb peers that could be promoted
371
+ // or new peer can join as dumb and be promoted later
410
372
  //
411
373
  // When a dumb peer responds with valid txIndices, it gets
412
374
  // promoted to smart and releases the semaphore, waking this worker.
413
- await executeTimeout((_: AbortSignal) => this.smartRequesterSemaphore.acquire(), this.timeoutMs);
375
+ await Promise.race([this.smartRequesterSemaphore.acquire(), this.requestTracker.cancellationToken]);
376
+ if (this.requestTracker.checkCancelled()) {
377
+ break;
378
+ }
414
379
  this.logger.debug(`Worker loop smart: acquired next smart peer`);
415
380
  continue;
416
381
  }
@@ -437,11 +402,7 @@ export class BatchTxRequester {
437
402
  });
438
403
  }
439
404
  } catch (err: any) {
440
- if (err instanceof TimeoutError) {
441
- this.logger.debug(`Smart worker ${workerIndex} timed out waiting for semaphore`);
442
- } else {
443
- this.logger.error(`Smart worker ${workerIndex} encountered an error: ${err}`);
444
- }
405
+ this.logger.error(`Smart worker ${workerIndex} encountered an error: ${err}`);
445
406
  } finally {
446
407
  this.logger.debug(`Smart worker ${workerIndex} finished`);
447
408
  }
@@ -468,6 +429,15 @@ export class BatchTxRequester {
468
429
  }
469
430
 
470
431
  const blockResponse = BlockTxsResponse.fromBuffer(response.data);
432
+
433
+ // Validate response. Peers will be penalised by the validator if they send invalid response.
434
+ const isValid = await this.p2pService.validateRequestedBlockTxsConsistency(request, blockResponse, peerId);
435
+ if (!isValid) {
436
+ this.logger.debug(`Peer ${peerId.toString()} sent invalid response`);
437
+ this.handleFailResponseFromPeer(peerId, ReqRespStatus.INTERNAL_ERROR);
438
+ return;
439
+ }
440
+
471
441
  await this.handleSuccessResponseFromPeer(peerId, blockResponse);
472
442
  } catch (err: any) {
473
443
  this.logger.error(`Failed to get valid response from peer ${peerId.toString()}: ${err.message}`, {
@@ -485,18 +455,24 @@ export class BatchTxRequester {
485
455
  * Handles failed response form the peer
486
456
  * There are 3 scenarios
487
457
  * - RATE_LIMIT_EXCEEDED: We mark this and don't query this peer again for some_time
458
+ * - INTERNAL_ERROR: We use this to cover cases where the request-response consistency validation fails.
488
459
  * - FAILURE and UNKNOWN: We penalise this, if peer has been penalised this way N times they are not queried again
489
460
  * this implies we will query these peers couple of more times and give them a chance to "redeem" themselves before completely ignoring them
490
461
  */
491
462
  private handleFailResponseFromPeer(peerId: PeerId, responseStatus: ReqRespStatus) {
492
- //TODO: Should we ban these peers?
493
- if (responseStatus === ReqRespStatus.FAILURE || responseStatus === ReqRespStatus.UNKNOWN) {
494
- this.peers.penalisePeer(peerId, PeerErrorSeverity.HighToleranceError);
495
- return;
496
- }
497
-
498
- if (responseStatus === ReqRespStatus.RATE_LIMIT_EXCEEDED) {
499
- this.peers.markPeerRateLimitExceeded(peerId);
463
+ switch (responseStatus) {
464
+ case ReqRespStatus.RATE_LIMIT_EXCEEDED:
465
+ this.peers.markPeerRateLimitExceeded(peerId);
466
+ return;
467
+ case ReqRespStatus.INTERNAL_ERROR:
468
+ this.peers.markPeerDumb(peerId);
469
+ this.txsMetadata.clearPeerData(peerId);
470
+ return;
471
+ default: // includes FAILURE, UNKNOWN
472
+ this.peers.penalisePeer(peerId, PeerErrorSeverity.HighToleranceError);
473
+ this.peers.markPeerDumb(peerId);
474
+ this.txsMetadata.clearPeerData(peerId);
475
+ return;
500
476
  }
501
477
  }
502
478
 
@@ -516,7 +492,7 @@ export class BatchTxRequester {
516
492
  * Handles received txs.
517
493
  * Transactions are validated and then put on async queue
518
494
  * to be yielded by main running loop
519
- * */
495
+ */
520
496
  private async handleReceivedTxs(peerId: PeerId, txs: TxArray) {
521
497
  const newTxs = txs.filter(tx => !this.txsMetadata.alreadyFetched(tx.txHash));
522
498
 
@@ -524,12 +500,12 @@ export class BatchTxRequester {
524
500
  return;
525
501
  }
526
502
 
527
- //TODO: this validation can be slow, maybe spawn worker just for validation
503
+ // TODO: this validation can be slow, maybe spawn worker just for validation
528
504
  // We could use the async queue for communication.
529
505
  const validationResults = await Promise.allSettled(
530
506
  newTxs.map(async tx => ({
531
507
  tx,
532
- isValid: (await this.txValidator.validateRequestedTx(tx)).result === 'valid',
508
+ isValid: (await this.txValidator.validateTx(tx)).result === 'valid',
533
509
  })),
534
510
  );
535
511
 
@@ -545,6 +521,9 @@ export class BatchTxRequester {
545
521
  });
546
522
 
547
523
  if (hasInvalidTx) {
524
+ this.logger.warn(`Penalizing peer ${peerId.toString()} for sending invalid transactions in batch response`, {
525
+ peerId,
526
+ });
548
527
  this.peers.penalisePeer(peerId, PeerErrorSeverity.LowToleranceError);
549
528
  } else {
550
529
  // If we have received successful response from the peer, they have "redeemed" themselves and not considered bad anymore
@@ -581,10 +560,10 @@ export class BatchTxRequester {
581
560
  return;
582
561
  }
583
562
 
584
- // If block response is invalid we still want to query this peer in the future
585
- // Because they sent successful response, so they might become smart peer in the future
586
- // Or send us needed txs
587
- if (!this.isBlockResponseValid(response)) {
563
+ // If the peer doesn't have the block, we mark them as dumb.
564
+ if (!response.peerHasBlock()) {
565
+ this.peers.markPeerDumb(peerId);
566
+ this.txsMetadata.clearPeerData(peerId);
588
567
  return;
589
568
  }
590
569
 
@@ -599,18 +578,13 @@ export class BatchTxRequester {
599
578
  this.markTxsPeerHas(peerId, response);
600
579
 
601
580
  // Unblock smart workers
602
- if (this.peers.getSmartPeersToQuery().length <= this.smartParallelWorkerCount) {
603
- this.smartRequesterSemaphore.release();
604
- }
605
- }
606
-
607
- private isBlockResponseValid(response: BlockTxsResponse): boolean {
608
- const archiveRootsMatch = this.blockTxsSource.archive.toString() === response.archiveRoot.toString();
609
- const peerHasSomeTxsFromProposal = !response.txIndices.isEmpty();
610
- return archiveRootsMatch && peerHasSomeTxsFromProposal;
581
+ this.smartRequesterSemaphore.release();
611
582
  }
612
583
 
613
584
  private peerHasSomeTxsWeAreMissing(_peerId: PeerId, response: BlockTxsResponse): boolean {
585
+ if (response.txIndices.isEmpty()) {
586
+ return false;
587
+ }
614
588
  const txsPeerHas = new Set(this.extractHashesPeerHasFromResponse(response).map(h => h.toString()));
615
589
  return this.txsMetadata.getMissingTxHashes().intersection(txsPeerHas).size > 0;
616
590
  }
@@ -622,15 +596,9 @@ export class BatchTxRequester {
622
596
  }
623
597
 
624
598
  private extractHashesPeerHasFromResponse(response: BlockTxsResponse): Array<TxHash> {
625
- const hashes: TxHash[] = [];
626
- const indicesOfHashesPeerHas = new Set(response.txIndices.getTrueIndices());
627
- this.blockTxsSource.txHashes.forEach((hash, idx) => {
628
- if (indicesOfHashesPeerHas.has(idx)) {
629
- hashes.push(hash);
630
- }
631
- });
632
-
633
- return hashes;
599
+ // Should already have been validated, but just in case.
600
+ assert(response.txIndices.getLength() === this.blockTxsSource.txHashes.length);
601
+ return response.txIndices.getTrueIndices().map(idx => this.blockTxsSource.txHashes[idx]);
634
602
  }
635
603
 
636
604
  /*
@@ -659,27 +627,14 @@ export class BatchTxRequester {
659
627
  }
660
628
 
661
629
  /*
662
- * @returns true if all missing txs have been fetched */
663
- private fetchedAllTxs() {
664
- return this.txsMetadata.getMissingTxHashes().size == 0;
665
- }
666
-
667
- /*
668
- * Checks if the BatchTxRequester should stop fetching missing txs
669
- * Conditions for stopping are:
670
- * - There have been no missing transactions to start with
671
- * - All transactions have been fetched
672
- * - The deadline has been hit (no more time to fetch)
673
- * - This process has been cancelled via abortSignal
674
- *
675
- * @returns true if BatchTxRequester should stop, otherwise false*/
630
+ * Checks if the BatchTxRequester should stop fetching missing txs.
631
+ * Delegates to requestTracker which covers: deadline hit, all txs fetched, or external cancellation. */
676
632
  private shouldStop() {
677
- const aborted = this.opts.abortSignal?.aborted ?? false;
678
- if (aborted) {
633
+ if (this.requestTracker.checkCancelled()) {
679
634
  this.unlockSmartRequesterSemaphores();
680
635
  }
681
636
 
682
- return aborted || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
637
+ return this.requestTracker.checkCancelled();
683
638
  }
684
639
 
685
640
  /*
@@ -697,10 +652,9 @@ export class BatchTxRequester {
697
652
  * This ensures we don't sleep past the deadline.
698
653
  * */
699
654
  private async sleepClampedToDeadline(durationMs: number) {
700
- const remaining = this.deadline - this.dateProvider.now();
701
- const thereIsTimeRemaining = remaining > 0;
702
- if (thereIsTimeRemaining) {
703
- await sleep(Math.min(durationMs, remaining));
655
+ if (this.requestTracker.checkCancelled()) {
656
+ return;
704
657
  }
658
+ await Promise.race([sleep(durationMs), this.requestTracker.cancellationToken]);
705
659
  }
706
660
  }
@@ -1,13 +1,14 @@
1
1
  import type { ISemaphore } from '@aztec/foundation/queue';
2
2
  import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
3
+ import type { Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
4
4
 
5
5
  import type { PeerId } from '@libp2p/interface';
6
6
 
7
7
  import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
8
+ import type { BlockTxsRequest, BlockTxsResponse } from '../index.js';
8
9
  import type { ReqRespInterface } from '../interface.js';
9
10
  import type { IPeerCollection } from './peer_collection.js';
10
- import type { BatchRequestTxValidatorConfig, IBatchRequestTxValidator } from './tx_validator.js';
11
+ import type { BatchRequestTxValidatorConfig } from './tx_validator.js';
11
12
 
12
13
  export interface IPeerPenalizer {
13
14
  penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity): void;
@@ -23,6 +24,8 @@ export interface ITxMetadataCollection {
23
24
  alreadyFetched(txHash: TxHash): boolean;
24
25
  // Returns true if tx was marked as fetched, false if it was already marked as fetched
25
26
  markPeerHas(peerId: PeerId, txHashes: TxHash[]): void;
27
+ /** Remove all tx metadata associations for a peer (e.g. on demotion from smart to dumb). */
28
+ clearPeerData(peerId: PeerId): void;
26
29
  }
27
30
 
28
31
  /**
@@ -30,13 +33,19 @@ export interface ITxMetadataCollection {
30
33
  */
31
34
  export interface BatchTxRequesterLibP2PService {
32
35
  /** ReqResp interface for sending requests to peers */
33
- reqResp: Pick<ReqRespInterface, 'sendBatchRequest' | 'sendRequestToPeer'>;
36
+ reqResp: Pick<ReqRespInterface, 'sendRequestToPeer'>;
34
37
  /** Connection sampler for getting peer lists */
35
38
  connectionSampler: Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>;
36
39
  /** Configuration needed for transaction validation */
37
40
  txValidatorConfig: BatchRequestTxValidatorConfig;
38
41
  /** Peer scoring for penalizing peers */
39
42
  peerScoring: IPeerPenalizer;
43
+ /** Validate the requested block transactions request-response consistency */
44
+ validateRequestedBlockTxsConsistency: (
45
+ request: BlockTxsRequest,
46
+ response: BlockTxsResponse,
47
+ peerId: PeerId,
48
+ ) => Promise<boolean>;
40
49
  }
41
50
 
42
51
  export interface BatchTxRequesterOptions {
@@ -47,7 +56,6 @@ export interface BatchTxRequesterOptions {
47
56
  //Injectable for testing purposes
48
57
  semaphore?: ISemaphore;
49
58
  peerCollection?: IPeerCollection;
50
- abortSignal?: AbortSignal;
51
59
  /** Optional tx validator for testing - if not provided, one is created from p2pService.txValidatorConfig */
52
- txValidator?: IBatchRequestTxValidator;
60
+ txValidator?: TxValidator;
53
61
  }
@@ -2,7 +2,7 @@ import { type Tx, TxHash } from '@aztec/stdlib/tx';
2
2
 
3
3
  import type { PeerId } from '@libp2p/interface';
4
4
 
5
- import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
5
+ import type { IRequestTracker } from '../../tx_collection/request_tracker.js';
6
6
  import { DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE } from './config.js';
7
7
  import type { ITxMetadataCollection } from './interface.js';
8
8
 
@@ -41,10 +41,10 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
41
41
  private txMetadata = new Map<string, MissingTxMetadata>();
42
42
 
43
43
  constructor(
44
- private missingTxsTracker: IMissingTxsTracker,
44
+ private requestTracker: IRequestTracker,
45
45
  private readonly txBatchSize: number = DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
46
46
  ) {
47
- missingTxsTracker.missingTxHashes.forEach(hash => this.txMetadata.set(hash, new MissingTxMetadata(hash)));
47
+ requestTracker.missingTxHashes.forEach(hash => this.txMetadata.set(hash, new MissingTxMetadata(hash)));
48
48
  }
49
49
 
50
50
  public getPrioritizingNotInFlightAndLowerRequestCount(txs: string[]): MissingTxMetadata[] {
@@ -65,7 +65,7 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
65
65
  }
66
66
 
67
67
  public getMissingTxHashes(): Set<string> {
68
- return this.missingTxsTracker.missingTxHashes;
68
+ return this.requestTracker.missingTxHashes;
69
69
  }
70
70
 
71
71
  public getTxsPeerHas(peer: PeerId): Set<string> {
@@ -128,7 +128,7 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
128
128
  }
129
129
 
130
130
  public alreadyFetched(txHash: TxHash): boolean {
131
- return !this.missingTxsTracker.isMissing(txHash.toString());
131
+ return !this.requestTracker.isMissing(txHash.toString());
132
132
  }
133
133
 
134
134
  public markFetched(peerId: PeerId, tx: Tx): boolean {
@@ -144,7 +144,7 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
144
144
  }
145
145
 
146
146
  txMeta.peers.add(peerId.toString());
147
- return this.missingTxsTracker.markFetched(tx);
147
+ return this.requestTracker.markFetched(tx);
148
148
  }
149
149
 
150
150
  public markPeerHas(peerId: PeerId, txHash: TxHash[]) {
@@ -158,4 +158,11 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
158
158
  }
159
159
  });
160
160
  }
161
+
162
+ public clearPeerData(peerId: PeerId) {
163
+ const peerIdStr = peerId.toString();
164
+ for (const txMeta of this.txMetadata.values()) {
165
+ txMeta.peers.delete(peerIdStr);
166
+ }
167
+ }
161
168
  }