@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.7035c9bd6

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 (393) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +11 -11
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +52 -15
  5. package/dest/client/interface.d.ts +46 -33
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +39 -51
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +157 -224
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +9 -9
  11. package/dest/config.d.ts +54 -17
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +102 -38
  14. package/dest/errors/tx-pool.error.d.ts +8 -0
  15. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  16. package/dest/errors/tx-pool.error.js +9 -0
  17. package/dest/index.d.ts +2 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -0
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.js +445 -3
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  26. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  27. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/index.js +1 -2
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  30. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  32. package/dest/mem_pools/index.d.ts +3 -2
  33. package/dest/mem_pools/index.d.ts.map +1 -1
  34. package/dest/mem_pools/index.js +1 -1
  35. package/dest/mem_pools/instrumentation.d.ts +4 -2
  36. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.js +16 -14
  38. package/dest/mem_pools/interface.d.ts +5 -5
  39. package/dest/mem_pools/interface.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  41. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
  43. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  44. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  45. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/priority.js +4 -4
  47. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  48. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  50. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  51. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  53. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  54. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  56. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +7 -3
  59. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  61. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  62. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  63. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  66. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  67. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  69. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  70. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  71. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  72. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  73. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  74. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  75. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  76. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  77. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  79. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  80. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  81. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  82. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  83. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  84. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  85. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +30 -12
  86. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  87. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  88. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -15
  89. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  90. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +139 -18
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  93. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +50 -45
  94. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
  95. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  96. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +17 -6
  97. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  98. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  99. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +364 -189
  100. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  101. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  102. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  103. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  104. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  105. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  106. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  107. package/dest/msg_validators/clock_tolerance.js +4 -3
  108. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  109. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  111. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  112. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  114. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  115. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
  117. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  118. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  119. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  120. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  121. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  122. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  123. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  124. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  125. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  126. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  127. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  129. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  130. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  132. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  133. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/factory.js +240 -59
  135. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  136. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  138. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  139. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  141. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  142. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/index.js +2 -0
  144. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  145. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  147. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  148. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  149. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  150. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  151. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  152. package/dest/msg_validators/tx_validator/phases_validator.js +71 -23
  153. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  154. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  155. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  156. package/dest/services/dummy_service.d.ts +13 -5
  157. package/dest/services/dummy_service.d.ts.map +1 -1
  158. package/dest/services/dummy_service.js +10 -4
  159. package/dest/services/encoding.d.ts +7 -3
  160. package/dest/services/encoding.d.ts.map +1 -1
  161. package/dest/services/encoding.js +18 -11
  162. package/dest/services/gossipsub/index.d.ts +3 -0
  163. package/dest/services/gossipsub/index.d.ts.map +1 -0
  164. package/dest/services/gossipsub/index.js +2 -0
  165. package/dest/services/gossipsub/scoring.d.ts +21 -3
  166. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  167. package/dest/services/gossipsub/scoring.js +24 -7
  168. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  169. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  170. package/dest/services/gossipsub/topic_score_params.js +346 -0
  171. package/dest/services/libp2p/libp2p_service.d.ts +95 -50
  172. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  173. package/dest/services/libp2p/libp2p_service.js +464 -364
  174. package/dest/services/peer-manager/metrics.d.ts +3 -1
  175. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  176. package/dest/services/peer-manager/metrics.js +6 -0
  177. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  178. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  179. package/dest/services/peer-manager/peer_manager.js +4 -3
  180. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  181. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  182. package/dest/services/peer-manager/peer_scoring.js +25 -2
  183. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
  184. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  185. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +80 -106
  186. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
  187. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  188. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  189. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  190. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  191. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  192. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  193. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  194. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  195. package/dest/services/reqresp/interface.d.ts +10 -1
  196. package/dest/services/reqresp/interface.d.ts.map +1 -1
  197. package/dest/services/reqresp/interface.js +15 -1
  198. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
  199. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  200. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  201. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  202. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  203. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  204. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  205. package/dest/services/reqresp/protocols/tx.js +20 -0
  206. package/dest/services/reqresp/reqresp.d.ts +1 -1
  207. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  208. package/dest/services/reqresp/reqresp.js +30 -14
  209. package/dest/services/service.d.ts +39 -3
  210. package/dest/services/service.d.ts.map +1 -1
  211. package/dest/services/tx_collection/config.d.ts +19 -1
  212. package/dest/services/tx_collection/config.d.ts.map +1 -1
  213. package/dest/services/tx_collection/config.js +46 -0
  214. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -4
  215. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  216. package/dest/services/tx_collection/fast_tx_collection.js +80 -76
  217. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  218. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  219. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  220. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  221. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  222. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  223. package/dest/services/tx_collection/index.d.ts +2 -1
  224. package/dest/services/tx_collection/index.d.ts.map +1 -1
  225. package/dest/services/tx_collection/index.js +1 -0
  226. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  227. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  228. package/dest/services/tx_collection/instrumentation.js +2 -1
  229. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -7
  230. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  231. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  232. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  233. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  234. package/dest/services/tx_collection/request_tracker.js +84 -0
  235. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  236. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  237. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  238. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  239. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  240. package/dest/services/tx_collection/tx_collection.js +75 -3
  241. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  242. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  243. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  244. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  245. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  246. package/dest/services/tx_collection/tx_source.js +19 -2
  247. package/dest/services/tx_file_store/config.d.ts +1 -3
  248. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  249. package/dest/services/tx_file_store/config.js +0 -4
  250. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  251. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  252. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  253. package/dest/services/tx_provider.d.ts +4 -4
  254. package/dest/services/tx_provider.d.ts.map +1 -1
  255. package/dest/services/tx_provider.js +9 -8
  256. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  257. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  258. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  259. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  260. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  261. package/dest/test-helpers/mock-pubsub.js +105 -4
  262. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  263. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  264. package/dest/test-helpers/reqresp-nodes.js +4 -3
  265. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  266. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  267. package/dest/test-helpers/testbench-utils.js +149 -61
  268. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  269. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  270. package/dest/testbench/p2p_client_testbench_worker.js +19 -17
  271. package/dest/testbench/worker_client_manager.d.ts +3 -1
  272. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  273. package/dest/testbench/worker_client_manager.js +6 -2
  274. package/dest/util.d.ts +3 -3
  275. package/dest/util.d.ts.map +1 -1
  276. package/package.json +14 -14
  277. package/src/client/factory.ts +99 -28
  278. package/src/client/interface.ts +56 -34
  279. package/src/client/p2p_client.ts +190 -269
  280. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +22 -14
  281. package/src/config.ts +158 -44
  282. package/src/errors/tx-pool.error.ts +12 -0
  283. package/src/index.ts +1 -0
  284. package/src/mem_pools/attestation_pool/attestation_pool.ts +497 -91
  285. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  286. package/src/mem_pools/attestation_pool/index.ts +9 -2
  287. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  288. package/src/mem_pools/index.ts +4 -1
  289. package/src/mem_pools/instrumentation.ts +17 -13
  290. package/src/mem_pools/interface.ts +4 -4
  291. package/src/mem_pools/tx_pool/README.md +1 -1
  292. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  293. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  294. package/src/mem_pools/tx_pool/priority.ts +4 -4
  295. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  296. package/src/mem_pools/tx_pool_v2/README.md +85 -11
  297. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  298. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  299. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +7 -3
  300. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  301. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  302. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  303. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  304. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  305. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  306. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  307. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  308. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  309. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  310. package/src/mem_pools/tx_pool_v2/interfaces.ts +32 -12
  311. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +202 -26
  312. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
  313. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
  314. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
  315. package/src/msg_validators/attestation_validator/README.md +49 -0
  316. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  317. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  318. package/src/msg_validators/clock_tolerance.ts +4 -3
  319. package/src/msg_validators/proposal_validator/README.md +123 -0
  320. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  321. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  322. package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
  323. package/src/msg_validators/tx_validator/README.md +119 -0
  324. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  325. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  326. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  327. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  328. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  329. package/src/msg_validators/tx_validator/factory.ts +387 -78
  330. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  331. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  332. package/src/msg_validators/tx_validator/index.ts +2 -0
  333. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  334. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  335. package/src/msg_validators/tx_validator/phases_validator.ts +81 -26
  336. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  337. package/src/services/dummy_service.ts +18 -6
  338. package/src/services/encoding.ts +18 -10
  339. package/src/services/gossipsub/README.md +641 -0
  340. package/src/services/gossipsub/index.ts +2 -0
  341. package/src/services/gossipsub/scoring.ts +29 -5
  342. package/src/services/gossipsub/topic_score_params.ts +487 -0
  343. package/src/services/libp2p/libp2p_service.ts +483 -392
  344. package/src/services/peer-manager/metrics.ts +7 -0
  345. package/src/services/peer-manager/peer_manager.ts +5 -3
  346. package/src/services/peer-manager/peer_scoring.ts +25 -0
  347. package/src/services/reqresp/README.md +229 -0
  348. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  349. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +76 -112
  350. package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
  351. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  352. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  353. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  354. package/src/services/reqresp/interface.ts +26 -1
  355. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
  356. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  357. package/src/services/reqresp/protocols/tx.ts +22 -0
  358. package/src/services/reqresp/reqresp.ts +35 -15
  359. package/src/services/service.ts +51 -2
  360. package/src/services/tx_collection/config.ts +68 -0
  361. package/src/services/tx_collection/fast_tx_collection.ts +83 -76
  362. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  363. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  364. package/src/services/tx_collection/index.ts +1 -0
  365. package/src/services/tx_collection/instrumentation.ts +7 -1
  366. package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
  367. package/src/services/tx_collection/request_tracker.ts +127 -0
  368. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  369. package/src/services/tx_collection/tx_collection.ts +114 -19
  370. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  371. package/src/services/tx_collection/tx_source.ts +22 -3
  372. package/src/services/tx_file_store/config.ts +0 -6
  373. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  374. package/src/services/tx_provider.ts +10 -9
  375. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  376. package/src/test-helpers/mock-pubsub.ts +146 -9
  377. package/src/test-helpers/reqresp-nodes.ts +5 -7
  378. package/src/test-helpers/testbench-utils.ts +156 -74
  379. package/src/testbench/p2p_client_testbench_worker.ts +27 -25
  380. package/src/testbench/worker_client_manager.ts +13 -5
  381. package/src/util.ts +8 -2
  382. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  383. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  384. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  385. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  386. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  387. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  388. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  389. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  390. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  391. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  392. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  393. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -4,6 +4,7 @@ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
