@aztec/p2p 0.0.1-commit.7d4e6cd → 0.0.1-commit.858058eac

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 (475) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +4 -3
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +4 -4
  4. package/dest/client/factory.d.ts +5 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +47 -13
  7. package/dest/client/interface.d.ts +33 -15
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +35 -36
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +116 -140
  12. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
  13. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
  14. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
  15. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
  16. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
  17. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
  18. package/dest/config.d.ts +24 -3
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +18 -4
  21. package/dest/index.d.ts +2 -1
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +102 -88
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.js +436 -3
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +373 -96
  30. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  31. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/index.js +1 -2
  33. package/dest/mem_pools/attestation_pool/mocks.d.ts +4 -2
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/mocks.js +8 -5
  36. package/dest/mem_pools/index.d.ts +3 -2
  37. package/dest/mem_pools/index.d.ts.map +1 -1
  38. package/dest/mem_pools/index.js +1 -1
  39. package/dest/mem_pools/instrumentation.d.ts +1 -1
  40. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  41. package/dest/mem_pools/instrumentation.js +2 -2
  42. package/dest/mem_pools/interface.d.ts +5 -5
  43. package/dest/mem_pools/interface.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
  45. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
  47. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
  48. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
  50. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
  51. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
  53. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  54. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  56. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
  57. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
  59. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
  61. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
  62. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  64. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  66. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  67. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  69. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  70. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  72. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +87 -0
  73. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +180 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  92. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  93. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  94. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  95. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  96. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  97. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  98. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  99. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  100. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  101. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  102. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  103. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  104. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  105. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  106. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  107. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  108. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  109. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  110. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +93 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  113. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +127 -0
  114. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  115. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  116. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  117. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  118. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  119. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  120. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  121. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  122. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  123. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  124. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  125. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +751 -0
  126. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
  127. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  128. package/dest/msg_validators/attestation_validator/attestation_validator.js +41 -10
  129. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  130. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -6
  132. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  133. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  134. package/dest/msg_validators/clock_tolerance.js +37 -0
  135. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
  136. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  137. package/dest/msg_validators/proposal_validator/proposal_validator.js +55 -31
  138. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
  139. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
  140. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +93 -64
  141. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
  142. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  144. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  145. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  146. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
  147. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  148. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  149. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  150. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  151. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  152. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
  153. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  154. package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
  155. package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
  156. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  157. package/dest/msg_validators/tx_validator/factory.js +21 -11
  158. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  159. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  160. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  161. package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
  162. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  163. package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
  164. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  165. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  166. package/dest/msg_validators/tx_validator/index.js +1 -0
  167. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  168. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  169. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  170. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  171. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  172. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  173. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  174. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  175. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  176. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +22 -5
  177. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  178. package/dest/msg_validators/tx_validator/timestamp_validator.js +4 -4
  179. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  180. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  181. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  182. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  183. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  184. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  185. package/dest/services/data_store.d.ts +1 -1
  186. package/dest/services/data_store.d.ts.map +1 -1
  187. package/dest/services/data_store.js +10 -6
  188. package/dest/services/discv5/discV5_service.js +1 -1
  189. package/dest/services/dummy_service.d.ts +22 -2
  190. package/dest/services/dummy_service.d.ts.map +1 -1
  191. package/dest/services/dummy_service.js +45 -0
  192. package/dest/services/encoding.d.ts +2 -2
  193. package/dest/services/encoding.d.ts.map +1 -1
  194. package/dest/services/encoding.js +4 -5
  195. package/dest/services/gossipsub/index.d.ts +3 -0
  196. package/dest/services/gossipsub/index.d.ts.map +1 -0
  197. package/dest/services/gossipsub/index.js +2 -0
  198. package/dest/services/gossipsub/scoring.d.ts +21 -3
  199. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  200. package/dest/services/gossipsub/scoring.js +24 -7
  201. package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
  202. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  203. package/dest/services/gossipsub/topic_score_params.js +324 -0
  204. package/dest/services/index.d.ts +2 -1
  205. package/dest/services/index.d.ts.map +1 -1
  206. package/dest/services/index.js +1 -0
  207. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  208. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  209. package/dest/services/libp2p/instrumentation.js +19 -8
  210. package/dest/services/libp2p/libp2p_service.d.ts +91 -36
  211. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  212. package/dest/services/libp2p/libp2p_service.js +407 -303
  213. package/dest/services/peer-manager/metrics.d.ts +2 -2
  214. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  215. package/dest/services/peer-manager/metrics.js +20 -5
  216. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  217. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  218. package/dest/services/peer-manager/peer_scoring.js +33 -4
  219. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
  220. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  221. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
  222. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  223. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  224. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  225. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  226. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  227. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  228. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
  229. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  230. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
  231. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
  232. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  233. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
  234. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  235. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  236. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  237. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  238. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  239. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  240. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  241. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  242. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  243. package/dest/services/reqresp/constants.d.ts +12 -0
  244. package/dest/services/reqresp/constants.d.ts.map +1 -0
  245. package/dest/services/reqresp/constants.js +7 -0
  246. package/dest/services/reqresp/interface.d.ts +12 -1
  247. package/dest/services/reqresp/interface.d.ts.map +1 -1
  248. package/dest/services/reqresp/interface.js +15 -1
  249. package/dest/services/reqresp/metrics.d.ts +6 -5
  250. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  251. package/dest/services/reqresp/metrics.js +17 -5
  252. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  253. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  254. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  255. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  256. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  257. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  258. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +29 -6
  259. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  260. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +59 -13
  261. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  262. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  263. package/dest/services/reqresp/protocols/status.js +2 -1
  264. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  265. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  266. package/dest/services/reqresp/protocols/tx.js +20 -0
  267. package/dest/services/reqresp/reqresp.d.ts +6 -1
  268. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  269. package/dest/services/reqresp/reqresp.js +69 -26
  270. package/dest/services/service.d.ts +38 -1
  271. package/dest/services/service.d.ts.map +1 -1
  272. package/dest/services/tx_collection/config.d.ts +10 -1
  273. package/dest/services/tx_collection/config.d.ts.map +1 -1
  274. package/dest/services/tx_collection/config.js +25 -1
  275. package/dest/services/tx_collection/fast_tx_collection.d.ts +7 -4
  276. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  277. package/dest/services/tx_collection/fast_tx_collection.js +34 -13
  278. package/dest/services/tx_collection/file_store_tx_collection.d.ts +44 -0
  279. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  280. package/dest/services/tx_collection/file_store_tx_collection.js +118 -0
  281. package/dest/services/tx_collection/file_store_tx_source.d.ts +27 -0
  282. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  283. package/dest/services/tx_collection/file_store_tx_source.js +57 -0
  284. package/dest/services/tx_collection/index.d.ts +3 -1
  285. package/dest/services/tx_collection/index.d.ts.map +1 -1
  286. package/dest/services/tx_collection/index.js +2 -0
  287. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  288. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  289. package/dest/services/tx_collection/instrumentation.js +9 -2
  290. package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
  291. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  292. package/dest/services/tx_collection/proposal_tx_collector.js +49 -0
  293. package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
  294. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  295. package/dest/services/tx_collection/slow_tx_collection.js +48 -19
  296. package/dest/services/tx_collection/tx_collection.d.ts +23 -13
  297. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  298. package/dest/services/tx_collection/tx_collection.js +62 -6
  299. package/dest/services/tx_collection/tx_collection_sink.d.ts +15 -6
  300. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  301. package/dest/services/tx_collection/tx_collection_sink.js +13 -7
  302. package/dest/services/tx_file_store/config.d.ts +16 -0
  303. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  304. package/dest/services/tx_file_store/config.js +22 -0
  305. package/dest/services/tx_file_store/index.d.ts +4 -0
  306. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  307. package/dest/services/tx_file_store/index.js +3 -0
  308. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  309. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  310. package/dest/services/tx_file_store/instrumentation.js +29 -0
  311. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  312. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  313. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  314. package/dest/services/tx_provider.d.ts +5 -5
  315. package/dest/services/tx_provider.d.ts.map +1 -1
  316. package/dest/services/tx_provider.js +5 -4
  317. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  318. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  319. package/dest/services/tx_provider_instrumentation.js +5 -5
  320. package/dest/test-helpers/index.d.ts +3 -1
  321. package/dest/test-helpers/index.d.ts.map +1 -1
  322. package/dest/test-helpers/index.js +2 -0
  323. package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
  324. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  325. package/dest/test-helpers/mock-pubsub.d.ts +27 -1
  326. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  327. package/dest/test-helpers/mock-pubsub.js +97 -2
  328. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  329. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  330. package/dest/test-helpers/reqresp-nodes.js +2 -1
  331. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  332. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  333. package/dest/test-helpers/test_tx_provider.js +41 -0
  334. package/dest/test-helpers/testbench-utils.d.ts +158 -0
  335. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  336. package/dest/test-helpers/testbench-utils.js +360 -0
  337. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  338. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  339. package/dest/testbench/p2p_client_testbench_worker.js +213 -133
  340. package/dest/testbench/worker_client_manager.d.ts +51 -6
  341. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  342. package/dest/testbench/worker_client_manager.js +226 -44
  343. package/package.json +16 -16
  344. package/src/bootstrap/bootstrap.ts +7 -4
  345. package/src/client/factory.ts +78 -22
  346. package/src/client/interface.ts +39 -14
  347. package/src/client/p2p_client.ts +156 -167
  348. package/src/client/test/tx_proposal_collector/README.md +227 -0
  349. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
  350. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  351. package/src/config.ts +40 -4
  352. package/src/index.ts +1 -0
  353. package/src/mem_pools/attestation_pool/attestation_pool.ts +488 -91
  354. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +460 -112
  355. package/src/mem_pools/attestation_pool/index.ts +9 -2
  356. package/src/mem_pools/attestation_pool/mocks.ts +6 -4
  357. package/src/mem_pools/index.ts +4 -1
  358. package/src/mem_pools/instrumentation.ts +2 -1
  359. package/src/mem_pools/interface.ts +4 -4
  360. package/src/mem_pools/tx_pool/README.md +28 -13
  361. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
  362. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
  363. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
  364. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  365. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  366. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  367. package/src/mem_pools/tx_pool_v2/README.md +259 -0
  368. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  369. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  370. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +234 -0
  371. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  372. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  373. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  374. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  375. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  376. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  377. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  378. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  379. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  380. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  381. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  382. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  383. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +207 -0
  384. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  385. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  386. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  387. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +895 -0
  388. package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -14
  389. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +16 -10
  390. package/src/msg_validators/clock_tolerance.ts +51 -0
  391. package/src/msg_validators/proposal_validator/proposal_validator.ts +31 -31
  392. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +91 -67
  393. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
  394. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  395. package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
  396. package/src/msg_validators/tx_validator/data_validator.ts +6 -2
  397. package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
  398. package/src/msg_validators/tx_validator/factory.ts +64 -23
  399. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  400. package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
  401. package/src/msg_validators/tx_validator/index.ts +1 -0
  402. package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
  403. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  404. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  405. package/src/msg_validators/tx_validator/timestamp_validator.ts +25 -17
  406. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  407. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  408. package/src/services/data_store.ts +10 -7
  409. package/src/services/discv5/discV5_service.ts +1 -1
  410. package/src/services/dummy_service.ts +57 -0
  411. package/src/services/encoding.ts +4 -5
  412. package/src/services/gossipsub/README.md +626 -0
  413. package/src/services/gossipsub/index.ts +2 -0
  414. package/src/services/gossipsub/scoring.ts +29 -5
  415. package/src/services/gossipsub/topic_score_params.ts +451 -0
  416. package/src/services/index.ts +1 -0
  417. package/src/services/libp2p/instrumentation.ts +20 -7
  418. package/src/services/libp2p/libp2p_service.ts +435 -314
  419. package/src/services/peer-manager/metrics.ts +21 -4
  420. package/src/services/peer-manager/peer_scoring.ts +29 -1
  421. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  422. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
  423. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  424. package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
  425. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
  426. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
  427. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  428. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  429. package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
  430. package/src/services/reqresp/constants.ts +14 -0
  431. package/src/services/reqresp/interface.ts +29 -1
  432. package/src/services/reqresp/metrics.ts +34 -9
  433. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  434. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +35 -12
  435. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +74 -9
  436. package/src/services/reqresp/protocols/status.ts +5 -3
  437. package/src/services/reqresp/protocols/tx.ts +22 -0
  438. package/src/services/reqresp/reqresp.ts +79 -22
  439. package/src/services/service.ts +44 -0
  440. package/src/services/tx_collection/config.ts +41 -1
  441. package/src/services/tx_collection/fast_tx_collection.ts +44 -19
  442. package/src/services/tx_collection/file_store_tx_collection.ts +152 -0
  443. package/src/services/tx_collection/file_store_tx_source.ts +70 -0
  444. package/src/services/tx_collection/index.ts +6 -0
  445. package/src/services/tx_collection/instrumentation.ts +11 -2
  446. package/src/services/tx_collection/proposal_tx_collector.ts +112 -0
  447. package/src/services/tx_collection/slow_tx_collection.ts +57 -28
  448. package/src/services/tx_collection/tx_collection.ts +86 -20
  449. package/src/services/tx_collection/tx_collection_sink.ts +17 -7
  450. package/src/services/tx_file_store/config.ts +37 -0
  451. package/src/services/tx_file_store/index.ts +3 -0
  452. package/src/services/tx_file_store/instrumentation.ts +36 -0
  453. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  454. package/src/services/tx_provider.ts +10 -9
  455. package/src/services/tx_provider_instrumentation.ts +11 -5
  456. package/src/test-helpers/index.ts +2 -0
  457. package/src/test-helpers/make-test-p2p-clients.ts +3 -3
  458. package/src/test-helpers/mock-pubsub.ts +133 -3
  459. package/src/test-helpers/reqresp-nodes.ts +2 -1
  460. package/src/test-helpers/test_tx_provider.ts +64 -0
  461. package/src/test-helpers/testbench-utils.ts +422 -0
  462. package/src/testbench/p2p_client_testbench_worker.ts +322 -127
  463. package/src/testbench/worker_client_manager.ts +304 -47
  464. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  465. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  466. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  467. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  468. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  469. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  470. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
  471. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
  472. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
  473. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  474. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  475. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
