@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (443) 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 +22 -9
  4. package/dest/client/factory.d.ts +15 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -25
  7. package/dest/client/index.d.ts +2 -1
  8. package/dest/client/index.d.ts.map +1 -1
  9. package/dest/client/index.js +1 -0
  10. package/dest/client/interface.d.ts +170 -0
  11. package/dest/client/interface.d.ts.map +1 -0
  12. package/dest/client/interface.js +9 -0
  13. package/dest/client/p2p_client.d.ts +75 -193
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +757 -228
  16. package/dest/config.d.ts +148 -125
  17. package/dest/config.d.ts.map +1 -1
  18. package/dest/config.js +180 -34
  19. package/dest/enr/generate-enr.d.ts +11 -3
  20. package/dest/enr/generate-enr.d.ts.map +1 -1
  21. package/dest/enr/generate-enr.js +27 -5
  22. package/dest/enr/index.d.ts +1 -1
  23. package/dest/errors/attestation-pool.error.d.ts +7 -0
  24. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  25. package/dest/errors/attestation-pool.error.js +12 -0
  26. package/dest/errors/reqresp.error.d.ts +1 -1
  27. package/dest/errors/reqresp.error.d.ts.map +1 -1
  28. package/dest/index.d.ts +4 -1
  29. package/dest/index.d.ts.map +1 -1
  30. package/dest/index.js +2 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -25
  32. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +288 -174
  36. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  37. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +29 -11
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +168 -62
  40. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +24 -10
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +133 -82
  43. package/dest/mem_pools/attestation_pool/mocks.d.ts +232 -11
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +15 -20
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +16 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +55 -40
  50. package/dest/mem_pools/interface.d.ts +3 -4
  51. package/dest/mem_pools/interface.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +70 -16
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +452 -142
  55. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
  56. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  57. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
  58. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
  59. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  60. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
  61. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
  62. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
  63. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
  64. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  65. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  66. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  67. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  68. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  69. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
  70. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  71. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  72. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  73. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  74. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  75. package/dest/mem_pools/tx_pool/index.js +0 -1
  76. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  77. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool/priority.js +7 -2
  79. package/dest/mem_pools/tx_pool/tx_pool.d.ts +72 -11
  80. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  81. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  82. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  83. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +276 -45
  84. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -5
  85. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  86. package/dest/msg_validators/attestation_validator/attestation_validator.js +48 -10
  87. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  88. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  89. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +64 -0
  90. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  91. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  92. package/dest/msg_validators/attestation_validator/index.js +1 -0
  93. package/dest/msg_validators/index.d.ts +2 -2
  94. package/dest/msg_validators/index.d.ts.map +1 -1
  95. package/dest/msg_validators/index.js +1 -1
  96. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  97. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  98. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  99. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  100. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  101. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  102. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  103. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  104. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  105. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  106. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  107. package/dest/msg_validators/proposal_validator/index.js +3 -0
  108. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  109. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  110. package/dest/msg_validators/proposal_validator/proposal_validator.js +80 -0
  111. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  112. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  113. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +183 -0
  114. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  115. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  117. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  118. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  119. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  120. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  121. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  122. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  123. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  125. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  126. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  127. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  128. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  129. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  131. package/dest/msg_validators/tx_validator/factory.d.ts +16 -0
  132. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  133. package/dest/msg_validators/tx_validator/factory.js +74 -0
  134. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  135. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  136. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  137. package/dest/msg_validators/tx_validator/index.d.ts +8 -1
  138. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  139. package/dest/msg_validators/tx_validator/index.js +7 -0
  140. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +9 -5
  141. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  142. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  143. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  144. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  145. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  146. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  147. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  148. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  149. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  150. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  151. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  152. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  153. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  154. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  155. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  156. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  157. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  158. package/dest/services/data_store.d.ts +1 -1
  159. package/dest/services/data_store.d.ts.map +1 -1
  160. package/dest/services/discv5/discV5_service.d.ts +10 -9
  161. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  162. package/dest/services/discv5/discV5_service.js +63 -36
  163. package/dest/services/dummy_service.d.ts +54 -11
  164. package/dest/services/dummy_service.d.ts.map +1 -1
  165. package/dest/services/dummy_service.js +91 -5
  166. package/dest/services/encoding.d.ts +26 -7
  167. package/dest/services/encoding.d.ts.map +1 -1
  168. package/dest/services/encoding.js +76 -6
  169. package/dest/services/gossipsub/scoring.d.ts +1 -1
  170. package/dest/services/index.d.ts +5 -1
  171. package/dest/services/index.d.ts.map +1 -1
  172. package/dest/services/index.js +4 -0
  173. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  174. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  175. package/dest/services/libp2p/instrumentation.js +111 -0
  176. package/dest/services/libp2p/libp2p_service.d.ts +102 -96
  177. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  178. package/dest/services/libp2p/libp2p_service.js +1307 -301
  179. package/dest/services/peer-manager/interface.d.ts +23 -0
  180. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  181. package/dest/services/peer-manager/interface.js +1 -0
  182. package/dest/services/peer-manager/metrics.d.ts +11 -2
  183. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  184. package/dest/services/peer-manager/metrics.js +29 -12
  185. package/dest/services/peer-manager/peer_manager.d.ts +103 -23
  186. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  187. package/dest/services/peer-manager/peer_manager.js +551 -82
  188. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  189. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  190. package/dest/services/peer-manager/peer_scoring.js +37 -2
  191. package/dest/services/reqresp/config.d.ts +11 -9
  192. package/dest/services/reqresp/config.d.ts.map +1 -1
  193. package/dest/services/reqresp/config.js +18 -4
  194. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  195. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  196. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  197. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  198. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  199. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  200. package/dest/services/reqresp/index.d.ts +3 -2
  201. package/dest/services/reqresp/index.d.ts.map +1 -1
  202. package/dest/services/reqresp/index.js +2 -1
  203. package/dest/services/reqresp/interface.d.ts +73 -24
  204. package/dest/services/reqresp/interface.d.ts.map +1 -1
  205. package/dest/services/reqresp/interface.js +46 -27
  206. package/dest/services/reqresp/metrics.d.ts +1 -1
  207. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  208. package/dest/services/reqresp/metrics.js +5 -21
  209. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  210. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  211. package/dest/services/reqresp/protocols/auth.js +71 -0
  212. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  213. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  214. package/dest/services/reqresp/protocols/block.js +30 -6
  215. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  216. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  217. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  218. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  219. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  220. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  221. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  222. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  223. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  224. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  225. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  226. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  227. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  228. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  229. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  230. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  231. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  232. package/dest/services/reqresp/protocols/index.js +2 -0
  233. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  234. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  235. package/dest/services/reqresp/protocols/status.d.ts +40 -7
  236. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  237. package/dest/services/reqresp/protocols/status.js +75 -5
  238. package/dest/services/reqresp/protocols/tx.d.ts +14 -4
  239. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  240. package/dest/services/reqresp/protocols/tx.js +34 -6
  241. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  242. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  243. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  244. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  245. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  246. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  247. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  248. package/dest/services/reqresp/reqresp.d.ts +24 -66
  249. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  250. package/dest/services/reqresp/reqresp.js +699 -230
  251. package/dest/services/reqresp/status.d.ts +10 -4
  252. package/dest/services/reqresp/status.d.ts.map +1 -1
  253. package/dest/services/reqresp/status.js +9 -2
  254. package/dest/services/service.d.ts +37 -20
  255. package/dest/services/service.d.ts.map +1 -1
  256. package/dest/services/tx_collection/config.d.ts +25 -0
  257. package/dest/services/tx_collection/config.d.ts.map +1 -0
  258. package/dest/services/tx_collection/config.js +58 -0
  259. package/dest/services/tx_collection/fast_tx_collection.d.ts +51 -0
  260. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  261. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  262. package/dest/services/tx_collection/index.d.ts +3 -0
  263. package/dest/services/tx_collection/index.d.ts.map +1 -0
  264. package/dest/services/tx_collection/index.js +2 -0
  265. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  266. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  267. package/dest/services/tx_collection/instrumentation.js +24 -0
  268. package/dest/services/tx_collection/slow_tx_collection.d.ts +53 -0
  269. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  270. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  271. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  272. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  273. package/dest/services/tx_collection/tx_collection.js +128 -0
  274. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  275. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  276. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  277. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  278. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  279. package/dest/services/tx_collection/tx_source.js +31 -0
  280. package/dest/services/tx_provider.d.ts +51 -0
  281. package/dest/services/tx_provider.d.ts.map +1 -0
  282. package/dest/services/tx_provider.js +219 -0
  283. package/dest/services/tx_provider_instrumentation.d.ts +16 -0
  284. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  285. package/dest/services/tx_provider_instrumentation.js +34 -0
  286. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  287. package/dest/test-helpers/get-ports.d.ts +1 -1
  288. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  289. package/dest/test-helpers/index.d.ts +2 -1
  290. package/dest/test-helpers/index.d.ts.map +1 -1
  291. package/dest/test-helpers/index.js +1 -0
  292. package/dest/test-helpers/make-enrs.d.ts +1 -1
  293. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  294. package/dest/test-helpers/make-enrs.js +4 -5
  295. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  296. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  297. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  298. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  299. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  300. package/dest/test-helpers/mock-pubsub.js +130 -0
  301. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  302. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  303. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  304. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  305. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  306. package/dest/test-helpers/reqresp-nodes.js +62 -28
  307. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  308. package/dest/testbench/p2p_client_testbench_worker.js +124 -35
  309. package/dest/testbench/parse_log_file.d.ts +1 -1
  310. package/dest/testbench/parse_log_file.js +4 -4
  311. package/dest/testbench/testbench.d.ts +1 -1
  312. package/dest/testbench/testbench.js +4 -4
  313. package/dest/testbench/worker_client_manager.d.ts +1 -6
  314. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  315. package/dest/testbench/worker_client_manager.js +17 -20
  316. package/dest/types/index.d.ts +4 -2
  317. package/dest/types/index.d.ts.map +1 -1
  318. package/dest/types/index.js +2 -0
  319. package/dest/util.d.ts +24 -16
  320. package/dest/util.d.ts.map +1 -1
  321. package/dest/util.js +75 -69
  322. package/dest/versioning.d.ts +4 -4
  323. package/dest/versioning.d.ts.map +1 -1
  324. package/dest/versioning.js +8 -3
  325. package/package.json +32 -27
  326. package/src/bootstrap/bootstrap.ts +27 -11
  327. package/src/client/factory.ts +139 -53
  328. package/src/client/index.ts +1 -0
  329. package/src/client/interface.ts +213 -0
  330. package/src/client/p2p_client.ts +471 -385
  331. package/src/config.ts +299 -134
  332. package/src/enr/generate-enr.ts +39 -6
  333. package/src/errors/attestation-pool.error.ts +13 -0
  334. package/src/index.ts +4 -0
  335. package/src/mem_pools/attestation_pool/attestation_pool.ts +119 -24
  336. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +344 -201
  337. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +233 -72
  338. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +199 -96
  339. package/src/mem_pools/attestation_pool/mocks.ts +21 -16
  340. package/src/mem_pools/instrumentation.ts +71 -48
  341. package/src/mem_pools/interface.ts +2 -4
  342. package/src/mem_pools/tx_pool/README.md +255 -0
  343. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +537 -155
  344. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
  345. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
  346. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
  347. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  348. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
  349. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  350. package/src/mem_pools/tx_pool/index.ts +0 -1
  351. package/src/mem_pools/tx_pool/priority.ts +9 -2
  352. package/src/mem_pools/tx_pool/tx_pool.ts +75 -10
  353. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +225 -36
  354. package/src/msg_validators/attestation_validator/attestation_validator.ts +60 -14
  355. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +88 -0
  356. package/src/msg_validators/attestation_validator/index.ts +1 -0
  357. package/src/msg_validators/index.ts +1 -1
  358. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  359. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  360. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  361. package/src/msg_validators/proposal_validator/index.ts +3 -0
  362. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  363. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +206 -0
  364. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  365. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  366. package/src/msg_validators/tx_validator/block_header_validator.ts +5 -5
  367. package/src/msg_validators/tx_validator/data_validator.ts +89 -69
  368. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  369. package/src/msg_validators/tx_validator/factory.ts +110 -0
  370. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  371. package/src/msg_validators/tx_validator/index.ts +7 -0
  372. package/src/msg_validators/tx_validator/metadata_validator.ts +67 -22
  373. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  374. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  375. package/src/msg_validators/tx_validator/timestamp_validator.ts +49 -0
  376. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  377. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  378. package/src/services/discv5/discV5_service.ts +84 -38
  379. package/src/services/dummy_service.ts +153 -9
  380. package/src/services/encoding.ts +83 -6
  381. package/src/services/index.ts +4 -0
  382. package/src/services/libp2p/instrumentation.ts +113 -0
  383. package/src/services/libp2p/libp2p_service.ts +1120 -329
  384. package/src/services/peer-manager/interface.ts +29 -0
  385. package/src/services/peer-manager/metrics.ts +38 -12
  386. package/src/services/peer-manager/peer_manager.ts +657 -80
  387. package/src/services/peer-manager/peer_scoring.ts +42 -3
  388. package/src/services/reqresp/config.ts +26 -9
  389. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  390. package/src/services/reqresp/connection-sampler/connection_sampler.ts +150 -95
  391. package/src/services/reqresp/index.ts +2 -0
  392. package/src/services/reqresp/interface.ts +92 -37
  393. package/src/services/reqresp/metrics.ts +11 -24
  394. package/src/services/reqresp/protocols/auth.ts +83 -0
  395. package/src/services/reqresp/protocols/block.ts +26 -4
  396. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  397. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  398. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  399. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  400. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  401. package/src/services/reqresp/protocols/index.ts +2 -0
  402. package/src/services/reqresp/protocols/status.ts +119 -5
  403. package/src/services/reqresp/protocols/tx.ts +36 -8
  404. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  405. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  406. package/src/services/reqresp/reqresp.ts +387 -256
  407. package/src/services/reqresp/status.ts +12 -3
  408. package/src/services/service.ts +61 -22
  409. package/src/services/tx_collection/config.ts +84 -0
  410. package/src/services/tx_collection/fast_tx_collection.ts +341 -0
  411. package/src/services/tx_collection/index.ts +2 -0
  412. package/src/services/tx_collection/instrumentation.ts +26 -0
  413. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  414. package/src/services/tx_collection/tx_collection.ts +216 -0
  415. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  416. package/src/services/tx_collection/tx_source.ts +37 -0
  417. package/src/services/tx_provider.ts +232 -0
  418. package/src/services/tx_provider_instrumentation.ts +48 -0
  419. package/src/test-helpers/index.ts +1 -0
  420. package/src/test-helpers/make-enrs.ts +4 -5
  421. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  422. package/src/test-helpers/mock-pubsub.ts +188 -0
  423. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  424. package/src/test-helpers/reqresp-nodes.ts +87 -36
  425. package/src/testbench/p2p_client_testbench_worker.ts +182 -32
  426. package/src/testbench/parse_log_file.ts +4 -4
  427. package/src/testbench/testbench.ts +4 -4
  428. package/src/testbench/worker_client_manager.ts +23 -24
  429. package/src/types/index.ts +2 -0
  430. package/src/util.ts +105 -91
  431. package/src/versioning.ts +11 -4
  432. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
  433. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  434. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -141
  435. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
  436. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  437. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -21
  438. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  439. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  440. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  441. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -174
  442. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -29
  443. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,21 +1,38 @@
