@aztec/p2p 0.0.1-commit.0c875d939 → 0.0.1-commit.10bd49492

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 (290) hide show
  1. package/dest/client/factory.d.ts +7 -7
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +24 -28
  4. package/dest/client/interface.d.ts +10 -19
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +7 -18
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +47 -96
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
  10. package/dest/config.d.ts +28 -15
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +76 -37
  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/mem_pools/attestation_pool/attestation_pool.d.ts +1 -1
  17. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool.js +5 -1
  19. package/dest/mem_pools/instrumentation.d.ts +4 -2
  20. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  21. package/dest/mem_pools/instrumentation.js +16 -14
  22. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  23. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  24. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool/priority.js +4 -3
  26. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  27. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  29. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -1
  30. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
  32. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  33. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  34. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  35. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -3
  36. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  37. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  38. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  39. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  40. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  41. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  43. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +4 -4
  46. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -5
  47. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  48. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +12 -6
  50. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  51. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  53. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  54. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  56. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  57. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  59. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  60. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  62. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +18 -6
  63. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
  65. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +46 -14
  66. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  67. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +99 -17
  68. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
  69. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +38 -46
  71. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +6 -3
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +9 -5
  74. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -5
  75. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +285 -149
  77. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  78. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  79. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  80. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  81. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  82. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  83. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  84. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  85. package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
  86. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  87. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  88. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  89. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  90. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  91. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  92. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  93. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  94. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  95. package/dest/msg_validators/tx_validator/factory.d.ts +125 -6
  96. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/factory.js +226 -58
  98. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  99. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  101. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  104. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  105. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  106. package/dest/msg_validators/tx_validator/index.js +2 -0
  107. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  108. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  110. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  111. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  112. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  113. package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
  114. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  115. package/dest/msg_validators/tx_validator/phases_validator.js +44 -23
  116. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  117. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  119. package/dest/services/dummy_service.d.ts +4 -4
  120. package/dest/services/dummy_service.d.ts.map +1 -1
  121. package/dest/services/dummy_service.js +4 -4
  122. package/dest/services/encoding.d.ts +2 -2
  123. package/dest/services/encoding.d.ts.map +1 -1
  124. package/dest/services/encoding.js +9 -8
  125. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  126. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  127. package/dest/services/gossipsub/topic_score_params.js +32 -10
  128. package/dest/services/libp2p/libp2p_service.d.ts +16 -13
  129. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  130. package/dest/services/libp2p/libp2p_service.js +111 -93
  131. package/dest/services/peer-manager/metrics.d.ts +3 -1
  132. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  133. package/dest/services/peer-manager/metrics.js +6 -0
  134. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  135. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  136. package/dest/services/peer-manager/peer_manager.js +2 -1
  137. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  138. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  139. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  140. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  141. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  142. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  143. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  144. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  145. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  146. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  147. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  148. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  149. package/dest/services/reqresp/reqresp.d.ts +1 -1
  150. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  151. package/dest/services/reqresp/reqresp.js +2 -1
  152. package/dest/services/service.d.ts +5 -3
  153. package/dest/services/service.d.ts.map +1 -1
  154. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  155. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  156. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  157. package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
  158. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  159. package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
  160. package/dest/services/tx_collection/file_store_tx_source.d.ts +15 -6
  161. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  162. package/dest/services/tx_collection/file_store_tx_source.js +47 -16
  163. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  164. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  165. package/dest/services/tx_collection/instrumentation.js +2 -1
  166. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  167. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  168. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  169. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  170. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  171. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  172. package/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
  173. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  174. package/dest/services/tx_collection/slow_tx_collection.js +10 -8
  175. package/dest/services/tx_collection/tx_collection.d.ts +5 -4
  176. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  177. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  178. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  179. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  180. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  181. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  182. package/dest/services/tx_collection/tx_source.js +19 -2
  183. package/dest/services/tx_file_store/tx_file_store.js +1 -1
  184. package/dest/services/tx_provider.d.ts +3 -3
  185. package/dest/services/tx_provider.d.ts.map +1 -1
  186. package/dest/services/tx_provider.js +4 -4
  187. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  188. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  189. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  190. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  191. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  192. package/dest/test-helpers/mock-pubsub.js +8 -2
  193. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  194. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  195. package/dest/test-helpers/reqresp-nodes.js +2 -2
  196. package/dest/test-helpers/testbench-utils.d.ts +6 -3
  197. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  198. package/dest/test-helpers/testbench-utils.js +3 -2
  199. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  200. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  201. package/dest/testbench/p2p_client_testbench_worker.js +15 -14
  202. package/dest/testbench/worker_client_manager.d.ts +3 -1
  203. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  204. package/dest/testbench/worker_client_manager.js +6 -2
  205. package/dest/util.d.ts +3 -3
  206. package/dest/util.d.ts.map +1 -1
  207. package/package.json +14 -14
  208. package/src/client/factory.ts +35 -49
  209. package/src/client/interface.ts +11 -20
  210. package/src/client/p2p_client.ts +48 -126
  211. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
  212. package/src/config.ts +108 -43
  213. package/src/errors/tx-pool.error.ts +12 -0
  214. package/src/mem_pools/attestation_pool/attestation_pool.ts +5 -4
  215. package/src/mem_pools/instrumentation.ts +17 -13
  216. package/src/mem_pools/tx_pool/README.md +1 -1
  217. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  218. package/src/mem_pools/tx_pool/priority.ts +6 -3
  219. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  220. package/src/mem_pools/tx_pool_v2/README.md +10 -2
  221. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
  222. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  223. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -3
  224. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  225. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  226. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  227. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +4 -4
  228. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  229. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -9
  230. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  231. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  232. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  233. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  234. package/src/mem_pools/tx_pool_v2/interfaces.ts +18 -6
  235. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +141 -25
  236. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -46
  237. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +15 -7
  238. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +318 -145
  239. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  240. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  241. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
  242. package/src/msg_validators/tx_validator/README.md +115 -0
  243. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  244. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  245. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  246. package/src/msg_validators/tx_validator/factory.ts +366 -77
  247. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  248. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  249. package/src/msg_validators/tx_validator/index.ts +2 -0
  250. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  251. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  252. package/src/msg_validators/tx_validator/phases_validator.ts +51 -26
  253. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  254. package/src/services/dummy_service.ts +6 -6
  255. package/src/services/encoding.ts +7 -7
  256. package/src/services/gossipsub/README.md +29 -14
  257. package/src/services/gossipsub/topic_score_params.ts +49 -13
  258. package/src/services/libp2p/libp2p_service.ts +122 -101
  259. package/src/services/peer-manager/metrics.ts +7 -0
  260. package/src/services/peer-manager/peer_manager.ts +2 -1
  261. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  262. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  263. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  264. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  265. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  266. package/src/services/reqresp/reqresp.ts +3 -1
  267. package/src/services/service.ts +11 -2
  268. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  269. package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
  270. package/src/services/tx_collection/file_store_tx_source.ts +61 -17
  271. package/src/services/tx_collection/instrumentation.ts +7 -1
  272. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  273. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  274. package/src/services/tx_collection/slow_tx_collection.ts +8 -9
  275. package/src/services/tx_collection/tx_collection.ts +4 -3
  276. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  277. package/src/services/tx_collection/tx_source.ts +22 -3
  278. package/src/services/tx_file_store/tx_file_store.ts +1 -1
  279. package/src/services/tx_provider.ts +2 -2
  280. package/src/test-helpers/make-test-p2p-clients.ts +1 -3
  281. package/src/test-helpers/mock-pubsub.ts +13 -6
  282. package/src/test-helpers/reqresp-nodes.ts +3 -6
  283. package/src/test-helpers/testbench-utils.ts +4 -3
  284. package/src/testbench/p2p_client_testbench_worker.ts +24 -20
  285. package/src/testbench/worker_client_manager.ts +13 -5
  286. package/src/util.ts +8 -2
  287. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  288. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  289. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  290. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -6,7 +6,8 @@ import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
