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

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 (308) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +2 -2
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +25 -11
  5. package/dest/client/interface.d.ts +9 -2
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +3 -2
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +37 -36
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
  11. package/dest/config.d.ts +24 -2
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +66 -7
  14. package/dest/errors/p2p-service.error.d.ts +9 -0
  15. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  16. package/dest/errors/p2p-service.error.js +10 -0
  17. package/dest/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -5
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
  24. package/dest/mem_pools/index.d.ts +1 -2
  25. package/dest/mem_pools/index.d.ts.map +1 -1
  26. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  27. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
  29. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
  30. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
  32. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  33. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
  34. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
  35. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  37. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
  38. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
  40. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +25 -10
  41. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +38 -11
  43. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  44. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
  46. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  47. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
  49. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
  50. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +21 -6
  52. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  53. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  54. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  55. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  56. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  57. package/dest/msg_validators/clock_tolerance.js +4 -3
  58. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +5 -4
  59. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  60. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  61. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +5 -4
  62. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  63. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  64. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +12 -9
  65. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  66. package/dest/msg_validators/proposal_validator/proposal_validator.js +51 -49
  67. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  68. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/allowed_public_setup.js +21 -32
  70. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  71. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  72. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  73. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  74. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  75. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  76. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  77. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  78. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  79. package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
  80. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/factory.js +36 -10
  82. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  83. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  85. package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
  86. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  87. package/dest/msg_validators/tx_validator/gas_validator.js +49 -17
  88. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  89. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/index.js +1 -0
  91. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  92. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  93. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  94. package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
  95. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  96. package/dest/msg_validators/tx_validator/phases_validator.js +49 -2
  97. package/dest/services/dummy_service.d.ts +5 -3
  98. package/dest/services/dummy_service.d.ts.map +1 -1
  99. package/dest/services/dummy_service.js +5 -1
  100. package/dest/services/encoding.d.ts +5 -1
  101. package/dest/services/encoding.d.ts.map +1 -1
  102. package/dest/services/encoding.js +7 -1
  103. package/dest/services/libp2p/libp2p_service.d.ts +15 -25
  104. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  105. package/dest/services/libp2p/libp2p_service.js +149 -126
  106. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  107. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  108. package/dest/services/peer-manager/peer_manager.js +22 -8
  109. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  110. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  111. package/dest/services/peer-manager/peer_scoring.js +32 -10
  112. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
  113. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  114. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
  115. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
  116. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  117. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  118. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  119. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  120. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
  121. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  122. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
  123. package/dest/services/reqresp/interface.d.ts +1 -9
  124. package/dest/services/reqresp/interface.d.ts.map +1 -1
  125. package/dest/services/reqresp/interface.js +0 -11
  126. package/dest/services/reqresp/metrics.d.ts +1 -1
  127. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  128. package/dest/services/reqresp/metrics.js +0 -1
  129. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  130. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  131. package/dest/services/reqresp/protocols/index.js +0 -1
  132. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  133. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  134. package/dest/services/reqresp/protocols/tx.js +1 -3
  135. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  136. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  137. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  138. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  139. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  140. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  141. package/dest/services/reqresp/reqresp.d.ts +1 -1
  142. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  143. package/dest/services/reqresp/reqresp.js +18 -10
  144. package/dest/services/service.d.ts +5 -2
  145. package/dest/services/service.d.ts.map +1 -1
  146. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
  147. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  148. package/dest/services/tx_collection/fast_tx_collection.js +57 -73
  149. package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
  150. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  151. package/dest/services/tx_collection/file_store_tx_source.js +39 -29
  152. package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
  153. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  154. package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
  155. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  156. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  157. package/dest/services/tx_collection/request_tracker.js +84 -0
  158. package/dest/services/tx_collection/slow_tx_collection.js +1 -1
  159. package/dest/services/tx_collection/tx_collection.d.ts +3 -6
  160. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  161. package/dest/services/tx_collection/tx_source.d.ts +6 -5
  162. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  163. package/dest/services/tx_collection/tx_source.js +9 -7
  164. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  165. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  166. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  167. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  168. package/dest/test-helpers/reqresp-nodes.js +0 -2
  169. package/dest/test-helpers/testbench-utils.d.ts +1 -1
  170. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  171. package/dest/test-helpers/testbench-utils.js +23 -3
  172. package/dest/testbench/p2p_client_testbench_worker.js +68 -16
  173. package/dest/testbench/worker_client_manager.d.ts +10 -1
  174. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  175. package/dest/testbench/worker_client_manager.js +55 -3
  176. package/dest/util.d.ts +1 -1
  177. package/package.json +14 -14
  178. package/src/client/factory.ts +43 -14
  179. package/src/client/interface.ts +9 -1
  180. package/src/client/p2p_client.ts +39 -36
  181. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
  182. package/src/config.ts +92 -4
  183. package/src/errors/p2p-service.error.ts +11 -0
  184. package/src/index.ts +0 -1
  185. package/src/mem_pools/attestation_pool/attestation_pool.ts +7 -5
  186. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
  187. package/src/mem_pools/index.ts +0 -3
  188. package/src/mem_pools/tx_pool_v2/README.md +9 -1
  189. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  190. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
  191. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
  192. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
  193. package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
  194. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +59 -13
  195. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
  196. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
  197. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +23 -6
  198. package/src/msg_validators/attestation_validator/README.md +49 -0
  199. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  200. package/src/msg_validators/clock_tolerance.ts +4 -3
  201. package/src/msg_validators/proposal_validator/README.md +123 -0
  202. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +13 -3
  203. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +19 -6
  204. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -53
  205. package/src/msg_validators/tx_validator/README.md +5 -1
  206. package/src/msg_validators/tx_validator/allowed_public_setup.ts +16 -35
  207. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  208. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  209. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  210. package/src/msg_validators/tx_validator/factory.ts +43 -3
  211. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  212. package/src/msg_validators/tx_validator/gas_validator.ts +65 -16
  213. package/src/msg_validators/tx_validator/index.ts +1 -0
  214. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  215. package/src/msg_validators/tx_validator/phases_validator.ts +60 -1
  216. package/src/services/dummy_service.ts +7 -2
  217. package/src/services/encoding.ts +9 -1
  218. package/src/services/libp2p/libp2p_service.ts +148 -140
  219. package/src/services/peer-manager/peer_manager.ts +26 -8
  220. package/src/services/peer-manager/peer_scoring.ts +27 -5
  221. package/src/services/reqresp/README.md +229 -0
  222. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  223. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
  224. package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
  225. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  226. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
  227. package/src/services/reqresp/interface.ts +0 -11
  228. package/src/services/reqresp/metrics.ts +0 -1
  229. package/src/services/reqresp/protocols/index.ts +0 -1
  230. package/src/services/reqresp/protocols/tx.ts +1 -3
  231. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  232. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  233. package/src/services/reqresp/reqresp.ts +20 -12
  234. package/src/services/service.ts +6 -1
  235. package/src/services/tx_collection/fast_tx_collection.ts +57 -83
  236. package/src/services/tx_collection/file_store_tx_source.ts +43 -31
  237. package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
  238. package/src/services/tx_collection/request_tracker.ts +127 -0
  239. package/src/services/tx_collection/slow_tx_collection.ts +1 -1
  240. package/src/services/tx_collection/tx_collection.ts +3 -5
  241. package/src/services/tx_collection/tx_source.ts +8 -7
  242. package/src/test-helpers/make-test-p2p-clients.ts +1 -1
  243. package/src/test-helpers/reqresp-nodes.ts +1 -3
  244. package/src/test-helpers/testbench-utils.ts +30 -3
  245. package/src/testbench/p2p_client_testbench_worker.ts +72 -15
  246. package/src/testbench/worker_client_manager.ts +68 -6
  247. package/src/util.ts +1 -1
  248. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  249. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  250. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  251. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  252. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  253. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  254. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  255. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  256. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  257. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  258. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  259. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  260. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  261. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  262. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  263. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  264. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  265. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  266. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  267. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  268. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  269. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  270. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  271. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  272. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  273. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  274. package/dest/mem_pools/tx_pool/index.js +0 -2
  275. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  276. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  277. package/dest/mem_pools/tx_pool/priority.js +0 -15
  278. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  279. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  280. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  281. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  282. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  283. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  284. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -24
  285. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  286. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -378
  287. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  288. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  289. package/dest/services/reqresp/protocols/block.js +0 -32
  290. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  291. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  292. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  293. package/src/mem_pools/tx_pool/README.md +0 -270
  294. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  295. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  296. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  297. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  298. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  299. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  300. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  301. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  302. package/src/mem_pools/tx_pool/index.ts +0 -2
  303. package/src/mem_pools/tx_pool/priority.ts +0 -20
  304. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  305. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  306. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -373
  307. package/src/services/reqresp/protocols/block.ts +0 -37
  308. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
