@aztec/p2p 0.0.1-commit.03f7ef2 → 0.0.1-commit.0658669b3

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 (545) 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 +7 -6
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +41 -14
  7. package/dest/client/interface.d.ts +60 -34
  8. package/dest/client/interface.d.ts.map +1 -1
  9. package/dest/client/p2p_client.d.ts +46 -59
  10. package/dest/client/p2p_client.d.ts.map +1 -1
  11. package/dest/client/p2p_client.js +600 -313
  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 +38 -13
  19. package/dest/config.d.ts.map +1 -1
  20. package/dest/config.js +29 -18
  21. package/dest/errors/tx-pool.error.d.ts +8 -0
  22. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  23. package/dest/errors/tx-pool.error.js +9 -0
  24. package/dest/index.d.ts +2 -1
  25. package/dest/index.d.ts.map +1 -1
  26. package/dest/index.js +1 -0
  27. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +111 -76
  28. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
  30. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  31. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  32. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +527 -287
  33. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  34. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/index.js +1 -2
  36. package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
  37. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  38. package/dest/mem_pools/attestation_pool/mocks.js +16 -12
  39. package/dest/mem_pools/index.d.ts +3 -2
  40. package/dest/mem_pools/index.d.ts.map +1 -1
  41. package/dest/mem_pools/index.js +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts +3 -3
  43. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  44. package/dest/mem_pools/instrumentation.js +11 -18
  45. package/dest/mem_pools/interface.d.ts +5 -5
  46. package/dest/mem_pools/interface.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
  48. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +312 -336
  50. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
  51. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
  53. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
  54. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
  56. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  57. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  59. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  60. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  62. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  63. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
  65. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  66. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  68. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  69. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  71. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  72. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool/index.js +0 -1
  74. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  75. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool/priority.js +6 -1
  77. package/dest/mem_pools/tx_pool/tx_pool.d.ts +8 -4
  78. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +7 -7
  80. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  81. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  83. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  84. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  85. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  86. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  87. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  88. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
  92. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  93. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  94. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +93 -0
  95. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  96. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  97. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +95 -0
  98. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  99. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  100. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  101. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +174 -0
  102. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  103. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
  104. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  105. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  106. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
  107. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  108. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  109. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
  110. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  111. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  112. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
  113. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  114. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  115. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +73 -0
  116. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  117. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  118. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  119. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  120. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  121. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  122. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  123. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  124. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  125. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +211 -0
  126. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  127. package/dest/mem_pools/tx_pool_v2/interfaces.js +9 -0
  128. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +105 -0
  129. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  130. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +164 -0
  131. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  132. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  133. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  134. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
  135. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  136. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +355 -0
  137. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +60 -0
  138. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  139. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +161 -0
  140. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +77 -0
  141. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  142. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +891 -0
  143. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  144. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  145. package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
  146. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -7
  147. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  148. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
  149. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  150. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  151. package/dest/msg_validators/clock_tolerance.js +37 -0
  152. package/dest/msg_validators/index.d.ts +2 -2
  153. package/dest/msg_validators/index.d.ts.map +1 -1
  154. package/dest/msg_validators/index.js +1 -1
  155. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  156. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  157. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  158. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  159. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  160. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  161. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  162. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  163. package/dest/msg_validators/proposal_validator/index.js +3 -0
  164. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  165. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  166. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  167. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  168. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  169. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  170. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  171. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  172. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  173. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  174. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  175. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  176. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
  177. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  178. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  179. package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
  180. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  181. package/dest/msg_validators/tx_validator/data_validator.js +4 -1
  182. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
  183. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  184. package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
  185. package/dest/msg_validators/tx_validator/factory.d.ts +118 -5
  186. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  187. package/dest/msg_validators/tx_validator/factory.js +228 -57
  188. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  189. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  190. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  191. package/dest/msg_validators/tx_validator/gas_validator.d.ts +59 -3
  192. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  193. package/dest/msg_validators/tx_validator/gas_validator.js +84 -52
  194. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  195. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  196. package/dest/msg_validators/tx_validator/index.js +2 -0
  197. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
  198. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  199. package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
  200. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  201. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  202. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  203. package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
  204. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  205. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  206. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  207. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  208. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  209. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +22 -5
  210. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  211. package/dest/msg_validators/tx_validator/timestamp_validator.js +8 -8
  212. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  213. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  214. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  215. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
  216. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  217. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
  218. package/dest/services/data_store.d.ts +1 -1
  219. package/dest/services/data_store.d.ts.map +1 -1
  220. package/dest/services/data_store.js +10 -6
  221. package/dest/services/discv5/discV5_service.js +1 -1
  222. package/dest/services/dummy_service.d.ts +28 -4
  223. package/dest/services/dummy_service.d.ts.map +1 -1
  224. package/dest/services/dummy_service.js +49 -1
  225. package/dest/services/encoding.d.ts +2 -2
  226. package/dest/services/encoding.d.ts.map +1 -1
  227. package/dest/services/encoding.js +9 -7
  228. package/dest/services/gossipsub/index.d.ts +3 -0
  229. package/dest/services/gossipsub/index.d.ts.map +1 -0
  230. package/dest/services/gossipsub/index.js +2 -0
  231. package/dest/services/gossipsub/scoring.d.ts +21 -3
  232. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  233. package/dest/services/gossipsub/scoring.js +24 -7
  234. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  235. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  236. package/dest/services/gossipsub/topic_score_params.js +346 -0
  237. package/dest/services/index.d.ts +2 -1
  238. package/dest/services/index.d.ts.map +1 -1
  239. package/dest/services/index.js +1 -0
  240. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  241. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  242. package/dest/services/libp2p/instrumentation.js +30 -72
  243. package/dest/services/libp2p/libp2p_service.d.ts +111 -35
  244. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  245. package/dest/services/libp2p/libp2p_service.js +1019 -365
  246. package/dest/services/peer-manager/metrics.d.ts +7 -2
  247. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  248. package/dest/services/peer-manager/metrics.js +33 -21
  249. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  250. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  251. package/dest/services/peer-manager/peer_manager.js +2 -10
  252. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  253. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  254. package/dest/services/peer-manager/peer_scoring.js +32 -6
  255. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +48 -0
  256. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  257. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +539 -0
  258. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  259. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  260. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  261. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +46 -0
  262. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  263. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  264. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +34 -0
  265. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  266. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +130 -0
  267. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +60 -0
  268. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  269. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +173 -0
  270. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
  271. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  272. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
  273. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
  274. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  275. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
  276. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  277. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  278. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  279. package/dest/services/reqresp/constants.d.ts +12 -0
  280. package/dest/services/reqresp/constants.d.ts.map +1 -0
  281. package/dest/services/reqresp/constants.js +7 -0
  282. package/dest/services/reqresp/interface.d.ts +12 -1
  283. package/dest/services/reqresp/interface.d.ts.map +1 -1
  284. package/dest/services/reqresp/interface.js +15 -1
  285. package/dest/services/reqresp/metrics.d.ts +6 -5
  286. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  287. package/dest/services/reqresp/metrics.js +17 -21
  288. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
  289. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  290. package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
  291. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  292. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  293. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
  294. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +29 -6
  295. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  296. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +59 -13
  297. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  298. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  299. package/dest/services/reqresp/protocols/status.js +4 -1
  300. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  301. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  302. package/dest/services/reqresp/protocols/tx.js +20 -0
  303. package/dest/services/reqresp/reqresp.d.ts +6 -1
  304. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  305. package/dest/services/reqresp/reqresp.js +471 -50
  306. package/dest/services/service.d.ts +56 -4
  307. package/dest/services/service.d.ts.map +1 -1
  308. package/dest/services/tx_collection/config.d.ts +22 -1
  309. package/dest/services/tx_collection/config.d.ts.map +1 -1
  310. package/dest/services/tx_collection/config.js +55 -1
  311. package/dest/services/tx_collection/fast_tx_collection.d.ts +7 -4
  312. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  313. package/dest/services/tx_collection/fast_tx_collection.js +71 -44
  314. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  315. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  316. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  317. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  318. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  319. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  320. package/dest/services/tx_collection/index.d.ts +3 -1
  321. package/dest/services/tx_collection/index.d.ts.map +1 -1
  322. package/dest/services/tx_collection/index.js +2 -0
  323. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  324. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  325. package/dest/services/tx_collection/instrumentation.js +11 -13
  326. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  327. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  328. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  329. package/dest/services/tx_collection/proposal_tx_collector.d.ts +49 -0
  330. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
  331. package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
  332. package/dest/services/tx_collection/slow_tx_collection.d.ts +9 -5
  333. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  334. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  335. package/dest/services/tx_collection/tx_collection.d.ts +29 -16
  336. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  337. package/dest/services/tx_collection/tx_collection.js +79 -7
  338. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  339. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  340. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  341. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  342. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  343. package/dest/services/tx_collection/tx_source.js +19 -2
  344. package/dest/services/tx_file_store/config.d.ts +16 -0
  345. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  346. package/dest/services/tx_file_store/config.js +22 -0
  347. package/dest/services/tx_file_store/index.d.ts +4 -0
  348. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  349. package/dest/services/tx_file_store/index.js +3 -0
  350. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  351. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  352. package/dest/services/tx_file_store/instrumentation.js +29 -0
  353. package/dest/services/tx_file_store/tx_file_store.d.ts +48 -0
  354. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  355. package/dest/services/tx_file_store/tx_file_store.js +152 -0
  356. package/dest/services/tx_provider.d.ts +6 -6
  357. package/dest/services/tx_provider.d.ts.map +1 -1
  358. package/dest/services/tx_provider.js +12 -9
  359. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  360. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  361. package/dest/services/tx_provider_instrumentation.js +7 -20
  362. package/dest/test-helpers/index.d.ts +3 -1
  363. package/dest/test-helpers/index.d.ts.map +1 -1
  364. package/dest/test-helpers/index.js +2 -0
  365. package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
  366. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  367. package/dest/test-helpers/mock-pubsub.d.ts +29 -2
  368. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  369. package/dest/test-helpers/mock-pubsub.js +103 -2
  370. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  371. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  372. package/dest/test-helpers/reqresp-nodes.js +2 -1
  373. package/dest/test-helpers/test_tx_provider.d.ts +40 -0
  374. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  375. package/dest/test-helpers/test_tx_provider.js +41 -0
  376. package/dest/test-helpers/testbench-utils.d.ts +163 -0
  377. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  378. package/dest/test-helpers/testbench-utils.js +366 -0
  379. package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
  380. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  381. package/dest/testbench/p2p_client_testbench_worker.js +221 -126
  382. package/dest/testbench/worker_client_manager.d.ts +51 -6
  383. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  384. package/dest/testbench/worker_client_manager.js +226 -39
  385. package/dest/util.d.ts +2 -2
  386. package/dest/util.d.ts.map +1 -1
  387. package/package.json +16 -16
  388. package/src/bootstrap/bootstrap.ts +7 -4
  389. package/src/client/factory.ts +76 -24
  390. package/src/client/interface.ts +78 -35
  391. package/src/client/p2p_client.ts +263 -358
  392. package/src/client/test/tx_proposal_collector/README.md +227 -0
  393. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +346 -0
  394. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
  395. package/src/config.ts +57 -27
  396. package/src/errors/tx-pool.error.ts +12 -0
  397. package/src/index.ts +1 -0
  398. package/src/mem_pools/attestation_pool/attestation_pool.ts +510 -78
  399. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +612 -320
  400. package/src/mem_pools/attestation_pool/index.ts +9 -2
  401. package/src/mem_pools/attestation_pool/mocks.ts +20 -13
  402. package/src/mem_pools/index.ts +4 -1
  403. package/src/mem_pools/instrumentation.ts +19 -25
  404. package/src/mem_pools/interface.ts +4 -4
  405. package/src/mem_pools/tx_pool/README.md +270 -0
  406. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +360 -368
  407. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
  408. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
  409. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  410. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  411. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
  412. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  413. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  414. package/src/mem_pools/tx_pool/index.ts +0 -1
  415. package/src/mem_pools/tx_pool/priority.ts +8 -1
  416. package/src/mem_pools/tx_pool/tx_pool.ts +8 -3
  417. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +7 -7
  418. package/src/mem_pools/tx_pool_v2/README.md +275 -0
  419. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  420. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  421. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  422. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
  423. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +121 -0
  424. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +122 -0
  425. package/src/mem_pools/tx_pool_v2/eviction/index.ts +27 -0
  426. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +209 -0
  427. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  428. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  429. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
  430. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +90 -0
  431. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  432. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  433. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  434. package/src/mem_pools/tx_pool_v2/interfaces.ts +242 -0
  435. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +255 -0
  436. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  437. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +444 -0
  438. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +223 -0
  439. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1063 -0
  440. package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
  441. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +21 -18
  442. package/src/msg_validators/clock_tolerance.ts +51 -0
  443. package/src/msg_validators/index.ts +1 -1
  444. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  445. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  446. package/src/msg_validators/proposal_validator/index.ts +3 -0
  447. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  448. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  449. package/src/msg_validators/tx_validator/README.md +115 -0
  450. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  451. package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
  452. package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
  453. package/src/msg_validators/tx_validator/data_validator.ts +18 -6
  454. package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
  455. package/src/msg_validators/tx_validator/factory.ts +372 -55
  456. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  457. package/src/msg_validators/tx_validator/gas_validator.ts +106 -54
  458. package/src/msg_validators/tx_validator/index.ts +2 -0
  459. package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
  460. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  461. package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
  462. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  463. package/src/msg_validators/tx_validator/timestamp_validator.ts +29 -19
  464. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  465. package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
  466. package/src/services/data_store.ts +10 -7
  467. package/src/services/discv5/discV5_service.ts +1 -1
  468. package/src/services/dummy_service.ts +65 -2
  469. package/src/services/encoding.ts +8 -6
  470. package/src/services/gossipsub/README.md +641 -0
  471. package/src/services/gossipsub/index.ts +2 -0
  472. package/src/services/gossipsub/scoring.ts +29 -5
  473. package/src/services/gossipsub/topic_score_params.ts +487 -0
  474. package/src/services/index.ts +1 -0
  475. package/src/services/libp2p/instrumentation.ts +32 -73
  476. package/src/services/libp2p/libp2p_service.ts +705 -364
  477. package/src/services/peer-manager/metrics.ts +39 -21
  478. package/src/services/peer-manager/peer_manager.ts +3 -2
  479. package/src/services/peer-manager/peer_scoring.ts +28 -4
  480. package/src/services/reqresp/batch-tx-requester/README.md +305 -0
  481. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +678 -0
  482. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  483. package/src/services/reqresp/batch-tx-requester/interface.ts +53 -0
  484. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +161 -0
  485. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +244 -0
  486. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
  487. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
  488. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  489. package/src/services/reqresp/constants.ts +14 -0
  490. package/src/services/reqresp/interface.ts +29 -1
  491. package/src/services/reqresp/metrics.ts +36 -27
  492. package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
  493. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +35 -12
  494. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +74 -9
  495. package/src/services/reqresp/protocols/status.ts +7 -4
  496. package/src/services/reqresp/protocols/tx.ts +22 -0
  497. package/src/services/reqresp/reqresp.ts +79 -22
  498. package/src/services/service.ts +73 -5
  499. package/src/services/tx_collection/config.ts +83 -1
  500. package/src/services/tx_collection/fast_tx_collection.ts +93 -47
  501. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  502. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  503. package/src/services/tx_collection/index.ts +6 -0
  504. package/src/services/tx_collection/instrumentation.ts +11 -13
  505. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  506. package/src/services/tx_collection/proposal_tx_collector.ts +113 -0
  507. package/src/services/tx_collection/slow_tx_collection.ts +68 -35
  508. package/src/services/tx_collection/tx_collection.ts +121 -24
  509. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  510. package/src/services/tx_collection/tx_source.ts +22 -3
  511. package/src/services/tx_file_store/config.ts +37 -0
  512. package/src/services/tx_file_store/index.ts +3 -0
  513. package/src/services/tx_file_store/instrumentation.ts +36 -0
  514. package/src/services/tx_file_store/tx_file_store.ts +175 -0
  515. package/src/services/tx_provider.ts +16 -12
  516. package/src/services/tx_provider_instrumentation.ts +13 -20
  517. package/src/test-helpers/index.ts +2 -0
  518. package/src/test-helpers/make-test-p2p-clients.ts +3 -3
  519. package/src/test-helpers/mock-pubsub.ts +143 -3
  520. package/src/test-helpers/reqresp-nodes.ts +2 -1
  521. package/src/test-helpers/test_tx_provider.ts +64 -0
  522. package/src/test-helpers/testbench-utils.ts +430 -0
  523. package/src/testbench/p2p_client_testbench_worker.ts +348 -122
  524. package/src/testbench/worker_client_manager.ts +304 -42
  525. package/src/util.ts +7 -1
  526. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -37
  527. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  528. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -213
  529. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -30
  530. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  531. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -219
  532. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
  533. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  534. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -242
  535. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  536. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  537. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  538. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  539. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  540. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  541. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -298
  542. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -287
  543. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -288
  544. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  545. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,39 +1,42 @@
