@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f504929

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 (326) hide show
  1. package/dest/client/factory.d.ts +8 -8
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +37 -13
  4. package/dest/client/interface.d.ts +39 -33
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +37 -50
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +138 -199
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
  10. package/dest/config.d.ts +29 -15
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +39 -35
  13. package/dest/errors/tx-pool.error.d.ts +8 -0
  14. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  15. package/dest/errors/tx-pool.error.js +9 -0
  16. package/dest/index.d.ts +2 -1
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +1 -0
  19. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/attestation_pool.js +72 -38
  22. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +53 -53
  25. package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
  26. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/index.js +1 -1
  28. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  31. package/dest/mem_pools/index.d.ts +2 -1
  32. package/dest/mem_pools/index.d.ts.map +1 -1
  33. package/dest/mem_pools/instrumentation.d.ts +4 -2
  34. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  35. package/dest/mem_pools/instrumentation.js +16 -14
  36. package/dest/mem_pools/interface.d.ts +3 -3
  37. package/dest/mem_pools/interface.d.ts.map +1 -1
  38. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  39. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  40. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  41. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  42. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  43. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  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 -2
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  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 +12 -4
  51. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  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 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  55. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  58. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  59. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  60. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  61. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  62. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  63. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  65. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  66. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  67. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  68. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  69. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  71. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  72. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  74. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -8
  75. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
  77. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +56 -8
  78. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +108 -10
  80. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  81. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  82. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +14 -6
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  87. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  88. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +344 -184
  89. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
  90. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  91. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
  92. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  93. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
  94. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/proposal_validator/proposal_validator.js +10 -0
  96. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +2 -1
  97. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
  98. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +166 -0
  99. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  100. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  101. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  102. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  103. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  104. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -10
  105. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  106. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  108. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  109. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  111. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  112. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/factory.js +219 -58
  114. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  115. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  117. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  118. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  119. package/dest/msg_validators/tx_validator/index.js +1 -0
  120. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  121. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  122. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  123. package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
  124. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/phases_validator.js +25 -24
  126. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  127. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  129. package/dest/services/dummy_service.d.ts +9 -5
  130. package/dest/services/dummy_service.d.ts.map +1 -1
  131. package/dest/services/dummy_service.js +7 -4
  132. package/dest/services/encoding.d.ts +3 -3
  133. package/dest/services/encoding.d.ts.map +1 -1
  134. package/dest/services/encoding.js +11 -10
  135. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  136. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  137. package/dest/services/gossipsub/topic_score_params.js +32 -10
  138. package/dest/services/libp2p/libp2p_service.d.ts +25 -14
  139. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  140. package/dest/services/libp2p/libp2p_service.js +143 -114
  141. package/dest/services/peer-manager/metrics.d.ts +3 -1
  142. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  143. package/dest/services/peer-manager/metrics.js +6 -0
  144. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  145. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  146. package/dest/services/peer-manager/peer_manager.js +2 -1
  147. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  148. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  149. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  150. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  151. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  152. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  153. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  154. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  155. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  156. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  157. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  158. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  159. package/dest/services/reqresp/interface.d.ts +10 -1
  160. package/dest/services/reqresp/interface.d.ts.map +1 -1
  161. package/dest/services/reqresp/interface.js +15 -1
  162. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
  163. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  164. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  165. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  166. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  167. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  168. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  169. package/dest/services/reqresp/protocols/tx.js +20 -0
  170. package/dest/services/reqresp/reqresp.d.ts +1 -1
  171. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  172. package/dest/services/reqresp/reqresp.js +13 -5
  173. package/dest/services/service.d.ts +22 -3
  174. package/dest/services/service.d.ts.map +1 -1
  175. package/dest/services/tx_collection/config.d.ts +19 -1
  176. package/dest/services/tx_collection/config.d.ts.map +1 -1
  177. package/dest/services/tx_collection/config.js +46 -0
  178. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
  179. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  180. package/dest/services/tx_collection/fast_tx_collection.js +56 -36
  181. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  182. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  183. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  184. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  185. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  186. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  187. package/dest/services/tx_collection/index.d.ts +2 -1
  188. package/dest/services/tx_collection/index.d.ts.map +1 -1
  189. package/dest/services/tx_collection/index.js +1 -0
  190. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  191. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  192. package/dest/services/tx_collection/instrumentation.js +2 -1
  193. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  194. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  195. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  196. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  197. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  198. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  199. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  200. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  201. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  202. package/dest/services/tx_collection/tx_collection.d.ts +23 -10
  203. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  204. package/dest/services/tx_collection/tx_collection.js +75 -3
  205. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  206. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  207. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  208. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  209. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  210. package/dest/services/tx_collection/tx_source.js +19 -2
  211. package/dest/services/tx_file_store/config.d.ts +1 -3
  212. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  213. package/dest/services/tx_file_store/config.js +0 -4
  214. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  215. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  216. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  217. package/dest/services/tx_provider.d.ts +4 -4
  218. package/dest/services/tx_provider.d.ts.map +1 -1
  219. package/dest/services/tx_provider.js +9 -8
  220. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  221. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  222. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  223. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  224. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  225. package/dest/test-helpers/mock-pubsub.js +105 -4
  226. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  227. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  228. package/dest/test-helpers/reqresp-nodes.js +2 -2
  229. package/dest/test-helpers/testbench-utils.d.ts +35 -24
  230. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  231. package/dest/test-helpers/testbench-utils.js +93 -35
  232. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  233. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  234. package/dest/testbench/p2p_client_testbench_worker.js +14 -14
  235. package/dest/util.d.ts +2 -2
  236. package/dest/util.d.ts.map +1 -1
  237. package/package.json +14 -14
  238. package/src/client/factory.ts +71 -23
  239. package/src/client/interface.ts +43 -33
  240. package/src/client/p2p_client.ts +164 -243
  241. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
  242. package/src/config.ts +60 -42
  243. package/src/errors/tx-pool.error.ts +12 -0
  244. package/src/index.ts +1 -0
  245. package/src/mem_pools/attestation_pool/attestation_pool.ts +100 -48
  246. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +57 -53
  247. package/src/mem_pools/attestation_pool/index.ts +3 -3
  248. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  249. package/src/mem_pools/index.ts +3 -0
  250. package/src/mem_pools/instrumentation.ts +17 -13
  251. package/src/mem_pools/interface.ts +2 -2
  252. package/src/mem_pools/tx_pool/README.md +1 -1
  253. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  254. package/src/mem_pools/tx_pool_v2/README.md +76 -10
  255. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  256. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  257. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  258. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  259. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  260. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  261. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  262. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  263. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  264. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  265. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  266. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  267. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  268. package/src/mem_pools/tx_pool_v2/interfaces.ts +23 -8
  269. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +153 -17
  270. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
  271. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +21 -7
  272. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +388 -182
  273. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +1 -1
  274. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +1 -1
  275. package/src/msg_validators/proposal_validator/proposal_validator.ts +15 -1
  276. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +144 -1
  277. package/src/msg_validators/tx_validator/README.md +115 -0
  278. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  279. package/src/msg_validators/tx_validator/allowed_public_setup.ts +27 -13
  280. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  281. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  282. package/src/msg_validators/tx_validator/factory.ts +353 -77
  283. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  284. package/src/msg_validators/tx_validator/index.ts +1 -0
  285. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  286. package/src/msg_validators/tx_validator/phases_validator.ts +25 -29
  287. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  288. package/src/services/dummy_service.ts +12 -6
  289. package/src/services/encoding.ts +9 -9
  290. package/src/services/gossipsub/README.md +29 -14
  291. package/src/services/gossipsub/topic_score_params.ts +49 -13
  292. package/src/services/libp2p/libp2p_service.ts +153 -123
  293. package/src/services/peer-manager/metrics.ts +7 -0
  294. package/src/services/peer-manager/peer_manager.ts +2 -1
  295. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  296. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  297. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  298. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  299. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  300. package/src/services/reqresp/interface.ts +26 -1
  301. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
  302. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  303. package/src/services/reqresp/protocols/tx.ts +22 -0
  304. package/src/services/reqresp/reqresp.ts +16 -4
  305. package/src/services/service.ts +31 -2
  306. package/src/services/tx_collection/config.ts +68 -0
  307. package/src/services/tx_collection/fast_tx_collection.ts +65 -32
  308. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  309. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  310. package/src/services/tx_collection/index.ts +1 -0
  311. package/src/services/tx_collection/instrumentation.ts +7 -1
  312. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  313. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  314. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  315. package/src/services/tx_collection/tx_collection.ts +113 -16
  316. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  317. package/src/services/tx_collection/tx_source.ts +22 -3
  318. package/src/services/tx_file_store/config.ts +0 -6
  319. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  320. package/src/services/tx_provider.ts +10 -9
  321. package/src/test-helpers/make-test-p2p-clients.ts +3 -5
  322. package/src/test-helpers/mock-pubsub.ts +146 -9
  323. package/src/test-helpers/reqresp-nodes.ts +2 -5
  324. package/src/test-helpers/testbench-utils.ts +108 -40
  325. package/src/testbench/p2p_client_testbench_worker.ts +23 -20
  326. package/src/util.ts +7 -1