@@ -1,7 +1,12 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Buffer32 } from '@aztec/foundation/buffer';
1
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
6
+ import { type BlockHeader, type Tx, TxHash } from '@aztec/stdlib/tx';
4
7
 
8
+ import { getFeePayerBalanceDelta } from '../../../msg_validators/tx_validator/fee_payer_balance.js';
9
+ import { getTxPriorityFee } from '../priority.js';
5
10
  import type { TxPoolOptions } from '../tx_pool.js';
6
11
 
7
12
  export const EvictionEvent = {
@@ -16,16 +21,17 @@ export type EvictionContext =
16
21
  | {
17
22
  event: typeof EvictionEvent.TXS_ADDED;
18
23
  newTxs: TxHash[];
24
+ feePayers: AztecAddress[];
19
25
  }
20
26
  | {
21
27
  event: typeof EvictionEvent.CHAIN_PRUNED;
22
- blockNumber: number;
28
+ blockNumber: BlockNumber;
23
29
  }
24
30
  | {
25
31
  event: typeof EvictionEvent.BLOCK_MINED;
26
32
  block: BlockHeader;
27
33
  newNullifiers: Fr[];
28
- minedFeePayers: AztecAddress[];
34
+ feePayers: AztecAddress[];
29
35
  };
30
36
 
31
37
  /**
@@ -63,7 +69,8 @@ export interface TxPoolOperations {
63
69
  getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
64
70
  getPendingTxInfos(): Promise<PendingTxInfo[]>;
65
71
  getPendingTxsReferencingBlocks(blockHashes: Fr[]): Promise<TxBlockReference[]>;
66
- getPendingTxsWithFeePayer(feePayer: AztecAddress[]): Promise<PendingTxInfo[]>;
72
+ getPendingFeePayers(): Promise<AztecAddress[]>;
73
+ getFeePayerTxInfos(feePayer: AztecAddress): AsyncIterable<FeePayerTxInfo>;
67
74
  /** Cheap count of current pending transactions. */
68
75
  getPendingTxCount(): Promise<number>;
69
76
  /**
@@ -91,3 +98,111 @@ export interface EvictionRule {
91
98
  */
92
99
  updateConfig(config: TxPoolOptions): void;
93
100
  }
