@aztec/p2p 0.0.1-commit.f504929 → 0.0.1-commit.f5d02921e

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 (283) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +2 -2
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +25 -11
  5. package/dest/client/interface.d.ts +9 -2
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +3 -2
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +37 -36
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
  11. package/dest/config.d.ts +24 -2
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +66 -7
  14. package/dest/errors/p2p-service.error.d.ts +9 -0
  15. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  16. package/dest/errors/p2p-service.error.js +10 -0
  17. package/dest/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -5
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
  24. package/dest/mem_pools/index.d.ts +1 -2
  25. package/dest/mem_pools/index.d.ts.map +1 -1
  26. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  27. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
  29. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
  30. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
  32. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  33. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
  34. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
  35. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  37. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
  38. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
  40. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +25 -10
  41. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +38 -11
  43. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  44. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
  46. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  47. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
  49. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
  50. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +21 -6
  52. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  53. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  54. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  55. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  56. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  57. package/dest/msg_validators/clock_tolerance.js +4 -3
  58. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +5 -4
  59. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  60. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  61. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +5 -4
  62. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  63. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  64. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +12 -9
  65. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  66. package/dest/msg_validators/proposal_validator/proposal_validator.js +51 -49
  67. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  68. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/allowed_public_setup.js +21 -32
  70. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  71. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  72. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  73. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  74. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  75. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  76. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  77. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  78. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  79. package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
  80. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/factory.js +36 -10
  82. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  83. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  85. package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
  86. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  87. package/dest/msg_validators/tx_validator/gas_validator.js +39 -9
  88. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  89. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/index.js +1 -0
  91. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  92. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  93. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  94. package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
  95. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  96. package/dest/msg_validators/tx_validator/phases_validator.js +49 -2
  97. package/dest/services/dummy_service.d.ts +5 -3
  98. package/dest/services/dummy_service.d.ts.map +1 -1
  99. package/dest/services/dummy_service.js +5 -1
  100. package/dest/services/encoding.d.ts +5 -1
  101. package/dest/services/encoding.d.ts.map +1 -1
  102. package/dest/services/encoding.js +7 -1
  103. package/dest/services/libp2p/libp2p_service.d.ts +14 -11
  104. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  105. package/dest/services/libp2p/libp2p_service.js +146 -74
  106. package/dest/services/peer-manager/peer_manager.d.ts +6 -2
  107. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  108. package/dest/services/peer-manager/peer_manager.js +22 -8
  109. package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
  110. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  111. package/dest/services/peer-manager/peer_scoring.js +28 -10
  112. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
  113. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  114. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
  115. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
  116. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  117. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  118. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  119. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  120. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
  121. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  122. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
  123. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  124. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  125. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  126. package/dest/services/reqresp/reqresp.d.ts +1 -1
  127. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  128. package/dest/services/reqresp/reqresp.js +17 -9
  129. package/dest/services/service.d.ts +5 -2
  130. package/dest/services/service.d.ts.map +1 -1
  131. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
  132. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  133. package/dest/services/tx_collection/fast_tx_collection.js +57 -73
  134. package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
  135. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  136. package/dest/services/tx_collection/file_store_tx_source.js +39 -29
  137. package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
  138. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  139. package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
  140. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  141. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  142. package/dest/services/tx_collection/request_tracker.js +84 -0
  143. package/dest/services/tx_collection/slow_tx_collection.js +1 -1
  144. package/dest/services/tx_collection/tx_collection.d.ts +3 -6
  145. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  146. package/dest/services/tx_collection/tx_source.d.ts +6 -5
  147. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  148. package/dest/services/tx_collection/tx_source.js +9 -7
  149. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  150. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  151. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  152. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  153. package/dest/test-helpers/testbench-utils.d.ts +1 -1
  154. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  155. package/dest/test-helpers/testbench-utils.js +22 -3
  156. package/dest/testbench/p2p_client_testbench_worker.js +46 -16
  157. package/dest/testbench/worker_client_manager.d.ts +3 -1
  158. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  159. package/dest/testbench/worker_client_manager.js +6 -3
  160. package/dest/util.d.ts +1 -1
  161. package/package.json +14 -14
  162. package/src/client/factory.ts +43 -14
  163. package/src/client/interface.ts +9 -1
  164. package/src/client/p2p_client.ts +39 -36
  165. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
  166. package/src/config.ts +92 -4
  167. package/src/errors/p2p-service.error.ts +11 -0
  168. package/src/index.ts +0 -1
  169. package/src/mem_pools/attestation_pool/attestation_pool.ts +7 -5
  170. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
  171. package/src/mem_pools/index.ts +0 -3
  172. package/src/mem_pools/tx_pool_v2/README.md +9 -1
  173. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  174. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
  175. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
  176. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
  177. package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
  178. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +59 -13
  179. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
  180. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
  181. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +23 -6
  182. package/src/msg_validators/attestation_validator/README.md +49 -0
  183. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  184. package/src/msg_validators/clock_tolerance.ts +4 -3
  185. package/src/msg_validators/proposal_validator/README.md +123 -0
  186. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +13 -3
  187. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +19 -6
  188. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -53
  189. package/src/msg_validators/tx_validator/README.md +5 -1
  190. package/src/msg_validators/tx_validator/allowed_public_setup.ts +16 -35
  191. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  192. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  193. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  194. package/src/msg_validators/tx_validator/factory.ts +43 -3
  195. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  196. package/src/msg_validators/tx_validator/gas_validator.ts +41 -8
  197. package/src/msg_validators/tx_validator/index.ts +1 -0
  198. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  199. package/src/msg_validators/tx_validator/phases_validator.ts +60 -1
  200. package/src/services/dummy_service.ts +7 -2
  201. package/src/services/encoding.ts +9 -1
  202. package/src/services/libp2p/libp2p_service.ts +147 -87
  203. package/src/services/peer-manager/peer_manager.ts +26 -8
  204. package/src/services/peer-manager/peer_scoring.ts +21 -5
  205. package/src/services/reqresp/README.md +229 -0
  206. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  207. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
  208. package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
  209. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  210. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
  211. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  212. package/src/services/reqresp/reqresp.ts +19 -11
  213. package/src/services/service.ts +6 -1
  214. package/src/services/tx_collection/fast_tx_collection.ts +57 -83
  215. package/src/services/tx_collection/file_store_tx_source.ts +43 -31
  216. package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
  217. package/src/services/tx_collection/request_tracker.ts +127 -0
  218. package/src/services/tx_collection/slow_tx_collection.ts +1 -1
  219. package/src/services/tx_collection/tx_collection.ts +3 -5
  220. package/src/services/tx_collection/tx_source.ts +8 -7
  221. package/src/test-helpers/make-test-p2p-clients.ts +1 -1
  222. package/src/test-helpers/reqresp-nodes.ts +1 -1
  223. package/src/test-helpers/testbench-utils.ts +29 -3
  224. package/src/testbench/p2p_client_testbench_worker.ts +45 -15
  225. package/src/testbench/worker_client_manager.ts +13 -6
  226. package/src/util.ts +1 -1
  227. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  228. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  229. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  230. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  231. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  232. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  233. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  234. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  235. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  236. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  237. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  238. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  239. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  240. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  241. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  242. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  243. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  244. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  245. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  246. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  247. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  248. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  249. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  250. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  251. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  252. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  253. package/dest/mem_pools/tx_pool/index.js +0 -2
  254. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  255. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  256. package/dest/mem_pools/tx_pool/priority.js +0 -15
  257. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  258. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  259. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  260. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  261. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  262. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  263. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -24
  264. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  265. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -378
  266. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  267. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  268. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  269. package/src/mem_pools/tx_pool/README.md +0 -270
  270. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  271. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  272. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  273. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  274. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  275. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  276. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  277. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  278. package/src/mem_pools/tx_pool/index.ts +0 -2
  279. package/src/mem_pools/tx_pool/priority.ts +0 -20
  280. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  281. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  282. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -373
  283. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
