@aztec/p2p 0.0.1-commit.aada20e3 → 0.0.1-commit.b1c78909e

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 (378) hide show
  1. package/dest/client/factory.d.ts +11 -11
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +45 -15
  4. package/dest/client/interface.d.ts +46 -33
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +39 -51
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +151 -224
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +7 -8
  10. package/dest/config.d.ts +49 -18
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +92 -38
  13. package/dest/errors/tx-pool.error.d.ts +8 -0
  14. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  15. package/dest/errors/tx-pool.error.js +9 -0
  16. package/dest/index.d.ts +2 -1
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +1 -0
  19. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/attestation_pool.js +445 -3
  22. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  25. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  26. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/index.js +1 -2
  28. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  31. package/dest/mem_pools/index.d.ts +3 -2
  32. package/dest/mem_pools/index.d.ts.map +1 -1
  33. package/dest/mem_pools/index.js +1 -1
  34. package/dest/mem_pools/instrumentation.d.ts +4 -2
  35. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  36. package/dest/mem_pools/instrumentation.js +16 -14
  37. package/dest/mem_pools/interface.d.ts +5 -5
  38. package/dest/mem_pools/interface.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  40. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  41. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/priority.js +4 -3
  43. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  44. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  46. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  47. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  48. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  49. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  50. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
  55. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  56. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  58. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  59. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  61. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  62. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  65. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  66. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  67. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  68. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  69. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  70. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  71. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  72. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  73. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  75. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  76. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  77. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  78. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  79. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  81. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +28 -8
  82. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  83. package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
  84. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +70 -14
  85. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  86. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +132 -16
  87. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
  88. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +337 -0
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +20 -6
  93. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
  94. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  95. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +467 -592
  96. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  97. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  99. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  100. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  101. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  102. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  104. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  105. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  106. package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
  107. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  108. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  110. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  111. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  112. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  113. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  114. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  115. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  116. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  117. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  119. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  120. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  121. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  122. package/dest/msg_validators/tx_validator/factory.d.ts +125 -6
  123. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/factory.js +226 -58
  125. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  126. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  127. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  128. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  129. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  131. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  132. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  133. package/dest/msg_validators/tx_validator/index.js +2 -0
  134. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  135. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  136. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  137. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  138. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  139. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  140. package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
  141. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/phases_validator.js +44 -23
  143. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  144. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  145. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  146. package/dest/services/dummy_service.d.ts +13 -5
  147. package/dest/services/dummy_service.d.ts.map +1 -1
  148. package/dest/services/dummy_service.js +10 -4
  149. package/dest/services/encoding.d.ts +3 -3
  150. package/dest/services/encoding.d.ts.map +1 -1
  151. package/dest/services/encoding.js +11 -10
  152. package/dest/services/gossipsub/index.d.ts +3 -0
  153. package/dest/services/gossipsub/index.d.ts.map +1 -0
  154. package/dest/services/gossipsub/index.js +2 -0
  155. package/dest/services/gossipsub/scoring.d.ts +21 -3
  156. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  157. package/dest/services/gossipsub/scoring.js +24 -7
  158. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  159. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  160. package/dest/services/gossipsub/topic_score_params.js +346 -0
  161. package/dest/services/libp2p/libp2p_service.d.ts +94 -42
  162. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  163. package/dest/services/libp2p/libp2p_service.js +463 -350
  164. package/dest/services/peer-manager/metrics.d.ts +3 -1
  165. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  166. package/dest/services/peer-manager/metrics.js +6 -0
  167. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  168. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  169. package/dest/services/peer-manager/peer_manager.js +2 -1
  170. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  171. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  172. package/dest/services/peer-manager/peer_scoring.js +25 -2
  173. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +6 -5
  174. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  175. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +26 -53
  176. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  177. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  178. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  179. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  180. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  181. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  182. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  183. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  184. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  185. package/dest/services/reqresp/interface.d.ts +10 -1
  186. package/dest/services/reqresp/interface.d.ts.map +1 -1
  187. package/dest/services/reqresp/interface.js +15 -1
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
  191. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +21 -10
  192. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  193. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +27 -11
  194. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  195. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  196. package/dest/services/reqresp/protocols/tx.js +20 -0
  197. package/dest/services/reqresp/reqresp.d.ts +1 -1
  198. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  199. package/dest/services/reqresp/reqresp.js +13 -5
  200. package/dest/services/service.d.ts +39 -3
  201. package/dest/services/service.d.ts.map +1 -1
  202. package/dest/services/tx_collection/config.d.ts +22 -4
  203. package/dest/services/tx_collection/config.d.ts.map +1 -1
  204. package/dest/services/tx_collection/config.js +49 -3
  205. package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -5
  206. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  207. package/dest/services/tx_collection/fast_tx_collection.js +64 -48
  208. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  209. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  210. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  211. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  212. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  213. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  214. package/dest/services/tx_collection/index.d.ts +3 -2
  215. package/dest/services/tx_collection/index.d.ts.map +1 -1
  216. package/dest/services/tx_collection/index.js +1 -0
  217. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  218. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  219. package/dest/services/tx_collection/instrumentation.js +2 -1
  220. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  221. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  222. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  223. package/dest/services/tx_collection/proposal_tx_collector.d.ts +15 -14
  224. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  225. package/dest/services/tx_collection/proposal_tx_collector.js +6 -6
  226. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  227. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  228. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  229. package/dest/services/tx_collection/tx_collection.d.ts +23 -10
  230. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  231. package/dest/services/tx_collection/tx_collection.js +75 -3
  232. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  233. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  234. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  235. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  236. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  237. package/dest/services/tx_collection/tx_source.js +19 -2
  238. package/dest/services/tx_file_store/config.d.ts +1 -3
  239. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  240. package/dest/services/tx_file_store/config.js +0 -4
  241. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  242. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  243. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  244. package/dest/services/tx_provider.d.ts +4 -4
  245. package/dest/services/tx_provider.d.ts.map +1 -1
  246. package/dest/services/tx_provider.js +9 -8
  247. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  248. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  249. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  250. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  251. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  252. package/dest/test-helpers/mock-pubsub.js +105 -4
  253. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  254. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  255. package/dest/test-helpers/reqresp-nodes.js +4 -3
  256. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  257. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  258. package/dest/test-helpers/testbench-utils.js +129 -59
  259. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  260. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  261. package/dest/testbench/p2p_client_testbench_worker.js +17 -16
  262. package/dest/testbench/worker_client_manager.d.ts +3 -1
  263. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  264. package/dest/testbench/worker_client_manager.js +6 -2
  265. package/dest/util.d.ts +3 -3
  266. package/dest/util.d.ts.map +1 -1
  267. package/package.json +14 -14
  268. package/src/client/factory.ts +82 -28
  269. package/src/client/interface.ts +56 -34
  270. package/src/client/p2p_client.ts +181 -269
  271. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +21 -12
  272. package/src/config.ts +141 -44
  273. package/src/errors/tx-pool.error.ts +12 -0
  274. package/src/index.ts +1 -0
  275. package/src/mem_pools/attestation_pool/attestation_pool.ts +497 -91
  276. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  277. package/src/mem_pools/attestation_pool/index.ts +9 -2
  278. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  279. package/src/mem_pools/index.ts +4 -1
  280. package/src/mem_pools/instrumentation.ts +17 -13
  281. package/src/mem_pools/interface.ts +4 -4
  282. package/src/mem_pools/tx_pool/README.md +1 -1
  283. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  284. package/src/mem_pools/tx_pool/priority.ts +6 -3
  285. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  286. package/src/mem_pools/tx_pool_v2/README.md +112 -17
  287. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  288. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  289. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  290. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  291. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  292. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  293. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  294. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  295. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  296. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  297. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  298. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  299. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  300. package/src/mem_pools/tx_pool_v2/interfaces.ts +28 -8
  301. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +191 -24
  302. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +430 -0
  303. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +24 -7
  304. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +508 -676
  305. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  306. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  307. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  308. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
  309. package/src/msg_validators/tx_validator/README.md +115 -0
  310. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  311. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  312. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  313. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  314. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  315. package/src/msg_validators/tx_validator/factory.ts +366 -77
  316. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  317. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  318. package/src/msg_validators/tx_validator/index.ts +2 -0
  319. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  320. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  321. package/src/msg_validators/tx_validator/phases_validator.ts +51 -26
  322. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  323. package/src/services/dummy_service.ts +18 -6
  324. package/src/services/encoding.ts +9 -9
  325. package/src/services/gossipsub/README.md +641 -0
  326. package/src/services/gossipsub/index.ts +2 -0
  327. package/src/services/gossipsub/scoring.ts +29 -5
  328. package/src/services/gossipsub/topic_score_params.ts +487 -0
  329. package/src/services/libp2p/libp2p_service.ts +488 -372
  330. package/src/services/peer-manager/metrics.ts +7 -0
  331. package/src/services/peer-manager/peer_manager.ts +2 -1
  332. package/src/services/peer-manager/peer_scoring.ts +25 -0
  333. package/src/services/reqresp/batch-tx-requester/README.md +7 -7
  334. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +31 -59
  335. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  336. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  337. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  338. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  339. package/src/services/reqresp/interface.ts +26 -1
  340. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +23 -14
  341. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +38 -15
  342. package/src/services/reqresp/protocols/tx.ts +22 -0
  343. package/src/services/reqresp/reqresp.ts +16 -4
  344. package/src/services/service.ts +51 -2
  345. package/src/services/tx_collection/config.ts +74 -6
  346. package/src/services/tx_collection/fast_tx_collection.ts +74 -51
  347. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  348. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  349. package/src/services/tx_collection/index.ts +2 -1
  350. package/src/services/tx_collection/instrumentation.ts +7 -1
  351. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  352. package/src/services/tx_collection/proposal_tx_collector.ts +20 -21
  353. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  354. package/src/services/tx_collection/tx_collection.ts +113 -16
  355. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  356. package/src/services/tx_collection/tx_source.ts +22 -3
  357. package/src/services/tx_file_store/config.ts +0 -6
  358. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  359. package/src/services/tx_provider.ts +10 -9
  360. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  361. package/src/test-helpers/mock-pubsub.ts +146 -9
  362. package/src/test-helpers/reqresp-nodes.ts +5 -7
  363. package/src/test-helpers/testbench-utils.ts +128 -71
  364. package/src/testbench/p2p_client_testbench_worker.ts +26 -22
  365. package/src/testbench/worker_client_manager.ts +13 -5
  366. package/src/util.ts +8 -2
  367. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  368. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  369. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  370. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  371. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  372. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  373. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  374. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  375. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  376. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  377. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  378. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -1,12 +1,16 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
