@aztec/p2p 0.0.1-commit.7d4e6cd → 0.0.1-commit.87a0206

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 (421) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +4 -3
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +4 -4
  4. package/dest/client/factory.d.ts +3 -3
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +11 -8
  7. package/dest/client/interface.d.ts +9 -2
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +7 -4
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +25 -8
  12. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
  13. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
  14. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
  15. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
  16. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
  17. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
  18. package/dest/config.d.ts +14 -2
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +7 -3
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
  22. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  23. package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +371 -94
  27. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  28. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/index.js +1 -2
  30. package/dest/mem_pools/attestation_pool/mocks.d.ts +4 -2
  31. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/mocks.js +8 -5
  33. package/dest/mem_pools/index.d.ts +2 -2
  34. package/dest/mem_pools/index.d.ts.map +1 -1
  35. package/dest/mem_pools/index.js +1 -1
  36. package/dest/mem_pools/instrumentation.d.ts +1 -1
  37. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  38. package/dest/mem_pools/instrumentation.js +2 -2
  39. package/dest/mem_pools/interface.d.ts +3 -3
  40. package/dest/mem_pools/interface.d.ts.map +1 -1
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
  44. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
  45. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
  47. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
  48. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
  50. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  51. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  53. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
  54. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
  56. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
  58. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
  59. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  61. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  63. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  64. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  66. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  67. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  92. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  93. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  94. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  95. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  96. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  97. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  98. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  99. package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
  100. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  101. package/dest/mem_pools/tx_pool_v2/index.js +4 -0
  102. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  103. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  104. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  113. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  114. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  115. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  116. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  117. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  118. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  119. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
  120. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
  121. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/attestation_validator/attestation_validator.js +41 -10
  123. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  124. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -6
  126. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  127. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  128. package/dest/msg_validators/clock_tolerance.js +37 -0
  129. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
  130. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/proposal_validator/proposal_validator.js +55 -31
  132. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
  133. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
  134. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +93 -64
  135. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  136. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  138. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
  139. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
  141. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  142. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  144. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
  145. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
  147. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  148. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  149. package/dest/msg_validators/tx_validator/factory.js +21 -11
  150. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  151. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  152. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  153. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  154. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  155. package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
  156. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  157. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  158. package/dest/msg_validators/tx_validator/index.js +1 -0
  159. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  160. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  161. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  162. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  163. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  164. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  165. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  166. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  167. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  168. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  169. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  170. package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
  171. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  172. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  173. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  174. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  175. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  176. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  177. package/dest/services/data_store.d.ts +1 -1
  178. package/dest/services/data_store.d.ts.map +1 -1
  179. package/dest/services/data_store.js +10 -6
  180. package/dest/services/discv5/discV5_service.js +1 -1
  181. package/dest/services/dummy_service.d.ts +18 -2
  182. package/dest/services/dummy_service.d.ts.map +1 -1
  183. package/dest/services/dummy_service.js +42 -0
  184. package/dest/services/encoding.d.ts +1 -1
  185. package/dest/services/encoding.d.ts.map +1 -1
  186. package/dest/services/encoding.js +2 -3
  187. package/dest/services/index.d.ts +2 -1
  188. package/dest/services/index.d.ts.map +1 -1
  189. package/dest/services/index.js +1 -0
  190. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  191. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  192. package/dest/services/libp2p/instrumentation.js +19 -8
  193. package/dest/services/libp2p/libp2p_service.d.ts +81 -34
  194. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  195. package/dest/services/libp2p/libp2p_service.js +338 -258
  196. package/dest/services/peer-manager/metrics.d.ts +2 -2
  197. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  198. package/dest/services/peer-manager/metrics.js +20 -5
  199. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  200. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  201. package/dest/services/peer-manager/peer_scoring.js +8 -2
  202. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  203. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  204. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  205. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  206. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  207. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  208. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  209. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  210. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  211. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  212. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  213. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  214. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  215. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  216. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  217. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  218. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  219. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  220. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  221. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  222. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  223. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  224. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  225. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  226. package/dest/services/reqresp/constants.d.ts +12 -0
  227. package/dest/services/reqresp/constants.d.ts.map +1 -0
  228. package/dest/services/reqresp/constants.js +7 -0
  229. package/dest/services/reqresp/interface.d.ts +3 -1
  230. package/dest/services/reqresp/interface.d.ts.map +1 -1
  231. package/dest/services/reqresp/metrics.d.ts +6 -5
  232. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  233. package/dest/services/reqresp/metrics.js +17 -5
  234. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  235. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  236. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  237. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
  238. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  239. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  240. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +23 -6
  241. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  242. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +44 -13
  243. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  244. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  245. package/dest/services/reqresp/protocols/status.js +2 -1
  246. package/dest/services/reqresp/reqresp.d.ts +6 -1
  247. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  248. package/dest/services/reqresp/reqresp.js +58 -22
  249. package/dest/services/service.d.ts +21 -1
  250. package/dest/services/service.d.ts.map +1 -1
  251. package/dest/services/tx_collection/config.d.ts +4 -1
  252. package/dest/services/tx_collection/config.d.ts.map +1 -1
  253. package/dest/services/tx_collection/config.js +9 -1
  254. package/dest/services/tx_collection/fast_tx_collection.d.ts +5 -4
  255. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  256. package/dest/services/tx_collection/fast_tx_collection.js +17 -10
  257. package/dest/services/tx_collection/index.d.ts +2 -1
  258. package/dest/services/tx_collection/index.d.ts.map +1 -1
  259. package/dest/services/tx_collection/index.js +1 -0
  260. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  261. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  262. package/dest/services/tx_collection/instrumentation.js +9 -2
  263. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  264. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  265. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  266. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  267. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  268. package/dest/services/tx_collection/tx_collection.d.ts +8 -8
  269. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  270. package/dest/services/tx_collection/tx_collection.js +5 -5
  271. package/dest/services/tx_file_store/config.d.ts +18 -0
  272. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  273. package/dest/services/tx_file_store/config.js +26 -0
  274. package/dest/services/tx_file_store/index.d.ts +4 -0
  275. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  276. package/dest/services/tx_file_store/index.js +3 -0
  277. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  278. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  279. package/dest/services/tx_file_store/instrumentation.js +29 -0
  280. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  281. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  282. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  283. package/dest/services/tx_provider.d.ts +3 -3
  284. package/dest/services/tx_provider.d.ts.map +1 -1
  285. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  286. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  287. package/dest/services/tx_provider_instrumentation.js +5 -5
  288. package/dest/test-helpers/index.d.ts +3 -1
  289. package/dest/test-helpers/index.d.ts.map +1 -1
  290. package/dest/test-helpers/index.js +2 -0
  291. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  292. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  293. package/dest/test-helpers/test_tx_provider.js +41 -0
  294. package/dest/test-helpers/testbench-utils.d.ts +152 -0
  295. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  296. package/dest/test-helpers/testbench-utils.js +299 -0
  297. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  298. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  299. package/dest/testbench/p2p_client_testbench_worker.js +212 -132
  300. package/dest/testbench/worker_client_manager.d.ts +51 -6
  301. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  302. package/dest/testbench/worker_client_manager.js +226 -44
  303. package/package.json +16 -16
  304. package/src/bootstrap/bootstrap.ts +7 -4
  305. package/src/client/factory.ts +13 -14
  306. package/src/client/interface.ts +13 -1
  307. package/src/client/p2p_client.ts +38 -14
  308. package/src/client/test/tx_proposal_collector/README.md +227 -0
  309. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  310. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  311. package/src/config.ts +15 -3
  312. package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
  313. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +454 -110
  314. package/src/mem_pools/attestation_pool/index.ts +9 -2
  315. package/src/mem_pools/attestation_pool/mocks.ts +6 -4
  316. package/src/mem_pools/index.ts +1 -1
  317. package/src/mem_pools/instrumentation.ts +2 -1
  318. package/src/mem_pools/interface.ts +2 -2
  319. package/src/mem_pools/tx_pool/README.md +28 -13
  320. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
  321. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
  322. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
  323. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  324. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  325. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  326. package/src/mem_pools/tx_pool_v2/README.md +209 -0
  327. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  328. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  329. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  330. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  331. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  332. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  333. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  334. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  335. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  336. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  337. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  338. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  339. package/src/mem_pools/tx_pool_v2/index.ts +11 -0
  340. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  341. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
  342. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  343. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  344. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  345. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
  346. package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -14
  347. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +16 -10
  348. package/src/msg_validators/clock_tolerance.ts +51 -0
  349. package/src/msg_validators/proposal_validator/proposal_validator.ts +31 -31
  350. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +91 -67
  351. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  352. package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
  353. package/src/msg_validators/tx_validator/data_validator.ts +6 -2
  354. package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
  355. package/src/msg_validators/tx_validator/factory.ts +64 -23
  356. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  357. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  358. package/src/msg_validators/tx_validator/index.ts +1 -0
  359. package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
  360. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  361. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  362. package/src/msg_validators/tx_validator/timestamp_validator.ts +6 -3
  363. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  364. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  365. package/src/services/data_store.ts +10 -7
  366. package/src/services/discv5/discV5_service.ts +1 -1
  367. package/src/services/dummy_service.ts +51 -0
  368. package/src/services/encoding.ts +2 -3
  369. package/src/services/index.ts +1 -0
  370. package/src/services/libp2p/instrumentation.ts +20 -7
  371. package/src/services/libp2p/libp2p_service.ts +369 -269
  372. package/src/services/peer-manager/metrics.ts +21 -4
  373. package/src/services/peer-manager/peer_scoring.ts +4 -1
  374. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  375. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  376. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  377. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  378. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  379. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  380. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  381. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  382. package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
  383. package/src/services/reqresp/constants.ts +14 -0
  384. package/src/services/reqresp/interface.ts +3 -0
  385. package/src/services/reqresp/metrics.ts +34 -9
  386. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  387. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -11
  388. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +57 -9
  389. package/src/services/reqresp/protocols/status.ts +5 -3
  390. package/src/services/reqresp/reqresp.ts +66 -19
  391. package/src/services/service.ts +24 -0
  392. package/src/services/tx_collection/config.ts +15 -1
  393. package/src/services/tx_collection/fast_tx_collection.ts +30 -17
  394. package/src/services/tx_collection/index.ts +5 -0
  395. package/src/services/tx_collection/instrumentation.ts +11 -2
  396. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  397. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  398. package/src/services/tx_collection/tx_collection.ts +8 -8
  399. package/src/services/tx_file_store/config.ts +43 -0
  400. package/src/services/tx_file_store/index.ts +3 -0
  401. package/src/services/tx_file_store/instrumentation.ts +36 -0
  402. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  403. package/src/services/tx_provider.ts +2 -2
  404. package/src/services/tx_provider_instrumentation.ts +11 -5
  405. package/src/test-helpers/index.ts +2 -0
  406. package/src/test-helpers/test_tx_provider.ts +64 -0
  407. package/src/test-helpers/testbench-utils.ts +353 -0
  408. package/src/testbench/p2p_client_testbench_worker.ts +321 -126
  409. package/src/testbench/worker_client_manager.ts +304 -47
  410. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  411. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  412. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  413. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  414. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  415. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  416. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
  417. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
  418. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
  419. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  420. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  421. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
@@ -0,0 +1,74 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+
3
+ import type { EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
4
+ import { EvictionEvent } from './interfaces.js';
5
+
6
+ /**
7
+ * Eviction rule that removes invalid transactions after a block is mined.
8
+ * Only triggers on BLOCK_MINED events.
9
+ *
10
+ * Eviction criteria includes:
11
+ * - Transactions with nullifiers that are already included in the mined block
12
+ * - Transactions with an expiration timestamp less than or equal to the mined block timestamp
13
+ */
14
+ export class InvalidTxsAfterMiningRule implements EvictionRule {
15
+ public readonly name = 'InvalidTxsAfterMining';
16
+
17
+ private log = createLogger('p2p:tx_pool_v2:invalid_txs_after_mining_rule');
18
+
19
+ async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
20
+ if (context.event !== EvictionEvent.BLOCK_MINED) {
21
+ return {
22
+ reason: 'block_mined_invalid_txs',
23
+ success: true,
24
+ txsEvicted: [],
25
+ };
26
+ }
27
+
28
+ try {
29
+ const { timestamp } = context.block.globalVariables;
30
+ const minedNullifiers = new Set(context.newNullifiers);
31
+
32
+ const txsToEvict: string[] = [];
33
+ const pendingTxs = pool.getPendingTxs();
34
+
35
+ for (const meta of pendingTxs) {
36
+ // Evict pending txs that share nullifiers with mined txs
37
+ if (meta.nullifiers.some(nullifier => minedNullifiers.has(nullifier))) {
38
+ this.log.verbose(`Evicting tx ${meta.txHash} from pool due to a duplicate nullifier with a mined tx`);
39
+ txsToEvict.push(meta.txHash);
40
+ continue;
41
+ }
42
+
43
+ // Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
44
+ if (meta.includeByTimestamp <= timestamp) {
45
+ this.log.verbose(
46
+ `Evicting tx ${meta.txHash} from pool due to the tx being expired (includeByTimestamp: ${meta.includeByTimestamp}, mined block timestamp: ${timestamp})`,
47
+ );
48
+ txsToEvict.push(meta.txHash);
49
+ continue;
50
+ }
51
+ }
52
+
53
+ if (txsToEvict.length > 0) {
54
+ await pool.deleteTxs(txsToEvict);
55
+ }
56
+
57
+ this.log.debug(`Evicted ${txsToEvict.length} invalid txs after block mined`);
58
+
59
+ return {
60
+ reason: 'block_mined_invalid_txs',
61
+ success: true,
62
+ txsEvicted: txsToEvict,
63
+ };
64
+ } catch (err) {
65
+ this.log.error('Failed to evict invalid transactions after mining', { err });
66
+ return {
67
+ reason: 'block_mined_invalid_txs',
68
+ success: false,
69
+ txsEvicted: [],
70
+ error: new Error('Failed to evict invalid txs after mining', { cause: err }),
71
+ };
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,101 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
4
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
5
+
6
+ import type { EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
7
+ import { EvictionEvent } from './interfaces.js';
8
+
9
+ /**
10
+ * Eviction rule that removes invalid transactions after a blockchain reorganization.
11
+ * Only triggers on CHAIN_PRUNED events.
12
+ *
13
+ * Eviction criteria includes:
14
+ * - Transactions that reference pruned block hashes (invalid by definition)
15
+ */
16
+ export class InvalidTxsAfterReorgRule implements EvictionRule {
17
+ public readonly name = 'InvalidTxsAfterReorg';
18
+
19
+ private log = createLogger('p2p:tx_pool_v2:invalid_txs_after_reorg_rule');
20
+
21
+ constructor(private worldState: WorldStateSynchronizer) {}
22
+
23
+ async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
24
+ if (context.event !== EvictionEvent.CHAIN_PRUNED) {
25
+ return {
26
+ reason: 'reorg_invalid_txs',
27
+ success: true,
28
+ txsEvicted: [],
29
+ };
30
+ }
31
+
32
+ try {
33
+ const pendingTxs = pool.getPendingTxs();
34
+
35
+ // Deduplicate block hashes to reduce redundant DB lookups
36
+ const uniqueBlockHashes = new Map<string, Fr>();
37
+ const txsByBlockHash = new Map<string, string[]>();
38
+
39
+ for (const meta of pendingTxs) {
40
+ const blockHashStr = meta.anchorBlockHeaderHash;
41
+ if (!txsByBlockHash.has(blockHashStr)) {
42
+ txsByBlockHash.set(blockHashStr, []);
43
+ uniqueBlockHashes.set(blockHashStr, Fr.fromHexString(blockHashStr));
44
+ }
45
+ txsByBlockHash.get(blockHashStr)!.push(meta.txHash);
46
+ }
47
+
48
+ // Ensure world state is synced to this block before accessing the snapshot
49
+ await this.worldState.syncImmediate(context.blockNumber);
50
+ const db = this.worldState.getSnapshot(context.blockNumber);
51
+
52
+ // Check which blocks exist in the archive
53
+ const blockHashArray = Array.from(uniqueBlockHashes.values());
54
+ const blocksFromDb = await db.findLeafIndices(MerkleTreeId.ARCHIVE, blockHashArray);
55
+
56
+ // Build set of pruned block hashes
57
+ const prunedBlockHashes = new Set<string>();
58
+ let i = 0;
59
+ for (const [blockHashStr] of uniqueBlockHashes) {
60
+ if (blocksFromDb[i] === undefined) {
61
+ prunedBlockHashes.add(blockHashStr);
62
+ }
63
+ i++;
64
+ }
65
+
66
+ // Identify txs whose anchor block was pruned
67
+ const txsToEvict: string[] = [];
68
+ for (const [blockHashStr, txHashes] of txsByBlockHash) {
69
+ if (prunedBlockHashes.has(blockHashStr)) {
70
+ txsToEvict.push(...txHashes);
71
+ }
72
+ }
73
+
74
+ if (txsToEvict.length > 0) {
75
+ this.log.verbose(`Evicting ${txsToEvict.length} txs from pool due to referencing pruned blocks`);
76
+ await pool.deleteTxs(txsToEvict);
77
+ }
78
+
79
+ const keptCount = pendingTxs.length - txsToEvict.length;
80
+ if (keptCount > 0) {
81
+ this.log.verbose(`Kept ${keptCount} txs that did not reference pruned blocks`);
82
+ }
83
+
84
+ this.log.debug(`Evicted ${txsToEvict.length} invalid txs after reorg`);
85
+
86
+ return {
87
+ reason: 'reorg_invalid_txs',
88
+ success: true,
89
+ txsEvicted: txsToEvict,
90
+ };
91
+ } catch (err) {
92
+ this.log.error('Failed to evict invalid transactions after reorg', { err });
93
+ return {
94
+ reason: 'reorg_invalid_txs',
95
+ success: false,
96
+ txsEvicted: [],
97
+ error: new Error('Failed to evict invalid txs after reorg', { cause: err }),
98
+ };
99
+ }
100
+ }
101
+ }
@@ -0,0 +1,86 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+
3
+ import type { EvictionConfig, EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
4
+ import { EvictionEvent } from './interfaces.js';
5
+
6
+ /**
7
+ * Eviction rule that removes low-priority transactions when the pool exceeds configured limits.
8
+ * Only triggers on TXS_ADDED events.
9
+ */
10
+ export class LowPriorityEvictionRule implements EvictionRule {
11
+ public readonly name = 'LowPriorityEviction';
12
+
13
+ private log = createLogger('p2p:tx_pool_v2:low_priority_eviction_rule');
14
+ private maxPoolSize: number;
15
+
16
+ constructor(config: { maxPoolSize: number }) {
17
+ this.maxPoolSize = config.maxPoolSize;
18
+ }
19
+
20
+ async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
21
+ if (context.event !== EvictionEvent.TXS_ADDED) {
22
+ return {
23
+ reason: 'low_priority',
24
+ success: true,
25
+ txsEvicted: [],
26
+ };
27
+ }
28
+
29
+ if (this.maxPoolSize === 0) {
30
+ return {
31
+ reason: 'low_priority',
32
+ success: true,
33
+ txsEvicted: [],
34
+ };
35
+ }
36
+
37
+ try {
38
+ const currentTxCount = pool.getPendingTxCount();
39
+
40
+ if (currentTxCount <= this.maxPoolSize) {
41
+ this.log.trace(
42
+ `Not evicting low priority txs. Pending tx count below limit ${currentTxCount} <= ${this.maxPoolSize}`,
43
+ );
44
+ return {
45
+ reason: 'low_priority',
46
+ success: true,
47
+ txsEvicted: [],
48
+ };
49
+ }
50
+
51
+ this.log.verbose(
52
+ `Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${this.maxPoolSize}`,
53
+ );
54
+ const numberToEvict = currentTxCount - this.maxPoolSize;
55
+ const txsToEvict = pool.getLowestPriorityPending(numberToEvict);
56
+
57
+ if (txsToEvict.length > 0) {
58
+ await pool.deleteTxs(txsToEvict);
59
+ }
60
+
61
+ const numNewTxsEvicted = context.newTxHashes.filter(newTxHash => txsToEvict.includes(newTxHash)).length;
62
+
63
+ this.log.verbose(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`);
64
+
65
+ return {
66
+ reason: 'low_priority',
67
+ success: true,
68
+ txsEvicted: txsToEvict,
69
+ };
70
+ } catch (err) {
71
+ this.log.error('Failed to evict low priority transactions', { err });
72
+ return {
73
+ reason: 'low_priority',
74
+ success: false,
75
+ txsEvicted: [],
76
+ error: new Error('Failed to evict low priority txs', { cause: err }),
77
+ };
78
+ }
79
+ }
80
+
81
+ updateConfig(config: EvictionConfig): void {
82
+ if (config.maxPendingTxCount !== undefined) {
83
+ this.maxPoolSize = config.maxPendingTxCount;
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,72 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+
3
+ import type { TxMetaData } from '../tx_metadata.js';
4
+ import type { EvictionConfig, PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
5
+
6
+ /**
7
+ * Pre-add rule that checks if the pool is at capacity and handles low-priority eviction.
8
+ *
9
+ * When the pool is at capacity:
10
+ * - If incoming tx has higher priority than the lowest priority tx, evict the lowest and accept incoming
11
+ * - If incoming tx has equal or lower priority than the lowest, ignore incoming (it would be evicted anyway)
12
+ */
13
+ export class LowPriorityPreAddRule implements PreAddRule {
14
+ public readonly name = 'LowPriorityPreAdd';
15
+
16
+ private log = createLogger('p2p:tx_pool_v2:low_priority_pre_add_rule');
17
+ private maxPoolSize: number;
18
+
19
+ constructor(config: { maxPoolSize: number }) {
20
+ this.maxPoolSize = config.maxPoolSize;
21
+ }
22
+
23
+ check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
24
+ // Skip if max pool size is disabled (0 = unlimited)
25
+ if (this.maxPoolSize === 0) {
26
+ return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
27
+ }
28
+
29
+ const currentCount = poolAccess.getPendingTxCount();
30
+
31
+ // If pool is not at capacity, accept the tx
32
+ if (currentCount < this.maxPoolSize) {
33
+ return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
34
+ }
35
+
36
+ // Pool is at capacity - need to compare priorities
37
+ const lowestPriorityMeta = poolAccess.getLowestPriorityPendingTx();
38
+ if (!lowestPriorityMeta) {
39
+ // No pending txs (shouldn't happen if count > 0, but handle gracefully)
40
+ return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
41
+ }
42
+
43
+ // If incoming tx has strictly higher priority, evict the lowest priority tx
44
+ if (incomingMeta.priorityFee > lowestPriorityMeta.priorityFee) {
45
+ this.log.debug(
46
+ `Pool at capacity (${currentCount}/${this.maxPoolSize}), evicting ${lowestPriorityMeta.txHash} ` +
47
+ `(priority ${lowestPriorityMeta.priorityFee}) for ${incomingMeta.txHash} (priority ${incomingMeta.priorityFee})`,
48
+ );
49
+ return Promise.resolve({
50
+ shouldIgnore: false,
51
+ txHashesToEvict: [lowestPriorityMeta.txHash],
52
+ });
53
+ }
54
+
55
+ // Incoming tx has equal or lower priority - ignore it (it would be evicted anyway)
56
+ this.log.debug(
57
+ `Pool at capacity (${currentCount}/${this.maxPoolSize}), ignoring ${incomingMeta.txHash} ` +
58
+ `(priority ${incomingMeta.priorityFee}) - lower than existing minimum (priority ${lowestPriorityMeta.priorityFee})`,
59
+ );
60
+ return Promise.resolve({
61
+ shouldIgnore: true,
62
+ txHashesToEvict: [],
63
+ reason: `pool at capacity and tx has lower priority than existing transactions`,
64
+ });
65
+ }
66
+
67
+ updateConfig(config: EvictionConfig): void {
68
+ if (config.maxPendingTxCount !== undefined) {
69
+ this.maxPoolSize = config.maxPendingTxCount;
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,31 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+
3
+ import { type TxMetaData, checkNullifierConflict } from '../tx_metadata.js';
4
+ import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
5
+
6
+ /**
7
+ * Pre-add rule that checks for nullifier conflicts between incoming and existing transactions.
8
+ *
9
+ * When an incoming tx shares nullifiers with existing pending txs:
10
+ * - If the incoming tx has strictly higher priority, evict all conflicting txs
11
+ * - If any conflicting tx has equal or higher priority, ignore the incoming tx
12
+ */
13
+ export class NullifierConflictRule implements PreAddRule {
14
+ public readonly name = 'NullifierConflict';
15
+
16
+ private log = createLogger('p2p:tx_pool_v2:nullifier_conflict_rule');
17
+
18
+ check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
19
+ const result = checkNullifierConflict(
20
+ incomingMeta,
21
+ nullifier => poolAccess.getTxHashByNullifier(nullifier),
22
+ txHash => poolAccess.getMetadata(txHash),
23
+ );
24
+
25
+ if (result.shouldIgnore) {
26
+ this.log.debug(`Ignoring tx ${incomingMeta.txHash}: ${result.reason}`);
27
+ }
28
+
29
+ return Promise.resolve(result);
30
+ }
31
+ }
@@ -0,0 +1,11 @@
1
+ export { AztecKVTxPoolV2 } from './tx_pool_v2.js';
2
+ export {
3
+ type TxPoolV2,
4
+ type TxPoolV2Config,
5
+ type TxPoolV2Events,
6
+ type AddTxsResult,
7
+ type PoolReadAccess,
8
+ DEFAULT_TX_POOL_V2_CONFIG,
9
+ } from './interfaces.js';
10
+ export { type TxMetaData, type TxState, buildTxMetaData, comparePriority } from './tx_metadata.js';
11
+ export { TxArchive } from './archive/index.js';
@@ -0,0 +1,227 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { TypedEventEmitter } from '@aztec/foundation/types';
3
+ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
4
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
5
+ import type { BlockHeader, Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
6
+
7
+ import type { TxMetaData, TxState } from './tx_metadata.js';
8
+
9
+ /**
10
+ * Result of adding transactions to the pending pool.
11
+ * Categorizes transactions by their outcome.
12
+ */
13
+ export type AddTxsResult = {
14
+ /** Transactions successfully added to the pool */
15
+ accepted: TxHash[];
16
+ /** Transactions ignored because they're valid but undesirable (e.g., duplicate, lower priority nullifier conflict) */
17
+ ignored: TxHash[];
18
+ /** Transactions rejected because they failed validation (e.g., invalid proof, expired timestamp) */
19
+ rejected: TxHash[];
20
+ };
21
+
22
+ /**
23
+ * Events emitted by TxPoolV2.
24
+ */
25
+ export type TxPoolV2Events = {
26
+ /** Emitted when transactions are successfully added to the pool */
27
+ 'txs-added': (args: { txs: Tx[]; source?: string }) => void;
28
+ /** Emitted when transactions are removed from the pool */
29
+ 'txs-removed': (args: { txHashes: TxHash[] }) => void;
30
+ };
31
+
32
+ /**
33
+ * Configuration options for TxPoolV2.
34
+ */
35
+ export type TxPoolV2Config = {
36
+ /** Maximum number of pending transactions before low-priority eviction */
37
+ maxPendingTxCount: number;
38
+ /** Maximum number of archived transactions to retain (0 = disabled) */
39
+ archivedTxLimit: number;
40
+ };
41
+
42
+ /**
43
+ * Default configuration values for TxPoolV2.
44
+ */
45
+ export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
46
+ maxPendingTxCount: 0, // 0 = disabled
47
+ archivedTxLimit: 0, // 0 = disabled
48
+ };
49
+
50
+ /**
51
+ * Dependencies required by TxPoolV2.
52
+ */
53
+ export type TxPoolV2Dependencies = {
54
+ /** Block source (Archiver) for checking mined status and verifying pruned blocks */
55
+ l2BlockSource: L2BlockSource;
56
+ /** World state synchronizer for validating transactions after chain prunes */
57
+ worldStateSynchronizer: WorldStateSynchronizer;
58
+ /** Validator for transactions entering the pending pool */
59
+ pendingTxValidator: TxValidator<Tx>;
60
+ };
61
+
62
+ /**
63
+ * Read-only access to pool state for pre-add checks.
64
+ * Used by eviction rules to inspect pool state during transaction addition.
65
+ */
66
+ export interface PoolReadAccess {
67
+ /** Get metadata for a transaction by its hash (as string) */
68
+ getMetadata(txHash: string): TxMetaData | undefined;
69
+ /** Get the transaction hash that uses a specific nullifier (as string) */
70
+ getTxHashByNullifier(nullifier: string): string | undefined;
71
+ /** Get all transaction hashes for a fee payer (as string) */
72
+ getTxHashesByFeePayer(feePayer: string): Set<string> | undefined;
73
+ /** Get the current pending transaction count */
74
+ getPendingTxCount(): number;
75
+ }
76
+
77
+ /**
78
+ *
79
+ * The pool manages transactions through a state machine:
80
+ * - Pending: Transaction is awaiting inclusion in a block
81
+ * - Protected: Transaction is being considered for a block proposal
82
+ * - Mined: Transaction has been included in a block
83
+ * - Deleted: Transaction has been removed from the pool
84
+ *
85
+ * All state-mutating operations are serialized through a handler queue
86
+ * to prevent race conditions.
87
+ */
88
+ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
89
+ // === Core Operations ===
90
+
91
+ /**
92
+ * Adds transactions to the pending pool with challenge and validation.
93
+ * Handles nullifier conflicts via the challenge mechanism.
94
+ * @param txs - Transactions to add
95
+ * @param opts - Optional metadata (e.g., source for logging)
96
+ * @returns Result categorizing each transaction as accepted, rejected, or ignored
97
+ */
98
+ addPendingTxs(txs: Tx[], opts?: { source?: string }): Promise<AddTxsResult>;
99
+
100
+ /**
101
+ * Checks if a transaction can be added without modifying the pool.
102
+ * Performs the same validation as addPendingTxs but doesn't persist changes.
103
+ * @param tx - Transaction to check
104
+ * @returns Result: 'accepted', 'ignored' (if already in pool or undesirable), or 'rejected' (if validation fails)
105
+ */
106
+ canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored' | 'rejected'>;
107
+
108
+ /**
109
+ * Adds transactions as immediately protected for a given slot.
110
+ * Used when receiving transactions from a block proposal we're validating.
111
+ * @param txs - Transactions to add as protected
112
+ * @param block - Block header providing slot context
113
+ * @param opts - Optional metadata (e.g., source for logging)
114
+ */
115
+ addProtectedTxs(txs: Tx[], block: BlockHeader, opts?: { source?: string }): Promise<void>;
116
+
117
+ /**
118
+ * Protects existing transactions by hash for a given slot.
119
+ * Returns hashes of transactions that weren't found in the pool.
120
+ * Records unknown hashes for automatic protection when received via gossip.
121
+ * @param txHashes - Hashes of transactions to protect
122
+ * @param block - Block header providing slot context
123
+ * @returns Hashes of transactions not found in the pool
124
+ */
125
+ protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]>;
126
+
127
+ /**
128
+ * Adds transactions as already mined.
129
+ * Used by prover nodes fetching transactions via request/response.
130
+ * @param txs - Transactions to add as mined
131
+ * @param block - Block header the transactions were mined in
132
+ * @param opts - Optional metadata (e.g., source for logging)
133
+ */
134
+ addMinedTxs(txs: Tx[], block: BlockHeader, opts?: { source?: string }): Promise<void>;
135
+
136
+ // === State Transition Handlers ===
137
+
138
+ /**
139
+ * Handles a mined block - marks transactions as mined and evicts conflicting pending txs.
140
+ * Uses nullifiers directly from the block to evict pending transactions with conflicts.
141
+ * @param block - The complete mined block
142
+ */
143
+ handleMinedBlock(block: L2Block): Promise<void>;
144
+
145
+ /**
146
+ * Prepares the pool for a new slot.
147
+ * Unprotects transactions from earlier slots and validates them before
148
+ * returning to pending state.
149
+ * @param slotNumber - The slot number to prepare for
150
+ */
151
+ prepareForSlot(slotNumber: SlotNumber): Promise<void>;
152
+
153
+ /**
154
+ * Handles pruned blocks during a reorg.
155
+ * Un-mines all transactions mined in blocks beyond the given latest block
156
+ * and validates them before returning to pending.
157
+ * @param latestBlock - The latest valid block ID after the prune
158
+ */
159
+ handlePrunedBlocks(latestBlock: L2BlockId): Promise<void>;
160
+
161
+ /**
162
+ * Handles failed transaction execution.
163
+ * Deletes transactions that failed during block building.
164
+ * @param txHashes - Hashes of transactions that failed
165
+ */
166
+ handleFailedExecution(txHashes: TxHash[]): Promise<void>;
167
+
168
+ /**
169
+ * Handles a finalized block.
170
+ * Permanently deletes mined transactions and optionally archives them.
171
+ * @param block - Header of the finalized block
172
+ */
173
+ handleFinalizedBlock(block: BlockHeader): Promise<void>;
174
+
175
+ /** Gets a transaction by its hash */
176
+ getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
177
+
178
+ /** Gets multiple transactions by their hashes */
179
+ getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
180
+
181
+ /** Checks if transactions exist in the pool */
182
+ hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
183
+
184
+ /** Gets the status of a transaction */
185
+ getTxStatus(txHash: TxHash): Promise<TxState | 'deleted' | undefined>;
186
+
187
+ /** Gets pending transaction hashes sorted by priority (highest first) */
188
+ getPendingTxHashes(): Promise<TxHash[]>;
189
+
190
+ /** Gets the count of pending transactions */
191
+ getPendingTxCount(): Promise<number>;
192
+
193
+ /** Gets mined transaction hashes with their block IDs */
194
+ getMinedTxHashes(): Promise<[TxHash, L2BlockId][]>;
195
+
196
+ /** Gets the count of mined transactions */
197
+ getMinedTxCount(): Promise<number>;
198
+
199
+ /** Checks if the pool is empty */
200
+ isEmpty(): Promise<boolean>;
201
+
202
+ /** Gets an archived transaction by its hash */
203
+ getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
204
+
205
+ /** Gets the lowest priority pending transactions */
206
+ getLowestPriorityPending(limit: number): Promise<TxHash[]>;
207
+
208
+ // === Configuration ===
209
+
210
+ /** Updates the pool configuration */
211
+ updateConfig(config: Partial<TxPoolV2Config>): Promise<void>;
212
+
213
+ // === Lifecycle ===
214
+
215
+ /**
216
+ * Starts the pool and initializes state from persistence.
217
+ * Must be called before other operations.
218
+ * - Reads all transactions from the database
219
+ * - Checks each against the Archiver to determine mined status
220
+ * - Validates all non-mined transactions
221
+ * - Populates in-memory indices
222
+ */
223
+ start(): Promise<void>;
224
+
225
+ /** Stops the pool and releases resources */
226
+ stop(): Promise<void>;
227
+ }