@@ -1,24 +1,29 @@
1
1
  import type { Logger } from '@aztec/foundation/log';
2
2
  import { elapsed } from '@aztec/foundation/timer';
3
3
  import type { TypedEventEmitter } from '@aztec/foundation/types';
4
- import { Tx, type TxHash } from '@aztec/stdlib/tx';
4
+ import type { L2Block } from '@aztec/stdlib/block';
5
+ import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
5
6
  import type { TelemetryClient } from '@aztec/telemetry-client';
6
7
 
7
8
  import EventEmitter from 'node:events';
8
9
 
9
- import type { TxPool, TxPoolEvents } from '../../mem_pools/tx_pool/tx_pool.js';
10
+ import type { TxPoolV2, TxPoolV2Events } from '../../mem_pools/index.js';
10
11
  import { TxCollectionInstrumentation } from './instrumentation.js';
11
12
  import type { CollectionMethod } from './tx_collection.js';
13
+ import type { TxSourceCollectionResult } from './tx_source.js';
14
+
15
+ /** Context determining how collected txs should be added to the pool. */
16
+ export type TxAddContext = { type: 'proposal'; blockHeader: BlockHeader } | { type: 'mined'; block: L2Block };
12
17
 
13
18
  /**
14
19
  * Executes collection requests from the fast and slow collection loops, and handles collected txs
15
20
  * by adding them to the tx pool and emitting events, as well as handling logging and metrics.
16
21
  */
