@aztec/p2p 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107

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 (334) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +14 -4
  4. package/dest/client/factory.d.ts +3 -2
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +9 -5
  7. package/dest/client/index.d.ts +1 -1
  8. package/dest/client/interface.d.ts +8 -6
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +12 -35
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +457 -61
  13. package/dest/config.d.ts +67 -61
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +28 -15
  16. package/dest/enr/generate-enr.d.ts +2 -2
  17. package/dest/enr/generate-enr.d.ts.map +1 -1
  18. package/dest/enr/generate-enr.js +1 -1
  19. package/dest/enr/index.d.ts +1 -1
  20. package/dest/errors/attestation-pool.error.d.ts +7 -0
  21. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  22. package/dest/errors/attestation-pool.error.js +12 -0
  23. package/dest/errors/reqresp.error.d.ts +1 -1
  24. package/dest/errors/reqresp.error.d.ts.map +1 -1
  25. package/dest/index.d.ts +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
  27. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  29. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +72 -46
  31. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  32. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
  33. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  34. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +73 -18
  35. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
  36. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  37. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +69 -11
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
  39. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  40. package/dest/mem_pools/attestation_pool/mocks.js +9 -7
  41. package/dest/mem_pools/index.d.ts +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts +9 -1
  43. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  44. package/dest/mem_pools/instrumentation.js +38 -2
  45. package/dest/mem_pools/interface.d.ts +3 -4
  46. package/dest/mem_pools/interface.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +39 -58
  48. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -317
  50. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
  51. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
  53. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
  54. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
  56. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
  57. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
  59. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  60. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  62. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  63. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
  65. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  66. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  68. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  69. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool/index.js +0 -1
  71. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  72. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool/priority.js +6 -1
  74. package/dest/mem_pools/tx_pool/tx_pool.d.ts +28 -9
  75. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  77. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +155 -25
  79. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  80. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/attestation_validator/attestation_validator.js +32 -5
  82. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  83. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  84. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  85. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  86. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  87. package/dest/msg_validators/attestation_validator/index.js +1 -0
  88. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -2
  89. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  90. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +44 -12
  91. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  92. package/dest/msg_validators/index.d.ts +1 -1
  93. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
  94. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  96. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
  98. package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
  99. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  101. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  102. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  103. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  104. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  105. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
  106. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/double_spend_validator.js +1 -1
  108. package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
  109. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/factory.js +11 -5
  111. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  112. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  113. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  114. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  115. package/dest/msg_validators/tx_validator/index.js +1 -0
  116. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -6
  117. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/metadata_validator.js +6 -24
  119. package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
  120. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  121. package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
  122. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  123. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  125. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  126. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  127. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
  128. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  130. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  131. package/dest/services/data_store.d.ts +1 -1
  132. package/dest/services/data_store.d.ts.map +1 -1
  133. package/dest/services/discv5/discV5_service.d.ts +3 -3
  134. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  135. package/dest/services/discv5/discV5_service.js +2 -2
  136. package/dest/services/dummy_service.d.ts +2 -2
  137. package/dest/services/dummy_service.d.ts.map +1 -1
  138. package/dest/services/encoding.d.ts +25 -4
  139. package/dest/services/encoding.d.ts.map +1 -1
  140. package/dest/services/encoding.js +74 -6
  141. package/dest/services/gossipsub/scoring.d.ts +1 -1
  142. package/dest/services/index.d.ts +1 -1
  143. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  144. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  145. package/dest/services/libp2p/instrumentation.js +9 -2
  146. package/dest/services/libp2p/libp2p_service.d.ts +32 -72
  147. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  148. package/dest/services/libp2p/libp2p_service.js +796 -171
  149. package/dest/services/peer-manager/interface.d.ts +1 -1
  150. package/dest/services/peer-manager/metrics.d.ts +8 -1
  151. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  152. package/dest/services/peer-manager/metrics.js +28 -0
  153. package/dest/services/peer-manager/peer_manager.d.ts +1 -32
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +412 -21
  156. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  157. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  158. package/dest/services/peer-manager/peer_scoring.js +40 -2
  159. package/dest/services/reqresp/config.d.ts +1 -1
  160. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  161. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  162. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
  163. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  164. package/dest/services/reqresp/index.d.ts +1 -1
  165. package/dest/services/reqresp/interface.d.ts +2 -11
  166. package/dest/services/reqresp/interface.d.ts.map +1 -1
  167. package/dest/services/reqresp/interface.js +1 -18
  168. package/dest/services/reqresp/metrics.d.ts +1 -1
  169. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  170. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  171. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  172. package/dest/services/reqresp/protocols/auth.js +2 -2
  173. package/dest/services/reqresp/protocols/block.d.ts +1 -1
  174. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  175. package/dest/services/reqresp/protocols/block.js +3 -2
  176. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  177. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  178. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  179. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
  180. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  181. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
  182. package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
  183. package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
  184. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  185. package/dest/services/reqresp/protocols/index.d.ts +1 -1
  186. package/dest/services/reqresp/protocols/ping.d.ts +1 -1
  187. package/dest/services/reqresp/protocols/status.d.ts +6 -5
  188. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  189. package/dest/services/reqresp/protocols/status.js +4 -3
  190. package/dest/services/reqresp/protocols/tx.d.ts +2 -3
  191. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  192. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  193. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
  194. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  195. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  196. package/dest/services/reqresp/reqresp.d.ts +1 -41
  197. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  198. package/dest/services/reqresp/reqresp.js +416 -34
  199. package/dest/services/reqresp/status.d.ts +2 -2
  200. package/dest/services/reqresp/status.d.ts.map +1 -1
  201. package/dest/services/service.d.ts +2 -2
  202. package/dest/services/service.d.ts.map +1 -1
  203. package/dest/services/tx_collection/config.d.ts +1 -1
  204. package/dest/services/tx_collection/config.js +1 -1
  205. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
  206. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  207. package/dest/services/tx_collection/fast_tx_collection.js +6 -1
  208. package/dest/services/tx_collection/index.d.ts +1 -1
  209. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  210. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  211. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
  212. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  213. package/dest/services/tx_collection/slow_tx_collection.js +2 -1
  214. package/dest/services/tx_collection/tx_collection.d.ts +12 -11
  215. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  216. package/dest/services/tx_collection/tx_collection.js +3 -2
  217. package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
  218. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  219. package/dest/services/tx_collection/tx_collection_sink.js +34 -4
  220. package/dest/services/tx_collection/tx_source.d.ts +1 -1
  221. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  222. package/dest/services/tx_collection/tx_source.js +2 -2
  223. package/dest/services/tx_provider.d.ts +6 -4
  224. package/dest/services/tx_provider.d.ts.map +1 -1
  225. package/dest/services/tx_provider.js +19 -6
  226. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  227. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  228. package/dest/services/tx_provider_instrumentation.js +14 -1
  229. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  230. package/dest/test-helpers/get-ports.d.ts +1 -1
  231. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  232. package/dest/test-helpers/index.d.ts +1 -1
  233. package/dest/test-helpers/make-enrs.d.ts +1 -1
  234. package/dest/test-helpers/make-enrs.js +1 -1
  235. package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
  236. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  237. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  238. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  239. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  240. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  241. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  242. package/dest/test-helpers/reqresp-nodes.d.ts +3 -3
  243. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  244. package/dest/test-helpers/reqresp-nodes.js +4 -3
  245. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  246. package/dest/testbench/p2p_client_testbench_worker.js +17 -9
  247. package/dest/testbench/parse_log_file.d.ts +1 -1
  248. package/dest/testbench/testbench.d.ts +1 -1
  249. package/dest/testbench/testbench.js +2 -2
  250. package/dest/testbench/worker_client_manager.d.ts +1 -1
  251. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  252. package/dest/types/index.d.ts +1 -1
  253. package/dest/util.d.ts +2 -1
  254. package/dest/util.d.ts.map +1 -1
  255. package/dest/util.js +11 -2
  256. package/dest/versioning.d.ts +2 -2
  257. package/dest/versioning.d.ts.map +1 -1
  258. package/dest/versioning.js +2 -2
  259. package/package.json +21 -21
  260. package/src/bootstrap/bootstrap.ts +15 -4
  261. package/src/client/factory.ts +21 -12
  262. package/src/client/interface.ts +8 -5
  263. package/src/client/p2p_client.ts +97 -88
  264. package/src/config.ts +42 -21
  265. package/src/enr/generate-enr.ts +1 -1
  266. package/src/errors/attestation-pool.error.ts +13 -0
  267. package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
  268. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +89 -48
  269. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +107 -24
  270. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +98 -19
  271. package/src/mem_pools/attestation_pool/mocks.ts +11 -8
  272. package/src/mem_pools/instrumentation.ts +46 -0
  273. package/src/mem_pools/interface.ts +2 -4
  274. package/src/mem_pools/tx_pool/README.md +255 -0
  275. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +368 -360
  276. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
  277. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
  278. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
  279. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  280. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
  281. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  282. package/src/mem_pools/tx_pool/index.ts +0 -1
  283. package/src/mem_pools/tx_pool/priority.ts +8 -1
  284. package/src/mem_pools/tx_pool/tx_pool.ts +28 -8
  285. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +131 -18
  286. package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -6
  287. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  288. package/src/msg_validators/attestation_validator/index.ts +1 -0
  289. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +53 -12
  290. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  291. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  292. package/src/msg_validators/tx_validator/double_spend_validator.ts +1 -1
  293. package/src/msg_validators/tx_validator/factory.ts +13 -6
  294. package/src/msg_validators/tx_validator/index.ts +1 -0
  295. package/src/msg_validators/tx_validator/metadata_validator.ts +8 -42
  296. package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
  297. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  298. package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
  299. package/src/services/discv5/discV5_service.ts +2 -2
  300. package/src/services/dummy_service.ts +1 -1
  301. package/src/services/encoding.ts +81 -6
  302. package/src/services/libp2p/instrumentation.ts +10 -1
  303. package/src/services/libp2p/libp2p_service.ts +430 -165
  304. package/src/services/peer-manager/metrics.ts +32 -0
  305. package/src/services/peer-manager/peer_manager.ts +24 -14
  306. package/src/services/peer-manager/peer_scoring.ts +46 -3
  307. package/src/services/reqresp/interface.ts +1 -22
  308. package/src/services/reqresp/protocols/auth.ts +2 -2
  309. package/src/services/reqresp/protocols/block.ts +3 -2
  310. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
  311. package/src/services/reqresp/protocols/status.ts +9 -8
  312. package/src/services/reqresp/protocols/tx.ts +1 -2
  313. package/src/services/reqresp/reqresp.ts +15 -11
  314. package/src/services/service.ts +1 -1
  315. package/src/services/tx_collection/config.ts +1 -1
  316. package/src/services/tx_collection/fast_tx_collection.ts +8 -5
  317. package/src/services/tx_collection/slow_tx_collection.ts +7 -6
  318. package/src/services/tx_collection/tx_collection.ts +12 -10
  319. package/src/services/tx_collection/tx_collection_sink.ts +34 -3
  320. package/src/services/tx_collection/tx_source.ts +2 -2
  321. package/src/services/tx_provider.ts +26 -9
  322. package/src/services/tx_provider_instrumentation.ts +19 -2
  323. package/src/test-helpers/make-enrs.ts +1 -1
  324. package/src/test-helpers/mock-pubsub.ts +1 -1
  325. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  326. package/src/test-helpers/reqresp-nodes.ts +4 -3
  327. package/src/testbench/p2p_client_testbench_worker.ts +14 -6
  328. package/src/testbench/testbench.ts +2 -2
  329. package/src/util.ts +12 -2
  330. package/src/versioning.ts +3 -3
  331. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -68
  332. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  333. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -160
  334. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -199