1
+ import { insertIntoSortedArray } from '@aztec/foundation/array';
1
2
  import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { toArray } from '@aztec/foundation/iterable';
3
4
  import { createLogger } from '@aztec/foundation/log';
4
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
- import { GasFees } from '@aztec/stdlib/gas';
5
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
6
  import { ChonkProof } from '@aztec/stdlib/proofs';
7
- import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
8
7
  import { Tx, TxHash } from '@aztec/stdlib/tx';
9
8
  import { getTelemetryClient } from '@aztec/telemetry-client';
10
9
  import assert from 'assert';
11
10
  import EventEmitter from 'node:events';
12
11
  import { ArchiveCache } from '../../msg_validators/tx_validator/archive_cache.js';
13
- import { GasTxValidator } from '../../msg_validators/tx_validator/gas_validator.js';
14
12
  import { PoolInstrumentation, PoolName } from '../instrumentation.js';
13
+ import { EvictionManager } from './eviction/eviction_manager.js';
14
+ import { FeePayerTxInfo } from './eviction/eviction_strategy.js';
15
+ import { FeePayerBalanceEvictionRule } from './eviction/fee_payer_balance_eviction_rule.js';
16
+ import { InvalidTxsAfterMiningRule } from './eviction/invalid_txs_after_mining_rule.js';
17
+ import { InvalidTxsAfterReorgRule } from './eviction/invalid_txs_after_reorg_rule.js';
18
+ import { LowPriorityEvictionRule } from './eviction/low_priority_eviction_rule.js';
19
+ import { NullifierConflictPreAddRule } from './eviction/nullifier_conflict_pre_add_rule.js';
15
20
  import { getPendingTxPriority } from './priority.js';
