@aztec/p2p 0.0.1-commit.5914bae → 0.0.1-commit.59a0419c6

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 (286) hide show
  1. package/dest/client/factory.d.ts +4 -3
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +17 -15
  4. package/dest/client/interface.d.ts +9 -2
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +3 -2
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +30 -8
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +21 -7
  10. package/dest/config.d.ts +107 -103
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +17 -12
  13. package/dest/errors/p2p-service.error.d.ts +9 -0
  14. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  15. package/dest/errors/p2p-service.error.js +10 -0
  16. package/dest/index.d.ts +1 -2
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +0 -1
  19. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/attestation_pool.js +16 -9
  22. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
  23. package/dest/mem_pools/index.d.ts +1 -2
  24. package/dest/mem_pools/index.d.ts.map +1 -1
  25. package/dest/mem_pools/instrumentation.d.ts +4 -2
  26. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  27. package/dest/mem_pools/instrumentation.js +16 -14
  28. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
  29. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  30. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
  31. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  32. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  33. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  34. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
  35. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +10 -5
  36. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/interfaces.js +1 -0
  38. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +9 -7
  39. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +13 -6
  41. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  42. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
  44. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +1 -1
  45. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
  47. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -1
  48. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +20 -2
  50. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
  51. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  52. package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
  53. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
  54. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  55. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
  56. package/dest/msg_validators/clock_tolerance.d.ts +12 -1
  57. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  58. package/dest/msg_validators/clock_tolerance.js +54 -3
  59. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
  60. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  61. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
  62. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  63. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
  64. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  65. package/dest/msg_validators/proposal_validator/proposal_validator.js +19 -11
  66. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  67. package/dest/msg_validators/tx_validator/factory.d.ts +2 -2
  68. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/factory.js +3 -3
  70. package/dest/msg_validators/tx_validator/gas_validator.d.ts +36 -4
  71. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/gas_validator.js +50 -33
  73. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  74. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  76. package/dest/services/data_store.d.ts +1 -1
  77. package/dest/services/data_store.d.ts.map +1 -1
  78. package/dest/services/data_store.js +5 -5
  79. package/dest/services/dummy_service.d.ts +6 -3
  80. package/dest/services/dummy_service.d.ts.map +1 -1
  81. package/dest/services/dummy_service.js +6 -1
  82. package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
  83. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  84. package/dest/services/gossipsub/topic_score_params.js +21 -4
  85. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  86. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  87. package/dest/services/libp2p/instrumentation.js +14 -0
  88. package/dest/services/libp2p/libp2p_service.d.ts +19 -27
  89. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  90. package/dest/services/libp2p/libp2p_service.js +158 -133
  91. package/dest/services/peer-manager/metrics.d.ts +3 -1
  92. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  93. package/dest/services/peer-manager/metrics.js +6 -0
  94. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  95. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  96. package/dest/services/peer-manager/peer_manager.js +39 -11
  97. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  98. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  99. package/dest/services/peer-manager/peer_scoring.js +32 -10
  100. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
  101. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  102. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +82 -101
  103. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
  104. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  105. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  106. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  107. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  108. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  109. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  110. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  111. package/dest/services/reqresp/config.d.ts +3 -3
  112. package/dest/services/reqresp/config.d.ts.map +1 -1
  113. package/dest/services/reqresp/interface.d.ts +14 -9
  114. package/dest/services/reqresp/interface.d.ts.map +1 -1
  115. package/dest/services/reqresp/interface.js +10 -11
  116. package/dest/services/reqresp/metrics.d.ts +1 -1
  117. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  118. package/dest/services/reqresp/metrics.js +0 -1
  119. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  120. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  121. package/dest/services/reqresp/protocols/index.js +0 -1
  122. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  123. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  124. package/dest/services/reqresp/protocols/tx.js +1 -3
  125. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  126. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  127. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  128. package/dest/services/reqresp/reqresp.d.ts +4 -2
  129. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  130. package/dest/services/reqresp/reqresp.js +13 -3
  131. package/dest/services/service.d.ts +5 -2
  132. package/dest/services/service.d.ts.map +1 -1
  133. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
  134. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  135. package/dest/services/tx_collection/fast_tx_collection.js +57 -73
  136. package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
  137. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  138. package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
  139. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  140. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  141. package/dest/services/tx_collection/request_tracker.js +84 -0
  142. package/dest/services/tx_collection/slow_tx_collection.js +1 -1
  143. package/dest/services/tx_collection/tx_collection.d.ts +3 -6
  144. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  145. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  146. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  147. package/dest/test-helpers/make-test-p2p-clients.js +4 -1
  148. package/dest/test-helpers/mock-pubsub.d.ts +11 -3
  149. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  150. package/dest/test-helpers/mock-pubsub.js +36 -11
  151. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  152. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  153. package/dest/test-helpers/reqresp-nodes.js +5 -3
  154. package/dest/test-helpers/testbench-utils.d.ts +1 -1
  155. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  156. package/dest/test-helpers/testbench-utils.js +21 -2
  157. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  158. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  159. package/dest/testbench/p2p_client_testbench_worker.js +73 -17
  160. package/dest/testbench/worker_client_manager.d.ts +8 -1
  161. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  162. package/dest/testbench/worker_client_manager.js +51 -2
  163. package/dest/util.d.ts +1 -1
  164. package/package.json +14 -14
  165. package/src/client/factory.ts +25 -19
  166. package/src/client/interface.ts +9 -1
  167. package/src/client/p2p_client.ts +34 -9
  168. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +21 -9
  169. package/src/config.ts +29 -17
  170. package/src/errors/p2p-service.error.ts +11 -0
  171. package/src/index.ts +0 -1
  172. package/src/mem_pools/attestation_pool/attestation_pool.ts +17 -12
  173. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
  174. package/src/mem_pools/index.ts +0 -3
  175. package/src/mem_pools/instrumentation.ts +17 -13
  176. package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
  177. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  178. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
  179. package/src/mem_pools/tx_pool_v2/interfaces.ts +10 -4
  180. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +24 -12
  181. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
  182. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +3 -0
  183. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +21 -1
  184. package/src/msg_validators/attestation_validator/README.md +1 -1
  185. package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
  186. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
  187. package/src/msg_validators/clock_tolerance.ts +72 -3
  188. package/src/msg_validators/proposal_validator/README.md +4 -4
  189. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +4 -1
  190. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +4 -1
  191. package/src/msg_validators/proposal_validator/proposal_validator.ts +17 -10
  192. package/src/msg_validators/tx_validator/README.md +11 -3
  193. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  194. package/src/msg_validators/tx_validator/factory.ts +3 -1
  195. package/src/msg_validators/tx_validator/gas_validator.ts +82 -33
  196. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  197. package/src/services/data_store.ts +5 -13
  198. package/src/services/dummy_service.ts +8 -2
  199. package/src/services/gossipsub/topic_score_params.ts +36 -4
  200. package/src/services/libp2p/instrumentation.ts +14 -0
  201. package/src/services/libp2p/libp2p_service.ts +154 -143
  202. package/src/services/peer-manager/metrics.ts +7 -0
  203. package/src/services/peer-manager/peer_manager.ts +45 -11
  204. package/src/services/peer-manager/peer_scoring.ts +27 -5
  205. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  206. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +78 -111
  207. package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
  208. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  209. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  210. package/src/services/reqresp/config.ts +2 -2
  211. package/src/services/reqresp/interface.ts +21 -11
  212. package/src/services/reqresp/metrics.ts +0 -1
  213. package/src/services/reqresp/protocols/index.ts +0 -1
  214. package/src/services/reqresp/protocols/tx.ts +1 -3
  215. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  216. package/src/services/reqresp/reqresp.ts +21 -2
  217. package/src/services/service.ts +6 -1
  218. package/src/services/tx_collection/fast_tx_collection.ts +57 -83
  219. package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
  220. package/src/services/tx_collection/request_tracker.ts +127 -0
  221. package/src/services/tx_collection/slow_tx_collection.ts +1 -1
  222. package/src/services/tx_collection/tx_collection.ts +3 -5
  223. package/src/test-helpers/make-test-p2p-clients.ts +3 -1
  224. package/src/test-helpers/mock-pubsub.ts +34 -5
  225. package/src/test-helpers/reqresp-nodes.ts +5 -3
  226. package/src/test-helpers/testbench-utils.ts +29 -3
  227. package/src/testbench/p2p_client_testbench_worker.ts +74 -15
  228. package/src/testbench/worker_client_manager.ts +57 -2
  229. package/src/util.ts +1 -1
  230. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  231. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  232. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  233. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  234. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  235. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  236. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  237. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  238. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  239. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  240. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  241. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -123
  242. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  243. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  244. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  245. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  246. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  247. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  248. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  249. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  250. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  251. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  252. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  253. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  254. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  255. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  256. package/dest/mem_pools/tx_pool/index.js +0 -2
  257. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  258. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  259. package/dest/mem_pools/tx_pool/priority.js +0 -15
  260. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  261. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  262. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  263. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  264. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  265. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -402
  266. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  267. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  268. package/dest/services/reqresp/protocols/block.js +0 -32
  269. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  270. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  271. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  272. package/src/mem_pools/tx_pool/README.md +0 -270
  273. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  274. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  275. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  276. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -163
  277. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  278. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  279. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  280. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  281. package/src/mem_pools/tx_pool/index.ts +0 -2
  282. package/src/mem_pools/tx_pool/priority.ts +0 -20
  283. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  284. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -321
  285. package/src/services/reqresp/protocols/block.ts +0 -37
  286. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