6
6
  import { Tx, TxHash } from '@aztec/stdlib/tx';
7
7
  import { TxArchive } from './archive/index.js';
8
8
  import { DeletedPool } from './deleted_pool.js';
9
- import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule } from './eviction/index.js';
9
+ import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule, TxPoolRejectionCode } from './eviction/index.js';
10
+ import { TxPoolV2Instrumentation } from './instrumentation.js';
10
11
  import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
11
12
  import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
12
13
  import { TxPoolIndices } from './tx_pool_indices.js';
@@ -30,9 +31,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
30
31
  #deletedPool;
31
32
  #evictionManager;
32
33
  #dateProvider;
34
+ #instrumentation;
35
+ #evictedTxHashes = new Set();
33
36
  #log;
34
37
  #callbacks;
35
- constructor(store, archiveStore, deps, callbacks, config = {}, dateProvider, log){
38
+ constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
36
39
  this.#store = store;
37
40
  this.#txsDB = store.openMap('txs');
38
41
  this.#l2BlockSource = deps.l2BlockSource;
@@ -45,6 +48,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
45
48
  this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
46
49
  this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
47
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
@@ -122,8 +126,35 @@ import { TxPoolIndices } from './tx_pool_indices.js';
122
126
  const accepted = [];
123
127
  const ignored = [];
124
128
  const rejected = [];
129
+ const errors = new Map();
125
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.
126
153
  const poolAccess = this.#createPreAddPoolAccess();
154
+ const preAddContext = opts.feeComparisonOnly !== undefined ? {
155
+ feeComparisonOnly: opts.feeComparisonOnly,
156
+ priceBumpPercentage: this.#config.priceBumpPercentage
157
+ } : undefined;
127
158
  await this.#store.transactionAsync(async ()=>{
128
159
  for (const tx of txs){
129
160
  const txHash = tx.getTxHash();
@@ -133,85 +164,112 @@ import { TxPoolIndices } from './tx_pool_indices.js';
133
164
  ignored.push(txHash);
134
165
  continue;
135
166
  }
136
- // Check mined status first (applies to all paths)
137
- const minedBlockId = await this.#getMinedBlockId(txHash);
167
+ const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
138
168
  const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
139
169
  if (minedBlockId) {
140
170
  // Already mined - add directly (protection already set if pre-protected)
141
171
  await this.#addTx(tx, {
142
172
  mined: minedBlockId
143
- }, opts);
173
+ }, opts, meta);
144
174
  accepted.push(txHash);
