@aztec/p2p 0.0.1-commit.001888fc → 0.0.1-commit.017a351

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 (403) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +9 -1
  4. package/dest/client/factory.d.ts +4 -3
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +28 -23
  7. package/dest/client/interface.d.ts +14 -5
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +13 -9
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +78 -20
  12. package/dest/config.d.ts +135 -99
  13. package/dest/config.d.ts.map +1 -1
  14. package/dest/config.js +62 -7
  15. package/dest/errors/p2p-service.error.d.ts +9 -0
  16. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  17. package/dest/errors/p2p-service.error.js +10 -0
  18. package/dest/errors/reqresp.error.d.ts +1 -20
  19. package/dest/errors/reqresp.error.d.ts.map +1 -1
  20. package/dest/errors/reqresp.error.js +0 -21
  21. package/dest/index.d.ts +1 -2
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +0 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +99 -59
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.js +265 -199
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +181 -65
  30. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
  31. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/mocks.js +6 -4
  33. package/dest/mem_pools/index.d.ts +1 -2
  34. package/dest/mem_pools/index.d.ts.map +1 -1
  35. package/dest/mem_pools/instrumentation.d.ts +1 -1
  36. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.js +17 -1
  38. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
  39. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
  41. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
  44. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  46. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  47. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
  48. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +8 -5
  49. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +5 -2
  51. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +13 -6
  53. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
  54. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +75 -84
  56. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +9 -3
  57. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  58. package/dest/msg_validators/attestation_validator/attestation_validator.js +37 -12
  59. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
  60. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  61. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  62. package/dest/msg_validators/clock_tolerance.d.ts +12 -1
  63. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  64. package/dest/msg_validators/clock_tolerance.js +56 -3
  65. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -2
  66. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -2
  68. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  69. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +10 -2
  70. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  71. package/dest/msg_validators/proposal_validator/proposal_validator.js +46 -12
  72. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  73. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  74. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
  75. package/dest/msg_validators/tx_validator/allowed_public_setup.js +3 -3
  76. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  77. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  78. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  79. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  80. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  81. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  82. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  83. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  84. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  85. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  86. package/dest/msg_validators/tx_validator/factory.d.ts +6 -5
  87. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  88. package/dest/msg_validators/tx_validator/factory.js +21 -11
  89. package/dest/msg_validators/tx_validator/gas_validator.d.ts +36 -4
  90. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  91. package/dest/msg_validators/tx_validator/gas_validator.js +50 -33
  92. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  93. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  94. package/dest/msg_validators/tx_validator/index.js +2 -0
  95. package/dest/msg_validators/tx_validator/phases_validator.js +1 -1
  96. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  97. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  99. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  100. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  101. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  102. package/dest/services/data_store.d.ts +1 -1
  103. package/dest/services/data_store.d.ts.map +1 -1
  104. package/dest/services/data_store.js +5 -5
  105. package/dest/services/discv5/discV5_service.d.ts +2 -1
  106. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  107. package/dest/services/discv5/discV5_service.js +35 -8
  108. package/dest/services/dummy_service.d.ts +11 -15
  109. package/dest/services/dummy_service.d.ts.map +1 -1
  110. package/dest/services/dummy_service.js +12 -16
  111. package/dest/services/encoding.d.ts +5 -1
  112. package/dest/services/encoding.d.ts.map +1 -1
  113. package/dest/services/encoding.js +7 -1
  114. package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
  115. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  116. package/dest/services/gossipsub/topic_score_params.js +21 -4
  117. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  118. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  119. package/dest/services/libp2p/instrumentation.js +14 -0
  120. package/dest/services/libp2p/libp2p_service.d.ts +36 -46
  121. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  122. package/dest/services/libp2p/libp2p_service.js +272 -262
  123. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  124. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  125. package/dest/services/peer-manager/peer_manager.js +38 -10
  126. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  127. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  128. package/dest/services/peer-manager/peer_scoring.js +32 -10
  129. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -14
  130. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  131. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +78 -100
  132. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +8 -6
  133. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  134. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +4 -4
  135. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  136. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +7 -7
  137. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  138. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  139. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  140. package/dest/services/reqresp/config.d.ts +3 -3
  141. package/dest/services/reqresp/config.d.ts.map +1 -1
  142. package/dest/services/reqresp/interface.d.ts +16 -18
  143. package/dest/services/reqresp/interface.d.ts.map +1 -1
  144. package/dest/services/reqresp/interface.js +10 -20
  145. package/dest/services/reqresp/metrics.d.ts +1 -1
  146. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  147. package/dest/services/reqresp/metrics.js +0 -1
  148. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  149. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  150. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  151. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  152. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  153. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
  154. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
  155. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  156. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
  157. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  158. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  159. package/dest/services/reqresp/protocols/index.js +0 -1
  160. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  161. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  162. package/dest/services/reqresp/protocols/tx.js +1 -3
  163. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  164. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  165. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  166. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  167. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  168. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  169. package/dest/services/reqresp/reqresp.d.ts +7 -29
  170. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  171. package/dest/services/reqresp/reqresp.js +41 -214
  172. package/dest/services/service.d.ts +9 -12
  173. package/dest/services/service.d.ts.map +1 -1
  174. package/dest/services/tx_collection/config.d.ts +2 -23
  175. package/dest/services/tx_collection/config.d.ts.map +1 -1
  176. package/dest/services/tx_collection/config.js +2 -55
  177. package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
  178. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  179. package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
  180. package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
  181. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  182. package/dest/services/tx_collection/file_store_tx_source.js +39 -29
  183. package/dest/services/tx_collection/index.d.ts +2 -3
  184. package/dest/services/tx_collection/index.d.ts.map +1 -1
  185. package/dest/services/tx_collection/index.js +0 -1
  186. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  187. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  188. package/dest/services/tx_collection/instrumentation.js +0 -2
  189. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  190. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  191. package/dest/services/tx_collection/request_tracker.js +84 -0
  192. package/dest/services/tx_collection/tx_collection.d.ts +36 -55
  193. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  194. package/dest/services/tx_collection/tx_collection.js +275 -119
  195. package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
  196. package/dest/services/tx_collection/tx_collection_sink.js +2 -2
  197. package/dest/services/tx_collection/tx_source.d.ts +6 -5
  198. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  199. package/dest/services/tx_collection/tx_source.js +9 -7
  200. package/dest/services/tx_file_store/tx_file_store.d.ts +1 -3
  201. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  202. package/dest/services/tx_file_store/tx_file_store.js +4 -14
  203. package/dest/services/tx_provider.d.ts +3 -1
  204. package/dest/services/tx_provider.d.ts.map +1 -1
  205. package/dest/services/tx_provider.js +3 -0
  206. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  207. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  208. package/dest/test-helpers/make-test-p2p-clients.js +5 -2
  209. package/dest/test-helpers/mock-pubsub.d.ts +23 -9
  210. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  211. package/dest/test-helpers/mock-pubsub.js +44 -44
  212. package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
  213. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  214. package/dest/test-helpers/reqresp-nodes.js +16 -18
  215. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  216. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  217. package/dest/test-helpers/test_tx_provider.js +3 -0
  218. package/dest/test-helpers/testbench-utils.d.ts +12 -14
  219. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  220. package/dest/test-helpers/testbench-utils.js +38 -14
  221. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  222. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  223. package/dest/testbench/p2p_client_testbench_worker.js +83 -38
  224. package/dest/testbench/worker_client_manager.d.ts +10 -6
  225. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  226. package/dest/testbench/worker_client_manager.js +51 -9
  227. package/dest/util.d.ts +11 -6
  228. package/dest/util.d.ts.map +1 -1
  229. package/dest/util.js +35 -14
  230. package/dest/versioning.d.ts +3 -6
  231. package/dest/versioning.d.ts.map +1 -1
  232. package/dest/versioning.js +3 -24
  233. package/package.json +15 -14
  234. package/src/bootstrap/bootstrap.ts +9 -1
  235. package/src/client/factory.ts +48 -23
  236. package/src/client/interface.ts +15 -11
  237. package/src/client/p2p_client.ts +91 -41
  238. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  239. package/src/config.ts +123 -6
  240. package/src/errors/p2p-service.error.ts +11 -0
  241. package/src/errors/reqresp.error.ts +0 -25
  242. package/src/index.ts +0 -1
  243. package/src/mem_pools/attestation_pool/attestation_pool.ts +316 -241
  244. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +204 -68
  245. package/src/mem_pools/attestation_pool/mocks.ts +13 -8
  246. package/src/mem_pools/index.ts +0 -3
  247. package/src/mem_pools/instrumentation.ts +5 -1
  248. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
  249. package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
  250. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  251. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
  252. package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
  253. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +20 -8
  254. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +75 -90
  255. package/src/msg_validators/attestation_validator/README.md +1 -1
  256. package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -9
  257. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +14 -7
  258. package/src/msg_validators/clock_tolerance.ts +73 -3
  259. package/src/msg_validators/proposal_validator/README.md +4 -4
  260. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +12 -2
  261. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +17 -2
  262. package/src/msg_validators/proposal_validator/proposal_validator.ts +54 -10
  263. package/src/msg_validators/tx_validator/README.md +11 -3
  264. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
  265. package/src/msg_validators/tx_validator/allowed_public_setup.ts +3 -3
  266. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  267. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  268. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  269. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  270. package/src/msg_validators/tx_validator/factory.ts +25 -7
  271. package/src/msg_validators/tx_validator/gas_validator.ts +82 -33
  272. package/src/msg_validators/tx_validator/index.ts +2 -0
  273. package/src/msg_validators/tx_validator/phases_validator.ts +1 -1
  274. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  275. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  276. package/src/services/data_store.ts +5 -13
  277. package/src/services/discv5/discV5_service.ts +38 -5
  278. package/src/services/dummy_service.ts +14 -39
  279. package/src/services/encoding.ts +9 -1
  280. package/src/services/gossipsub/topic_score_params.ts +36 -4
  281. package/src/services/libp2p/instrumentation.ts +14 -0
  282. package/src/services/libp2p/libp2p_service.ts +302 -300
  283. package/src/services/peer-manager/peer_manager.ts +44 -10
  284. package/src/services/peer-manager/peer_scoring.ts +27 -5
  285. package/src/services/reqresp/README.md +0 -14
  286. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  287. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +74 -112
  288. package/src/services/reqresp/batch-tx-requester/interface.ts +11 -5
  289. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +6 -6
  290. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  291. package/src/services/reqresp/config.ts +2 -2
  292. package/src/services/reqresp/interface.ts +21 -47
  293. package/src/services/reqresp/metrics.ts +0 -1
  294. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  295. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
  296. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
  297. package/src/services/reqresp/protocols/index.ts +0 -1
  298. package/src/services/reqresp/protocols/tx.ts +1 -3
  299. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  300. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  301. package/src/services/reqresp/reqresp.ts +45 -260
  302. package/src/services/service.ts +12 -28
  303. package/src/services/tx_collection/config.ts +3 -80
  304. package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
  305. package/src/services/tx_collection/file_store_tx_source.ts +43 -31
  306. package/src/services/tx_collection/index.ts +1 -6
  307. package/src/services/tx_collection/instrumentation.ts +1 -7
  308. package/src/services/tx_collection/request_tracker.ts +127 -0
  309. package/src/services/tx_collection/tx_collection.ts +331 -176
  310. package/src/services/tx_collection/tx_collection_sink.ts +2 -2
  311. package/src/services/tx_collection/tx_source.ts +8 -7
  312. package/src/services/tx_file_store/tx_file_store.ts +5 -17
  313. package/src/services/tx_provider.ts +5 -0
  314. package/src/test-helpers/make-test-p2p-clients.ts +3 -0
  315. package/src/test-helpers/mock-pubsub.ts +46 -60
  316. package/src/test-helpers/reqresp-nodes.ts +12 -22
  317. package/src/test-helpers/test_tx_provider.ts +5 -0
  318. package/src/test-helpers/testbench-utils.ts +50 -28
  319. package/src/testbench/p2p_client_testbench_worker.ts +87 -54
  320. package/src/testbench/worker_client_manager.ts +59 -20
  321. package/src/util.ts +32 -17
  322. package/src/versioning.ts +3 -33
  323. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  324. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  325. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -304
  326. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  327. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  328. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  329. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  330. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  331. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  332. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  333. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  334. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  335. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  336. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  337. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  338. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  339. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  340. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -123
  341. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  342. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  343. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  344. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  345. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  346. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  347. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  348. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  349. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  350. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  351. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  352. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  353. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  354. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  355. package/dest/mem_pools/tx_pool/index.js +0 -2
  356. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  357. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  358. package/dest/mem_pools/tx_pool/priority.js +0 -15
  359. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  360. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  361. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  362. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  363. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  364. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -402
  365. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  366. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  367. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  368. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  369. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  370. package/dest/services/reqresp/protocols/block.js +0 -32
  371. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -54
  372. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  373. package/dest/services/tx_collection/fast_tx_collection.js +0 -327
  374. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  375. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  376. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  377. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -49
  378. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  379. package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
  380. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
  381. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  382. package/dest/services/tx_collection/slow_tx_collection.js +0 -211
  383. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -345
  384. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  385. package/src/mem_pools/tx_pool/README.md +0 -270
  386. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  387. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  388. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  389. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -163
  390. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  391. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  392. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  393. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  394. package/src/mem_pools/tx_pool/index.ts +0 -2
  395. package/src/mem_pools/tx_pool/priority.ts +0 -20
  396. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  397. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -321
  398. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  399. package/src/services/reqresp/protocols/block.ts +0 -37
  400. package/src/services/tx_collection/fast_tx_collection.ts +0 -387
  401. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
  402. package/src/services/tx_collection/proposal_tx_collector.ts +0 -113
  403. package/src/services/tx_collection/slow_tx_collection.ts +0 -266