@@ -26,10 +26,10 @@ export type TryAddResult = {
26
26
  count: number;
27
27
  };
28
28
 
29
- export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 5;
30
- export const MAX_BLOCK_PROPOSALS_PER_POSITION = 3;
29
+ export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 2;
30
+ export const MAX_BLOCK_PROPOSALS_PER_POSITION = 2;
31
31
  /** Maximum attestations a single signer can make per slot before being rejected. */
32
- export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 3;
32
+ export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 2;
33
33
 
34
34
  /** Public API interface for attestation pools. Used for typing mocks and test implementations. */
35
35
  export type AttestationPoolApi = Pick<
@@ -154,14 +154,16 @@ export class AttestationPool {
154
154
  /** Maximum indexWithinCheckpoint value (2^10 - 1 = 1023). */
155
155
  private static readonly MAX_INDEX = (1 << AttestationPool.INDEX_BITS) - 1;
156
156
 
157
- /** Creates a position key for block proposals: (slot << 10) | indexWithinCheckpoint. */
157
+ /** Creates a position key for block proposals: slot * 1024 + indexWithinCheckpoint.
158
+ * Uses multiplication instead of bit-shift to avoid 32-bit signed integer overflow
159
+ * (bit-shift overflows after slot ~2^21, roughly 278 days of uptime). */
158
160
  private getBlockPositionKey(slot: number, indexWithinCheckpoint: number): number {
159
161
  if (indexWithinCheckpoint > AttestationPool.MAX_INDEX) {
160
162
  throw new Error(
161
163
  `Value for indexWithinCheckpoint ${indexWithinCheckpoint} exceeds maximum ${AttestationPool.MAX_INDEX}`,
162
164
  );
163
165
  }
164
- return (slot << AttestationPool.INDEX_BITS) | indexWithinCheckpoint;
166
+ return slot * (1 << AttestationPool.INDEX_BITS) + indexWithinCheckpoint;
165
167
  }
166
168
 
167
169
  /**
@@ -278,7 +280,7 @@ export class AttestationPool {
278
280
  * @returns Result indicating whether the proposal was added and duplicate detection info
279
281
  */
280
282
  public async tryAddCheckpointProposal(proposal: CheckpointProposalCore): Promise<TryAddResult> {
281
- return await this.store.transactionAsync(async () => {
283
+ const result = await this.store.transactionAsync(async () => {
282
284
  const proposalId = proposal.archive.toString();
283
285
 
284
286
  // Check if already exists
@@ -304,6 +306,8 @@ export class AttestationPool {
304
306
 
305
307
  return { added: true, alreadyExists: false, count: count + 1 };
306
308
  });
309
+
310
+ return result;
307
311
  }
308
312
 
309
313
  /** Internal method - must be called within a transaction. */
@@ -345,7 +349,7 @@ export class AttestationPool {
345
349
  await this.store.transactionAsync(async () => {
346
350
  for (const attestation of attestations) {
347
351
  const slotNumber = attestation.payload.header.slotNumber;
348
- const proposalId = attestation.archive;
352
+ const proposalId = attestation.archive.toString();
349
353
  const sender = attestation.getSender();
350
354
 
351
355
  // Skip attestations with invalid signatures
@@ -359,11 +363,10 @@ export class AttestationPool {
359
363
  }
360
364
 
361
365
  const address = sender.toString();
366
+ const ownKey = this.getAttestationKey(slotNumber, proposalId, address);
362
367
 
363
- await this.checkpointAttestations.set(
364
- this.getAttestationKey(slotNumber, proposalId, address),
365
- attestation.toBuffer(),
366
- );
368
+ await this.checkpointAttestations.set(ownKey, attestation.toBuffer());
369
+ this.metrics.trackMempoolItemAdded(ownKey);
367
370
 
368
371
  this.log.debug(`Added own checkpoint attestation for slot ${slotNumber} from ${address}`, {
369
372
  signature: attestation.signature.toString(),
@@ -429,6 +432,7 @@ export class AttestationPool {
429
432
  const attestationEndKey = new Fr(oldestSlot).toString();
430
433
  for await (const key of this.checkpointAttestations.keysAsync({ end: attestationEndKey })) {
431
434
  await this.checkpointAttestations.delete(key);
435
+ this.metrics.trackMempoolItemRemoved(key);
432
436
  numberOfAttestations++;
433
437
  }
434
438
 
@@ -452,7 +456,7 @@ export class AttestationPool {
452
456
 
453
457
  // Delete block proposals for slots < oldestSlot, using blockProposalsForSlotAndIndex as index
454
458
  // Key format: (slot << INDEX_BITS) | indexWithinCheckpoint
455
- const blockPositionEndKey = oldestSlot << AttestationPool.INDEX_BITS;
459
+ const blockPositionEndKey = oldestSlot * (1 << AttestationPool.INDEX_BITS);
456
460
  for await (const positionKey of this.blockProposalsForSlotAndIndex.keysAsync({ end: blockPositionEndKey })) {
457
461
  const proposalIds = await toArray(this.blockProposalsForSlotAndIndex.getValuesAsync(positionKey));
458
462
  for (const proposalId of proposalIds) {
@@ -526,6 +530,7 @@ export class AttestationPool {
526
530
 
527
531
  // Add the attestation
528
532
  await this.checkpointAttestations.set(key, attestation.toBuffer());
533
+ this.metrics.trackMempoolItemAdded(key);
529
534
 
530
535
  // Track this attestation in the per-signer-per-slot index for duplicate detection
531
536
  const slotSignerKey = this.getSlotSignerKey(slotNumber, signerAddress);
@@ -446,12 +446,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
446
446
  const result2 = await ap.tryAddBlockProposal(proposal2);
447
447
  expect(result2.count).toBe(2);
448
448
 
449
- // Add a third proposal for same position
449
+ // Third proposal for same position should be rejected (cap is 2)
450
450
  const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
451
451
  const result3 = await ap.tryAddBlockProposal(proposal3);
452
452
 
453
- expect(result3.added).toBe(true);
454
- expect(result3.count).toBe(3);
453
+ expect(result3.added).toBe(false);
454
+ expect(result3.count).toBe(2);
455
455
  });
456
456
 
457
457
  it('should return added=false when exceeding capacity', async () => {
@@ -666,12 +666,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
666
666
  const result2 = await ap.tryAddCheckpointProposal(proposal2);
667
667
  expect(result2.count).toBe(2);
668
668
 
669
- // Add a third proposal for same slot
669
+ // Third proposal for same slot should be rejected (cap is 2)
670
670
  const proposal3 = await mockCheckpointProposalCoreForPool(signers[2], slotNumber);
671
671
  const result3 = await ap.tryAddCheckpointProposal(proposal3);
672
672
 
673
- expect(result3.added).toBe(true);
674
- expect(result3.count).toBe(3);
673
+ expect(result3.added).toBe(false);
674
+ expect(result3.count).toBe(2);
675
675
  });
676
676
 
677
677
  it('should not count attestations as proposals for duplicate detection', async () => {
@@ -1,6 +1,3 @@
1
1
  export { AttestationPool, type AttestationPoolApi } from './attestation_pool/attestation_pool.js';
2
2
  export { type MemPools } from './interface.js';
3
- // Old TxPool exports - kept temporarily for external consumers
4
- export { type TxPool } from './tx_pool/tx_pool.js';
5
- // New TxPoolV2 exports
6
3
  export { type TxPoolV2, type TxPoolV2Config, type TxPoolV2Events, type AddTxsResult } from './tx_pool_v2/index.js';
@@ -73,7 +73,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
73
73
  private defaultAttributes;
74
74
  private meter: Meter;
75
75
 
76
- private txAddedTimestamp: Map<bigint, number> = new Map<bigint, number>();
76
+ private mempoolItemAddedTimestamp: Map<bigint | string, number> = new Map<bigint | string, number>();
77
77
 
78
78
  constructor(
79
79
  telemetry: TelemetryClient,
@@ -114,22 +114,26 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
114
114
  }
115
115
 
116
116
  public transactionsAdded(transactions: Tx[]) {
117
- const timestamp = Date.now();
118
- for (const transaction of transactions) {
119
- this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
120
- }
117
+ transactions.forEach(tx => this.trackMempoolItemAdded(tx.txHash.toBigInt()));
121
118
  }
122
119
 
123
120
  public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
124
- const timestamp = Date.now();
125
121
  for (const hash of hashes) {
126
- const key = BigInt(hash);
127
- const addedAt = this.txAddedTimestamp.get(key);
128
- if (addedAt !== undefined) {
129
- this.txAddedTimestamp.delete(key);
130
- if (addedAt < timestamp) {
131
- this.minedDelay.record(timestamp - addedAt);
132
- }
122
+ this.trackMempoolItemRemoved(BigInt(hash));
123
+ }
124
+ }
125
+
126
+ public trackMempoolItemAdded(key: bigint | string): void {
127
+ this.mempoolItemAddedTimestamp.set(key, Date.now());
128
+ }
129
+
130
+ public trackMempoolItemRemoved(key: bigint | string): void {
131
+ const timestamp = Date.now();
132
+ const addedAt = this.mempoolItemAddedTimestamp.get(key);
133
+ if (addedAt !== undefined) {
134
+ this.mempoolItemAddedTimestamp.delete(key);
135
+ if (addedAt < timestamp) {
136
+ this.minedDelay.record(timestamp - addedAt);
133
137
  }
134
138
  }
135
139
  }
@@ -21,6 +21,7 @@ export { FeePayerBalancePreAddRule } from './fee_payer_balance_pre_add_rule.js';
21
21
  export { LowPriorityPreAddRule } from './low_priority_pre_add_rule.js';
22
22
 
23
23
  // Post-event eviction rules
24
+ export { InsufficientFeePerGasEvictionRule } from './insufficient_fee_per_gas_eviction_rule.js';
24
25
  export { InvalidTxsAfterMiningRule } from './invalid_txs_after_mining_rule.js';
25
26
  export { InvalidTxsAfterReorgRule } from './invalid_txs_after_reorg_rule.js';
26
27
  export { FeePayerBalanceEvictionRule } from './fee_payer_balance_eviction_rule.js';
@@ -0,0 +1,65 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import type { BlockMinFeesProvider } from '@aztec/stdlib/gas';
3
+
4
+ import type { EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
5
+ import { EvictionEvent } from './interfaces.js';
6
+
7
+ /**
8
+ * Eviction rule that removes transactions whose maxFeesPerGas no longer meets
9
+ * the projected minimum gas fees after a new block is mined.
10
+ * Uses the BlockMinFeesProvider (forward-looking) to get the projected minimum fees.
11
+ * Only triggers on BLOCK_MINED events.
12
+ */
13
+ export class InsufficientFeePerGasEvictionRule implements EvictionRule {
14
+ public readonly name = 'InsufficientFeePerGas';
15
+
16
+ private log = createLogger('p2p:tx_pool_v2:insufficient_fee_per_gas_eviction_rule');
17
+
18
+ constructor(private blockMinFeesProvider: BlockMinFeesProvider) {}
19
+
20
+ async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
21
+ if (context.event !== EvictionEvent.BLOCK_MINED) {
22
+ return {
23
+ reason: 'insufficient_fee_per_gas',
24
+ success: true,
25
+ txsEvicted: [],
26
+ };
27
+ }
28
+
29
+ try {
30
+ const gasFees = await this.blockMinFeesProvider.getCurrentMinFees();
31
+ const txsToEvict: string[] = [];
32
+ const pendingTxs = pool.getPendingTxs();
33
+
34
+ for (const meta of pendingTxs) {
35
+ const maxFeesPerGas = meta.data.constants.txContext.gasSettings.maxFeesPerGas;
36
+ if (maxFeesPerGas.feePerDaGas < gasFees.feePerDaGas || maxFeesPerGas.feePerL2Gas < gasFees.feePerL2Gas) {
37
+ this.log.verbose(`Evicting tx ${meta.txHash} from pool due to insufficient fee per gas`, {
38
+ txMaxFeesPerGas: maxFeesPerGas.toInspect(),
39
+ blockGasFees: gasFees.toInspect(),
40
+ });
41
+ txsToEvict.push(meta.txHash);
42
+ }
43
+ }
44
+
45
+ if (txsToEvict.length > 0) {
46
+ this.log.info(`Evicted ${txsToEvict.length} txs with insufficient fee per gas after block mined`);
47
+ await pool.deleteTxs(txsToEvict, this.name);
48
+ }
49
+
50
+ return {
51
+ reason: 'insufficient_fee_per_gas',
52
+ success: true,
53
+ txsEvicted: txsToEvict,
54
+ };
55
+ } catch (err) {
56
+ this.log.error('Failed to evict transactions with insufficient fee per gas', { err });
57
+ return {
58
+ reason: 'insufficient_fee_per_gas',
59
+ success: false,
60
+ txsEvicted: [],
61
+ error: new Error('Failed to evict txs with insufficient fee per gas', { cause: err }),
62
+ };
63
+ }
64
+ }
65
+ }
@@ -1,5 +1,5 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import { BlockHash } from '@aztec/stdlib/block';
3
3
  import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
4
4
  import { MerkleTreeId } from '@aztec/stdlib/trees';
5
5
 
@@ -33,14 +33,14 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
33
33
  const pendingTxs = pool.getPendingTxs();
34
34
 
35
35
  // Deduplicate block hashes to reduce redundant DB lookups
36
- const uniqueBlockHashes = new Map<string, Fr>();
36
+ const uniqueBlockHashes = new Map<string, BlockHash>();
37
37
  const txsByBlockHash = new Map<string, string[]>();
38
38
 
39
39
  for (const meta of pendingTxs) {
40
40
  const blockHashStr = meta.anchorBlockHeaderHash;
41
41
  if (!txsByBlockHash.has(blockHashStr)) {
42
42
  txsByBlockHash.set(blockHashStr, []);
43
- uniqueBlockHashes.set(blockHashStr, Fr.fromHexString(blockHashStr));
43
+ uniqueBlockHashes.set(blockHashStr, BlockHash.fromString(blockHashStr));
44
44
  }
45
45
  txsByBlockHash.get(blockHashStr)!.push(meta.txHash);
46
46
  }
@@ -1,6 +1,7 @@
1
1
  import type { SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { TypedEventEmitter } from '@aztec/foundation/types';
3
3
  import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
4
+ import type { BlockMinFeesProvider } from '@aztec/stdlib/gas';
4
5
  import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
5
6
  import type { BlockHeader, Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
6
7
 
@@ -44,6 +45,8 @@ export type TxPoolV2Config = {
44
45
  minTxPoolAgeMs: number;
45
46
  /** Maximum number of evicted tx hashes to remember for metrics tracking */
46
47
  evictedTxCacheSize: number;
48
+ /** The probability (0-1) that a transaction is discarded. 0 disables dropping. For testing purposes only. */
49
+ dropTransactionsProbability: number;
47
50
  /** Minimum percentage fee increase required to replace an existing tx via RPC (0 = no bump). */
48
51
  priceBumpPercentage: bigint;
49
52
  };
@@ -56,6 +59,7 @@ export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
56
59
  archivedTxLimit: 0, // 0 = disabled
57
60
  minTxPoolAgeMs: 2_000,
58
61
  evictedTxCacheSize: 10_000,
62
+ dropTransactionsProbability: 0,
59
63
  priceBumpPercentage: 10n,
60
64
  };
61
65
 
@@ -71,6 +75,8 @@ export type TxPoolV2Dependencies = {
71
75
  createTxValidator: () => Promise<TxValidator<TxMetaData>>;
72
76
  /** Checks whether a tx's setup-phase calls are on the allow list. Precomputed at receipt time. */
73
77
  checkAllowedSetupCalls: (tx: Tx) => Promise<boolean>;
78
+ /** Provides projected minimum fees for the next block. Used by eviction rules instead of stale block header fees. */
79
+ blockMinFeesProvider: BlockMinFeesProvider;
74
80
  };
75
81
 
76
82
  /**
@@ -157,10 +163,10 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
157
163
  handleMinedBlock(block: L2Block): Promise<void>;
158
164
 
159
165
  /**
160
- * Prepares the pool for a new slot.
161
- * Unprotects transactions from earlier slots and validates them before
162
- * returning to pending state.
163
- * @param slotNumber - The slot number to prepare for
166
+ * Prepares the pool for a new slot by unprotecting transactions from earlier
167
+ * slots and re-validating them before returning to pending state.
168
+ * @param slotNumber - The pipeline slot we are building for (i.e. the slot
169
+ * the resulting blocks will target on L1).
164
170
  */
165
171
  prepareForSlot(slotNumber: SlotNumber): Promise<void>;
166
172
 
@@ -1,12 +1,12 @@
1
+ import { minBigint } from '@aztec/foundation/bigint';
1
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
5
  import { BlockHash, type L2BlockId } from '@aztec/stdlib/block';
5
- import { Gas } from '@aztec/stdlib/gas';
6
+ import { Gas, GasFees } from '@aztec/stdlib/gas';
6
7
  import { type Tx, TxHash } from '@aztec/stdlib/tx';
7
8
 
8
9
  import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
9
- import { getTxPriorityFee } from '../tx_pool/priority.js';
10
10
  import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
11
11
 
12
12
  /** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
@@ -23,7 +23,7 @@ export type TxMetaValidationData = {
23
23
  };
24
24
  };
25
25
  txContext: {
26
- gasSettings: { gasLimits: Gas };
26
+ gasSettings: { gasLimits: Gas; maxFeesPerGas: GasFees };
27
27
  };
28
28
  };
29
29
  };
@@ -132,7 +132,10 @@ export async function buildTxMetaData(tx: Tx, allowedSetupCalls: boolean = true)
132
132
  globalVariables: { blockNumber: anchorBlockNumber },
133
133
  },
134
134
  txContext: {
135
- gasSettings: { gasLimits: tx.data.constants.txContext.gasSettings.gasLimits },
135
+ gasSettings: {
136
+ gasLimits: tx.data.constants.txContext.gasSettings.gasLimits,
137
+ maxFeesPerGas: tx.data.constants.txContext.gasSettings.maxFeesPerGas,
138
+ },
136
139
  },
137
140
  },
138
141
  },
@@ -166,13 +169,13 @@ export function txHashFromBigInt(value: bigint): string {
166
169
  }
167
170
 
168
171
  /** Minimal fields required for priority comparison. */
169
- type PriorityComparable = Pick<TxMetaData, 'txHashBigInt' | 'priorityFee'>;
172
+ export type PriorityComparable = Pick<TxMetaData, 'txHash' | 'txHashBigInt' | 'priorityFee'>;
170
173
 
171
174
  /**
172
175
  * Compares two priority fees in ascending order.
173
176
  * Returns negative if a < b, positive if a > b, 0 if equal.
174
177
  */
175
- export function compareFee(a: bigint, b: bigint): number {
178
+ export function compareFee(a: bigint, b: bigint): -1 | 0 | 1 {
176
179
  return a < b ? -1 : a > b ? 1 : 0;
177
180
  }
178
181
 
@@ -181,7 +184,7 @@ export function compareFee(a: bigint, b: bigint): number {
181
184
  * Uses field element comparison for deterministic ordering.
182
185
  * Returns negative if a < b, positive if a > b, 0 if equal.
183
186
  */
184
- export function compareTxHash(a: bigint, b: bigint): number {
187
+ export function compareTxHash(a: bigint, b: bigint): -1 | 0 | 1 {
185
188
  return Fr.cmpAsBigInt(a, b);
186
189
  }
187
190
 
@@ -190,7 +193,7 @@ export function compareTxHash(a: bigint, b: bigint): number {
190
193
  * Returns negative if a < b, positive if a > b, 0 if equal.
191
194
  * Use with sort() for ascending order, or negate/reverse for descending.
192
195
  */
193
- export function comparePriority(a: PriorityComparable, b: PriorityComparable): number {
196
+ export function comparePriority(a: PriorityComparable, b: PriorityComparable): -1 | 0 | 1 {
194
197
  const feeComparison = compareFee(a.priorityFee, b.priorityFee);
195
198
  if (feeComparison !== 0) {
196
199
  return feeComparison;
@@ -285,17 +288,19 @@ export function checkNullifierConflict(
285
288
  }
286
289
 
287
290
  /** Creates a stub TxMetaValidationData for tests that don't exercise validators. */
288
- export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigint } = {}): TxMetaValidationData {
291
+ export function stubTxMetaValidationData(
292
+ overrides: { expirationTimestamp?: bigint; maxFeesPerGas?: GasFees } = {},
293
+ ): TxMetaValidationData {
289
294
  return {
290
295
  getNonEmptyNullifiers: () => [],
291
296
  expirationTimestamp: overrides.expirationTimestamp ?? 0n,
292
297
  constants: {
293
298
  anchorBlockHeader: {
294
- hash: () => Promise.resolve(new BlockHash(Fr.ZERO)),
299
+ hash: () => Promise.resolve(BlockHash.ZERO),
295
300
  globalVariables: { blockNumber: BlockNumber(0) },
296
301
  },
297
302
  txContext: {
298
- gasSettings: { gasLimits: Gas.empty() },
303
+ gasSettings: { gasLimits: Gas.empty(), maxFeesPerGas: overrides.maxFeesPerGas ?? GasFees.empty() },
299
304
  },
300
305
  },
301
306
  };
@@ -313,6 +318,7 @@ export function stubTxMetaData(
313
318
  expirationTimestamp?: bigint;
314
319
  anchorBlockHeaderHash?: string;
315
320
  allowedSetupCalls?: boolean;
321
+ maxFeesPerGas?: GasFees;
316
322
  } = {},
317
323
  ): TxMetaData {
318
324
  const txHashBigInt = Fr.fromHexString(txHash).toBigInt();
@@ -332,6 +338,12 @@ export function stubTxMetaData(
332
338
  allowedSetupCalls: overrides.allowedSetupCalls ?? true,
333
339
  receivedAt: 0,
334
340
  estimatedSizeBytes: 0,
335
- data: stubTxMetaValidationData({ expirationTimestamp }),
341
+ data: stubTxMetaValidationData({ expirationTimestamp, maxFeesPerGas: overrides.maxFeesPerGas }),
336
342
  };
337
343
  }
344
+
345
+ /** Returns the priority fee for a tx, based on the L2 priority fee capped by the max fee per gas. */
346
+ function getTxPriorityFee(tx: Tx): bigint {
347
+ const { maxPriorityFeesPerGas: priorityFees, maxFeesPerGas } = tx.getGasSettings();
348
+ return minBigint(maxFeesPerGas.feePerL2Gas, priorityFees.feePerL2Gas);
349
+ }
@@ -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, txHashFromBigInt } 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 txHash bigints grouped by priority fee */
26
- #pendingByPriority: Map<bigint, Set<bigint>> = 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
 
@@ -73,20 +74,14 @@ export class TxPoolIndices {
73
74
  * @param order - 'desc' for highest priority first, 'asc' for lowest priority first
74
75
  */
75
76
  *iteratePendingByPriority(order: 'asc' | 'desc', filter?: (hash: string) => boolean): Generator<string> {
76
- const feeCompareFn = order === 'desc' ? (a: bigint, b: bigint) => compareFee(b, a) : compareFee;
77
- const hashCompareFn =
78
- order === 'desc' ? (a: bigint, b: bigint) => compareTxHash(b, a) : (a: bigint, b: bigint) => compareTxHash(a, b);
79
-
80
- const sortedFees = [...this.#pendingByPriority.keys()].sort(feeCompareFn);
81
-
82
- for (const fee of sortedFees) {
83
- const hashesAtFee = this.#pendingByPriority.get(fee)!;
84
- const sortedHashes = [...hashesAtFee].sort(hashCompareFn);
85
- for (const hashBigInt of sortedHashes) {
86
- const hash = txHashFromBigInt(hashBigInt);
87
- if (filter === undefined || filter(hash)) {
88
- yield hash;
89
- }
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;
90
85
  }
91
86
  }
92
87
  }
@@ -227,11 +222,7 @@ export class TxPoolIndices {
227
222
 
228
223
  /** Gets the count of pending transactions */
229
224
  getPendingTxCount(): number {
230
- let count = 0;
231
- for (const hashes of this.#pendingByPriority.values()) {
232
- count += hashes.size;
233
- }
234
- return count;
225
+ return this.#pendingByPriority.length;
235
226
  }
236
227
 
237
228
  /** Gets the lowest priority pending transaction hashes (up to limit) */
@@ -264,12 +255,10 @@ export class TxPoolIndices {
264
255
  /** Gets all pending transactions */
265
256
  getPendingTxs(): TxMetaData[] {
266
257
  const result: TxMetaData[] = [];
267
- for (const hashSet of this.#pendingByPriority.values()) {
268
- for (const txHashBigInt of hashSet) {
269
- const meta = this.#metadata.get(txHashFromBigInt(txHashBigInt));
270
- if (meta) {
271
- result.push(meta);
272
- }
258
+ for (const entry of this.#pendingByPriority) {
259
+ const meta = this.#metadata.get(entry.txHash);
260
+ if (meta) {
261
+ result.push(meta);
273
262
  }
274
263
  }
275
264
  return result;
@@ -408,13 +397,12 @@ export class TxPoolIndices {
408
397
  }
409
398
  feePayerSet.add(meta.txHash);
410
399
 
411
- // Add to priority bucket
412
- let prioritySet = this.#pendingByPriority.get(meta.priorityFee);
413
- if (!prioritySet) {
414
- prioritySet = new Set();
415
- this.#pendingByPriority.set(meta.priorityFee, prioritySet);
416
- }
417
- prioritySet.add(meta.txHashBigInt);
400
+ insertIntoSortedArray(
401
+ this.#pendingByPriority,
402
+ { txHash: meta.txHash, priorityFee: meta.priorityFee, txHashBigInt: meta.txHashBigInt },
403
+ comparePriority,
404
+ false,
405
+ );
418
406
  }
419
407
 
420
408
  #removeFromPendingIndices(meta: TxMetaData): void {
@@ -432,13 +420,11 @@ export class TxPoolIndices {
432
420
  }
433
421
  }
434
422
 
435
- // Remove from priority map
436
- const hashSet = this.#pendingByPriority.get(meta.priorityFee);
437
- if (hashSet) {
438
- hashSet.delete(meta.txHashBigInt);
439
- if (hashSet.size === 0) {
440
- this.#pendingByPriority.delete(meta.priorityFee);
441
- }
442
- }
423
+ // Remove from priority array
424
+ removeFromSortedArray(
425
+ this.#pendingByPriority,
426
+ { txHash: meta.txHash, priorityFee: meta.priorityFee, txHashBigInt: meta.txHashBigInt },
427
+ comparePriority,
428
+ );
443
429
  }
444
430
  }
@@ -65,6 +65,9 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
65
65
  const hashes = txHashes.map(h => (typeof h === 'string' ? TxHash.fromString(h) : TxHash.fromBigInt(h)));
66
66
  this.emit('txs-removed', { txHashes: hashes });
67
67
  },
68
+ onTxsMined: (txHashes: string[]) => {
69
+ this.#metrics?.transactionsRemoved(txHashes);
70
+ },
68
71
  };
69
72
 
70
73
  // Create the implementation
@@ -17,6 +17,7 @@ import {
17
17
  EvictionManager,
18
18
  FeePayerBalanceEvictionRule,
19
19
  FeePayerBalancePreAddRule,
20
+ InsufficientFeePerGasEvictionRule,
20
21
  InvalidTxsAfterMiningRule,
21
22
  InvalidTxsAfterReorgRule,
22
23
  LowPriorityEvictionRule,
@@ -45,6 +46,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
45
46
  export interface TxPoolV2Callbacks {
46
47
  onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
47
48
  onTxsRemoved: (txHashes: string[] | bigint[]) => void;
49
+ onTxsMined: (txHashes: string[]) => void;
48
50
  }
49
51
 
50
52
  /**
@@ -115,6 +117,7 @@ export class TxPoolV2Impl {
115
117
 
116
118
  // Post-event eviction rules (run after events to check ALL pending txs)
117
119
  this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
120
+ this.#evictionManager.registerRule(new InsufficientFeePerGasEvictionRule(deps.blockMinFeesProvider));
118
121
  this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(deps.worldStateSynchronizer));
119
122
  this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(deps.worldStateSynchronizer));
120
123
  // LowPriorityEvictionRule handles cases where txs become pending via prepareForSlot (unprotect)
@@ -339,6 +342,12 @@ export class TxPoolV2Impl {
339
342
  }
340
343
  }
341
344
 
345
+ // Randomly drop the transaction for testing purposes (report as accepted so it propagates)
346
+ if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
347
+ this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
348
+ return { status: 'accepted' };
349
+ }
350
+
342
351
  // Add the transaction
343
352
  await this.#addTx(tx, 'pending', opts, precomputedMeta);
344
353
  return { status: 'accepted' };
@@ -349,6 +358,7 @@ export class TxPoolV2Impl {
349
358
 
350
359
  // Check if already in pool
351
360
  if (this.#indices.has(txHashStr)) {
361
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
352
362
  return 'ignored';
353
363
  }
354
364
 
@@ -357,7 +367,13 @@ export class TxPoolV2Impl {
357
367
  const poolAccess = this.#createPreAddPoolAccess();
358
368
  const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
359
369
 
360
- return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
370
+ if (preAddResult.shouldIgnore) {
371
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
372
+ reason: preAddResult.reason?.message ?? 'no reason provided',
373
+ });
374
+ return 'ignored';
375
+ }
376
+ return 'accepted';
361
377
  }
362
378
 
363
379
  async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
@@ -501,6 +517,10 @@ export class TxPoolV2Impl {
501
517
  await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
502
518
  });
503
519
 
520
+ if (found.length > 0) {
521
+ this.#callbacks.onTxsMined(found.map(m => m.txHash));
522
+ }
523
+
504
524
  this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
505
525
  }
506
526
 
@@ -24,7 +24,7 @@ This module validates `CheckpointAttestation` gossipsub messages. Attestations a
24
24
  |---|------|-------------|
25
25
  | 8 | Sender recoverable (pool-side) | Silent drop |
26
26
  | 9 | Not a duplicate (same slot + proposalId + signer) | IGNORE |
27
- | 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` = 3 | IGNORE |
27
+ | 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` = 2 | IGNORE |
28
28
 
29
29
  Own attestations added via `addOwnCheckpointAttestations` bypass the per-signer cap.
30
30