17
- export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitter<TxPoolEvents>) {
22
+ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitter<TxPoolV2Events>) {
18
23
  private readonly instrumentation: TxCollectionInstrumentation;
19
24
 
20
25
  constructor(
21
- private readonly txPool: TxPool,
26
+ private readonly txPool: TxPoolV2,
22
27
  telemetryClient: TelemetryClient,
23
28
  private readonly log: Logger,
24
29
  ) {
@@ -27,51 +32,37 @@ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitt
27
32
  }
28
33
 
29
34
  public async collect(
30
- collectValidTxsFn: (txHashes: TxHash[]) => Promise<(Tx | undefined)[]>,
31
- requested: TxHash[],
35
+ collectValidTxsFn: () => Promise<TxSourceCollectionResult>,
36
+ requested: string[],
32
37
  info: Record<string, any> & { description: string; method: CollectionMethod },
38
+ context: TxAddContext,
33
39
  ) {
34
40
  this.log.trace(`Requesting ${requested.length} txs via ${info.description}`, {
35
41
  ...info,
36
- requestedTxs: requested.map(t => t.toString()),
42
+ requestedTxs: requested,
37
43
  });
38
44
 
39
45
  // Execute collection function and measure the time taken, catching any errors.
40
- const [duration, txs] = await elapsed(async () => {
46
+ const [duration, { validTxs, invalidTxHashes }] = await elapsed(async () => {
41
47
  try {
42
- const response = await collectValidTxsFn(requested);
43
- return response.filter(tx => tx !== undefined);
48
+ return await collectValidTxsFn();
44
49
  } catch (err) {
45
50
  this.log.error(`Error collecting txs via ${info.description}`, err, {
46
51
  ...info,
47
- requestedTxs: requested.map(hash => hash.toString()),
52
+ requestedTxs: requested,
48
53
  });
49
- return [] as Tx[];
54
+ return { validTxs: [] as Tx[], invalidTxHashes: [] as string[] };
50
55
  }
51
56
  });
52
57
 
53
- if (txs.length === 0) {
58
+ if (validTxs.length === 0 && invalidTxHashes.length === 0) {
54
59
  this.log.trace(`No txs found via ${info.description}`, {
55
60
  ...info,
56
- requestedTxs: requested.map(t => t.toString()),
61
+ requestedTxs: requested,
57
62
  });
58
- return { txs, requested, duration };
63
+ return { txs: validTxs, requested, duration };
59
64
  }
60
65
 
61
- // Validate tx hashes for all collected txs from external sources
62
- const validTxs: Tx[] = [];
63
- const invalidTxHashes: string[] = [];
64
- await Promise.all(
65
- txs.map(async tx => {
66
- const isValid = await tx.validateTxHash();
67
- if (isValid) {
68
- validTxs.push(tx);
69
- } else {
70
- invalidTxHashes.push(tx.getTxHash().toString());
71
- }
72
- }),
73
- );
74
-
75
66
  if (invalidTxHashes.length > 0) {
76
67
  this.log.warn(`Rejecting ${invalidTxHashes.length} txs with invalid hashes from ${info.description}`, {
77
68
  ...info,
@@ -82,7 +73,7 @@ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitt
82
73
  if (validTxs.length === 0) {
83
74
  this.log.trace(`No valid txs found via ${info.description} after validation`, {
84
75
  ...info,
85
- requestedTxs: requested.map(t => t.toString()),
76
+ requestedTxs: requested,
86
77
  invalidTxHashes,
87
78
  });
88
79
  return { txs: [], requested, duration };
@@ -94,17 +85,18 @@ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitt
94
85
  ...info,
95
86
  duration,
96
87
  txs: validTxs.map(t => t.getTxHash().toString()),
97
- requestedTxs: requested.map(t => t.toString()),
88
+ requestedTxs: requested,
98
89
  rejectedCount: invalidTxHashes.length,
99
90
  },
100
91
  );
101
92
 
102
- return await this.foundTxs(validTxs, { ...info, duration });
93
+ return await this.foundTxs(validTxs, { ...info, duration }, context);
103
94
  }
104
95
 
105
96
  private async foundTxs(
106
97
  txs: Tx[],
107
98
  info: Record<string, any> & { description: string; method: CollectionMethod; duration: number },
99
+ context: TxAddContext,
108
100
  ) {
109
101
  // Report metrics for the collection
110
102
  this.instrumentation.increaseTxsFor(info.method, txs.length, info.duration);
@@ -112,9 +104,13 @@ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitt
112
104
  // Mark txs as found in the slow missing txs set and all fast requests
113
105
  this.emit('txs-added', { txs });
114
106
 
115
- // Add the txs to the tx pool (should not fail, but we catch it just in case)
107
+ // Add the txs to the tx pool using the appropriate method based on context
116
108
  try {
117
- await this.txPool.addTxs(txs, { source: `tx-collection` });
109
+ if (context.type === 'mined') {
110
+ await this.txPool.addMinedTxs(txs, context.block.header, { source: 'tx-collection' });
111
+ } else {
112
+ await this.txPool.addProtectedTxs(txs, context.blockHeader, { source: 'tx-collection' });
113
+ }
118
114
  } catch (err) {
119
115
  this.log.error(`Error adding txs to the pool via ${info.description}`, err, {
120
116
  ...info,
@@ -6,9 +6,11 @@ import type { Tx, TxHash } from '@aztec/stdlib/tx';
6
6
  import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
7
7
  import { makeTracedFetch } from '@aztec/telemetry-client';
8
8
 
9
+ export type TxSourceCollectionResult = { validTxs: Tx[]; invalidTxHashes: string[] };
10
+
9
11
  export interface TxSource {
10
12
  getInfo(): string;
11
- getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
13
+ getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult>;
12
14
  }
13
15
 
14
16
  export class NodeRpcTxSource implements TxSource {
@@ -26,8 +28,25 @@ export class NodeRpcTxSource implements TxSource {
26
28
  return this.info;
27
29
  }
28
30
 
29
- public getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
30
- return this.client.getTxsByHash(txHashes);
31
+ public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
32
+ return this.verifyTxs(await this.client.getTxsByHash(txHashes));
33
+ }
34
+
35
+ private async verifyTxs(txs: Tx[]): Promise<TxSourceCollectionResult> {
36
+ // Validate tx hashes for all collected txs from external sources
37
+ const validTxs: Tx[] = [];
38
+ const invalidTxHashes: string[] = [];
39
+ await Promise.all(
40
+ txs.map(async tx => {
41
+ const isValid = await tx.validateTxHash();
42
+ if (isValid) {
43
+ validTxs.push(tx);
44
+ } else {
45
+ invalidTxHashes.push(tx.getTxHash().toString());
46
+ }
47
+ }),
48
+ );
49
+ return { validTxs: validTxs, invalidTxHashes: invalidTxHashes };
31
50
  }
32
51
  }
33
52
 
@@ -6,8 +6,6 @@ import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from
6
6
  export type TxFileStoreConfig = {
7
7
  /** URL for uploading txs to file storage (s3://, gs://, file://) */
8
8
  txFileStoreUrl?: string;
9
- /** URL for downloading txs from file storage */
10
- txFileStoreDownloadUrl?: string;
11
9
  /** Max concurrent uploads */
12
10
  txFileStoreUploadConcurrency: number;
13
11
  /** Max queue size to prevent unbounded memory growth */
@@ -21,10 +19,6 @@ export const txFileStoreConfigMappings: ConfigMappingsType<TxFileStoreConfig> =
21
19
  env: 'TX_FILE_STORE_URL',
22
20
  description: 'URL for uploading txs to file storage (s3://, gs://, file://)',
23
21
  },
24
- txFileStoreDownloadUrl: {
25
- env: 'TX_FILE_STORE_DOWNLOAD_URL',
26
- description: 'URL for downloading txs from file storage',
27
- },
28
22
  txFileStoreUploadConcurrency: {
29
23
  env: 'TX_FILE_STORE_UPLOAD_CONCURRENCY',
30
24
  description: 'Maximum number of concurrent tx uploads',
@@ -6,7 +6,7 @@ import { type FileStore, createFileStore } from '@aztec/stdlib/file-store';
6
6
  import type { Tx } from '@aztec/stdlib/tx';
7
7
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
8
8
 
9
- import type { TxPool, TxPoolEvents } from '../../mem_pools/tx_pool/index.js';
9
+ import type { TxPoolV2 } from '../../mem_pools/index.js';
10
10
  import type { TxFileStoreConfig } from './config.js';
11
11
  import { TxFileStoreInstrumentation } from './instrumentation.js';
12
12
 
@@ -18,7 +18,7 @@ export class TxFileStore {
18
18
  private uploadQueue: Tx[] = [];
19
19
  private activeUploads = 0;
20
20
  private readonly queueProcessor: RunningPromise;
21
- private readonly handleTxsAdded: TxPoolEvents['txs-added'];
21
+ private readonly handleTxsAdded: (args: { txs: Tx[]; source?: string }) => void;
22
22
 
23
23
  /** Recently uploaded tx hashes for deduplication. */
24
24
  private recentUploads: Set<string> = new Set();
@@ -27,10 +27,11 @@ export class TxFileStore {
27
27
 
28
28
  private constructor(
29
29
  private readonly fileStore: FileStore,
30
- private readonly txPool: TxPool,
30
+ private readonly txPool: TxPoolV2,
31
31
  private readonly config: TxFileStoreConfig,
32
32
  private readonly instrumentation: TxFileStoreInstrumentation,
33
33
  private readonly log: Logger,
34
+ private readonly basePath: string,
34
35
  ) {
35
36
  this.handleTxsAdded = (args: { txs: Tx[]; source?: string }) => {
36
37
  this.enqueueTxs(args.txs);
@@ -48,8 +49,9 @@ export class TxFileStore {
48
49
  * @returns The file store instance, or undefined if not configured/enabled.
49
50
  */
50
51
  static async create(
51
- txPool: TxPool,
52
+ txPool: TxPoolV2,
52
53
  config: TxFileStoreConfig,
54
+ basePath: string,
53
55
  log: Logger = createLogger('p2p:tx_file_store'),
54
56
  telemetry: TelemetryClient = getTelemetryClient(),
55
57
  fileStoreOverride?: FileStore,
@@ -71,8 +73,8 @@ export class TxFileStore {
71
73
  }
72
74
 
73
75
  const instrumentation = new TxFileStoreInstrumentation(telemetry, 'TxFileStore');
74
- log.info('Created tx file store', { url: config.txFileStoreUrl });
75
- return new TxFileStore(fileStore, txPool, config, instrumentation, log);
76
+ log.info('Created tx file store', { url: config.txFileStoreUrl, basePath });
77
+ return new TxFileStore(fileStore, txPool, config, instrumentation, log, basePath);
76
78
  }
77
79
 
78
80
  /** Starts listening to TxPool events and uploading txs. */
@@ -122,7 +124,7 @@ export class TxFileStore {
122
124
 
123
125
  private async uploadTx(tx: Tx): Promise<void> {
124
126
  const txHash = tx.getTxHash().toString();
125
- const path = `txs/${txHash}.bin`;
127
+ const path = `${this.basePath}/txs/${txHash}.bin`;
126
128
  const timer = new Timer();
127
129
 
128
130
  if (this.recentUploads.has(txHash)) {
@@ -144,7 +146,7 @@ export class TxFileStore {
144
146
  }
145
147
 
146
148
  await retry(
147
- () => this.fileStore.save(path, tx.toBuffer(), { compress: false }),
149
+ () => this.fileStore.save(path, tx.toBuffer(), { compress: true }),
148
150
  `Uploading tx ${txHash}`,
149
151
  makeBackoff([0.1, 0.5, 2]),
150
152
  this.log,
@@ -5,13 +5,13 @@ import { elapsed } from '@aztec/foundation/timer';
5
5
  import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
6
6
  import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
7
7
  import type { BlockProposal } from '@aztec/stdlib/p2p';
8
- import { Tx, TxHash } from '@aztec/stdlib/tx';
8
+ import { type BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
9
9
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
10
10
 
11
11
  import type { PeerId } from '@libp2p/interface';
12
12
 
13
13
  import type { P2PClient } from '../client/p2p_client.js';
14
- import type { TxPool } from '../mem_pools/index.js';
14
+ import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
15
15
  import type { FastCollectionRequestInput, TxCollection } from './tx_collection/tx_collection.js';
16
16
  import { TxProviderInstrumentation } from './tx_provider_instrumentation.js';
17
17
 
@@ -24,8 +24,8 @@ export class TxProvider implements ITxProvider {
24
24
 
25
25
  constructor(
26
26
  private txCollection: TxCollection,
27
- private txPool: TxPool,
28
- private txValidator: Pick<P2PClient, 'validate'>,
27
+ private txPool: TxPoolV2,
28
+ private blockProposalTransactionValidator: Pick<P2PClient, 'validateTxsReceivedInBlockProposal'>,
29
29
  private log: Logger = createLogger('p2p:tx-collector'),
30
30
  client: TelemetryClient = getTelemetryClient(),
31
31
  ) {
@@ -144,6 +144,7 @@ export class TxProvider implements ITxProvider {
144
144
  // Take txs from the proposal body if there are any
145
145
  // Note that we still have to validate these txs, but we do it in parallel with tx collection
146
146
  const proposal = request.type === 'proposal' ? request.blockProposal : undefined;
147
+ const proposalBlockHeader = proposal?.blockHeader;
147
148
  const txsFromProposal = this.extractFromProposal(proposal, [...missingTxHashes]);
148
149
  if (txsFromProposal.length > 0) {
149
150
  this.instrumentation.incTxsFromProposals(txsFromProposal.length);
@@ -155,7 +156,7 @@ export class TxProvider implements ITxProvider {
155
156
  }
156
157
 
157
158
  if (missingTxHashes.size === 0) {
158
- await this.processProposalTxs(txsFromProposal);
159
+ await this.processProposalTxs(txsFromProposal, proposalBlockHeader!);
159
160
  this.instrumentation.incTxsFromP2P(0, txHashes.length);
160
161
  return { txsFromMempool, txsFromProposal };
161
162
  }
@@ -163,7 +164,7 @@ export class TxProvider implements ITxProvider {
163
164
  // Start tx collection from the network if needed, while we validate the txs taken from the proposal in parallel
164
165
  const [txsFromNetwork] = await Promise.all([
165
166
  this.collectFromP2P(request, [...missingTxHashes], opts),
166
- this.processProposalTxs(txsFromProposal),
167
+ this.processProposalTxs(txsFromProposal, proposalBlockHeader!),
167
168
  ] as const);
168
169
 
169
170
  if (txsFromNetwork.length > 0) {
@@ -222,11 +223,11 @@ export class TxProvider implements ITxProvider {
222
223
  return compactArray(proposal.txs ?? []).filter(tx => missingTxHashes.includes(tx.getTxHash().toString()));
223
224
  }
224
225
 
225
- private async processProposalTxs(txs: Tx[]): Promise<void> {
226
+ private async processProposalTxs(txs: Tx[], blockHeader: BlockHeader): Promise<void> {
226
227
  if (txs.length === 0) {
227
228
  return;
228
229
  }
229
- await this.txValidator.validate(txs);
230
- await this.txPool.addTxs(txs);
230
+ await this.blockProposalTransactionValidator.validateTxsReceivedInBlockProposal(txs);
231
+ await this.txPool.addProtectedTxs(txs, blockHeader);
231
232
  }
232
233
  }
@@ -7,13 +7,12 @@ import { sleep } from '@aztec/foundation/sleep';
7
7
  import type { DataStoreConfig } from '@aztec/kv-store/config';
8
8
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
9
9
  import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
10
- import { P2PClientType } from '@aztec/stdlib/p2p';
11
10
 
12
11
  import { createP2PClient } from '../client/index.js';
13
12
  import type { P2PClient } from '../client/p2p_client.js';
14
13
  import type { P2PConfig } from '../config.js';
15
14
  import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
16
- import type { TxPool } from '../mem_pools/tx_pool/index.js';
15
+ import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
17
16
  import { generatePeerIdPrivateKeys } from '../test-helpers/generate-peer-id-private-keys.js';
18
17
  import { getPorts } from './get-ports.js';
19
18
  import { makeEnrs } from './make-enrs.js';
@@ -22,7 +21,7 @@ import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from './reqresp
22
21
 
23
22
  export interface MakeTestP2PClientOptions {
24
23
  mockAttestationPool: AttestationPool;
25
- mockTxPool: TxPool;
24
+ mockTxPool: TxPoolV2;
26
25
  mockEpochCache: EpochCache;
27
26
  mockWorldState: WorldStateSynchronizer;
28
27
  alwaysTrueVerifier?: boolean;
@@ -98,7 +97,6 @@ export async function makeTestP2PClient(
98
97
  const kvStore = await openTmpStore('test');
99
98
 
100
99
  const client = await createP2PClient(
101
- P2PClientType.Full,
102
100
  config,
103
101
  l2BlockSource,
104
102
  proofVerifier,
@@ -108,7 +106,7 @@ export async function makeTestP2PClient(
108
106
  undefined,
109
107
  undefined,
110
108
  {
111
- txPool: mockTxPool as unknown as TxPool,
109
+ txPool: mockTxPool as unknown as TxPoolV2,
112
110
  attestationPool: mockAttestationPool as unknown as AttestationPool,
113
111
  store: kvStore,
114
112
  logger,
@@ -4,7 +4,6 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
4
  import type { L2BlockSource } from '@aztec/stdlib/block';
5
5
  import type { ContractDataSource } from '@aztec/stdlib/contract';
6
6
  import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
7
- import { P2PClientType } from '@aztec/stdlib/p2p';
8
7
  import type { TelemetryClient } from '@aztec/telemetry-client';
9
8
 
10
9
  import type { GossipsubEvents, GossipsubMessage } from '@chainsafe/libp2p-gossipsub';
@@ -19,8 +18,20 @@ import {
19
18
 
20
19
  import type { P2PConfig } from '../config.js';
21
20
  import type { MemPools } from '../mem_pools/interface.js';
22
- import { DummyPeerDiscoveryService, DummyPeerManager, DummyReqResp, LibP2PService } from '../services/index.js';
23
- import type { ReqRespInterface } from '../services/reqresp/interface.js';
21
+ import { DummyPeerDiscoveryService, DummyPeerManager, LibP2PService } from '../services/index.js';
22
+ import type { P2PReqRespConfig } from '../services/reqresp/config.js';
23
+ import type { ConnectionSampler } from '../services/reqresp/connection-sampler/connection_sampler.js';
24
+ import {
25
+ type ReqRespInterface,
26
+ type ReqRespResponse,
27
+ type ReqRespSubProtocol,
28
+ type ReqRespSubProtocolHandler,
29
+ type ReqRespSubProtocolHandlers,
30
+ type ReqRespSubProtocolValidators,
31
+ type SubProtocolMap,
32
+ responseFromBuffer,
33
+ } from '../services/reqresp/interface.js';
34
+ import { ReqRespStatus } from '../services/reqresp/status.js';
24
35
  import { GossipSubEvent } from '../types/index.js';
25
36
  import type { PubSubLibp2p } from '../util.js';
26
37
 
@@ -30,11 +41,10 @@ type GossipSubService = PubSubLibp2p['services']['pubsub'];
30
41
  * Given a mock gossip sub network, returns a factory function that creates an instance LibP2PService connected to it.
31
42
  * Designed to be used in tests in P2PClientDeps.p2pServiceFactory.
32
43
  */
33
- export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
44
+ export function getMockPubSubP2PServiceFactory(
34
45
  network: MockGossipSubNetwork,
35
- ): (...args: Parameters<(typeof LibP2PService<T>)['new']>) => Promise<LibP2PService<T>> {
46
+ ): (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService> {
36
47
  return (
37
- clientType: P2PClientType,
38
48
  config: P2PConfig,
39
49
  peerId: PeerId,
40
50
  deps: {
@@ -52,10 +62,9 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
52
62
  deps.logger.verbose('Creating mock PubSub service');
53
63
  const libp2p = new MockPubSub(peerId, network);
54
64
  const peerManager = new DummyPeerManager(peerId, network);
55
- const reqresp: ReqRespInterface = new DummyReqResp();
65
+ const reqresp: ReqRespInterface = new MockReqResp(peerId, network);
56
66
  const peerDiscoveryService = new DummyPeerDiscoveryService();
57
- const service = new LibP2PService<T>(
58
- clientType as T,
67
+ const service = new LibP2PService(
59
68
  config,
60
69
  libp2p,
61
70
  peerDiscoveryService,
@@ -74,6 +83,115 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
74
83
  };
75
84
  }
76
85
 
86
+ /**
87
+ * Mock implementation of ReqRespInterface that routes requests to other peers' handlers through the mock network.
88
+ * When a peer calls sendBatchRequest, the mock iterates over network peers and invokes their registered handler
89
+ * for the sub-protocol, simulating the request-response protocol without actual libp2p streams.
90
+ */
91
+ class MockReqResp implements ReqRespInterface {
92
+ private handlers: Partial<ReqRespSubProtocolHandlers> = {};
93
+ private logger = createLogger('p2p:test:mock-reqresp');
94
+
95
+ constructor(
96
+ private peerId: PeerId,
97
+ private network: MockGossipSubNetwork,
98
+ ) {
99
+ network.registerReqRespPeer(this);
100
+ }
101
+
102
+ updateConfig(_config: Partial<P2PReqRespConfig>): void {}
103
+
104
+ start(
105
+ subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
106
+ _subProtocolValidators: ReqRespSubProtocolValidators,
107
+ ): Promise<void> {
108
+ Object.assign(this.handlers, subProtocolHandlers);
109
+ return Promise.resolve();
110
+ }
111
+
112
+ addSubProtocol(
113
+ subProtocol: ReqRespSubProtocol,
114
+ handler: ReqRespSubProtocolHandler,
115
+ _validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
116
+ ): Promise<void> {
117
+ this.handlers[subProtocol] = handler;
118
+ return Promise.resolve();
119
+ }
120
+
121
+ stop(): Promise<void> {
122
+ this.handlers = {};
123
+ return Promise.resolve();
124
+ }
125
+
126
+ getHandler(subProtocol: ReqRespSubProtocol): ReqRespSubProtocolHandler | undefined {
127
+ return this.handlers[subProtocol];
128
+ }
129
+
130
+ async sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
131
+ subProtocol: SubProtocol,
132
+ requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
133
+ pinnedPeer: PeerId | undefined,
134
+ _timeoutMs?: number,
135
+ _maxPeers?: number,
136
+ _maxRetryAttempts?: number,
137
+ ): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
138
+ const responses: InstanceType<SubProtocolMap[SubProtocol]['response']>[] = [];
139
+ const peers = this.network.getReqRespPeers().filter(p => !p.peerId.equals(this.peerId));
140
+ const targetPeers = pinnedPeer ? peers.filter(p => p.peerId.equals(pinnedPeer)) : peers;
141
+
142
+ for (const request of requests) {
143
+ const requestBuffer = request.toBuffer();
144
+ for (const peer of targetPeers) {
145
+ const handler = peer.getHandler(subProtocol);
146
+ if (!handler) {
147
+ continue;
148
+ }
149
+ try {
150
+ const responseBuffer = await handler(this.peerId, requestBuffer);
151
+ if (responseBuffer.length > 0) {
152
+ const response = responseFromBuffer(subProtocol, responseBuffer);
153
+ responses.push(response as InstanceType<SubProtocolMap[SubProtocol]['response']>);
154
+ break;
155
+ }
156
+ } catch (err) {
157
+ this.logger.debug(`Mock reqresp handler error from peer ${peer.peerId}`, { err });
158
+ }
159
+ }
160
+ }
161
+
162
+ return responses;
163
+ }
164
+
165
+ async sendRequestToPeer(
166
+ peerId: PeerId,
167
+ subProtocol: ReqRespSubProtocol,
168
+ payload: Buffer,
169
+ _dialTimeout?: number,
170
+ ): Promise<ReqRespResponse> {
171
+ const peer = this.network.getReqRespPeers().find(p => p.peerId.equals(peerId));
172
+ const handler = peer?.getHandler(subProtocol);
173
+ if (!handler) {
174
+ return { status: ReqRespStatus.SUCCESS, data: Buffer.from([]) };
175
+ }
176
+ try {
177
+ const data = await handler(this.peerId, payload);
178
+ return { status: ReqRespStatus.SUCCESS, data };
179
+ } catch {
180
+ return { status: ReqRespStatus.FAILURE };
181
+ }
182
+ }
183
+
184
+ getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'> {
185
+ return {
186
+ getPeerListSortedByConnectionCountAsc: () =>
187
+ this.network
188
+ .getReqRespPeers()
189
+ .filter(p => !p.peerId.equals(this.peerId))
190
+ .map(p => p.peerId),
191
+ };
192
+ }
193
+ }
194
+
77
195
  /**
78
196
  * Implementation of PubSub services that relies on a mock gossip sub network.
79
197
  * This is used in tests to simulate a gossip sub network without needing a real P2P network.
@@ -149,6 +267,16 @@ class MockGossipSubService extends TypedEventEmitter<GossipsubEvents> implements
149
267
  { msgId, propagationSource, acceptance },
150
268
  );
151
269
  }
270
+
271
+ getMeshPeers(topic?: TopicStr): PeerIdStr[] {
272
+ if (topic && !this.subscribedTopics.has(topic)) {
273
+ return [];
274
+ }
275
+ return this.network
276
+ .getPeers()
277
+ .filter(peer => !this.peerId.equals(peer))
278
+ .map(peer => peer.toString());
279
+ }
152
280
  }
153
281
 
154
282
  /**
@@ -157,6 +285,7 @@ class MockGossipSubService extends TypedEventEmitter<GossipsubEvents> implements
157
285
  */
158
286
  export class MockGossipSubNetwork {
159
287
  private peers: MockGossipSubService[] = [];
288
+ private reqRespPeers: MockReqResp[] = [];
160
289
  private nextMsgId = 0;
161
290
 
162
291
  private logger = createLogger('p2p:test:mock-gossipsub-network');
@@ -169,6 +298,14 @@ export class MockGossipSubNetwork {
169
298
  this.peers.push(peer);
170
299
  }
171
300
 
301
+ public registerReqRespPeer(peer: MockReqResp): void {
302
+ this.reqRespPeers.push(peer);
303
+ }
304
+
305
+ public getReqRespPeers(): MockReqResp[] {
306
+ return this.reqRespPeers;
307
+ }
308
+
172
309
  public publishToPeers(topic: TopicStr, data: Uint8Array, sender: PeerId): void {
173
310
  const msgId = (this.nextMsgId++).toString();
174
311
  this.logger.debug(`Network is distributing message on topic ${topic}`, {
@@ -12,7 +12,6 @@ import type {
12
12
  IVCProofVerificationResult,
13
13
  WorldStateSynchronizer,
14
14
  } from '@aztec/stdlib/interfaces/server';
15
- import type { P2PClientType } from '@aztec/stdlib/p2p';
16
15
  import type { Tx } from '@aztec/stdlib/tx';
17
16
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
18
17
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
@@ -107,8 +106,7 @@ export async function createLibp2pNode(
107
106
  *
108
107
  *
109
108
  */
110
- export async function createTestLibP2PService<T extends P2PClientType>(
111
- clientType: T,
109
+ export async function createTestLibP2PService(
112
110
  boostrapAddrs: string[] = [],
113
111
  archiver: L2BlockSource & ContractDataSource,
114
112
  worldStateSynchronizer: WorldStateSynchronizer,
@@ -159,8 +157,7 @@ export async function createTestLibP2PService<T extends P2PClientType>(
159
157
  p2pNode.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
160
158
  peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
161
159
 
162
- return new LibP2PService<T>(
163
- clientType,
160
+ return new LibP2PService(
164
161
  config,
165
162
  p2pNode as PubSubLibp2p,
166
163
  discoveryService,