16
21
  /**
17
22
  * KV implementation of the Transaction Pool.
18
23
  */ export class AztecKVTxPool extends EventEmitter {
19
24
  #store;
20
25
  /** Our tx pool, stored as a Map, with K: tx hash and V: the transaction. */ #txs;
21
- /** The maximum cumulative tx size that the pending txs in the pool take up. */ #maxTxPoolSize = 0;
22
- /** The tx evicion logic will kick after pool size is greater than maxTxPoolSize * txPoolOverflowFactor */ txPoolOverflowFactor = 1;
26
+ /** Holds the historical block for each tx */ #pendingTxHashToHistoricalBlockHeaderHash;
23
27
  /** Index from tx hash to the block number in which they were mined, filtered by mined txs. */ #minedTxHashToBlock;
24
28
  /** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */ #pendingTxPriorityToHash;
25
- /** Index from tx hash to its tx size (in bytes), filtered by pending txs. */ #pendingTxHashToSize;
26
- /** Index from tx hash to its header hash, filtered by pending txs. */ #pendingTxHashToHeaderHash;
27
29
  /** Map from tx hash to the block number it was originally mined in (for soft-deleted txs). */ #deletedMinedTxHashes;
28
30
  /** MultiMap from block number to deleted mined tx hashes for efficient cleanup. */ #blockToDeletedMinedTxHash;
29
- /** The cumulative tx size in bytes that the pending txs in the pool take up. */ #pendingTxSize;
30
- /** In-memory mapping of pending tx hashes to the hydrated pending tx in the pool. */ #pendingTxs;
31
+ #historicalHeaderToTxHash;
32
+ #feePayerToBalanceEntry;
33
+ /** Index from nullifier to pending tx hash */ #pendingNullifierToTxHash;
31
34
  /** In-memory set of txs that should not be evicted from the pool. */ #nonEvictableTxs;
32
35
  /** KV store for archived txs. */ #archive;
33
36
  /** Archived txs map for future lookup. */ #archivedTxs;
34
37
  /** Indexes of the archived txs by insertion order. */ #archivedTxIndices;
35
38
  /** Number of txs to archive. */ #archivedTxLimit = 0;
36
- /** The world state synchronizer used in the node. */ #worldStateSynchronizer;
39
+ #evictionManager;
37
40
  #log;
38
41
  #metrics;
39
42
  /**
@@ -43,25 +46,33 @@ import { getPendingTxPriority } from './priority.js';
43
46
  * @param telemetry - A telemetry client.
44
47
  * @param archivedTxLimit - The number of txs to archive.
45
48
  * @param log - A logger.
46
- */ constructor(store, archive, worldStateSynchronizer, telemetry = getTelemetryClient(), config = {}, log = createLogger('p2p:tx_pool')){
49
+ */ constructor(store, archive, worldState, telemetry = getTelemetryClient(), config = {}, log = createLogger('p2p:tx_pool')){
47
50
  super();
48
51
  this.#log = log;
52
+ this.#evictionManager = new EvictionManager(this);
53
+ this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
54
+ this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(worldState));
55
+ this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(worldState));
56
+ this.#evictionManager.registerRule(new LowPriorityEvictionRule({
57
+ //NOTE: 0 effectively disables low priority eviction
58
+ maxPoolSize: config.maxPendingTxCount ?? 0
59
+ }));
60
+ this.#evictionManager.registerPreAddRule(new NullifierConflictPreAddRule());
49
61
  this.updateConfig(config);
