@aztec/p2p 0.0.1-commit.86469d5 → 0.0.1-commit.88c5703d4

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 (414) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +11 -11
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +53 -14
  5. package/dest/client/interface.d.ts +46 -33
  6. package/dest/client/interface.d.ts.map +1 -1
  7. package/dest/client/p2p_client.d.ts +41 -51
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +159 -224
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +7 -8
  11. package/dest/config.d.ts +54 -17
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +95 -39
  14. package/dest/errors/tx-pool.error.d.ts +8 -0
  15. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  16. package/dest/errors/tx-pool.error.js +9 -0
  17. package/dest/index.d.ts +2 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -0
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
  21. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/attestation_pool/attestation_pool.js +445 -3
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  26. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  27. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/index.js +1 -2
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  30. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  32. package/dest/mem_pools/index.d.ts +3 -2
  33. package/dest/mem_pools/index.d.ts.map +1 -1
  34. package/dest/mem_pools/index.js +1 -1
  35. package/dest/mem_pools/instrumentation.d.ts +4 -2
  36. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  37. package/dest/mem_pools/instrumentation.js +16 -14
  38. package/dest/mem_pools/interface.d.ts +5 -5
  39. package/dest/mem_pools/interface.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  41. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
  43. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  44. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  45. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/priority.js +4 -4
  47. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  48. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  50. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  51. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  53. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  54. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  56. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  57. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +97 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  89. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  90. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  92. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  93. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  94. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  95. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +215 -0
  96. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  97. package/dest/mem_pools/tx_pool_v2/interfaces.js +10 -0
  98. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +134 -0
  99. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  100. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +216 -0
  101. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +337 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +62 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +167 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +78 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +923 -0
  113. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  114. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  115. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  116. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  117. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  118. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  119. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  120. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  121. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  122. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  123. package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
  124. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  125. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  126. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  127. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  128. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  129. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  130. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  131. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  132. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  133. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  134. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  135. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  136. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  137. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  138. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  139. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  140. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  141. package/dest/msg_validators/tx_validator/factory.js +240 -59
  142. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  143. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  144. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  145. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  146. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  147. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  148. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  149. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  150. package/dest/msg_validators/tx_validator/index.js +2 -0
  151. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  152. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  153. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  154. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  155. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  156. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  157. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  158. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  159. package/dest/msg_validators/tx_validator/phases_validator.js +71 -23
  160. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  161. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  162. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  163. package/dest/services/dummy_service.d.ts +13 -5
  164. package/dest/services/dummy_service.d.ts.map +1 -1
  165. package/dest/services/dummy_service.js +10 -4
  166. package/dest/services/encoding.d.ts +3 -3
  167. package/dest/services/encoding.d.ts.map +1 -1
  168. package/dest/services/encoding.js +11 -10
  169. package/dest/services/gossipsub/index.d.ts +3 -0
  170. package/dest/services/gossipsub/index.d.ts.map +1 -0
  171. package/dest/services/gossipsub/index.js +2 -0
  172. package/dest/services/gossipsub/scoring.d.ts +21 -3
  173. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  174. package/dest/services/gossipsub/scoring.js +24 -7
  175. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  176. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  177. package/dest/services/gossipsub/topic_score_params.js +346 -0
  178. package/dest/services/index.d.ts +2 -1
  179. package/dest/services/index.d.ts.map +1 -1
  180. package/dest/services/index.js +1 -0
  181. package/dest/services/libp2p/libp2p_service.d.ts +94 -42
  182. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  183. package/dest/services/libp2p/libp2p_service.js +463 -350
  184. package/dest/services/peer-manager/metrics.d.ts +3 -1
  185. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  186. package/dest/services/peer-manager/metrics.js +6 -0
  187. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  188. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  189. package/dest/services/peer-manager/peer_manager.js +2 -1
  190. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  191. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  192. package/dest/services/peer-manager/peer_scoring.js +25 -2
  193. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +13 -6
  194. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  195. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +51 -61
  196. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -6
  197. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  198. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  199. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  200. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  201. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  202. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  203. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  204. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  205. package/dest/services/reqresp/interface.d.ts +10 -1
  206. package/dest/services/reqresp/interface.d.ts.map +1 -1
  207. package/dest/services/reqresp/interface.js +15 -1
  208. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  209. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  210. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
  211. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +21 -10
  212. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  213. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +27 -11
  214. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  215. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  216. package/dest/services/reqresp/protocols/tx.js +20 -0
  217. package/dest/services/reqresp/reqresp.d.ts +1 -1
  218. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  219. package/dest/services/reqresp/reqresp.js +14 -6
  220. package/dest/services/service.d.ts +39 -3
  221. package/dest/services/service.d.ts.map +1 -1
  222. package/dest/services/tx_collection/config.d.ts +22 -4
  223. package/dest/services/tx_collection/config.d.ts.map +1 -1
  224. package/dest/services/tx_collection/config.js +49 -3
  225. package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -5
  226. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  227. package/dest/services/tx_collection/fast_tx_collection.js +64 -48
  228. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  229. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  230. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  231. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  232. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  233. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  234. package/dest/services/tx_collection/index.d.ts +3 -2
  235. package/dest/services/tx_collection/index.d.ts.map +1 -1
  236. package/dest/services/tx_collection/index.js +1 -0
  237. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  238. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  239. package/dest/services/tx_collection/instrumentation.js +2 -1
  240. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  241. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  242. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  243. package/dest/services/tx_collection/proposal_tx_collector.d.ts +15 -14
  244. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  245. package/dest/services/tx_collection/proposal_tx_collector.js +6 -6
  246. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  247. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  248. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  249. package/dest/services/tx_collection/tx_collection.d.ts +23 -10
  250. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  251. package/dest/services/tx_collection/tx_collection.js +75 -3
  252. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  253. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  254. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  255. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  256. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  257. package/dest/services/tx_collection/tx_source.js +19 -2
  258. package/dest/services/tx_file_store/config.d.ts +16 -0
  259. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  260. package/dest/services/tx_file_store/config.js +22 -0
  261. package/dest/services/tx_file_store/index.d.ts +4 -0
  262. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  263. package/dest/services/tx_file_store/index.js +3 -0
  264. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  265. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  266. package/dest/services/tx_file_store/instrumentation.js +29 -0
  267. package/dest/services/tx_file_store/tx_file_store.d.ts +48 -0
  268. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  269. package/dest/services/tx_file_store/tx_file_store.js +152 -0
  270. package/dest/services/tx_provider.d.ts +4 -4
  271. package/dest/services/tx_provider.d.ts.map +1 -1
  272. package/dest/services/tx_provider.js +9 -8
  273. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  274. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  275. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  276. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  277. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  278. package/dest/test-helpers/mock-pubsub.js +105 -4
  279. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  280. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  281. package/dest/test-helpers/reqresp-nodes.js +4 -3
  282. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  283. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  284. package/dest/test-helpers/testbench-utils.js +129 -59
  285. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  286. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  287. package/dest/testbench/p2p_client_testbench_worker.js +17 -16
  288. package/dest/testbench/worker_client_manager.d.ts +3 -1
  289. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  290. package/dest/testbench/worker_client_manager.js +6 -2
  291. package/dest/util.d.ts +3 -3
  292. package/dest/util.d.ts.map +1 -1
  293. package/package.json +14 -14
  294. package/src/client/factory.ts +102 -27
  295. package/src/client/interface.ts +56 -34
  296. package/src/client/p2p_client.ts +193 -269
  297. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +21 -12
  298. package/src/config.ts +148 -44
  299. package/src/errors/tx-pool.error.ts +12 -0
  300. package/src/index.ts +1 -0
  301. package/src/mem_pools/attestation_pool/attestation_pool.ts +497 -91
  302. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  303. package/src/mem_pools/attestation_pool/index.ts +9 -2
  304. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  305. package/src/mem_pools/index.ts +4 -1
  306. package/src/mem_pools/instrumentation.ts +17 -13
  307. package/src/mem_pools/interface.ts +4 -4
  308. package/src/mem_pools/tx_pool/README.md +1 -1
  309. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  310. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  311. package/src/mem_pools/tx_pool/priority.ts +4 -4
  312. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  313. package/src/mem_pools/tx_pool_v2/README.md +283 -0
  314. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  315. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  316. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  317. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
  318. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +122 -0
  319. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +125 -0
  320. package/src/mem_pools/tx_pool_v2/eviction/index.ts +27 -0
  321. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
  322. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  323. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  324. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
  325. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
  326. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
  327. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  328. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  329. package/src/mem_pools/tx_pool_v2/interfaces.ts +247 -0
  330. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +337 -0
  331. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  332. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +430 -0
  333. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +238 -0
  334. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1105 -0
  335. package/src/msg_validators/attestation_validator/README.md +49 -0
  336. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  337. package/src/msg_validators/proposal_validator/README.md +123 -0
  338. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  339. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  340. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
  341. package/src/msg_validators/tx_validator/README.md +119 -0
  342. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  343. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  344. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  345. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  346. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  347. package/src/msg_validators/tx_validator/factory.ts +387 -78
  348. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  349. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  350. package/src/msg_validators/tx_validator/index.ts +2 -0
  351. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  352. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  353. package/src/msg_validators/tx_validator/phases_validator.ts +81 -26
  354. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  355. package/src/services/dummy_service.ts +18 -6
  356. package/src/services/encoding.ts +9 -9
  357. package/src/services/gossipsub/README.md +641 -0
  358. package/src/services/gossipsub/index.ts +2 -0
  359. package/src/services/gossipsub/scoring.ts +29 -5
  360. package/src/services/gossipsub/topic_score_params.ts +487 -0
  361. package/src/services/index.ts +1 -0
  362. package/src/services/libp2p/libp2p_service.ts +488 -372
  363. package/src/services/peer-manager/metrics.ts +7 -0
  364. package/src/services/peer-manager/peer_manager.ts +2 -1
  365. package/src/services/peer-manager/peer_scoring.ts +25 -0
  366. package/src/services/reqresp/README.md +229 -0
  367. package/src/services/reqresp/batch-tx-requester/README.md +7 -7
  368. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +59 -67
  369. package/src/services/reqresp/batch-tx-requester/interface.ts +3 -5
  370. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  371. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  372. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  373. package/src/services/reqresp/interface.ts +26 -1
  374. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +23 -14
  375. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +38 -15
  376. package/src/services/reqresp/protocols/tx.ts +22 -0
  377. package/src/services/reqresp/reqresp.ts +17 -5
  378. package/src/services/service.ts +51 -2
  379. package/src/services/tx_collection/config.ts +74 -6
  380. package/src/services/tx_collection/fast_tx_collection.ts +74 -51
  381. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  382. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  383. package/src/services/tx_collection/index.ts +2 -1
  384. package/src/services/tx_collection/instrumentation.ts +7 -1
  385. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  386. package/src/services/tx_collection/proposal_tx_collector.ts +20 -21
  387. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  388. package/src/services/tx_collection/tx_collection.ts +113 -16
  389. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  390. package/src/services/tx_collection/tx_source.ts +22 -3
  391. package/src/services/tx_file_store/config.ts +37 -0
  392. package/src/services/tx_file_store/index.ts +3 -0
  393. package/src/services/tx_file_store/instrumentation.ts +36 -0
  394. package/src/services/tx_file_store/tx_file_store.ts +175 -0
  395. package/src/services/tx_provider.ts +10 -9
  396. package/src/test-helpers/make-test-p2p-clients.ts +4 -6
  397. package/src/test-helpers/mock-pubsub.ts +146 -9
  398. package/src/test-helpers/reqresp-nodes.ts +5 -7
  399. package/src/test-helpers/testbench-utils.ts +128 -71
  400. package/src/testbench/p2p_client_testbench_worker.ts +26 -22
  401. package/src/testbench/worker_client_manager.ts +13 -5
  402. package/src/util.ts +8 -2
  403. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  404. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  405. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  406. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  407. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  408. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  409. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  410. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  411. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  412. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  413. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  414. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -6,7 +6,6 @@ import type { PeerId } from '@libp2p/interface';