1
+ import { insertIntoSortedArray } from '@aztec/foundation/array';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
3
  import { toArray } from '@aztec/foundation/iterable';
2
4
  import { createLogger } from '@aztec/foundation/log';
3
- import { ClientIvcProof } from '@aztec/stdlib/proofs';
5
+ import { ChonkProof } from '@aztec/stdlib/proofs';
4
6
  import { Tx, TxHash } from '@aztec/stdlib/tx';
5
7
  import { getTelemetryClient } from '@aztec/telemetry-client';
8
+ import assert from 'assert';
9
+ import EventEmitter from 'node:events';
10
+ import { ArchiveCache } from '../../msg_validators/tx_validator/archive_cache.js';
6
11
  import { PoolInstrumentation, PoolName } from '../instrumentation.js';
12
+ import { EvictionManager } from './eviction/eviction_manager.js';
13
+ import { InsufficientFeePayerBalanceRule } from './eviction/insufficient_fee_payer_balance_rule.js';
14
+ import { InvalidTxsAfterMiningRule } from './eviction/invalid_txs_after_mining_rule.js';
15
+ import { InvalidTxsAfterReorgRule } from './eviction/invalid_txs_after_reorg_rule.js';
16
+ import { LowPriorityEvictionRule } from './eviction/low_priority_eviction_rule.js';
7
17
  import { getPendingTxPriority } from './priority.js';