4
4
  import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
5
5
  import type { BlockHeader, Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
6
6
 
7
+ import type { TxPoolRejectionError } from './eviction/interfaces.js';
7
8
  import type { TxMetaData, TxState } from './tx_metadata.js';
8
9
 
9
10
  /**
@@ -17,6 +18,8 @@ export type AddTxsResult = {
17
18
  ignored: TxHash[];
18
19
  /** Transactions rejected because they failed validation (e.g., invalid proof, expired timestamp) */
19
20
  rejected: TxHash[];
21
+ /** Optional rejection errors, only present when there are rejections with structured errors. */
22
+ errors?: Map<string, TxPoolRejectionError>;
20
23
  };
21
24
 
22
25
  /**
@@ -37,6 +40,14 @@ export type TxPoolV2Config = {
37
40
  maxPendingTxCount: number;
38
41
  /** Maximum number of archived transactions to retain (0 = disabled) */
39
42
  archivedTxLimit: number;
43
+ /** Minimum age (ms) a transaction must have been in the pool before it's eligible for block building */
44
+ minTxPoolAgeMs: number;
45
+ /** Maximum number of evicted tx hashes to remember for metrics tracking */
46
+ evictedTxCacheSize: number;
47
+ /** The probability (0-1) that a transaction is discarded. 0 disables dropping. For testing purposes only. */
48
+ dropTransactionsProbability: number;
49
+ /** Minimum percentage fee increase required to replace an existing tx via RPC (0 = no bump). */
50
+ priceBumpPercentage: bigint;
40
51
  };