6
6
 
7
7
  import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
8
8
  import type { ReqRespInterface } from '../interface.js';
9
- import type { MissingTxMetadata } from './missing_txs.js';
10
9
  import type { IPeerCollection } from './peer_collection.js';
11
10
  import type { BatchRequestTxValidatorConfig, IBatchRequestTxValidator } from './tx_validator.js';
12
11
 
@@ -15,18 +14,17 @@ export interface IPeerPenalizer {
15
14
  }
16
15
 
17
16
  export interface ITxMetadataCollection {
18
- size: number;
19
- values(): IterableIterator<MissingTxMetadata>;
20
17
  getMissingTxHashes(): Set<string>;
18
+ markFetched(peerId: PeerId, tx: Tx): boolean;
21
19
  getTxsToRequestFromThePeer(peer: PeerId): TxHash[];
22
20
  markRequested(txHash: TxHash): void;
23
21
  markInFlightBySmartPeer(txHash: TxHash): void;
24
22
  markNotInFlightBySmartPeer(txHash: TxHash): void;
25
23
  alreadyFetched(txHash: TxHash): boolean;
26
24
  // Returns true if tx was marked as fetched, false if it was already marked as fetched
27
- markFetched(peerId: PeerId, tx: Tx): boolean;
28
25
  markPeerHas(peerId: PeerId, txHashes: TxHash[]): void;
29
- getFetchedTxs(): Tx[];
26
+ /** Remove all tx metadata associations for a peer (e.g. on demotion from smart to dumb). */
27
+ clearPeerData(peerId: PeerId): void;
30
28
  }