@@ -1,12 +1,9 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { times } from '@aztec/foundation/collection';
3
- import { AbortError, TimeoutError } from '@aztec/foundation/error';
4
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
5
- import { promiseWithResolvers } from '@aztec/foundation/promise';
6
4
  import { sleep } from '@aztec/foundation/sleep';
7
5
  import { DateProvider, elapsed } from '@aztec/foundation/timer';
8
6
  import type { L2BlockInfo } from '@aztec/stdlib/block';
9
- import type { BlockProposal } from '@aztec/stdlib/p2p';
10
7
  import { type Tx, TxHash } from '@aztec/stdlib/tx';
11
8
 
12
9
  import type { PeerId } from '@libp2p/interface';
@@ -14,12 +11,12 @@ import type { PeerId } from '@libp2p/interface';
14
11
  import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
15
12
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
16
13
  import type { TxCollectionConfig } from './config.js';
17
- import { MissingTxsTracker } from './missing_txs_tracker.js';
18
14
  import {
19
15
  BatchTxRequesterCollector,
20
16
  type MissingTxsCollector,
21
17
  SendBatchRequestCollector,
22
18
  } from './proposal_tx_collector.js';
19
+ import { RequestTracker } from './request_tracker.js';
23
20
  import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
24
21
  import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