3
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
3
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
5
  import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
5
6
  import { Tx, TxHash } from '@aztec/stdlib/tx';
6
7
  import { TxArchive } from './archive/index.js';
7
- import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule } from './eviction/index.js';
8
+ import { DeletedPool } from './deleted_pool.js';
9
+ import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule, TxPoolRejectionCode } from './eviction/index.js';
10
+ import { TxPoolV2Instrumentation } from './instrumentation.js';
8
11
  import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
9
- import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } from './tx_metadata.js';
12
+ import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
13
+ import { TxPoolIndices } from './tx_pool_indices.js';
10
14
  /**
11
15
  * Implementation of TxPoolV2 logic.
12
16
  *
@@ -18,33 +22,33 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
18
22
  // === Dependencies ===
19
23
  #l2BlockSource;
20
24
  #worldStateSynchronizer;
21
- #pendingTxValidator;
25
+ #createTxValidator;
22
26
  // === In-Memory Indices ===
23
- /** Primary metadata store: txHash -> TxMetaData */ #metadata = new Map();
24
- /** Nullifier to txHash index (pending txs only) */ #nullifierToTxHash = new Map();
25
- /** Fee payer to txHashes index (pending txs only) */ #feePayerToTxHashes = new Map();
26
- /**
27
- * Pending txHashes grouped by priority fee.
28
- * Outer map: priorityFee -> Set of txHashes at that fee level.
29
- */ #pendingByPriority = new Map();
30
- /** Protected transactions: txHash -> slotNumber. Includes txs we have and txs we expect to receive. */ #protectedTransactions = new Map();
27
+ #indices = new TxPoolIndices();
31
28
  // === Config & Services ===
32
29
  #config;
33
30
  #archive;
31
+ #deletedPool;
34
32
  #evictionManager;
33
+ #dateProvider;
34
+ #instrumentation;
35
+ #evictedTxHashes = new Set();
35
36
  #log;
36
37
  #callbacks;
37
- constructor(store, archiveStore, deps, callbacks, config = {}, log){
38
+ constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
38
39
  this.#store = store;
39
40
  this.#txsDB = store.openMap('txs');
40
41
  this.#l2BlockSource = deps.l2BlockSource;
41
42
  this.#worldStateSynchronizer = deps.worldStateSynchronizer;
42
- this.#pendingTxValidator = deps.pendingTxValidator;
43
+ this.#createTxValidator = deps.createTxValidator;
43
44
  this.#config = {
44
45
  ...DEFAULT_TX_POOL_V2_CONFIG,
45
46
  ...config
46
47
  };
47
48
  this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
49
+ this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
50
+ this.#dateProvider = dateProvider;
51
+ this.#instrumentation = new TxPoolV2Instrumentation(telemetry, ()=>this.#indices.getTotalMetadataBytes());
48
52
  this.#log = log;
49
53
  this.#callbacks = callbacks;
50
54
  // Setup eviction manager with rules
@@ -75,20 +79,32 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
75
79
  * Note: Protected status is lost on restart. All non-mined txs are rebuilt as pending
76
80
  * by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
77
81
  */ async hydrateFromDatabase() {
78
- // Step 1: Load all transactions from DB
82
+ // Step 0: Hydrate deleted pool state
83
+ await this.#deletedPool.hydrateFromDatabase();
84
+ // Step 1: Load all transactions from DB (excluding soft-deleted)
79
85
  const { loaded, errors: deserializationErrors } = await this.#loadAllTxsFromDb();
80
86
  // Step 2: Check mined status for each tx
81
87
  await this.#markMinedStatusBatch(loaded.map((l)=>l.meta));
82
88
  // Step 3: Partition by mined status
83
- const { mined, nonMined } = this.#partitionByMinedStatus(loaded);
89
+ const mined = [];
90
+ const nonMined = [];
91
+ for (const entry of loaded){
92
+ if (entry.meta.minedL2BlockId !== undefined) {
93
+ mined.push(entry.meta);
94
+ } else {
95
+ nonMined.push(entry);
96
+ }
97
+ }
84
98
  // Step 4: Validate non-mined transactions
85
- const { valid, invalid } = await this.#validateNonMinedTxs(nonMined);
99
+ const { valid, invalid } = await this.#revalidateMetadata(nonMined.map((e)=>e.meta), 'on startup');
86
100
  // Step 5: Populate mined indices (these don't need conflict resolution)
87
- this.#populateMinedIndices(mined);
101
+ for (const meta of mined){
102
+ this.#indices.addMined(meta);
103
+ }
88
104
  // Step 6: Rebuild pending pool by running pre-add rules for each tx
89
105
  // This resolves nullifier conflicts, fee payer balance issues, and pool size limits
90
106
  const { rejected } = await this.#rebuildPendingPool(valid);
91
- // Step 7: Delete invalid and rejected txs from DB
107
+ // Step 7: Delete invalid and rejected txs from DB only (indices were never populated for these)
92
108
  const toDelete = [
93
109
  ...deserializationErrors,
94
110
  ...invalid,
@@ -102,104 +118,158 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
102
118
  await this.#txsDB.delete(txHashStr);
103
119
  }
104
120
  });