41
52
 
42
53
  /**
@@ -45,6 +56,10 @@ export type TxPoolV2Config = {
45
56
  export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
46
57
  maxPendingTxCount: 0, // 0 = disabled
47
58
  archivedTxLimit: 0, // 0 = disabled
59
+ minTxPoolAgeMs: 2_000,
60
+ evictedTxCacheSize: 10_000,
61
+ dropTransactionsProbability: 0,
62
+ priceBumpPercentage: 10n,
48
63
  };
49
64
 
50
65
  /**
@@ -55,8 +70,10 @@ export type TxPoolV2Dependencies = {
55
70
  l2BlockSource: L2BlockSource;
56
71
  /** World state synchronizer for validating transactions after chain prunes */
57
72
  worldStateSynchronizer: WorldStateSynchronizer;
58
- /** Validator for transactions entering the pending pool */
59
- pendingTxValidator: TxValidator<Tx>;
73
+ /** Factory that creates a validator for re-validating pool transactions using metadata */
74
+ createTxValidator: () => Promise<TxValidator<TxMetaData>>;
75
+ /** Checks whether a tx's setup-phase calls are on the allow list. Precomputed at receipt time. */
76
+ checkAllowedSetupCalls: (tx: Tx) => Promise<boolean>;
60
77
  };
