@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.24de95ac

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 (339) hide show
  1. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  2. package/dest/bootstrap/bootstrap.js +22 -9
  3. package/dest/client/factory.d.ts +13 -3
  4. package/dest/client/factory.d.ts.map +1 -1
  5. package/dest/client/factory.js +60 -24
  6. package/dest/client/index.d.ts +1 -0
  7. package/dest/client/index.d.ts.map +1 -1
  8. package/dest/client/index.js +1 -0
  9. package/dest/client/interface.d.ts +155 -0
  10. package/dest/client/interface.d.ts.map +1 -0
  11. package/dest/client/interface.js +9 -0
  12. package/dest/client/p2p_client.d.ts +72 -169
  13. package/dest/client/p2p_client.d.ts.map +1 -1
  14. package/dest/client/p2p_client.js +365 -174
  15. package/dest/config.d.ts +123 -103
  16. package/dest/config.d.ts.map +1 -1
  17. package/dest/config.js +173 -34
  18. package/dest/enr/generate-enr.d.ts +10 -2
  19. package/dest/enr/generate-enr.d.ts.map +1 -1
  20. package/dest/enr/generate-enr.js +27 -5
  21. package/dest/index.d.ts +3 -0
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +2 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +204 -54
  28. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
  29. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
  31. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
  32. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
  35. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/mocks.js +9 -15
  37. package/dest/mem_pools/instrumentation.d.ts +7 -11
  38. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.js +25 -37
  40. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
  43. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
  44. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
  46. package/dest/mem_pools/tx_pool/priority.js +1 -1
  47. package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
  48. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
  51. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
  52. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  53. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  54. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -1
  55. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  56. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +61 -12
  57. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  58. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  59. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  60. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  61. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  62. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  63. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  64. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  65. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  66. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  68. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  70. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
  71. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  73. package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
  74. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  75. package/dest/msg_validators/tx_validator/factory.js +74 -0
  76. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  77. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  78. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  79. package/dest/msg_validators/tx_validator/index.d.ts +7 -0
  80. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/index.js +7 -0
  82. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +7 -3
  83. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  85. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  86. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/phases_validator.js +91 -0
  88. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  89. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  90. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  91. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
  92. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  93. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  94. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  95. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  96. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  97. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  99. package/dest/services/discv5/discV5_service.d.ts +9 -8
  100. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  101. package/dest/services/discv5/discV5_service.js +63 -36
  102. package/dest/services/dummy_service.d.ts +49 -10
  103. package/dest/services/dummy_service.d.ts.map +1 -1
  104. package/dest/services/dummy_service.js +88 -5
  105. package/dest/services/encoding.d.ts +25 -6
  106. package/dest/services/encoding.d.ts.map +1 -1
  107. package/dest/services/encoding.js +73 -5
  108. package/dest/services/index.d.ts +4 -0
  109. package/dest/services/index.d.ts.map +1 -1
  110. package/dest/services/index.js +4 -0
  111. package/dest/services/libp2p/instrumentation.d.ts +18 -0
  112. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  113. package/dest/services/libp2p/instrumentation.js +157 -0
  114. package/dest/services/libp2p/libp2p_service.d.ts +87 -42
  115. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  116. package/dest/services/libp2p/libp2p_service.js +500 -218
  117. package/dest/services/peer-manager/interface.d.ts +23 -0
  118. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  119. package/dest/services/peer-manager/interface.js +1 -0
  120. package/dest/services/peer-manager/metrics.d.ts +3 -1
  121. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  122. package/dest/services/peer-manager/metrics.js +11 -2
  123. package/dest/services/peer-manager/peer_manager.d.ts +126 -15
  124. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  125. package/dest/services/peer-manager/peer_manager.js +547 -72
  126. package/dest/services/reqresp/config.d.ts +10 -8
  127. package/dest/services/reqresp/config.d.ts.map +1 -1
  128. package/dest/services/reqresp/config.js +18 -4
  129. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  130. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  131. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  132. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +30 -13
  133. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  134. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  135. package/dest/services/reqresp/index.d.ts +2 -1
  136. package/dest/services/reqresp/index.d.ts.map +1 -1
  137. package/dest/services/reqresp/index.js +2 -1
  138. package/dest/services/reqresp/interface.d.ts +72 -23
  139. package/dest/services/reqresp/interface.d.ts.map +1 -1
  140. package/dest/services/reqresp/interface.js +45 -26
  141. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  142. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  143. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  144. package/dest/services/reqresp/protocols/auth.js +71 -0
  145. package/dest/services/reqresp/protocols/block.d.ts +5 -0
  146. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  147. package/dest/services/reqresp/protocols/block.js +28 -5
  148. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  149. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  150. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  151. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  152. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  153. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  154. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
  155. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  156. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  157. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  158. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  159. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  160. package/dest/services/reqresp/protocols/goodbye.d.ts +2 -4
  161. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  162. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  163. package/dest/services/reqresp/protocols/index.d.ts +2 -0
  164. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  165. package/dest/services/reqresp/protocols/index.js +2 -0
  166. package/dest/services/reqresp/protocols/ping.d.ts +0 -2
  167. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  168. package/dest/services/reqresp/protocols/status.d.ts +38 -6
  169. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  170. package/dest/services/reqresp/protocols/status.js +72 -5
  171. package/dest/services/reqresp/protocols/tx.d.ts +12 -1
  172. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  173. package/dest/services/reqresp/protocols/tx.js +34 -6
  174. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +4 -2
  175. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  176. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  177. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  178. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  179. package/dest/services/reqresp/reqresp.d.ts +45 -47
  180. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  181. package/dest/services/reqresp/reqresp.js +298 -207
  182. package/dest/services/reqresp/status.d.ts +9 -3
  183. package/dest/services/reqresp/status.d.ts.map +1 -1
  184. package/dest/services/reqresp/status.js +9 -2
  185. package/dest/services/service.d.ts +22 -18
  186. package/dest/services/service.d.ts.map +1 -1
  187. package/dest/services/tx_collection/config.d.ts +25 -0
  188. package/dest/services/tx_collection/config.d.ts.map +1 -0
  189. package/dest/services/tx_collection/config.js +58 -0
  190. package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
  191. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  192. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  193. package/dest/services/tx_collection/index.d.ts +3 -0
  194. package/dest/services/tx_collection/index.d.ts.map +1 -0
  195. package/dest/services/tx_collection/index.js +2 -0
  196. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  197. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  198. package/dest/services/tx_collection/instrumentation.js +34 -0
  199. package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
  200. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  201. package/dest/services/tx_collection/slow_tx_collection.js +176 -0
  202. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  203. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  204. package/dest/services/tx_collection/tx_collection.js +128 -0
  205. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  206. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  207. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  208. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  209. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  210. package/dest/services/tx_collection/tx_source.js +31 -0
  211. package/dest/services/tx_provider.d.ts +49 -0
  212. package/dest/services/tx_provider.d.ts.map +1 -0
  213. package/dest/services/tx_provider.js +210 -0
  214. package/dest/services/tx_provider_instrumentation.d.ts +13 -0
  215. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  216. package/dest/services/tx_provider_instrumentation.js +34 -0
  217. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  218. package/dest/test-helpers/index.d.ts +1 -0
  219. package/dest/test-helpers/index.d.ts.map +1 -1
  220. package/dest/test-helpers/index.js +1 -0
  221. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  222. package/dest/test-helpers/make-enrs.js +4 -5
  223. package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
  224. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  225. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  226. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  227. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  228. package/dest/test-helpers/mock-pubsub.js +130 -0
  229. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  230. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  231. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  232. package/dest/test-helpers/reqresp-nodes.d.ts +14 -10
  233. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  234. package/dest/test-helpers/reqresp-nodes.js +62 -28
  235. package/dest/testbench/p2p_client_testbench_worker.js +96 -25
  236. package/dest/testbench/parse_log_file.js +4 -4
  237. package/dest/testbench/testbench.js +4 -4
  238. package/dest/testbench/worker_client_manager.d.ts +0 -5
  239. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  240. package/dest/testbench/worker_client_manager.js +11 -19
  241. package/dest/types/index.d.ts +3 -1
  242. package/dest/types/index.d.ts.map +1 -1
  243. package/dest/types/index.js +2 -0
  244. package/dest/util.d.ts +22 -15
  245. package/dest/util.d.ts.map +1 -1
  246. package/dest/util.js +64 -67
  247. package/dest/versioning.d.ts +3 -3
  248. package/dest/versioning.d.ts.map +1 -1
  249. package/dest/versioning.js +8 -3
  250. package/package.json +28 -24
  251. package/src/bootstrap/bootstrap.ts +27 -11
  252. package/src/client/factory.ts +136 -45
  253. package/src/client/index.ts +1 -0
  254. package/src/client/interface.ts +195 -0
  255. package/src/client/p2p_client.ts +460 -327
  256. package/src/config.ts +288 -134
  257. package/src/enr/generate-enr.ts +39 -6
  258. package/src/index.ts +4 -0
  259. package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
  260. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
  261. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
  262. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
  263. package/src/mem_pools/attestation_pool/mocks.ts +11 -10
  264. package/src/mem_pools/instrumentation.ts +32 -46
  265. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
  266. package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
  267. package/src/mem_pools/tx_pool/priority.ts +1 -1
  268. package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
  269. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
  270. package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
  271. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -14
  272. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  273. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  274. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  275. package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
  276. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  277. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  278. package/src/msg_validators/tx_validator/factory.ts +109 -0
  279. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  280. package/src/msg_validators/tx_validator/index.ts +7 -0
  281. package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
  282. package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
  283. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  284. package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
  285. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  286. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  287. package/src/services/discv5/discV5_service.ts +84 -38
  288. package/src/services/dummy_service.ts +147 -9
  289. package/src/services/encoding.ts +80 -5
  290. package/src/services/index.ts +4 -0
  291. package/src/services/libp2p/instrumentation.ts +158 -0
  292. package/src/services/libp2p/libp2p_service.ts +646 -263
  293. package/src/services/peer-manager/interface.ts +29 -0
  294. package/src/services/peer-manager/metrics.ts +16 -1
  295. package/src/services/peer-manager/peer_manager.ts +652 -78
  296. package/src/services/reqresp/config.ts +26 -9
  297. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  298. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  299. package/src/services/reqresp/index.ts +2 -0
  300. package/src/services/reqresp/interface.ts +91 -36
  301. package/src/services/reqresp/metrics.ts +4 -1
  302. package/src/services/reqresp/protocols/auth.ts +83 -0
  303. package/src/services/reqresp/protocols/block.ts +24 -3
  304. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  305. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  306. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  307. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  308. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  309. package/src/services/reqresp/protocols/index.ts +2 -0
  310. package/src/services/reqresp/protocols/status.ts +117 -5
  311. package/src/services/reqresp/protocols/tx.ts +35 -6
  312. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  313. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  314. package/src/services/reqresp/reqresp.ts +387 -256
  315. package/src/services/reqresp/status.ts +12 -3
  316. package/src/services/service.ts +45 -21
  317. package/src/services/tx_collection/config.ts +84 -0
  318. package/src/services/tx_collection/fast_tx_collection.ts +340 -0
  319. package/src/services/tx_collection/index.ts +2 -0
  320. package/src/services/tx_collection/instrumentation.ts +43 -0
  321. package/src/services/tx_collection/slow_tx_collection.ts +232 -0
  322. package/src/services/tx_collection/tx_collection.ts +215 -0
  323. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  324. package/src/services/tx_collection/tx_source.ts +37 -0
  325. package/src/services/tx_provider.ts +216 -0
  326. package/src/services/tx_provider_instrumentation.ts +44 -0
  327. package/src/test-helpers/index.ts +1 -0
  328. package/src/test-helpers/make-enrs.ts +4 -5
  329. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  330. package/src/test-helpers/mock-pubsub.ts +188 -0
  331. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  332. package/src/test-helpers/reqresp-nodes.ts +86 -35
  333. package/src/testbench/p2p_client_testbench_worker.ts +145 -22
  334. package/src/testbench/parse_log_file.ts +4 -4
  335. package/src/testbench/testbench.ts +4 -4
  336. package/src/testbench/worker_client_manager.ts +17 -23
  337. package/src/types/index.ts +2 -0
  338. package/src/util.ts +93 -89
  339. package/src/versioning.ts +11 -4