101
+
102
+ /**
103
+ * Balance-related information about a transaction for a fee payer.
104
+ */
105
+ export class FeePayerTxInfo {
106
+ txHash: TxHash;
107
+ priority: bigint;
108
+ feeLimit: bigint;
109
+ claimAmount: bigint;
110
+ isEvictable: boolean;
111
+
112
+ constructor(fields: {
113
+ txHash: TxHash;
114
+ priority: bigint;
115
+ feeLimit: bigint;
116
+ claimAmount: bigint;
117
+ isEvictable: boolean;
118
+ }) {
119
+ this.txHash = fields.txHash;
120
+ this.priority = fields.priority;
121
+ this.feeLimit = fields.feeLimit;
122
+ this.claimAmount = fields.claimAmount;
123
+ this.isEvictable = fields.isEvictable;
124
+ }
125
+
126
+ static async encode(tx: Tx, txHash: string | TxHash): Promise<Buffer> {
127
+ const { feeLimit, claimAmount } = await getFeePayerBalanceDelta(tx, ProtocolContractAddress.FeeJuice);
128
+ const priority = Buffer32.fromBigInt(getTxPriorityFee(tx)).toBuffer();
129
+ const hashBuffer = (typeof txHash === 'string' ? TxHash.fromString(txHash) : txHash).toBuffer();
130
+ const feeLimitBuffer = Buffer32.fromBigInt(feeLimit).toBuffer();
131
+ const claimAmountBuffer = Buffer32.fromBigInt(claimAmount).toBuffer();
132
+ return Buffer.concat([priority, hashBuffer, feeLimitBuffer, claimAmountBuffer]);
133
+ }
134
+
135
+ static decode(value: Buffer, isEvictable = true): FeePayerTxInfo {
136
+ const priority = Buffer32.fromBuffer(value.subarray(0, Buffer32.SIZE)).toBigInt();
137
+ const hashOffset = Buffer32.SIZE;
138
+ const feeLimitOffset = hashOffset + TxHash.SIZE;
139
+ const claimOffset = feeLimitOffset + Buffer32.SIZE;
140
+
141
+ return new FeePayerTxInfo({
142
+ txHash: TxHash.fromBuffer(value.subarray(hashOffset, feeLimitOffset)),
143
+ priority,
144
+ feeLimit: Buffer32.fromBuffer(value.subarray(feeLimitOffset, claimOffset)).toBigInt(),
145
+ claimAmount: Buffer32.fromBuffer(value.subarray(claimOffset, claimOffset + Buffer32.SIZE)).toBigInt(),
146
+ isEvictable,
147
+ });
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Read-only access to pool state for pre-add eviction checks.
153
+ * Passed to pre-add rules during the addTxs transaction.
154
+ */
155
+ export interface PreAddPoolAccess {
156
+ /**
157
+ * Get the pending tx hash that uses a specific nullifier, if any.
158
+ * Returns undefined if no pending tx uses this nullifier.
159
+ */
160
+ getTxHashByNullifier(nullifier: Fr): Promise<TxHash | undefined>;
161
+
162
+ /**
163
+ * Get a pending transaction by its hash.
164
+ */
165
+ getPendingTxByHash(hash: TxHash): Promise<Tx | undefined>;
166
+
167
+ /**
168
+ * Get the priority string for a transaction (for fee comparison).
169
+ */
170
+ getTxPriority(tx: Tx): string;
171
+ }
172
+
173
+ /**
174
+ * Result of a pre-add eviction check for a single transaction.
175
+ */
176
+ export interface PreAddEvictionResult {
177
+ /** Whether the incoming tx should be rejected */
178
+ readonly shouldReject: boolean;
179
+ /** Sorted array of existing tx hashes that should be evicted if this tx is added */
180
+ readonly txHashesToEvict: TxHash[];
181
+ /** Optional reason for rejection */
182
+ readonly reason?: string;
183
+ }
184
+
185
+ /**
186
+ * Strategy interface for pre-add eviction rules.
187
+ * These run inside the addTxs transaction before a tx is added,
188
+ * deciding whether to evict existing txs or reject the incoming tx.
189
+ */
190
+ export interface PreAddEvictionRule {
191
+ readonly name: string;
192
+
193
+ /**
194
+ * Check if incoming tx should be added and which existing txs to evict.
195
+ * Called inside the addTxs database transaction for atomicity.
196
+ *
197
+ * @param tx - The incoming transaction to check
198
+ * @param poolAccess - Read-only access to current pool state
199
+ * @returns Result indicating whether to reject and what to evict
200
+ */
201
+ check(tx: Tx, poolAccess: PreAddPoolAccess): Promise<PreAddEvictionResult>;
202
+
203
+ /**
204
+ * Updates the configuration for this rule.
205
+ * Rules should ignore config options that don't apply to them.
206
+ */
207
+ updateConfig?(config: TxPoolOptions): void;
208
+ }
@@ -0,0 +1,162 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
+ import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
6
+ import { DatabasePublicStateSource, type MerkleTreeReadOperations } from '@aztec/stdlib/trees';
7
+ import type { TxHash } from '@aztec/stdlib/tx';
8
+
9
+ import type { TxPoolOptions } from '../tx_pool.js';
10
+ import {
11
+ type EvictionContext,
12
+ EvictionEvent,
13
+ type EvictionResult,
14
+ type EvictionRule,
15
+ type FeePayerTxInfo,
16
+ type TxPoolOperations,
17
+ } from './eviction_strategy.js';
18
+
19
+ export class FeePayerBalanceEvictionRule implements EvictionRule {
20
+ public readonly name = 'FeePayerBalanceEviction';
21
+ public readonly reason = 'fee_payer_balance';
22
+
23
+ private log = createLogger('p2p:mempool:tx_pool:fee_payer_balance_eviction_rule');
24
+
25
+ constructor(private worldState: WorldStateSynchronizer) {}
26
+
27
+ async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
28
+ try {
29
+ if (context.event === EvictionEvent.TXS_ADDED) {
30
+ return await this.evictForFeePayers(context.feePayers, this.worldState.getCommitted(), txPool);
31
+ }
32
+
33
+ if (context.event === EvictionEvent.BLOCK_MINED) {
34
+ const blockNumber = context.block.getBlockNumber();
35
+ // Ensure world state is synced to this block before accessing the snapshot.
36
+ // This handles the race where a block is added to the archiver
37
+ // but the world state hasn't synced it yet.
38
+ await this.worldState.syncImmediate(blockNumber);
39
+ return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), txPool);
40
+ }
41
+
42
+ // TODO: fix this edge-case
43
+ // This can lead to a race condition if we are catching up in the p2p client.
44
+ // Let's say we have 3 txs for the same fee payer, which get mined in blocks 1, 2, 3.
45
+ // Tx1 consumes fee juice, tx2 increases it, tx3 consumes it again. We see block1 with tx1 first, run this rule, and evict tx3.
46
+ // But tx3 was valid (due to tx2) and mined on block3. And we have just removed from the mempool a tx we needed for proving/reexec.
47
+ //
48
+ // NOTE: this will happen only in case of that lower-priority-fee tx entered in e.g. block 2, and we have higher-priority-fee tx in block 3
49
+ // (simply because that was the timing of these txs). But, in case of higher-priority-fee txs being in block 2, the tx3 won't be evicted
50
+ // -----
51
+ // Proposed fix: evict only if node is synched
52
+ if (context.event === EvictionEvent.CHAIN_PRUNED) {
53
+ // Ensure world state is synced to this block before accessing the snapshot.
54
+ await this.worldState.syncImmediate(context.blockNumber);
55
+ const feePayers = await txPool.getPendingFeePayers();
56
+ return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), txPool);
57
+ }
58
+
59
+ return {
60
+ reason: this.reason,
61
+ success: true,
62
+ txsEvicted: [],
63
+ };
64
+ } catch (err) {
65
+ this.log.error('Failed to evict txs due to fee payer balance', { err });
66
+ return {
67
+ reason: this.reason,
68
+ success: false,
69
+ txsEvicted: [],
70
+ error: new Error('Failed to evict txs due to fee payer balance', { cause: err }),
71
+ };
72
+ }
73
+ }
74
+
75
+ updateConfig(_config: TxPoolOptions): void {}
76
+
77
+ private async evictForFeePayers(
78
+ feePayers: Array<AztecAddress>, // assumed to be unique
79
+ db: MerkleTreeReadOperations,
80
+ txPool: TxPoolOperations,
81
+ ): Promise<EvictionResult> {
82
+ const publicStateSource = this.createPublicStateSource(db);
83
+
84
+ const txsToEvict = (
85
+ await Promise.all(feePayers.map(feePayer => this.getEvictionsForFeePayer(feePayer, publicStateSource, txPool)))
86
+ ).flat();
87
+
88
+ if (txsToEvict.length > 0) {
89
+ await txPool.deleteTxs(txsToEvict);
90
+ }
91
+
92
+ return {
93
+ reason: this.reason,
94
+ success: true,
95
+ txsEvicted: txsToEvict,
96
+ };
97
+ }
98
+
99
+ private async getEvictionsForFeePayer(
100
+ feePayer: AztecAddress,
101
+ publicStateSource: DatabasePublicStateSource,
102
+ txPool: TxPoolOperations,
103
+ ): Promise<TxHash[]> {
104
+ const initialBalance = (
105
+ await publicStateSource.storageRead(
106
+ ProtocolContractAddress.FeeJuice,
107
+ //TODO: cache this LRU-style
108
+ await computeFeePayerBalanceStorageSlot(feePayer),
109
+ )
110
+ ).toBigInt();
111
+
112
+ const txs: FeePayerTxInfo[] = [];
113
+ for await (const entry of txPool.getFeePayerTxInfos(feePayer)) {
114
+ txs.push(entry);
115
+ }
116
+
117
+ if (txs.length === 0) {
118
+ return [];
119
+ }
120
+
121
+ const txsToEvict: TxHash[] = [];
122
+ let balance = initialBalance;
123
+ let hasNonEvictableOverBalance = false;
124
+
125
+ // Evaluate balance in priority order so later claims cannot fund earlier spends.
126
+ // This sorts so that higher priority txs come first.
127
+ txs.sort((a, b) => {
128
+ if (a.priority === b.priority) {
129
+ return a.txHash.toBigInt() >= b.txHash.toBigInt() ? -1 : 1;
130
+ }
131
+
132
+ return a.priority > b.priority ? -1 : 1;
133
+ });
134
+
135
+ for (const tx of txs) {
136
+ const available = balance + tx.claimAmount;
137
+ if (available >= tx.feeLimit) {
138
+ balance = available - tx.feeLimit;
139
+ continue;
140
+ }
141
+
142
+ if (tx.isEvictable) {
143
+ txsToEvict.push(tx.txHash);
144
+ } else {
145
+ hasNonEvictableOverBalance = true;
146
+ }
147
+ }
148
+
149
+ if (hasNonEvictableOverBalance) {
150
+ this.log.verbose('Fee payer balance cannot be satisfied due to non-evictable txs', {
151
+ feePayer: feePayer.toString(),
152
+ balance: initialBalance,
153
+ });
154
+ }
155
+
156
+ return txsToEvict;
157
+ }
158
+
159
+ private createPublicStateSource(db: MerkleTreeReadOperations): DatabasePublicStateSource {
160
+ return new DatabasePublicStateSource(db);
161
+ }
162
+ }
@@ -1,7 +1,7 @@
1
1
  import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