31
29
 
32
30
  /**
@@ -2,13 +2,13 @@ import { type Tx, TxHash } from '@aztec/stdlib/tx';
2
2
 
3
3
  import type { PeerId } from '@libp2p/interface';
4
4
 
5
+ import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
5
6
  import { DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE } from './config.js';
6
7
  import type { ITxMetadataCollection } from './interface.js';
7
8
 
8
- export class MissingTxMetadata {
9
+ class MissingTxMetadata {
9
10
  constructor(
10
- public readonly txHash: TxHash,
11
- public fetched = false,
11
+ public readonly txHash: string,
12
12
  public requestedCount = 0,
13
13
  public inFlightCount = 0,
14
14
  public tx: Tx | undefined = undefined,
@@ -30,24 +30,6 @@ export class MissingTxMetadata {
30
30
  public isInFlight(): boolean {
31
31
  return this.inFlightCount > 0;
32
32
  }
33
-
34
- //Returns true if this is the first time we mark it as fetched
35
- public markAsFetched(peerId: PeerId, tx: Tx): boolean {
36
- if (this.fetched) {
37
- return false;
38
- }
39
-
40
- this.fetched = true;
41
- this.tx = tx;
42
-
43
- this.peers.add(peerId.toString());
44
-
45
- return true;
46
- }
47
-
48
- public toString() {
49
- return this.txHash.toString();
50
- }
51
33
  }
52
34
 
53
35
  /*
@@ -55,21 +37,18 @@ export class MissingTxMetadata {
55
37
  * This could be better optimized but given expected count of missing txs (N < 100)
56
38
  * At the moment there is no need for it. And benefit is that we have everything in single store
57
39
  * */