105
- this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`);
121
+ this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, {
122
+ txHashes: toDelete
123
+ });
106
124
  }
107
125
  async addPendingTxs(txs, opts) {
108
126
  const accepted = [];
109
127
  const ignored = [];
110
128
  const rejected = [];
111
- const newlyAdded = [];
129
+ const errors = new Map();
112
130
  const acceptedPending = new Set();
131
+ // Phase 1: Pre-compute all throwable I/O outside the transaction.
132
+ // If any pre-computation throws, the entire call fails before mutations happen.
133
+ const precomputed = new Map();
134
+ const validator = await this.#createTxValidator();
135
+ for (const tx of txs){
136
+ const txHash = tx.getTxHash();
137
+ const txHashStr = txHash.toString();
138
+ const meta = await buildTxMetaData(tx);
139
+ const minedBlockId = await this.#getMinedBlockId(txHash);
140
+ // Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
141
+ let isValid = true;
142
+ if (!minedBlockId) {
143
+ isValid = await this.#validateMeta(meta, validator);
144
+ }
145
+ precomputed.set(txHashStr, {
146
+ meta,
147
+ minedBlockId,
148
+ isValid
149
+ });
150
+ }
151
+ // Phase 2: Apply mutations inside the transaction using only pre-computed results,
152
+ // in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
113
153
  const poolAccess = this.#createPreAddPoolAccess();
154
+ const preAddContext = opts.feeComparisonOnly !== undefined ? {
155
+ feeComparisonOnly: opts.feeComparisonOnly,
156
+ priceBumpPercentage: this.#config.priceBumpPercentage
157
+ } : undefined;
114
158
  await this.#store.transactionAsync(async ()=>{
115
159
  for (const tx of txs){
116
160
  const txHash = tx.getTxHash();
117
161
  const txHashStr = txHash.toString();
118
162
  // Skip duplicates
119
- if (this.#isDuplicateTx(txHashStr)) {
163
+ if (this.#indices.has(txHashStr)) {
120
164
  ignored.push(txHash);
121
165
  continue;
122
166
  }
123
- // Check mined status first (applies to all paths)
124
- const minedBlockId = await this.#getMinedBlockId(txHash);
125
- const preProtectedSlot = this.#protectedTransactions.get(txHashStr);
167
+ const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
168
+ const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
126
169
  if (minedBlockId) {
127
170
  // Already mined - add directly (protection already set if pre-protected)
128
- await this.#addNewMinedTx(tx, minedBlockId);
171
+ await this.#addTx(tx, {
172
+ mined: minedBlockId
173
+ }, opts, meta);
129
174
  accepted.push(txHash);
130
- newlyAdded.push(tx);
131
175
  } else if (preProtectedSlot !== undefined) {
132
176
  // Pre-protected and not mined - add as protected (bypass validation)
133
- await this.#addNewProtectedTx(tx, preProtectedSlot);
177
+ await this.#addTx(tx, {
178
+ protected: preProtectedSlot
179
+ }, opts, meta);
134
180
  accepted.push(txHash);
135
- newlyAdded.push(tx);
181
+ } else if (!isValid) {
182
+ // Failed pre-computed validation
183
+ rejected.push(txHash);
136
184
  } else {
137
- // Regular pending tx - validate and run pre-add rules
138
- const result = await this.#tryAddRegularPendingTx(tx, poolAccess, acceptedPending, ignored);
185
+ // Regular pending tx - run pre-add rules using pre-computed metadata
186
+ const result = await this.#tryAddRegularPendingTx(tx, meta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
139
187
  if (result.status === 'accepted') {
140
188
  acceptedPending.add(txHashStr);
141
- newlyAdded.push(tx);
142
- } else if (result.status === 'rejected') {
143
- rejected.push(txHash);
144
189
  } else {
145
190
  ignored.push(txHash);
146
191
  }
147
192
  }
148
193
  }
194
+ // Run post-add eviction rules for pending txs (inside transaction for atomicity)
195
+ if (acceptedPending.size > 0) {
196
+ const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
197
+ const uniqueFeePayers = new Set(feePayers);
198
+ await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
199
+ ...uniqueFeePayers
200
+ ]);
201
+ }
149
202
  });
150
203
  // Build final accepted list for pending txs (excludes intra-batch evictions)
151
204
  for (const txHashStr of acceptedPending){
152
205
  accepted.push(TxHash.fromString(txHashStr));
153
206
  }
154
- // Run post-add eviction rules for pending txs
155
- if (acceptedPending.size > 0) {
156
- const feePayers = Array.from(acceptedPending).map((txHash)=>this.#metadata.get(txHash).feePayer);
157
- const uniqueFeePayers = new Set(feePayers);
158
- await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
159
- ...uniqueFeePayers
160
- ]);
207
+ // Record metrics
208
+ if (ignored.length > 0) {
209
+ this.#instrumentation.recordIgnored(ignored.length);
161
210
  }
162
- // Emit events
163
- if (newlyAdded.length > 0) {
164
- this.#callbacks.onTxsAdded(newlyAdded, opts);
211
+ if (rejected.length > 0) {
212
+ this.#instrumentation.recordRejected(rejected.length);
165
213
  }
166
214
  return {
167
215
  accepted,
168
216
  ignored,
169
- rejected
217
+ rejected,
218
+ ...errors.size > 0 ? {
219
+ errors
220
+ } : {}
170
221
  };
171
222
  }
172
- /** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, poolAccess, acceptedPending, ignored) {
173
- const txHash = tx.getTxHash();
174
- const txHashStr = txHash.toString();
175
- // Validate transaction
176
- const validationResult = await this.#pendingTxValidator.validateTx(tx);
177
- if (validationResult.result !== 'valid') {
178
- this.#log.info(`Rejecting tx ${txHashStr}: ${validationResult.reason?.join(', ')}`);
179
- return {
180
- status: 'rejected'
181
- };
182
- }
183
- // Build metadata and run pre-add rules
184
- const meta = await buildTxMetaData(tx);
185
- const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
223
+ /** Adds a validated pending tx, running pre-add rules and evicting conflicts. */ async #tryAddRegularPendingTx(tx, precomputedMeta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
224
+ const txHashStr = tx.getTxHash().toString();
225
+ // Run pre-add rules
226
+ const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
186
227
  if (preAddResult.shouldIgnore) {
187
- this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
228
+ this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
229
+ if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
230
+ errors.set(txHashStr, preAddResult.reason);
231
+ }
188
232
  return {
189
233
  status: 'ignored'
190
234
  };
191
235
  }
192
- // Evict conflicts (tracking intra-batch evictions)
193
- for (const evictHashStr of preAddResult.txHashesToEvict){
194
- await this.#deleteTx(evictHashStr);
195
- this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`);
196
- if (acceptedPending.has(evictHashStr)) {
197
- acceptedPending.delete(evictHashStr);
198
- ignored.push(TxHash.fromString(evictHashStr));
236
+ // Evict conflicts, grouped by rule name for metrics
237
+ if (preAddResult.evictions && preAddResult.evictions.length > 0) {
238
+ const byReason = new Map();
239
+ for (const { txHash: evictHash, reason } of preAddResult.evictions){
240
+ const group = byReason.get(reason);
241
+ if (group) {
242
+ group.push(evictHash);
243
+ } else {
244
+ byReason.set(reason, [
245
+ evictHash
246
+ ]);
247
+ }
248
+ }
249
+ for (const [reason, hashes] of byReason){
250
+ await this.#evictTxs(hashes, reason);
199
251
  }
252
+ for (const evictHashStr of preAddResult.txHashesToEvict){
253
+ this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
254
+ evictedTxHash: evictHashStr,
255
+ replacementTxHash: txHashStr
256
+ });
257
+ if (acceptedPending.has(evictHashStr)) {
258
+ // Evicted tx was from this batch - mark as ignored in result
259
+ acceptedPending.delete(evictHashStr);
260
+ ignored.push(TxHash.fromString(evictHashStr));
261
+ }
262
+ }
263
+ }
264
+ // Randomly drop the transaction for testing purposes (report as accepted so it propagates)
265
+ if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
266
+ this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
267
+ return {
268
+ status: 'accepted'
269
+ };
200
270
  }
201
271
  // Add the transaction
202
- await this.#addNewPendingTx(tx);
272
+ await this.#addTx(tx, 'pending', opts, precomputedMeta);
203
273
  return {
204
274
  status: 'accepted'
205
275
  };
@@ -207,89 +277,121 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
207
277
  async canAddPendingTx(tx) {
208
278
  const txHashStr = tx.getTxHash().toString();
209
279
  // Check if already in pool
210
- if (this.#metadata.has(txHashStr)) {
280
+ if (this.#indices.has(txHashStr)) {
281
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
211
282
  return 'ignored';
212
283
  }
213
- // Validate transaction
214
- const validationResult = await this.#pendingTxValidator.validateTx(tx);
215
- if (validationResult.result !== 'valid') {
216
- return 'rejected';
217
- }
218
- // Build metadata and use pre-add rules
284
+ // Build metadata and check pre-add rules
219
285
  const meta = await buildTxMetaData(tx);
220
286
  const poolAccess = this.#createPreAddPoolAccess();
221
287
  const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
222
- return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
288
+ if (preAddResult.shouldIgnore) {
289
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
290
+ reason: preAddResult.reason?.message ?? 'no reason provided'
291
+ });
292
+ return 'ignored';
293
+ }
294
+ return 'accepted';
223
295
  }
224
296
  async addProtectedTxs(txs, block, opts) {
225
297
  const slotNumber = block.globalVariables.slotNumber;
226
- const newlyAdded = [];
227
298
  await this.#store.transactionAsync(async ()=>{
228
299
  for (const tx of txs){
229
300
  const txHash = tx.getTxHash();
230
301
  const txHashStr = txHash.toString();
231
- const isNew = !this.#metadata.has(txHashStr);
302
+ const isNew = !this.#indices.has(txHashStr);
232
303
  const minedBlockId = await this.#getMinedBlockId(txHash);
233
304
  if (isNew) {
234
- // New tx - add as mined or protected
305
+ // New tx - add as mined or protected (callback emitted by #addTx)
235
306
  if (minedBlockId) {
236
- await this.#addNewMinedTx(tx, minedBlockId);
237
- this.#protectedTransactions.set(txHashStr, slotNumber);
307
+ await this.#addTx(tx, {
308
+ mined: minedBlockId
309
+ }, opts);
310
+ this.#indices.setProtection(txHashStr, slotNumber);
238
311
  } else {
239
- await this.#addNewProtectedTx(tx, slotNumber);
312
+ await this.#addTx(tx, {
313
+ protected: slotNumber
314
+ }, opts);
240
315
  }
241
- newlyAdded.push(tx);
242
316
  } else {
243
317
  // Existing tx - update protection and mined status
244
- this.#updateProtection(txHashStr, slotNumber);
318
+ this.#indices.updateProtection(txHashStr, slotNumber);
245
319
  if (minedBlockId) {
246
- this.#markAsMined(this.#metadata.get(txHashStr), minedBlockId);
320
+ const meta = this.#indices.getMetadata(txHashStr);
321
+ this.#indices.markAsMined(meta, minedBlockId);
247
322
  }
248
323
  }