25
22
  import type { TxSource } from './tx_source.js';
@@ -48,7 +45,9 @@ export class FastTxCollection {
48
45
  }
49
46
 
50
47
  public async stop() {
51
- this.requests.forEach(request => request.promise.reject(new AbortError(`Stopped collection service`)));
48
+ this.requests.forEach(request => {
49
+ request.requestTracker.cancel();
50
+ });
52
51
  await Promise.resolve();
53
52
  }
54
53
 
@@ -75,81 +74,65 @@ export class FastTxCollection {
75
74
  ? { ...input.blockProposal.toBlockInfo(), blockNumber: input.blockNumber }
76
75
  : { ...input.block.toBlockInfo() };
77
76
 
78
- // This promise is used to await for the collection to finish during the main collectFast method.
79
- // It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
80
- const promise = promiseWithResolvers<void>();
81
- const timeoutTimer = setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
82
-
83
77
  const request: FastCollectionRequest = {
84
78
  ...input,
85
79
  blockInfo,
86
- promise,
87
- missingTxTracker: MissingTxsTracker.fromArray(txHashes),
88
- deadline: opts.deadline,
80
+ requestTracker: RequestTracker.create(txHashes, opts.deadline, this.dateProvider),
89
81
  };
90
82
 
91
83
  const [duration] = await elapsed(() => this.collectFast(request, { ...opts }));
92
- clearTimeout(timeoutTimer);
93
84
 
94
85
  this.log.verbose(
95
- `Collected ${request.missingTxTracker.collectedTxs.length} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
86
+ `Collected ${request.requestTracker.collectedTxs.length} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
96
87
  {
97
88
  ...blockInfo,
98
89
  duration,
99
90
  requestType: input.type,
100
- missingTxs: [...request.missingTxTracker.missingTxHashes],
91
+ missingTxs: [...request.requestTracker.missingTxHashes],
101
92
  },
102
93
  );
103
- return request.missingTxTracker.collectedTxs;
94
+ return request.requestTracker.collectedTxs;
104
95
  }
105
96
 
