@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.733c4a3

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 (315) hide show
  1. package/dest/client/factory.d.ts +7 -6
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +35 -11
  4. package/dest/client/interface.d.ts +45 -32
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +38 -50
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +145 -200
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -6
  10. package/dest/config.d.ts +24 -8
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +16 -6
  13. package/dest/errors/tx-pool.error.d.ts +8 -0
  14. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  15. package/dest/errors/tx-pool.error.js +9 -0
  16. package/dest/index.d.ts +2 -1
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +1 -0
  19. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
  22. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  25. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  26. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/index.js +1 -2
  28. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  31. package/dest/mem_pools/index.d.ts +3 -2
  32. package/dest/mem_pools/index.d.ts.map +1 -1
  33. package/dest/mem_pools/index.js +1 -1
  34. package/dest/mem_pools/interface.d.ts +5 -5
  35. package/dest/mem_pools/interface.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  37. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  38. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  39. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  40. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  41. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  43. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  44. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
  46. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  47. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +10 -4
  49. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  50. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  53. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  55. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  56. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  57. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  58. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  60. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  61. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  63. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  64. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  66. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -1
  67. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  68. package/dest/mem_pools/tx_pool_v2/index.js +1 -0
  69. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  70. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  72. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -8
  73. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
  75. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +39 -5
  76. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  77. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +74 -5
  78. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  79. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  80. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +27 -4
  81. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  82. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +11 -6
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +13 -5
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +312 -169
  87. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  88. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  90. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  91. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  92. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  93. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  94. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  95. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  96. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  98. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  99. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/factory.js +219 -58
  101. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  104. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  105. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  106. package/dest/msg_validators/tx_validator/index.js +1 -0
  107. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  108. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  109. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  110. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  111. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  113. package/dest/services/dummy_service.d.ts +13 -5
  114. package/dest/services/dummy_service.d.ts.map +1 -1
  115. package/dest/services/dummy_service.js +10 -4
  116. package/dest/services/encoding.d.ts +2 -2
  117. package/dest/services/encoding.d.ts.map +1 -1
  118. package/dest/services/encoding.js +4 -3
  119. package/dest/services/gossipsub/index.d.ts +3 -0
  120. package/dest/services/gossipsub/index.d.ts.map +1 -0
  121. package/dest/services/gossipsub/index.js +2 -0
  122. package/dest/services/gossipsub/scoring.d.ts +21 -3
  123. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  124. package/dest/services/gossipsub/scoring.js +24 -7
  125. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  126. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  127. package/dest/services/gossipsub/topic_score_params.js +346 -0
  128. package/dest/services/libp2p/libp2p_service.d.ts +91 -38
  129. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  130. package/dest/services/libp2p/libp2p_service.js +411 -321
  131. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  132. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  133. package/dest/services/peer-manager/peer_scoring.js +25 -2
  134. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  135. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  136. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  137. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  138. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  139. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  140. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  141. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  142. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  143. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  144. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  145. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  146. package/dest/services/reqresp/interface.d.ts +10 -1
  147. package/dest/services/reqresp/interface.d.ts.map +1 -1
  148. package/dest/services/reqresp/interface.js +15 -1
  149. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
  150. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  151. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  152. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  153. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  154. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  155. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  156. package/dest/services/reqresp/protocols/tx.js +20 -0
  157. package/dest/services/reqresp/reqresp.d.ts +1 -1
  158. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  159. package/dest/services/reqresp/reqresp.js +11 -4
  160. package/dest/services/service.d.ts +39 -3
  161. package/dest/services/service.d.ts.map +1 -1
  162. package/dest/services/tx_collection/config.d.ts +19 -1
  163. package/dest/services/tx_collection/config.d.ts.map +1 -1
  164. package/dest/services/tx_collection/config.js +46 -0
  165. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
  166. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  167. package/dest/services/tx_collection/fast_tx_collection.js +56 -36
  168. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  169. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  170. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  171. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  172. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  173. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  174. package/dest/services/tx_collection/index.d.ts +2 -1
  175. package/dest/services/tx_collection/index.d.ts.map +1 -1
  176. package/dest/services/tx_collection/index.js +1 -0
  177. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  178. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  179. package/dest/services/tx_collection/instrumentation.js +2 -1
  180. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  181. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  182. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  183. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  184. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  185. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  186. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  187. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  188. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  189. package/dest/services/tx_collection/tx_collection.d.ts +23 -10
  190. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  191. package/dest/services/tx_collection/tx_collection.js +75 -3
  192. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  193. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  194. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  195. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  196. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  197. package/dest/services/tx_collection/tx_source.js +19 -2
  198. package/dest/services/tx_file_store/config.d.ts +1 -3
  199. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  200. package/dest/services/tx_file_store/config.js +0 -4
  201. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  202. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  203. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  204. package/dest/services/tx_provider.d.ts +4 -4
  205. package/dest/services/tx_provider.d.ts.map +1 -1
  206. package/dest/services/tx_provider.js +9 -8
  207. package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
  208. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  209. package/dest/test-helpers/mock-pubsub.d.ts +29 -2
  210. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  211. package/dest/test-helpers/mock-pubsub.js +103 -2
  212. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  213. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  214. package/dest/test-helpers/reqresp-nodes.js +2 -1
  215. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  216. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  217. package/dest/test-helpers/testbench-utils.js +128 -59
  218. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  219. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  220. package/dest/testbench/p2p_client_testbench_worker.js +10 -10
  221. package/dest/util.d.ts +2 -2
  222. package/dest/util.d.ts.map +1 -1
  223. package/package.json +14 -14
  224. package/src/client/factory.ts +66 -14
  225. package/src/client/interface.ts +61 -33
  226. package/src/client/p2p_client.ts +179 -236
  227. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
  228. package/src/config.ts +35 -11
  229. package/src/errors/tx-pool.error.ts +12 -0
  230. package/src/index.ts +1 -0
  231. package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
  232. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  233. package/src/mem_pools/attestation_pool/index.ts +9 -2
  234. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  235. package/src/mem_pools/index.ts +4 -1
  236. package/src/mem_pools/interface.ts +4 -4
  237. package/src/mem_pools/tx_pool/README.md +1 -1
  238. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  239. package/src/mem_pools/tx_pool_v2/README.md +76 -10
  240. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  241. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  242. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  243. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
  244. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  245. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  246. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  247. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  248. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  249. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  250. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  251. package/src/mem_pools/tx_pool_v2/index.ts +1 -0
  252. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  253. package/src/mem_pools/tx_pool_v2/interfaces.ts +23 -8
  254. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +103 -9
  255. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +32 -5
  256. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
  257. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +347 -166
  258. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  259. package/src/msg_validators/tx_validator/README.md +115 -0
  260. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  261. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  262. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  263. package/src/msg_validators/tx_validator/factory.ts +353 -77
  264. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  265. package/src/msg_validators/tx_validator/index.ts +1 -0
  266. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  267. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  268. package/src/services/dummy_service.ts +18 -6
  269. package/src/services/encoding.ts +4 -3
  270. package/src/services/gossipsub/README.md +641 -0
  271. package/src/services/gossipsub/index.ts +2 -0
  272. package/src/services/gossipsub/scoring.ts +29 -5
  273. package/src/services/gossipsub/topic_score_params.ts +487 -0
  274. package/src/services/libp2p/libp2p_service.ts +431 -344
  275. package/src/services/peer-manager/peer_scoring.ts +25 -0
  276. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  277. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  278. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  279. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  280. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  281. package/src/services/reqresp/interface.ts +26 -1
  282. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
  283. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  284. package/src/services/reqresp/protocols/tx.ts +22 -0
  285. package/src/services/reqresp/reqresp.ts +13 -3
  286. package/src/services/service.ts +51 -2
  287. package/src/services/tx_collection/config.ts +68 -0
  288. package/src/services/tx_collection/fast_tx_collection.ts +65 -32
  289. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  290. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  291. package/src/services/tx_collection/index.ts +1 -0
  292. package/src/services/tx_collection/instrumentation.ts +7 -1
  293. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  294. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  295. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  296. package/src/services/tx_collection/tx_collection.ts +113 -16
  297. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  298. package/src/services/tx_collection/tx_source.ts +22 -3
  299. package/src/services/tx_file_store/config.ts +0 -6
  300. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  301. package/src/services/tx_provider.ts +10 -9
  302. package/src/test-helpers/make-test-p2p-clients.ts +3 -3
  303. package/src/test-helpers/mock-pubsub.ts +143 -3
  304. package/src/test-helpers/reqresp-nodes.ts +2 -1
  305. package/src/test-helpers/testbench-utils.ts +127 -71
  306. package/src/testbench/p2p_client_testbench_worker.ts +22 -15
  307. package/src/util.ts +7 -1
  308. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  309. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  310. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  311. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  312. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  313. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  314. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  315. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
@@ -1,2 +1,9 @@
1
- export * from './attestation_pool.js';
2
- export * from './memory_attestation_pool.js';
1
+ export {
2
+ AttestationPool,
3
+ type AttestationPoolApi,
4
+ type TryAddResult,
5
+ createTestAttestationPool,
6
+ MAX_CHECKPOINT_PROPOSALS_PER_SLOT,
7
+ MAX_BLOCK_PROPOSALS_PER_POSITION,
8
+ MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER,
9
+ } from './attestation_pool.js';
@@ -34,9 +34,10 @@ export const mockCheckpointAttestation = (
34
34
  slot: number = 0,
35
35
  archive: Fr = Fr.random(),
36
36
  header?: CheckpointHeader,
37
+ feeAssetPriceModifier: bigint = 0n,
37
38
  ): CheckpointAttestation => {
38
39
  header = header ?? CheckpointHeader.random({ slotNumber: SlotNumber(slot) });
39
- const payload = new ConsensusPayload(header, archive);
40
+ const payload = new ConsensusPayload(header, archive, feeAssetPriceModifier);
40
41
 
41
42
  const attestationHash = getHashedSignaturePayloadEthSignedMessage(
42
43
  payload,
@@ -1,3 +1,6 @@
1
- export { type AttestationPool } from './attestation_pool/attestation_pool.js';
1
+ export { AttestationPool, type AttestationPoolApi } from './attestation_pool/attestation_pool.js';
2
2
  export { type MemPools } from './interface.js';
3
+ // Old TxPool exports - kept temporarily for external consumers
3
4
  export { type TxPool } from './tx_pool/tx_pool.js';
5
+ // New TxPoolV2 exports
6
+ export { type TxPoolV2, type TxPoolV2Config, type TxPoolV2Events, type AddTxsResult } from './tx_pool_v2/index.js';
@@ -1,10 +1,10 @@
1
- import type { AttestationPool } from './attestation_pool/attestation_pool.js';
2
- import type { TxPool } from './tx_pool/tx_pool.js';
1
+ import type { AttestationPoolApi } from './attestation_pool/attestation_pool.js';
2
+ import type { TxPoolV2 } from './tx_pool_v2/interfaces.js';
3
3
 
4
4
  /**
5
5
  * A interface the combines all mempools
6
6
  */
7
7
  export type MemPools = {
8
- txPool: TxPool;
9
- attestationPool: AttestationPool;
8
+ txPool: TxPoolV2;
9
+ attestationPool: AttestationPoolApi;
10
10
  };
@@ -213,7 +213,7 @@ The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
213
213
  Evicts transactions that become invalid after a block is mined:
214
214
 
215
215
  - Duplicate nullifiers: Txs with nullifiers already included in the mined block
216
- - Expired transactions: Txs with `includeByTimestamp` ≤ mined block timestamp
216
+ - Expired transactions: Txs with `expirationTimestamp` ≤ mined block timestamp
217
217
 
218
218
  #### 2. `InvalidTxsAfterReorgRule`
219
219
 
@@ -68,10 +68,10 @@ export class InvalidTxsAfterMiningRule implements EvictionRule {
68
68
  }
69
69
 
70
70
  // Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
71
- const includeByTimestamp = tx.data.includeByTimestamp;
72
- if (includeByTimestamp <= timestamp) {
71
+ const expirationTimestamp = tx.data.expirationTimestamp;
72
+ if (expirationTimestamp <= timestamp) {
73
73
  this.log.verbose(
74
- `Evicting tx ${txHash} from pool due to the tx being expired (includeByTimestamp: ${includeByTimestamp}, mined block timestamp: ${timestamp})`,
74
+ `Evicting tx ${txHash} from pool due to the tx being expired (expirationTimestamp: ${expirationTimestamp}, mined block timestamp: ${timestamp})`,
75
75
  );
76
76
  txsToEvict.push(txHash);
77
77
  continue;
@@ -28,13 +28,22 @@ TxPoolV2 manages transactions through a state machine with clear transitions:
28
28
  │ MINED │───────────────────┘
29
29
  │ (included in a block) │ handlePrunedBlocks()
30
30
  └─────────────────────────────────────┘ (reorg)
31
-
32
- │ handleFinalizedBlock()
33
-
34
- ┌─────────────────────────────────────┐
35
- │ DELETED │
36
- (optionally archived)
37
- └─────────────────────────────────────┘
31
+
32
+ │ handleFinalizedBlock() │ eviction after reorg
33
+ │ / eviction / failed exec │ (validation failure)
34
+ ▼ ▼
35
+ ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
36
+ SLOT-SOFT-DELETED │ PRUNE-SOFT-DELETED │
37
+ │ (kept in DB until next slot) │ │ (kept in DB until finalized) │
38
+ └─────────────────────────────────────┘ └─────────────────────────────────────┘
39
+ │ │
40
+ │ prepareForSlot() │ handleFinalizedBlock()
41
+ │ (slot advanced) │ (mined block finalized)
42
+ ▼ ▼
43
+ ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
44
+ │ HARD-DELETED │ │ HARD-DELETED │
45
+ │ (permanently removed from DB) │ │ (permanently removed from DB) │
46
+ └─────────────────────────────────────┘ └─────────────────────────────────────┘
38
47
  ```
39
48
 
40
49
  ## Key Components
@@ -52,6 +61,14 @@ Core implementation containing:
52
61
  - Pre-add rule execution
53
62
  - Post-event eviction rule execution
54
63
 
64
+ ### DeletedPool (`deleted_pool.ts`)
65
+
66
+ Manages all transaction deletions in the pool with two soft-deletion mechanisms:
67
+ - **Slot-based**: Non-pruned txs are kept in DB until the next slot, allowing other nodes to fetch them via reqresp
68
+ - **Prune-based**: Txs from pruned blocks are kept in DB until their original mined block is finalized
69
+
70
+ All deletions go through `DeletedPool.deleteTx()`, which routes to the appropriate path based on whether the tx is tracked as being from a pruned block.
71
+
55
72
  ### TxMetaData (`tx_metadata.ts`)
56
73
 
57
74
  Lightweight metadata stored alongside each transaction:
@@ -62,14 +79,60 @@ Lightweight metadata stored alongside each transaction:
62
79
  - `claimAmount`: Fee payer's claim from bridging
63
80
  - `feeLimit`: Maximum fee the tx can pay
64
81
  - `nullifiers`: For conflict detection
65
- - `includeByTimestamp`: Expiration timestamp
82
+ - `expirationTimestamp`: Expiration timestamp
66
83
  - `minedL2BlockId`: Set when mined (undefined otherwise)
67
84
 
68
85
  State is derived by TxPoolIndices:
69
86
  - `mined` if `minedL2BlockId` is set
70
87
  - `protected` if in protection map
88
+ - `deleted` if soft-deleted (slot-based or prune-based, evicted but kept in DB)
71
89
  - `pending` otherwise
72
90
 
91
+ ## Soft Deletion
92
+
93
+ Deleted transactions are kept in the database for a grace period before being permanently removed. There are two soft-deletion mechanisms:
94
+
95
+ ### Slot-Based Soft Deletion
96
+
97
+ When a transaction is deleted from the pool (eviction, validation failure, failed execution) and is **not** from a pruned block, it is "slot-soft-deleted":
98
+
99
+ 1. **Soft Delete**: The tx is removed from indices but kept in the database, tagged with the current slot number
100
+ 2. **Retrieval**: Slot-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
101
+ 3. **Hard Delete**: When `prepareForSlot` advances to a new slot, txs deleted in earlier slots are permanently removed
102
+ 4. **Re-addition**: If a slot-soft-deleted tx is re-added to the pool, the slot-deleted tracking is cleared
103
+
104
+ This allows other nodes to still fetch recently-deleted transactions via reqresp during the current slot.
105
+
106
+ ### Prune-Based Soft Deletion
107
+
108
+ When a chain reorganization occurs, transactions that were mined in pruned blocks are handled with longer retention:
109
+
110
+ 1. **Tracking**: When `handlePrunedBlocks` is called, all un-mined transactions are tracked by their original mined block number
111
+ 2. **Soft Delete**: If these transactions are later evicted (failed validation, nullifier conflict, etc.), they are "prune-soft-deleted" - removed from indices but kept in the database
112
+ 3. **Retrieval**: Prune-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
113
+ 4. **Hard Delete**: When `handleFinalizedBlock` is called and the finalized block number reaches or exceeds the transaction's original mined block, the transaction is permanently removed
114
+ 5. **Re-addition**: If a prune-soft-deleted tx is re-added, the `softDeleted` flag is reset to `false` but the prune tracking is preserved, so a subsequent deletion still uses the prune path
115
+
116
+ Prune-soft-deleted transactions are **not** affected by slot cleanup - they survive across slot boundaries until finalized.
117
+
118
+ **Prune example:**
119
+ 1. Tx mined at block 10
120
+ 2. Chain prunes to block 5 (tx becomes un-mined, tracked as minedAtBlock=10)
121
+ 3. Tx fails validation and is prune-soft-deleted
122
+ 4. Block 9 finalized → tx still in DB (minedAtBlock=10 > finalized=9)
123
+ 5. Block 10 finalized → tx hard-deleted (minedAtBlock=10 ≤ finalized=10)
124
+
125
+ If the tx is re-mined at a higher block before being soft-deleted:
126
+ 1. Tx mined at block 10, pruned (tracked as minedAtBlock=10)
127
+ 2. Tx re-mined at block 15, pruned again (updated to minedAtBlock=15)
128
+ 3. Tx soft-deleted
129
+ 4. Block 10 finalized → tx still in DB
130
+ 5. Block 15 finalized → tx hard-deleted
131
+
132
+ ### Hydration
133
+
134
+ On node restart, slot-soft-deleted transactions are immediately hard-deleted (they are stale by definition). Prune-soft-deleted transactions are loaded from the database and tracked normally.
135
+
73
136
  ## Architecture: Pre-add vs Post-event Rules
74
137
 
75
138
  **Pre-add rules** (run during `addPendingTxs`):
@@ -120,7 +183,7 @@ import { AztecKVTxPoolV2 } from './tx_pool_v2.js';
120
183
  const pool = new AztecKVTxPoolV2(txStore, archiveStore, {
121
184
  l2BlockSource: archiver,
122
185
  worldStateSynchronizer: worldState,
123
- pendingTxValidator: validator,
186
+ createTxValidator: () => validator,
124
187
  });
125
188
 
126
189
  await pool.start();
@@ -195,9 +258,12 @@ The archive uses FIFO eviction when `archivedTxLimit` is reached.
195
258
  ## Testing
196
259
 
197
260
  ```bash
198
- # Unit tests (131 tests)
261
+ # Unit tests (177 tests)
199
262
  yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts
200
263
 
264
+ # Deleted pool tests (17 tests)
265
+ yarn test src/mem_pools/tx_pool_v2/deleted_pool.test.ts
266
+
201
267
  # Compatibility tests (25 tests)
202
268
  yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.compat.test.ts
203
269
 
@@ -0,0 +1,321 @@
1
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+ import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSet } from '@aztec/kv-store';
4
+
5
+ /**
6
+ * State stored for each transaction from a pruned block.
7
+ */
8
+ type DeletedTxState = {
9
+ /** Block number in which the transaction was originally mined (before being un-mined by a prune) */
10
+ minedAtBlock: BlockNumber;
11
+ /** Whether the transaction has been soft-deleted (removed from indices) */
12
+ softDeleted: boolean;
13
+ };
14
+
15
+ /**
16
+ * Serializes DeletedTxState to a Buffer.
17
+ * Format: 4 bytes for blockNumber (uint32) + 1 byte for softDeleted (0 or 1)
18
+ */
19
+ function serializeState(state: DeletedTxState): Buffer {
20
+ const buffer = Buffer.alloc(5);
21
+ buffer.writeUInt32BE(Number(state.minedAtBlock), 0);
22
+ buffer.writeUInt8(state.softDeleted ? 1 : 0, 4);
23
+ return buffer;
24
+ }
25
+
26
+ /**
27
+ * Deserializes a Buffer to DeletedTxState.
28
+ */
29
+ function deserializeState(buffer: Buffer): DeletedTxState {
30
+ return {
31
+ minedAtBlock: BlockNumber(buffer.readUInt32BE(0)),
32
+ softDeleted: buffer.readUInt8(4) === 1,
33
+ };
34
+ }
35
+
36
+ /**
37
+ * Manages all transaction deletions in the pool.
38
+ *
39
+ * When a chain prune (reorg) happens, transactions from pruned blocks are tracked here.
40
+ * This class is responsible for ALL deletion decisions:
41
+ *
42
+ * - Transactions from pruned blocks are "prune-soft-deleted" - removed from indices but kept
43
+ * in the database for later re-execution until their mined block is finalized
44
+ * - Transactions NOT from pruned blocks are "slot-soft-deleted" - kept in the database
45
+ * until the next slot, so other nodes can still fetch them via reqresp
46
+ *
47
+ * When a block is finalized, prune-soft-deleted transactions that were originally mined at or
48
+ * before that block number are permanently (hard) deleted. Slot-soft-deleted transactions
49
+ * are hard-deleted when `prepareForSlot` advances to a new slot.
50
+ */
51
+ export class DeletedPool {
52
+ /** Persisted map: txHash -> DeletedTxState (serialized) - for prune-based soft deletions */
53
+ #deletedTxsDB: AztecAsyncMap<string, Buffer>;
54
+
55
+ /** Reference to the main txs database for hard deletion */
56
+ #txsDB: AztecAsyncMap<string, Buffer>;
57
+
58
+ /** In-memory state for transactions from pruned blocks */
59
+ #state: Map<string, DeletedTxState> = new Map();
60
+
61
+ /** In-memory tracking: txHash -> slot at which the tx was deleted */
62
+ #slotDeletedTxs: Map<string, SlotNumber> = new Map();
63
+
64
+ /** Persisted set tracking which txs are slot-deleted, for hydration cleanup. */
65
+ #slotDeletedDB: AztecAsyncSet<string>;
66
+
67
+ /** Current slot number, updated by cleanupSlotDeleted */
68
+ #currentSlot: SlotNumber = SlotNumber(0);
69
+
70
+ #log: Logger;
71
+
72
+ constructor(store: AztecAsyncKVStore, txsDB: AztecAsyncMap<string, Buffer>, log: Logger) {
73
+ this.#deletedTxsDB = store.openMap('deleted_txs');
74
+ this.#slotDeletedDB = store.openSet('slot_deleted_txs');
75
+ this.#txsDB = txsDB;
76
+ this.#log = log;
77
+ }
78
+
79
+ /**
80
+ * Loads state from the database on startup.
81
+ * Slot-deleted txs are stale after restart and are immediately hard-deleted.
82
+ */
83
+ async hydrateFromDatabase(): Promise<void> {
84
+ let prunedCount = 0;
85
+ let softDeletedCount = 0;
86
+
87
+ for await (const [txHash, buffer] of this.#deletedTxsDB.entriesAsync()) {
88
+ const state = deserializeState(buffer);
89
+ this.#state.set(txHash, state);
90
+ prunedCount++;
91
+ if (state.softDeleted) {
92
+ softDeletedCount++;
93
+ }
94
+ }
95
+
96
+ if (prunedCount > 0 || softDeletedCount > 0) {
97
+ this.#log.info(`Loaded ${prunedCount} txs from pruned blocks, ${softDeletedCount} soft-deleted`);
98
+ }
99
+
100
+ // Slot-deleted txs are stale after restart - hard-delete them all
101
+ let slotDeletedCount = 0;
102
+ for await (const txHash of this.#slotDeletedDB.entriesAsync()) {
103
+ await this.#txsDB.delete(txHash);
104
+ await this.#slotDeletedDB.delete(txHash);
105
+ slotDeletedCount++;
106
+ }
107
+
108
+ if (slotDeletedCount > 0) {
109
+ this.#log.info(`Hard-deleted ${slotDeletedCount} stale slot-deleted txs on startup`);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Marks transactions as being from a pruned block.
115
+ * Called during handlePrunedBlocks for ALL transactions that were un-mined.
116
+ *
117
+ * If a tx was previously tracked (e.g., mined at block 4, pruned, re-mined at block 5,
118
+ * pruned again), updates to the higher block number. This ensures the tx is kept until
119
+ * its most recent mined block is finalized.
120
+ *
121
+ * @param txs - Array of {txHash, minedAtBlock} pairs, where minedAtBlock is the block
122
+ * number in which the tx was mined before being un-mined
123
+ */
124
+ async markFromPrunedBlock(txs: { txHash: string; minedAtBlock: BlockNumber }[]): Promise<void> {
125
+ if (txs.length === 0) {
126
+ return;
127
+ }
128
+
129
+ let count = 0;
130
+ for (const { txHash, minedAtBlock } of txs) {
131
+ const existing = this.#state.get(txHash);
132
+ // Update if not tracked, or if this is a higher mined block (tx was re-mined then pruned again)
133
+ if (existing === undefined || minedAtBlock > existing.minedAtBlock) {
134
+ const state: DeletedTxState = {
135
+ minedAtBlock,
136
+ softDeleted: existing?.softDeleted ?? false,
137
+ };
138
+ this.#state.set(txHash, state);
139
+ await this.#deletedTxsDB.set(txHash, serializeState(state));
140
+ count++;
141
+ }
142
+ }
143
+
144
+ if (count > 0) {
145
+ this.#log.info(`Marked ${count} transactions from pruned blocks`);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Deletes a transaction. This is the single entry point for ALL deletions.
151
+ * The tx is always soft-deleted (kept in DB):
152
+ *
153
+ * - If the tx is from a pruned block: prune-soft-delete (kept until finalized)
154
+ * - If the tx is NOT from a pruned block: slot-soft-delete (kept until next slot)
155
+ */
156
+ async deleteTx(txHash: string): Promise<void> {
157
+ const existing = this.#state.get(txHash);
158
+ if (existing !== undefined) {
159
+ // Prune-soft-delete - keep in DB until finalized
160
+ const state: DeletedTxState = {
161
+ minedAtBlock: existing.minedAtBlock,
162
+ softDeleted: true,
163
+ };
164
+ this.#state.set(txHash, state);
165
+ await this.#deletedTxsDB.set(txHash, serializeState(state));
166
+ } else {
167
+ // Slot-soft-delete - keep in DB until next slot
168
+ this.#slotDeletedTxs.set(txHash, this.#currentSlot);
169
+ await this.#slotDeletedDB.add(txHash);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Clears tracking for a transaction if it re-mines at a block number >= the tracked minedAtBlock.
175
+ *
176
+ * When a tx re-mines at a higher (or equal) block, the old high-water mark is no longer needed:
177
+ * any future prune would re-add the tx with an even higher block number. Clearing keeps
178
+ * DeletedPool consistent — only txs that are actually un-mined should be tracked here.
179
+ *
180
+ * When a tx re-mines at a lower block, we must preserve the existing entry to retain
181
+ * the high-water mark for re-execution purposes.
182
+ */
183
+ async clearIfMinedHigher(txHash: string, minedAtBlock: BlockNumber): Promise<void> {
184
+ const existing = this.#state.get(txHash);
185
+ if (existing !== undefined && minedAtBlock >= existing.minedAtBlock) {
186
+ this.#state.delete(txHash);
187
+ await this.#deletedTxsDB.delete(txHash);
188
+ this.#log.debug(
189
+ `Cleared tracking for tx ${txHash}: re-mined at block ${minedAtBlock} (was ${existing.minedAtBlock})`,
190
+ );
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Checks if a transaction is from a pruned block.
196
+ */
197
+ isFromPrunedBlock(txHash: string): boolean {
198
+ return this.#state.has(txHash);
199
+ }
200
+
201
+ /**
202
+ * Checks if a transaction is soft-deleted (either prune-based or slot-based).
203
+ */
204
+ isSoftDeleted(txHash: string): boolean {
205
+ return (this.#state.get(txHash)?.softDeleted ?? false) || this.#slotDeletedTxs.has(txHash);
206
+ }
207
+
208
+ /**
209
+ * Gets the block number in which a transaction was originally mined.
210
+ */
211
+ getMinedAtBlock(txHash: string): BlockNumber | undefined {
212
+ return this.#state.get(txHash)?.minedAtBlock;
213
+ }
214
+
215
+ /**
216
+ * Finalizes transactions when a block is finalized.
217
+ * Hard-deletes transactions that were originally mined at or before the finalized block.
218
+ *
219
+ * @returns The hashes of transactions that were hard-deleted
220
+ */
221
+ async finalizeBlock(finalizedBlockNumber: BlockNumber): Promise<string[]> {
222
+ const toHardDelete: string[] = [];
223
+ for (const [txHash, state] of this.#state) {
224
+ if (state.softDeleted && state.minedAtBlock <= finalizedBlockNumber) {
225
+ toHardDelete.push(txHash);
226
+ }
227
+ }
228
+
229
+ if (toHardDelete.length === 0) {
230
+ return [];
231
+ }
232
+
233
+ // Hard-delete from all stores
234
+ for (const txHash of toHardDelete) {
235
+ this.#state.delete(txHash);
236
+ await this.#deletedTxsDB.delete(txHash);
237
+ await this.#txsDB.delete(txHash);
238
+ }
239
+
240
+ this.#log.debug(`Finalized ${toHardDelete.length} txs from pruned blocks at block ${finalizedBlockNumber}`, {
241
+ txHashes: toHardDelete,
242
+ });
243
+ return toHardDelete;
244
+ }
245
+
246
+ /**
247
+ * Cleans up slot-deleted transactions from previous slots.
248
+ * Called at the start of prepareForSlot. Updates #currentSlot and hard-deletes
249
+ * any txs that were deleted in an earlier slot.
250
+ */
251
+ async cleanupSlotDeleted(currentSlot: SlotNumber): Promise<void> {
252
+ const previousSlot = this.#currentSlot;
253
+ this.#currentSlot = currentSlot;
254
+
255
+ const toHardDelete: string[] = [];
256
+ for (const [txHash, deletedAtSlot] of this.#slotDeletedTxs) {
257
+ if (deletedAtSlot < currentSlot) {
258
+ toHardDelete.push(txHash);
259
+ }
260
+ }
261
+
262
+ if (toHardDelete.length === 0) {
263
+ return;
264
+ }
265
+
266
+ for (const txHash of toHardDelete) {
267
+ this.#slotDeletedTxs.delete(txHash);
268
+ await this.#slotDeletedDB.delete(txHash);
269
+ await this.#txsDB.delete(txHash);
270
+ }
271
+
272
+ this.#log.debug(
273
+ `Cleaned up ${toHardDelete.length} slot-deleted txs from slot ${previousSlot} (now slot ${currentSlot})`,
274
+ { txHashes: toHardDelete },
275
+ );
276
+ }
277
+
278
+ /**
279
+ * Clears soft-deletion status for a transaction being re-added to the pool.
280
+ * Removes slot-deleted tracking entirely, and resets the prune-soft-deleted flag
281
+ * while preserving the prune tracking itself (so a subsequent delete still uses
282
+ * the prune path).
283
+ */
284
+ async clearSoftDeleted(txHash: string): Promise<void> {
285
+ if (this.#slotDeletedTxs.has(txHash)) {
286
+ this.#slotDeletedTxs.delete(txHash);
287
+ await this.#slotDeletedDB.delete(txHash);
288
+ }
289
+ const existing = this.#state.get(txHash);
290
+ if (existing?.softDeleted) {
291
+ const state: DeletedTxState = { minedAtBlock: existing.minedAtBlock, softDeleted: false };
292
+ this.#state.set(txHash, state);
293
+ await this.#deletedTxsDB.set(txHash, serializeState(state));
294
+ }
295
+ }
296
+
297
+ /**
298
+ * Gets the count of transactions from pruned blocks.
299
+ */
300
+ getCount(): number {
301
+ return this.#state.size;
302
+ }
303
+
304
+ /** Gets the count of soft-deleted transactions (both prune-based and slot-based). */
305
+ getSoftDeletedCount(): number {
306
+ let count = this.#slotDeletedTxs.size;
307
+ for (const state of this.#state.values()) {
308
+ if (state.softDeleted) {
309
+ count++;
310
+ }
311
+ }
312
+ return count;
313
+ }
314
+
315
+ /**
316
+ * Gets all transaction hashes from pruned blocks.
317
+ */
318
+ getPrunedTxHashes(): string[] {
319
+ return Array.from(this.#state.keys());
320
+ }
321
+ }
@@ -9,9 +9,12 @@ import {
9
9
  EvictionEvent,
10
10
  type EvictionRule,
11
11
  type PoolOperations,
12
+ type PreAddContext,
12
13
  type PreAddPoolAccess,
13
14
  type PreAddResult,
14
15
  type PreAddRule,
16
+ type TaggedEviction,
17
+ TxPoolRejectionCode,
15
18
  } from './interfaces.js';
16
19
 
17
20
  /**
@@ -47,21 +50,27 @@ export class EvictionManager {
47
50
  * Runs all pre-add rules for an incoming transaction.
48
51
  * Returns combined result of all rules.
49
52
  */
50
- async runPreAddRules(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
51
- const allTxHashesToEvict: string[] = [];
53
+ async runPreAddRules(
54
+ incomingMeta: TxMetaData,
55
+ poolAccess: PreAddPoolAccess,
56
+ context?: PreAddContext,
57
+ ): Promise<PreAddResult> {
58
+ const evictions: TaggedEviction[] = [];
59
+ const seen = new Set<string>();
52
60
 
53
61
  for (const rule of this.preAddRules) {
54
62
  try {
55
- const result = await rule.check(incomingMeta, poolAccess);
63
+ const result = await rule.check(incomingMeta, poolAccess, context);
56
64
 
57
65
  if (result.shouldIgnore) {
58
66
  return result;
59
67
  }
60
68
 
61
- // Collect txs to evict from all rules
69
+ // Collect txs to evict from all rules, tagged with the rule name
62
70
  for (const txHash of result.txHashesToEvict) {
63
- if (!allTxHashesToEvict.includes(txHash)) {
64
- allTxHashesToEvict.push(txHash);
71
+ if (!seen.has(txHash)) {
72
+ seen.add(txHash);
73
+ evictions.push({ txHash, reason: rule.name });
65
74
  }
66
75
  }
67
76
  } catch (err) {
@@ -70,14 +79,18 @@ export class EvictionManager {
70
79
  return {
71
80
  shouldIgnore: true,
72
81
  txHashesToEvict: [],
73
- reason: `pre-add rule ${rule.name} error: ${err}`,
82
+ reason: {
83
+ code: TxPoolRejectionCode.INTERNAL_ERROR,
84
+ message: `Pre-add rule ${rule.name} error: ${err}`,
85
+ },
74
86
  };
75
87
  }
76
88
  }
77
89
 
78
90
  return {
79
91
  shouldIgnore: false,
80
- txHashesToEvict: allTxHashesToEvict,
92
+ txHashesToEvict: evictions.map(e => e.txHash),
93
+ evictions,
81
94
  };
82
95
  }
83
96
 
@@ -34,7 +34,7 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
34
34
  }
35
35
 
36
36
  if (context.event === EvictionEvent.CHAIN_PRUNED) {
37
- await this.worldState.syncImmediate(context.blockNumber);
37
+ await this.worldState.syncImmediate();
38
38
  const feePayers = pool.getPendingFeePayers();
39
39
  return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), pool);
40
40
  }
@@ -67,7 +67,10 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
67
67
  ).flat();
68
68
 
69
69
  if (txsToEvict.length > 0) {
70
- await pool.deleteTxs(txsToEvict);
70
+ await pool.deleteTxs(txsToEvict, this.name);
71
+ this.log.debug(`Evicted ${txsToEvict.length} txs due to insufficient fee payer balance`, {
72
+ txHashes: txsToEvict,
73
+ });
71
74
  }
72
75
 
73
76
  return {
@@ -1,7 +1,13 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import { type TxMetaData, comparePriority } from '../tx_metadata.js';
4
- import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
4
+ import {
5
+ type PreAddContext,
6
+ type PreAddPoolAccess,
7
+ type PreAddResult,
8
+ type PreAddRule,
9
+ TxPoolRejectionCode,
10
+ } from './interfaces.js';
5
11
 
6
12
  /**
7
13
  * Pre-add rule that checks if a fee payer has sufficient balance to cover the incoming transaction.
@@ -19,7 +25,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
19
25
 
20
26
  private log = createLogger('p2p:tx_pool_v2:fee_payer_balance_pre_add_rule');
21
27
 
22
- async check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
28
+ async check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, _context?: PreAddContext): Promise<PreAddResult> {
23
29
  // Get fee payer's on-chain balance
24
30
  const initialBalance = await poolAccess.getFeePayerBalance(incomingMeta.feePayer);
25
31
 
@@ -78,7 +84,13 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
78
84
  return {
79
85
  shouldIgnore: true,
80
86
  txHashesToEvict: [],
81
- reason: `fee payer ${incomingMeta.feePayer} has insufficient balance`,
87
+ reason: {
88
+ code: TxPoolRejectionCode.INSUFFICIENT_FEE_PAYER_BALANCE,
89
+ message: `Fee payer ${incomingMeta.feePayer} has insufficient balance. Balance at transaction: ${available}, required: ${incomingMeta.feeLimit}`,
90
+ currentBalance: initialBalance,
91
+ availableBalance: available,
92
+ feeLimit: incomingMeta.feeLimit,
93
+ },
82
94
  };
83
95
  } else {
84
96
  // Existing tx cannot be covered after adding incoming - mark for eviction
@@ -93,7 +105,6 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
93
105
  return {
94
106
  shouldIgnore: true,
95
107
  txHashesToEvict: [],
96
- reason: 'internal error: tx coverage not determined',
97
108
  };
98
109
  }
99
110
 
@@ -6,9 +6,13 @@ export {
6
6
  type EvictionResult,
7
7
  type EvictionRule,
8
8
  type PoolOperations,
9
+ type PreAddContext,
9
10
  type PreAddPoolAccess,
10
11
  type PreAddResult,
11
12
  type PreAddRule,
13
+ type TaggedEviction,
14
+ TxPoolRejectionCode,
15
+ type TxPoolRejectionError,
12
16
  } from './interfaces.js';
13
17
 
14
18
  // Pre-add rules