61
78
 
62
79
  /**
@@ -95,15 +112,15 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
95
112
  * @param opts - Optional metadata (e.g., source for logging)
96
113
  * @returns Result categorizing each transaction as accepted, rejected, or ignored
97
114
  */
98
- addPendingTxs(txs: Tx[], opts?: { source?: string }): Promise<AddTxsResult>;
115
+ addPendingTxs(txs: Tx[], opts?: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult>;
99
116
 
100
117
  /**
101
- * Checks if a transaction can be added without modifying the pool.
102
- * Performs the same validation as addPendingTxs but doesn't persist changes.
118
+ * Checks if the pool would accept a transaction without modifying state.
119
+ * Used as a pre-check before expensive proof verification.
103
120
  * @param tx - Transaction to check
104
- * @returns Result: 'accepted', 'ignored' (if already in pool or undesirable), or 'rejected' (if validation fails)
121
+ * @returns 'accepted' if the pool would accept, 'ignored' if already in pool or undesirable
105
122
  */
106
- canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored' | 'rejected'>;
123
+ canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'>;
107
124
 
108
125
  /**
109
126
  * Adds transactions as immediately protected for a given slot.
@@ -143,10 +160,10 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
143
160
  handleMinedBlock(block: L2Block): Promise<void>;
144
161
 
145
162
  /**
146
- * Prepares the pool for a new slot.
147
- * Unprotects transactions from earlier slots and validates them before
148
- * returning to pending state.
149
- * @param slotNumber - The slot number to prepare for
163
+ * Prepares the pool for a new slot by unprotecting transactions from earlier
164
+ * slots and re-validating them before returning to pending state.
165
+ * @param slotNumber - The pipeline slot we are building for (i.e. the slot
166
+ * the resulting blocks will target on L1).
150
167
  */
151
168
  prepareForSlot(slotNumber: SlotNumber): Promise<void>;
152
169
 
@@ -156,7 +173,7 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
156
173
  * and validates them before returning to pending.
157
174
  * @param latestBlock - The latest valid block ID after the prune
158
175
  */
159
- handlePrunedBlocks(latestBlock: L2BlockId): Promise<void>;
176
+ handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void>;
160
177
 
161
178
  /**
162
179
  * Handles failed transaction execution.
@@ -187,6 +204,9 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
187
204
  /** Gets pending transaction hashes sorted by priority (highest first) */
188
205
  getPendingTxHashes(): Promise<TxHash[]>;
189
206
 
207
+ /** Gets pending transaction hashes that have been in the pool long enough per minTxPoolAgeMs, sorted by priority (highest first) */
208
+ getEligiblePendingTxHashes(): Promise<TxHash[]>;
209
+
190
210
  /** Gets the count of pending transactions */
191
211
  getPendingTxCount(): Promise<number>;
192
212
 
@@ -1,11 +1,32 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import type { L2BlockId } from '@aztec/stdlib/block';
4
- import type { Tx } from '@aztec/stdlib/tx';
4
+ import { BlockHash, type L2BlockId } from '@aztec/stdlib/block';
5
+ import { Gas } from '@aztec/stdlib/gas';
6
+ import { type Tx, TxHash } from '@aztec/stdlib/tx';
5
7
 
6
8
  import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
7
9
  import { getTxPriorityFee } from '../tx_pool/priority.js';
8
- import type { PreAddResult } from './eviction/interfaces.js';
10
+ import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
11
+
12
+ /** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
13
+ export type TxMetaValidationData = {
14
+ getNonEmptyNullifiers(): Fr[];
15
+ expirationTimestamp: bigint;
16
+ /** Whether the tx has public calls. Used to select the correct L2 gas minimum. */
17
+ forPublic?: unknown;
18
+ constants: {
19
+ anchorBlockHeader: {
20
+ hash(): Promise<BlockHash>;
21
+ globalVariables: {
22
+ blockNumber: BlockNumber;
23
+ };
24
+ };
25
+ txContext: {
26
+ gasSettings: { gasLimits: Gas };
27
+ };
28
+ };
29
+ };
9
30
 