145
175
  } else if (preProtectedSlot !== undefined) {
146
176
  // Pre-protected and not mined - add as protected (bypass validation)
147
177
  await this.#addTx(tx, {
148
178
  protected: preProtectedSlot
149
- }, opts);
179
+ }, opts, meta);
150
180
  accepted.push(txHash);
181
+ } else if (!isValid) {
182
+ // Failed pre-computed validation
183
+ rejected.push(txHash);
151
184
  } else {
152
- // Regular pending tx - validate and run pre-add rules
153
- const result = await this.#tryAddRegularPendingTx(tx, opts, 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);
154
187
  if (result.status === 'accepted') {
155
188
  acceptedPending.add(txHashStr);
156
- } else if (result.status === 'rejected') {
157
- rejected.push(txHash);
158
189
  } else {
159
190
  ignored.push(txHash);
160
191
  }
161
192
  }
162
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
+ }
163
202
  });
164
203
  // Build final accepted list for pending txs (excludes intra-batch evictions)
165
204
  for (const txHashStr of acceptedPending){
166
205
  accepted.push(TxHash.fromString(txHashStr));
167
206
  }
168
- // Run post-add eviction rules for pending txs
169
- if (acceptedPending.size > 0) {
170
- const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
171
- const uniqueFeePayers = new Set(feePayers);
172
- await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
173
- ...uniqueFeePayers
174
- ]);
207
+ // Record metrics
208
+ if (ignored.length > 0) {
209
+ this.#instrumentation.recordIgnored(ignored.length);
210
+ }
211
+ if (rejected.length > 0) {
212
+ this.#instrumentation.recordRejected(rejected.length);
175
213
  }
176
214
  return {
177
215
  accepted,
178
216
  ignored,
179
- rejected
217
+ rejected,
218
+ ...errors.size > 0 ? {
219
+ errors
220
+ } : {}
180
221
  };
181
222
  }