50
62
  this.#txs = store.openMap('txs');
51
63
  this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
52
64
  this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
53
- this.#pendingTxHashToSize = store.openMap('pendingTxHashToSize');
54
- this.#pendingTxHashToHeaderHash = store.openMap('pendingTxHashToHeaderHash');
55
- this.#pendingTxSize = store.openSingleton('pendingTxSize');
56
65
  this.#deletedMinedTxHashes = store.openMap('deletedMinedTxHashes');
57
66
  this.#blockToDeletedMinedTxHash = store.openMultiMap('blockToDeletedMinedTxHash');
58
- this.#pendingTxs = new Map();
67
+ this.#pendingTxHashToHistoricalBlockHeaderHash = store.openMap('txHistoricalBlock');
68
+ this.#historicalHeaderToTxHash = store.openMultiMap('historicalHeaderToPendingTxHash');
69
+ this.#feePayerToBalanceEntry = store.openMultiMap('feePayerToBalanceEntry');
70
+ this.#pendingNullifierToTxHash = store.openMap('pendingNullifierToTxHash');
59
71
  this.#nonEvictableTxs = new Set();
60
72
  this.#archivedTxs = archive.openMap('archivedTxs');
61
73
  this.#archivedTxIndices = archive.openMap('archivedTxIndices');
62
74
  this.#store = store;
63
75
  this.#archive = archive;
64
- this.#worldStateSynchronizer = worldStateSynchronizer;
65
76
  this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, this.countTxs, ()=>store.estimateSize());
66
77
  }
67
78
  countTxs = async ()=>{
@@ -92,60 +103,68 @@ import { getPendingTxPriority } from './priority.js';
92
103
  if (txHashes.length === 0) {
93
104
  return Promise.resolve();
94
105
  }
95
- const minedNullifiers = new Set();
96
- const minedFeePayers = new Set();
97
- await this.#store.transactionAsync(async ()=>{
98
- let pendingTxSize = await this.#pendingTxSize.getAsync() ?? 0;
99
- for (const hash of txHashes){
100
- const key = hash.toString();
101
- // If this tx was previously soft-deleted, remove it from the deleted sets
102
- if (await this.#deletedMinedTxHashes.hasAsync(key)) {
103
- const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
104
- await this.#deletedMinedTxHashes.delete(key);
105
- // Remove from block-to-hash mapping
106
- if (originalBlock !== undefined) {
107
- await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
106
+ const uniqueMinedNullifiers = [];
107
+ const uniqueMinedFeePayers = [];
108
+ try {
109
+ await this.#store.transactionAsync(async ()=>{
110
+ for (const hash of txHashes){
111
+ const key = hash.toString();
112
+ await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
113
+ const tx = await this.getTxByHash(hash);
114
+ if (tx) {
115
+ const nullifiers = tx.data.getNonEmptyNullifiers();
116
+ nullifiers.forEach((nullifier)=>insertIntoSortedArray(uniqueMinedNullifiers, nullifier, Fr.cmp, false));
117
+ insertIntoSortedArray(uniqueMinedFeePayers, tx.data.feePayer, (a, b)=>a.toField().cmp(b.toField()), false);
118
+ await this.removePendingTxIndicesInDbTx(tx, key);
119
+ }
120
+ // If this tx was previously soft-deleted, remove it from the deleted sets
121
+ if (await this.#deletedMinedTxHashes.hasAsync(key)) {
122
+ const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
123
+ await this.#deletedMinedTxHashes.delete(key);
124
+ // Remove from block-to-hash mapping
125
+ if (originalBlock !== undefined) {
126
+ await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
127
+ }
108
128
  }
109
129
  }
110
- await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
111
- const tx = await this.getPendingTxByHash(hash);
112
- if (tx) {
113
- const nullifiers = tx.data.getNonEmptyNullifiers();
114
- nullifiers.forEach((nullifier)=>minedNullifiers.add(nullifier.toString()));
115
- minedFeePayers.add(tx.data.feePayer.toString());
116
- pendingTxSize -= tx.getSize();
117
- await this.removePendingTxIndices(tx, key);
118
- }
119
- }
120
- await this.#pendingTxSize.set(pendingTxSize);
121
- await this.evictInvalidTxsAfterMining(txHashes, blockHeader, minedNullifiers, minedFeePayers);
122
- });
123
- this.#metrics.transactionsRemoved(txHashes);
124
- // We update this after the transaction above. This ensures that the non-evictable transactions are not evicted
125
- // until any that have been mined are marked as such.
126
- // The non-evictable set is not considered when evicting transactions that are invalid after a block is mined.
127
- this.#nonEvictableTxs.clear();
130
+ });
131
+ await this.#evictionManager.evictAfterNewBlock(blockHeader, uniqueMinedNullifiers, uniqueMinedFeePayers);
132
+ this.#metrics.transactionsRemoved(txHashes.map((hash)=>hash.toBigInt()));
133
+ } catch (err) {
134
+ this.#log.warn('Unexpected error when marking txs as mined', {
135
+ err
136
+ });
137
+ }
128
138
  }
129
- async markMinedAsPending(txHashes) {
139
+ async markMinedAsPending(txHashes, latestBlock) {
130
140
  if (txHashes.length === 0) {
131
141
  return Promise.resolve();
132
142
  }
133
- await this.#store.transactionAsync(async ()=>{
134
- let pendingTxSize = await this.#pendingTxSize.getAsync() ?? 0;
135
- for (const hash of txHashes){
136
- const key = hash.toString();
137
- await this.#minedTxHashToBlock.delete(key);
138
- // Rehydrate the tx in the in-memory pending txs mapping
139
- const tx = await this.getPendingTxByHash(hash);
140
- if (tx) {
141
- await this.addPendingTxIndices(tx, key);
142
- pendingTxSize += tx.getSize();
143
+ try {
144
+ await this.#store.transactionAsync(async ()=>{
145
+ for (const hash of txHashes){
146
+ const key = hash.toString();
147
+ await this.#minedTxHashToBlock.delete(key);
148
+ // Clear soft-delete metadata if this tx was previously soft-deleted,
149
+ // so cleanupDeletedMinedTxs won't later hard-delete it while it's pending
150
+ const deletedBlock = await this.#deletedMinedTxHashes.getAsync(key);
151
+ if (deletedBlock !== undefined) {
152
+ await this.#deletedMinedTxHashes.delete(key);
153
+ await this.#blockToDeletedMinedTxHash.deleteValue(deletedBlock, key);
154
+ }
155
+ // Rehydrate the tx in the in-memory pending txs mapping
156
+ const tx = await this.getTxByHash(hash);
157
+ if (tx) {
158
+ await this.addPendingTxIndicesInDbTx(tx, key);
159
+ }
143
160
  }
144
- }
145
- await this.#pendingTxSize.set(pendingTxSize);
146
- });
147
- await this.evictInvalidTxsAfterReorg(txHashes);
148
- await this.evictLowPriorityTxs(txHashes);
161
+ });
162
+ await this.#evictionManager.evictAfterChainPrune(latestBlock);
163
+ } catch (err) {
164
+ this.#log.warn('Unexpected error when marking mined txs as pending', {
165
+ err
166
+ });
167
+ }
149
168
  }
150
169
  async getPendingTxHashes() {
151
170
  const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({
@@ -153,36 +172,6 @@ import { getPendingTxPriority } from './priority.js';
153
172
  }));
154
173
  return vals.map(TxHash.fromString);
155
174
  }