249
324
  }
250
325
  });
251
- if (newlyAdded.length > 0) {
252
- this.#callbacks.onTxsAdded(newlyAdded, opts);
253
- }
254
326
  }
255
- protectTxs(txHashes, block) {
327
+ async protectTxs(txHashes, block) {
256
328
  const slotNumber = block.globalVariables.slotNumber;
257
329
  const missing = [];
258
- for (const txHash of txHashes){
259
- const txHashStr = txHash.toString();
260
- if (this.#metadata.has(txHashStr)) {
261
- // Step 1a: Update protection for existing tx
262
- this.#updateProtection(txHashStr, slotNumber);
263
- } else {
264
- // Step 1b: Pre-record protection for tx we don't have yet
265
- this.#protectedTransactions.set(txHashStr, slotNumber);
266
- missing.push(txHash);
330
+ let softDeletedHits = 0;
331
+ let missingPreviouslyEvicted = 0;
332
+ await this.#store.transactionAsync(async ()=>{
333
+ for (const txHash of txHashes){
334
+ const txHashStr = txHash.toString();
335
+ if (this.#indices.has(txHashStr)) {
336
+ // Update protection for existing tx
337
+ this.#indices.updateProtection(txHashStr, slotNumber);
338
+ } else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
339
+ // Resurrect soft-deleted tx as protected
340
+ const buffer = await this.#txsDB.getAsync(txHashStr);
341
+ if (buffer) {
342
+ const tx = Tx.fromBuffer(buffer);
343
+ await this.#addTx(tx, {
344
+ protected: slotNumber
345
+ });
346
+ softDeletedHits++;
347
+ } else {
348
+ // Data missing despite soft-delete flag — treat as truly missing
349
+ this.#indices.setProtection(txHashStr, slotNumber);
350
+ missing.push(txHash);
351
+ }
352
+ } else {
353
+ // Truly missing — pre-record protection for tx we don't have yet
354
+ this.#indices.setProtection(txHashStr, slotNumber);
355
+ missing.push(txHash);
356
+ if (this.#evictedTxHashes.has(txHashStr)) {
357
+ missingPreviouslyEvicted++;
358
+ }
359
+ }
267
360
  }
361
+ });
362
+ // Record metrics
363
+ if (softDeletedHits > 0) {
364
+ this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
365
+ }
366
+ if (missing.length > 0) {
367
+ this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
368
+ this.#instrumentation.recordMissingOnProtect(missing.length);
268
369
  }
370
+ if (missingPreviouslyEvicted > 0) {
371
+ this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
372
+ }
373
+ this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
269
374
  return missing;
270
375
  }
271
376
  async addMinedTxs(txs, block, opts) {
272
377
  // Step 1: Build block ID
273
378
  const blockId = await this.#buildBlockId(block);
274
- const newlyAdded = [];
275
379
  await this.#store.transactionAsync(async ()=>{
276
380
  for (const tx of txs){
277
381
  const txHashStr = tx.getTxHash().toString();
278
- const existingMeta = this.#metadata.get(txHashStr);
382
+ const existingMeta = this.#indices.getMetadata(txHashStr);
279
383
  if (existingMeta) {
280
- // Step 2a: Mark existing tx as mined
281
- this.#markAsMined(existingMeta, blockId);
384
+ // Mark existing tx as mined
385
+ this.#indices.markAsMined(existingMeta, blockId);
282
386
  } else {
283
- // Step 2b: Add new mined tx
284
- await this.#addNewMinedTx(tx, blockId);
285
- newlyAdded.push(tx);
387
+ // Add new mined tx (callback emitted by #addTx)
388
+ await this.#addTx(tx, {
389
+ mined: blockId
390
+ }, opts);
286
391
  }
392
+ await this.#deletedPool.clearIfMinedHigher(txHashStr, blockId.number);
287
393
  }
288
394
  });
289
- // Step 3: Emit events for newly added txs
290
- if (newlyAdded.length > 0) {
291
- this.#callbacks.onTxsAdded(newlyAdded, opts);
292
- }
293
395
  }
294
396
  async handleMinedBlock(block) {
295
397
  // Step 1: Build block ID
@@ -301,102 +403,141 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
301
403
  const feePayers = [];
302
404
  const found = [];
303
405
  for (const txHash of txHashes){
304
- const meta = this.#metadata.get(txHash.toString());
406
+ const meta = this.#indices.getMetadata(txHash.toString());
305
407
  if (meta) {
306
408
  feePayers.push(meta.feePayer);
307
409
  found.push(meta);
308
410
  }
309
411
  }
310
- // Step 4: Mark txs as mined (only those we have in the pool)
311
- this.#markTxsAsMined(found, blockId);
312
- // Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
313
- await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
314
- this.#callbacks.onTxsRemoved(txHashes.map((h)=>h.toBigInt()));
412
+ await this.#store.transactionAsync(async ()=>{
413
+ // Step 4: Mark txs as mined (only those we have in the pool)
414
+ for (const meta of found){
415
+ this.#indices.markAsMined(meta, blockId);
416
+ await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
417
+ }
418
+ // Step 5: Run post-event eviction rules (inside transaction for atomicity)
419
+ await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
420
+ });
421
+ if (found.length > 0) {
422
+ this.#callbacks.onTxsMined(found.map((m)=>m.txHash));
423
+ }
315
424
  this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
316
425
  }
317
426
  async prepareForSlot(slotNumber) {
318
- // Step 1: Find expired protected txs
319
- const expiredProtected = this.#findExpiredProtectedTxs(slotNumber);
320
- // Step 2: Clear protection for all expired entries (including those without metadata)
321
- this.#clearProtection(expiredProtected);
322
- // Step 3: Filter to only txs that have metadata and are not mined
323
- const txsToRestore = this.#filterRestorable(expiredProtected);
324
- if (txsToRestore.length === 0) {
325
- return;
326
- }
327
- this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
328
- // Step 4: Validate for pending pool
329
- const { valid, invalid } = await this.#validateForPending(txsToRestore);
330
- // Step 5: Resolve nullifier conflicts and add winners to pending indices
331
- const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
332
- // Step 6: Delete invalid and evicted txs
333
- await this.#deleteTxsBatch([
334
- ...invalid,
335
- ...toEvict
336
- ]);
337
- // Step 7: Run eviction rules (enforce pool size limit)
338
- if (added.length > 0) {
339
- const feePayers = added.map((meta)=>meta.feePayer);
340
- const uniqueFeePayers = new Set(feePayers);
341
- await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
342
- ...uniqueFeePayers
343
- ]);
344
- }
427
+ await this.#store.transactionAsync(async ()=>{
428
+ // Step 0: Clean up slot-deleted txs from previous slots
429
+ await this.#deletedPool.cleanupSlotDeleted(slotNumber);
430
+ // Step 1: Find expired protected txs
431
+ const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
432
+ // Step 2: Clear protection for all expired entries (including those without metadata)
433
+ this.#indices.clearProtection(expiredProtected);
434
+ // Step 3: Filter to only txs that have metadata and are not mined
435
+ const txsToRestore = this.#indices.filterRestorable(expiredProtected);
436
+ if (txsToRestore.length === 0) {
437
+ this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
438
+ return;
439
+ }
440
+ this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
441
+ // Step 4: Validate for pending pool
442
+ const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
443
+ // Step 5: Resolve nullifier conflicts and add winners to pending indices
444
+ const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
445
+ // Step 6: Delete invalid txs and evict conflict losers
446
+ await this.#deleteTxsBatch(invalid);
447
+ await this.#evictTxs(toEvict, 'NullifierConflict');
448
+ // Step 7: Run eviction rules (enforce pool size limit)
449
+ if (added.length > 0) {
450
+ const feePayers = added.map((meta)=>meta.feePayer);
451
+ const uniqueFeePayers = new Set(feePayers);
452
+ await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
453
+ ...uniqueFeePayers
454
+ ]);
455
+ }
456
+ });
345
457
  }