@@ -0,0 +1,83 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { keccak256 } from '@aztec/foundation/crypto';
3
+ import { Signature } from '@aztec/foundation/eth-signature';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
6
+
7
+ import { StatusMessage } from './status.js';
8
+
9
+ export const VALIDATOR_AUTH_DOMAIN_SEPARATOR = 'Aztec Validator Challenge:';
10
+ export const VALIDATOR_AUTH_FULL_CHALLENGE_ENCODED_LENGTH =
11
+ VALIDATOR_AUTH_DOMAIN_SEPARATOR.length + Fr.random().toString().length;
12
+
13
+ /*
14
+ * P2P Auth Message
15
+ * Superset of the StatusMessage, used to establish a handshake between peers and authenticate them.
16
+ */
17
+ export class AuthRequest {
18
+ constructor(
19
+ readonly status: StatusMessage,
20
+ readonly challenge: Fr,
21
+ ) {}
22
+
23
+ /**
24
+ * Deserializes the AuthRequest object from a Buffer.
25
+ * @param buffer - Buffer or BufferReader object to deserialize.
26
+ * @returns An instance of StatusMessage.
27
+ */
28
+ static fromBuffer(buffer: Buffer | BufferReader): AuthRequest {
29
+ const reader = BufferReader.asReader(buffer);
30
+ return new AuthRequest(
31
+ StatusMessage.fromBuffer(reader), // Deserialize StatusMessage
32
+ Fr.fromBuffer(reader), // challenge
33
+ );
34
+ }
35
+
36
+ /**
37
+ * Serializes the AuthRequest object into a Buffer.
38
+ * @returns Buffer representation of the StatusMessage object.
39
+ */
40
+ toBuffer() {
41
+ return serializeToBuffer([this.status, this.challenge]);
42
+ }
43
+
44
+ getPayloadToSign(): Buffer32 {
45
+ const fullChallenge = VALIDATOR_AUTH_DOMAIN_SEPARATOR + this.challenge.toString();
46
+ return Buffer32.fromBuffer(keccak256(Buffer.from(fullChallenge, 'utf-8')));
47
+ }
48
+
49
+ static random(): AuthRequest {
50
+ return new AuthRequest(StatusMessage.random(), Fr.random());
51
+ }
52
+ }
53
+
54
+ export class AuthResponse {
55
+ constructor(
56
+ readonly status: StatusMessage,
57
+ readonly signature: Signature,
58
+ ) {}
59
+ /**
60
+ * Deserializes the AuthResponse object from a Buffer.
61
+ * @param buffer - Buffer or BufferReader object to deserialize.
62
+ * @returns An instance of StatusMessage.
63
+ */
64
+ static fromBuffer(buffer: Buffer | BufferReader): AuthResponse {
65
+ const reader = BufferReader.asReader(buffer);
66
+ return new AuthResponse(
67
+ StatusMessage.fromBuffer(reader), // Deserialize StatusMessage
68
+ Signature.fromBuffer(reader), // response
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Serializes the AuthRequest object into a Buffer.
74
+ * @returns Buffer representation of the StatusMessage object.
75
+ */
76
+ toBuffer() {
77
+ return serializeToBuffer([this.status, this.signature]);
78
+ }
79
+
80
+ static random(): AuthResponse {
81
+ return new AuthResponse(StatusMessage.random(), Signature.random());
82
+ }
83
+ }
@@ -4,12 +4,33 @@ import type { L2BlockSource } from '@aztec/stdlib/block';
4
4
  import type { PeerId } from '@libp2p/interface';
5
5
 
6
6
  import type { ReqRespSubProtocolHandler } from '../interface.js';
7
+ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
7
8
 
9
+ /**
10
+ * Handler for L2 Block requests
11
+ * @param l2BlockSource - source for L2 blocks
12
+ * @returns the Block request handler
13
+ * */
8
14
  export function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubProtocolHandler {
15
+ /**
16
+ * @param peerId - the peer ID of the requester
17
+ * @param msg - the block request message, which is expected to contain valid block number as a Buffer
18
+ * @returns a Buffer containing the requested block data, or an empty Buffer if the block is not found
19
+ * @throws ReqRespStatusError if the input msg is not a valid block number
20
+ * */
9
21
  return async (_peerId: PeerId, msg: Buffer) => {
10
- const blockNumber = Fr.fromBuffer(msg);
22
+ let blockNumber: Fr;
23
+ try {
24
+ blockNumber = Fr.fromBuffer(msg);
25
+ } catch (err: any) {
26
+ throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
27
+ }
11
28
 
12
- const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
13
- return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
29
+ try {
30
+ const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
31
+ return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
32
+ } catch (err: any) {
33
+ throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
34
+ }
14
35
  };
15
36
  }
@@ -0,0 +1,90 @@
1
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
2
+
3
+ /**
4
+ * BitVector helper class for representing and serializing bit vectors
5
+ */
6
+ export class BitVector {
7
+ private buffer: Buffer;
8
+ private length: number;
9
+
10
+ constructor(buffer: Buffer, length: number) {
11
+ this.buffer = buffer;
12
+ this.length = length;
13
+ }
14
+
15
+ /*
16
+ * Creates new BitVector instance
17
+ * @param length - Length of the bit vector
18
+ * @param indices - Array of indices to set to 1 in the bit vector
19
+ *
20
+ * @returns A new BitVector instance with specified length and set indices
21
+ * */
22
+ static init(length: number, indices: number[]): BitVector {
23
+ if (indices.length > length) {
24
+ throw new Error('Indices length exceeds specified length');
25
+ }
26
+
27
+ const buffer = Buffer.alloc(BitVector.byteLength(length));
28
+
29
+ indices.forEach(idx => {
30
+ const invalidIndex = idx < 0 || idx >= length;
31
+ if (invalidIndex) {
32
+ throw new Error(`Index ${idx} is out of bounds for BitVector of length ${length}`);
33
+ }
34
+
35
+ const byteIndex = Math.floor(idx / 8);
36
+ const bitIndex = idx % 8;
37
+ buffer[byteIndex] |= 1 << bitIndex;
38
+ });
39
+
40
+ return new BitVector(buffer, length);
41
+ }
42
+
43
+ getLength(): number {
44
+ return this.length;
45
+ }
46
+
47
+ /*
48
+ * Checks if element at index is set to true
49
+ *
50
+ * @param index - Index of the bit to check
51
+ *
52
+ * @returns True if the bit at index is set, false otherwise
53
+ * */
54
+ isSet(index: number): boolean {
55
+ return index >= 0 && index < this.length && !!(this.buffer[Math.floor(index / 8)] & (1 << index % 8));
56
+ }
57
+
58
+ /**
59
+ * Returns all indices which are set to true
60
+ * */
61
+ getTrueIndices(): number[] {
62
+ return Array.from({ length: this.length }, (_, i) => i).filter(i => this.isSet(i));
63
+ }
64
+
65
+ /**
66
+ * Serializes the BitVector object into a Buffer
67
+ *
68
+ * @returns Buffer representation of the BitVector object
69
+ * */
70
+ toBuffer(): Buffer {
71
+ return serializeToBuffer([this.length, this.buffer]);
72
+ }
73
+
74
+ /**
75
+ * Deserializes buffer into new BitVector
76
+ *
77
+ * @returns A new BitVector instance
78
+ * */
79
+ static fromBuffer(buffer: Buffer | BufferReader): BitVector {
80
+ const reader = BufferReader.asReader(buffer);
81
+ const length = reader.readNumber();
82
+
83
+ const bitBuffer = reader.readBytes(BitVector.byteLength(length));
84
+ return new BitVector(bitBuffer, length);
85
+ }
86
+
87
+ static byteLength(length: number) {
88
+ return Math.ceil(length / 8);
89
+ }
90
+ }
@@ -0,0 +1,53 @@
1
+ import { TxArray } from '@aztec/stdlib/tx';
2
+
3
+ import type { PeerId } from '@libp2p/interface';
4
+
5
+ import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
6
+ import type { TxPool } from '../../../../mem_pools/index.js';
7
+ import type { ReqRespSubProtocolHandler } from '../../interface.js';
8
+ import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
9
+ import { BitVector } from './bitvector.js';
10
+ import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
11
+
12
+ /**
13
+ * Handler for block txs requests
14
+ * @param attestationPool - the attestation pool to check for block proposals
15
+ * @param mempools - the mempools containing the tx pool
16
+ * @returns the BlockTxs request handler
17
+ */
18
+ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler {
19
+ /**
20
+ * Handler for block txs requests
21
+ * @param msg - the block txs request message
22
+ * @returns the block txs response message
23
+ * @throws if msg is not a valid block txs request
24
+ */
25
+ return async (_peerId: PeerId, msg: Buffer) => {
26
+ let request: BlockTxsRequest;
27
+ try {
28
+ request = BlockTxsRequest.fromBuffer(msg);
29
+ } catch (err: any) {
30
+ throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
31
+ }
32
+
33
+ const blockProposal = await attestationPool.getBlockProposal(request.blockHash.toString());
34
+
35
+ if (!blockProposal) {
36
+ throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
37
+ }
38
+
39
+ const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
40
+ //Map txs in the pool to their indices in the block proposal
41
+ const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
42
+ const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
43
+
44
+ const requestedIndices = new Set(request.txIndices.getTrueIndices());
45
+ const requestedTxsHashes = blockProposal.txHashes.filter((_, idx) => requestedIndices.has(idx));
46
+
47
+ const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
48
+
49
+ const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
50
+
51
+ return response.toBuffer();
52
+ };
53
+ }
@@ -0,0 +1,79 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { TxArray } from '@aztec/stdlib/tx';
4
+
5
+ import { BitVector } from './bitvector.js';
6
+
7
+ /**
8
+ * Request message for requesting specific transactions from a block
9
+ */
10
+ export class BlockTxsRequest {
11
+ constructor(
12
+ readonly blockHash: Fr, // 32 byte hash of the proposed block header
13
+ // BitVector indicating which txs from the proposal we are requesting
14
+ // 1 means we want the tx, 0 means we don't
15
+ readonly txIndices: BitVector,
16
+ ) {}
17
+
18
+ /**
19
+ * Deserializes the BlockTxRequest object from a Buffer
20
+ * @param buffer - Buffer or BufferReader object to deserialize
21
+ * @returns An instance of BlockTxRequest
22
+ */
23
+ static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
24
+ const reader = BufferReader.asReader(buffer);
25
+ const blockHash = Fr.fromBuffer(reader);
26
+ const txIndices = BitVector.fromBuffer(reader);
27
+
28
+ return new BlockTxsRequest(blockHash, txIndices);
29
+ }
30
+
31
+ /**
32
+ * Serializes the BlockTxRequest object into a Buffer
33
+ * @returns Buffer representation of the BlockTxRequest object
34
+ */
35
+ toBuffer(): Buffer {
36
+ return serializeToBuffer([this.blockHash, this.txIndices.toBuffer()]);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Response message containing requested transactions from a block
42
+ */
43
+ export class BlockTxsResponse {
44
+ constructor(
45
+ readonly blockHash: Fr,
46
+ readonly txs: TxArray, // List of transactions we requested and peer has
47
+ // BitVector indicating which txs from the proposal are available at the peer
48
+ // 1 means the tx is available, 0 means it is not
49
+ readonly txIndices: BitVector,
50
+ ) {}
51
+
52
+ /**
53
+ * Deserializes the BlockTxResponse object from a Buffer
54
+ * @param buffer - Buffer or BufferReader object to deserialize
55
+ * @returns An instance of BlockTxResponse
56
+ */
57
+ static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
58
+ const reader = BufferReader.asReader(buffer);
59
+ const blockHash = Fr.fromBuffer(reader);
60
+ const txs = TxArray.fromBuffer(reader);
61
+ const txIndices = BitVector.fromBuffer(reader);
62
+
63
+ return new BlockTxsResponse(blockHash, txs, txIndices);
64
+ }
65
+
66
+ /**
67
+ * Serializes the BlockTxResponse object into a Buffer
68
+ * @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
69
+ * thus we serialize it last
70
+ * @returns Buffer representation of the BlockTxResponse object
71
+ */
72
+ toBuffer(): Buffer {
73
+ return serializeToBuffer([this.blockHash, this.txs.toBuffer(), this.txIndices.toBuffer()]);
74
+ }
75
+
76
+ static empty(): BlockTxsResponse {
77
+ return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
78
+ }
79
+ }
@@ -0,0 +1,3 @@
1
+ export * from './block_txs_handler.js';
2
+ export * from './bitvector.js';
3
+ export * from './block_txs_reqresp.js';
@@ -2,7 +2,7 @@ import { createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import type { PeerId } from '@libp2p/interface';
4
4
 
5
- import type { PeerManager } from '../../peer-manager/peer_manager.js';
5
+ import type { PeerManagerInterface } from '../../peer-manager/interface.js';
6
6
  import { ReqRespSubProtocol, type ReqRespSubProtocolHandler } from '../interface.js';
7
7
  import type { ReqResp } from '../reqresp.js';
8
8
 
@@ -34,7 +34,7 @@ export function decodeGoodbyeReason(buffer: Buffer): GoodByeReason {
34
34
  throw new Error('Invalid goodbye reason buffer length');
35
35
  }
36
36
  return buffer[0] as GoodByeReason;
37
- } catch (error) {
37
+ } catch {
38
38
  return GoodByeReason.UNKNOWN;
39
39
  }
40
40
  }
@@ -89,13 +89,15 @@ export class GoodbyeProtocolHandler {
89
89
  * @param peerManager - The peer manager.
90
90
  * @returns A resolved promise with the goodbye response.
91
91
  */
92
- export function reqGoodbyeHandler(peerManager: PeerManager): ReqRespSubProtocolHandler {
93
- return (peerId: PeerId, _msg: Buffer) => {
94
- const reason = decodeGoodbyeReason(_msg);
92
+ export function reqGoodbyeHandler(peerManager: PeerManagerInterface): ReqRespSubProtocolHandler {
93
+ return (peerId: PeerId, msg: Buffer) => {
94
+ const reason = decodeGoodbyeReason(msg);
95
95
 
96
96
  peerManager.goodbyeReceived(peerId, reason);
97
97
 
98
- // Return a buffer of length 1 as an acknowledgement: this is allowed to fail
99
- return Promise.resolve(Buffer.from([0x0]));
98
+ // NOTE: In the current implementation this won't be sent to peer,
99
+ // as the connection to peer has been already closed by peerManager.goodbyeReceived
100
+ // We have this just to satisfy interface
101
+ return Promise.resolve(Buffer.alloc(0));
100
102
  };
101
103
  }
@@ -6,3 +6,5 @@ export * from './status.js';
6
6
  export * from './tx.js';
7
7
  export * from './goodbye.js';
8
8
  export * from './block.js';
9
+ export * from './auth.js';
10
+ export * from './block_txs/index.js';
@@ -1,8 +1,120 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
+ import { bufferToHex } from '@aztec/foundation/string';
5
+ import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
6
+
7
+ import type { PeerId } from '@libp2p/interface';
8
+
9
+ /*
10
+ * P2P Status Message
11
+ * It is used to establish Status handshake between to peers
12
+ * By validating Status handshake we ensure peers are on the same Blockchain fork
13
+ * And get peer sync status
14
+ */
15
+ export class StatusMessage {
16
+ constructor(
17
+ readonly compressedComponentsVersion: string,
18
+ readonly latestBlockNumber: number,
19
+ readonly latestBlockHash: string,
20
+ readonly finalizedBlockNumber: number,
21
+ //TODO: add finalizedBlockHash
22
+ //readonly finalizedBlockHash: string,
23
+ ) {}
24
+
25
+ /**
26
+ * Deserializes the StatusMessage object from a Buffer.
27
+ * @param buffer - Buffer or BufferReader object to deserialize.
28
+ * @returns An instance of StatusMessage.
29
+ */
30
+ static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
31
+ const reader = BufferReader.asReader(buffer);
32
+ return new StatusMessage(
33
+ reader.readString(), // compressedComponentsVersion
34
+ reader.readNumber(), // latestBlockNumber
35
+ reader.readString(), // latestBlockHash
36
+ reader.readNumber(), // finalizedBlockNumber
37
+ //TODO: add finalizedBlockHash
38
+ //reader.readString(), // finalizedBlockHash
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Serializes the StatusMessage object into a Buffer.
44
+ * @returns Buffer representation of the StatusMessage object.
45
+ */
46
+ toBuffer() {
47
+ return serializeToBuffer([
48
+ this.compressedComponentsVersion,
49
+ this.latestBlockNumber,
50
+ this.latestBlockHash,
51
+ this.finalizedBlockNumber,
52
+ //TODO: add finalizedBlockHash
53
+ // this.finalizedBlockHash,
54
+ ]);
55
+ }
56
+
57
+ /**
58
+ * Builds Status message
59
+ * @param version - Compressed Components Version
60
+ * @param worldStateSyncStatus - Info about the current sync status
61
+ * @returns StatusMessage instance
62
+ */
63
+ static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
64
+ return new StatusMessage(
65
+ version,
66
+ syncStatus.latestBlockNumber,
67
+ syncStatus.latestBlockHash,
68
+ syncStatus.finalizedBlockNumber,
69
+ //TODO: add finalizedBlockHash
70
+ );
71
+ }
72
+
73
+ static random(): StatusMessage {
74
+ return new StatusMessage(
75
+ '1.0.0',
76
+ Math.floor(Math.random() * 100),
77
+ Buffer32.random().toString(),
78
+ Math.floor(Math.random() * 100),
79
+ //TODO: add finalizedBlockHash
80
+ );
81
+ }
82
+
83
+ validate(peerStatus: StatusMessage): boolean {
84
+ // TODO: Validate other fields as well
85
+ return this.compressedComponentsVersion === peerStatus.compressedComponentsVersion;
86
+ }
87
+
88
+ equals(other: StatusMessage): boolean {
89
+ return (
90
+ this.compressedComponentsVersion === other.compressedComponentsVersion &&
91
+ this.latestBlockNumber === other.latestBlockNumber &&
92
+ this.latestBlockHash === other.latestBlockHash &&
93
+ this.finalizedBlockNumber === other.finalizedBlockNumber
94
+ );
95
+ }
96
+ }
97
+
1
98
  /**
2
- * Handles the status request.
3
- * @param _msg - The status request message.
4
- * @returns A resolved promise with the ok response.
99
+ * Handles the status request. By immediately responding with the current node status.
100
+ * @param compressedComponentsVersion - Compressed Components Version
101
+ * @param worldStateSynchronizer - World State Synchronizer to fetch the sync status from.
102
+ * Note the WorldStateSynchronizer must be injected to fetch the fresh sync status, we cannot pass in pre-built StatusMessage.
103
+ * @returns Status message handler
5
104
  */
6
- export function statusHandler(_msg: any): Promise<Buffer> {
7
- return Promise.resolve(Buffer.from('ok'));
105
+ export function reqRespStatusHandler(
106
+ compressedComponentsVersion: string,
107
+ worldStateSynchronizer: WorldStateSynchronizer,
108
+ logger?: Logger,
109
+ ) {
110
+ return async (peerId: PeerId, _msg: Buffer) => {
111
+ logger?.trace(`Received status handshake request from ${peerId}`);
112
+ const status = StatusMessage.fromWorldStateSyncStatus(
113
+ compressedComponentsVersion,
114
+ (await worldStateSynchronizer.status()).syncSummary,
115
+ );
116
+ const response = status.toBuffer();
117
+ logger?.trace(`Responding status handshake from ${peerId}`, { data: bufferToHex(response) });
118
+ return response;
119
+ };
8
120
  }
@@ -1,10 +1,12 @@
1
+ import { chunk } from '@aztec/foundation/collection';
1
2
  import type { P2PClientType } from '@aztec/stdlib/p2p';
2
- import { TxHash } from '@aztec/stdlib/tx';
3
+ import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
3
4
 
4
5
  import type { PeerId } from '@libp2p/interface';
5
6
 
6
7
  import type { MemPools } from '../../../mem_pools/interface.js';
7
8
  import type { ReqRespSubProtocolHandler } from '../interface.js';
9
+ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
8
10
 
9
11
  /**
10
12
  * We want to keep the logic of the req resp handler in this file, but we do not have a reference to the mempools here
@@ -12,18 +14,45 @@ import type { ReqRespSubProtocolHandler } from '../interface.js';
12
14
  *
13
15
  * Handler for tx requests
14
16
  * @param mempools - the mempools
15
- * @returns the tx response message
17
+ * @returns the Tx request handler
16
18
  */
17
19
  export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): ReqRespSubProtocolHandler {
18
20
  /**
19
21
  * Handler for tx requests
20
22
  * @param msg - the tx request message
21
23
  * @returns the tx response message
24
+ * @throws if msg is not a valid tx hash
22
25
  */
23
26
  return async (_peerId: PeerId, msg: Buffer) => {
24
- const txHash = TxHash.fromBuffer(msg);
25
- const foundTx = await mempools.txPool.getTxByHash(txHash);
26
- const buf = foundTx ? foundTx.toBuffer() : Buffer.alloc(0);
27
- return buf;
27
+ let txHashes: TxHashArray;
28
+ try {
29
+ txHashes = TxHashArray.fromBuffer(msg);
30
+ } catch (err: any) {
31
+ throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
32
+ }
33
+
34
+ try {
35
+ const txs = new TxArray(
36
+ ...(await Promise.all(txHashes.map(txHash => mempools.txPool.getTxByHash(txHash)))).filter(t => !!t),
37
+ );
38
+ return txs.toBuffer();
39
+ } catch (err: any) {
40
+ throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
41
+ }
28
42
  };
29
43
  }
44
+
45
+ /**
46
+ * Helper function to chunk an array of transaction hashes into chunks of a specified size.
47
+ * This is mainly used in ReqResp in order not to request too many transactions at once from the single peer.
48
+ *
49
+ * @param hashes - The array of transaction hashes to chunk.
50
+ * @param chunkSize - The size of each chunk. Default is 8. Reasoning:
51
+ * Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
52
+ * we define Q as max number of transactions per batch, the comment explains why we use 8.
53
+ */
54
+ //TODO: (mralj) chunk size should by default be 8, this is just temporary until the protocol is implemented correctly
55
+ //more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
56
+ export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
57
+ return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
58
+ }
@@ -8,7 +8,7 @@ import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
8
8
  import type { PeerId } from '@libp2p/interface';
9
9
 
10
10
  import type { PeerScoring } from '../../peer-manager/peer_scoring.js';
11
- import type { ReqRespSubProtocol, ReqRespSubProtocolRateLimits } from '../interface.js';
11
+ import type { ProtocolRateLimitQuota, ReqRespSubProtocol, ReqRespSubProtocolRateLimits } from '../interface.js';
12
12
  import { DEFAULT_RATE_LIMITS } from './rate_limits.js';
13
13
 
14
14
  // Check for disconnected peers every 10 minutes
@@ -177,13 +177,18 @@ export class SubProtocolRateLimiter {
177
177
  */
178
178
  export class RequestResponseRateLimiter {
179
179
  private subProtocolRateLimiters: Map<ReqRespSubProtocol, SubProtocolRateLimiter>;
180
+ private rateLimits: ReqRespSubProtocolRateLimits;
180
181
 
181
182
  private cleanupInterval: NodeJS.Timeout | undefined = undefined;
182
183
 
183
- constructor(private peerScoring: PeerScoring, rateLimits: ReqRespSubProtocolRateLimits = DEFAULT_RATE_LIMITS) {
184
+ constructor(
185
+ private peerScoring: PeerScoring,
186
+ rateLimits: Partial<ReqRespSubProtocolRateLimits> = {},
187
+ ) {
184
188
  this.subProtocolRateLimiters = new Map();
185
189
 
186
- for (const [subProtocol, protocolLimits] of Object.entries(rateLimits)) {
190
+ this.rateLimits = { ...DEFAULT_RATE_LIMITS, ...rateLimits };
191
+ for (const [subProtocol, protocolLimits] of Object.entries(this.rateLimits)) {
187
192
  this.subProtocolRateLimiters.set(
188
193
  subProtocol as ReqRespSubProtocol,
189
194
  new SubProtocolRateLimiter(
@@ -225,4 +230,8 @@ export class RequestResponseRateLimiter {
225
230
  stop() {
226
231
  clearInterval(this.cleanupInterval);
227
232
  }
233
+
234
+ getRateLimits(protocol: ReqRespSubProtocol): ProtocolRateLimitQuota {
235
+ return this.rateLimits[protocol];
236
+ }
228
237
  }
@@ -22,6 +22,16 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
22
22
  quotaCount: 10,
23
23
  },
24
24
  },
25
+ [ReqRespSubProtocol.AUTH]: {
26
+ peerLimit: {
27
+ quotaTimeMs: 1000,
28
+ quotaCount: 5,
29
+ },
30
+ globalLimit: {
31
+ quotaTimeMs: 1000,
32
+ quotaCount: 10,
33
+ },
34
+ },
25
35
  [ReqRespSubProtocol.TX]: {
26
36
  peerLimit: {
27
37
  quotaTimeMs: 1000,
@@ -29,7 +39,7 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
29
39
  },
30
40
  globalLimit: {
31
41
  quotaTimeMs: 1000,
32
- quotaCount: 20,
42
+ quotaCount: 200,
33
43
  },
34
44
  },
35
45
  [ReqRespSubProtocol.BLOCK]: {
@@ -52,4 +62,14 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
52
62
  quotaCount: 10,
53
63
  },
54
64
  },
65
+ [ReqRespSubProtocol.BLOCK_TXS]: {
66
+ peerLimit: {
67
+ quotaTimeMs: 1000,
68
+ quotaCount: 10,
69
+ },
70
+ globalLimit: {
71
+ quotaTimeMs: 1000,
72
+ quotaCount: 200,
73
+ },
74
+ },
55
75
  };