156
- async getMinedTxHashes() {
157
- const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
158
- return vals.map(([txHash, blockNumber])=>[
159
- TxHash.fromString(txHash),
160
- blockNumber
161
- ]);
162
- }
163
- async getPendingTxCount() {
164
- return await this.#pendingTxHashToHeaderHash.sizeAsync() ?? 0;
165
- }
166
- async getMinedTxCount() {
167
- return await this.#minedTxHashToBlock.sizeAsync() ?? 0;
168
- }
169
- async getTxStatus(txHash) {
170
- const key = txHash.toString();
171
- const [isMined, isKnown, isDeleted] = await Promise.all([
172
- this.#minedTxHashToBlock.hasAsync(key),
173
- this.#txs.hasAsync(key),
174
- this.#deletedMinedTxHashes.hasAsync(key)
175
- ]);
176
- if (isDeleted) {
177
- return 'deleted';
178
- } else if (isMined) {
179
- return 'mined';
180
- } else if (isKnown) {
181
- return 'pending';
182
- } else {
183
- return undefined;
184
- }
185
- }
186
175
  /**
187
176
  * Checks if a transaction exists in the pool and returns it.
188
177
  * @param txHash - The generated tx hash.
@@ -214,38 +203,68 @@ import { getPendingTxPriority } from './priority.js';
214
203
  }
215
204
  /**
216
205
  * Adds a list of transactions to the pool. Duplicates are ignored.
206
+ * Handles nullifier deduplication: if an incoming tx has a nullifier conflict with
207
+ * existing pending txs, it will either replace them (if higher fee) or be rejected.
217
208
  * @param txs - An array of txs to be added to the pool.
218
- * @returns Empty promise.
209
+ * @returns count of added transactions
219
210
  */ async addTxs(txs, opts = {}) {
211
+ if (txs.length === 0) {
212
+ return Promise.resolve(0);
213
+ }
220
214
  const addedTxs = [];
215
+ const uniqueFeePayers = [];
216
+ const replacedTxHashes = [];
221
217
  const hashesAndStats = txs.map((tx)=>({
222
218
  txHash: tx.getTxHash(),
223
219
  txStats: tx.getStats()
224
220
  }));
225
- await this.#store.transactionAsync(async ()=>{
226
- let pendingTxSize = await this.#pendingTxSize.getAsync() ?? 0;
227
- await Promise.all(txs.map(async (tx, i)=>{
228
- const { txHash, txStats } = hashesAndStats[i];
229
- const key = txHash.toString();
230
- if (await this.#txs.hasAsync(key)) {
231
- this.#log.debug(`Tx ${txHash.toString()} already exists in the pool`);
232
- return;
233
- }
234
- this.#log.verbose(`Adding tx ${txHash.toString()} to pool`, {
235
- eventName: 'tx-added-to-pool',
236
- ...txStats
237
- });
238
- await this.#txs.set(key, tx.toBuffer());
239
- addedTxs.push(tx);
240
- if (!await this.#minedTxHashToBlock.hasAsync(key)) {
241
- pendingTxSize += tx.getSize();
242
- await this.addPendingTxIndices(tx, key);
243
- this.#metrics.recordSize(tx);
221
+ try {
222
+ await this.#store.transactionAsync(async ()=>{
223
+ for(let i = 0; i < txs.length; i++){
224
+ const tx = txs[i];
225
+ const { txHash, txStats } = hashesAndStats[i];
226
+ const key = txHash.toString();
227
+ if (await this.#txs.hasAsync(key)) {
228
+ this.#log.debug(`Tx ${key} already exists in the pool`);
229
+ continue;
230
+ }
231
+ const poolAccess = this.getPreAddPoolAccess();
232
+ const { shouldReject, txHashesToEvict } = await this.#evictionManager.runPreAddRules(tx, poolAccess);
233
+ if (shouldReject) {
234
+ continue;
235
+ }
236
+ for (const txHashToEvict of txHashesToEvict){
237
+ const txToDelete = await this.getTxByHash(txHashToEvict);
238
+ if (txToDelete) {
239
+ const evictedKey = txHashToEvict.toString();
240
+ await this.deletePendingTxInDbTx(txToDelete, evictedKey);
241
+ replacedTxHashes.push(txHashToEvict);
242
+ this.#log.verbose(`Evicted tx ${evictedKey} due to higher-fee tx ${key}`);
243
+ }
244
+ }
245
+ this.#log.verbose(`Adding tx ${key} to pool`, {
246
+ eventName: 'tx-added-to-pool',
247
+ ...txStats
248
+ });
249
+ await this.#txs.set(key, tx.toBuffer());
250
+ addedTxs.push(tx);
251
+ insertIntoSortedArray(uniqueFeePayers, tx.data.feePayer, (a, b)=>a.toField().cmp(b.toField()), false);
252
+ await this.#pendingTxHashToHistoricalBlockHeaderHash.set(key, (await tx.data.constants.anchorBlockHeader.hash()).toString());
253
+ if (!await this.#minedTxHashToBlock.hasAsync(key)) {
254
+ await this.addPendingTxIndicesInDbTx(tx, key);
255
+ this.#metrics.recordSize(tx);
256
+ }
244
257
  }
245
- }));
246
- await this.#pendingTxSize.set(pendingTxSize);
247
- await this.evictLowPriorityTxs(hashesAndStats.map(({ txHash })=>txHash));
248
- });
258
+ });
259
+ await this.#evictionManager.evictAfterNewTxs(addedTxs.map(({ txHash })=>txHash), uniqueFeePayers);
260
+ } catch (err) {
261
+ this.#log.warn('Unexpected error when adding txs', {
262
+ err
263
+ });
264
+ }
265
+ if (replacedTxHashes.length > 0) {
266
+ this.#metrics.transactionsRemoved(replacedTxHashes.map((hash)=>hash.toBigInt()));
267
+ }
249
268
  if (addedTxs.length > 0) {
250
269
  this.#metrics.transactionsAdded(addedTxs);
251
270
  this.emit('txs-added', {
@@ -260,52 +279,58 @@ import { getPendingTxPriority } from './priority.js';
260
279
  * Mined transactions are soft-deleted with a timestamp, pending transactions are permanently deleted.
261
280
  * @param txHashes - An array of tx hashes to be deleted from the tx pool.
262
281
  * @returns Empty promise.
263
- */ deleteTxs(txHashes, opts = {}) {
282
+ */ deleteTxs(txHashes, opts) {
264
283
  if (txHashes.length === 0) {
265
284
  return Promise.resolve();
266
285
  }
267
286
  const deletedTxs = [];
268
287
  const poolDbTx = this.#store.transactionAsync(async ()=>{
269
- let pendingTxSize = await this.#pendingTxSize.getAsync() ?? 0;
270
288
  for (const hash of txHashes){
271
289
  const key = hash.toString();
272
290
  const tx = await this.getTxByHash(hash);
273
- if (tx) {
274
- const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
275
- if (minedBlockNumber !== undefined) {
276
- await this.#minedTxHashToBlock.delete(key);
277
- if (opts.permanently) {
278
- // Permanently delete mined transactions if specified
279
- this.#log.trace(`Deleting mined tx ${key} from pool`);
280
- await this.#txs.delete(key);
281
- } else {
282
- // Soft-delete mined transactions: remove from mined set but keep in storage
283
- this.#log.trace(`Soft-deleting mined tx ${key} from pool`);
284
- await this.#deletedMinedTxHashes.set(key, minedBlockNumber);
285
- await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, key);
286
- }
287
- } else {
288
- // Permanently delete pending transactions
289
- this.#log.trace(`Deleting pending tx ${key} from pool`);
290
- pendingTxSize -= tx.getSize();
291
- await this.removePendingTxIndices(tx, key);
292
- await this.#txs.delete(key);
293
- }
294
- if (!opts.eviction && this.#archivedTxLimit) {
291
+ if (!tx) {
292
+ this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
293
+ continue;
294
+ }
295
+ const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
296
+ const txIsPending = minedBlockNumber === undefined;
297
+ if (txIsPending) {
298
+ await this.deletePendingTxInDbTx(tx, key);
299
+ } else {
300
+ await this.deleteMinedTx(key, minedBlockNumber, opts?.permanently ?? false);
301
+ const shouldArchiveTx = this.#archivedTxLimit && !opts?.permanently;
302
+ if (shouldArchiveTx) {
295
303
  deletedTxs.push(tx);
296
304
  }
297
- } else {
298
- this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
299
305
  }
300
306
  }
301
- await this.#pendingTxSize.set(pendingTxSize);
302
307
  });
303
- this.#metrics.transactionsRemoved(txHashes);
308
+ this.#metrics.transactionsRemoved(txHashes.map((hash)=>hash.toBigInt()));
304
309
  this.#log.debug(`Deleted ${txHashes.length} txs from pool`, {
305
310
  txHashes
306
311
  });
307
312
  return this.#archivedTxLimit ? poolDbTx.then(()=>this.archiveTxs(deletedTxs)) : poolDbTx;
308
313
  }
314
+ async deleteMinedTx(txHash, minedBlockNumber, permanently) {
315
+ await this.#minedTxHashToBlock.delete(txHash);
316
+ if (permanently) {
317
+ this.#log.trace(`Deleting mined tx ${txHash} from pool`);
318
+ await this.#txs.delete(txHash);
319
+ return;
320
+ }
321
+ // Soft-delete mined transactions: remove from mined set but keep in storage
322
+ this.#log.trace(`Soft-deleting mined tx ${txHash} from pool`);
323
+ await this.#deletedMinedTxHashes.set(txHash, minedBlockNumber);
324
+ await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, txHash);
325
+ }
326
+ // Assumes being called within a DB transaction
327
+ async deletePendingTxInDbTx(tx, txHash) {
328
+ // We always permanently delete pending transactions
329
+ this.#log.trace(`Deleting pending tx ${txHash} from pool`);
330
+ await this.removePendingTxIndicesInDbTx(tx, txHash);
331
+ await this.#txs.delete(txHash);
332
+ await this.#pendingTxHashToHistoricalBlockHeaderHash.delete(txHash);
333
+ }
309
334
  /**
310
335
  * Gets all the transactions stored in the pool.
311
336
  * @returns Array of tx objects in the order they were added to the pool.
@@ -320,45 +345,116 @@ import { getPendingTxPriority } from './priority.js';
320
345
  const vals = await toArray(this.#txs.keysAsync());
321
346
  return vals.map((x)=>TxHash.fromString(x));
322
347
  }
323
- updateConfig({ maxTxPoolSize, txPoolOverflowFactor, archivedTxLimit }) {
324
- if (typeof maxTxPoolSize === 'number') {
325
- assert(maxTxPoolSize >= 0, 'maxTxPoolSize must be greater or equal to 0');
326
- this.#maxTxPoolSize = maxTxPoolSize;
327
- if (maxTxPoolSize === 0) {
328
- this.#log.info(`Disabling maximum tx mempool size. Tx eviction stopped`);
329
- } else {
330
- this.#log.info(`Setting maximum tx mempool size`, {
331
- maxTxPoolSize
332
- });
348
+ async getPendingTxInfos() {
349
+ const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync());
350
+ const results = await Promise.all(vals.map((val)=>this.getPendingTxInfo(TxHash.fromString(val))));
351
+ return results.filter((info)=>info !== undefined);
352
+ }
353
+ async getPendingTxInfo(txHash) {
354
+ let historicalBlockHash = await this.#pendingTxHashToHistoricalBlockHeaderHash.getAsync(txHash.toString());
355
+ // Not all tx might have this index created.
356
+ if (!historicalBlockHash) {
357
+ const tx = await this.getTxByHash(txHash);
358
+ if (!tx) {
359
+ this.#log.warn(`PendingTxInfo:tx ${txHash} not found`);
360
+ return undefined;
333
361
  }
362
+ historicalBlockHash = (await tx.data.constants.anchorBlockHeader.hash()).toString();
363
+ await this.#pendingTxHashToHistoricalBlockHeaderHash.set(txHash.toString(), historicalBlockHash);
334
364
  }
335
- if (typeof txPoolOverflowFactor === 'number') {
336
- assert(txPoolOverflowFactor >= 1, 'txPoolOveflowFactor must be greater or equal to 1');
337
- this.txPoolOverflowFactor = txPoolOverflowFactor;
338
- this.#log.info(`Allowing tx pool size to grow above limit`, {
339
- maxTxPoolSize,
340
- txPoolOverflowFactor
341
- });
365
+ return {
366
+ txHash,
367
+ blockHash: Fr.fromString(historicalBlockHash),
368
+ isEvictable: !this.#nonEvictableTxs.has(txHash.toString())
369
+ };
370
+ }
371
+ async getPendingTxsReferencingBlocks(blockHashes) {
372
+ const result = [];
373
+ for (const blockHash of blockHashes){
374
+ const chunk = await toArray(this.#historicalHeaderToTxHash.getValuesAsync(blockHash.toString()));
375
+ result.push(...chunk.map((txHash)=>({
376
+ txHash: TxHash.fromString(txHash),
377
+ blockHash,
378
+ isEvictable: !this.#nonEvictableTxs.has(txHash)
379
+ })));
342
380
  }
343
- if (typeof archivedTxLimit === 'number') {
344
- assert(archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
345
- this.#archivedTxLimit = archivedTxLimit;
381
+ return result;
382
+ }
383
+ async getPendingFeePayers() {
384
+ const feePayers = [];
385
+ for await (const feePayer of this.#feePayerToBalanceEntry.keysAsync()){
386
+ const address = AztecAddress.fromString(feePayer);
387
+ insertIntoSortedArray(feePayers, address, (a, b)=>a.toField().cmp(b.toField()), false);
388
+ }
389
+ return feePayers;
390
+ }
391
+ async *getFeePayerTxInfos(feePayer) {
392
+ for await (const value of this.#feePayerToBalanceEntry.getValuesAsync(feePayer.toString())){
393
+ const info = FeePayerTxInfo.decode(value);
394
+ info.isEvictable = !this.#nonEvictableTxs.has(info.txHash.toString());
395
+ yield info;
396
+ }
397
+ }
398
+ async getMinedTxHashes() {
399
+ const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
400
+ return vals.map(([txHash, blockNumber])=>[
401
+ TxHash.fromString(txHash),
402
+ blockNumber
403
+ ]);
404
+ }
405
+ async getPendingTxCount() {
406
+ return await this.#pendingTxPriorityToHash.sizeAsync() ?? 0;
407
+ }
408
+ async getMinedTxCount() {
409
+ return await this.#minedTxHashToBlock.sizeAsync() ?? 0;
410
+ }
411
+ async getTxStatus(txHash) {
412
+ const key = txHash.toString();
413
+ const [isMined, isKnown, isDeleted] = await Promise.all([
414
+ this.#minedTxHashToBlock.hasAsync(key),
415
+ this.#txs.hasAsync(key),
416
+ this.#deletedMinedTxHashes.hasAsync(key)
417
+ ]);
418
+ if (isDeleted) {
419
+ return 'deleted';
420
+ } else if (isMined) {
421
+ return 'mined';
422
+ } else if (isKnown) {
423
+ return 'pending';
424
+ } else {
425
+ return undefined;
426
+ }
427
+ }
428
+ updateConfig(cfg) {
429
+ if (typeof cfg.archivedTxLimit === 'number') {
430
+ assert(cfg.archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
431
+ this.#archivedTxLimit = cfg.archivedTxLimit;
432
+ }
433
+ if (this.#evictionManager) {
434
+ this.#evictionManager.updateConfig(cfg);
346
435
  }
347
- // deletedMinedCleanupThresholdMs is no longer used in block-based cleanup
348
436
  }
349
437
  markTxsAsNonEvictable(txHashes) {
350
438
  txHashes.forEach((txHash)=>this.#nonEvictableTxs.add(txHash.toString()));
351
439
  return Promise.resolve();
352
440
  }
441
+ clearNonEvictableTxs() {
442
+ // Clear the non-evictable set after completing the DB updates above.
443
+ // This ensures pinned (non-evictable) txs are protected while we mark mined txs,
444
+ // but they won't remain pinned indefinitely across blocks. Note that eviction rules
445
+ // (including post-mining invalidation) respect the non-evictable flag while it is set.
446
+ this.#nonEvictableTxs.clear();
447
+ return Promise.resolve();
448
+ }
353
449
  /**
354
450
  * Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
355
451
  * @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
356
452
  * @returns The number of transactions permanently deleted.
357
453
  */ async cleanupDeletedMinedTxs(blockNumber) {
358
454
  let deletedCount = 0;
359
- const txHashesToDelete = [];
360
- const blocksToDelete = [];
361
455
  await this.#store.transactionAsync(async ()=>{
456
+ const txHashesToDelete = [];
457
+ const blocksToDelete = [];
362
458
  // Iterate through all entries and check block numbers
363
459
  for await (const [block, txHash] of this.#blockToDeletedMinedTxHash.entriesAsync()){
364
460
  if (block <= blockNumber) {
@@ -372,6 +468,7 @@ import { getPendingTxPriority } from './priority.js';
372
468
  deletedCount++;
373
469
  }
374
470
  }
471
+ this.#metrics.transactionsRemoved(txHashesToDelete);
375
472
  // Clean up block-to-hash mapping - delete all values for each block
376
473
  for (const block of blocksToDelete){
377
474
  const txHashesForBlock = await toArray(this.#blockToDeletedMinedTxHash.getValuesAsync(block));
@@ -386,13 +483,6 @@ import { getPendingTxPriority } from './priority.js';
386
483
  return deletedCount;
387
484
  }
388
485
  /**
389
- * Creates a GasTxValidator instance.
390
- * @param db - DB for the validator to use
391
- * @returns A GasTxValidator instance
392
- */ createGasTxValidator(db) {
393
- return new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, GasFees.empty());
394
- }
395
- /**
396
486
  * Creates an ArchiveCache instance.
397
487
  * @param db - DB for the cache to use
398
488
  * @returns An ArchiveCache instance
@@ -400,36 +490,17 @@ import { getPendingTxPriority } from './priority.js';
400
490
  return new ArchiveCache(db);
401
491
  }
402
492
  /**
403
- * Checks if a cached transaction exists in the in-memory pending tx pool and returns it.
404
- * Otherwise, it checks the tx pool, updates the pending tx pool, and returns the tx.
405
- * @param txHash - The generated tx hash.
406
- * @returns The transaction, if found, 'undefined' otherwise.
407
- */ async getPendingTxByHash(txHash) {
408
- let key;
409
- if (typeof txHash === 'string') {
410
- key = txHash;
411
- txHash = TxHash.fromString(txHash);
412
- } else {
413
- key = txHash.toString();
414
- }
415
- if (this.#pendingTxs.has(key)) {
416
- return this.#pendingTxs.get(key);
417
- }
418
- const tx = await this.getTxByHash(txHash);
419
- if (tx) {
420
- this.#pendingTxs.set(key, tx);
421
- return tx;
422
- }
423
- return undefined;
424
- }
425
- /**
426
493
  * Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
494
+ * Note: Pending txs should not be archived, only finalized txs
427
495
  * @param txs - The list of transactions to archive.
428
496
  * @returns Empty promise.
429
497
  */ async archiveTxs(txs) {
430
498
  if (txs.length === 0) {
431
499
  return;
432
500
  }
501
+ if (this.#archivedTxLimit === 0) {
502
+ return;
503
+ }
433
504
  try {
434
505
  const txHashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
435
506
  await this.#archive.transactionAsync(async ()=>{
@@ -468,153 +539,58 @@ import { getPendingTxPriority } from './priority.js';
468
539
  });
469
540
  }