8
18
  /**
9
19
  * KV implementation of the Transaction Pool.
10
- */ export class AztecKVTxPool {
20
+ */ export class AztecKVTxPool extends EventEmitter {
11
21
  #store;
12
22
  /** Our tx pool, stored as a Map, with K: tx hash and V: the transaction. */ #txs;
23
+ /** Holds the historical block for each tx */ #pendingTxHashToHistoricalBlockHeaderHash;
13
24
  /** Index from tx hash to the block number in which they were mined, filtered by mined txs. */ #minedTxHashToBlock;
14
25
  /** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */ #pendingTxPriorityToHash;
26
+ /** Map from tx hash to the block number it was originally mined in (for soft-deleted txs). */ #deletedMinedTxHashes;
27
+ /** MultiMap from block number to deleted mined tx hashes for efficient cleanup. */ #blockToDeletedMinedTxHash;
28
+ #historicalHeaderToTxHash;
29
+ #feePayerToTxHash;
30
+ /** In-memory set of txs that should not be evicted from the pool. */ #nonEvictableTxs;
15
31
  /** KV store for archived txs. */ #archive;
16
32
  /** Archived txs map for future lookup. */ #archivedTxs;
17
33
  /** Indexes of the archived txs by insertion order. */ #archivedTxIndices;
18
- /** Number of txs to archive. */ #archivedTxLimit;
34
+ /** Number of txs to archive. */ #archivedTxLimit = 0;
35
+ #evictionManager;
19
36
  #log;
20
37
  #metrics;
21
38
  /**
@@ -25,83 +42,122 @@ import { getPendingTxPriority } from './priority.js';
25
42
  * @param telemetry - A telemetry client.
26
43
  * @param archivedTxLimit - The number of txs to archive.
27
44
  * @param log - A logger.
28
- */ constructor(store, archive, telemetry = getTelemetryClient(), archivedTxLimit = 0, log = createLogger('p2p:tx_pool')){
45
+ */ constructor(store, archive, worldState, telemetry = getTelemetryClient(), config = {}, log = createLogger('p2p:tx_pool')){
46
+ super();
47
+ this.#log = log;
48
+ this.#evictionManager = new EvictionManager(this);
49
+ this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
50
+ this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(worldState));
51
+ this.#evictionManager.registerRule(new InsufficientFeePayerBalanceRule(worldState));
52
+ this.#evictionManager.registerRule(new LowPriorityEvictionRule({
53
+ //NOTE: 0 effectively disables low priority eviction
54
+ maxPoolSize: config.maxPendingTxCount ?? 0
55
+ }));
56
+ this.updateConfig(config);
29
57
  this.#txs = store.openMap('txs');