346
- async handlePrunedBlocks(latestBlock) {
458
+ async handlePrunedBlocks(latestBlock, options) {
347
459
  // Step 1: Find transactions mined after the prune point
348
- const txsToUnmine = this.#findTxsMinedAfter(latestBlock.number);
460
+ const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
349
461
  if (txsToUnmine.length === 0) {
350
462
  this.#log.debug(`No transactions to un-mine for prune to block ${latestBlock.number}`);
351
463
  return;
352
464
  }
353
465
  this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
354
- // Step 2: Unmine - clear mined status from metadata
355
- this.#unmineTxs(txsToUnmine);
356
- // Step 3: Filter out protected txs (they'll be handled by prepareForSlot)
357
- const unprotectedTxs = this.#filterUnprotected(txsToUnmine);
358
- // Step 4: Validate for pending pool
359
- const { valid, invalid } = await this.#validateForPending(unprotectedTxs);
360
- // Step 5: Resolve nullifier conflicts and add winners to pending indices
361
- const { toEvict } = this.#applyNullifierConflictResolution(valid);
362
- // Step 6: Delete invalid and evicted txs
363
- await this.#deleteTxsBatch([
364
- ...invalid,
365
- ...toEvict
366
- ]);
367
- // Step 7: Run eviction rules for ALL pending txs (not just restored ones)
368
- // This handles cases like existing pending txs with invalid fee payer balances
369
- await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
466
+ await this.#store.transactionAsync(async ()=>{
467
+ // Step 2: Mark ALL un-mined txs with their original mined block number
468
+ // This ensures they get soft-deleted if removed later, and only hard-deleted
469
+ // when their original mined block is finalized
470
+ await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
471
+ txHash: m.txHash,
472
+ minedAtBlock: BlockNumber(m.minedL2BlockId.number)
473
+ })));
474
+ // Step 3: Unmine - clear mined status from metadata
475
+ for (const meta of txsToUnmine){
476
+ this.#indices.markAsUnmined(meta);
477
+ }
478
+ // If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
479
+ if (options?.deleteAllTxs) {
480
+ const allTxHashes = txsToUnmine.map((m)=>m.txHash);
481
+ await this.#deleteTxsBatch(allTxHashes);
482
+ this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
483
+ return;
484
+ }
485
+ // Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
486
+ const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
487
+ // Step 5: Validate for pending pool
488
+ const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
489
+ // Step 6: Resolve nullifier conflicts and add winners to pending indices
490
+ const { toEvict } = this.#applyNullifierConflictResolution(valid);
491
+ // Step 7: Delete invalid txs and evict conflict losers
492
+ await this.#deleteTxsBatch(invalid);
493
+ await this.#evictTxs(toEvict, 'NullifierConflict');
494
+ this.#log.info(`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`, {
495
+ txHashesRestored: valid.map((m)=>m.txHash),
496
+ txHashesInvalid: invalid,
497
+ txHashesEvicted: toEvict
498
+ });
499
+ // Step 8: Run eviction rules for ALL pending txs (not just restored ones)
500
+ // This handles cases like existing pending txs with invalid fee payer balances
501
+ await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
502
+ });
370
503
  }
371
504
  async handleFailedExecution(txHashes) {
372
- // Step 1: Delete failed txs
373
- await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
374
- this.#log.info(`Deleted ${txHashes.length} failed txs`);
505
+ await this.#store.transactionAsync(async ()=>{
506
+ await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
507
+ });
508
+ this.#log.info(`Deleted ${txHashes.length} failed txs`, {
509
+ txHashes: txHashes.map((h)=>h.toString())
510
+ });
375
511
  }
376
512
  async handleFinalizedBlock(block) {
377
513
  const blockNumber = block.globalVariables.blockNumber;
378
- // Step 1: Find txs mined at or before finalized block
379
- const txsToFinalize = this.#findTxsMinedAtOrBefore(blockNumber);
380
- if (txsToFinalize.length === 0) {
381
- return;
382
- }
383
- // Step 2: Collect txs for archiving (before deletion)
384
- const txsToArchive = [];
385
- if (this.#archive.isEnabled()) {
386
- for (const txHashStr of txsToFinalize){
387
- const buffer = await this.#txsDB.getAsync(txHashStr);
388
- if (buffer) {
389
- txsToArchive.push(Tx.fromBuffer(buffer));
514
+ // Step 1: Find mined txs at or before finalized block
515
+ const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
516
+ await this.#store.transactionAsync(async ()=>{
517
+ // Step 2: Collect mined txs for archiving (before deletion)
518
+ const txsToArchive = [];
519
+ if (this.#archive.isEnabled()) {
520
+ for (const txHashStr of minedTxsToFinalize){
521
+ const buffer = await this.#txsDB.getAsync(txHashStr);
522
+ if (buffer) {
523
+ txsToArchive.push(Tx.fromBuffer(buffer));
524
+ }
390
525
  }
391
526
  }
527
+ // Step 3: Delete mined txs from active pool
528
+ await this.#deleteTxsBatch(minedTxsToFinalize);
529
+ // Step 4: Finalize soft-deleted txs
530
+ await this.#deletedPool.finalizeBlock(blockNumber);
531
+ // Step 5: Archive mined txs
532
+ if (txsToArchive.length > 0) {
533
+ await this.#archive.archiveTxs(txsToArchive);
534
+ }
535
+ });
536
+ if (minedTxsToFinalize.length > 0) {
537
+ this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
538
+ txHashes: minedTxsToFinalize
539
+ });
392
540
  }
393
- // Step 3: Delete from active pool
394
- await this.#deleteTxsBatch(txsToFinalize);
395
- // Step 4: Archive
396
- if (txsToArchive.length > 0) {
397
- await this.#archive.archiveTxs(txsToArchive);
398
- }
399
- this.#log.info(`Finalized ${txsToFinalize.length} txs from blocks up to ${blockNumber}`);
400
541
  }
401
542
  // === Query Methods ===
402
543
  async getTxByHash(txHash) {
@@ -412,42 +553,46 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
412
553
  return results;
413
554
  }
414
555
  hasTxs(txHashes) {
415
- return txHashes.map((h)=>this.#metadata.has(h.toString()));
556
+ return txHashes.map((h)=>{
557
+ const hashStr = h.toString();
558
+ return this.#indices.has(hashStr) || this.#deletedPool.isSoftDeleted(hashStr);
559
+ });
416
560
  }
417
561
  getTxStatus(txHash) {
418
- const meta = this.#metadata.get(txHash.toString());
419
- if (!meta) {
420
- return undefined;
562
+ const txHashStr = txHash.toString();
563
+ const meta = this.#indices.getMetadata(txHashStr);
564
+ if (meta) {
565
+ return this.#indices.getTxState(meta);
566
+ }
567
+ // Check if soft-deleted
568
+ if (this.#deletedPool.isSoftDeleted(txHashStr)) {
569
+ return 'deleted';
421
570
  }
422
- return this.#getTxState(meta);
571
+ return undefined;
423
572
  }
424
573
  getPendingTxHashes() {
425
574
  return [
426
- ...this.#iteratePendingByPriority('desc')
575
+ ...this.#indices.iteratePendingByPriority('desc')
576
+ ].map((hash)=>TxHash.fromString(hash));
577
+ }
578
+ getEligiblePendingTxHashes() {
579
+ const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
580
+ return [
581
+ ...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)
427
582
  ].map((hash)=>TxHash.fromString(hash));
428
583
  }
429
584
  getPendingTxCount() {
430
- let count = 0;
431
- for (const hashes of this.#pendingByPriority.values()){
432
- count += hashes.size;
433
- }
434
- return count;
585
+ return this.#indices.getPendingTxCount();
435
586
  }
436
587
  getMinedTxHashes() {
437
- const result = [];
438
- for (const [txHash, meta] of this.#metadata){
439
- if (meta.minedL2BlockId !== undefined) {
440
- result.push([
441
- TxHash.fromString(txHash),
442
- meta.minedL2BlockId
443
- ]);
444
- }
445
- }
446
- return result;
588
+ return this.#indices.getMinedTxs().map(([hash, blockId])=>[
589
+ TxHash.fromString(hash),
590
+ blockId
591
+ ]);
447
592
  }