58
- export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata> implements ITxMetadataCollection {
40
+ export class MissingTxMetadataCollection implements ITxMetadataCollection {
41
+ private txMetadata = new Map<string, MissingTxMetadata>();
42
+
59
43
  constructor(
60
- entries?: readonly (readonly [string, MissingTxMetadata])[] | null,
44
+ private missingTxsTracker: IMissingTxsTracker,
61
45
  private readonly txBatchSize: number = DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
62
46
  ) {
63
- super(entries);
64
- }
65
- public getSortedByRequestedCountAsc(txs: string[]): MissingTxMetadata[] {
66
- return Array.from(this.values().filter(txMeta => txs.includes(txMeta.txHash.toString()))).sort(
67
- (a, b) => a.requestedCount - b.requestedCount,
68
- );
47
+ missingTxsTracker.missingTxHashes.forEach(hash => this.txMetadata.set(hash, new MissingTxMetadata(hash)));
69
48
  }
70
49
 
71
50
  public getPrioritizingNotInFlightAndLowerRequestCount(txs: string[]): MissingTxMetadata[] {
72
- const filtered = Array.from(this.values()).filter(txMeta => txs.includes(txMeta.txHash.toString()));
51
+ const filtered = Array.from(this.txMetadata.values()).filter(txMeta => txs.includes(txMeta.txHash.toString()));
73
52
 
74
53
  const [notInFlight, inFlight] = filtered.reduce<[MissingTxMetadata[], MissingTxMetadata[]]>(
75
54
  (buckets, tx) => {
@@ -85,43 +64,15 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
85
64
  return [...notInFlight, ...inFlight];
86
65
  }
87
66
 
88
- public getFetchedTxHashes(): Set<string> {
89
- return new Set(
90
- this.values()
91
- .filter(t => t.fetched)
92
- .map(t => t.txHash.toString()),
93
- );
94
- }
95
-
96
67
  public getMissingTxHashes(): Set<string> {
97
- return new Set(
98
- this.values()
99
- .filter(t => !t.fetched)
100
- .map(t => t.txHash.toString()),
101
- );
102
- }
103
-
104
- public getInFlightTxHashes(): Set<string> {
105
- return new Set(
106
- this.values()
107
- .filter(t => t.isInFlight())
108
- .map(t => t.txHash.toString()),
109
- );
110
- }
111
-
112
- public getFetchedTxs(): Tx[] {
113
- return Array.from(
114
- this.values()
115
- .map(t => t.tx)
116
- .filter(t => !!t),
117
- );
68
+ return this.missingTxsTracker.missingTxHashes;
118
69
  }
119
70
 
120
71
  public getTxsPeerHas(peer: PeerId): Set<string> {
121
72
  const peerIdStr = peer.toString();
122
73
  const txsPeerHas = new Set<string>();
123
74
 
124
- this.values().forEach(txMeta => {
75
+ this.txMetadata.values().forEach(txMeta => {
125
76
  if (txMeta.peers.has(peerIdStr)) {
126
77
  txsPeerHas.add(txMeta.txHash.toString());
127
78
  }
@@ -132,13 +83,13 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
132
83
 
133
84
  public getTxsToRequestFromThePeer(peer: PeerId): TxHash[] {
134
85
  const txsPeerHas = this.getTxsPeerHas(peer);
135
- const fetchedTxs = this.getFetchedTxHashes();
86
+ const missingTxHashes = this.getMissingTxHashes();
136
87
 
137
- const txsToRequest = txsPeerHas.difference(fetchedTxs);
88
+ const txsToRequest = txsPeerHas.intersection(missingTxHashes);
138
89
 
139
90
  if (txsToRequest.size >= this.txBatchSize) {
140
91
  return this.getPrioritizingNotInFlightAndLowerRequestCount(Array.from(txsToRequest))
141
- .map(t => t.txHash)
92
+ .map(t => TxHash.fromString(t.txHash))
142
93
  .slice(0, this.txBatchSize);
143
94
  }
144
95
 
@@ -150,13 +101,13 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
150
101
  Array.from(this.getMissingTxHashes().difference(txsToRequest)),
151
102
  )
152
103
  .slice(0, countToFill)
153
- .map(t => t.txHash);
104
+ .map(t => TxHash.fromString(t.txHash));
154
105
 
155
106
  return [...Array.from(txsToRequest).map(t => TxHash.fromString(t)), ...txsToFill];
156
107
  }
157
108
 
158
109
  public markRequested(txHash: TxHash) {
159
- this.get(txHash.toString())?.markAsRequested();
110
+ this.txMetadata.get(txHash.toString())?.markAsRequested();
160
111
  }
161
112
 
162
113
  /*
@@ -165,7 +116,7 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
165
116
  * "dumb" peer might return it, or might not - we don't know
166
117
  * */
167
118
  public markInFlightBySmartPeer(txHash: TxHash) {
168
- this.get(txHash.toString())?.markInFlight();
119
+ this.txMetadata.get(txHash.toString())?.markInFlight();
169
120
  }
170
121
 
171
122
  /*
@@ -173,16 +124,16 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
173
124
  * Because the smart peer should return this tx, whereas
174
125
  * "dumb" peer might return it, or might not - we don't know*/
175
126
  public markNotInFlightBySmartPeer(txHash: TxHash) {
176
- this.get(txHash.toString())?.markNotInFlight();
127
+ this.txMetadata.get(txHash.toString())?.markNotInFlight();
177
128
  }
178
129
 
179
130
  public alreadyFetched(txHash: TxHash): boolean {
180
- return this.get(txHash.toString())?.fetched ?? false;
131
+ return !this.missingTxsTracker.isMissing(txHash.toString());
181
132
  }
182
133
 
183
134
  public markFetched(peerId: PeerId, tx: Tx): boolean {
184
135
  const txHashStr = tx.txHash.toString();
185
- const txMeta = this.get(txHashStr);
136
+ const txMeta = this.txMetadata.get(txHashStr);
186
137
  if (!txMeta) {
187
138
  //TODO: what to do about peer which sent txs we didn't request?
188
139
  // 1. don't request from it in the scope of this batch request
@@ -192,7 +143,8 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
192
143
  return false;
193
144
  }
194
145
 
195
- return txMeta.markAsFetched(peerId, tx);
146
+ txMeta.peers.add(peerId.toString());
147
+ return this.missingTxsTracker.markFetched(tx);
196
148
  }
197
149
 
198
150
  public markPeerHas(peerId: PeerId, txHash: TxHash[]) {
@@ -200,10 +152,17 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
200
152
  txHash
201
153
  .map(t => t.toString())
202
154
  .forEach(txh => {
203
- const txMeta = this.get(txh);
155
+ const txMeta = this.txMetadata.get(txh);
204
156
  if (txMeta) {
205
157
  txMeta.peers.add(peerIdStr);
206
158
  }
207
159
  });
208
160
  }
161
+
162
+ public clearPeerData(peerId: PeerId) {
163
+ const peerIdStr = peerId.toString();
164
+ for (const txMeta of this.txMetadata.values()) {
165
+ txMeta.peers.delete(peerIdStr);
166
+ }
167
+ }
209
168
  }
@@ -2,18 +2,23 @@ import type { DateProvider } from '@aztec/foundation/timer';
2
2
  import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
3
 
4
4
  import type { PeerId } from '@libp2p/interface';
5
+ import { peerIdFromString } from '@libp2p/peer-id';
5
6
 
7
+ import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
6
8
  import { DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD } from './config.js';
7
9
  import type { IPeerPenalizer } from './interface.js';
8
10
 
9
11
  export const RATE_LIMIT_EXCEEDED_PEER_CACHE_TTL = 1000; // 1s
10
12
 
11
13
  export interface IPeerCollection {
12
- getAllPeers(): Set<string>;
13
- getSmartPeers(): Set<string>;
14
14
  markPeerSmart(peerId: PeerId): void;
15
- getSmartPeersToQuery(): Array<string>;
16
- getDumbPeersToQuery(): Array<string>;
15
+ markPeerDumb(peerId: PeerId): void;
16
+
17
+ /** Sample next peer in round-robin fashion. No smart peers if returns undefined */
18
+ nextSmartPeerToQuery(): PeerId | undefined;
19
+ /** Sample next peer in round-robin fashion. No dumb peers if returns undefined */
20
+ nextDumbPeerToQuery(): PeerId | undefined;
21
+
17
22
  thereAreSomeDumbRatelimitExceededPeers(): boolean;
18
23
  penalisePeer(peerId: PeerId, severity: PeerErrorSeverity): void;
19
24
  unMarkPeerAsBad(peerId: PeerId): void;
@@ -28,8 +33,6 @@ export interface IPeerCollection {
28
33
  }
29
34
 
30
35
  export class PeerCollection implements IPeerCollection {
31
- private readonly peers;
32
-
33
36
  private readonly smartPeers = new Set<string>();
34
37
  private readonly inFlightPeers = new Set<string>();
35
38
  private readonly rateLimitExceededPeers = new Map<string, number>();
@@ -37,46 +40,64 @@ export class PeerCollection implements IPeerCollection {
37
40
  private readonly badPeers = new Set<string>();
38
41
 
39
42
  constructor(
40
- initialPeers: PeerId[],
43
+ private readonly connectionSampler: Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>,
41
44
  private readonly pinnedPeerId: PeerId | undefined,
42
45
  private readonly dateProvider: DateProvider,
43
46
  private readonly badPeerThreshold: number = DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD,
44
47
  private readonly peerPenalizer?: IPeerPenalizer,
45
48
  ) {
46
- this.peers = new Set(initialPeers.map(peer => peer.toString()));
47
-
48
- // Pinned peer is treaded specially, always mark it as in-flight
49
+ // Pinned peer is treated specially, always mark it as in-flight
49
50
  // and never return it as part of smart/dumb peers
50
51
  if (this.pinnedPeerId) {
51
52
  const peerIdStr = this.pinnedPeerId.toString();
52
53
  this.inFlightPeers.add(peerIdStr);
53
- this.peers.delete(peerIdStr);
54
54
  }
55
55
  }
56
56
 
57
- public getAllPeers(): Set<string> {
58
- return this.peers;
57
+ public markPeerSmart(peerId: PeerId): void {
58
+ this.smartPeers.add(peerId.toString());
59
59
  }
60
60
 
61
- public getSmartPeers(): Set<string> {
62
- return this.smartPeers;
61
+ public markPeerDumb(peerId: PeerId): void {
62
+ this.smartPeers.delete(peerId.toString());
63
63
  }
64
64
 
65
- public markPeerSmart(peerId: PeerId): void {
66
- this.smartPeers.add(peerId.toString());
65
+ // We keep track of all peers that are queried for peer sampling algorithm
66
+ private queriedSmartPeers: Set<string> = new Set<string>();
67
+ private queriedDumbPeers: Set<string> = new Set<string>();
68
+
69
+ private static nextPeer(allPeers: Set<string>, queried: Set<string>): PeerId | undefined {
70
+ if (allPeers.size === 0) {
71
+ return undefined;
72
+ }
73
+ const availablePeers = allPeers.difference(queried);
74
+ let [first] = availablePeers;
75
+ if (first === undefined) {
76
+ // We queried all peers. Start over
77
+ [first] = allPeers;
78
+ queried.clear();
79
+ }
80
+ queried.add(first);
81
+ return peerIdFromString(first);
67
82
  }
68
83
 
69
- public getSmartPeersToQuery(): Array<string> {
70
- return Array.from(
84
+ public nextSmartPeerToQuery(): PeerId | undefined {
85
+ return PeerCollection.nextPeer(this.availableSmartPeers, this.queriedSmartPeers);
86
+ }
87
+
88
+ public nextDumbPeerToQuery(): PeerId | undefined {
89
+ return PeerCollection.nextPeer(this.availableDumbPeers, this.queriedDumbPeers);
90
+ }
91
+
92
+ private get availableSmartPeers(): Set<string> {
93
+ return this.peers.intersection(
71
94
  this.smartPeers.difference(this.getBadPeers().union(this.inFlightPeers).union(this.getRateLimitExceededPeers())),
72
95
  );
73
96
  }
74
97
 
75
- public getDumbPeersToQuery(): Array<string> {
76
- return Array.from(
77
- this.peers.difference(
78
- this.smartPeers.union(this.getBadPeers()).union(this.inFlightPeers).union(this.getRateLimitExceededPeers()),
79
- ),
98
+ private get availableDumbPeers(): Set<string> {
99
+ return this.peers.difference(
100
+ this.smartPeers.union(this.getBadPeers()).union(this.inFlightPeers).union(this.getRateLimitExceededPeers()),
80
101
  );
81
102
  }
82
103
 
@@ -202,4 +223,27 @@ export class PeerCollection implements IPeerCollection {
202
223
 
203
224
  return minExpiry! - now;
204
225
  }
226
+
227
+ private orderedPeers: Set<string> = new Set();
228
+
229
+ private get peers(): Set<string> {
230
+ const pinnedStr = this.pinnedPeerId?.toString();
231
+ const currentlyConnected = new Set(
232
+ this.connectionSampler
233
+ .getPeerListSortedByConnectionCountAsc()
234
+ .map(p => p.toString())
235
+ .filter(p => p !== pinnedStr),
236
+ );
237
+
238
+ // Remove disconnected peers, preserving order of the rest.
239
+ this.orderedPeers = this.orderedPeers.intersection(currentlyConnected);
240
+
241
+ // Append newly connected peers at the end (lowest priority).
242
+ for (const peer of currentlyConnected) {
243
+ if (!this.orderedPeers.has(peer)) {
244
+ this.orderedPeers.add(peer);
245
+ }
246
+ }
247
+ return this.orderedPeers;
248
+ }
205
249
  }
@@ -1,7 +1,7 @@
1
1
  import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
2
2
  import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
3
3
 
4
- import { createTxReqRespValidator } from '../../../msg_validators/tx_validator/factory.js';
4
+ import { createTxValidatorForReqResponseReceivedTxs } from '../../../msg_validators/index.js';
5
5
 
6
6
  export interface BatchRequestTxValidatorConfig {
7
7
  l1ChainId: number;
@@ -29,7 +29,7 @@ export class BatchRequestTxValidator implements IBatchRequestTxValidator {
29
29
  }
30
30
 
31
31
  static createRequestedTxValidator(config: BatchRequestTxValidatorConfig): TxValidator {
32
- return createTxReqRespValidator(config.proofVerifier, {
32
+ return createTxValidatorForReqResponseReceivedTxs(config.proofVerifier, {
33
33
  l1ChainId: config.l1ChainId,
34
34
  rollupVersion: config.rollupVersion,
35
35
  });
@@ -1,5 +1,6 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { L2Block } from '@aztec/stdlib/block';
3
+ import { MAX_L2_BLOCK_SIZE_KB } from '@aztec/stdlib/p2p';
3
4
  import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
4
5
 
5
6
  import type { PeerId } from '@libp2p/interface';
@@ -7,8 +8,13 @@ import type { PeerId } from '@libp2p/interface';
7
8
  import type { P2PReqRespConfig } from './config.js';
8
9
  import type { ConnectionSampler } from './connection-sampler/connection_sampler.js';
9
10
  import { AuthRequest, AuthResponse } from './protocols/auth.js';
10
- import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
11
+ import {
12
+ BlockTxsRequest,
13
+ BlockTxsResponse,
14
+ calculateBlockTxsResponseSize,
15
+ } from './protocols/block_txs/block_txs_reqresp.js';
11
16
  import { StatusMessage } from './protocols/status.js';
17
+ import { calculateTxResponseSize } from './protocols/tx.js';
12
18
  import type { ReqRespStatus } from './status.js';
13
19
 
14
20
  /*
@@ -211,6 +217,25 @@ export const subProtocolMap = {
211
217
  },
212
218
  };
213
219
 
220
+ /**
221
+ * Type for a function that calculates the expected response size in KB for a given request.
222
+ */
223
+ export type ExpectedResponseSizeCalculator = (requestBuffer: Buffer) => number;
224
+
225
+ /**
226
+ * Map of sub-protocols to their expected response size calculators.
227
+ * These are used to validate that responses don't exceed expected sizes based on request parameters.
228
+ */
229
+ export const subProtocolSizeCalculators: Record<ReqRespSubProtocol, ExpectedResponseSizeCalculator> = {
230
+ [ReqRespSubProtocol.TX]: calculateTxResponseSize,
231
+ [ReqRespSubProtocol.BLOCK_TXS]: calculateBlockTxsResponseSize,
232
+ [ReqRespSubProtocol.BLOCK]: () => MAX_L2_BLOCK_SIZE_KB,
233
+ [ReqRespSubProtocol.STATUS]: () => 1,
234
+ [ReqRespSubProtocol.PING]: () => 1,
235
+ [ReqRespSubProtocol.AUTH]: () => 1,
236
+ [ReqRespSubProtocol.GOODBYE]: () => 1, // No response expected, but provide minimal limit
237
+ };
238
+
214
239
  export interface ReqRespInterface {
215
240
  start(
216
241
  subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
@@ -1,10 +1,11 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { L2BlockSource } from '@aztec/stdlib/block';
2
3
  import { TxArray } from '@aztec/stdlib/tx';
3
4
 
4
5
  import type { PeerId } from '@libp2p/interface';
5
6
 
6
- import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
7
- import type { TxPool } from '../../../../mem_pools/index.js';
7
+ import type { AttestationPoolApi } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
8
+ import type { TxPoolV2 } from '../../../../mem_pools/tx_pool_v2/interfaces.js';
8
9
  import type { ReqRespSubProtocolHandler } from '../../interface.js';
9
10
  import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
10
11
  import { BitVector } from './bitvector.js';
@@ -13,10 +14,15 @@ import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
13
14
  /**
14
15
  * Handler for block txs requests
15
16
  * @param attestationPool - the attestation pool to check for block proposals
16
- * @param mempools - the mempools containing the tx pool
17
+ * @param archiver - the archiver to look up blocks by archive root
18
+ * @param txPool - the tx pool to fetch transactions from
17
19
  * @returns the BlockTxs request handler
18
20
  */
19
- export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler {
21
+ export function reqRespBlockTxsHandler(
22
+ attestationPool: AttestationPoolApi,
23
+ archiver: L2BlockSource,
24
+ txPool: TxPoolV2,
25
+ ): ReqRespSubProtocolHandler {
20
26
  /**
21
27
  * Handler for block txs requests
22
28
  * @param msg - the block txs request message
@@ -30,34 +36,37 @@ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool:
30
36
  } catch (err: any) {
31
37
  throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
32
38
  }
33
-
34
- const blockProposal = await attestationPool.getBlockProposal(request.archiveRoot.toString());
39
+ // First try attestation pool, then fall back to archiver
40
+ let txHashes = (await attestationPool.getBlockProposal(request.archiveRoot.toString()))?.txHashes;
41
+ if (!txHashes) {
42
+ txHashes = (await archiver.getL2BlockByArchive(request.archiveRoot))?.body.txEffects.map(effect => effect.txHash);
43
+ }
35
44
 
36
45
  let requestedTxsHashes;
37
46
  if (request.txHashes.length > 0) {
38
47
  requestedTxsHashes = request.txHashes;
39
48
  }
40
49
 
41
- // This is scenario in which we don't have this block proposal the peer is requesting from us
50
+ // This is scenario in which we don't have this block the peer is requesting from us
42
51
  // But peer has sent requested tx hashes, so we can send them the transactions
43
- if (!blockProposal && requestedTxsHashes !== undefined) {
52
+ if (!txHashes && requestedTxsHashes !== undefined) {
44
53
  const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
45
54
  const response = new BlockTxsResponse(Fr.zero(), new TxArray(...responseTxs), BitVector.init(0, []));
46
55
  return response.toBuffer();
47
56
  }
48
57
 
49
- // If don't have this block proposal and peer has not sent requested tx hashes
50
- if (!blockProposal) {
58
+ // If we don't have this block and peer has not sent requested tx hashes
59
+ if (!txHashes) {
51
60
  throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
52
61
  }
53
62
 
54
- const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
55
- //Map txs in the pool to their indices in the block proposal
63
+ const txsAvailableInPool = await txPool.hasTxs(txHashes);
64
+ // Map txs in the pool to their indices in the block
56
65
  const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
57
- const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
66
+ const responseBitVector = BitVector.init(txHashes.length, availableIndices);
58
67
 
59
68
  const requestedIndices = new Set(request.txIndices.getTrueIndices());
60
- requestedTxsHashes = blockProposal.txHashes.filter((_, idx) => requestedIndices.has(idx));
69
+ requestedTxsHashes = txHashes.filter((_, idx) => requestedIndices.has(idx));
61
70
 
62
71
  const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
63
72
  const response = new BlockTxsResponse(request.archiveRoot, new TxArray(...responseTxs), responseBitVector);
@@ -1,10 +1,16 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
- import type { BlockProposal } from '@aztec/stdlib/p2p';
4
- import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
3
+ import { MAX_TX_SIZE_KB } from '@aztec/stdlib/p2p';
4
+ import { TxArray, type TxHash, TxHashArray } from '@aztec/stdlib/tx';
5
5
 
6
6
  import { BitVector } from './bitvector.js';
7
7
 
8
+ /** Minimal interface for a block source that provides tx hashes and an archive root. */
9
+ export interface BlockTxsSource {
10
+ txHashes: TxHash[];
11
+ archive: Fr;
12
+ }
13
+
8
14
  /**
9
15
  * Request message for requesting specific transactions from a block
10
16
  */
@@ -22,16 +28,17 @@ export class BlockTxsRequest {
22
28
  ) {}
23
29
 
24
30
  /**
25
- * Creates new BlockTxsRequest given proposal and missing tx hashes
31
+ * Creates new BlockTxsRequest given a block txs source and missing tx hashes.
26
32
  *
27
- * @param: blockProposal - The block proposal for which we are making request
28
- * @param: missingTxHashes - Tx hashes from the proposal we are missing
29
- * @param: includeFullTxHashes - Whether to include full list of missing tx hashes in the request or just Bitvector indices
33
+ * @param blockTxsSource - The block or proposal for which we are making the request
34
+ * @param missingTxHashes - Tx hashes from the source we are missing
35
+ * @param includeFullTxHashes - Whether to include full list of missing tx hashes in the request or just Bitvector indices
30
36
  *
31
- * @returns undefined if there were no missingTxHashes matching BlockProposal hashes, otherwise
32
- * returns new BlockTxsRequest*/
33
- static fromBlockProposalAndMissingTxs(
34
- blockProposal: BlockProposal,
37
+ * @returns undefined if there were no missingTxHashes matching the source hashes, otherwise
38
+ * returns new BlockTxsRequest
39
+ */
40
+ static fromTxsSourceAndMissingTxs(
41
+ blockTxsSource: BlockTxsSource,
35
42
  missingTxHashes: TxHash[],
36
43
  includeFullTxHashes = false,
37
44
  ): BlockTxsRequest | undefined {
@@ -41,19 +48,19 @@ export class BlockTxsRequest {
41
48
 
42
49
  const missingHashesSet = new Set(missingTxHashes.map(t => t.toString()));
43
50
 
44
- // We cannot request txs that are not part of the block proposal
45
- if (!missingHashesSet.isSubsetOf(new Set(blockProposal.txHashes.map(t => t.toString())))) {
51
+ // We cannot request txs that are not part of the block
52
+ if (!missingHashesSet.isSubsetOf(new Set(blockTxsSource.txHashes.map(t => t.toString())))) {
46
53
  return undefined;
47
54
  }
48
55
 
49
- const missingIndices = blockProposal.txHashes
56
+ const missingIndices = blockTxsSource.txHashes
50
57
  .map((hash, idx) => (missingHashesSet.has(hash.toString()) ? idx : -1))
51
58
  .filter(i => i != -1);
52
59
 
53
- const requestBitVector = BitVector.init(blockProposal.txHashes.length, missingIndices);
60
+ const requestBitVector = BitVector.init(blockTxsSource.txHashes.length, missingIndices);
54
61
  const hashes = includeFullTxHashes ? new TxHashArray(...missingTxHashes) : new TxHashArray();
55
62
 
56
- return new BlockTxsRequest(blockProposal.archive, hashes, requestBitVector);
63
+ return new BlockTxsRequest(blockTxsSource.archive, hashes, requestBitVector);
57
64
  }
58
65
 
59
66
  /**
@@ -119,3 +126,19 @@ export class BlockTxsResponse {
119
126
  return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
120
127
  }
121
128
  }
129
+
130
+ /**
131
+ * Calculate the expected response size for a BLOCK_TXS request.
132
+ * @param requestBuffer - The serialized request buffer containing BlockTxsRequest
133
+ * @returns Expected response size in KB
134
+ */
135
+ export function calculateBlockTxsResponseSize(requestBuffer: Buffer): number {
136
+ try {
137
+ const request = BlockTxsRequest.fromBuffer(requestBuffer);
138
+ const requestedTxCount = request.txIndices.getTrueIndices().length;
139
+ return requestedTxCount * MAX_TX_SIZE_KB + 1; // +1 KB overhead for serialization
140
+ } catch {
141
+ // If we can't parse the request, fall back to allowing a single transaction response
142
+ return MAX_TX_SIZE_KB + 1;
143
+ }
144
+ }
@@ -1,4 +1,5 @@
1
1
  import { chunk } from '@aztec/foundation/collection';
2
+ import { MAX_TX_SIZE_KB } from '@aztec/stdlib/p2p';
2
3
  import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
3
4
 
4
5
  import type { PeerId } from '@libp2p/interface';
@@ -55,3 +56,24 @@ export function reqRespTxHandler(mempools: MemPools): ReqRespSubProtocolHandler
55
56
  export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
56
57
  return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
57
58
  }
59
+
60
+ /**
61
+ * Calculate the expected response size for a TX request.
62
+ * @param requestBuffer - The serialized request buffer containing TxHashArray
63
+ * @returns Expected response size in KB
64
+ */
65
+ export function calculateTxResponseSize(requestBuffer: Buffer): number {
66
+ try {
67
+ const txHashes = TxHashArray.fromBuffer(requestBuffer);
68
+ // TxHashArray.fromBuffer returns empty array on parse failure, so check for that
69
+ if (txHashes.length === 0 && requestBuffer.length > 0) {
70
+ // If we got an empty array but had a non-empty buffer, parsing likely failed
71
+ // Fall back to allowing a single transaction response
72
+ return MAX_TX_SIZE_KB + 1;
73
+ }
74
+ return Math.max(txHashes.length, 1) * MAX_TX_SIZE_KB + 1; // +1 KB overhead, at least 1 tx
75
+ } catch {
76
+ // If we can't parse the request, fall back to allowing a single transaction response
77
+ return MAX_TX_SIZE_KB + 1;
78
+ }
79
+ }