10
31
  /**
11
32
  * Lightweight in-memory representation of a transaction.
@@ -19,6 +40,9 @@ export type TxMetaData = {
19
40
  /** The transaction hash as hex string */
20
41
  readonly txHash: string;
21
42
 
43
+ /** The transaction hash as bigint (for efficient Fr conversion in comparisons) */
44
+ readonly txHashBigInt: bigint;
45
+
22
46
  /** Block ID (number and hash) in which the transaction was mined (undefined if not mined) */
23
47
  minedL2BlockId?: L2BlockId;
24
48
 
@@ -41,46 +65,114 @@ export type TxMetaData = {
41
65
  readonly nullifiers: readonly string[];
42
66
 
43
67
  /** Timestamp by which the transaction must be included (for expiration checks) */
44
- readonly includeByTimestamp: bigint;
68
+ readonly expirationTimestamp: bigint;
69
+
70
+ /** Whether the tx's setup-phase calls pass the allow list check. Computed at receipt time. */
71
+ readonly allowedSetupCalls: boolean;
72
+
73
+ /** Validator-compatible data, providing the same access patterns as Tx.data */
74
+ readonly data: TxMetaValidationData;
75
+
76
+ /** Timestamp (ms) when the tx was received into the pool. 0 for hydrated txs (always eligible). */
77
+ receivedAt: number;
78
+
79
+ /** Estimated memory footprint of this metadata object in bytes */
80
+ readonly estimatedSizeBytes: number;
45
81
  };
46
82
 
47
83
  /** Transaction state derived from TxMetaData fields and pool protection status */
48
- export type TxState = 'pending' | 'protected' | 'mined';
84
+ export type TxState = 'pending' | 'protected' | 'mined' | 'deleted';
49
85
 
50
86
  /**
51
87
  * Builds TxMetaData from a full Tx object.
52
88
  * Extracts all relevant fields for efficient in-memory storage and querying.
89
+ * Fr values are captured in closures for zero-cost re-validation.
90
+ *
91
+ * @param allowedSetupCalls - Whether the tx's setup-phase calls pass the allow list.
92
+ * For gossip/RPC txs this is always `true` (already validated by PhasesTxValidator).
93
+ * For req/resp txs this should be computed by the caller using the phases validator.
53
94
  */