448
593
  getMinedTxCount() {
449
594
  let count = 0;
450
- for (const meta of this.#metadata.values()){
595
+ for (const [, meta] of this.#indices.iterateMetadata()){
451
596
  if (meta.minedL2BlockId !== undefined) {
452
597
  count++;
453
598
  }
@@ -455,26 +600,16 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
455
600
  return count;
456
601
  }
457
602
  isEmpty() {
458
- return this.#metadata.size === 0;
603
+ return this.#indices.isEmpty();
459
604
  }
460
605
  getTxCount() {
461
- return this.#metadata.size;
606
+ return this.#indices.getTxCount();
462
607
  }
463
608
  getArchivedTxByHash(txHash) {
464
609
  return this.#archive.getTxByHash(txHash);
465
610
  }
466
611
  getLowestPriorityPending(limit) {
467
- if (limit <= 0) {
468
- return [];
469
- }
470
- const result = [];
471
- for (const hash of this.#iteratePendingByPriority('asc')){
472
- result.push(TxHash.fromString(hash));
473
- if (result.length >= limit) {
474
- break;
475
- }
476
- }
477
- return result;
612
+ return this.#indices.getLowestPriorityPending(limit).map((h)=>TxHash.fromString(h));
478
613
  }
479
614
  // === Configuration ===
480
615
  updateConfig(config) {
@@ -485,138 +620,122 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
485
620
  this.#config.archivedTxLimit = config.archivedTxLimit;
486
621
  this.#archive.updateLimit(config.archivedTxLimit);
487
622
  }
623
+ if (config.minTxPoolAgeMs !== undefined) {
624
+ this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
625
+ }
488
626
  // Update eviction rules with new config
489
627
  this.#evictionManager.updateConfig(config);
490
628
  }
491
629
  // === Pool Read Access ===
492
630
  getPoolReadAccess() {
493
631
  return {
494
- getMetadata: (txHash)=>this.#metadata.get(txHash),
495
- getTxHashByNullifier: (nullifier)=>this.#nullifierToTxHash.get(nullifier),
496
- getTxHashesByFeePayer: (feePayer)=>this.#feePayerToTxHashes.get(feePayer),
497
- getPendingTxCount: ()=>this.getPendingTxCount()
632
+ getMetadata: (txHash)=>this.#indices.getMetadata(txHash),
633
+ getTxHashByNullifier: (nullifier)=>this.#indices.getTxHashByNullifier(nullifier),
634
+ getTxHashesByFeePayer: (feePayer)=>this.#indices.getTxHashesByFeePayer(feePayer),
635
+ getPendingTxCount: ()=>this.#indices.getPendingTxCount()
498
636
  };
499
637
  }
500
638
  // === Metrics ===
501
639
  countTxs() {
502
- let pending = 0;
503
- let protected_ = 0;
504
- let mined = 0;
505
- for (const meta of this.#metadata.values()){
506
- const state = this.#getTxState(meta);
507
- if (state === 'pending') {
508
- pending++;
509
- } else if (state === 'protected') {
510
- protected_++;
511
- } else if (state === 'mined') {
512
- mined++;
513
- }
514
- }
515
640
  return {
516
- pending,
517
- protected: protected_,
518
- mined
641
+ ...this.#indices.countTxs(),
642
+ softDeleted: this.#deletedPool.getSoftDeletedCount()
519
643
  };
520
644
  }
521
645
  // ============================================================================
522
- // PRIVATE QUERY IMPLEMENTATIONS
646
+ // PRIVATE HELPERS - Transaction Management
523
647
  // ============================================================================
524
648
  /**
525
- * Derives the transaction state from its metadata and protection status.
526
- * A transaction is:
527
- * - 'mined' if it has a minedL2BlockId
528
- * - 'protected' if it's in the protectedTransactions map (but not mined)
529
- * - 'pending' otherwise
530
- */ #getTxState(meta) {
531
- if (meta.minedL2BlockId !== undefined) {
532
- return 'mined';
533
- } else if (this.#protectedTransactions.has(meta.txHash)) {
534
- return 'protected';
649
+ * Adds a new transaction to the pool with the specified state.
650
+ * Emits onTxsAdded callback immediately after DB write.
651
+ */ async #addTx(tx, state, opts = {}, precomputedMeta) {
652
+ const txHashStr = tx.getTxHash().toString();
653
+ const meta = precomputedMeta ?? await buildTxMetaData(tx);
654
+ meta.receivedAt = this.#dateProvider.now();
655
+ await this.#txsDB.set(txHashStr, tx.toBuffer());
656
+ await this.#deletedPool.clearSoftDeleted(txHashStr);
657
+ this.#callbacks.onTxsAdded([
658
+ tx
659
+ ], opts);
660
+ if (state === 'pending') {
661
+ this.#indices.addPending(meta);
662
+ } else if ('protected' in state) {
663
+ this.#indices.addProtected(meta, state.protected);
535
664
  } else {
536
- return 'pending';
665
+ meta.minedL2BlockId = state.mined;
666
+ this.#indices.addMined(meta);
537
667
  }
668
+ const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
669
+ this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
670
+ eventName: 'tx-added-to-pool',
671
+ txHash: txHashStr,
672
+ state: stateStr,
673
+ source: opts.source
674
+ });
675
+ return meta;
538
676
  }
539
677
  /**
540
- * Iterates pending transaction hashes in priority order.
541
- * @param order - 'desc' for highest priority first, 'asc' for lowest priority first
542
- */ *#iteratePendingByPriority(order) {
543
- // Use shared comparators, negating for descending order
544
- const feeCompareFn = order === 'desc' ? (a, b)=>compareFee(b, a) : (a, b)=>compareFee(a, b);
545
- const hashCompareFn = order === 'desc' ? (a, b)=>compareTxHash(b, a) : (a, b)=>compareTxHash(a, b);
546
- const sortedFees = [
547
- ...this.#pendingByPriority.keys()
548
- ].sort(feeCompareFn);
549
- for (const fee of sortedFees){
550
- const hashesAtFee = this.#pendingByPriority.get(fee);
551
- const sortedHashes = [
552
- ...hashesAtFee
553
- ].sort(hashCompareFn);
554
- for (const hash of sortedHashes){
555
- yield hash;
556
- }
557
- }
678
+ * Deletes a transaction from both indices and DB.
679
+ * Emits onTxsRemoved callback immediately after DB delete.
680
+ */ /**
681
+ * Deletes a transaction from the pool.
682
+ * Delegates to DeletedPool which decides soft vs hard delete based on whether
683
+ * the tx is from a pruned block.
684
+ */ async #deleteTx(txHashStr) {
685
+ this.#indices.remove(txHashStr);
686
+ this.#callbacks.onTxsRemoved([
687
+ txHashStr
688
+ ]);
689
+ await this.#deletedPool.deleteTx(txHashStr);
558
690
  }
559
- // ============================================================================
560
- // HELPER FUNCTIONS - Pipeline Step Functions
561
- // ============================================================================
562
- // --- Finding & Filtering Steps ---
563
- /** Finds all transactions mined in blocks after the given block number */ #findTxsMinedAfter(blockNumber) {
564
- const result = [];
565
- for (const meta of this.#metadata.values()){
566
- if (meta.minedL2BlockId !== undefined && meta.minedL2BlockId.number > blockNumber) {
567
- result.push(meta);
568
- }
691
+ /** Deletes a batch of transactions, emitting callbacks individually for each. */ async #deleteTxsBatch(txHashes) {
692
+ for (const txHashStr of txHashes){
693
+ await this.#deleteTx(txHashStr);
569
694
  }
570
- return result;
571
695
  }
572
- /** Finds tx hashes mined at or before the given block number */ #findTxsMinedAtOrBefore(blockNumber) {
573
- const result = [];
574
- for (const [txHashStr, meta] of this.#metadata){
575
- if (meta.minedL2BlockId !== undefined && meta.minedL2BlockId.number <= blockNumber) {
576
- result.push(txHashStr);
577
- }
696
+ /** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
697
+ if (txHashes.length === 0) {
698
+ return;
578
699
  }
579
- return result;
580
- }
581
- /** Finds protected tx hashes from slots earlier than the given slot number */ #findExpiredProtectedTxs(slotNumber) {
582
- const result = [];
583
- for (const [txHashStr, protectedSlot] of this.#protectedTransactions){
584
- if (protectedSlot < slotNumber) {
585
- result.push(txHashStr);
586
- }
700
+ this.#instrumentation.recordEvictions(txHashes.length, reason);
701
+ for (const txHashStr of txHashes){
702
+ this.#log.debug(`Evicting tx ${txHashStr}`, {
703
+ txHash: txHashStr,
704
+ reason
705
+ });
706
+ this.#addToEvictedCache(txHashStr);
587
707
  }
588
- return result;
708
+ await this.#deleteTxsBatch(txHashes);
589
709
  }