@@ -1,106 +0,0 @@
1
- import { createLogger } from '@aztec/foundation/log';
2
- import type { TxHash } from '@aztec/stdlib/tx';
3
-
4
- import type { TxPoolOptions } from '../tx_pool.js';
5
- import {
6
- type EvictionContext,
7
- EvictionEvent,
8
- type EvictionResult,
9
- type EvictionRule,
10
- type TxPoolOperations,
11
- } from './eviction_strategy.js';
12
-
13
- export interface LowPriorityEvictionConfig {
14
- /** Maximum number of pending transactions before eviction kicks in */
15
- maxPoolSize: number;
16
- }
17
-
18
- /**
19
- * Eviction rule that removes low-priority transactions when the number of pending transactions exceeds configured limits.
20
- * Only triggers on TXS_ADDED events and respects non-evictable transactions.
21
- */
22
- export class LowPriorityEvictionRule implements EvictionRule {
23
- public readonly name = 'LowPriorityEviction';
24
-
25
- private log = createLogger('p2p:mempool:tx_pool:low_priority_eviction_rule');
26
-
27
- constructor(private config: LowPriorityEvictionConfig) {}
28
-
29
- public async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
30
- if (context.event !== EvictionEvent.TXS_ADDED) {
31
- return {
32
- reason: 'low_priority',
33
- success: true,
34
- txsEvicted: [],
35
- };
36
- }
37
-
38
- if (this.config.maxPoolSize === 0) {
39
- return {
40
- reason: 'low_priority',
41
- success: true,
42
- txsEvicted: [],
43
- };
44
- }
45
-
46
- try {
47
- const currentTxCount = await txPool.getPendingTxCount();
48
- const maxCount = this.config.maxPoolSize;
49
-
50
- if (currentTxCount <= maxCount) {
51
- this.log.trace(`Not evicting low priority txs. Pending tx count below limit ${currentTxCount} <= ${maxCount}`);
52
- return {
53
- reason: 'low_priority',
54
- success: true,
55
- txsEvicted: [],
56
- };
57
- }
58
-
59
- this.log.verbose(`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${maxCount}`);
60
- const numberToEvict = currentTxCount - maxCount;
61
- const txsToEvict: TxHash[] = await txPool.getLowestPriorityEvictable(numberToEvict);
62
-
63
- if (txsToEvict.length > 0) {
64
- await txPool.deleteTxs(txsToEvict);
65
- }
66
-
67
- const numNewTxsEvicted = context.newTxs.filter(newTxHash =>
68
- txsToEvict.some(evictedTx => evictedTx.equals(newTxHash)),
69
- ).length;
70
-
71
- this.log.verbose(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`, {
72
- txsEvicted: txsToEvict,
73
- });
74
-
75
- return {
76
- reason: 'low_priority',
77
- success: true,
78
- txsEvicted: txsToEvict,
79
- };
80
- } catch (err) {
81
- this.log.error('Failed to evict low priority transactions', { err });
82
- return {
83
- reason: 'low_priority',
84
- success: false,
85
- txsEvicted: [],
86
- error: new Error('Failed to evict low priority txs', { cause: err }),
87
- };
88
- }
89
- }
90
-
91
- /**
92
- * Updates the configuration for this eviction rule
93
- */
94
- updateConfig(config: TxPoolOptions): void {
95
- if (config.maxPendingTxCount !== undefined) {
96
- this.config.maxPoolSize = config.maxPendingTxCount;
97
- }
98
- }
99
-
100
- /**
101
- * Gets the current configuration
102
- */
103
- getConfig(): LowPriorityEvictionConfig {
104
- return { ...this.config };
105
- }
106
- }
@@ -1,75 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export * from './tx_pool.js';
2
- export * from './aztec_kv_tx_pool.js';
@@ -1,20 +0,0 @@
1
- import { Buffer32 } from '@aztec/foundation/buffer';
2
- import type { Tx } from '@aztec/stdlib/tx';
3
-
4
- /**
5
- * Returns a string representing the priority of a tx.
6
- * Txs with a higher priority value are returned first when retrieving pending tx hashes.
7
- * We currently use the sum of the priority fees for the tx for this value, represented as hex.
8
- */
9
- export function getPendingTxPriority(tx: Tx): string {
10
- return Buffer32.fromBigInt(getTxPriorityFee(tx)).toString();
11
- }
12
-
13
- /**
14
- * Returns the priority of a tx.
15
- */
16
- export function getTxPriorityFee(tx: Tx): bigint {
17
- const priorityFees = tx.getGasSettings().maxPriorityFeesPerGas;
18
- const totalFees = priorityFees.feePerDaGas + priorityFees.feePerL2Gas;
19
- return totalFees;
20
- }
@@ -1,141 +0,0 @@
1
- import type { BlockNumber } from '@aztec/foundation/branded-types';
2
- import type { TypedEventEmitter } from '@aztec/foundation/types';
3
- import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
4
-
5
- export type TxPoolOptions = {
6
- maxPendingTxCount?: number;
7
- archivedTxLimit?: number;
8
- };
9
-
10
- export type TxPoolEvents = {
11
- ['txs-added']: (args: { txs: Tx[]; source?: string }) => void | Promise<void>;
12
- };
13
-
14
- /**
15
- * Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
16
- */
17
- export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
18
- /**
19
- * Adds a list of transactions to the pool. Duplicates are ignored.
20
- * @param txs - An array of txs to be added to the pool.
21
- * @returns The number of txs added to the pool. Note if the transaction already exists, it will not be added again.
22
- */
23
- addTxs(txs: Tx[], opts?: { source?: string }): Promise<number>;
24
-
25
- /**
26
- * Checks if a transaction exists in the pool and returns it.
27
- * @param txHash - The hash of the transaction, used as an ID.
28
- * @returns The transaction, if found, 'undefined' otherwise.
29
- */
30
- getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
31
-
32
- /**
33
- * Checks if transactions exist in the pool and returns them.
34
- * @param txHashes - The hashes of the transactions
35
- * @returns The transactions, if found, 'undefined' otherwise.
36
- */
37
- getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
38
-
39
- /**
40
- * Checks if transactions exist in the pool
41
- * @param txHashes - The hashes of the transactions to check for
42
- * @returns True or False for each tx hash
43
- */
44
- hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
45
-
46
- /**
47
- * Checks if a transaction exists in the pool
48
- * @param txHash - The hash of the transaction to check for
49
- * @returns True if the transaction exists, false otherwise
50
- */
51
- hasTx(txHash: TxHash): Promise<boolean>;
52
-
53
- /**
54
- * Checks if an archived transaction exists in the pool and returns it.
55
- * @param txHash - The hash of the transaction, used as an ID.
56
- * @returns The transaction, if found, 'undefined' otherwise.
57
- */
58
- getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
59
-
60
- /**
61
- * Marks the set of txs as mined, as opposed to pending.
62
- * @param txHashes - Hashes of the txs to flag as mined.
63
- * @param blockHeader - The header of the mined block.
64
- */
65
- markAsMined(txHashes: TxHash[], blockHeader: BlockHeader): Promise<void>;
66
-
67
- /**
68
- * Moves mined txs back to the pending set in the case of a reorg.
69
- * Note: txs not known by this peer will be ignored.
70
- * @param txHashes - Hashes of the txs to flag as pending.
71
- * @param latestBlock - The block number the chain was pruned to.
72
- */
73
- markMinedAsPending(txHashes: TxHash[], latestBlock: BlockNumber): Promise<void>;
74
-
75
- /**
76
- * Deletes transactions from the pool. Tx hashes that are not present are ignored.
77
- * @param txHashes - An array of tx hashes to be removed from the tx pool.
78
- */
79
- deleteTxs(txHashes: TxHash[], opts?: { permanently?: boolean }): Promise<void>;
80
-
81
- /**
82
- * Gets all transactions currently in the tx pool.
83
- * @returns An array of transaction objects found in the tx pool.
84
- */
85
- getAllTxs(): Promise<Tx[]>;
86
-
87
- /**
88
- * Gets the hashes of all transactions currently in the tx pool.
89
- * @returns An array of transaction hashes found in the tx pool.
90
- */
91
- getAllTxHashes(): Promise<TxHash[]>;
92
-
93
- /**
94
- * Gets the hashes of pending transactions currently in the tx pool sorted by priority (see getPendingTxPriority).
95
- * @returns An array of pending transaction hashes found in the tx pool.
96
- */
97
- getPendingTxHashes(): Promise<TxHash[]>;
98
-
99
- /** Returns the number of pending txs in the pool. */
100
- getPendingTxCount(): Promise<number>;
101
-
102
- /**
103
- * Gets the hashes of mined transactions currently in the tx pool.
104
- * @returns An array of mined transaction hashes found in the tx pool.
105
- */
106
- getMinedTxHashes(): Promise<[tx: TxHash, blockNumber: BlockNumber][]>;
107
-
108
- /**
109
- * Returns whether the given tx hash is flagged as pending, mined, or deleted.
110
- * @param txHash - Hash of the tx to query.
111
- * @returns Pending, mined, or deleted depending on its status, or undefined if not found.
112
- */
113
- getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined>;
114
-
115
- /**
116
- * Configure the maximum size of the tx pool
117
- * @param maxSizeBytes - The maximum size in bytes of the mempool. Set to undefined to disable it
118
- */
119
- updateConfig(config: TxPoolOptions): void;
120
-
121
- /** Returns whether the pool is empty. */
122
- isEmpty(): Promise<boolean>;
123
-
124
- /**
125
- * Marks transactions as non-evictible in the pool.
126
- * @param txHashes - Hashes of the transactions to mark as non-evictible.
127
- */
128
- markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void>;
129
-
130
- /**
131
- * Clears collection of non-evictable transactions in the pool
132
- */
133
- clearNonEvictableTxs(): Promise<void>;
134
-
135
- /**
136
- * Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
137
- * @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
138
- * @returns The number of transactions permanently deleted.
139
- */
140
- cleanupDeletedMinedTxs(blockNumber: BlockNumber): Promise<number>;
141
- }
@@ -1,319 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { unfreeze } from '@aztec/foundation/types';
3
- import { GasFees } from '@aztec/stdlib/gas';
4
- import { mockTx } from '@aztec/stdlib/testing';
5
- import { BlockHeader, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
6
-
7
- import type { TxPool } from './tx_pool.js';
8
-
9
- /**
10
- * Tests a TxPool implementation.
11
- * @param getTxPool - Gets a fresh TxPool
12
- */
13
- export function describeTxPool(getTxPool: () => TxPool) {
14
- let pool: TxPool;
15
-
16
- const minedBlockHeader = BlockHeader.empty({
17
- globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(1), timestamp: 0n }),
18
- });
19
-
20
- beforeEach(() => {
21
- pool = getTxPool();
22
- });
23
-
24
- afterEach(() => {
25
- pool.removeAllListeners('txs-added');
26
- });
27
-
28
- it('adds txs to the pool as pending', async () => {
29
- const tx1 = await mockTx(1);
30
-
31
- await pool.addTxs([tx1]);
32
- const poolTx = await pool.getTxByHash(tx1.getTxHash());
33
- expect(poolTx!.getTxHash()).toEqual(tx1.getTxHash());
34
- await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('pending');
35
- await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]);
36
- await expect(pool.getPendingTxCount()).resolves.toEqual(1);
37
- });
38
-
39
- it('emits txs-added event with new txs', async () => {
40
- const tx1 = await mockTx(1); // existing and pending
41
- const tx2 = await mockTx(2); // mined but not known
42
- const tx3 = await mockTx(3); // brand new
43
-
44
- await pool.addTxs([tx1]);
45
- await pool.markAsMined([tx2.getTxHash()], minedBlockHeader);
46
-
47
- let txsFromEvent: Tx[] | undefined = undefined;
48
- pool.once('txs-added', ({ txs }) => {
49
- txsFromEvent = txs;
50
- });
51
-
52
- await pool.addTxs([tx1, tx2, tx3]);
53
- expect(txsFromEvent).toBeDefined();
54
- expect(txsFromEvent).toHaveLength(2);
55
- const eventHashes = txsFromEvent!.map(tx => tx.getTxHash());
56
- expect(eventHashes).toEqual(expect.arrayContaining([tx2.getTxHash(), tx3.getTxHash()]));
57
- });
58
-
59
- it('removes txs from the pool', async () => {
60
- const pendingTx = await mockTx(1);
61
- const minedTx = await mockTx(2);
62
-
63
- await pool.addTxs([pendingTx, minedTx]);
64
- await pool.markAsMined([minedTx.getTxHash()], minedBlockHeader);
65
-
66
- // Delete a pending tx - should be permanently deleted
67
- await pool.deleteTxs([pendingTx.getTxHash()]);
68
- await expect(pool.getTxByHash(pendingTx.getTxHash())).resolves.toBeUndefined();
69
- await expect(pool.getTxStatus(pendingTx.getTxHash())).resolves.toBeUndefined();
70
-
71
- // Delete a mined tx - should be soft-deleted (still in storage)
72
- await pool.deleteTxs([minedTx.getTxHash()]);
73
- await expect(pool.getTxByHash(minedTx.getTxHash())).resolves.toBeDefined();
74
- await expect(pool.getTxStatus(minedTx.getTxHash())).resolves.toEqual('deleted');
75
- await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
76
-
77
- await expect(pool.getPendingTxCount()).resolves.toEqual(0);
78
- });
79
-
80
- it('marks txs as mined', async () => {
81
- const tx1 = await mockTx(1);
82
- const tx2 = await mockTx(2);
83
-
84
- await pool.addTxs([tx1, tx2]);
85
- await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
86
-
87
- const retrievedTx = await pool.getTxByHash(tx1.getTxHash());
88
- expect(retrievedTx?.getTxHash()).toEqual(tx1.getTxHash());
89
- await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
90
- await expect(pool.getMinedTxHashes()).resolves.toEqual([[tx1.getTxHash(), 1]]);
91
- await expect(pool.getPendingTxHashes()).resolves.toEqual([tx2.getTxHash()]);
92
- await expect(pool.getPendingTxCount()).resolves.toEqual(1);
93
- });
94
-
95
- it('marks txs as pending after being mined', async () => {
96
- const tx1 = await mockTx(1);
97
- const tx2 = await mockTx(2);
98
-
99
- await pool.addTxs([tx1, tx2]);
100
- await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
101
-
102
- await pool.markMinedAsPending([tx1.getTxHash()], BlockNumber(1));
103
- await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
104
- const pending = await pool.getPendingTxHashes();
105
- expect(pending).toHaveLength(2);
106
- expect(pending).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash()]));
107
- await expect(pool.getPendingTxCount()).resolves.toEqual(2);
108
- });
109
-
110
- it('only marks txs as pending if they are known', async () => {
111
- const tx1 = await mockTx(1);
112
- // simulate a situation where not all peers have all the txs
113
- const tx2 = await mockTx(2);
114
- const someTxHashThatThisPeerDidNotSee = tx2.getTxHash();
115
- await pool.addTxs([tx1]);
116
- // this peer knows that tx2 was mined, but it does not have the tx object
117
- await pool.markAsMined([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], minedBlockHeader);
118
- expect(await pool.getMinedTxHashes()).toEqual(
119
- expect.arrayContaining([
120
- [tx1.getTxHash(), 1],
121
- [someTxHashThatThisPeerDidNotSee, 1],
122
- ]),
123
- );
124
-
125
- // reorg: both txs should now become available again
126
- await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], BlockNumber(1));
127
- await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
128
- await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]); // tx2 is not in the pool
129
- await expect(pool.getPendingTxCount()).resolves.toEqual(1);
130
- });
131
-
132
- it('returns all transactions in the pool', async () => {
133
- const tx1 = await mockTx(1);
134
- const tx2 = await mockTx(2);
135
- const tx3 = await mockTx(3);
136
-
137
- await pool.addTxs([tx1, tx2, tx3]);
138
-
139
- const poolTxs = await pool.getAllTxs();
140
- expect(poolTxs).toHaveLength(3);
141
- const poolHashes = poolTxs.map(tx => tx.getTxHash());
142
- expect(poolHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash(), tx3.getTxHash()]));
143
- await expect(pool.getPendingTxCount()).resolves.toEqual(3);
144
- });
145
-
146
- it('returns all txHashes in the pool', async () => {
147
- const tx1 = await mockTx(1);
148
- const tx2 = await mockTx(2);
149
- const tx3 = await mockTx(3);
150
-
151
- await pool.addTxs([tx1, tx2, tx3]);
152
-
153
- const poolTxHashes = await pool.getAllTxHashes();
154
- const expectedHashes = [tx1, tx2, tx3].map(tx => tx.getTxHash());
155
- expect(poolTxHashes).toHaveLength(3);
156
- expect(poolTxHashes).toEqual(expect.arrayContaining(expectedHashes));
157
- await expect(pool.getPendingTxCount()).resolves.toEqual(3);
158
- });
159
-
160
- it('returns txs by their hash', async () => {
161
- const tx1 = await mockTx(1);
162
- const tx2 = await mockTx(2);
163
- const tx3 = await mockTx(3);
164
-
165
- await pool.addTxs([tx1, tx2, tx3]);
166
-
167
- const requestedTxs = await pool.getTxsByHash([tx1.getTxHash(), tx3.getTxHash()]);
168
- expect(requestedTxs).toHaveLength(2);
169
- const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
170
- expect(requestedHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx3.getTxHash()]));
171
- });
172
-
173
- it('returns a large number of transactions by their hash', async () => {
174
- const numTxs = 1_000;
175
- const txs = await Promise.all(Array.from({ length: numTxs }, (_, i) => mockTx(i)));
176
- const hashes = txs.map(tx => tx.getTxHash());
177
- await pool.addTxs(txs);
178
- const requestedTxs = await pool.getTxsByHash(hashes);
179
- expect(requestedTxs).toHaveLength(numTxs);
180
- const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
181
- expect(requestedHashes).toEqual(expect.arrayContaining(hashes));
182
- });
183
-
184
- it('returns whether or not txs exist', async () => {
185
- const tx1 = await mockTx(1);
186
- const tx2 = await mockTx(2);
187
- const tx3 = await mockTx(3);
188
-
189
- await pool.addTxs([tx1, tx2, tx3]);
190
-
191
- const tx4 = await mockTx(4);
192
- const tx5 = await mockTx(5);
193
-
194
- const availability = await pool.hasTxs([
195
- tx1.getTxHash(),
196
- tx2.getTxHash(),
197
- tx3.getTxHash(),
198
- tx4.getTxHash(),
199
- tx5.getTxHash(),
200
- ]);
201
- expect(availability).toHaveLength(5);
202
- expect(availability).toEqual(expect.arrayContaining([true, true, true, false, false]));
203
- });
204
-
205
- it('returns pending tx hashes sorted by priority', async () => {
206
- const withPriorityFee = (tx: Tx, fee: number) => {
207
- unfreeze(tx.data.constants.txContext.gasSettings).maxPriorityFeesPerGas = new GasFees(fee, fee);
208
- return tx;
209
- };
210
-
211
- const tx1 = withPriorityFee(await mockTx(0), 1000);
212
- const tx2 = withPriorityFee(await mockTx(1), 100);
213
- const tx3 = withPriorityFee(await mockTx(2), 200);
214
- const tx4 = withPriorityFee(await mockTx(3), 3000);
215
-
216
- await pool.addTxs([tx1, tx2, tx3, tx4]);
217
-
218
- const poolTxHashes = await pool.getPendingTxHashes();
219
- expect(poolTxHashes).toHaveLength(4);
220
- expect(poolTxHashes).toEqual([tx4, tx1, tx3, tx2].map(tx => tx.getTxHash()));
221
- });
222
-
223
- describe('soft-delete', () => {
224
- it('soft-deletes mined txs and keeps them in storage', async () => {
225
- const txs = await Promise.all([mockTx(1), mockTx(2), mockTx(3)]);
226
- await pool.addTxs(txs);
227
-
228
- // Mark first tx as mined
229
- await pool.markAsMined([txs[0].getTxHash()], minedBlockHeader);
230
-
231
- // Verify initial state
232
- await expect(pool.getPendingTxCount()).resolves.toBe(2);
233
- await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
234
- await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeDefined();
235
-
236
- // Delete mined tx - should be soft-deleted
237
- await pool.deleteTxs([txs[0].getTxHash()]);
238
-
239
- // Delete pending tx - should be permanently deleted
240
- await pool.deleteTxs([txs[1].getTxHash()]);
241
-
242
- // Verify mined tx still exists in storage but has 'deleted' status
243
- await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
244
- await expect(pool.getTxStatus(txs[0].getTxHash())).resolves.toEqual('deleted');
245
-
246
- // Verify pending tx is permanently deleted
247
- await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
248
- await expect(pool.getTxStatus(txs[1].getTxHash())).resolves.toBeUndefined();
249
-
250
- // Verify remaining pending count
251
- await expect(pool.getPendingTxCount()).resolves.toBe(1);
252
-
253
- // Verify pending hashes don't include deleted txs
254
- const pendingHashes = await pool.getPendingTxHashes();
255
- expect(pendingHashes).toHaveLength(1);
256
- expect(pendingHashes.map(h => h.toString())).toContain(txs[2].getTxHash().toString());
257
- });
258
-
259
- it('cleans up old deleted mined transactions', async () => {
260
- const txs = await Promise.all([mockTx(1), mockTx(2), mockTx(3)]);
261
- await pool.addTxs(txs);
262
-
263
- // Mark first two as mined in block 1
264
- await pool.markAsMined([txs[0].getTxHash(), txs[1].getTxHash()], minedBlockHeader);
265
-
266
- // Soft-delete mined transactions
267
- await pool.deleteTxs([txs[0].getTxHash(), txs[1].getTxHash()]);
268
-
269
- // Clean up deleted mined txs from block 1 and earlier
270
- const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
271
-
272
- // Verify old transactions are permanently deleted
273
- expect(deletedCount).toBe(2);
274
- await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeUndefined();
275
- await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
276
- await expect(pool.getTxByHash(txs[2].getTxHash())).resolves.toBeDefined();
277
- });
278
-
279
- it('does not clean up recent deleted mined transactions', async () => {
280
- const txs = await Promise.all([mockTx(1), mockTx(2)]);
281
- await pool.addTxs(txs);
282
-
283
- // Mark as mined in block 2
284
- const laterBlockHeader = BlockHeader.empty({
285
- globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(2), timestamp: 0n }),
286
- });
287
- await pool.markAsMined([txs[0].getTxHash()], laterBlockHeader);
288
-
289
- // Soft-delete a mined transaction
290
- await pool.deleteTxs([txs[0].getTxHash()]);
291
-
292
- // Try to clean up with block 1 (before the mined block)
293
- const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
294
-
295
- // Verify no transactions were cleaned up
296
- expect(deletedCount).toBe(0);
297
- await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
298
- });
299
-
300
- it('restores deleted mined tx when it is mined again', async () => {
301
- const tx = await mockTx(1);
302
- await pool.addTxs([tx]);
303
-
304
- // Mark as mined
305
- await pool.markAsMined([tx.getTxHash()], minedBlockHeader);
306
-
307
- // Soft-delete it
308
- await pool.deleteTxs([tx.getTxHash()]);
309
- await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('deleted');
310
-
311
- // Mark as mined again (e.g., after a reorg)
312
- await pool.markAsMined([tx.getTxHash()], minedBlockHeader);
313
-
314
- // Should be back to mined status
315
- await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('mined');
316
- await expect(pool.getTxByHash(tx.getTxHash())).resolves.toBeDefined();
317
- });
318
- });
319
- }