182
- /** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored) {
183
- const txHash = tx.getTxHash();
184
- const txHashStr = txHash.toString();
185
- // Build metadata and validate using metadata
186
- const meta = await buildTxMetaData(tx);
187
- if (!await this.#validateMeta(meta)) {
188
- return {
189
- status: 'rejected'
190
- };
191
- }
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();
192
225
  // Run pre-add rules
193
- const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
226
+ const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
194
227
  if (preAddResult.shouldIgnore) {
195
- 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
+ }
196
232
  return {
197
233
  status: 'ignored'
198
234
  };
199
235
  }
200
- // Evict conflicts
201
- for (const evictHashStr of preAddResult.txHashesToEvict){
202
- await this.#deleteTx(evictHashStr);
203
- this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
204
- evictedTxHash: evictHashStr,
205
- replacementTxHash: txHashStr
206
- });
207
- if (acceptedPending.has(evictHashStr)) {
208
- // Evicted tx was from this batch - mark as ignored in result
209
- acceptedPending.delete(evictHashStr);
210
- 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
+ }
211
248
  }
249
+ for (const [reason, hashes] of byReason){
250
+ await this.#evictTxs(hashes, reason);
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
+ };
212
270
  }
213
271
  // Add the transaction
214
- await this.#addTx(tx, 'pending', opts);
272
+ await this.#addTx(tx, 'pending', opts, precomputedMeta);
215
273
  return {
216
274
  status: 'accepted'
217
275
  };
@@ -220,18 +278,20 @@ import { TxPoolIndices } from './tx_pool_indices.js';
220
278
  const txHashStr = tx.getTxHash().toString();
221
279
  // Check if already in pool
222
280
  if (this.#indices.has(txHashStr)) {
281
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
223
282
  return 'ignored';
224
283
  }
225
- // Build metadata and validate using metadata
284
+ // Build metadata and check pre-add rules
226
285
  const meta = await buildTxMetaData(tx);
227
- const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
228
- if (validationResult !== true) {
229
- return 'rejected';
230
- }
231
- // Use pre-add rules
232
286
  const poolAccess = this.#createPreAddPoolAccess();
233
287
  const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
234
- 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';
235
295
  }
236
296
  async addProtectedTxs(txs, block, opts) {
237
297
  const slotNumber = block.globalVariables.slotNumber;
@@ -264,20 +324,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
264
324
  }
265
325
  });
266
326
  }
267
- protectTxs(txHashes, block) {
327
+ async protectTxs(txHashes, block) {
268
328
  const slotNumber = block.globalVariables.slotNumber;
269
329
  const missing = [];
270
- for (const txHash of txHashes){
271
- const txHashStr = txHash.toString();
272
- if (this.#indices.has(txHashStr)) {
273
- // Update protection for existing tx
274
- this.#indices.updateProtection(txHashStr, slotNumber);
275
- } else {
276
- // Pre-record protection for tx we don't have yet
277
- this.#indices.setProtection(txHashStr, slotNumber);
278
- 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
+ }
279
360
  }
361
+ });
362
+ // Record metrics
363
+ if (softDeletedHits > 0) {
364
+ this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
280
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);
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}`);
281
374
  return missing;
282
375
  }
283
376
  async addMinedTxs(txs, block, opts) {
@@ -316,47 +409,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
316
409
  found.push(meta);
317
410
  }
318
411
  }
319
- // Step 4: Mark txs as mined (only those we have in the pool)
320
- for (const meta of found){
321
- this.#indices.markAsMined(meta, blockId);
322
- await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
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));
323
423
  }
324
- // Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
325
- await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
326
424
  this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
327
425
  }
328
426
  async prepareForSlot(slotNumber) {
329
- // Step 0: Clean up slot-deleted txs from previous slots
330
- await this.#deletedPool.cleanupSlotDeleted(slotNumber);
331
- // Step 1: Find expired protected txs
332
- const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
333
- // Step 2: Clear protection for all expired entries (including those without metadata)
334
- this.#indices.clearProtection(expiredProtected);
335
- // Step 3: Filter to only txs that have metadata and are not mined
336
- const txsToRestore = this.#indices.filterRestorable(expiredProtected);
337
- if (txsToRestore.length === 0) {
338
- return;
339
- }
340
- this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
341
- // Step 4: Validate for pending pool
342
- const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
343
- // Step 5: Resolve nullifier conflicts and add winners to pending indices
344
- const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
345
- // Step 6: Delete invalid and evicted txs
346
- await this.#deleteTxsBatch([
347
- ...invalid,
348
- ...toEvict
349
- ]);
350
- // Step 7: Run eviction rules (enforce pool size limit)
351
- if (added.length > 0) {
352
- const feePayers = added.map((meta)=>meta.feePayer);
353
- const uniqueFeePayers = new Set(feePayers);
354
- await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
355
- ...uniqueFeePayers
356
- ]);
357
- }
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
+ });
358
457
  }
359
- async handlePrunedBlocks(latestBlock) {
458
+ async handlePrunedBlocks(latestBlock, options) {
360
459
  // Step 1: Find transactions mined after the prune point
361
460
  const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
362
461
  if (txsToUnmine.length === 0) {
@@ -364,40 +463,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
364
463
  return;
365
464
  }
366
465
  this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
367
- // Step 2: Mark ALL un-mined txs with their original mined block number
368
- // This ensures they get soft-deleted if removed later, and only hard-deleted
369
- // when their original mined block is finalized
370
- await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
371
- txHash: m.txHash,
372
- minedAtBlock: BlockNumber(m.minedL2BlockId.number)
373
- })));
374
- // Step 3: Unmine - clear mined status from metadata
375
- for (const meta of txsToUnmine){
376
- this.#indices.markAsUnmined(meta);
377
- }
378
- // Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
379
- const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
380
- // Step 4: Validate for pending pool
381
- const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
382
- // Step 6: Resolve nullifier conflicts and add winners to pending indices
383
- const { toEvict } = this.#applyNullifierConflictResolution(valid);
384
- // Step 7: Delete invalid and evicted txs
385
- await this.#deleteTxsBatch([
386
- ...invalid,
387
- ...toEvict
388
- ]);
389
- 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`, {
390
- txHashesRestored: valid.map((m)=>m.txHash),
391
- txHashesInvalid: invalid,
392
- txHashesEvicted: toEvict
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);
393
502
  });
394
- // Step 8: Run eviction rules for ALL pending txs (not just restored ones)
395
- // This handles cases like existing pending txs with invalid fee payer balances
396
- await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
397
503
  }
398
504
  async handleFailedExecution(txHashes) {
399
- // Delete failed txs
400
- await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
505
+ await this.#store.transactionAsync(async ()=>{
506
+ await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
507
+ });
401
508
  this.#log.info(`Deleted ${txHashes.length} failed txs`, {
402
509
  txHashes: txHashes.map((h)=>h.toString())
403
510
  });
@@ -406,24 +513,26 @@ import { TxPoolIndices } from './tx_pool_indices.js';
406
513
  const blockNumber = block.globalVariables.blockNumber;
407
514
  // Step 1: Find mined txs at or before finalized block
408
515
  const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
409
- // Step 2: Collect mined txs for archiving (before deletion)
410
- const txsToArchive = [];
411
- if (this.#archive.isEnabled()) {
412
- for (const txHashStr of minedTxsToFinalize){
413
- const buffer = await this.#txsDB.getAsync(txHashStr);
414
- if (buffer) {
415
- txsToArchive.push(Tx.fromBuffer(buffer));
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
+ }
416
525
  }
417
526
  }
418
- }
419
- // Step 3: Delete mined txs from active pool
420
- await this.#deleteTxsBatch(minedTxsToFinalize);
421
- // Step 4: Finalize soft-deleted txs
422
- await this.#deletedPool.finalizeBlock(blockNumber);
423
- // Step 5: Archive mined txs
424
- if (txsToArchive.length > 0) {
425
- await this.#archive.archiveTxs(txsToArchive);
426
- }
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
+ });
427
536
  if (minedTxsToFinalize.length > 0) {
428
537
  this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
429
538
  txHashes: minedTxsToFinalize
@@ -528,7 +637,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
528
637
  }
529
638
  // === Metrics ===
530
639
  countTxs() {
531
- return this.#indices.countTxs();
640
+ return {
641
+ ...this.#indices.countTxs(),
642
+ softDeleted: this.#deletedPool.getSoftDeletedCount()
643
+ };
532
644
  }
533
645
  // ============================================================================
534
646
  // PRIVATE HELPERS - Transaction Management
@@ -536,9 +648,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
536
648
  /**
537
649
  * Adds a new transaction to the pool with the specified state.
538
650
  * Emits onTxsAdded callback immediately after DB write.
539
- */ async #addTx(tx, state, opts = {}) {
651
+ */ async #addTx(tx, state, opts = {}, precomputedMeta) {
540
652
  const txHashStr = tx.getTxHash().toString();