590
- /** Filters out transactions that are currently protected */ #filterUnprotected(txs) {
591
- return txs.filter((meta)=>!this.#protectedTransactions.has(meta.txHash));
710
+ /** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
711
+ if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
712
+ // FIFO eviction: remove the first (oldest) entry
713
+ const oldest = this.#evictedTxHashes.values().next().value;
714
+ this.#evictedTxHashes.delete(oldest);
715
+ }
716
+ this.#evictedTxHashes.add(txHashStr);
592
717
  }
593
- /** Filters to transactions that have metadata and are not mined */ #filterRestorable(txHashes) {
594
- const result = [];
595
- for (const txHashStr of txHashes){
596
- const meta = this.#metadata.get(txHashStr);
597
- if (meta && meta.minedL2BlockId === undefined) {
598
- result.push(meta);
599
- }
718
+ // ============================================================================
719
+ // PRIVATE HELPERS - Validation & Conflict Resolution
720
+ // ============================================================================
721
+ /** Validates transaction metadata, returning true if valid */ async #validateMeta(meta, validator, context) {
722
+ const txValidator = validator ?? await this.#createTxValidator();
723
+ const result = await txValidator.validateTx(meta);
724
+ if (result.result !== 'valid') {
725
+ const contextStr = context ? ` ${context}` : '';
726
+ this.#log.info(`Tx ${meta.txHash}${contextStr} failed validation: ${result.reason?.join(', ')}`);
727
+ return false;
600
728
  }
601
- return result;
729
+ return true;
602
730
  }
603
- // --- Validation & Conflict Resolution Steps ---
604
- /** Validates transactions for pending pool, returning valid and invalid groups */ async #validateForPending(txs) {
731
+ /** Validates metadata directly */ async #revalidateMetadata(metas, context) {
605
732
  const valid = [];
606
733
  const invalid = [];
607
- for (const meta of txs){
608
- const buffer = await this.#txsDB.getAsync(meta.txHash);
609
- if (!buffer) {
610
- this.#log.warn(`Tx ${meta.txHash} not found in DB during validation`);
611
- invalid.push(meta.txHash);
612
- continue;
613
- }
614
- const tx = Tx.fromBuffer(buffer);
615
- const result = await this.#pendingTxValidator.validateTx(tx);
616
- if (result.result === 'valid') {
734
+ const validator = await this.#createTxValidator();
735
+ for (const meta of metas){
736
+ if (await this.#validateMeta(meta, validator, context)) {
617
737
  valid.push(meta);
618
738
  } else {
619
- this.#log.info(`Tx ${meta.txHash} failed validation: ${result.reason?.join(', ')}`);
620
739
  invalid.push(meta.txHash);
621
740
  }
622
741
  }
@@ -633,7 +752,7 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
633
752
  const added = [];
634
753
  const toEvict = [];
635
754
  for (const meta of txs){
636
- const conflict = checkNullifierConflict(meta, (nullifier)=>this.#nullifierToTxHash.get(nullifier), (txHash)=>this.#metadata.get(txHash));
755
+ const conflict = checkNullifierConflict(meta, (nullifier)=>this.#indices.getTxHashByNullifier(nullifier), (txHash)=>this.#indices.getMetadata(txHash));
637
756
  if (conflict.shouldIgnore) {
638
757
  // Lower priority than existing - don't add, mark for deletion
639
758
  toEvict.push(meta.txHash);
@@ -642,13 +761,13 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
642
761
  toEvict.push(...conflict.txHashesToEvict);
643
762
  // Remove evicted from indices immediately for subsequent checks
644
763
  for (const evictHash of conflict.txHashesToEvict){
645
- const evictMeta = this.#metadata.get(evictHash);
764
+ const evictMeta = this.#indices.getMetadata(evictHash);
646
765
  if (evictMeta) {
647
- this.#removeFromPendingIndices(evictMeta);
766
+ this.#indices.removeFromPendingIndices(evictMeta);
648
767
  }
649
768
  }
650
769
  // Add to pending indices immediately so subsequent txs in the batch see this tx
651
- this.#addToPendingIndices(meta);
770
+ this.#indices.addToPendingIndices(meta);
652
771
  added.push(meta);
653
772
  }
654
773
  }
@@ -657,32 +776,10 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
657
776
  toEvict
658
777
  };
659
778
  }
660
- // --- State Transition Steps ---
661
- /** Clears the mined status from transactions, returning them for further processing */ #unmineTxs(txs) {
662
- for (const meta of txs){
663
- meta.minedL2BlockId = undefined;
664
- }
665
- return txs;
666
- }
667
- /** Removes protection from tx hashes and clears them from the protected map */ #clearProtection(txHashes) {
668
- for (const txHashStr of txHashes){
669
- this.#protectedTransactions.delete(txHashStr);
670
- }
671
- }
672
- // --- Batch Operation Steps ---
673
- /** Deletes a batch of transactions permanently */ async #deleteTxsBatch(txHashes) {
674
- if (txHashes.length === 0) {
675
- return;
676
- }
677
- await this.#store.transactionAsync(async ()=>{
678
- for (const txHashStr of txHashes){
679
- await this.#deleteTx(txHashStr);
680
- }
681
- });
682
- this.#callbacks.onTxsRemoved(txHashes);
683
- }
684
- // --- Block & Tx Info Steps ---
685
- /** Builds a block ID from a block header */ async #buildBlockId(block) {
779
+ // ============================================================================
780
+ // PRIVATE HELPERS - Block & Hydration
781
+ // ============================================================================
782
+ async #buildBlockId(block) {
686
783
  return {
687
784
  number: block.globalVariables.blockNumber,
688
785
  hash: (await block.hash()).toString()
@@ -698,40 +795,14 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
698
795
  hash: txEffect.l2BlockHash.toString()
699
796
  };
700
797
  }
701
- /** Marks a batch of transactions as mined */ #markTxsAsMined(metas, blockId) {
702
- for (const meta of metas){
703
- this.#markAsMined(meta, blockId);
704
- }
705
- }
706
- // --- Add Transaction Steps ---
707
- /** Persists a transaction to the database */ async #persistTx(txHashStr, tx) {
708
- await this.#txsDB.set(txHashStr, tx.toBuffer());
709
- }
710
- /** Adds a new transaction as protected, returning its metadata */ async #addNewProtectedTx(tx, slotNumber) {
711
- const txHashStr = tx.getTxHash().toString();
712
- const meta = await buildTxMetaData(tx);
713
- this.#protectedTransactions.set(txHashStr, slotNumber);
714
- await this.#persistTx(txHashStr, tx);
715
- this.#metadata.set(txHashStr, meta);
716
- // Don't add to pending indices since it's protected
717
- this.#log.verbose(`Added protected tx ${txHashStr} for slot ${slotNumber}`);
718
- return meta;
719
- }
720
- /** Adds a new transaction as mined, returning its metadata */ async #addNewMinedTx(tx, blockId) {
721
- const txHashStr = tx.getTxHash().toString();
722
- const meta = await buildTxMetaData(tx);
723
- meta.minedL2BlockId = blockId;
724
- await this.#persistTx(txHashStr, tx);
725
- this.#metadata.set(txHashStr, meta);
726
- // Don't add to pending indices since it's mined
727
- this.#log.verbose(`Added mined tx ${txHashStr} from block ${blockId.number}`);
728
- return meta;
729
- }
730
- // --- Hydration Steps ---
731
798
  /** Loads all transactions from the database, returning loaded txs and deserialization errors */ async #loadAllTxsFromDb() {
732
799
  const loaded = [];
733
800
  const errors = [];
734
801
  for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()){
802
+ // Skip soft-deleted transactions - they stay in DB but not in indices
803
+ if (this.#deletedPool.isSoftDeleted(txHashStr)) {
804
+ continue;
805
+ }
735
806
  try {
736
807
  const tx = Tx.fromBuffer(buffer);
737
808
  const meta = await buildTxMetaData(tx);
@@ -768,43 +839,6 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
768
839
  }
769
840
  }
770
841
  }