470
541
  }
471
- /**
472
- * Evicts pending txs with the lowest priority fees from the pool to accomodate the max tx count and cumulative max tx size
473
- * after new txs are added.
474
- *
475
- * @param newTxHashes - The tx hashes of the new txs added to the pool.
476
- * @returns The total number of txs evicted from the pool and the number of new txs that were evicted.
477
- */ async evictLowPriorityTxs(newTxHashes) {
478
- if (this.#maxTxPoolSize === undefined || this.#maxTxPoolSize === 0) {
479
- return {
480
- numLowPriorityTxsEvicted: 0,
481
- numNewTxsEvicted: 0
482
- };
483
- }
484
- let numNewTxsEvicted = 0;
485
- const txsToEvict = [];
486
- let pendingTxsSize = await this.#pendingTxSize.getAsync() ?? 0;
487
- if (pendingTxsSize > this.#maxTxPoolSize * this.txPoolOverflowFactor) {
488
- for await (const txHash of this.#pendingTxPriorityToHash.valuesAsync()){
489
- if (this.#nonEvictableTxs.has(txHash.toString())) {
490
- continue;
491
- }
492
- const txSize = await this.#pendingTxHashToSize.getAsync(txHash.toString()) ?? (await this.getPendingTxByHash(txHash))?.getSize();
493
- this.#log.verbose(`Evicting tx ${txHash} from pool due to low priority to satisfy max tx size limit`, {
494
- txHash,
495
- txSize
496
- });
497
- txsToEvict.push(TxHash.fromString(txHash));
498
- if (txSize) {
499
- pendingTxsSize -= txSize;
500
- if (pendingTxsSize <= this.#maxTxPoolSize) {
501
- break;
502
- }
503
- }
504
- }
505
- numNewTxsEvicted += newTxHashes.filter((txHash)=>txsToEvict.includes(txHash)).length;
506
- }
507
- if (txsToEvict.length > 0) {
508
- await this.deleteTxs(txsToEvict, {
509
- eviction: true
510
- });
542
+ // Assumes being called within a DB transaction
543
+ async addPendingTxIndicesInDbTx(tx, txHash) {
544
+ await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
545
+ await this.#historicalHeaderToTxHash.set((await tx.data.constants.anchorBlockHeader.hash()).toString(), txHash);
546
+ await this.#feePayerToBalanceEntry.set(tx.data.feePayer.toString(), await FeePayerTxInfo.encode(tx, txHash));
547
+ // Add nullifier entries for conflict detection
548
+ const nullifiers = tx.data.getNonEmptyNullifiers();
549
+ for (const nullifier of nullifiers){
550
+ await this.#pendingNullifierToTxHash.set(nullifier.toString(), txHash);
511
551
  }
512
- return {
513
- numLowPriorityTxsEvicted: txsToEvict.length,
514
- numNewTxsEvicted
515
- };
516
552
  }
517
- /**
518
- * Evicts invalid pending txs from the pool after a txs from a block are mined.
519
- * Eviction criteria includes:
520
- * - txs with nullifiers that are already included in the mined block
521
- * - txs with an insufficient fee payer balance
522
- * - txs with an expiration timestamp lower than that of the mined block
523
- *
524
- * @param minedTxHashes - The tx hashes of the txs mined in the block.
525
- * @param blockHeader - The header of the mined block.
526
- * @returns The total number of txs evicted from the pool.
527
- */ async evictInvalidTxsAfterMining(minedTxHashes, blockHeader, minedNullifiers, minedFeePayers) {
528
- if (minedTxHashes.length === 0) {
529
- return 0;
530
- }
531
- const { blockNumber, timestamp } = blockHeader.globalVariables;
532
- // Wait for world state to be synced to at least the mined block number
533
- await this.#worldStateSynchronizer.syncImmediate(blockNumber);
534
- const db = this.#worldStateSynchronizer.getCommitted();
535
- const gasTxValidator = this.createGasTxValidator(db);
536
- const txsToEvict = [];
537
- for await (const txHash of this.#pendingTxPriorityToHash.valuesAsync()){
538
- const tx = await this.getPendingTxByHash(txHash);
539
- if (!tx) {
540
- continue;
541
- }
542
- // Evict pending txs that share nullifiers with mined txs
543
- const txNullifiers = tx.data.getNonEmptyNullifiers();
544
- if (txNullifiers.some((nullifier)=>minedNullifiers.has(nullifier.toString()))) {
545
- this.#log.verbose(`Evicting tx ${txHash} from pool due to a duplicate nullifier with a mined tx`);
546
- txsToEvict.push(TxHash.fromString(txHash));
547
- continue;
548
- }
549
- // Evict pending txs with an insufficient fee payer balance
550
- if (minedFeePayers.has(tx.data.feePayer.toString()) && (await gasTxValidator.validateTxFee(tx)).result === 'invalid') {
551
- this.#log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
552
- txsToEvict.push(TxHash.fromString(txHash));
553
- continue;
554
- }
555
- // Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
556
- const includeByTimestamp = tx.data.includeByTimestamp;
557
- if (includeByTimestamp <= timestamp) {
558
- this.#log.verbose(`Evicting tx ${txHash} from pool due to the tx being expired (includeByTimestamp: ${includeByTimestamp}, mined block timestamp: ${timestamp})`);
559
- txsToEvict.push(TxHash.fromString(txHash));
560
- continue;
561
- }
562
- }
563
- if (txsToEvict.length > 0) {
564
- await this.deleteTxs(txsToEvict, {
565
- eviction: true
566
- });
553
+ // Assumes being called within a DB transaction
554
+ async removePendingTxIndicesInDbTx(tx, txHash) {
555
+ await this.#pendingTxPriorityToHash.deleteValue(getPendingTxPriority(tx), txHash);
556
+ await this.#historicalHeaderToTxHash.deleteValue((await tx.data.constants.anchorBlockHeader.hash()).toString(), txHash);
557
+ await this.#feePayerToBalanceEntry.deleteValue(tx.data.feePayer.toString(), await FeePayerTxInfo.encode(tx, txHash));
558
+ // Remove nullifier entries
559
+ const nullifiers = tx.data.getNonEmptyNullifiers();
560
+ for (const nullifier of nullifiers){
561
+ await this.#pendingNullifierToTxHash.delete(nullifier.toString());
567
562
  }
568
- return txsToEvict.length;
569
563
  }
570
564
  /**
571
- * Evicts pending txs that no longer have valid archive roots or fee payer balances from the pool after a reorg.
572
- *
573
- * @param txHashes - The tx hashes of the txs that were moved from mined to pending.
574
- * @returns The total number of txs evicted from the pool.
575
- */ async evictInvalidTxsAfterReorg(txHashes) {
576
- if (txHashes.length === 0) {
577
- return 0;
578
- }
579
- await this.#worldStateSynchronizer.syncImmediate();
580
- const db = this.#worldStateSynchronizer.getCommitted();
581
- const archiveCache = this.createArchiveCache(db);
582
- const gasTxValidator = this.createGasTxValidator(db);
565
+ * Returns up to `limit` lowest-priority evictable pending tx hashes without hydrating transactions.
566
+ * Iterates the priority index in ascending order and skips non-evictable txs.
567
+ */ async getLowestPriorityEvictable(limit) {
583
568
  const txsToEvict = [];
584
- for await (const [txHash, headerHash] of this.#pendingTxHashToHeaderHash.entriesAsync()){
585
- const tx = await this.getPendingTxByHash(txHash);
586
- if (!tx) {
587
- continue;
588
- }
589
- const [index] = await archiveCache.getArchiveIndices([
590
- Fr.fromString(headerHash)
591
- ]);
592
- if (index === undefined) {
593
- this.#log.verbose(`Evicting tx ${txHash} from pool due to an invalid archive root`);
594
- txsToEvict.push(TxHash.fromString(txHash));
569
+ if (limit <= 0) {
570
+ return txsToEvict;
571
+ }
572
+ for await (const txHashStr of this.#pendingTxPriorityToHash.valuesAsync()){
573
+ if (this.#nonEvictableTxs.has(txHashStr)) {
595
574
  continue;
596
575
  }
597
- if ((await gasTxValidator.validateTxFee(tx)).result === 'invalid') {
598
- this.#log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
599
- txsToEvict.push(TxHash.fromString(txHash));
576
+ txsToEvict.push(TxHash.fromString(txHashStr));
577
+ if (txsToEvict.length >= limit) {
578
+ break;
600
579
  }
601
580
  }
602
- if (txsToEvict.length > 0) {
603
- await this.deleteTxs(txsToEvict, {
604
- eviction: true
605
- });
606
- }
607
- return txsToEvict.length;
581
+ return txsToEvict;
608
582
  }
609
- async addPendingTxIndices(tx, txHash) {
610
- await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
611
- await this.#pendingTxHashToSize.set(txHash, tx.getSize());
612
- await this.#pendingTxHashToHeaderHash.set(txHash, (await tx.data.constants.anchorBlockHeader.hash()).toString());
613
- }
614
- async removePendingTxIndices(tx, txHash) {
615
- await this.#pendingTxPriorityToHash.deleteValue(getPendingTxPriority(tx), txHash);
616
- await this.#pendingTxHashToSize.delete(txHash);
617
- await this.#pendingTxHashToHeaderHash.delete(txHash);
618
- this.#pendingTxs.delete(txHash);
583
+ /**
584
+ * Creates a PreAddPoolAccess object for use by pre-add eviction rules.
585
+ * Provides read-only access to pool state during addTxs transaction.
586
+ */ getPreAddPoolAccess() {
587
+ return {
588
+ getTxHashByNullifier: async (nullifier)=>{
589
+ const hashStr = await this.#pendingNullifierToTxHash.getAsync(nullifier.toString());
590
+ return hashStr ? TxHash.fromString(hashStr) : undefined;
591
+ },
592
+ getPendingTxByHash: this.getTxByHash.bind(this),
593
+ getTxPriority: getPendingTxPriority
594
+ };
619
595
  }
620
596
  }