- import type { ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
4
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
5
5
  import { MerkleTreeId } from '@aztec/stdlib/trees';
6
6
  import type { TxHash } from '@aztec/stdlib/tx';
7
7
 
@@ -26,7 +26,7 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
26
26
 
27
27
  private log = createLogger('p2p:mempool:tx_pool:invalid_txs_after_reorg_rule');
28
28
 
29
- public constructor(private worldState: ReadonlyWorldStateAccess) {}
29
+ public constructor(private worldState: WorldStateSynchronizer) {}
30
30
 
31
31
  async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
32
32
  if (context.event !== EvictionEvent.CHAIN_PRUNED) {
@@ -46,6 +46,8 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
46
46
  insertIntoSortedArray(uniqueBlockHashes, blockHash, Fr.cmp, false);
47
47
  });
48
48
 
49
+ // Ensure world state is synced to this block before accessing the snapshot.
50
+ await this.worldState.syncImmediate(context.blockNumber);
49
51
  const db = this.worldState.getSnapshot(context.blockNumber);
50
52
  const blocksFromDb = await db.findLeafIndices(MerkleTreeId.ARCHIVE, uniqueBlockHashes);
51
53
 
@@ -0,0 +1,75 @@
1
+ import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { type Tx, TxHash } from '@aztec/stdlib/tx';
5
+
6
+ import type { PreAddEvictionResult, PreAddEvictionRule, PreAddPoolAccess } from './eviction_strategy.js';
7
+
8
+ const cmpTxHash = (a: TxHash, b: TxHash) => Fr.cmp(a.hash, b.hash);
9
+
10
+ /**
11
+ * Pre-add eviction rule that checks for nullifier conflicts between incoming and existing transactions.
12
+ *
13
+ * When an incoming tx shares nullifiers with existing pending txs:
14
+ * - If the incoming tx has strictly higher priority fee, evict all conflicting txs
15
+ * - If any conflicting tx has equal or higher priority fee, reject the incoming tx
16
+ *
17
+ * This prevents nullifier spam attacks where an attacker floods the mempool with
18
+ * transactions spending the same nullifiers.
19
+ */
20
+ export class NullifierConflictPreAddRule implements PreAddEvictionRule {
21
+ public readonly name = 'NullifierConflictPreAdd';
22
+
23
+ private log = createLogger('p2p:mempool:tx_pool:nullifier_conflict_pre_add_rule');
24
+
25
+ /**
26
+ * Check if the incoming transaction conflicts with existing transactions via nullifiers.
27
+ *
28
+ * @param tx - The incoming transaction
29
+ * @param poolAccess - Read-only access to pool state
30
+ * @returns Result with rejection status and txs to evict
31
+ */
32
+ async check(tx: Tx, poolAccess: PreAddPoolAccess): Promise<PreAddEvictionResult> {
33
+ const txHash = tx.getTxHash();
34
+ const nullifiers = tx.data.getNonEmptyNullifiers();
35
+ const txHashesToEvict: TxHash[] = [];
36
+ const incomingPriority = poolAccess.getTxPriority(tx);
37
+
38
+ for (const nullifier of nullifiers) {
39
+ const conflictingHash = await poolAccess.getTxHashByNullifier(nullifier);
40
+
41
+ if (
42
+ !conflictingHash ||
43
+ conflictingHash.equals(txHash) ||
44
+ findIndexInSortedArray(txHashesToEvict, conflictingHash, cmpTxHash) !== -1
45
+ ) {
46
+ continue;
47
+ }
48
+
49
+ // Get the conflicting tx's priority
50
+ const conflictingTx = await poolAccess.getPendingTxByHash(conflictingHash);
51
+ if (!conflictingTx) {
52
+ continue;
53
+ }
54
+
55
+ const conflictingPriority = poolAccess.getTxPriority(conflictingTx);
56
+
57
+ // If incoming tx has strictly higher priority, mark for eviction
58
+ // Otherwise, reject incoming tx (ties go to existing tx)
59
+ if (incomingPriority > conflictingPriority) {
60
+ insertIntoSortedArray(txHashesToEvict, conflictingHash, cmpTxHash);
61
+ } else {
62
+ this.log.debug(
63
+ `Rejecting tx ${txHash.toString()}: nullifier conflict with ${conflictingHash.toString()} which has higher or equal fee`,
64
+ );
65
+ return {
66
+ shouldReject: true,
67
+ txHashesToEvict: [],
68
+ reason: `nullifier conflict with ${conflictingHash.toString()}`,
69
+ };
70
+ }
71
+ }
72
+
73
+ return { shouldReject: false, txHashesToEvict };
74
+ }
75
+ }
@@ -0,0 +1,259 @@
1
+ # TxPoolV2
2
+
3
+ Transaction pool implementation with explicit state management and pluggable eviction rules.
4
+
5
+ ## Overview
6
+
7
+ TxPoolV2 manages transactions through a state machine with clear transitions:
8
+
9
+ ```
10
+ addPendingTxs()
11
+
12
+
13
+ ┌─────────────────────────────────────┐
14
+ │ PENDING │◄──────────────────┐
15
+ │ (awaiting block inclusion) │ │
16
+ └─────────────────────────────────────┘ │
17
+ │ │
18
+ │ protectTxs() / addProtectedTxs() │
19
+ ▼ │
20
+ ┌─────────────────────────────────────┐ │
21
+ │ PROTECTED │───────────────────┘
22
+ │ (in a block proposal) │ prepareForSlot()
23
+ └─────────────────────────────────────┘ (slot passed without mining)
24
+ │ │
25
+ │ handleMinedBlock() │
26
+ ▼ │
27
+ ┌─────────────────────────────────────┐ │
28
+ │ MINED │───────────────────┘
29
+ │ (included in a block) │ handlePrunedBlocks()
30
+ └─────────────────────────────────────┘ (reorg)
31
+ │ │
32
+ │ handleFinalizedBlock() │ eviction after reorg
33
+ ▼ ▼
34
+ ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
35
+ │ DELETED │ │ SOFT-DELETED │
36
+ │ (hard-deleted or archived) │ │ (kept in DB for debugging) │
37
+ └─────────────────────────────────────┘ └─────────────────────────────────────┘
38
+
39
+ │ handleFinalizedBlock()
40
+ │ (mined block finalized)
41
+
42
+ ┌─────────────────────────────────────┐
43
+ │ HARD-DELETED │
44
+ │ (permanently removed from DB) │
45
+ └─────────────────────────────────────┘
46
+ ```
47
+
48
+ ## Key Components
49
+
50
+ ### TxPoolV2 (`tx_pool_v2.ts`)
51
+
52
+ The public API wrapper that serializes all operations through a queue to prevent race conditions. Delegates to `TxPoolV2Impl` for actual logic.
53
+
54
+ ### TxPoolV2Impl (`tx_pool_v2_impl.ts`)
55
+
56
+ Core implementation containing:
57
+ - KV store persistence for transactions and metadata
58
+ - In-memory indices for fast lookups (by nullifier, fee payer, priority)
59
+ - State transition logic
60
+ - Pre-add rule execution
61
+ - Post-event eviction rule execution
62
+
63
+ ### DeletedPool (`deleted_pool.ts`)
64
+
65
+ Manages soft deletion of transactions from pruned blocks:
66
+ - When a reorg (chain prune) occurs, transactions from pruned blocks are tracked with their original mined block number
67
+ - When these transactions are later evicted (e.g., failed validation, nullifier conflict), they are "soft-deleted" instead of removed
68
+ - Soft-deleted transactions remain in the database for debugging and potential resubmission
69
+ - When the original mined block is finalized on the new chain, soft-deleted transactions are permanently hard-deleted
70
+
71
+ This ensures transactions from reorged blocks are kept around until we're certain they won't be needed.
72
+
73
+ ### TxMetaData (`tx_metadata.ts`)
74
+
75
+ Lightweight metadata stored alongside each transaction:
76
+ - `txHash`: Transaction identifier
77
+ - `anchorBlockHeaderHash`: Hash of the anchor block header
78
+ - `priorityFee`: For priority ordering and challenges
79
+ - `feePayer`: For balance-based eviction
80
+ - `claimAmount`: Fee payer's claim from bridging
81
+ - `feeLimit`: Maximum fee the tx can pay
82
+ - `nullifiers`: For conflict detection
83
+ - `includeByTimestamp`: Expiration timestamp
84
+ - `minedL2BlockId`: Set when mined (undefined otherwise)
85
+
86
+ State is derived by TxPoolIndices:
87
+ - `mined` if `minedL2BlockId` is set
88
+ - `protected` if in protection map
89
+ - `deleted` if soft-deleted (from a pruned block, evicted but kept in DB)
90
+ - `pending` otherwise
91
+
92
+ ## Soft Deletion
93
+
94
+ When a chain reorganization occurs, transactions that were mined in pruned blocks are handled specially:
95
+
96
+ 1. **Tracking**: When `handlePrunedBlocks` is called, all un-mined transactions are tracked by their original mined block number
97
+ 2. **Soft Delete**: If these transactions are later evicted (failed validation, nullifier conflict, etc.), they are "soft-deleted" - removed from indices but kept in the database
98
+ 3. **Retrieval**: Soft-deleted transactions can still be retrieved via `getTxByHash` and `hasTxs`, and return status `'deleted'` from `getTxStatus`
99
+ 4. **Hard Delete**: When `handleFinalizedBlock` is called and the finalized block number reaches or exceeds the transaction's original mined block, the transaction is permanently removed
100
+
101
+ This design allows:
102
+ - Debugging reorg scenarios by keeping transaction data available
103
+ - Potential resubmission of transactions that failed validation after a reorg
104
+ - Clean eventual cleanup once we're certain the transaction won't be needed
105
+
106
+ **Example scenario:**
107
+ 1. Tx mined at block 10
108
+ 2. Chain prunes to block 5 (tx becomes un-mined, tracked as minedAtBlock=10)
109
+ 3. Tx fails validation and is soft-deleted
110
+ 4. Block 9 finalized → tx still in DB (minedAtBlock=10 > finalized=9)
111
+ 5. Block 10 finalized → tx hard-deleted (minedAtBlock=10 ≤ finalized=10)
112
+
113
+ If the tx is re-mined at a higher block before being soft-deleted:
114
+ 1. Tx mined at block 10, pruned (tracked as minedAtBlock=10)
115
+ 2. Tx re-mined at block 15, pruned again (updated to minedAtBlock=15)
116
+ 3. Tx soft-deleted
117
+ 4. Block 10 finalized → tx still in DB
118
+ 5. Block 15 finalized → tx hard-deleted
119
+
120
+ ## Architecture: Pre-add vs Post-event Rules
121
+
122
+ **Pre-add rules** (run during `addPendingTxs`):
123
+ - Used for external transactions entering the pool
124
+ - Can reject the incoming tx entirely
125
+ - Can evict lower-priority existing txs to make room
126
+ - Rules: NullifierConflictRule, FeePayerBalancePreAddRule, LowPriorityPreAddRule
127
+
128
+ **Post-event rules** (run after state transitions):
129
+ - Used for internal state changes (block mined, reorg, slot change)
130
+ - Only evict txs already in the pool
131
+ - Rules: InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, FeePayerBalanceEvictionRule, LowPriorityEvictionRule
132
+
133
+ This design choice means restored txs (from protected/mined states) use post-event rules only, because they were already validated on initial submission.
134
+
135
+ ## Eviction Rules
136
+
137
+ The pool uses a pluggable rule system for managing transactions.
138
+
139
+ ### Pre-Add Rules
140
+
141
+ Checked before adding a transaction to the pending pool:
142
+
143
+ | Rule | Purpose |
144
+ |------|---------|
145
+ | `NullifierConflictRule` | Handles transactions with conflicting nullifiers. Higher priority tx wins. |
146
+ | `FeePayerBalancePreAddRule` | Ensures fee payer has sufficient balance for all their pending txs. |
147
+ | `LowPriorityPreAddRule` | Rejects txs when pool is full and new tx has lowest priority. |
148
+
149
+ ### Post-Event Eviction Rules
150
+
151
+ Run after events to clean up the pool:
152
+
153
+ | Rule | Trigger | Purpose |
154
+ |------|---------|---------|
155
+ | `LowPriorityEvictionRule` | `txs_added` | Evicts lowest priority txs when pool exceeds limit. |
156
+ | `FeePayerBalanceEvictionRule` | `txs_added`, `block_mined`, `chain_pruned` | Evicts txs when fee payer has insufficient balance. |
157
+ | `InvalidTxsAfterMiningRule` | `block_mined` | Evicts pending txs with: (1) nullifiers in mined block, (2) expired timestamp. |
158
+ | `InvalidTxsAfterReorgRule` | `chain_pruned` | Evicts txs with invalid anchor blocks after reorg. |
159
+
160
+ ## Usage
161
+
162
+ ### Creating a Pool
163
+
164
+ ```typescript
165
+ import { AztecKVTxPoolV2 } from './tx_pool_v2.js';
166
+
167
+ const pool = new AztecKVTxPoolV2(txStore, archiveStore, {
168
+ l2BlockSource: archiver,
169
+ worldStateSynchronizer: worldState,
170
+ createTxValidator: () => validator,
171
+ });
172
+
173
+ await pool.start();
174
+ ```
175
+
176
+ ### Adding Transactions
177
+
178
+ ```typescript
179
+ // Add to pending pool (validates and runs pre-add rules)
180
+ const result = await pool.addPendingTxs(txs, { source: 'gossip' });
181
+ // result: { accepted: TxHash[], ignored: TxHash[], rejected: TxHash[] }
182
+
183
+ // Check without modifying pool
184
+ const canAdd = await pool.canAddPendingTx(tx);
185
+ // canAdd: 'accepted' | 'ignored' | 'rejected'
186
+ ```
187
+
188
+ ### Block Building Flow
189
+
190
+ ```typescript
191
+ // 1. Proposer protects txs for their block
192
+ await pool.protectTxs(selectedTxHashes, blockHeader);
193
+
194
+ // 2. On successful mining
195
+ await pool.handleMinedBlock(minedTxHashes, blockHeader);
196
+
197
+ // 3. If slot passes without mining
198
+ await pool.prepareForSlot(nextSlotNumber);
199
+
200
+ // 4. On finalization
201
+ await pool.handleFinalizedBlock(finalizedBlockHeader);
202
+ ```
203
+
204
+ ### Handling Reorgs
205
+
206
+ ```typescript
207
+ // When blocks are pruned, un-mine affected transactions
208
+ await pool.handlePrunedBlocks(latestValidBlockId);
209
+ ```
210
+
211
+ ## Configuration
212
+
213
+ ```typescript
214
+ await pool.updateConfig({
215
+ maxPendingTxCount: 10000, // 0 = unlimited
216
+ archivedTxLimit: 1000, // 0 = disabled
217
+ });
218
+ ```
219
+
220
+ ## Return Values
221
+
222
+ ### AddTxsResult
223
+
224
+ When adding pending transactions, each tx is categorized:
225
+
226
+ | Status | Meaning |
227
+ |--------|---------|
228
+ | `accepted` | Successfully added to the pool |
229
+ | `ignored` | Valid but not added (duplicate, lost nullifier conflict, insufficient balance) |
230
+ | `rejected` | Failed validation (invalid proof, expired, etc.) |
231
+
232
+ ## Archive
233
+
234
+ Finalized transactions can optionally be archived for historical queries:
235
+
236
+ ```typescript
237
+ const archivedTx = await pool.getArchivedTxByHash(txHash);
238
+ ```
239
+
240
+ The archive uses FIFO eviction when `archivedTxLimit` is reached.
241
+
242
+ ## Testing
243
+
244
+ ```bash
245
+ # Unit tests (177 tests)
246
+ yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts
247
+
248
+ # Deleted pool tests (17 tests)
249
+ yarn test src/mem_pools/tx_pool_v2/deleted_pool.test.ts
250
+
251
+ # Compatibility tests (25 tests)
252
+ yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.compat.test.ts
253
+
254
+ # Eviction rule tests
255
+ yarn test src/mem_pools/tx_pool_v2/eviction/
256
+
257
+ # Benchmarks
258
+ yarn test src/mem_pools/tx_pool_v2/tx_pool_v2_bench.test.ts
259
+ ```
@@ -0,0 +1 @@
1
+ export { TxArchive } from './tx_archive.js';