@aztec/p2p 0.0.1-commit.54489865 → 0.0.1-commit.5914bae

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 (410) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +10 -10
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +54 -15
  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 +166 -224
  10. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +7 -8
  11. package/dest/config.d.ts +55 -12
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +99 -33
  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 +441 -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/interface.d.ts +5 -5
  36. package/dest/mem_pools/interface.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  38. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
  40. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  41. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  42. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/priority.js +4 -4
  44. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  45. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  47. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  48. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  49. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  50. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  51. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  53. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  54. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  55. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  56. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +97 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  86. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  87. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  88. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  89. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  90. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  92. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +213 -0
  93. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  94. package/dest/mem_pools/tx_pool_v2/interfaces.js +9 -0
  95. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +135 -0
  96. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  97. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +216 -0
  98. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  99. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  100. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  101. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +354 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +62 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +164 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +77 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +906 -0
  110. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  111. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
  113. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  114. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
  115. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
  116. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  117. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
  118. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
  119. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  120. package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
  121. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  122. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  123. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  124. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  125. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  126. package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
  127. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  128. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  129. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  130. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  131. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  132. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  133. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  134. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  135. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  136. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  137. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  138. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  139. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  140. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  141. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  142. package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
  143. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  144. package/dest/msg_validators/tx_validator/factory.js +247 -60
  145. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  146. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  147. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  148. package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
  149. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  150. package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
  151. package/dest/msg_validators/tx_validator/index.d.ts +3 -1
  152. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  153. package/dest/msg_validators/tx_validator/index.js +2 -0
  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 +72 -24
  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/data_store.d.ts +1 -1
  164. package/dest/services/data_store.d.ts.map +1 -1
  165. package/dest/services/data_store.js +10 -6
  166. package/dest/services/dummy_service.d.ts +13 -5
  167. package/dest/services/dummy_service.d.ts.map +1 -1
  168. package/dest/services/dummy_service.js +10 -4
  169. package/dest/services/encoding.d.ts +7 -3
  170. package/dest/services/encoding.d.ts.map +1 -1
  171. package/dest/services/encoding.js +18 -11
  172. package/dest/services/gossipsub/index.d.ts +3 -0
  173. package/dest/services/gossipsub/index.d.ts.map +1 -0
  174. package/dest/services/gossipsub/index.js +2 -0
  175. package/dest/services/gossipsub/scoring.d.ts +21 -3
  176. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  177. package/dest/services/gossipsub/scoring.js +24 -7
  178. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  179. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  180. package/dest/services/gossipsub/topic_score_params.js +346 -0
  181. package/dest/services/index.d.ts +2 -1
  182. package/dest/services/index.d.ts.map +1 -1
  183. package/dest/services/index.js +1 -0
  184. package/dest/services/libp2p/libp2p_service.d.ts +94 -42
  185. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  186. package/dest/services/libp2p/libp2p_service.js +453 -354
  187. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  188. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  189. package/dest/services/peer-manager/peer_scoring.js +25 -2
  190. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +6 -5
  191. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  192. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +13 -17
  193. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  194. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  195. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  196. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  197. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  198. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  199. package/dest/services/reqresp/interface.d.ts +10 -1
  200. package/dest/services/reqresp/interface.d.ts.map +1 -1
  201. package/dest/services/reqresp/interface.js +15 -1
  202. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  203. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  204. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +17 -12
  205. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +25 -14
  206. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  207. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +40 -24
  208. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  209. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  210. package/dest/services/reqresp/protocols/tx.js +20 -0
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  212. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  213. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  214. package/dest/services/reqresp/reqresp.d.ts +1 -1
  215. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  216. package/dest/services/reqresp/reqresp.js +28 -13
  217. package/dest/services/service.d.ts +39 -3
  218. package/dest/services/service.d.ts.map +1 -1
  219. package/dest/services/tx_collection/config.d.ts +22 -4
  220. package/dest/services/tx_collection/config.d.ts.map +1 -1
  221. package/dest/services/tx_collection/config.js +49 -3
  222. package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -5
  223. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  224. package/dest/services/tx_collection/fast_tx_collection.js +64 -48
  225. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  226. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  227. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  228. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  229. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  230. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  231. package/dest/services/tx_collection/index.d.ts +3 -2
  232. package/dest/services/tx_collection/index.d.ts.map +1 -1
  233. package/dest/services/tx_collection/index.js +1 -0
  234. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  235. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  236. package/dest/services/tx_collection/instrumentation.js +2 -1
  237. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  238. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  239. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  240. package/dest/services/tx_collection/proposal_tx_collector.d.ts +15 -14
  241. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  242. package/dest/services/tx_collection/proposal_tx_collector.js +6 -6
  243. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  244. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  245. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  246. package/dest/services/tx_collection/tx_collection.d.ts +23 -10
  247. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  248. package/dest/services/tx_collection/tx_collection.js +75 -3
  249. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  250. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  251. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  252. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  253. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  254. package/dest/services/tx_collection/tx_source.js +26 -7
  255. package/dest/services/tx_file_store/config.d.ts +16 -0
  256. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  257. package/dest/services/tx_file_store/config.js +22 -0
  258. package/dest/services/tx_file_store/index.d.ts +4 -0
  259. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  260. package/dest/services/tx_file_store/index.js +3 -0
  261. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  262. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  263. package/dest/services/tx_file_store/instrumentation.js +29 -0
  264. package/dest/services/tx_file_store/tx_file_store.d.ts +48 -0
  265. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  266. package/dest/services/tx_file_store/tx_file_store.js +152 -0
  267. package/dest/services/tx_provider.d.ts +4 -4
  268. package/dest/services/tx_provider.d.ts.map +1 -1
  269. package/dest/services/tx_provider.js +9 -8
  270. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  271. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  272. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  273. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  274. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  275. package/dest/test-helpers/mock-pubsub.js +105 -4
  276. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  277. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  278. package/dest/test-helpers/reqresp-nodes.js +4 -3
  279. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  280. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  281. package/dest/test-helpers/testbench-utils.js +129 -59
  282. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  283. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  284. package/dest/testbench/p2p_client_testbench_worker.js +17 -16
  285. package/dest/testbench/worker_client_manager.d.ts +3 -1
  286. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  287. package/dest/testbench/worker_client_manager.js +4 -1
  288. package/dest/util.d.ts +2 -2
  289. package/dest/util.d.ts.map +1 -1
  290. package/package.json +14 -14
  291. package/src/client/factory.ts +106 -27
  292. package/src/client/interface.ts +56 -34
  293. package/src/client/p2p_client.ts +200 -269
  294. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
  295. package/src/config.ts +155 -34
  296. package/src/errors/tx-pool.error.ts +12 -0
  297. package/src/index.ts +1 -0
  298. package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
  299. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  300. package/src/mem_pools/attestation_pool/index.ts +9 -2
  301. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  302. package/src/mem_pools/index.ts +4 -1
  303. package/src/mem_pools/interface.ts +4 -4
  304. package/src/mem_pools/tx_pool/README.md +1 -1
  305. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  306. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  307. package/src/mem_pools/tx_pool/priority.ts +4 -4
  308. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  309. package/src/mem_pools/tx_pool_v2/README.md +283 -0
  310. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  311. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  312. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  313. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
  314. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +122 -0
  315. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +125 -0
  316. package/src/mem_pools/tx_pool_v2/eviction/index.ts +27 -0
  317. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
  318. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  319. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  320. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
  321. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
  322. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
  323. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  324. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  325. package/src/mem_pools/tx_pool_v2/interfaces.ts +244 -0
  326. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +337 -0
  327. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  328. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +444 -0
  329. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +235 -0
  330. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1087 -0
  331. package/src/msg_validators/attestation_validator/README.md +49 -0
  332. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  333. package/src/msg_validators/proposal_validator/README.md +123 -0
  334. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
  335. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
  336. package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
  337. package/src/msg_validators/tx_validator/README.md +119 -0
  338. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  339. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  340. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  341. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  342. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  343. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  344. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  345. package/src/msg_validators/tx_validator/factory.ts +394 -78
  346. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  347. package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
  348. package/src/msg_validators/tx_validator/index.ts +2 -0
  349. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  350. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  351. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  352. package/src/services/data_store.ts +10 -7
  353. package/src/services/dummy_service.ts +18 -6
  354. package/src/services/encoding.ts +18 -10
  355. package/src/services/gossipsub/README.md +641 -0
  356. package/src/services/gossipsub/index.ts +2 -0
  357. package/src/services/gossipsub/scoring.ts +29 -5
  358. package/src/services/gossipsub/topic_score_params.ts +487 -0
  359. package/src/services/index.ts +1 -0
  360. package/src/services/libp2p/libp2p_service.ts +481 -376
  361. package/src/services/peer-manager/peer_scoring.ts +25 -0
  362. package/src/services/reqresp/README.md +229 -0
  363. package/src/services/reqresp/batch-tx-requester/README.md +14 -14
  364. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +18 -18
  365. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  366. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  367. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  368. package/src/services/reqresp/interface.ts +26 -1
  369. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +24 -15
  370. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -24
  371. package/src/services/reqresp/protocols/tx.ts +22 -0
  372. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  373. package/src/services/reqresp/reqresp.ts +32 -14
  374. package/src/services/service.ts +51 -2
  375. package/src/services/tx_collection/config.ts +74 -6
  376. package/src/services/tx_collection/fast_tx_collection.ts +74 -51
  377. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  378. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  379. package/src/services/tx_collection/index.ts +2 -1
  380. package/src/services/tx_collection/instrumentation.ts +7 -1
  381. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  382. package/src/services/tx_collection/proposal_tx_collector.ts +20 -21
  383. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  384. package/src/services/tx_collection/tx_collection.ts +113 -16
  385. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  386. package/src/services/tx_collection/tx_source.ts +28 -8
  387. package/src/services/tx_file_store/config.ts +37 -0
  388. package/src/services/tx_file_store/index.ts +3 -0
  389. package/src/services/tx_file_store/instrumentation.ts +36 -0
  390. package/src/services/tx_file_store/tx_file_store.ts +175 -0
  391. package/src/services/tx_provider.ts +10 -9
  392. package/src/test-helpers/make-test-p2p-clients.ts +3 -5
  393. package/src/test-helpers/mock-pubsub.ts +146 -9
  394. package/src/test-helpers/reqresp-nodes.ts +4 -6
  395. package/src/test-helpers/testbench-utils.ts +128 -71
  396. package/src/testbench/p2p_client_testbench_worker.ts +25 -21
  397. package/src/testbench/worker_client_manager.ts +11 -4
  398. package/src/util.ts +7 -1
  399. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  400. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  401. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  402. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  403. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  404. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  405. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  406. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  407. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  408. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  409. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
  410. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