@@ -1,15 +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';
10
+ import { strict as assert } from 'assert';
11
11
 
12
- import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
12
+ import type { IRequestTracker } from '../../tx_collection/request_tracker.js';
13
13
  import { ReqRespSubProtocol } from '.././interface.js';
14
14
  import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
15
15
  import { ReqRespStatus } from '.././status.js';
@@ -22,7 +22,7 @@ import {
22
22
  import type { BatchTxRequesterLibP2PService, BatchTxRequesterOptions, ITxMetadataCollection } from './interface.js';
23
23
  import { MissingTxMetadataCollection } from './missing_txs.js';
24
24
  import { type IPeerCollection, PeerCollection } from './peer_collection.js';
25
- import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_validator.js';
25
+ import { createBatchRequestTxValidator } from './tx_validator.js';
26
26
 
27
27
  /*
28
28
  * Tries to fetch all missing transaction until deadline is hit.
@@ -42,39 +42,35 @@ import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_val
42
42
  * - Is the peer which was unable to send us successful response N times in a row
43
43
  * */
44
44
  export class BatchTxRequester {
45
+ private readonly requestTracker: IRequestTracker;
45
46
  private readonly blockTxsSource: BlockTxsSource;
46
47
  private readonly pinnedPeer: PeerId | undefined;
47
- private readonly timeoutMs: number;
48
48
  private readonly p2pService: BatchTxRequesterLibP2PService;
49
49
  private readonly logger: Logger;
50
- private readonly dateProvider: DateProvider;
51
50
  private readonly opts: BatchTxRequesterOptions;
52
51
  private readonly peers: IPeerCollection;
53
52
  private readonly txsMetadata: ITxMetadataCollection;
54
- private readonly deadline: number;
55
53
  private readonly smartRequesterSemaphore: ISemaphore;
56
54
  private readonly txQueue: FifoMemoryQueue<Tx>;
57
- private readonly txValidator: IBatchRequestTxValidator;
55
+ private readonly txValidator: TxValidator;
58
56
  private readonly smartParallelWorkerCount: number;
59
57
  private readonly dumbParallelWorkerCount: number;
60
58
  private readonly txBatchSize: number;
61
59
 
62
60
  constructor(
63
- missingTxsTracker: IMissingTxsTracker,
61
+ requestTracker: IRequestTracker,
64
62
  blockTxsSource: BlockTxsSource,
65
63
  pinnedPeer: PeerId | undefined,
66
- timeoutMs: number,
67
64
  p2pService: BatchTxRequesterLibP2PService,
68
65
  logger?: Logger,
69
66
  dateProvider?: DateProvider,
70
67
  opts?: BatchTxRequesterOptions,
71
68
  ) {
69
+ this.requestTracker = requestTracker;
72
70
  this.blockTxsSource = blockTxsSource;
73
71
  this.pinnedPeer = pinnedPeer;
74
- this.timeoutMs = timeoutMs;
75
72
  this.p2pService = p2pService;
76
73
  this.logger = logger ?? createLogger('p2p:reqresp_batch');
77
- this.dateProvider = dateProvider ?? new DateProvider();
78
74
  this.opts = opts ?? {};
79
75
 
80
76
  this.smartParallelWorkerCount =
@@ -82,9 +78,8 @@ export class BatchTxRequester {
82
78
  this.dumbParallelWorkerCount =
83
79
  this.opts.dumbParallelWorkerCount ?? DEFAULT_BATCH_TX_REQUESTER_DUMB_PARALLEL_WORKER_COUNT;
84
80
  this.txBatchSize = this.opts.txBatchSize ?? DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE;
85
- this.deadline = this.dateProvider.now() + this.timeoutMs;
86
81
  this.txQueue = new FifoMemoryQueue(this.logger);
87
- this.txValidator = this.opts.txValidator ?? new BatchRequestTxValidator(this.p2pService.txValidatorConfig);
82
+ this.txValidator = this.opts.txValidator ?? createBatchRequestTxValidator(this.p2pService.txValidatorConfig);
88
83
 
89
84
  if (this.opts.peerCollection) {
90
85
  this.peers = this.opts.peerCollection;
@@ -93,53 +88,43 @@ export class BatchTxRequester {
93
88
  this.peers = new PeerCollection(
94
89
  this.p2pService.connectionSampler,
95
90
  this.pinnedPeer,
96
- this.dateProvider,
91
+ dateProvider ?? new DateProvider(),
97
92
  badPeerThreshold,
98
93
  this.p2pService.peerScoring,
99
94
  );
100
95
  }
101
- this.txsMetadata = new MissingTxMetadataCollection(missingTxsTracker, this.txBatchSize);
96
+ this.txsMetadata = new MissingTxMetadataCollection(requestTracker, this.txBatchSize);
102
97
  this.smartRequesterSemaphore = this.opts.semaphore ?? new Semaphore(0);
103
98
  }
104
99
 
105
100
  /*
106
- * Fetches all missing transactions and yields them one by one
101
+ * Fetches all missing transactions and yields them one by one
107
102
  * */
108
103
  public async *run(): AsyncGenerator<Tx, Tx | undefined, unknown> {
109
- // Our timeout is represented in milliseconds but queue expects seconds
110
- // We also want to make sure we wait at least 1 second in case of very low timeouts
111
- const timeoutQueueAfter = Math.max(Math.ceil(this.timeoutMs / 1_000), 1);
112
104
  try {
113
105
  if (this.txsMetadata.getMissingTxHashes().size === 0) {
114
106
  return undefined;
115
107
  }
116
108
 
117
- // Start workers in background
118
- const workersPromise = executeTimeout(
119
- () => Promise.allSettled([this.smartRequester(), this.dumbRequester(), this.pinnedPeerRequester()]),
120
- this.timeoutMs,
121
- ).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(() => {
122
115
  this.txQueue.end();
123
116
  });
124
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.
125
120
  while (true) {
126
- const tx = await this.txQueue.get(timeoutQueueAfter);
121
+ const tx = await this.txQueue.get();
127
122
 
128
- // null indicates that the queue has ended
129
123
  if (tx === null) {
130
124
  break;
131
125
  }
132
126
 
133
127
  yield tx;
134
-
135
- if (this.shouldStop()) {
136
- // Drain queue before ending
137
- let remaining;
138
- while ((remaining = this.txQueue.getImmediate()) !== undefined) {
139
- yield remaining;
140
- }
141
- break;
142
- }
143
128
  }
144
129
 
145
130
  this.unlockSmartRequesterSemaphores();
@@ -360,7 +345,10 @@ export class BatchTxRequester {
360
345
  ) {
361
346
  try {
362
347
  this.logger.trace(`Smart worker ${workerIndex} started`);
363
- 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
+ }
364
352
  this.logger.trace(`Smart worker ${workerIndex} acquired semaphore`);
365
353
 
366
354
  while (!this.shouldStop()) {
@@ -384,7 +372,10 @@ export class BatchTxRequester {
384
372
  //
385
373
  // When a dumb peer responds with valid txIndices, it gets
386
374
  // promoted to smart and releases the semaphore, waking this worker.
387
- 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
+ }
388
379
  this.logger.debug(`Worker loop smart: acquired next smart peer`);
389
380
  continue;
390
381
  }
@@ -411,11 +402,7 @@ export class BatchTxRequester {
411
402
  });
412
403
  }
413
404
  } catch (err: any) {
414
- if (err instanceof TimeoutError) {
415
- this.logger.debug(`Smart worker ${workerIndex} timed out waiting for semaphore`);
416
- } else {
417
- this.logger.error(`Smart worker ${workerIndex} encountered an error: ${err}`);
418
- }
405
+ this.logger.error(`Smart worker ${workerIndex} encountered an error: ${err}`);
419
406
  } finally {
420
407
  this.logger.debug(`Smart worker ${workerIndex} finished`);
421
408
  }
@@ -442,6 +429,15 @@ export class BatchTxRequester {
442
429
  }
443
430
 
444
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
+
445
441
  await this.handleSuccessResponseFromPeer(peerId, blockResponse);
446
442
  } catch (err: any) {
447
443
  this.logger.error(`Failed to get valid response from peer ${peerId.toString()}: ${err.message}`, {
@@ -459,27 +455,24 @@ export class BatchTxRequester {
459
455
  * Handles failed response form the peer
460
456
  * There are 3 scenarios
461
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.
462
459
  * - FAILURE and UNKNOWN: We penalise this, if peer has been penalised this way N times they are not queried again
463
460
  * this implies we will query these peers couple of more times and give them a chance to "redeem" themselves before completely ignoring them
464
461
  */
465
462
  private handleFailResponseFromPeer(peerId: PeerId, responseStatus: ReqRespStatus) {
466
- if (responseStatus === ReqRespStatus.FAILURE || responseStatus === ReqRespStatus.UNKNOWN) {
467
- this.peers.penalisePeer(peerId, PeerErrorSeverity.HighToleranceError);
468
- this.peers.markPeerDumb(peerId);
469
- this.txsMetadata.clearPeerData(peerId);
470
- return;
471
- }
472
-
473
- // NOT_FOUND means the peer pruned its block proposal — it can no longer serve
474
- // index-based requests, but this is a legitimate state so we don't penalize.
475
- if (responseStatus === ReqRespStatus.NOT_FOUND) {
476
- this.peers.markPeerDumb(peerId);
477
- this.txsMetadata.clearPeerData(peerId);
478
- return;
479
- }
480
-
481
- if (responseStatus === ReqRespStatus.RATE_LIMIT_EXCEEDED) {
482
- 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;
483
476
  }
484
477
  }
485
478
 
@@ -499,7 +492,7 @@ export class BatchTxRequester {
499
492
  * Handles received txs.
500
493
  * Transactions are validated and then put on async queue
501
494
  * to be yielded by main running loop
502
- * */
495
+ */
503
496
  private async handleReceivedTxs(peerId: PeerId, txs: TxArray) {
504
497
  const newTxs = txs.filter(tx => !this.txsMetadata.alreadyFetched(tx.txHash));
505
498
 
@@ -507,12 +500,12 @@ export class BatchTxRequester {
507
500
  return;
508
501
  }
509
502
 
510
- //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
511
504
  // We could use the async queue for communication.
512
505
  const validationResults = await Promise.allSettled(
513
506
  newTxs.map(async tx => ({
514
507
  tx,
515
- isValid: (await this.txValidator.validateRequestedTx(tx)).result === 'valid',
508
+ isValid: (await this.txValidator.validateTx(tx)).result === 'valid',
516
509
  })),
517
510
  );
518
511
 
@@ -528,6 +521,9 @@ export class BatchTxRequester {
528
521
  });
529
522
 
530
523
  if (hasInvalidTx) {
524
+ this.logger.warn(`Penalizing peer ${peerId.toString()} for sending invalid transactions in batch response`, {
525
+ peerId,
526
+ });
531
527
  this.peers.penalisePeer(peerId, PeerErrorSeverity.LowToleranceError);
532
528
  } else {
533
529
  // If we have received successful response from the peer, they have "redeemed" themselves and not considered bad anymore
@@ -564,9 +560,10 @@ export class BatchTxRequester {
564
560
  return;
565
561
  }
566
562
 
567
- const hasArchiveRootMismatch = this.blockTxsSource.archive.toString() !== response.archiveRoot.toString();
568
- if (hasArchiveRootMismatch) {
569
- this.handleArchiveRootMismatch(peerId, 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);
570
567
  return;
571
568
  }
572
569
 
@@ -584,21 +581,6 @@ export class BatchTxRequester {
584
581
  this.smartRequesterSemaphore.release();
585
582
  }
586
583
 
587
- /**
588
- * Handles an archive root mismatch between local state and peer response.
589
- *
590
- * - Response archive is Fr.ZERO (peer pruned proposal, legitimate): marks peer dumb.
591
- * - Non-zero archive mismatch (malicious response): penalises + marks dumb.
592
- */
593
- private handleArchiveRootMismatch(peerId: PeerId, response: BlockTxsResponse): void {
594
- if (!response.archiveRoot.isZero()) {
595
- this.peers.penalisePeer(peerId, PeerErrorSeverity.LowToleranceError);
596
- }
597
-
598
- this.peers.markPeerDumb(peerId);
599
- this.txsMetadata.clearPeerData(peerId);
600
- }
601
-
602
584
  private peerHasSomeTxsWeAreMissing(_peerId: PeerId, response: BlockTxsResponse): boolean {
603
585
  if (response.txIndices.isEmpty()) {
604
586
  return false;
@@ -614,15 +596,9 @@ export class BatchTxRequester {
614
596
  }
615
597
 
616
598
  private extractHashesPeerHasFromResponse(response: BlockTxsResponse): Array<TxHash> {
617
- const hashes: TxHash[] = [];
618
- const indicesOfHashesPeerHas = new Set(response.txIndices.getTrueIndices());
619
- this.blockTxsSource.txHashes.forEach((hash, idx) => {
620
- if (indicesOfHashesPeerHas.has(idx)) {
621
- hashes.push(hash);
622
- }
623
- });
624
-
625
- 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]);
626
602
  }
627
603
 
628
604
  /*
@@ -651,27 +627,14 @@ export class BatchTxRequester {
651
627
  }
652
628
 
653
629
  /*
654
- * @returns true if all missing txs have been fetched */
655
- private fetchedAllTxs() {
656
- return this.txsMetadata.getMissingTxHashes().size == 0;
657
- }
658
-
659
- /*
660
- * Checks if the BatchTxRequester should stop fetching missing txs
661
- * Conditions for stopping are:
662
- * - There have been no missing transactions to start with
663
- * - All transactions have been fetched
664
- * - The deadline has been hit (no more time to fetch)
665
- * - This process has been cancelled via abortSignal
666
- *
667
- * @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. */
668
632
  private shouldStop() {
669
- const aborted = this.opts.abortSignal?.aborted ?? false;
670
- if (aborted) {
633
+ if (this.requestTracker.checkCancelled()) {
671
634
  this.unlockSmartRequesterSemaphores();
672
635
  }
673
636
 
674
- return aborted || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
637
+ return this.requestTracker.checkCancelled();
675
638
  }
676
639
 
677
640
  /*
@@ -689,10 +652,9 @@ export class BatchTxRequester {
689
652
  * This ensures we don't sleep past the deadline.
690
653
  * */
691
654
  private async sleepClampedToDeadline(durationMs: number) {
692
- const remaining = this.deadline - this.dateProvider.now();
693
- const thereIsTimeRemaining = remaining > 0;
694
- if (thereIsTimeRemaining) {
695
- await sleep(Math.min(durationMs, remaining));
655
+ if (this.requestTracker.checkCancelled()) {
656
+ return;
696
657
  }
658
+ await Promise.race([sleep(durationMs), this.requestTracker.cancellationToken]);
697
659
  }
698
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;
@@ -32,13 +33,19 @@ export interface ITxMetadataCollection {
32
33
  */
33
34
  export interface BatchTxRequesterLibP2PService {
34
35
  /** ReqResp interface for sending requests to peers */
35
- reqResp: Pick<ReqRespInterface, 'sendBatchRequest' | 'sendRequestToPeer'>;
36
+ reqResp: Pick<ReqRespInterface, 'sendRequestToPeer'>;
36
37
  /** Connection sampler for getting peer lists */
37
38
  connectionSampler: Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>;
38
39
  /** Configuration needed for transaction validation */
39
40
  txValidatorConfig: BatchRequestTxValidatorConfig;
40
41
  /** Peer scoring for penalizing peers */
41
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>;
42
49
  }
43
50
 
44
51
  export interface BatchTxRequesterOptions {
@@ -49,7 +56,6 @@ export interface BatchTxRequesterOptions {
49
56
  //Injectable for testing purposes
50
57
  semaphore?: ISemaphore;
51
58
  peerCollection?: IPeerCollection;
52
- abortSignal?: AbortSignal;
53
59
  /** Optional tx validator for testing - if not provided, one is created from p2pService.txValidatorConfig */
54
- txValidator?: IBatchRequestTxValidator;
60
+ txValidator?: TxValidator;
55
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[]) {
@@ -1,37 +1,24 @@
1
1
  import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
2
- import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
2
+ import type { TxValidator } from '@aztec/stdlib/tx';
3
3
 
4
- import { createTxValidatorForReqResponseReceivedTxs } from '../../../msg_validators/index.js';
4
+ import { createTxValidatorForOnDemandReceivedTxs } from '../../../msg_validators/index.js';
5
+ import type { TxValidationCache } from '../../../msg_validators/tx_validator/tx_validation_cache.js';
5
6
 
6
7
  export interface BatchRequestTxValidatorConfig {
7
8
  l1ChainId: number;
8
9
  rollupVersion: number;
9
10
  proofVerifier: ClientProtocolCircuitVerifier;
11
+ txValidationCache?: TxValidationCache;
10
12
  }
11
13
 
12
- export interface IBatchRequestTxValidator {
13
- validateRequestedTx(tx: Tx): Promise<TxValidationResult>;
14
- validateRequestedTxs(txs: Tx[]): Promise<TxValidationResult[]>;
15
- }
16
-
17
- export class BatchRequestTxValidator implements IBatchRequestTxValidator {
18
- readonly txValidator: TxValidator;
19
- constructor(private readonly config: BatchRequestTxValidatorConfig) {
20
- this.txValidator = BatchRequestTxValidator.createRequestedTxValidator(this.config);
21
- }
22
-
23
- public async validateRequestedTx(tx: Tx): Promise<TxValidationResult> {
24
- return await this.txValidator.validateTx(tx);
25
- }
26
-
27
- public async validateRequestedTxs(txs: Tx[]): Promise<TxValidationResult[]> {
28
- return await Promise.all(txs.map(tx => this.validateRequestedTx(tx)));
29
- }
30
-
31
- static createRequestedTxValidator(config: BatchRequestTxValidatorConfig): TxValidator {
32
- return createTxValidatorForReqResponseReceivedTxs(config.proofVerifier, {
14
+ export function createBatchRequestTxValidator(config: BatchRequestTxValidatorConfig): TxValidator {
15
+ return createTxValidatorForOnDemandReceivedTxs(
16
+ config.proofVerifier,
17
+ {
33
18
  l1ChainId: config.l1ChainId,
34
19
  rollupVersion: config.rollupVersion,
35
- });
36
- }
20
+ },
21
+ /*bindings=*/ undefined,
22
+ config.txValidationCache,
23
+ );
37
24
  }
@@ -1,4 +1,4 @@
1
- import { type ConfigMapping, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
1
+ import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
2
2
 
3
3
  export const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS = 10_000;
4
4
  export const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS = 10_000; // Not currently used
@@ -27,7 +27,7 @@ export interface P2PReqRespConfig {
27
27
  dialTimeoutMs: number;
28
28
  }
29
29
 
30
- export const p2pReqRespConfigMappings: Record<keyof P2PReqRespConfig, ConfigMapping> = {
30
+ export const p2pReqRespConfigMappings: ConfigMappingsType<P2PReqRespConfig> = {
31
31
  overallRequestTimeoutMs: {
32
32
  env: 'P2P_REQRESP_OVERALL_REQUEST_TIMEOUT_MS',
33
33
  description: 'The overall timeout for a request response operation.',
@@ -1,6 +1,3 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { L2Block } from '@aztec/stdlib/block';
3
- import { MAX_L2_BLOCK_SIZE_KB } from '@aztec/stdlib/p2p';
4
1
  import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
5
2
 
6
3
  import type { PeerId } from '@libp2p/interface';
@@ -24,7 +21,6 @@ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
24
21
  export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
25
22
  export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
26
23
  export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
27
- export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
28
24
  export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
29
25
  export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
30
26
 
@@ -33,7 +29,6 @@ export enum ReqRespSubProtocol {
33
29
  STATUS = STATUS_PROTOCOL,
34
30
  GOODBYE = GOODBYE_PROTOCOL,
35
31
  TX = TX_REQ_PROTOCOL,
36
- BLOCK = BLOCK_REQ_PROTOCOL,
37
32
  AUTH = AUTH_PROTOCOL,
38
33
  BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
39
34
  }
@@ -83,32 +78,28 @@ export interface ProtocolRateLimitQuota {
83
78
  globalLimit: RateLimitQuota;
84
79
  }
85
80
 
86
- export const noopValidator = () => Promise.resolve(true);
87
-
88
81
  /**
89
82
  * A type mapping from supprotocol to it's handling function
90
83
  */
91
84
  export type ReqRespSubProtocolHandlers = Record<ReqRespSubProtocol, ReqRespSubProtocolHandler>;
92
85
 
93
- type ResponseValidator<RequestIdentifier, Response> = (
94
- request: RequestIdentifier,
95
- response: Response,
96
- peerId: PeerId,
97
- ) => Promise<boolean>;
98
-
99
- export type ReqRespSubProtocolValidators = {
100
- [S in ReqRespSubProtocol]: ResponseValidator<any, any>;
101
- };
86
+ /**
87
+ * Protocols that are always allowed without authentication, even when p2pAllowOnlyValidators is enabled.
88
+ * These are needed for the handshake and connection management flow.
89
+ * All other protocols require the remote peer to be authenticated.
90
+ */
91
+ export const UNAUTHENTICATED_ALLOWED_PROTOCOLS: ReadonlySet<ReqRespSubProtocol> = new Set([
92
+ ReqRespSubProtocol.PING,
93
+ ReqRespSubProtocol.STATUS,
94
+ ReqRespSubProtocol.AUTH,
95
+ ReqRespSubProtocol.GOODBYE,
96
+ ]);
102
97
 
103
- export const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
104
- [ReqRespSubProtocol.PING]: noopValidator,
105
- [ReqRespSubProtocol.STATUS]: noopValidator,
106
- [ReqRespSubProtocol.TX]: noopValidator,
107
- [ReqRespSubProtocol.GOODBYE]: noopValidator,
108
- [ReqRespSubProtocol.BLOCK]: noopValidator,
109
- [ReqRespSubProtocol.AUTH]: noopValidator,
110
- [ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
111
- };
98
+ /**
99
+ * Callback that checks whether a peer should be rejected from req/resp data protocols.
100
+ * Returns true if the peer should be rejected (i.e. p2pAllowOnlyValidators is on and peer is unauthenticated).
101
+ */
102
+ export type ShouldRejectPeer = (peerId: string) => boolean;
112
103
 
113
104
  /*
114
105
  * Helper class to sub-protocol validation error*/
@@ -203,10 +194,6 @@ export const subProtocolMap = {
203
194
  request: RequestableBuffer,
204
195
  response: RequestableBuffer,
205
196
  },
206
- [ReqRespSubProtocol.BLOCK]: {
207
- request: Fr, // block number
208
- response: L2Block,
209
- },
210
197
  [ReqRespSubProtocol.AUTH]: {
211
198
  request: AuthRequest,
212
199
  response: AuthResponse,
@@ -229,7 +216,6 @@ export type ExpectedResponseSizeCalculator = (requestBuffer: Buffer) => number;
229
216
  export const subProtocolSizeCalculators: Record<ReqRespSubProtocol, ExpectedResponseSizeCalculator> = {
230
217
  [ReqRespSubProtocol.TX]: calculateTxResponseSize,
231
218
  [ReqRespSubProtocol.BLOCK_TXS]: calculateBlockTxsResponseSize,
232
- [ReqRespSubProtocol.BLOCK]: () => MAX_L2_BLOCK_SIZE_KB,
233
219
  [ReqRespSubProtocol.STATUS]: () => 1,
234
220
  [ReqRespSubProtocol.PING]: () => 1,
235
221
  [ReqRespSubProtocol.AUTH]: () => 1,
@@ -237,24 +223,9 @@ export const subProtocolSizeCalculators: Record<ReqRespSubProtocol, ExpectedResp
237
223
  };
238
224
 
239
225
  export interface ReqRespInterface {
240
- start(
241
- subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
242
- subProtocolValidators: ReqRespSubProtocolValidators,
243
- ): Promise<void>;
244
- addSubProtocol(
245
- subProtocol: ReqRespSubProtocol,
246
- handler: ReqRespSubProtocolHandler,
247
- validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
248
- ): Promise<void>;
226
+ start(subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>): Promise<void>;
227
+ addSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void>;
249
228
  stop(): Promise<void>;
250
- sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
251
- subProtocol: SubProtocol,
252
- requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
253
- pinnedPeer: PeerId | undefined,
254
- timeoutMs?: number,
255
- maxPeers?: number,
256
- maxRetryAttempts?: number,
257
- ): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
258
229
  sendRequestToPeer(
259
230
  peerId: PeerId,
260
231
  subProtocol: ReqRespSubProtocol,
@@ -264,5 +235,8 @@ export interface ReqRespInterface {
264
235
 
265
236
  updateConfig(config: Partial<P2PReqRespConfig>): void;
266
237
 
238
+ /** Sets the callback used to reject unauthenticated peers on gated req/resp protocols. */
239
+ setShouldRejectPeer(checker: ShouldRejectPeer): void;
240
+
267
241
  getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>;
268
242
  }
@@ -26,7 +26,6 @@ export class ReqRespMetrics {
26
26
  ReqRespSubProtocol.STATUS,
27
27
  ReqRespSubProtocol.GOODBYE,
28
28
  ReqRespSubProtocol.TX,
29
- ReqRespSubProtocol.BLOCK,
30
29
  ReqRespSubProtocol.AUTH,
31
30
  ReqRespSubProtocol.BLOCK_TXS,
32
31
  ],