771
- /** Partitions transactions by mined status */ #partitionByMinedStatus(txs) {
772
- const mined = [];
773
- const nonMined = [];
774
- for (const entry of txs){
775
- if (entry.meta.minedL2BlockId !== undefined) {
776
- mined.push(entry.meta);
777
- } else {
778
- nonMined.push(entry);
779
- }
780
- }
781
- return {
782
- mined,
783
- nonMined
784
- };
785
- }
786
- /** Validates non-mined transactions, returning valid metadata and invalid hashes */ async #validateNonMinedTxs(txs) {
787
- const valid = [];
788
- const invalid = [];
789
- for (const { tx, meta } of txs){
790
- const result = await this.#pendingTxValidator.validateTx(tx);
791
- if (result.result === 'valid') {
792
- valid.push(meta);
793
- } else {
794
- this.#log.info(`Removing invalid tx ${meta.txHash} on startup: ${result.reason?.join(', ')}`);
795
- invalid.push(meta.txHash);
796
- }
797
- }
798
- return {
799
- valid,
800
- invalid
801
- };
802
- }
803
- /** Populates metadata index for mined transactions */ #populateMinedIndices(metas) {
804
- for (const meta of metas){
805
- this.#metadata.set(meta.txHash, meta);
806
- }
807
- }
808
842
  /**
809
843
  * Rebuilds the pending pool by processing each tx through pre-add rules.
810
844
  * Starts with an empty pending pool and adds txs one by one, resolving conflicts.
@@ -819,22 +853,22 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
819
853
  if (preAddResult.shouldIgnore) {
820
854
  // Transaction rejected - mark for deletion from DB
821
855
  rejected.push(meta.txHash);
822
- this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
856
+ this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
823
857
  continue;
824
858
  }
825
859
  // Evict any conflicting txs identified by pre-add rules
826
860
  for (const evictHashStr of preAddResult.txHashesToEvict){
827
- const evictMeta = this.#metadata.get(evictHashStr);
861
+ const evictMeta = this.#indices.getMetadata(evictHashStr);
828
862
  if (evictMeta) {
829
- this.#removeFromPendingIndices(evictMeta);
830
- this.#metadata.delete(evictHashStr);
863
+ this.#indices.removeFromPendingIndices(evictMeta);
864
+ this.#indices.remove(evictHashStr);
831
865
  rejected.push(evictHashStr);
832
866
  accepted.delete(evictHashStr);
833
867
  this.#log.debug(`Evicted tx ${evictHashStr} during rebuild due to conflict with ${meta.txHash}`);
834
868
  }
835
869
  }
836
- // Add to metadata and pending indices
837
- this.#addToIndices(meta);
870
+ // Add to indices
871
+ this.#indices.addPending(meta);
838
872
  accepted.add(meta.txHash);
839
873
  }
840
874
  this.#log.info(`Rebuilt pending pool: ${accepted.size} accepted, ${rejected.length} rejected`);
@@ -845,197 +879,38 @@ import { buildTxMetaData, checkNullifierConflict, compareFee, compareTxHash } fr
845
879
  rejected
846
880
  };
847
881
  }
848
- // --- Add Pending Tx Steps ---
849
- /** Checks if a tx is a duplicate (already in pool) */ #isDuplicateTx(txHashStr) {
850
- return this.#metadata.has(txHashStr);
851
- }
852
- /** Adds a new pending tx to the pool, returning its metadata */ async #addNewPendingTx(tx) {
853
- const txHashStr = tx.getTxHash().toString();
854
- const meta = await buildTxMetaData(tx);
855
- await this.#persistTx(txHashStr, tx);
856
- this.#addToIndices(meta);
857
- this.#log.verbose(`Added tx ${txHashStr} to pool`, {
858
- eventName: 'tx-added-to-pool',
859
- state: this.#getTxState(meta)
860
- });
861
- return meta;
862
- }
863
- // ============================================================================
864
- // HELPER FUNCTIONS - Index Management
865
- // ============================================================================
866
- #addToIndices(meta) {
867
- this.#metadata.set(meta.txHash, meta);
868
- if (this.#getTxState(meta) === 'pending') {
869
- this.#addToPendingIndices(meta);
870
- }
871
- // Protected and mined txs don't go into pending indices
872
- }
873
- #addToPendingIndices(meta) {
874
- // Add to nullifier index
875
- for (const nullifier of meta.nullifiers){
876
- this.#nullifierToTxHash.set(nullifier, meta.txHash);
877
- }
878
- // Add to fee payer index
879
- let feePayerSet = this.#feePayerToTxHashes.get(meta.feePayer);
880
- if (!feePayerSet) {
881
- feePayerSet = new Set();
882
- this.#feePayerToTxHashes.set(meta.feePayer, feePayerSet);
883
- }
884
- feePayerSet.add(meta.txHash);
885
- // Add to priority bucket
886
- let prioritySet = this.#pendingByPriority.get(meta.priorityFee);
887
- if (!prioritySet) {
888
- prioritySet = new Set();
889
- this.#pendingByPriority.set(meta.priorityFee, prioritySet);
890
- }
891
- prioritySet.add(meta.txHash);
892
- }
893
- #removeFromPendingIndices(meta) {
894
- // Remove from nullifier index
895
- for (const nullifier of meta.nullifiers){
896
- this.#nullifierToTxHash.delete(nullifier);
897
- }
898
- // Remove from fee payer index
899
- const feePayerSet = this.#feePayerToTxHashes.get(meta.feePayer);
900
- if (feePayerSet) {
901
- feePayerSet.delete(meta.txHash);
902
- if (feePayerSet.size === 0) {
903
- this.#feePayerToTxHashes.delete(meta.feePayer);
904
- }
905
- }
906
- // Remove from priority map
907
- const hashSet = this.#pendingByPriority.get(meta.priorityFee);
908
- if (hashSet) {
909
- hashSet.delete(meta.txHash);
910
- if (hashSet.size === 0) {
911
- this.#pendingByPriority.delete(meta.priorityFee);
912
- }
913
- }
914
- }
915
- #updateProtection(txHashStr, slotNumber) {
916
- const currentSlot = this.#protectedTransactions.get(txHashStr);
917
- // Only update if not already protected at an equal or later slot
918
- if (currentSlot !== undefined && currentSlot >= slotNumber) {
919
- return;
920
- }
921
- // Remove from pending indices if transitioning from pending to protected
922
- if (currentSlot === undefined) {
923
- const meta = this.#metadata.get(txHashStr);
924
- if (meta) {
925
- this.#removeFromPendingIndices(meta);
926
- }
927
- }
928
- this.#protectedTransactions.set(txHashStr, slotNumber);
929
- }
930
- #markAsMined(meta, blockId) {
931
- meta.minedL2BlockId = blockId;
932
- // Safe to call unconditionally - removeFromPendingIndices is idempotent
933
- this.#removeFromPendingIndices(meta);
934
- }
935
- async #deleteTx(txHashStr) {
936
- const meta = this.#metadata.get(txHashStr);
937
- if (!meta) {
938
- return;
939
- }
940
- // Remove from all indices
941
- this.#metadata.delete(txHashStr);
942
- this.#protectedTransactions.delete(txHashStr);
943
- this.#removeFromPendingIndices(meta);
944
- // Remove from persistence
945
- await this.#txsDB.delete(txHashStr);
946
- }
947
882
  // ============================================================================
948
- // HELPER FUNCTIONS - Adapters
883
+ // PRIVATE HELPERS - Pool Access Adapters
949
884
  // ============================================================================
950
- /** Gets all pending transactions for a given fee payer. */ #getFeePayerPendingTxs(feePayer) {
951
- const txHashes = this.#feePayerToTxHashes.get(feePayer);
952
- if (!txHashes) {
953
- return [];
954
- }
955
- const result = [];
956
- for (const txHashStr of txHashes){
957
- const meta = this.#metadata.get(txHashStr);
958
- if (meta && this.#getTxState(meta) === 'pending') {
959
- result.push(meta);
960
- }
961
- }
962
- return result;
963
- }
964
- /**
965
- * Creates a PoolOperations adapter for use with the eviction manager.
966
- */ #createPoolOperations() {
885
+ #createPoolOperations() {
967
886
  return {
968
- getPendingTxs: ()=>{
969
- const result = [];
970
- for (const hashSet of this.#pendingByPriority.values()){
971
- for (const txHashStr of hashSet){
972
- const meta = this.#metadata.get(txHashStr);
973
- if (meta) {
974
- result.push(meta);
975
- }
976
- }
977
- }
978
- return result;
979
- },
980
- getPendingFeePayers: ()=>{
981
- return Array.from(this.#feePayerToTxHashes.keys());
982
- },
983
- getFeePayerPendingTxs: (feePayer)=>{
984
- return this.#getFeePayerPendingTxs(feePayer);
985
- },
986
- getPendingTxCount: ()=>{
987
- return this.getPendingTxCount();
988
- },
989
- getLowestPriorityPending: (limit)=>{
990
- return this.getLowestPriorityPending(limit).map((h)=>h.toString());
991
- },
992
- deleteTxs: async (txHashes)=>{
993
- await this.#store.transactionAsync(async ()=>{
994
- for (const txHashStr of txHashes){
995
- await this.#deleteTx(txHashStr);
996
- }
997
- });
998
- this.#callbacks.onTxsRemoved(txHashes);
999
- }
887
+ getPendingTxs: ()=>this.#indices.getPendingTxs(),
888
+ getPendingFeePayers: ()=>this.#indices.getPendingFeePayers(),
889
+ getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
890
+ getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
891
+ getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
892
+ deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
1000
893
  };
1001
894
  }
1002
- /**
1003
- * Creates a PreAddPoolAccess adapter for use with pre-add eviction rules.
1004
- * All methods work with strings and TxMetaData for efficiency.
1005
- */ #createPreAddPoolAccess() {
895
+ #createPreAddPoolAccess() {
1006
896
  return {
1007
897
  getMetadata: (txHashStr)=>{
1008
- const meta = this.#metadata.get(txHashStr);
1009
- if (!meta || this.#getTxState(meta) !== 'pending') {
898
+ const meta = this.#indices.getMetadata(txHashStr);
899
+ if (!meta || this.#indices.getTxState(meta) !== 'pending') {
1010
900
  return undefined;
1011
901
  }
1012
902
  return meta;
1013
903
  },
1014
- getTxHashByNullifier: (nullifier)=>{
1015
- return this.#nullifierToTxHash.get(nullifier);
1016
- },
904
+ getTxHashByNullifier: (nullifier)=>this.#indices.getTxHashByNullifier(nullifier),
1017
905
  getFeePayerBalance: async (feePayer)=>{
1018
906
  const db = this.#worldStateSynchronizer.getCommitted();
1019
907
  const publicStateSource = new DatabasePublicStateSource(db);
1020
908
  const balance = await publicStateSource.storageRead(ProtocolContractAddress.FeeJuice, await computeFeePayerBalanceStorageSlot(AztecAddress.fromString(feePayer)));
1021
909
  return balance.toBigInt();
1022
910
  },
1023
- getFeePayerPendingTxs: (feePayer)=>{
1024
- return this.#getFeePayerPendingTxs(feePayer);
1025
- },
1026
- getPendingTxCount: ()=>{
1027
- return this.getPendingTxCount();
1028
- },
1029
- getLowestPriorityPendingTx: ()=>{
1030
- // Iterate in ascending order to find the lowest priority
1031
- for (const txHashStr of this.#iteratePendingByPriority('asc')){
1032
- const meta = this.#metadata.get(txHashStr);
1033
- if (meta) {
1034
- return meta;
1035
- }
1036
- }
1037
- return undefined;
1038
- }
911
+ getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
912
+ getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
913
+ getLowestPriorityPendingTx: ()=>this.#indices.getLowestPriorityPendingTx()
1039
914
  };
1040
915
  }
1041
916
  }