30
58
  this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
31
59
  this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
60
+ this.#deletedMinedTxHashes = store.openMap('deletedMinedTxHashes');
61
+ this.#blockToDeletedMinedTxHash = store.openMultiMap('blockToDeletedMinedTxHash');
62
+ this.#pendingTxHashToHistoricalBlockHeaderHash = store.openMap('txHistoricalBlock');
63
+ this.#historicalHeaderToTxHash = store.openMultiMap('historicalHeaderToPendingTxHash');
64
+ this.#feePayerToTxHash = store.openMultiMap('feePayerToPendingTxHash');
65
+ this.#nonEvictableTxs = new Set();
32
66
  this.#archivedTxs = archive.openMap('archivedTxs');
33
67
  this.#archivedTxIndices = archive.openMap('archivedTxIndices');
34
- this.#archivedTxLimit = archivedTxLimit;
35
68
  this.#store = store;
36
69
  this.#archive = archive;
37
- this.#log = log;
38
- this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, ()=>store.estimateSize());
70
+ this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, this.countTxs, ()=>store.estimateSize());
71
+ }
72
+ countTxs = async ()=>{
73
+ const [pending = 0, mined = 0] = await Promise.all([
74
+ this.getPendingTxCount(),
75
+ this.getMinedTxCount()
76
+ ]);
77
+ return Promise.resolve({
78
+ itemCount: {
79
+ pending,
80
+ mined
81
+ }
82
+ });
83
+ };
84
+ async isEmpty() {
85
+ for await (const _ of this.#txs.entriesAsync()){
86
+ return false;
87
+ }
88
+ return true;
39
89
  }
40
- markAsMined(txHashes, blockNumber) {
90
+ /**
91
+ * Marks transactions as mined in a block and updates the pool state accordingly.
92
+ * Removes the transactions from the pending set and adds them to the mined set.
93
+ * Also evicts any transactions that become invalid after the block is mined.
94
+ * @param txHashes - Array of transaction hashes that were mined
95
+ * @param blockHeader - The header of the block the transactions were mined in
96
+ */ async markAsMined(txHashes, blockHeader) {
41
97
  if (txHashes.length === 0) {
42
98
  return Promise.resolve();
43
99
  }
44
- let deletedPending = 0;
45
- return this.#store.transactionAsync(async ()=>{
46
- for (const hash of txHashes){
47
- const key = hash.toString();
48
- await this.#minedTxHashToBlock.set(key, blockNumber);
49
- const tx = await this.getTxByHash(hash);
50
- if (tx) {
51
- deletedPending++;
52
- const fee = getPendingTxPriority(tx);
53
- await this.#pendingTxPriorityToHash.deleteValue(fee, key);
100
+ const uniqueMinedNullifiers = [];
101
+ const uniqueMinedFeePayers = [];
102
+ try {
103
+ await this.#store.transactionAsync(async ()=>{
104
+ for (const hash of txHashes){
105
+ const key = hash.toString();
106
+ await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
107
+ const tx = await this.getPendingTxByHash(hash);
108
+ if (tx) {
109
+ const nullifiers = tx.data.getNonEmptyNullifiers();
110
+ nullifiers.forEach((nullifier)=>insertIntoSortedArray(uniqueMinedNullifiers, nullifier, Fr.cmp, false));
111
+ insertIntoSortedArray(uniqueMinedFeePayers, tx.data.feePayer, (a, b)=>a.toField().cmp(b.toField()), false);
112
+ await this.removePendingTxIndicesInDbTx(tx, key);
113
+ }
114
+ // If this tx was previously soft-deleted, remove it from the deleted sets
115
+ if (await this.#deletedMinedTxHashes.hasAsync(key)) {
116
+ const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
117
+ await this.#deletedMinedTxHashes.delete(key);
118
+ // Remove from block-to-hash mapping
119
+ if (originalBlock !== undefined) {
120
+ await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
121
+ }
122
+ }
54
123
  }
55
- }
56
- this.#metrics.recordAddedObjects(txHashes.length, 'mined');
57
- this.#metrics.recordRemovedObjects(deletedPending, 'pending');
58
- });
124
+ });
125
+ await this.#evictionManager.evictAfterNewBlock(blockHeader, uniqueMinedNullifiers, uniqueMinedFeePayers);
126
+ this.#metrics.transactionsRemoved(txHashes.map((hash)=>hash.toBigInt()));
127
+ } catch (err) {
128
+ this.#log.warn('Unexpected error when marking txs as mined', {
129
+ err
130
+ });
131
+ }
59
132
  }
60
- markMinedAsPending(txHashes) {
133
+ async markMinedAsPending(txHashes, latestBlock) {
61
134
  if (txHashes.length === 0) {
62
135
  return Promise.resolve();
63
136
  }
64
- let markedAsPending = 0;
65
- return this.#store.transactionAsync(async ()=>{
66
- for (const hash of txHashes){
67
- const key = hash.toString();
68
- await this.#minedTxHashToBlock.delete(key);
69
- const tx = await this.getTxByHash(hash);
70
- if (tx) {
71
- await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), key);
72
- markedAsPending++;
137
+ try {
138
+ await this.#store.transactionAsync(async ()=>{
139
+ for (const hash of txHashes){
140
+ const key = hash.toString();
141
+ await this.#minedTxHashToBlock.delete(key);
142
+ // Rehydrate the tx in the in-memory pending txs mapping
143
+ const tx = await this.getPendingTxByHash(hash);
144
+ if (tx) {
145
+ await this.addPendingTxIndicesInDbTx(tx, key);
146
+ }
73
147
  }
74
- }
75
- this.#metrics.recordAddedObjects(markedAsPending, 'pending');
76
- this.#metrics.recordRemovedObjects(markedAsPending, 'mined');
77
- });
148
+ });
149
+ await this.#evictionManager.evictAfterChainPrune(latestBlock);
150
+ } catch (err) {
151
+ this.#log.warn('Unexpected error when marking mined txs as pending', {
152
+ err
153
+ });
154
+ }
78
155
  }
79
156
  async getPendingTxHashes() {
80
157
  const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({
81
158
  reverse: true
82
159
  }));
83
- return vals.map((x)=>TxHash.fromString(x));
84
- }
85
- async getMinedTxHashes() {
86
- const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
87
- return vals.map(([txHash, blockNumber])=>[
88
- TxHash.fromString(txHash),
89
- blockNumber
90
- ]);
91
- }
92
- async getTxStatus(txHash) {
93
- const key = txHash.toString();
94
- const [isMined, isKnown] = await Promise.all([
95
- this.#minedTxHashToBlock.hasAsync(key),
96
- this.#txs.hasAsync(key)
97
- ]);
98
- if (isMined) {
99
- return 'mined';
100
- } else if (isKnown) {
101
- return 'pending';
102
- } else {
103
- return undefined;
104
- }
160
+ return vals.map(TxHash.fromString);
105
161
  }
106
162
  /**
107
163
  * Checks if a transaction exists in the pool and returns it.
@@ -109,12 +165,20 @@ import { getPendingTxPriority } from './priority.js';
109
165
  * @returns The transaction, if found, 'undefined' otherwise.
110
166
  */ async getTxByHash(txHash) {
111
167
  const buffer = await this.#txs.getAsync(txHash.toString());
112
- if (buffer) {
113
- const tx = Tx.fromBuffer(buffer);
114
- tx.setTxHash(txHash);
115
- return tx;
116
- }
117
- return undefined;
168
+ return buffer ? Tx.fromBuffer(buffer) : undefined;
169
+ }
170
+ async getTxsByHash(txHashes) {
171
+ const txs = await Promise.all(txHashes.map((txHash)=>this.#txs.getAsync(txHash.toString())));
172
+ return txs.map((buffer)=>buffer ? Tx.fromBuffer(buffer) : undefined);
173
+ }
174
+ async hasTxs(txHashes) {
175
+ return await Promise.all(txHashes.map((txHash)=>this.#txs.hasAsync(txHash.toString())));
176
+ }
177
+ async hasTx(txHash) {
178
+ const result = await this.hasTxs([
179
+ txHash
180
+ ]);
181
+ return result[0];
118
182
  }
119
183
  /**
120
184
  * Checks if an archived tx exists and returns it.
@@ -122,85 +186,120 @@ import { getPendingTxPriority } from './priority.js';
122
186
  * @returns The transaction metadata, if found, 'undefined' otherwise.
123
187
  */ async getArchivedTxByHash(txHash) {
124
188
  const buffer = await this.#archivedTxs.getAsync(txHash.toString());
125
- if (buffer) {
126
- const tx = Tx.fromBuffer(buffer);
127
- tx.setTxHash(txHash);
128
- return tx;
129
- }
130
- return undefined;
189
+ return buffer ? Tx.fromBuffer(buffer) : undefined;
131
190
  }
132
191
  /**
133
192
  * Adds a list of transactions to the pool. Duplicates are ignored.
134
193
  * @param txs - An array of txs to be added to the pool.
135
- * @returns Empty promise.
136
- */ async addTxs(txs) {
137
- const hashesAndStats = await Promise.all(txs.map(async (tx)=>({
138
- txHash: await tx.getTxHash(),
139
- txStats: await tx.getStats()
140
- })));
141
- await this.#store.transactionAsync(async ()=>{
142
- let pendingCount = 0;
143
- await Promise.all(txs.map(async (tx, i)=>{
144
- const { txHash, txStats } = hashesAndStats[i];
145
- this.#log.verbose(`Adding tx ${txHash.toString()} to pool`, {
146
- eventName: 'tx-added-to-pool',
147
- ...txStats
148
- });
149
- const key = txHash.toString();
150
- await this.#txs.set(key, tx.toBuffer());
151
- if (!await this.#minedTxHashToBlock.hasAsync(key)) {
152
- pendingCount++;
153
- // REFACTOR: Use an lmdb conditional write to avoid race conditions with this write tx
154
- await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), key);
155
- this.#metrics.recordSize(tx);
156
- }
194
+ * @returns count of added transactions
195
+ */ async addTxs(txs, opts = {}) {
196
+ if (txs.length === 0) {
197
+ return Promise.resolve(0);
198
+ }
199
+ const addedTxs = [];
200
+ const hashesAndStats = txs.map((tx)=>({
201
+ txHash: tx.getTxHash(),
202
+ txStats: tx.getStats()
157
203
  }));
158
- this.#metrics.recordAddedObjects(pendingCount, 'pending');
159
- });
204
+ try {
205
+ await this.#store.transactionAsync(async ()=>{
206
+ await Promise.all(txs.map(async (tx, i)=>{
207
+ const { txHash, txStats } = hashesAndStats[i];
208
+ const key = txHash.toString();
209
+ if (await this.#txs.hasAsync(key)) {
210
+ this.#log.debug(`Tx ${txHash.toString()} already exists in the pool`);
211
+ return;
212
+ }
213
+ this.#log.verbose(`Adding tx ${txHash.toString()} to pool`, {
214
+ eventName: 'tx-added-to-pool',
215
+ ...txStats
216
+ });
217
+ await this.#txs.set(key, tx.toBuffer());
218
+ addedTxs.push(tx);
219
+ await this.#pendingTxHashToHistoricalBlockHeaderHash.set(key, (await tx.data.constants.anchorBlockHeader.hash()).toString());
220
+ if (!await this.#minedTxHashToBlock.hasAsync(key)) {
221
+ await this.addPendingTxIndicesInDbTx(tx, key);
222
+ this.#metrics.recordSize(tx);
223
+ }
224
+ }));
225
+ });
226
+ await this.#evictionManager.evictAfterNewTxs(addedTxs.map(({ txHash })=>txHash));
227
+ } catch (err) {
228
+ this.#log.warn('Unexpected error when adding txs', {
229
+ err
230
+ });
231
+ }
232
+ if (addedTxs.length > 0) {
233
+ this.#metrics.transactionsAdded(addedTxs);
234
+ this.emit('txs-added', {
235
+ ...opts,
236
+ txs: addedTxs
237
+ });
238
+ }
239
+ return addedTxs.length;
160
240
  }
161
241
  /**
162
242
  * Deletes transactions from the pool. Tx hashes that are not present are ignored.
163
- * @param txHashes - An array of tx hashes to be removed from the tx pool.
243
+ * Mined transactions are soft-deleted with a timestamp, pending transactions are permanently deleted.
244
+ * @param txHashes - An array of tx hashes to be deleted from the tx pool.
164
245
  * @returns Empty promise.
165
- */ deleteTxs(txHashes) {
166
- let pendingDeleted = 0;
167
- let minedDeleted = 0;
246
+ */ deleteTxs(txHashes, opts) {
247
+ if (txHashes.length === 0) {
248
+ return Promise.resolve();
249
+ }
168
250
  const deletedTxs = [];
169
251
  const poolDbTx = this.#store.transactionAsync(async ()=>{
170
252
  for (const hash of txHashes){
171
253
  const key = hash.toString();
172
254
  const tx = await this.getTxByHash(hash);
173
- if (tx) {
174
- const fee = getPendingTxPriority(tx);
175
- await this.#pendingTxPriorityToHash.deleteValue(fee, key);
176
- const isMined = await this.#minedTxHashToBlock.hasAsync(key);
177
- if (isMined) {
178
- minedDeleted++;
179
- } else {
180
- pendingDeleted++;
181
- }
182
- if (this.#archivedTxLimit) {
255
+ if (!tx) {
256
+ this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
257
+ continue;
258
+ }
259
+ const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
260
+ const txIsPending = minedBlockNumber === undefined;
261
+ if (txIsPending) {
262
+ await this.deletePendingTx(tx, key);
263
+ } else {
264
+ await this.deleteMinedTx(key, minedBlockNumber, opts?.permanently ?? false);
265
+ const shouldArchiveTx = this.#archivedTxLimit && !opts?.permanently;
266
+ if (shouldArchiveTx) {
183
267
  deletedTxs.push(tx);
184
268
  }
185
- await this.#txs.delete(key);
186
- await this.#minedTxHashToBlock.delete(key);
187
269
  }
188
270
  }
189
- this.#metrics.recordRemovedObjects(pendingDeleted, 'pending');
190
- this.#metrics.recordRemovedObjects(minedDeleted, 'mined');
271
+ });
272
+ this.#metrics.transactionsRemoved(txHashes.map((hash)=>hash.toBigInt()));
273
+ this.#log.debug(`Deleted ${txHashes.length} txs from pool`, {
274
+ txHashes
191
275
  });
192
276
  return this.#archivedTxLimit ? poolDbTx.then(()=>this.archiveTxs(deletedTxs)) : poolDbTx;
193
277
  }
278
+ async deleteMinedTx(txHash, minedBlockNumber, permanently) {
279
+ await this.#minedTxHashToBlock.delete(txHash);
280
+ if (permanently) {
281
+ this.#log.trace(`Deleting mined tx ${txHash} from pool`);
282
+ await this.#txs.delete(txHash);
283
+ return;
284
+ }
285
+ // Soft-delete mined transactions: remove from mined set but keep in storage
286
+ this.#log.trace(`Soft-deleting mined tx ${txHash} from pool`);
287
+ await this.#deletedMinedTxHashes.set(txHash, minedBlockNumber);
288
+ await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, txHash);
289
+ }
290
+ async deletePendingTx(tx, txHash) {
291
+ // We always permanently delete pending transactions
292
+ this.#log.trace(`Deleting pending tx ${txHash} from pool`);
293
+ await this.removePendingTxIndices(tx, txHash);
294
+ await this.#txs.delete(txHash);
295
+ await this.#pendingTxHashToHistoricalBlockHeaderHash.delete(txHash);
296
+ }
194
297
  /**
195
298
  * Gets all the transactions stored in the pool.
196
299
  * @returns Array of tx objects in the order they were added to the pool.
197
300
  */ async getAllTxs() {
198
- const vals = await toArray(this.#txs.entriesAsync());
199
- return vals.map(([hash, buffer])=>{
200
- const tx = Tx.fromBuffer(buffer);
201
- tx.setTxHash(TxHash.fromString(hash));
202
- return tx;
203
- });
301
+ const vals = await toArray(this.#txs.valuesAsync());
302
+ return vals.map((buffer)=>Tx.fromBuffer(buffer));
204
303
  }
205
304
  /**
206
305
  * Gets the hashes of all transactions currently in the tx pool.
@@ -209,37 +308,248 @@ import { getPendingTxPriority } from './priority.js';
209
308
  const vals = await toArray(this.#txs.keysAsync());
210
309
  return vals.map((x)=>TxHash.fromString(x));
211
310
  }
311
+ async getPendingTxInfos() {
312
+ const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync());
313
+ const results = await Promise.all(vals.map((val)=>this.getPendingTxInfo(TxHash.fromString(val))));
314
+ return results.filter((info)=>info !== undefined);
315
+ }
316
+ async getPendingTxInfo(txHash) {
317
+ let historicalBlockHash = await this.#pendingTxHashToHistoricalBlockHeaderHash.getAsync(txHash.toString());
318
+ // Not all tx might have this index created.
319
+ if (!historicalBlockHash) {
320
+ const tx = await this.getPendingTxByHash(txHash);
321
+ if (!tx) {
322
+ this.#log.warn(`PendingTxInfo:tx ${txHash} not found`);
323
+ return undefined;
324
+ }
325
+ historicalBlockHash = (await tx.data.constants.anchorBlockHeader.hash()).toString();
326
+ await this.#pendingTxHashToHistoricalBlockHeaderHash.set(txHash.toString(), historicalBlockHash);
327
+ }
328
+ return {
329
+ txHash,
330
+ blockHash: Fr.fromString(historicalBlockHash),
331
+ isEvictable: !this.#nonEvictableTxs.has(txHash.toString())
332
+ };
333
+ }
334
+ async getPendingTxsReferencingBlocks(blockHashes) {
335
+ const result = [];
336
+ for (const blockHash of blockHashes){
337
+ const chunk = await toArray(this.#historicalHeaderToTxHash.getValuesAsync(blockHash.toString()));
338
+ result.push(...chunk.map((txHash)=>({
339
+ txHash: TxHash.fromString(txHash),
340
+ blockHash,
341
+ isEvictable: !this.#nonEvictableTxs.has(txHash)
342
+ })));
343
+ }
344
+ return result;
345
+ }
346
+ async getPendingTxsWithFeePayer(feePayers) {
347
+ const result = [];
348
+ for (const feePayer of feePayers){
349
+ const chunk = await toArray(this.#feePayerToTxHash.getValuesAsync(feePayer.toString()));
350
+ const infos = await Promise.all(chunk.map((txHash)=>this.getPendingTxInfo(TxHash.fromString(txHash))));
351
+ result.push(...infos.filter((info)=>info !== undefined));
352
+ }
353
+ return result;
354
+ }
355
+ async getMinedTxHashes() {
356
+ const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
357
+ return vals.map(([txHash, blockNumber])=>[
358
+ TxHash.fromString(txHash),
359
+ blockNumber
360
+ ]);
361
+ }
362
+ async getPendingTxCount() {
363
+ return await this.#pendingTxPriorityToHash.sizeAsync() ?? 0;
364
+ }
365
+ async getMinedTxCount() {
366
+ return await this.#minedTxHashToBlock.sizeAsync() ?? 0;
367
+ }
368
+ async getTxStatus(txHash) {
369
+ const key = txHash.toString();
370
+ const [isMined, isKnown, isDeleted] = await Promise.all([
371
+ this.#minedTxHashToBlock.hasAsync(key),
372
+ this.#txs.hasAsync(key),
373
+ this.#deletedMinedTxHashes.hasAsync(key)
374
+ ]);
375
+ if (isDeleted) {
376
+ return 'deleted';
377
+ } else if (isMined) {
378
+ return 'mined';
379
+ } else if (isKnown) {
380
+ return 'pending';
381
+ } else {
382
+ return undefined;
383
+ }
384
+ }
385
+ updateConfig(cfg) {
386
+ if (typeof cfg.archivedTxLimit === 'number') {
387
+ assert(cfg.archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
388
+ this.#archivedTxLimit = cfg.archivedTxLimit;
389
+ }
390
+ if (this.#evictionManager) {
391
+ this.#evictionManager.updateConfig(cfg);
392
+ }
393
+ }
394
+ markTxsAsNonEvictable(txHashes) {
395
+ txHashes.forEach((txHash)=>this.#nonEvictableTxs.add(txHash.toString()));
396
+ return Promise.resolve();
397
+ }
398
+ clearNonEvictableTxs() {
399
+ // Clear the non-evictable set after completing the DB updates above.
400
+ // This ensures pinned (non-evictable) txs are protected while we mark mined txs,
401
+ // but they won't remain pinned indefinitely across blocks. Note that eviction rules
402
+ // (including post-mining invalidation) respect the non-evictable flag while it is set.
403
+ this.#nonEvictableTxs.clear();
404
+ return Promise.resolve();
405
+ }
406
+ /**
407
+ * Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
408
+ * @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
409
+ * @returns The number of transactions permanently deleted.
410
+ */ async cleanupDeletedMinedTxs(blockNumber) {
411
+ let deletedCount = 0;
412
+ await this.#store.transactionAsync(async ()=>{
413
+ const txHashesToDelete = [];
414
+ const blocksToDelete = [];
415
+ // Iterate through all entries and check block numbers
416
+ for await (const [block, txHash] of this.#blockToDeletedMinedTxHash.entriesAsync()){
417
+ if (block <= blockNumber) {
418
+ // Permanently delete the transaction
419
+ await this.#txs.delete(txHash);
420
+ await this.#deletedMinedTxHashes.delete(txHash);
421
+ txHashesToDelete.push(txHash);
422
+ if (!blocksToDelete.includes(block)) {
423
+ blocksToDelete.push(block);
424
+ }
425
+ deletedCount++;
426
+ }
427
+ }
428
+ this.#metrics.transactionsRemoved(txHashesToDelete);
429
+ // Clean up block-to-hash mapping - delete all values for each block
430
+ for (const block of blocksToDelete){
431
+ const txHashesForBlock = await toArray(this.#blockToDeletedMinedTxHash.getValuesAsync(block));
432
+ for (const txHash of txHashesForBlock){
433
+ await this.#blockToDeletedMinedTxHash.deleteValue(block, txHash);
434
+ }
435
+ }
436
+ });
437
+ if (deletedCount > 0) {
438
+ this.#log.debug(`Permanently deleted ${deletedCount} deleted mined txs from blocks up to ${blockNumber}`);
439
+ }
440
+ return deletedCount;
441
+ }
442
+ /**
443
+ * Creates an ArchiveCache instance.
444
+ * @param db - DB for the cache to use
445
+ * @returns An ArchiveCache instance
446
+ */ createArchiveCache(db) {
447
+ return new ArchiveCache(db);
448
+ }
449
+ /**
450
+ * Checks if a cached transaction exists in the in-memory pending tx pool and returns it.
451
+ * Otherwise, it checks the tx pool, updates the pending tx pool, and returns the tx.
452
+ * @param txHash - The generated tx hash.
453
+ * @returns The transaction, if found, 'undefined' otherwise.
454
+ */ async getPendingTxByHash(txHash) {
455
+ if (typeof txHash === 'string') {
456
+ txHash = TxHash.fromString(txHash);
457
+ }
458
+ const tx = await this.getTxByHash(txHash);
459
+ if (tx) {
460
+ return tx;
461
+ }
462
+ return undefined;
463
+ }
212
464
  /**
213
465
  * Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
466
+ * Note: Pending txs should not be archived, only finalized txs
214
467
  * @param txs - The list of transactions to archive.
215
468
  * @returns Empty promise.
216
469
  */ async archiveTxs(txs) {
217
- const txHashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
218
- await this.#archive.transactionAsync(async ()=>{
219
- // calcualte the head and tail indices of the archived txs by insertion order.
220
- let headIdx = ((await this.#archivedTxIndices.entriesAsync({
221
- limit: 1,
222
- reverse: true
223
- }).next()).value?.[0] ?? -1) + 1;
224
- let tailIdx = (await this.#archivedTxIndices.entriesAsync({
225
- limit: 1
226
- }).next()).value?.[0] ?? 0;
227
- for(let i = 0; i < txs.length; i++){
228
- const tx = txs[i];
229
- while(headIdx - tailIdx >= this.#archivedTxLimit){
230
- const txHash = await this.#archivedTxIndices.getAsync(tailIdx);
231
- if (txHash) {
232
- await this.#archivedTxs.delete(txHash);
233
- await this.#archivedTxIndices.delete(tailIdx);
470
+ if (txs.length === 0) {
471
+ return;
472
+ }
473
+ if (this.#archivedTxLimit === 0) {
474
+ return;
475
+ }
476
+ try {
477
+ const txHashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
478
+ await this.#archive.transactionAsync(async ()=>{
479
+ // calculate the head and tail indices of the archived txs by insertion order.
480
+ let headIdx = ((await this.#archivedTxIndices.entriesAsync({
481
+ limit: 1,
482
+ reverse: true
483
+ }).next()).value?.[0] ?? -1) + 1;
484
+ let tailIdx = (await this.#archivedTxIndices.entriesAsync({
485
+ limit: 1
486
+ }).next()).value?.[0] ?? 0;
487
+ for(let i = 0; i < txs.length; i++){
488
+ const tx = txs[i];
489
+ while(headIdx - tailIdx >= this.#archivedTxLimit){
490
+ const txHash = await this.#archivedTxIndices.getAsync(tailIdx);
491
+ if (txHash) {
492
+ await this.#archivedTxs.delete(txHash);
493
+ await this.#archivedTxIndices.delete(tailIdx);
494
+ }
495
+ tailIdx++;
234
496
  }
235
- tailIdx++;
497
+ const archivedTx = new Tx(tx.txHash, tx.data, ChonkProof.empty(), tx.contractClassLogFields, tx.publicFunctionCalldata);
498
+ const txHash = txHashes[i].toString();
499
+ await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
500
+ await this.#archivedTxIndices.set(headIdx, txHash);
501
+ headIdx++;
236
502
  }
237
- const archivedTx = new Tx(tx.data, ClientIvcProof.empty(), tx.contractClassLogs, tx.enqueuedPublicFunctionCalls, tx.publicTeardownFunctionCall);
238
- const txHash = txHashes[i].toString();
239
- await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
240
- await this.#archivedTxIndices.set(headIdx, txHash);
241
- headIdx++;
242
- }
503
+ this.#log.debug(`Archived ${txs.length} txs`, {
504
+ txHashes
505
+ });
506
+ this.#log.debug(`Total archived txs: ${headIdx - tailIdx}`);
507
+ });
508
+ } catch (error) {
509
+ this.#log.error(`Error archiving txs`, {
510
+ error
511
+ });
512
+ }
513
+ }
514
+ // Assumes being called within a DB transaction
515
+ async addPendingTxIndicesInDbTx(tx, txHash) {
516
+ await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
517
+ await this.#historicalHeaderToTxHash.set((await tx.data.constants.anchorBlockHeader.hash()).toString(), txHash);
518
+ await this.#feePayerToTxHash.set(tx.data.feePayer.toString(), txHash);
519
+ }
520
+ async addPendingTxIndices(tx, txHash) {
521
+ return await this.#store.transactionAsync(async ()=>{
522
+ await this.addPendingTxIndicesInDbTx(tx, txHash);
243
523
  });
244
524
  }
525
+ // Assumes being called within a DB transaction
526
+ async removePendingTxIndicesInDbTx(tx, txHash) {
527
+ await this.#pendingTxPriorityToHash.deleteValue(getPendingTxPriority(tx), txHash);
528
+ await this.#historicalHeaderToTxHash.deleteValue((await tx.data.constants.anchorBlockHeader.hash()).toString(), txHash);
529
+ await this.#feePayerToTxHash.deleteValue(tx.data.feePayer.toString(), txHash);
530
+ }
531
+ async removePendingTxIndices(tx, txHash) {
532
+ return await this.#store.transactionAsync(async ()=>{
533
+ await this.removePendingTxIndicesInDbTx(tx, txHash);
534
+ });
535
+ }
536
+ /**
537
+ * Returns up to `limit` lowest-priority evictable pending tx hashes without hydrating transactions.
538
+ * Iterates the priority index in ascending order and skips non-evictable txs.
539
+ */ async getLowestPriorityEvictable(limit) {
540
+ const txsToEvict = [];
541
+ if (limit <= 0) {
542
+ return txsToEvict;
543
+ }
544
+ for await (const txHashStr of this.#pendingTxPriorityToHash.valuesAsync()){
545
+ if (this.#nonEvictableTxs.has(txHashStr)) {
546
+ continue;
547
+ }
548
+ txsToEvict.push(TxHash.fromString(txHashStr));
549
+ if (txsToEvict.length >= limit) {
550
+ break;
551
+ }
552
+ }
553
+ return txsToEvict;
554
+ }
245
555
  }