@@ -1,14 +1,20 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { createLogger } from '@aztec/foundation/log';
2
3
  import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
3
4
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
4
5
 
5
6
  import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
6
7
  import type { AttestationPool } from './attestation_pool.js';
8
+ import { ATTESTATION_CAP_BUFFER, MAX_PROPOSALS_PER_SLOT } from './kv_attestation_pool.js';
7
9
 
8
10
  export class InMemoryAttestationPool implements AttestationPool {
9
11
  private metrics: PoolInstrumentation<BlockAttestation>;
10
12
 
11
- private attestations: Map</*slot=*/ bigint, Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>>;
13
+ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
14
+ private attestations: Map<
15
+ /*slot=*/ SlotNumber,
16
+ Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>
17
+ >;
12
18
  private proposals: Map<string, BlockProposal>;
13
19
 
14
20
  constructor(
@@ -30,7 +36,7 @@ export class InMemoryAttestationPool implements AttestationPool {
30
36
  return Promise.resolve(this.attestations.size === 0);
31
37
  }
32
38
 
33
- public getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]> {
39
+ public getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]> {
34
40
  return Promise.resolve(
35
41
  Array.from(this.attestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
36
42
  Array.from(proposalAttestationMap.values()),
@@ -38,7 +44,7 @@ export class InMemoryAttestationPool implements AttestationPool {
38
44
  );
39
45
  }
40
46
 
41
- public getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
47
+ public getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]> {
42
48
  const slotAttestationMap = this.attestations.get(slot);
43
49
  if (slotAttestationMap) {
44
50
  const proposalAttestationMap = slotAttestationMap.get(proposalId);
@@ -55,16 +61,26 @@ export class InMemoryAttestationPool implements AttestationPool {
55
61
  const slotNumber = attestation.payload.header.slotNumber;
56
62
 
57
63
  const proposalId = attestation.archive.toString();
58
- const address = attestation.getSender();
64
+ const sender = attestation.getSender();
59
65
 
60
- const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber.toBigInt());
66
+ // Skip attestations with invalid signatures
67
+ if (!sender) {
68
+ this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber}`, {
69
+ signature: attestation.signature.toString(),
70
+ slotNumber,
71
+ proposalId,
72
+ });
73
+ continue;
74
+ }
75
+
76
+ const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber);
61
77
  const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
62
- proposalAttestationMap.set(address.toString(), attestation);
78
+ proposalAttestationMap.set(sender.toString(), attestation);
63
79
 
64
- this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${address}`, {
80
+ this.log.verbose(`Added attestation for slot ${slotNumber} from ${sender}`, {
65
81
  signature: attestation.signature.toString(),
66
82
  slotNumber,
67
- address,
83
+ address: sender,
68
84
  proposalId,
69
85
  });
70
86
  }
@@ -72,7 +88,7 @@ export class InMemoryAttestationPool implements AttestationPool {
72
88
  return Promise.resolve();
73
89
  }
74
90
 
75
- #getNumberOfAttestationsInSlot(slot: bigint): number {
91
+ #getNumberOfAttestationsInSlot(slot: SlotNumber): number {
76
92
  let total = 0;
77
93
  const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
78
94
 
@@ -84,7 +100,7 @@ export class InMemoryAttestationPool implements AttestationPool {
84
100
  return total;
85
101
  }
86
102
 
87
- public async deleteAttestationsOlderThan(oldestSlot: bigint): Promise<void> {
103
+ public async deleteAttestationsOlderThan(oldestSlot: SlotNumber): Promise<void> {
88
104
  const olderThan = [];
89
105
 
90
106
  // Entries are iterated in insertion order, so we can break as soon as we find a slot that is older than the oldestSlot.
@@ -105,7 +121,7 @@ export class InMemoryAttestationPool implements AttestationPool {
105
121
  return Promise.resolve();
106
122
  }
107
123
 
108
- public deleteAttestationsForSlot(slot: bigint): Promise<void> {
124
+ public deleteAttestationsForSlot(slot: SlotNumber): Promise<void> {
109
125
  // We count the number of attestations we are removing
110
126
  const numberOfAttestations = this.#getNumberOfAttestationsInSlot(slot);
111
127
  const proposalIdsToDelete = this.attestations.get(slot)?.keys();
@@ -123,7 +139,7 @@ export class InMemoryAttestationPool implements AttestationPool {
123
139
  return Promise.resolve();
124
140
  }
125
141
 
126
- public deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void> {
142
+ public deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void> {
127
143
  const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
128
144
  if (slotAttestationMap) {
129
145
  if (slotAttestationMap.has(proposalId)) {
@@ -142,24 +158,54 @@ export class InMemoryAttestationPool implements AttestationPool {
142
158
  public deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
143
159
  for (const attestation of attestations) {
144
160
  const slotNumber = attestation.payload.header.slotNumber;
145
- const slotAttestationMap = this.attestations.get(slotNumber.toBigInt());
161
+ const slotAttestationMap = this.attestations.get(slotNumber);
146
162
  if (slotAttestationMap) {
147
163
  const proposalId = attestation.archive.toString();
148
164
  const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
149
165
  if (proposalAttestationMap) {
150
- const address = attestation.getSender();
151
- proposalAttestationMap.delete(address.toString());
152
- this.log.debug(`Deleted attestation for slot ${slotNumber} from ${address}`);
166
+ const sender = attestation.getSender();
167
+
168
+ // Skip attestations with invalid signatures
169
+ if (!sender) {
170
+ this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber}`);
171
+ continue;
172
+ }
173
+
174
+ proposalAttestationMap.delete(sender.toString());
175
+ this.log.debug(`Deleted attestation for slot ${slotNumber} from ${sender}`);
153
176
  }
154
177
  }
155
178
  }
156
179
  return Promise.resolve();
157
180
  }
158
181
 
182
+ public hasAttestation(attestation: BlockAttestation): Promise<boolean> {
183
+ const slotNumber = attestation.payload.header.slotNumber;
184
+ const proposalId = attestation.archive.toString();
185
+ const sender = attestation.getSender();
186
+
187
+ // Attestations with invalid signatures are never in the pool
188
+ if (!sender) {
189
+ return Promise.resolve(false);
190
+ }
191
+
192
+ const slotAttestationMap = this.attestations.get(slotNumber);
193
+ if (!slotAttestationMap) {
194
+ return Promise.resolve(false);
195
+ }
196
+
197
+ const proposalAttestationMap = slotAttestationMap.get(proposalId);
198
+ if (!proposalAttestationMap) {
199
+ return Promise.resolve(false);
200
+ }
201
+
202
+ return Promise.resolve(proposalAttestationMap.has(sender.toString()));
203
+ }
204
+
159
205
  public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
160
206
  // We initialize slot-proposal mapping if it does not exist
161
207
  // This is important to ensure we can delete this proposal if there were not attestations for it
162
- const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber.toBigInt());
208
+ const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber);
163
209
  slotProposalMapping.set(blockProposal.payload.archive.toString(), new Map<string, BlockAttestation>());
164
210
 
165
211
  this.proposals.set(blockProposal.payload.archive.toString(), blockProposal);
@@ -169,6 +215,38 @@ export class InMemoryAttestationPool implements AttestationPool {
169
215
  public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
170
216
  return Promise.resolve(this.proposals.get(id));
171
217
  }
218
+
219
+ public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
220
+ const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
221
+ return Promise.resolve(this.proposals.has(id));
222
+ }
223
+
224
+ public hasReachedProposalCap(slot: SlotNumber): Promise<boolean> {
225
+ const slotAttestationMap = this.attestations.get(slot);
226
+ const proposalCount = slotAttestationMap?.size ?? 0;
227
+ return Promise.resolve(proposalCount >= MAX_PROPOSALS_PER_SLOT);
228
+ }
229
+
230
+ public hasReachedAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean> {
231
+ const limit = committeeSize + ATTESTATION_CAP_BUFFER;
232
+ const count = this.attestations.get(slot)?.get(proposalId)?.size ?? 0;
233
+ return Promise.resolve(limit <= 0 || count >= limit);
234
+ }
235
+
236
+ public async canAddProposal(block: BlockProposal): Promise<boolean> {
237
+ return this.proposals.has(block.archive.toString()) || !(await this.hasReachedProposalCap(block.slotNumber));
238
+ }
239
+
240
+ public async canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean> {
241
+ const sender = attestation.getSender();
242
+ const slot = attestation.payload.header.slotNumber;
243
+ const pid = attestation.archive.toString();
244
+ return (
245
+ !!sender &&
246
+ ((this.attestations.get(slot)?.get(pid)?.has(sender.toString()) ?? false) ||
247
+ !(await this.hasReachedAttestationCap(slot, pid, committeeSize)))
248
+ );
249
+ }
172
250
  }
173
251
 
174
252
  /**
@@ -180,8 +258,9 @@ export class InMemoryAttestationPool implements AttestationPool {
180
258
  * @returns The slot mapping
181
259
  */
182
260
  function getSlotOrDefault(
183
- map: Map<bigint, Map<string, Map<string, BlockAttestation>>>,
184
- slot: bigint,
261
+ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
262
+ map: Map<SlotNumber, Map<string, Map<string, BlockAttestation>>>,
263
+ slot: SlotNumber,
185
264
  ): Map<string, Map<string, BlockAttestation>> {
186
265
  if (!map.has(slot)) {
187
266
  map.set(slot, new Map<string, Map<string, BlockAttestation>>());
@@ -1,12 +1,12 @@
1
- import type { Secp256k1Signer } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import {
4
4
  BlockAttestation,
5
5
  ConsensusPayload,
6
6
  SignatureDomainSeparator,
7
7
  getHashedSignaturePayloadEthSignedMessage,
8
8
  } from '@aztec/stdlib/p2p';
9
- import { makeHeader } from '@aztec/stdlib/testing';
9
+ import { makeL2BlockHeader } from '@aztec/stdlib/testing';
10
10
 
11
11
  import { type LocalAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
12
12
 
@@ -32,11 +32,14 @@ export const mockAttestation = (
32
32
  archive: Fr = Fr.random(),
33
33
  ): BlockAttestation => {
34
34
  // Use arbitrary numbers for all other than slot
35
- const header = makeHeader(1, 2, slot);
36
- const payload = new ConsensusPayload(header.toPropose(), archive, header.state);
35
+ const header = makeL2BlockHeader(1, 2, slot);
36
+ const payload = new ConsensusPayload(header.toCheckpointHeader(), archive);
37
37
 
38
- const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
39
- const signature = signer.sign(hash);
38
+ const attestationHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
39
+ const attestationSignature = signer.sign(attestationHash);
40
40
 
41
- return new BlockAttestation(header.globalVariables.blockNumber, payload, signature);
41
+ const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
42
+ const proposerSignature = signer.sign(proposalHash);
43
+
44
+ return new BlockAttestation(payload, attestationSignature, proposerSignature);
42
45
  };
@@ -1,4 +1,5 @@
1
1
  import type { Gossipable } from '@aztec/stdlib/p2p';
2
+ import type { Tx } from '@aztec/stdlib/tx';
2
3
  import {
3
4
  Attributes,
4
5
  type BatchObservableResult,
@@ -10,6 +11,7 @@ import {
10
11
  type MetricsType,
11
12
  type ObservableGauge,
12
13
  type TelemetryClient,
14
+ type UpDownCounter,
13
15
  } from '@aztec/telemetry-client';
14
16
 
15
17
  export enum PoolName {
@@ -20,6 +22,8 @@ export enum PoolName {
20
22
  type MetricsLabels = {
21
23
  objectInMempool: MetricsType;
22
24
  objectSize: MetricsType;
25
+ itemsAdded: MetricsType;
26
+ itemMinedDelay: MetricsType;
23
27
  };
24
28
 
25
29
  /**
@@ -32,11 +36,15 @@ function getMetricsLabels(name: PoolName): MetricsLabels {
32
36
  return {
33
37
  objectInMempool: Metrics.MEMPOOL_TX_COUNT,
34
38
  objectSize: Metrics.MEMPOOL_TX_SIZE,
39
+ itemsAdded: Metrics.MEMPOOL_TX_ADDED_COUNT,
40
+ itemMinedDelay: Metrics.MEMPOOL_TX_MINED_DELAY,
35
41
  };
36
42
  } else if (name === PoolName.ATTESTATION_POOL) {
37
43
  return {
38
44
  objectInMempool: Metrics.MEMPOOL_ATTESTATIONS_COUNT,
39
45
  objectSize: Metrics.MEMPOOL_ATTESTATIONS_SIZE,
46
+ itemsAdded: Metrics.MEMPOOL_ATTESTATIONS_ADDED_COUNT,
47
+ itemMinedDelay: Metrics.MEMPOOL_ATTESTATIONS_MINED_DELAY,
40
48
  };
41
49
  }
42
50
 
@@ -53,14 +61,19 @@ export type PoolStatsCallback = () => Promise<{
53
61
  export class PoolInstrumentation<PoolObject extends Gossipable> {
54
62
  /** The number of txs in the mempool */
55
63
  private objectsInMempool: ObservableGauge;
64
+ private addObjectCounter: UpDownCounter;
56
65
  /** Tracks tx size */
57
66
  private objectSize: Histogram;
67
+ /** Track delay between transaction added and evicted */
68
+ private minedDelay: Histogram;
58
69
 
59
70
  private dbMetrics: LmdbMetrics;
60
71
 
61
72
  private defaultAttributes;
62
73
  private meter: Meter;
63
74
 
75
+ private txAddedTimestamp: Map<bigint, number> = new Map<bigint, number>();
76
+
64
77
  constructor(
65
78
  telemetry: TelemetryClient,
66
79
  name: PoolName,
@@ -89,6 +102,14 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
89
102
  dbStats,
90
103
  );
91
104
 
105
+ this.addObjectCounter = this.meter.createUpDownCounter(metricsLabels.itemsAdded, {
106
+ description: 'The number of transactions added to the mempool',
107
+ });
108
+
109
+ this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay, {
110
+ description: 'Delay between transaction added and evicted from the mempool',
111
+ });
112
+
92
113
  this.meter.addBatchObservableCallback(this.observeStats, [this.objectsInMempool]);
93
114
  }
94
115
 
@@ -96,6 +117,31 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
96
117
  this.objectSize.record(poolObject.getSize());
97
118
  }
98
119
 
120
+ public incrementAddedObjects(count: number) {
121
+ this.addObjectCounter.add(count);
122
+ }
123
+
124
+ public transactionsAdded(transactions: Tx[]) {
125
+ const timestamp = Date.now();
126
+ for (const transaction of transactions) {
127
+ this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
128
+ }
129
+ }
130
+
131
+ public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
132
+ const timestamp = Date.now();
133
+ for (const hash of hashes) {
134
+ const key = BigInt(hash);
135
+ const addedAt = this.txAddedTimestamp.get(key);
136
+ if (addedAt !== undefined) {
137
+ this.txAddedTimestamp.delete(key);
138
+ if (addedAt < timestamp) {
139
+ this.minedDelay.record(timestamp - addedAt);
140
+ }
141
+ }
142
+ }
143
+ }
144
+
99
145
  private observeStats = async (observer: BatchObservableResult) => {
100
146
  const { itemCount } = await this.poolStats();
101
147
  if (typeof itemCount === 'number') {
@@ -1,12 +1,10 @@
1
- import type { P2PClientType } from '@aztec/stdlib/p2p';
2
-
3
1
  import type { AttestationPool } from './attestation_pool/attestation_pool.js';
4
2
  import type { TxPool } from './tx_pool/tx_pool.js';
5
3
 
6
4
  /**
7
5
  * A interface the combines all mempools
8
6
  */
9
- export type MemPools<T extends P2PClientType = P2PClientType.Full> = {
7
+ export type MemPools = {
10
8
  txPool: TxPool;
11
- attestationPool?: T extends P2PClientType.Full ? AttestationPool : undefined;
9
+ attestationPool: AttestationPool;
12
10
  };
@@ -0,0 +1,255 @@
1
+ # Transaction Pool (Mempool)
2
+
3
+ This module implements the transaction pool (mempool) for the Aztec P2P network. The mempool holds unconfirmed transactions awaiting inclusion in a block.
4
+
5
+ ## Overview
6
+
7
+ The transaction pool serves as a staging area for transactions before they are included in blocks. It manages the lifecycle of transactions from initial submission through mining, handling duplicates, priority ordering, and eviction of invalid or low-priority transactions.
8
+
9
+ ## Interface: `TxPool`
10
+
11
+ The [`TxPool`](tx_pool.ts) interface defines the contract that all transaction pool implementations must fulfill:
12
+
13
+ ### Transaction Lifecycle
14
+
15
+ The lifecycle of transactions in the pool is summarised in the following table:
16
+
17
+ | State | Meaning | Possible Future States |
18
+ | --- | --- | --- |
19
+ | Pending | Available to be added to a block, can be evicted | Protected, Mined, Soft Deleted |
20
+ | Protected | Added to a proposal, must not be evicted | Mined, Pending |
21
+ | Mined | Confirmed as added to a block | Soft Deleted, Pending |
22
+ | Soft Deleted | Awaiting full deletion once state has been finalised on L1 | Pending, Deleted |
23
+ | Deleted | Removed from the pool | N/A |
24
+
25
+ **Note on why Soft Delete:**
26
+ Mined transactions are soft-deleted rather than permanently removed to support:
27
+ 1. Reorg handling — If a chain reorganization occurs, soft-deleted transactions are still available in the mempool
28
+ 2. Slash condition detection — The epoch prune watcher needs access to transactions from pruned epochs to correctly identify data withholding slash conditions. Without soft-delete, transactions invalidated by reorgs (e.g., built on removed blocks) would be lost, causing false positives for data withholding violations.
29
+
30
+ Mined transactions are permanently deleted via `cleanupDeletedMinedTxs()` once their original block is finalized on L1, ensuring theyremain available during the uncertainty window.
31
+ Alternatively, mined transactions can be permanently deleted immediately by passing the `permanent: true` option to `deleteTxs()`.
32
+
33
+ #### Transaction Lifecycle Methods
34
+
35
+ | Method | Description |
36
+ |--------|-------------|
37
+ | `addTxs(txs, opts?)` | Adds transactions to the pool. Duplicates are ignored. Returns count of newly added txs. |
38
+ | `deleteTxs(txHashes, opts?)` | Removes transactions from the pool. Supports soft-delete for mined txs. |
39
+ | `markAsMined(txHashes, blockHeader)` | Marks transactions as included in a block. |
40
+ | `markMinedAsPending(txHashes, blockNumber)` | Reverts mined transactions to pending (used during reorgs). |
41
+ | `getArchivedTxByHash(txHash)` | Retrieves archived (historical) transactions. |
42
+ | `getTxStatus(txHash)` | Returns status: `'pending'`, `'mined'`, `'deleted'`, or `undefined`. |
43
+
44
+ ### Transaction Fetching
45
+
46
+ | Method | Description |
47
+ |--------|-------------|
48
+ | `hasTx(txHash)` / `hasTxs(txHashes)` | Checks if transaction(s) exist in the pool. |
49
+ | `getTxByHash(txHash)` | Retrieves a transaction by its hash. |
50
+ | `getTxsByHash(txHashes)` | Batch retrieval of transactions by hash. |
51
+ | `getAllTxs()` / `getAllTxHashes()` | Returns all transactions or their hashes. |
52
+ | `getPendingTxHashes()` | Returns pending tx hashes **sorted by priority** (highest first). |
53
+ | `getPendingTxCount()` | Returns count of pending transactions. |
54
+ | `getMinedTxHashes()` | Returns mined tx hashes with their block numbers. |
55
+
56
+ ### Pool Management
57
+
58
+ | Method | Description |
59
+ |--------|-------------|
60
+ | `updateConfig(config)` | Updates pool configuration (max size, archive limit). |
61
+ | `markTxsAsNonEvictable(txHashes)` | Protects transactions from eviction. |
62
+ | `clearNonEvictableTxs()` | Clears non-evictable flag from all transactions. |
63
+ | `cleanupDeletedMinedTxs(blockNumber)` | Permanently removes soft-deleted txs from blocks ≤ blockNumber. |
64
+ | `isEmpty()` | Checks if the pool has no transactions. |
65
+
66
+ ### Events
67
+
68
+ The pool emits a `txs-added` event when new transactions are successfully added, allowing subscribers to react to pool changes.
69
+
70
+ ## `AztecKVTxPool`
71
+
72
+ The [`AztecKVTxPool`](aztec_kv_tx_pool.ts) is the production-grade implementation backed by a persistent key-value store. It provides:
73
+
74
+ - **Persistent storage** via `AztecAsyncKVStore`
75
+ - **Multiple indexes** for efficient queries
76
+ - **Automatic eviction** of invalid and low-priority transactions
77
+ - **Transaction archival** for historical lookups
78
+ - **Soft-delete semantics** for mined transactions
79
+
80
+ #### Storage Structure
81
+
82
+ The pool maintains several KV maps and indexes:
83
+
84
+ | Store | Purpose |
85
+ |-------|---------|
86
+ | `#txs` | Primary storage: tx hash → serialized tx buffer |
87
+ | `#minedTxHashToBlock` | Index of mined txs: tx hash → block number |
88
+ | `#pendingTxPriorityToHash` | Priority-ordered index of pending txs |
89
+ | `#deletedMinedTxHashes` | Soft-deleted mined txs: tx hash → original block number |
90
+ | `#blockToDeletedMinedTxHash` | Reverse index for cleanup: block → deleted tx hashes |
91
+ | `#txHashToHistoricalBlockHeaderHash` | Anchor block reference for each tx |
92
+ | `#historicalHeaderToTxHash` | Index from historical block → tx hashes |
93
+ | `#feePayerToTxHash` | Index from fee payer address → tx hashes |
94
+ | `#archivedTxs` | Archived transactions for historical lookup |
95
+
96
+ #### In-Memory Caches
97
+
98
+ | Cache | Purpose |
99
+ |-------|---------|
100
+ | `#pendingTxs` | Hydrated pending transactions for fast access |
101
+ | `#nonEvictableTxs` | Set of tx hashes protected from eviction |
102
+
103
+ ## Transaction Priority
104
+
105
+ Transactions are prioritized based on their **total priority fees** (see [`priority.ts`](priority.ts)):
106
+
107
+ ```typescript
108
+ priorityFee = maxPriorityFeesPerGas.feePerDaGas + maxPriorityFeesPerGas.feePerL2Gas
109
+ ```
110
+
111
+ The priority is stored as a hex string derived from a 32-byte buffer representation of the fee amount, enabling lexicographic ordering in the KV store. Pending transactions are returned in **descending priority order** (highest fees first).
112
+
113
+ ## Transaction Lifecycle in AztecKVTxPool
114
+
115
+ ### 1. Adding Transactions
116
+
117
+ When `addTxs()` is called:
118
+
119
+ 1. Check for duplicates (skip if tx already exists)
120
+ 2. Store the serialized tx in `#txs`
121
+ 3. Index the tx by its anchor block hash
122
+ 4. If not already mined, add to pending indexes:
123
+ - Priority-to-hash index (for ordering)
124
+ - Historical header index (for reorg handling)
125
+ - Fee payer index (for balance validation)
126
+ 5. Record metrics
127
+ 6. Trigger eviction rules for `TXS_ADDED` event
128
+ 7. Emit `txs-added` event
129
+
130
+ ### 2. Marking as Mined
131
+
132
+ When a block is finalized, `markAsMined()`:
133
+
134
+ 1. Move tx from pending to mined status
135
+ 2. If previously soft-deleted, restore to mined status
136
+ 3. Trigger eviction rules for `BLOCK_MINED` event
137
+
138
+ ### 3. Handling Reorgs
139
+
140
+ When blocks are pruned, `markMinedAsPending()`:
141
+
142
+ 1. Remove tx from mined index
143
+ 2. Rehydrate pending indexes
144
+ 3. Trigger eviction rules for `CHAIN_PRUNED` event
145
+
146
+ ### 4. Deleting Transactions
147
+
148
+ The `deleteTxs()` method handles two cases:
149
+
150
+ - **Pending transactions**: Permanently deleted (transactions and all indexes to the transaction)
151
+ - **Mined transactions**: Soft-deleted by default (moved to `#deletedMinedTxHashes`), with option for permanent deletion
152
+
153
+ Soft-deleted mined transactions are retained for potential future reference and can be permanently cleaned up later via `cleanupDeletedMinedTxs()`.
154
+
155
+ ## Eviction System
156
+
157
+ The eviction system automatically removes invalid or low-priority transactions based on configurable rules. See the [`eviction/`](eviction/) subdirectory for implementation details.
158
+
159
+ ### Architecture
160
+
161
+ ```
162
+ ┌─────────────────────────────────────────────────────────────────┐
163
+ │ EvictionManager │
164
+ │ Orchestrates eviction rules based on pool events │
165
+ ├─────────────────────────────────────────────────────────────────┤
166
+ │ │
167
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
168
+ │ │EvictionRule #1 │ │EvictionRule #2 │ │EvictionRule #N │ │
169
+ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
170
+ │ │
171
+ └─────────────────────────────────────────────────────────────────┘
172
+
173
+
174
+ ┌─────────────────┐
175
+ │ TxPoolOperations│
176
+ │ (interface) │
177
+ └─────────────────┘
178
+ ```
179
+
180
+ The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
181
+
182
+ 1. Registering multiple `EvictionRule` implementations
183
+ 2. Calling each rule when tx pool events occur
184
+ 3. Propagating configuration updates to all rules
185
+
186
+ ### Eviction Events
187
+
188
+ | Event | Trigger | Purpose |
189
+ |-------|---------|---------|
190
+ | `TXS_ADDED` | New transactions added | Enforce pool size limits |
191
+ | `BLOCK_MINED` | Block finalized | Remove invalidated transactions |
192
+ | `CHAIN_PRUNED` | Chain reorganization | Remove txs referencing pruned blocks |
193
+
194
+ ### Eviction Rules
195
+
196
+ #### 1. `InvalidTxsAfterMiningRule`
197
+
198
+ **Triggers on:** `BLOCK_MINED`
199
+
200
+ Evicts transactions that become invalid after a block is mined:
201
+
202
+ - Duplicate nullifiers: Txs with nullifiers already included in the mined block
203
+ - Expired transactions: Txs with `includeByTimestamp` ≤ mined block timestamp
204
+
205
+ #### 2. `InvalidTxsAfterReorgRule`
206
+
207
+ **Triggers on:** `CHAIN_PRUNED`
208
+
209
+ Evicts transactions that reference blocks no longer in the canonical chain:
210
+
211
+ - Checks each pending tx's anchor block hash against the archive tree
212
+ - Removes txs whose anchor blocks are not found (pruned)
213
+
214
+ #### 3. `InsufficientFeePayerBalanceRule`
215
+
216
+ **Triggers on:** `BLOCK_MINED`, `CHAIN_PRUNED`
217
+
218
+ Evicts transactions whose fee payer no longer has sufficient balance:
219
+
220
+ - Uses `GasTxValidator` to check fee payer balances against current world state
221
+
222
+ #### 4. `LowPriorityEvictionRule`
223
+
224
+ **Triggers on:** `TXS_ADDED`
225
+
226
+ Enforces maximum pool size by evicting lowest-priority (by fee) transactions:
227
+
228
+ - Configured via `maxPendingTxCount` option (0 = disabled)
229
+ - Uses `getLowestPriorityEvictable()` to find txs to evict
230
+
231
+ ### Non-Evictable Transactions
232
+
233
+ Transactions can be marked as non-evictable via `markTxsAsNonEvictable()`. This protects them from all eviction rules, typically used during block building to ensure transactions being processed aren't evicted mid-operation. The flag is cleared after block processing via `clearNonEvictableTxs()`.
234
+ The `clearNonEvictableTxs` is called upon getting new L2 block.
235
+
236
+ ## Configuration
237
+
238
+ The pool accepts configuration via `TxPoolOptions`:
239
+
240
+ ```typescript
241
+ type TxPoolOptions = {
242
+ maxPendingTxCount?: number; // Max pending txs (0 = unlimited)
243
+ archivedTxLimit?: number; // Number of archived txs to retain
244
+ };
245
+ ```
246
+
247
+ Configuration can be updated at runtime via `updateConfig()`.
248
+
249
+ ## Telemetry
250
+
251
+ The pool integrates with the telemetry system to report:
252
+
253
+ - Transaction counts (pending vs mined)
254
+ - Transaction sizes
255
+ - Store size estimates