106
- protected async collectFast(
107
- request: FastCollectionRequest,
108
- opts: { proposal?: BlockProposal; deadline: Date; pinnedPeer?: PeerId },
109
- ) {
97
+ protected async collectFast(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
110
98
  this.requests.add(request);
111
99
  const { blockInfo } = request;
112
100
 
113
101
  this.log.debug(
114
- `Starting fast collection of ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
115
- { ...blockInfo, requestType: request.type, deadline: opts.deadline },
102
+ `Starting fast collection of ${request.requestTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
103
+ { ...blockInfo, requestType: request.type, deadline: request.requestTracker.deadline },
116
104
  );
117
105
 
118
106
  try {
119
107
  // Start blasting all nodes for the txs. We give them a little time to respond before we start reqresp.
120
- // And keep an eye on the request promise to ensure we don't wait longer than the deadline or return as soon
121
- // as we have collected all txs, whatever the source.
122
- const nodeCollectionPromise = this.collectFastFromNodes(request, opts);
108
+ // We race against the cancellation token to exit as soon as all txs are collected, the deadline expires,
109
+ // or the request is externally cancelled.
110
+ const nodeCollectionPromise = this.collectFastFromNodes(request);
123
111
  const waitBeforeReqResp = sleep(this.config.txCollectionFastNodesTimeoutBeforeReqRespMs);
124
- await Promise.race([request.promise.promise, waitBeforeReqResp]);
112
+ await Promise.race([request.requestTracker.cancellationToken, waitBeforeReqResp]);
125
113
 
126
- // If we have collected all txs, we can stop here
127
- if (request.missingTxTracker.allFetched()) {
128
- this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
114
+ // If we have collected all txs or the request was cancelled, we can stop here.
115
+ // Wait for node collection to settle so inner tasks finish before we return.
116
+ if (request.requestTracker.checkCancelled()) {
117
+ if (request.requestTracker.allFetched()) {
118
+ this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
119
+ }
120
+ await nodeCollectionPromise;
129
121
  return;
130
122
  }
131
123
 
132
124
  // Start blasting reqresp for the remaining txs. Note that node collection keeps running in parallel.
133
125
  // We stop when we have collected all txs, timed out, or both node collection and reqresp have given up.
134
- const collectionPromise = Promise.allSettled([this.collectFastViaReqResp(request, opts), nodeCollectionPromise]);
135
- await Promise.race([collectionPromise, request.promise.promise]);
126
+ // Inner tasks observe requestTracker.checkCancelled() and stop themselves, so this settles shortly after cancellation.
127
+ await Promise.allSettled([this.collectFastViaReqResp(request, opts), nodeCollectionPromise]);
136
128
  } catch (err) {
137
- // Log and swallow all errors
138
- const logCtx = {
129
+ this.log.error(`Error collecting txs for ${request.type} for slot ${blockInfo.slotNumber}`, err, {
139
130
  ...blockInfo,
140
- errorMessage: err instanceof Error ? err.message : undefined,
141
- missingTxs: request.missingTxTracker.missingTxHashes.values().map(txHash => txHash.toString()),
142
- };
143
- if (err instanceof Error && err.name === 'TimeoutError') {
144
- this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
145
- } else if (err instanceof Error && err.name === 'AbortError') {
146
- this.log.warn(`Aborted collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
147
- } else {
148
- this.log.error(`Error collecting txs for ${request.type} for slot ${blockInfo.slotNumber}`, err, logCtx);
149
- }
131
+ missingTxs: request.requestTracker.missingTxHashes.values().map(txHash => txHash.toString()),
132
+ });
150
133
  } finally {
151
134
  // Ensure no unresolved promises and remove the request from the set
152
- request.promise.resolve();
135
+ request.requestTracker.cancel();
153
136
  this.requests.delete(request);
154
137
  }
155
138
  }
@@ -160,30 +143,28 @@ export class FastTxCollection {
160
143
  * the txs that have been requested less often whenever we need to send a new batch of requests. We ensure that no
161
144
  * tx is requested more than once at the same time to the same node.
162
145
  */
163
- private async collectFastFromNodes(request: FastCollectionRequest, opts: { deadline: Date }): Promise<void> {
146
+ private async collectFastFromNodes(request: FastCollectionRequest): Promise<void> {
164
147
  if (this.nodes.length === 0) {
165
148
  return;
166
149
  }
167
150
 
168
151
  // Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
169
- const attemptsPerTx = [...request.missingTxTracker.missingTxHashes].map(txHash => ({
152
+ const attemptsPerTx = [...request.requestTracker.missingTxHashes].map(txHash => ({
170
153
  txHash,
171
154
  attempts: 0,
172
155
  found: false,
173
156
  }));
174
157
 
175
158
  // Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
176
- await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx, opts)));
159
+ await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx)));
177
160
  }
178
161
 
179
162
  private async collectFastFromNode(
180
163
  request: FastCollectionRequest,
181
164
  node: TxSource,
182
165
  attemptsPerTx: { txHash: string; attempts: number; found: boolean }[],
183
- opts: { deadline: Date },
184
166
  ) {
185
- const notFinished = () =>
186
- this.dateProvider.now() <= +opts.deadline && !request.missingTxTracker.allFetched() && this.requests.has(request);
167
+ const notFinished = () => !request.requestTracker.checkCancelled();
187
168
 
188
169
  const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
189
170
  const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
@@ -200,7 +181,7 @@ export class FastTxCollection {
200
181
  if (!txToRequest) {
201
182
  // No more txs to process
202
183
  break;
203
- } else if (!request.missingTxTracker.isMissing(txToRequest.txHash)) {
184
+ } else if (!request.requestTracker.isMissing(txToRequest.txHash)) {
204
185
  // Mark as found if it was found somewhere else, we'll then remove it from the array.
205
186
  // We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
206
187
  txToRequest.found = true;
@@ -235,7 +216,7 @@ export class FastTxCollection {
235
216
  async () => {
236
217
  const result = await node.getTxsByHash(txHashes.map(TxHash.fromString));
237
218
  for (const tx of result.validTxs) {
238
- request.missingTxTracker.markFetched(tx);
219
+ request.requestTracker.markFetched(tx);
239
220
  }
240
221
  return result;
241
222
  },
@@ -254,9 +235,12 @@ export class FastTxCollection {
254
235
  activeRequestsToThisNode.delete(requestedTx.txHash);
255
236
  }
256
237
 
257
- // Sleep a bit until hitting the node again (or not, depending on config)
238
+ // Sleep a bit until hitting the node again, but wake up immediately on cancellation
258
239
  if (notFinished()) {
259
- await sleep(this.config.txCollectionFastNodeIntervalMs);
240
+ await Promise.race([
241
+ sleep(this.config.txCollectionFastNodeIntervalMs),
242
+ request.requestTracker.cancellationToken,
243
+ ]);
260
244
  }
261
245
  }
262
246
  };
@@ -266,21 +250,20 @@ export class FastTxCollection {
266
250
  }
267
251
 
268
252
  private async collectFastViaReqResp(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
269
- const timeoutMs = +request.deadline - this.dateProvider.now();
270
253
  const pinnedPeer = opts.pinnedPeer;
271
254
  const blockInfo = request.blockInfo;
272
255
  const slotNumber = blockInfo.slotNumber;
273
- if (timeoutMs < 100) {
256
+ if (request.requestTracker.timeoutMs < 100) {
274
257
  this.log.warn(
275
258
  `Not initiating fast reqresp for txs for ${request.type} at slot ${blockInfo.slotNumber} due to timeout`,
276
- { timeoutMs, ...blockInfo },
259
+ { timeoutMs: request.requestTracker.timeoutMs, ...blockInfo },
277
260
  );
278
261
  return;
279
262
  }
280
263
 
281
264
  this.log.debug(
282
- `Starting fast reqresp for ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
283
- { ...blockInfo, timeoutMs, pinnedPeer },
265
+ `Starting fast reqresp for ${request.requestTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
266
+ { ...blockInfo, timeoutMs: request.requestTracker.timeoutMs, pinnedPeer },
284
267
  );
285
268
 
286
269
  try {
@@ -289,34 +272,28 @@ export class FastTxCollection {
289
272
  let result: Tx[];
290
273
  if (request.type === 'proposal') {
291
274
  result = await this.missingTxsCollector.collectTxs(
292
- request.missingTxTracker,
275
+ request.requestTracker,
293
276
  request.blockProposal,
294
277
  pinnedPeer,
295
- timeoutMs,
296
278
  );
297
279
  } else if (request.type === 'block') {
298
280
  const blockTxsSource = {
299
281
  txHashes: request.block.body.txEffects.map(e => e.txHash),
300
282
  archive: request.block.archive.root,
301
283
  };
302
- result = await this.missingTxsCollector.collectTxs(
303
- request.missingTxTracker,
304
- blockTxsSource,
305
- pinnedPeer,
306
- timeoutMs,
307
- );
284
+ result = await this.missingTxsCollector.collectTxs(request.requestTracker, blockTxsSource, pinnedPeer);
308
285
  } else {
309
286
  throw new Error(`Unknown request type: ${(request as any).type}`);
310
287
  }
311
288
  return { validTxs: result, invalidTxHashes: [] };
312
289
  },
313
- Array.from(request.missingTxTracker.missingTxHashes),
290
+ Array.from(request.requestTracker.missingTxHashes),
314
291
  { description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
315
292
  this.getAddContext(request),
316
293
  );
317
294
  } catch (err) {
318
295
  this.log.error(`Error sending fast reqresp request for txs`, err, {
319
- txs: [...request.missingTxTracker.missingTxHashes],
296
+ txs: [...request.requestTracker.missingTxHashes],
320
297
  ...blockInfo,
321
298
  });
322
299
  }
@@ -340,20 +317,19 @@ export class FastTxCollection {
340
317
  for (const tx of txs) {
341
318
  const txHash = tx.txHash.toString();
342
319
  // Remove the tx hash from the missing set, and add it to the found set.
343
- if (request.missingTxTracker.markFetched(tx)) {
320
+ if (request.requestTracker.markFetched(tx)) {
344
321
  this.log.trace(`Found tx ${txHash} for fast collection request`, {
345
322
  ...request.blockInfo,
346
323
  txHash: tx.txHash.toString(),
347
324
  type: request.type,
348
325
  });
349
- }
350
- // If we found all txs for this request, we resolve the promise
351
- if (request.missingTxTracker.allFetched()) {
352
- this.log.trace(`All txs found for fast collection request`, {
353
- ...request.blockInfo,
354
- type: request.type,
355
- });
356
- request.promise.resolve();
326
+ if (request.requestTracker.allFetched()) {
327
+ this.log.trace(`All txs found for fast collection request`, {
328
+ ...request.blockInfo,
329
+ type: request.type,
330
+ });
331
+ break;
332
+ }
357
333
  }
358
334
  }
359
335
  }
@@ -366,8 +342,7 @@ export class FastTxCollection {
366
342
  public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
367
343
  for (const request of this.requests) {
368
344
  if (request.blockInfo.blockNumber <= blockNumber) {
369
- request.promise.reject(new AbortError(`Stopped collecting txs up to block ${blockNumber}`));
370
- this.requests.delete(request);
345
+ request.requestTracker.cancel();
371
346
  }
372
347
  }
373
348
  }
@@ -379,8 +354,7 @@ export class FastTxCollection {
379
354
  public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
380
355
  for (const request of this.requests) {
381
356
  if (request.blockInfo.blockNumber > blockNumber) {
382
- request.promise.reject(new AbortError(`Stopped collecting txs after block ${blockNumber}`));
383
- this.requests.delete(request);
357
+ request.requestTracker.cancel();
384
358
  }
385
359
  }
386
360
  }
@@ -1,7 +1,8 @@
1
+ import { partitionAsync } from '@aztec/foundation/collection';
1
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
3
  import { Timer } from '@aztec/foundation/timer';
3
4
  import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
4
- import { Tx, type TxHash } from '@aztec/stdlib/tx';
5
+ import { Tx, type TxHash, type TxValidator } from '@aztec/stdlib/tx';
5
6
  import {
6
7
  type Histogram,
7
8
  Metrics,
@@ -23,6 +24,7 @@ export class FileStoreTxSource implements TxSource {
23
24
  private readonly fileStore: ReadOnlyFileStore,
24
25
  private readonly baseUrl: string,
25
26
  private readonly basePath: string,
27
+ private readonly txValidator: TxValidator,
26
28
  private readonly log: Logger,
27
29
  telemetry: TelemetryClient,
28
30
  ) {
@@ -44,6 +46,7 @@ export class FileStoreTxSource implements TxSource {
44
46
  public static async create(
45
47
  url: string,
46
48
  basePath: string,
49
+ txValidator: TxValidator,
47
50
  log: Logger = createLogger('p2p:file_store_tx_source'),
48
51
  telemetry: TelemetryClient = getTelemetryClient(),
49
52
  ): Promise<FileStoreTxSource | undefined> {
@@ -53,7 +56,7 @@ export class FileStoreTxSource implements TxSource {
53
56
  log.warn(`Failed to create file store for URL: ${url}`);
54
57
  return undefined;
55
58
  }
56
- return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
59
+ return new FileStoreTxSource(fileStore, url, basePath, txValidator, log, telemetry);
57
60
  } catch (err) {
58
61
  log.warn(`Error creating file store for URL: ${url}`, { error: err });
59
62
  return undefined;
@@ -65,35 +68,41 @@ export class FileStoreTxSource implements TxSource {
65
68
  }
66
69
 
67
70
  public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
68
- const invalidTxHashes: string[] = [];
71
+ const results = await Promise.all(
72
+ txHashes.map(async txHash => {
73
+ const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
74
+ const timer = new Timer();
75
+ try {
76
+ const buffer = await this.fileStore.read(path);
77
+ const tx = Tx.fromBuffer(buffer);
78
+ return { tx, downloadDuration: timer.ms(), downloadSize: buffer.length };
79
+ } catch {
80
+ this.downloadsFailed.add(1);
81
+ return undefined;
82
+ }
83
+ }),
84
+ );
85
+
86
+ const txs = results.filter(tx => tx !== undefined);
87
+ const [validTxs, invalidTxs] = await partitionAsync(
88
+ txs,
89
+ async ({ tx, downloadDuration, downloadSize }): Promise<boolean> => {
90
+ const valid = await this.txValidator.validateTx(tx);
91
+ if (valid.result === 'valid') {
92
+ this.downloadsSuccess.add(1);
93
+ this.downloadDuration.record(Math.ceil(downloadDuration));
94
+ this.downloadSize.record(downloadSize);
95
+ return true;
96
+ } else {
97
+ this.downloadsFailed.add(1);
98
+ return false;
99
+ }
100
+ },
101
+ );
102
+
69
103
  return {
70
- validTxs: (
71
- await Promise.all(
72
- txHashes.map(async txHash => {
73
- const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
74
- const timer = new Timer();
75
- try {
76
- const buffer = await this.fileStore.read(path);
77
- const tx = Tx.fromBuffer(buffer);
78
- if ((await tx.validateTxHash()) && txHash.equals(tx.txHash)) {
79
- this.downloadsSuccess.add(1);
80
- this.downloadDuration.record(Math.ceil(timer.ms()));
81
- this.downloadSize.record(buffer.length);
82
- return tx;
83
- } else {
84
- invalidTxHashes.push(tx.txHash.toString());
85
- this.downloadsFailed.add(1);
86
- return undefined;
87
- }
88
- } catch {
89
- // Tx not found or error reading - return undefined
90
- this.downloadsFailed.add(1);
91
- return undefined;
92
- }
93
- }),
94
- )
95
- ).filter(tx => tx !== undefined),
96
- invalidTxHashes: invalidTxHashes,
104
+ validTxs: validTxs.map(({ tx }) => tx),
105
+ invalidTxHashes: invalidTxs.map(({ tx }) => tx.getTxHash().toString()),
97
106
  };
98
107
  }
99
108
  }
@@ -109,9 +118,12 @@ export class FileStoreTxSource implements TxSource {
109
118
  export async function createFileStoreTxSources(
110
119
  urls: string[],
111
120
  basePath: string,
121
+ txValidator: TxValidator,
112
122
  log: Logger = createLogger('p2p:file_store_tx_source'),
113
123
  telemetry: TelemetryClient = getTelemetryClient(),
114
124
  ): Promise<FileStoreTxSource[]> {
115
- const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, basePath, log, telemetry)));
125
+ const sources = await Promise.all(
126
+ urls.map(url => FileStoreTxSource.create(url, basePath, txValidator, log, telemetry)),
127
+ );
116
128
  return sources.filter((s): s is FileStoreTxSource => s !== undefined);
117
129
  }
@@ -9,7 +9,7 @@ import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/confi
9
9
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
10
10
  import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
11
11
  import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
12
- import type { IMissingTxsTracker } from './missing_txs_tracker.js';
12
+ import type { IRequestTracker } from './request_tracker.js';
13
13
 
14
14
  /**
15
15
  * Strategy interface for collecting missing transactions for a block or proposal.
@@ -18,17 +18,15 @@ import type { IMissingTxsTracker } from './missing_txs_tracker.js';
18
18
  export interface MissingTxsCollector {
19
19
  /**
20
20
  * Collect missing transactions for a block or proposal.
21
- * @param missingTxsTracker - The missing transactions tracker
21
+ * @param requestTracker - The missing transactions tracker
22
22
  * @param blockTxsSource - The block or proposal containing the transactions
23
23
  * @param pinnedPeer - Optional peer expected to have the transactions
24
- * @param timeoutMs - Timeout in milliseconds
25
24
  * @returns The collected transactions
26
25
  */
27
26
  collectTxs(
28
- missingTxsTracker: IMissingTxsTracker,
27
+ requestTracker: IRequestTracker,
29
28
  blockTxsSource: BlockTxsSource,
30
29
  pinnedPeer: PeerId | undefined,
31
- timeoutMs: number,
32
30
  ): Promise<Tx[]>;
33
31
  }
34
32
 
@@ -46,10 +44,9 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
46
44
  ) {}
47
45
 
48
46
  async collectTxs(
49
- missingTxsTracker: IMissingTxsTracker,
47
+ requestTracker: IRequestTracker,
50
48
  blockTxsSource: BlockTxsSource,
51
49
  pinnedPeer: PeerId | undefined,
52
- timeoutMs: number,
53
50
  ): Promise<Tx[]> {
54
51
  const {
55
52
  batchTxRequesterSmartParallelWorkerCount: smartParallelWorkerCount,
@@ -59,10 +56,9 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
59
56
  } = this.batchTxRequesterConfig ?? {};
60
57
 
61
58
  const batchRequester = new BatchTxRequester(
62
- missingTxsTracker,
59
+ requestTracker,
63
60
  blockTxsSource,
64
61
  pinnedPeer,
65
- timeoutMs,
66
62
  this.p2pService,
67
63
  this.log,
68
64
  this.dateProvider,
@@ -94,16 +90,15 @@ export class SendBatchRequestCollector implements MissingTxsCollector {
94
90
  ) {}
95
91
 
96
92
  async collectTxs(
97
- missingTxsTracker: IMissingTxsTracker,
93
+ requestTracker: IRequestTracker,
98
94
  _blockTxsSource: BlockTxsSource,
99
95
  pinnedPeer: PeerId | undefined,
100
- timeoutMs: number,
101
96
  ): Promise<Tx[]> {
102
97
  const txs = await this.p2pService.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
103
98
  ReqRespSubProtocol.TX,
104
- chunkTxHashesRequest(Array.from(missingTxsTracker.missingTxHashes).map(TxHash.fromString)),
99
+ chunkTxHashesRequest(Array.from(requestTracker.missingTxHashes).map(TxHash.fromString)),
105
100
  pinnedPeer,
106
- timeoutMs,
101
+ requestTracker.timeoutMs,
107
102
  this.maxPeers,
108
103
  this.maxRetryAttempts,
109
104
  );
@@ -0,0 +1,127 @@
1
+ import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
2
+ import type { DateProvider } from '@aztec/foundation/timer';
3
+ import { TxHash } from '@aztec/stdlib/tx';
4
+ import type { Tx } from '@aztec/stdlib/tx';
5
+
6
+ /**
7
+ * Tracks which transactions are still missing and need to be fetched.
8
+ * Manages the request deadline and serves as the sole source of cancellation signal.
9
+ * The request is cancelled when all txs are fetched or the deadline expires.
10
+ */
11
+ export interface IRequestTracker {
12
+ /** Returns the set of transaction hashes that are still missing. */
13
+ get missingTxHashes(): Set<string>;
14
+ /** Size of this.missingTxHashes */
15
+ get numberOfMissingTxs(): number;
16
+ /** Are all requested txs fetched */
17
+ allFetched(): boolean;
18
+ /** Checks that transaction is still missing */
19
+ isMissing(txHash: string): boolean;
20
+ /** Marks a transaction as fetched. Returns true if it was previously missing. */
21
+ markFetched(tx: Tx): boolean;
22
+ /** Get list of collected txs */
23
+ get collectedTxs(): Tx[];
24
+ /** The deadline for this request. */
25
+ get deadline(): Date;
26
+ /** Remaining time in milliseconds until deadline. Returns 0 if already past. */
27
+ get timeoutMs(): number;
28
+ /** Checks whether the request is cancelled (deadline expired or all fetched). May trigger cancellation if deadline has passed. */
29
+ checkCancelled(): boolean;
30
+ /** Resolves when deadline expires or all txs are fetched. */
31
+ get cancellationToken(): Promise<void>;
32
+ /** Externally cancel the request. */
33
+ cancel(): void;
34
+ }
35
+
36
+ export class RequestTracker implements IRequestTracker {
37
+ public readonly collectedTxs: Tx[] = [];
38
+ private done = false;
39
+ private readonly cancellationTokenPromise: PromiseWithResolvers<void>;
40
+ private readonly deadlineTimer: ReturnType<typeof setTimeout> | undefined;
41
+
42
+ private constructor(
43
+ public readonly missingTxHashes: Set<string>,
44
+ public readonly deadline: Date,
45
+ private readonly dateProvider?: DateProvider,
46
+ ) {
47
+ this.cancellationTokenPromise = promiseWithResolvers<void>();
48
+
49
+ if (missingTxHashes.size === 0) {
50
+ this.finish();
51
+ return;
52
+ }
53
+
54
+ const now = this.dateProvider?.now() ?? Date.now();
55
+ const remaining = deadline.getTime() - now;
56
+ if (remaining <= 0) {
57
+ this.finish();
58
+ } else {
59
+ this.deadlineTimer = setTimeout(() => this.finish(), remaining);
60
+ }
61
+ }
62
+
63
+ public static create(hashes: TxHash[] | string[], deadline: Date, dateProvider?: DateProvider) {
64
+ return new RequestTracker(new Set(hashes.map(hash => hash.toString())), deadline, dateProvider);
65
+ }
66
+
67
+ markFetched(tx: Tx): boolean {
68
+ if (this.missingTxHashes.delete(tx.txHash.toString())) {
69
+ this.collectedTxs.push(tx);
70
+ if (this.allFetched()) {
71
+ this.finish();
72
+ }
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+
78
+ get numberOfMissingTxs(): number {
79
+ return this.missingTxHashes.size;
80
+ }
81
+
82
+ allFetched(): boolean {
83
+ return this.numberOfMissingTxs === 0;
84
+ }
85
+
86
+ isMissing(txHash: string): boolean {
87
+ return this.missingTxHashes.has(txHash.toString());
88
+ }
89
+
90
+ get timeoutMs(): number {
91
+ const now = this.dateProvider?.now() ?? Date.now();
92
+ return Math.max(0, this.deadline.getTime() - now);
93
+ }
94
+
95
+ checkCancelled(): boolean {
96
+ if (this.done) {
97
+ return true;
98
+ }
99
+ // Synchronous fallback: check deadline even if setTimeout hasn't fired yet.
100
+ // This prevents macrotask starvation in tight async loops from blocking cancellation.
101
+ const now = this.dateProvider?.now() ?? Date.now();
102
+ if (now >= this.deadline.getTime()) {
103
+ this.finish();
104
+ return true;
105
+ }
106
+ return false;
107
+ }
108
+
109
+ get cancellationToken(): Promise<void> {
110
+ return this.cancellationTokenPromise.promise;
111
+ }
112
+
113
+ cancel(): void {
114
+ this.finish();
115
+ }
116
+
117
+ private finish() {
118
+ if (this.done) {
119
+ return;
120
+ }
121
+ this.done = true;
122
+ if (this.deadlineTimer) {
123
+ clearTimeout(this.deadlineTimer);
124
+ }
125
+ this.cancellationTokenPromise.resolve();
126
+ }
127
+ }
@@ -196,7 +196,7 @@ export class SlowTxCollection {
196
196
  // from mined unproven blocks it has seen in the past.
197
197
  const fastRequests = this.fastCollection.getFastCollectionRequests();
198
198
  const fastCollectionTxs: Set<string> = new Set(
199
- fastRequests.values().flatMap(r => Array.from(r.missingTxTracker.missingTxHashes)),
199
+ fastRequests.values().flatMap(r => Array.from(r.requestTracker.missingTxHashes)),
200
200
  );
201
201
 
202
202
  // Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested