@aztec/p2p 0.0.1-commit.64b6bbb → 0.0.1-commit.684755437

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 (295) hide show
  1. package/dest/client/factory.d.ts +7 -7
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +24 -30
  4. package/dest/client/interface.d.ts +14 -19
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +9 -18
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +52 -96
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
  10. package/dest/config.d.ts +31 -15
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +71 -37
  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/mem_pools/attestation_pool/attestation_pool.d.ts +4 -2
  17. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool.js +10 -1
  19. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  20. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  22. package/dest/mem_pools/instrumentation.d.ts +4 -2
  23. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  24. package/dest/mem_pools/instrumentation.js +16 -14
  25. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  26. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +30 -13
  27. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +91 -20
  29. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  30. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  32. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  33. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  34. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
  35. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  36. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  38. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  39. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  41. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  42. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  44. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  45. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  46. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  47. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  49. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  50. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  52. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  53. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  55. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  56. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  58. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  59. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  60. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  61. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -6
  62. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  64. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +48 -14
  65. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  66. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +100 -17
  67. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  68. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  69. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +50 -45
  70. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  71. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +14 -6
  73. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  74. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  75. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +300 -142
  76. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  77. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  78. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  79. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  80. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  82. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  83. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
  85. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  86. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  87. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  88. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  89. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  91. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  92. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  93. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  94. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  95. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  96. package/dest/msg_validators/tx_validator/factory.js +219 -58
  97. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  98. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  99. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  100. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  101. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  102. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  103. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  104. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  105. package/dest/msg_validators/tx_validator/index.js +2 -0
  106. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  107. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  108. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  109. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  110. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  111. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
  113. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  114. package/dest/msg_validators/tx_validator/phases_validator.js +44 -23
  115. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  116. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  117. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  118. package/dest/services/dummy_service.d.ts +4 -4
  119. package/dest/services/dummy_service.d.ts.map +1 -1
  120. package/dest/services/dummy_service.js +4 -4
  121. package/dest/services/encoding.d.ts +2 -2
  122. package/dest/services/encoding.d.ts.map +1 -1
  123. package/dest/services/encoding.js +9 -8
  124. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  125. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  126. package/dest/services/gossipsub/topic_score_params.js +32 -10
  127. package/dest/services/libp2p/libp2p_service.d.ts +16 -13
  128. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  129. package/dest/services/libp2p/libp2p_service.js +84 -90
  130. package/dest/services/peer-manager/metrics.d.ts +3 -1
  131. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  132. package/dest/services/peer-manager/metrics.js +6 -0
  133. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  134. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  135. package/dest/services/peer-manager/peer_manager.js +2 -1
  136. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  137. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  138. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  139. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  140. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  141. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  142. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  143. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  144. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  145. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  146. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  147. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  148. package/dest/services/reqresp/reqresp.d.ts +1 -1
  149. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  150. package/dest/services/reqresp/reqresp.js +2 -1
  151. package/dest/services/service.d.ts +5 -3
  152. package/dest/services/service.d.ts.map +1 -1
  153. package/dest/services/tx_collection/config.d.ts +13 -1
  154. package/dest/services/tx_collection/config.d.ts.map +1 -1
  155. package/dest/services/tx_collection/config.js +30 -0
  156. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  157. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  158. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  159. package/dest/services/tx_collection/file_store_tx_collection.d.ts +38 -29
  160. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  161. package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
  162. package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
  163. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  164. package/dest/services/tx_collection/file_store_tx_source.js +49 -16
  165. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  166. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  167. package/dest/services/tx_collection/instrumentation.js +2 -1
  168. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  169. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  170. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  171. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  172. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  173. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  174. package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
  175. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  176. package/dest/services/tx_collection/slow_tx_collection.js +17 -12
  177. package/dest/services/tx_collection/tx_collection.d.ts +9 -6
  178. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  179. package/dest/services/tx_collection/tx_collection.js +26 -10
  180. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  181. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  182. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  183. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  184. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  185. package/dest/services/tx_collection/tx_source.js +19 -2
  186. package/dest/services/tx_file_store/tx_file_store.d.ts +3 -2
  187. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  188. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  189. package/dest/services/tx_provider.d.ts +3 -3
  190. package/dest/services/tx_provider.d.ts.map +1 -1
  191. package/dest/services/tx_provider.js +4 -4
  192. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  193. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  194. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  195. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  196. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  197. package/dest/test-helpers/mock-pubsub.js +8 -2
  198. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  199. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  200. package/dest/test-helpers/reqresp-nodes.js +2 -2
  201. package/dest/test-helpers/testbench-utils.d.ts +8 -3
  202. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  203. package/dest/test-helpers/testbench-utils.js +7 -1
  204. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  205. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  206. package/dest/testbench/p2p_client_testbench_worker.js +15 -14
  207. package/dest/testbench/worker_client_manager.d.ts +3 -1
  208. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  209. package/dest/testbench/worker_client_manager.js +6 -2
  210. package/dest/util.d.ts +3 -3
  211. package/dest/util.d.ts.map +1 -1
  212. package/package.json +14 -14
  213. package/src/client/factory.ts +41 -49
  214. package/src/client/interface.ts +17 -20
  215. package/src/client/p2p_client.ts +60 -126
  216. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
  217. package/src/config.ts +100 -43
  218. package/src/errors/tx-pool.error.ts +12 -0
  219. package/src/mem_pools/attestation_pool/attestation_pool.ts +13 -4
  220. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  221. package/src/mem_pools/instrumentation.ts +17 -13
  222. package/src/mem_pools/tx_pool/README.md +1 -1
  223. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  224. package/src/mem_pools/tx_pool_v2/README.md +52 -28
  225. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
  226. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  227. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  228. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  229. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  230. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  231. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  232. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  233. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  234. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  235. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  236. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  237. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  238. package/src/mem_pools/tx_pool_v2/interfaces.ts +24 -6
  239. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +145 -25
  240. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
  241. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +21 -7
  242. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +333 -138
  243. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  244. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  245. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
  246. package/src/msg_validators/tx_validator/README.md +115 -0
  247. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  248. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  249. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  250. package/src/msg_validators/tx_validator/factory.ts +353 -77
  251. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  252. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  253. package/src/msg_validators/tx_validator/index.ts +2 -0
  254. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  255. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  256. package/src/msg_validators/tx_validator/phases_validator.ts +51 -26
  257. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  258. package/src/services/dummy_service.ts +6 -6
  259. package/src/services/encoding.ts +7 -7
  260. package/src/services/gossipsub/README.md +29 -14
  261. package/src/services/gossipsub/topic_score_params.ts +49 -13
  262. package/src/services/libp2p/libp2p_service.ts +95 -96
  263. package/src/services/peer-manager/metrics.ts +7 -0
  264. package/src/services/peer-manager/peer_manager.ts +2 -1
  265. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  266. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  267. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  268. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  269. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  270. package/src/services/reqresp/reqresp.ts +3 -1
  271. package/src/services/service.ts +11 -2
  272. package/src/services/tx_collection/config.ts +42 -0
  273. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  274. package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
  275. package/src/services/tx_collection/file_store_tx_source.ts +64 -17
  276. package/src/services/tx_collection/instrumentation.ts +7 -1
  277. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  278. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  279. package/src/services/tx_collection/slow_tx_collection.ts +17 -13
  280. package/src/services/tx_collection/tx_collection.ts +45 -14
  281. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  282. package/src/services/tx_collection/tx_source.ts +22 -3
  283. package/src/services/tx_file_store/tx_file_store.ts +6 -4
  284. package/src/services/tx_provider.ts +2 -2
  285. package/src/test-helpers/make-test-p2p-clients.ts +1 -3
  286. package/src/test-helpers/mock-pubsub.ts +13 -6
  287. package/src/test-helpers/reqresp-nodes.ts +3 -6
  288. package/src/test-helpers/testbench-utils.ts +11 -3
  289. package/src/testbench/p2p_client_testbench_worker.ts +24 -20
  290. package/src/testbench/worker_client_manager.ts +13 -5
  291. package/src/util.ts +8 -2
  292. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  293. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  294. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  295. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -2,16 +2,19 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
4
  import { BlockHash, type L2BlockId } from '@aztec/stdlib/block';
5
- import type { Tx } from '@aztec/stdlib/tx';
5
+ import { Gas } from '@aztec/stdlib/gas';
6
+ import { type Tx, TxHash } from '@aztec/stdlib/tx';
6
7
 
7
8
  import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
8
9
  import { getTxPriorityFee } from '../tx_pool/priority.js';
9
- import type { PreAddResult } from './eviction/interfaces.js';
10
+ import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
10
11
 
11
12
  /** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
12
13
  export type TxMetaValidationData = {
13
14
  getNonEmptyNullifiers(): Fr[];
14
- includeByTimestamp: bigint;
15
+ expirationTimestamp: bigint;
16
+ /** Whether the tx has public calls. Used to select the correct L2 gas minimum. */
17
+ forPublic?: unknown;
15
18
  constants: {
16
19
  anchorBlockHeader: {
17
20
  hash(): Promise<BlockHash>;
@@ -19,6 +22,9 @@ export type TxMetaValidationData = {
19
22
  blockNumber: BlockNumber;
20
23
  };
21
24
  };
25
+ txContext: {
26
+ gasSettings: { gasLimits: Gas };
27
+ };
22
28
  };
23
29
  };
24
30
 
@@ -34,6 +40,9 @@ export type TxMetaData = {
34
40
  /** The transaction hash as hex string */
35
41
  readonly txHash: string;
36
42
 
43
+ /** The transaction hash as bigint (for efficient Fr conversion in comparisons) */
44
+ readonly txHashBigInt: bigint;
45
+
37
46
  /** Block ID (number and hash) in which the transaction was mined (undefined if not mined) */
38
47
  minedL2BlockId?: L2BlockId;
39
48
 
@@ -56,10 +65,16 @@ export type TxMetaData = {
56
65
  readonly nullifiers: readonly string[];
57
66
 
58
67
  /** Timestamp by which the transaction must be included (for expiration checks) */
59
- readonly includeByTimestamp: bigint;
68
+ readonly expirationTimestamp: bigint;
60
69
 
61
70
  /** Validator-compatible data, providing the same access patterns as Tx.data */
62
71
  readonly data: TxMetaValidationData;
72
+
73
+ /** Timestamp (ms) when the tx was received into the pool. 0 for hydrated txs (always eligible). */
74
+ receivedAt: number;
75
+
76
+ /** Estimated memory footprint of this metadata object in bytes */
77
+ readonly estimatedSizeBytes: number;
63
78
  };
64
79
 
65
80
  /** Transaction state derived from TxMetaData fields and pool protection status */
@@ -71,48 +86,85 @@ export type TxState = 'pending' | 'protected' | 'mined' | 'deleted';
71
86
  * Fr values are captured in closures for zero-cost re-validation.
72
87
  */
73
88
  export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
74
- const txHash = tx.getTxHash().toString();
89
+ const txHashObj = tx.getTxHash();
90
+ const txHash = txHashObj.toString();
91
+ const txHashBigInt = txHashObj.toBigInt();
75
92
  const nullifierFrs = tx.data.getNonEmptyNullifiers();
76
93
  const nullifiers = nullifierFrs.map(n => n.toString());
77
94
  const anchorBlockHeaderHashFr = await tx.data.constants.anchorBlockHeader.hash();
78
95
  const anchorBlockHeaderHash = anchorBlockHeaderHashFr.toString();
79
- const includeByTimestamp = tx.data.includeByTimestamp;
96
+ const expirationTimestamp = tx.data.expirationTimestamp;
80
97
  const anchorBlockNumber = tx.data.constants.anchorBlockHeader.globalVariables.blockNumber;
81
98
  const priorityFee = getTxPriorityFee(tx);
82
99
  const feePayer = tx.data.feePayer.toString();
83
100
 
84
101
  const { feeLimit, claimAmount } = await getFeePayerBalanceDelta(tx, ProtocolContractAddress.FeeJuice);
85
102
 
103
+ const estimatedSizeBytes = estimateTxMetaDataSize(nullifiers.length);
104
+
86
105
  return {
87
106
  txHash,
107
+ txHashBigInt,
88
108
  anchorBlockHeaderHash,
89
109
  priorityFee,
90
110
  feePayer,
91
111
  claimAmount,
92
112
  feeLimit,
93
113
  nullifiers,
94
- includeByTimestamp,
114
+ expirationTimestamp,
115
+ receivedAt: 0,
116
+ estimatedSizeBytes,
95
117
  data: {
96
118
  getNonEmptyNullifiers: () => nullifierFrs,
97
- includeByTimestamp,
119
+ expirationTimestamp,
120
+ forPublic: !!tx.data.forPublic,
98
121
  constants: {
99
122
  anchorBlockHeader: {
100
123
  hash: () => Promise.resolve(anchorBlockHeaderHashFr),
101
124
  globalVariables: { blockNumber: anchorBlockNumber },
102
125
  },
126
+ txContext: {
127
+ gasSettings: { gasLimits: tx.data.constants.txContext.gasSettings.gasLimits },
128
+ },
103
129
  },
104
130
  },
105
131
  };
106
132
  }
107
133
 
134
+ // V8 JS object overhead (~64 bytes for a plain object with hidden class).
135
+ // String overhead: ~32 bytes header + 1 byte per ASCII char (V8 one-byte strings).
136
+ // Hex string (0x + 64 hex chars = 66 chars): ~98 bytes per string.
137
+ // bigint: ~32 bytes. number: 8 bytes. Fr: ~80 bytes (32 data + object overhead).
138
+ const OBJECT_OVERHEAD = 64;
139
+ const HEX_STRING_BYTES = 98;
140
+ const BIGINT_BYTES = 32;
141
+ const FR_BYTES = 80;
142
+ // Fixed cost: object shell + txHash + anchorBlockHeaderHash + feePayer (3 hex strings)
143
+ // + txHashBigInt + priorityFee + claimAmount + feeLimit + includeByTimestamp (5 bigints)
144
+ // + receivedAt (number, 8 bytes) + estimatedSizeBytes (number, 8 bytes)
145
+ // + data closure object (~OBJECT_OVERHEAD + anchorBlockHeaderHashFr Fr + anchorBlockNumber number)
146
+ const FIXED_METADATA_BYTES =
147
+ OBJECT_OVERHEAD + 3 * HEX_STRING_BYTES + 5 * BIGINT_BYTES + 8 + 8 + OBJECT_OVERHEAD + FR_BYTES + 8;
148
+
149
+ /** Estimates the in-memory size of a TxMetaData object based on the number of nullifiers. */
150
+ function estimateTxMetaDataSize(nullifierCount: number): number {
151
+ // Per nullifier: one hex string in nullifiers[] + one Fr in the captured nullifierFrs[]
152
+ return FIXED_METADATA_BYTES + nullifierCount * (HEX_STRING_BYTES + FR_BYTES);
153
+ }
154
+
155
+ /** Converts a txHash bigint back to the canonical 0x-prefixed 64-char hex string. */
156
+ export function txHashFromBigInt(value: bigint): string {
157
+ return TxHash.fromBigInt(value).toString();
158
+ }
159
+
108
160
  /** Minimal fields required for priority comparison. */
109
- type PriorityComparable = Pick<TxMetaData, 'txHash' | 'priorityFee'>;
161
+ export type PriorityComparable = Pick<TxMetaData, 'txHash' | 'txHashBigInt' | 'priorityFee'>;
110
162
 
111
163
  /**
112
164
  * Compares two priority fees in ascending order.
113
165
  * Returns negative if a < b, positive if a > b, 0 if equal.
114
166
  */
115
- export function compareFee(a: bigint, b: bigint): number {
167
+ export function compareFee(a: bigint, b: bigint): -1 | 0 | 1 {
116
168
  return a < b ? -1 : a > b ? 1 : 0;
117
169
  }
118
170
 
@@ -121,10 +173,8 @@ export function compareFee(a: bigint, b: bigint): number {
121
173
  * Uses field element comparison for deterministic ordering.
122
174
  * Returns negative if a < b, positive if a > b, 0 if equal.
123
175
  */
124
- export function compareTxHash(a: string, b: string): number {
125
- const fieldA = Fr.fromHexString(a);
126
- const fieldB = Fr.fromHexString(b);
127
- return fieldA.cmp(fieldB);
176
+ export function compareTxHash(a: bigint, b: bigint): -1 | 0 | 1 {
177
+ return Fr.cmpAsBigInt(a, b);
128
178
  }
129
179
 
130
180
  /**
@@ -132,29 +182,46 @@ export function compareTxHash(a: string, b: string): number {
132
182
  * Returns negative if a < b, positive if a > b, 0 if equal.
133
183
  * Use with sort() for ascending order, or negate/reverse for descending.
134
184
  */
135
- export function comparePriority(a: PriorityComparable, b: PriorityComparable): number {
185
+ export function comparePriority(a: PriorityComparable, b: PriorityComparable): -1 | 0 | 1 {
136
186
  const feeComparison = compareFee(a.priorityFee, b.priorityFee);
137
187
  if (feeComparison !== 0) {
138
188
  return feeComparison;
139
189
  }
140
- return compareTxHash(a.txHash, b.txHash);
190
+ return compareTxHash(a.txHashBigInt, b.txHashBigInt);
191
+ }
192
+
193
+ /**
194
+ * Returns the minimum fee required to replace an existing tx with the given price bump percentage.
195
+ * Uses integer arithmetic: `existingFee + existingFee * priceBumpPercentage / 100`.
196
+ */
197
+ export function getMinimumPriceBumpFee(existingFee: bigint, priceBumpPercentage: bigint): bigint {
198
+ const bump = (existingFee * priceBumpPercentage) / 100n;
199
+ // Ensure the minimum bump is at least 1, so that replacement always requires
200
+ // paying strictly more — even with 0% bump or zero existing fee.
201
+ const effectiveBump = bump > 0n ? bump : 1n;
202
+ return existingFee + effectiveBump;
141
203
  }
142
204
 
143
205
  /**
144
206
  * Checks for nullifier conflicts between an incoming transaction and existing pool state.
145
207
  *
146
208
  * When the incoming tx shares nullifiers with existing pending txs:
147
- * - If the incoming tx has strictly higher priority, mark conflicting txs for eviction
148
- * - If any conflicting tx has equal or higher priority, ignore the incoming tx
209
+ * - If the incoming tx meets or exceeds the required priority, mark conflicting txs for eviction
210
+ * - Otherwise, ignore the incoming tx
211
+ *
212
+ * When `priceBumpPercentage` is provided (RPC path), uses fee-only comparison with the
213
+ * percentage bump instead of `comparePriority`.
149
214
  *
150
215
  * @param incomingMeta - Metadata for the incoming transaction
151
216
  * @param getTxHashByNullifier - Accessor to find which tx uses a nullifier
152
217
  * @param getMetadata - Accessor to get metadata for a tx hash
218
+ * @param priceBumpPercentage - Optional percentage bump required for fee-based replacement
153
219
  */
154
220
  export function checkNullifierConflict(
155
221
  incomingMeta: TxMetaData,
156
222
  getTxHashByNullifier: (nullifier: string) => string | undefined,
157
223
  getMetadata: (txHash: string) => TxMetaData | undefined,
224
+ priceBumpPercentage?: bigint,
158
225
  ): PreAddResult {
159
226
  const txHashesToEvict: string[] = [];
160
227
 
@@ -175,16 +242,33 @@ export function checkNullifierConflict(
175
242
  continue;
176
243
  }
177
244
 
178
- // If incoming tx has strictly higher priority, mark for eviction
179
- // Otherwise, ignore incoming tx (ties go to existing tx)
180
- // Use comparePriority for deterministic ordering (includes txHash as tiebreaker)
181
- if (comparePriority(incomingMeta, conflictingMeta) > 0) {
245
+ // When price bump is set (RPC path), require the incoming fee to meet the bumped threshold.
246
+ // Otherwise (P2P path), use full comparePriority with tx hash tiebreaker.
247
+ const isHigherPriority =
248
+ priceBumpPercentage !== undefined
249
+ ? incomingMeta.priorityFee >= getMinimumPriceBumpFee(conflictingMeta.priorityFee, priceBumpPercentage)
250
+ : comparePriority(incomingMeta, conflictingMeta) > 0;
251
+
252
+ if (isHigherPriority) {
182
253
  txHashesToEvict.push(conflictingHashStr);
183
254
  } else {
255
+ const minimumFee =
256
+ priceBumpPercentage !== undefined
257
+ ? getMinimumPriceBumpFee(conflictingMeta.priorityFee, priceBumpPercentage)
258
+ : undefined;
184
259
  return {
185
260
  shouldIgnore: true,
186
261
  txHashesToEvict: [],
187
- reason: `nullifier conflict with ${conflictingHashStr}`,
262
+ reason: {
263
+ code: TxPoolRejectionCode.NULLIFIER_CONFLICT,
264
+ message:
265
+ minimumFee !== undefined
266
+ ? `Nullifier conflict with existing tx ${conflictingHashStr}. Minimum required fee: ${minimumFee}, got: ${incomingMeta.priorityFee}`
267
+ : `Nullifier conflict with existing tx ${conflictingHashStr}`,
268
+ conflictingTxHash: conflictingHashStr,
269
+ minimumPriceBumpFee: minimumFee,
270
+ txPriorityFee: minimumFee !== undefined ? incomingMeta.priorityFee : undefined,
271
+ },
188
272
  };
189
273
  }
190
274
  }
@@ -193,15 +277,51 @@ export function checkNullifierConflict(
193
277
  }
194
278
 
195
279
  /** Creates a stub TxMetaValidationData for tests that don't exercise validators. */
196
- export function stubTxMetaValidationData(overrides: { includeByTimestamp?: bigint } = {}): TxMetaValidationData {
280
+ export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigint } = {}): TxMetaValidationData {
197
281
  return {
198
282
  getNonEmptyNullifiers: () => [],
199
- includeByTimestamp: overrides.includeByTimestamp ?? 0n,
283
+ expirationTimestamp: overrides.expirationTimestamp ?? 0n,
200
284
  constants: {
201
285
  anchorBlockHeader: {
202
286
  hash: () => Promise.resolve(new BlockHash(Fr.ZERO)),
203
287
  globalVariables: { blockNumber: BlockNumber(0) },
204
288
  },
289
+ txContext: {
290
+ gasSettings: { gasLimits: Gas.empty() },
291
+ },
205
292
  },
206
293
  };
207
294
  }
295
+
296
+ /** Creates a stub TxMetaData for tests. All fields have sensible defaults and can be overridden. */
297
+ export function stubTxMetaData(
298
+ txHash: string,
299
+ overrides: {
300
+ priorityFee?: bigint;
301
+ feePayer?: string;
302
+ claimAmount?: bigint;
303
+ feeLimit?: bigint;
304
+ nullifiers?: string[];
305
+ expirationTimestamp?: bigint;
306
+ anchorBlockHeaderHash?: string;
307
+ } = {},
308
+ ): TxMetaData {
309
+ const txHashBigInt = Fr.fromHexString(txHash).toBigInt();
310
+ // Normalize to canonical zero-padded hex so txHashFromBigInt(txHashBigInt) === normalizedTxHash
311
+ const normalizedTxHash = txHashFromBigInt(txHashBigInt);
312
+ const expirationTimestamp = overrides.expirationTimestamp ?? 0n;
313
+ return {
314
+ txHash: normalizedTxHash,
315
+ txHashBigInt,
316
+ anchorBlockHeaderHash: overrides.anchorBlockHeaderHash ?? '0x1234',
317
+ priorityFee: overrides.priorityFee ?? 100n,
318
+ feePayer: overrides.feePayer ?? '0xfeepayer',
319
+ claimAmount: overrides.claimAmount ?? 0n,
320
+ feeLimit: overrides.feeLimit ?? 100n,
321
+ nullifiers: overrides.nullifiers ?? [`0x${normalizedTxHash.slice(2)}null1`],
322
+ expirationTimestamp,
323
+ receivedAt: 0,
324
+ estimatedSizeBytes: 0,
325
+ data: stubTxMetaValidationData({ expirationTimestamp }),
326
+ };
327
+ }
@@ -1,7 +1,8 @@
1
+ import { insertIntoSortedArray, removeFromSortedArray } from '@aztec/foundation/array';
1
2
  import { SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import type { L2BlockId } from '@aztec/stdlib/block';
3
4
 
4
- import { type TxMetaData, type TxState, compareFee, compareTxHash } from './tx_metadata.js';
5
+ import { type PriorityComparable, type TxMetaData, type TxState, comparePriority } from './tx_metadata.js';
5
6
 
6
7
  /**
7
8
  * Manages in-memory indices for the transaction pool.
@@ -22,8 +23,8 @@ export class TxPoolIndices {
22
23
  #nullifierToTxHash: Map<string, string> = new Map();
23
24
  /** Fee payer to txHashes index (pending txs only) */
24
25
  #feePayerToTxHashes: Map<string, Set<string>> = new Map();
25
- /** Pending txHashes grouped by priority fee */
26
- #pendingByPriority: Map<bigint, Set<string>> = new Map();
26
+ /** Pending transactions sorted ascending by priority fee, ties broken by txHash */
27
+ #pendingByPriority: PriorityComparable[] = [];
27
28
  /** Protected transactions: txHash -> slotNumber */
28
29
  #protectedTransactions: Map<string, SlotNumber> = new Map();
29
30
 
@@ -72,23 +73,33 @@ export class TxPoolIndices {
72
73
  * Iterates pending transaction hashes in priority order.
73
74
  * @param order - 'desc' for highest priority first, 'asc' for lowest priority first
74
75
  */
75
- *iteratePendingByPriority(order: 'asc' | 'desc'): Generator<string> {
76
- // Use compareFee from tx_metadata, swap args for descending order
77
- const feeCompareFn = order === 'desc' ? (a: bigint, b: bigint) => compareFee(b, a) : compareFee;
78
- const hashCompareFn = order === 'desc' ? (a: string, b: string) => compareTxHash(b, a) : compareTxHash;
79
-
80
- const sortedFees = [...this.#pendingByPriority.keys()].sort(feeCompareFn);
81
-
82
- for (const fee of sortedFees) {
83
- const hashesAtFee = this.#pendingByPriority.get(fee)!;
84
- // Use compareTxHash from tx_metadata, swap args for descending order
85
- const sortedHashes = [...hashesAtFee].sort(hashCompareFn);
86
- for (const hash of sortedHashes) {
87
- yield hash;
76
+ *iteratePendingByPriority(order: 'asc' | 'desc', filter?: (hash: string) => boolean): Generator<string> {
77
+ const arr = this.#pendingByPriority;
78
+ const start = order === 'asc' ? 0 : arr.length - 1;
79
+ const step = order === 'asc' ? 1 : -1;
80
+ const inBounds = order === 'asc' ? (i: number) => i < arr.length : (i: number) => i >= 0;
81
+
82
+ for (let i = start; inBounds(i); i += step) {
83
+ if (filter === undefined || filter(arr[i].txHash)) {
84
+ yield arr[i].txHash;
88
85
  }
89
86
  }
90
87
  }
91
88
 
89
+ /**
90
+ * Iterates pending transaction hashes in priority order, skipping txs received after maxReceivedAt.
91
+ * @param order - 'desc' for highest priority first, 'asc' for lowest priority first
92
+ * @param maxReceivedAt - Only yield txs with receivedAt <= this value
93
+ */
94
+ *iterateEligiblePendingByPriority(order: 'asc' | 'desc', maxReceivedAt: number): Generator<string> {
95
+ const filter = (hash: string) => {
96
+ const meta = this.#metadata.get(hash);
97
+ return meta !== undefined && meta.receivedAt <= maxReceivedAt;
98
+ };
99
+
100
+ yield* this.iteratePendingByPriority(order, filter);
101
+ }
102
+
92
103
  /** Iterates all metadata entries */
93
104
  *iterateMetadata(): Generator<[string, TxMetaData]> {
94
105
  yield* this.#metadata;
@@ -211,11 +222,7 @@ export class TxPoolIndices {
211
222
 
212
223
  /** Gets the count of pending transactions */
213
224
  getPendingTxCount(): number {
214
- let count = 0;
215
- for (const hashes of this.#pendingByPriority.values()) {
216
- count += hashes.size;
217
- }
218
- return count;
225
+ return this.#pendingByPriority.length;
219
226
  }
220
227
 
221
228
  /** Gets the lowest priority pending transaction hashes (up to limit) */
@@ -248,12 +255,10 @@ export class TxPoolIndices {
248
255
  /** Gets all pending transactions */
249
256
  getPendingTxs(): TxMetaData[] {
250
257
  const result: TxMetaData[] = [];
251
- for (const hashSet of this.#pendingByPriority.values()) {
252
- for (const txHash of hashSet) {
253
- const meta = this.#metadata.get(txHash);
254
- if (meta) {
255
- result.push(meta);
256
- }
258
+ for (const entry of this.#pendingByPriority) {
259
+ const meta = this.#metadata.get(entry.txHash);
260
+ if (meta) {
261
+ result.push(meta);
257
262
  }
258
263
  }
259
264
  return result;
@@ -332,13 +337,15 @@ export class TxPoolIndices {
332
337
  // METRICS
333
338
  // ============================================================================
334
339
 
335
- /** Counts transactions by state */
336
- countTxs(): { pending: number; protected: number; mined: number } {
340
+ /** Counts transactions by state and estimates total metadata memory usage */
341
+ countTxs(): { pending: number; protected: number; mined: number; totalMetadataBytes: number } {
337
342
  let pending = 0;
338
343
  let protected_ = 0;
339
344
  let mined = 0;
345
+ let totalMetadataBytes = 0;
340
346
 
341
347
  for (const meta of this.#metadata.values()) {
348
+ totalMetadataBytes += meta.estimatedSizeBytes;
342
349
  const state = this.getTxState(meta);
343
350
  if (state === 'pending') {
344
351
  pending++;
@@ -349,7 +356,16 @@ export class TxPoolIndices {
349
356
  }
350
357
  }
351
358
 
352
- return { pending, protected: protected_, mined };
359
+ return { pending, protected: protected_, mined, totalMetadataBytes };
360
+ }
361
+
362
+ /** Returns the estimated total memory consumed by all metadata objects */
363
+ getTotalMetadataBytes(): number {
364
+ let total = 0;
365
+ for (const meta of this.#metadata.values()) {
366
+ total += meta.estimatedSizeBytes;
367
+ }
368
+ return total;
353
369
  }
354
370
 
355
371
  /** Gets all mined transactions with their block IDs */
@@ -381,13 +397,12 @@ export class TxPoolIndices {
381
397
  }
382
398
  feePayerSet.add(meta.txHash);
383
399
 
384
- // Add to priority bucket
385
- let prioritySet = this.#pendingByPriority.get(meta.priorityFee);
386
- if (!prioritySet) {
387
- prioritySet = new Set();
388
- this.#pendingByPriority.set(meta.priorityFee, prioritySet);
389
- }
390
- prioritySet.add(meta.txHash);
400
+ insertIntoSortedArray(
401
+ this.#pendingByPriority,
402
+ { txHash: meta.txHash, priorityFee: meta.priorityFee, txHashBigInt: meta.txHashBigInt },
403
+ comparePriority,
404
+ false,
405
+ );
391
406
  }
392
407
 
393
408
  #removeFromPendingIndices(meta: TxMetaData): void {
@@ -405,13 +420,11 @@ export class TxPoolIndices {
405
420
  }
406
421
  }
407
422
 
408
- // Remove from priority map
409
- const hashSet = this.#pendingByPriority.get(meta.priorityFee);
410
- if (hashSet) {
411
- hashSet.delete(meta.txHash);
412
- if (hashSet.size === 0) {
413
- this.#pendingByPriority.delete(meta.priorityFee);
414
- }
415
- }
423
+ // Remove from priority array
424
+ removeFromSortedArray(
425
+ this.#pendingByPriority,
426
+ { txHash: meta.txHash, priorityFee: meta.priorityFee, txHashBigInt: meta.txHashBigInt },
427
+ comparePriority,
428
+ );
416
429
  }
417
430
  }
@@ -1,6 +1,7 @@
1
1
  import { SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { SerialQueue } from '@aztec/foundation/queue';
4
+ import { DateProvider } from '@aztec/foundation/timer';
4
5
  import type { TypedEventEmitter } from '@aztec/foundation/types';
5
6
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
6
7
  import type { L2Block, L2BlockId } from '@aztec/stdlib/block';
@@ -35,6 +36,7 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
35
36
  deps: TxPoolV2Dependencies,
36
37
  telemetry: TelemetryClient = getTelemetryClient(),
37
38
  config: Partial<TxPoolV2Config> = {},
39
+ dateProvider: DateProvider = new DateProvider(),
38
40
  log = createLogger('p2p:tx_pool_v2'),
39
41
  ) {
40
42
  super();
@@ -56,10 +58,13 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
56
58
  const hashes = txHashes.map(h => (typeof h === 'string' ? TxHash.fromString(h) : TxHash.fromBigInt(h)));
57
59
  this.emit('txs-removed', { txHashes: hashes });
58
60
  },
61
+ onTxsMined: (txHashes: string[]) => {
62
+ this.#metrics?.transactionsRemoved(txHashes);
63
+ },
59
64
  };
60
65
 
61
66
  // Create the implementation
62
- this.#impl = new TxPoolV2Impl(store, archiveStore, deps, callbacks, config, log);
67
+ this.#impl = new TxPoolV2Impl(store, archiveStore, deps, callbacks, telemetry, config, dateProvider, log);
63
68
  }
64
69
 
65
70
  // ============================================================================
@@ -68,11 +73,11 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
68
73
 
69
74
  // === Core Operations ===
70
75
 
71
- addPendingTxs(txs: Tx[], opts: { source?: string } = {}): Promise<AddTxsResult> {
76
+ addPendingTxs(txs: Tx[], opts: { source?: string; feeComparisonOnly?: boolean } = {}): Promise<AddTxsResult> {
72
77
  return this.#queue.put(() => this.#impl.addPendingTxs(txs, opts));
73
78
  }
74
79
 
75
- canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored' | 'rejected'> {
80
+ canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'> {
76
81
  return this.#queue.put(() => this.#impl.canAddPendingTx(tx));
77
82
  }
78
83
 
@@ -81,7 +86,7 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
81
86
  }
82
87
 
83
88
  protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]> {
84
- return this.#queue.put(() => Promise.resolve(this.#impl.protectTxs(txHashes, block)));
89
+ return this.#queue.put(() => this.#impl.protectTxs(txHashes, block));
85
90
  }
86
91
 
87
92
  addMinedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string } = {}): Promise<void> {
@@ -98,8 +103,8 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
98
103
  return this.#queue.put(() => this.#impl.prepareForSlot(slotNumber));
99
104
  }
100
105
 
101
- handlePrunedBlocks(latestBlock: L2BlockId): Promise<void> {
102
- return this.#queue.put(() => this.#impl.handlePrunedBlocks(latestBlock));
106
+ handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
107
+ return this.#queue.put(() => this.#impl.handlePrunedBlocks(latestBlock, options));
103
108
  }
104
109
 
105
110
  handleFailedExecution(txHashes: TxHash[]): Promise<void> {
@@ -132,6 +137,10 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
132
137
  return this.#queue.put(() => Promise.resolve(this.#impl.getPendingTxHashes()));
133
138
  }
134
139
 
140
+ getEligiblePendingTxHashes(): Promise<TxHash[]> {
141
+ return this.#queue.put(() => Promise.resolve(this.#impl.getEligiblePendingTxHashes()));
142
+ }
143
+
135
144
  getPendingTxCount(): Promise<number> {
136
145
  return this.#queue.put(() => Promise.resolve(this.#impl.getPendingTxCount()));
137
146
  }
@@ -189,7 +198,12 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
189
198
  this.#queue.put(() => {
190
199
  const counts = this.#impl.countTxs();
191
200
  return Promise.resolve({
192
- itemCount: { pending: counts.pending, protected: counts.protected, mined: counts.mined },
201
+ itemCount: {
202
+ pending: counts.pending,
203
+ protected: counts.protected,
204
+ mined: counts.mined,
205
+ softDeleted: counts.softDeleted,
206
+ },
193
207
  });
194
208
  }),
195
209
  () => this.#store.estimateSize(),