@@ -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,7 +152,7 @@ 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
  }
@@ -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,37 +36,40 @@ 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.blockHash.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
- const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
72
+ const response = new BlockTxsResponse(request.archiveRoot, new TxArray(...responseTxs), responseBitVector);
64
73
 
65
74
  return response.toBuffer();
66
75
  };
@@ -1,17 +1,23 @@
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
  */
11
17
  export class BlockTxsRequest {
12
18
  constructor(
13
- // 32 byte hash of the proposed block header
14
- readonly blockHash: Fr,
19
+ // Archive root after the proposed block is applied (proposal identifier)
20
+ readonly archiveRoot: Fr,
15
21
  // Hashes of txs we are requesting
16
22
  readonly txHashes: TxHashArray,
17
23
  // BitVector indicating which txs from the proposal we are requesting
@@ -22,16 +28,17 @@ export class BlockTxsRequest {
22
28
  ) {}
23
29
 
24
30
  /**
25
- * Crates 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
  /**
@@ -63,11 +70,11 @@ export class BlockTxsRequest {
63
70
  */
64
71
  static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
65
72
  const reader = BufferReader.asReader(buffer);
66
- const blockHash = Fr.fromBuffer(reader);
73
+ const archiveRoot = Fr.fromBuffer(reader);
67
74
  const txHashes = TxHashArray.fromBuffer(reader);
68
75
  const txIndices = BitVector.fromBuffer(reader);
69
76
 
70
- return new BlockTxsRequest(blockHash, txHashes, txIndices);
77
+ return new BlockTxsRequest(archiveRoot, txHashes, txIndices);
71
78
  }
72
79
 
73
80
  /**
@@ -75,7 +82,7 @@ export class BlockTxsRequest {
75
82
  * @returns Buffer representation of the BlockTxRequest object
76
83
  */
77
84
  toBuffer(): Buffer {
78
- return serializeToBuffer([this.blockHash, this.txHashes.toBuffer(), this.txIndices.toBuffer()]);
85
+ return serializeToBuffer([this.archiveRoot, this.txHashes.toBuffer(), this.txIndices.toBuffer()]);
79
86
  }
80
87
  }