541
- const meta = await buildTxMetaData(tx);
653
+ const meta = precomputedMeta ?? await buildTxMetaData(tx);
542
654
  meta.receivedAt = this.#dateProvider.now();
543
655
  await this.#txsDB.set(txHashStr, tx.toBuffer());
544
656
  await this.#deletedPool.clearSoftDeleted(txHashStr);
@@ -554,9 +666,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
554
666
  this.#indices.addMined(meta);
555
667
  }
556
668
  const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
557
- this.#log.verbose(`Added ${stateStr} tx ${txHashStr}`, {
669
+ this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
558
670
  eventName: 'tx-added-to-pool',
559
- state: stateStr
671
+ txHash: txHashStr,
672
+ state: stateStr,
673
+ source: opts.source
560
674
  });
561
675
  return meta;
562
676
  }
@@ -579,6 +693,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
579
693
  await this.#deleteTx(txHashStr);
580
694
  }
581
695
  }
696
+ /** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
697
+ if (txHashes.length === 0) {
698
+ return;
699
+ }
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);
707
+ }
708
+ await this.#deleteTxsBatch(txHashes);
709
+ }
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);
717
+ }
582
718
  // ============================================================================
583
719
  // PRIVATE HELPERS - Validation & Conflict Resolution
584
720
  // ============================================================================
@@ -717,7 +853,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
717
853
  if (preAddResult.shouldIgnore) {
718
854
  // Transaction rejected - mark for deletion from DB
719
855
  rejected.push(meta.txHash);
720
- 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'}`);
721
857
  continue;
722
858
  }
723
859
  // Evict any conflicting txs identified by pre-add rules
@@ -753,7 +889,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
753
889
  getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
754
890
  getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
755
891
  getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
756
- deleteTxs: (txHashes)=>this.#deleteTxsBatch(txHashes)
892
+ deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
757
893
  };
758
894
  }
759
895
  #createPreAddPoolAccess() {
@@ -1,9 +1,11 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import type { BlockProposal, P2PValidator } from '@aztec/stdlib/p2p';
3
- import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
4
- export declare class BlockProposalValidator extends ProposalValidator<BlockProposal> implements P2PValidator<BlockProposal> {
2
+ import type { BlockProposal, P2PValidator, ValidationResult } from '@aztec/stdlib/p2p';
3
+ export declare class BlockProposalValidator implements P2PValidator<BlockProposal> {
4
+ private proposalValidator;
5
5
  constructor(epochCache: EpochCacheInterface, opts: {
6
6
  txsPermitted: boolean;
7
+ maxTxsPerBlock?: number;
7
8
  });
9
+ validate(proposal: BlockProposal): Promise<ValidationResult>;
8
10
  }
9
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfcHJvcG9zYWxfdmFsaWRhdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbXNnX3ZhbGlkYXRvcnMvcHJvcG9zYWxfdmFsaWRhdG9yL2Jsb2NrX3Byb3Bvc2FsX3ZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxZQUFZLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUVyRSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSw2Q0FBNkMsQ0FBQztBQUVoRixxQkFBYSxzQkFBdUIsU0FBUSxpQkFBaUIsQ0FBQyxhQUFhLENBQUUsWUFBVyxZQUFZLENBQUMsYUFBYSxDQUFDO0lBQ2pILFlBQVksVUFBVSxFQUFFLG1CQUFtQixFQUFFLElBQUksRUFBRTtRQUFFLFlBQVksRUFBRSxPQUFPLENBQUE7S0FBRSxFQUUzRTtDQUNGIn0=
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfcHJvcG9zYWxfdmFsaWRhdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbXNnX3ZhbGlkYXRvcnMvcHJvcG9zYWxfdmFsaWRhdG9yL2Jsb2NrX3Byb3Bvc2FsX3ZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxZQUFZLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUl2RixxQkFBYSxzQkFBdUIsWUFBVyxZQUFZLENBQUMsYUFBYSxDQUFDO0lBQ3hFLE9BQU8sQ0FBQyxpQkFBaUIsQ0FBb0I7SUFFN0MsWUFBWSxVQUFVLEVBQUUsbUJBQW1CLEVBQUUsSUFBSSxFQUFFO1FBQUUsWUFBWSxFQUFFLE9BQU8sQ0FBQztRQUFDLGNBQWMsQ0FBQyxFQUFFLE1BQU0sQ0FBQTtLQUFFLEVBRXBHO0lBRUssUUFBUSxDQUFDLFFBQVEsRUFBRSxhQUFhLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBTWpFO0NBQ0YifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"block_proposal_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/proposal_validator/block_proposal_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAEhF,qBAAa,sBAAuB,SAAQ,iBAAiB,CAAC,aAAa,CAAE,YAAW,YAAY,CAAC,aAAa,CAAC;IACjH,YAAY,UAAU,EAAE,mBAAmB,EAAE,IAAI,EAAE;QAAE,YAAY,EAAE,OAAO,CAAA;KAAE,EAE3E;CACF"}
1
+ {"version":3,"file":"block_proposal_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/proposal_validator/block_proposal_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAIvF,qBAAa,sBAAuB,YAAW,YAAY,CAAC,aAAa,CAAC;IACxE,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,YAAY,UAAU,EAAE,mBAAmB,EAAE,IAAI,EAAE;QAAE,YAAY,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,EAEpG;IAEK,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAMjE;CACF"}