54
- export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
55
- const txHash = tx.getTxHash().toString();
56
- const anchorBlockHeaderHash = (await tx.data.constants.anchorBlockHeader.hash()).toString();
95
+ export async function buildTxMetaData(tx: Tx, allowedSetupCalls: boolean = true): Promise<TxMetaData> {
96
+ const txHashObj = tx.getTxHash();
97
+ const txHash = txHashObj.toString();
98
+ const txHashBigInt = txHashObj.toBigInt();
99
+ const nullifierFrs = tx.data.getNonEmptyNullifiers();
100
+ const nullifiers = nullifierFrs.map(n => n.toString());
101
+ const anchorBlockHeaderHashFr = await tx.data.constants.anchorBlockHeader.hash();
102
+ const anchorBlockHeaderHash = anchorBlockHeaderHashFr.toString();
103
+ const expirationTimestamp = tx.data.expirationTimestamp;
104
+ const anchorBlockNumber = tx.data.constants.anchorBlockHeader.globalVariables.blockNumber;
57
105
  const priorityFee = getTxPriorityFee(tx);
58
106
  const feePayer = tx.data.feePayer.toString();
59
- const nullifiers = tx.data.getNonEmptyNullifiers().map(n => n.toString());
60
- const includeByTimestamp = tx.data.includeByTimestamp;
61
107
 
62
108
  const { feeLimit, claimAmount } = await getFeePayerBalanceDelta(tx, ProtocolContractAddress.FeeJuice);
63
109
 
110
+ const estimatedSizeBytes = estimateTxMetaDataSize(nullifiers.length);
111
+
64
112
  return {
65
113
  txHash,
114
+ txHashBigInt,
66
115
  anchorBlockHeaderHash,
67
116
  priorityFee,
68
117
  feePayer,
69
118
  claimAmount,
70
119
  feeLimit,
71
120
  nullifiers,
72
- includeByTimestamp,
121
+ expirationTimestamp,
122
+ allowedSetupCalls,
123
+ receivedAt: 0,
124
+ estimatedSizeBytes,
125
+ data: {
126
+ getNonEmptyNullifiers: () => nullifierFrs,
127
+ expirationTimestamp,
128
+ forPublic: !!tx.data.forPublic,
129
+ constants: {
130
+ anchorBlockHeader: {
131
+ hash: () => Promise.resolve(anchorBlockHeaderHashFr),
132
+ globalVariables: { blockNumber: anchorBlockNumber },
133
+ },
134
+ txContext: {
135
+ gasSettings: { gasLimits: tx.data.constants.txContext.gasSettings.gasLimits },
136
+ },
137
+ },
138
+ },
73
139
  };
74
140
  }
75
141
 
142
+ // V8 JS object overhead (~64 bytes for a plain object with hidden class).
143
+ // String overhead: ~32 bytes header + 1 byte per ASCII char (V8 one-byte strings).
144
+ // Hex string (0x + 64 hex chars = 66 chars): ~98 bytes per string.
145
+ // bigint: ~32 bytes. number: 8 bytes. Fr: ~80 bytes (32 data + object overhead).
146
+ const OBJECT_OVERHEAD = 64;
147
+ const HEX_STRING_BYTES = 98;
148
+ const BIGINT_BYTES = 32;
149
+ const FR_BYTES = 80;
150
+ // Fixed cost: object shell + txHash + anchorBlockHeaderHash + feePayer (3 hex strings)
151
+ // + txHashBigInt + priorityFee + claimAmount + feeLimit + includeByTimestamp (5 bigints)
152
+ // + receivedAt (number, 8 bytes) + estimatedSizeBytes (number, 8 bytes)
153
+ // + data closure object (~OBJECT_OVERHEAD + anchorBlockHeaderHashFr Fr + anchorBlockNumber number)
154
+ const FIXED_METADATA_BYTES =
155
+ OBJECT_OVERHEAD + 3 * HEX_STRING_BYTES + 5 * BIGINT_BYTES + 8 + 8 + OBJECT_OVERHEAD + FR_BYTES + 8;
156
+
157
+ /** Estimates the in-memory size of a TxMetaData object based on the number of nullifiers. */
158
+ function estimateTxMetaDataSize(nullifierCount: number): number {
159
+ // Per nullifier: one hex string in nullifiers[] + one Fr in the captured nullifierFrs[]
160
+ return FIXED_METADATA_BYTES + nullifierCount * (HEX_STRING_BYTES + FR_BYTES);
161
+ }
162
+
163
+ /** Converts a txHash bigint back to the canonical 0x-prefixed 64-char hex string. */
164
+ export function txHashFromBigInt(value: bigint): string {
165
+ return TxHash.fromBigInt(value).toString();
166
+ }
167
+
76
168
  /** Minimal fields required for priority comparison. */
77
- type PriorityComparable = Pick<TxMetaData, 'txHash' | 'priorityFee'>;
169
+ export type PriorityComparable = Pick<TxMetaData, 'txHash' | 'txHashBigInt' | 'priorityFee'>;
78
170
 
79
171
  /**
80
172
  * Compares two priority fees in ascending order.
81
173
  * Returns negative if a < b, positive if a > b, 0 if equal.
82
174
  */