81
88
 
@@ -84,7 +91,7 @@ export class BlockTxsRequest {
84
91
  */
85
92
  export class BlockTxsResponse {
86
93
  constructor(
87
- readonly blockHash: Fr,
94
+ readonly archiveRoot: Fr,
88
95
  readonly txs: TxArray, // List of transactions we requested and peer has
89
96
  // BitVector indicating which txs from the proposal are available at the peer
90
97
  // 1 means the tx is available, 0 means it is not
@@ -98,11 +105,11 @@ export class BlockTxsResponse {
98
105
  */
99
106
  static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
100
107
  const reader = BufferReader.asReader(buffer);
101
- const blockHash = Fr.fromBuffer(reader);
108
+ const archiveRoot = Fr.fromBuffer(reader);
102
109
  const txs = TxArray.fromBuffer(reader);
103
110
  const txIndices = BitVector.fromBuffer(reader);
104
111
 
105
- return new BlockTxsResponse(blockHash, txs, txIndices);
112
+ return new BlockTxsResponse(archiveRoot, txs, txIndices);
106
113
  }
107
114
 
108
115
  /**
@@ -112,10 +119,26 @@ export class BlockTxsResponse {
112
119
  * @returns Buffer representation of the BlockTxResponse object
113
120
  */
114
121
  toBuffer(): Buffer {
115
- return serializeToBuffer([this.blockHash, this.txs.toBuffer(), this.txIndices.toBuffer()]);
122
+ return serializeToBuffer([this.archiveRoot, this.txs.toBuffer(), this.txIndices.toBuffer()]);
116
123
  }
117
124
 
118
125
  static empty(): 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
+ }
@@ -97,9 +97,10 @@ export function prettyPrintRateLimitStatus(status: RateLimitStatus) {
97
97
  * 2. Individual rate limits for each peer.
98
98
  *
99
99
  * How it works:
100
- * - When a request comes in, it first checks against the global rate limit.
101
- * - If the global limit allows, it then checks against the specific peer's rate limit.
102
- * - The request is only allowed if both the global and peer-specific limits allow it.
100
+ * - When a request comes in, it first checks against the peer's individual rate limit.
101
+ * - If the peer limit allows, it then checks against the global rate limit.
102
+ * - The request is only allowed if both the peer-specific and global limits allow it.
103
+ * - Checking peer limit first ensures a rate-limited peer cannot exhaust the global quota.
103
104
  * - It automatically creates and manages rate limiters for new peers as they make requests.
104
105
  * - It periodically cleans up rate limiters for inactive peers to conserve memory.
105
106
  *
@@ -119,10 +120,6 @@ export class SubProtocolRateLimiter {
119
120
  }
120
121
 
121
122
  allow(peerId: PeerId): RateLimitStatus {
122
- if (!this.globalLimiter.allow()) {
123
- return RateLimitStatus.DeniedGlobal;
124
- }
125
-
126
123
  const peerIdStr = peerId.toString();
127
124
  let peerLimiter: PeerRateLimiter | undefined = this.peerLimiters.get(peerIdStr);
128
125
  if (!peerLimiter) {
@@ -135,10 +132,17 @@ export class SubProtocolRateLimiter {
135
132
  } else {
136
133
  peerLimiter.lastAccess = Date.now();
137
134
  }
138
- const peerLimitAllowed = peerLimiter.limiter.allow();
139
- if (!peerLimitAllowed) {
135
+
136
+ // Check peer limit first: a rate-limited peer must not consume global quota,
137
+ // otherwise one spamming peer can starve all others by exhausting the global bucket.
138
+ if (!peerLimiter.limiter.allow()) {
140
139
  return RateLimitStatus.DeniedPeer;
141
140
  }
141
+
142
+ if (!this.globalLimiter.allow()) {
143
+ return RateLimitStatus.DeniedGlobal;
144
+ }
145
+
142
146
  return RateLimitStatus.Allowed;
143
147
  }
144
148