83
- export function compareFee(a: bigint, b: bigint): number {
175
+ export function compareFee(a: bigint, b: bigint): -1 | 0 | 1 {
84
176
  return a < b ? -1 : a > b ? 1 : 0;
85
177
  }
86
178
 
@@ -89,10 +181,8 @@ export function compareFee(a: bigint, b: bigint): number {
89
181
  * Uses field element comparison for deterministic ordering.
90
182
  * Returns negative if a < b, positive if a > b, 0 if equal.
91
183
  */
92
- export function compareTxHash(a: string, b: string): number {
93
- const fieldA = Fr.fromHexString(a);
94
- const fieldB = Fr.fromHexString(b);
95
- return fieldA.cmp(fieldB);
184
+ export function compareTxHash(a: bigint, b: bigint): -1 | 0 | 1 {
185
+ return Fr.cmpAsBigInt(a, b);
96
186
  }
97
187
 
98
188
  /**
@@ -100,29 +190,46 @@ export function compareTxHash(a: string, b: string): number {
100
190
  * Returns negative if a < b, positive if a > b, 0 if equal.
101
191
  * Use with sort() for ascending order, or negate/reverse for descending.
102
192
  */
103
- export function comparePriority(a: PriorityComparable, b: PriorityComparable): number {
193
+ export function comparePriority(a: PriorityComparable, b: PriorityComparable): -1 | 0 | 1 {
104
194
  const feeComparison = compareFee(a.priorityFee, b.priorityFee);
105
195
  if (feeComparison !== 0) {
106
196
  return feeComparison;
107
197
  }
108
- return compareTxHash(a.txHash, b.txHash);
198
+ return compareTxHash(a.txHashBigInt, b.txHashBigInt);
199
+ }
200
+
201
+ /**
202
+ * Returns the minimum fee required to replace an existing tx with the given price bump percentage.
203
+ * Uses integer arithmetic: `existingFee + existingFee * priceBumpPercentage / 100`.
204
+ */
205
+ export function getMinimumPriceBumpFee(existingFee: bigint, priceBumpPercentage: bigint): bigint {
206
+ const bump = (existingFee * priceBumpPercentage) / 100n;
207
+ // Ensure the minimum bump is at least 1, so that replacement always requires
208
+ // paying strictly more — even with 0% bump or zero existing fee.
209
+ const effectiveBump = bump > 0n ? bump : 1n;
210
+ return existingFee + effectiveBump;
109
211
  }
110
212
 
111
213
  /**
112
214
  * Checks for nullifier conflicts between an incoming transaction and existing pool state.
113
215
  *
114
216
  * When the incoming tx shares nullifiers with existing pending txs:
115
- * - If the incoming tx has strictly higher priority, mark conflicting txs for eviction
116
- * - If any conflicting tx has equal or higher priority, ignore the incoming tx
217
+ * - If the incoming tx meets or exceeds the required priority, mark conflicting txs for eviction
218
+ * - Otherwise, ignore the incoming tx
219
+ *
220
+ * When `priceBumpPercentage` is provided (RPC path), uses fee-only comparison with the
221
+ * percentage bump instead of `comparePriority`.
117
222
  *
118
223
  * @param incomingMeta - Metadata for the incoming transaction
119
224
  * @param getTxHashByNullifier - Accessor to find which tx uses a nullifier
120
225
  * @param getMetadata - Accessor to get metadata for a tx hash
226
+ * @param priceBumpPercentage - Optional percentage bump required for fee-based replacement
121
227
  */
122
228
  export function checkNullifierConflict(
123
229
  incomingMeta: TxMetaData,
124
230
  getTxHashByNullifier: (nullifier: string) => string | undefined,
125
231
  getMetadata: (txHash: string) => TxMetaData | undefined,
232
+ priceBumpPercentage?: bigint,
126
233
  ): PreAddResult {
127
234
  const txHashesToEvict: string[] = [];
128
235
 
@@ -143,19 +250,88 @@ export function checkNullifierConflict(
143
250
  continue;
144
251
  }
145
252
 
146
- // If incoming tx has strictly higher priority, mark for eviction
147
- // Otherwise, ignore incoming tx (ties go to existing tx)
148
- // Use comparePriority for deterministic ordering (includes txHash as tiebreaker)
149
- if (comparePriority(incomingMeta, conflictingMeta) > 0) {
253
+ // When price bump is set (RPC path), require the incoming fee to meet the bumped threshold.
254
+ // Otherwise (P2P path), use full comparePriority with tx hash tiebreaker.
255
+ const isHigherPriority =
256
+ priceBumpPercentage !== undefined
257
+ ? incomingMeta.priorityFee >= getMinimumPriceBumpFee(conflictingMeta.priorityFee, priceBumpPercentage)
258
+ : comparePriority(incomingMeta, conflictingMeta) > 0;
259
+
260
+ if (isHigherPriority) {
150
261
  txHashesToEvict.push(conflictingHashStr);
151
262
  } else {
263
+ const minimumFee =
264
+ priceBumpPercentage !== undefined
265
+ ? getMinimumPriceBumpFee(conflictingMeta.priorityFee, priceBumpPercentage)
266
+ : undefined;
152
267
  return {
153
268
  shouldIgnore: true,
154
269
  txHashesToEvict: [],
155
- reason: `nullifier conflict with ${conflictingHashStr}`,
270
+ reason: {
271
+ code: TxPoolRejectionCode.NULLIFIER_CONFLICT,
272
+ message:
273
+ minimumFee !== undefined
274
+ ? `Nullifier conflict with existing tx ${conflictingHashStr}. Minimum required fee: ${minimumFee}, got: ${incomingMeta.priorityFee}`
275
+ : `Nullifier conflict with existing tx ${conflictingHashStr}`,
276
+ conflictingTxHash: conflictingHashStr,
277
+ minimumPriceBumpFee: minimumFee,
278
+ txPriorityFee: minimumFee !== undefined ? incomingMeta.priorityFee : undefined,
279
+ },
156
280
  };
157
281
  }
158
282
  }
159
283
 
160
284
  return { shouldIgnore: false, txHashesToEvict };
161
285
  }
286
+
287
+ /** Creates a stub TxMetaValidationData for tests that don't exercise validators. */
288
+ export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigint } = {}): TxMetaValidationData {
289
+ return {
290
+ getNonEmptyNullifiers: () => [],
291
+ expirationTimestamp: overrides.expirationTimestamp ?? 0n,
292
+ constants: {
293
+ anchorBlockHeader: {
294
+ hash: () => Promise.resolve(new BlockHash(Fr.ZERO)),
295
+ globalVariables: { blockNumber: BlockNumber(0) },
296
+ },
297
+ txContext: {
298
+ gasSettings: { gasLimits: Gas.empty() },
299
+ },
300
+ },
301
+ };
302
+ }
303
+
304
+ /** Creates a stub TxMetaData for tests. All fields have sensible defaults and can be overridden. */
305
+ export function stubTxMetaData(
306
+ txHash: string,
307
+ overrides: {
308
+ priorityFee?: bigint;
309
+ feePayer?: string;
310
+ claimAmount?: bigint;
311
+ feeLimit?: bigint;
312
+ nullifiers?: string[];
313
+ expirationTimestamp?: bigint;
314
+ anchorBlockHeaderHash?: string;
315
+ allowedSetupCalls?: boolean;
316
+ } = {},
317
+ ): TxMetaData {
318
+ const txHashBigInt = Fr.fromHexString(txHash).toBigInt();
319
+ // Normalize to canonical zero-padded hex so txHashFromBigInt(txHashBigInt) === normalizedTxHash
320
+ const normalizedTxHash = txHashFromBigInt(txHashBigInt);
321
+ const expirationTimestamp = overrides.expirationTimestamp ?? 0n;
322
+ return {
323
+ txHash: normalizedTxHash,
324
+ txHashBigInt,
325
+ anchorBlockHeaderHash: overrides.anchorBlockHeaderHash ?? '0x1234',
326
+ priorityFee: overrides.priorityFee ?? 100n,
327
+ feePayer: overrides.feePayer ?? '0xfeepayer',
328
+ claimAmount: overrides.claimAmount ?? 0n,
329
+ feeLimit: overrides.feeLimit ?? 100n,
330
+ nullifiers: overrides.nullifiers ?? [`0x${normalizedTxHash.slice(2)}null1`],
331
+ expirationTimestamp,
332
+ allowedSetupCalls: overrides.allowedSetupCalls ?? true,
333
+ receivedAt: 0,
334
+ estimatedSizeBytes: 0,
335
+ data: stubTxMetaValidationData({ expirationTimestamp }),
336
+ };
337
+ }
@@ -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
  }