@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.21caa21

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 (385) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +22 -9
  4. package/dest/client/factory.d.ts +14 -4
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -24
  7. package/dest/client/index.d.ts +2 -1
  8. package/dest/client/index.d.ts.map +1 -1
  9. package/dest/client/index.js +1 -0
  10. package/dest/client/interface.d.ts +157 -0
  11. package/dest/client/interface.d.ts.map +1 -0
  12. package/dest/client/interface.js +9 -0
  13. package/dest/client/p2p_client.d.ts +72 -187
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +373 -177
  16. package/dest/config.d.ts +151 -125
  17. package/dest/config.d.ts.map +1 -1
  18. package/dest/config.js +183 -34
  19. package/dest/enr/generate-enr.d.ts +11 -3
  20. package/dest/enr/generate-enr.d.ts.map +1 -1
  21. package/dest/enr/generate-enr.js +27 -5
  22. package/dest/enr/index.d.ts +1 -1
  23. package/dest/errors/attestation-pool.error.d.ts +7 -0
  24. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  25. package/dest/errors/attestation-pool.error.js +12 -0
  26. package/dest/errors/reqresp.error.d.ts +1 -1
  27. package/dest/errors/reqresp.error.d.ts.map +1 -1
  28. package/dest/index.d.ts +4 -1
  29. package/dest/index.d.ts.map +1 -1
  30. package/dest/index.js +2 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +68 -8
  32. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +214 -63
  36. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  37. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +126 -25
  40. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
  43. package/dest/mem_pools/attestation_pool/mocks.d.ts +225 -5
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +9 -15
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +10 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +35 -38
  50. package/dest/mem_pools/interface.d.ts +1 -1
  51. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +62 -13
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
  54. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  55. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +34 -10
  56. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
  58. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  59. package/dest/mem_pools/tx_pool/priority.js +1 -1
  60. package/dest/mem_pools/tx_pool/tx_pool.d.ts +65 -9
  61. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  63. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
  65. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  66. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  68. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  69. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  70. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  71. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  72. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  73. package/dest/msg_validators/attestation_validator/index.js +1 -0
  74. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
  75. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  76. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
  77. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  78. package/dest/msg_validators/index.d.ts +1 -1
  79. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  80. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  81. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  82. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  83. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  85. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  86. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  87. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  88. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  89. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  90. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
  91. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  93. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  94. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  95. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  96. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  97. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  99. package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
  100. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  101. package/dest/msg_validators/tx_validator/factory.js +74 -0
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  103. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  104. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  105. package/dest/msg_validators/tx_validator/index.d.ts +8 -1
  106. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  107. package/dest/msg_validators/tx_validator/index.js +7 -0
  108. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
  109. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  110. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  111. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  113. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  114. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  115. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  116. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  117. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
  118. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  119. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  120. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  121. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  122. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  123. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  124. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  125. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  126. package/dest/services/data_store.d.ts +1 -1
  127. package/dest/services/data_store.d.ts.map +1 -1
  128. package/dest/services/discv5/discV5_service.d.ts +10 -9
  129. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  130. package/dest/services/discv5/discV5_service.js +63 -36
  131. package/dest/services/dummy_service.d.ts +50 -11
  132. package/dest/services/dummy_service.d.ts.map +1 -1
  133. package/dest/services/dummy_service.js +88 -5
  134. package/dest/services/encoding.d.ts +26 -7
  135. package/dest/services/encoding.d.ts.map +1 -1
  136. package/dest/services/encoding.js +73 -5
  137. package/dest/services/gossipsub/scoring.d.ts +1 -1
  138. package/dest/services/index.d.ts +5 -1
  139. package/dest/services/index.d.ts.map +1 -1
  140. package/dest/services/index.js +4 -0
  141. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  142. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  143. package/dest/services/libp2p/instrumentation.js +164 -0
  144. package/dest/services/libp2p/libp2p_service.d.ts +78 -89
  145. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  146. package/dest/services/libp2p/libp2p_service.js +698 -246
  147. package/dest/services/peer-manager/interface.d.ts +23 -0
  148. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  149. package/dest/services/peer-manager/interface.js +1 -0
  150. package/dest/services/peer-manager/metrics.d.ts +6 -2
  151. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  152. package/dest/services/peer-manager/metrics.js +22 -2
  153. package/dest/services/peer-manager/peer_manager.d.ts +102 -22
  154. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  155. package/dest/services/peer-manager/peer_manager.js +549 -72
  156. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  157. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  158. package/dest/services/peer-manager/peer_scoring.js +40 -2
  159. package/dest/services/reqresp/config.d.ts +11 -9
  160. package/dest/services/reqresp/config.d.ts.map +1 -1
  161. package/dest/services/reqresp/config.js +18 -4
  162. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  163. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  164. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  165. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  166. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  167. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  168. package/dest/services/reqresp/index.d.ts +3 -2
  169. package/dest/services/reqresp/index.d.ts.map +1 -1
  170. package/dest/services/reqresp/index.js +2 -1
  171. package/dest/services/reqresp/interface.d.ts +73 -24
  172. package/dest/services/reqresp/interface.d.ts.map +1 -1
  173. package/dest/services/reqresp/interface.js +45 -26
  174. package/dest/services/reqresp/metrics.d.ts +1 -1
  175. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  176. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  177. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  178. package/dest/services/reqresp/protocols/auth.js +71 -0
  179. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  180. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  181. package/dest/services/reqresp/protocols/block.js +28 -5
  182. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  183. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  184. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  185. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  186. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  187. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  191. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  192. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  193. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  194. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  195. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  196. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  197. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  198. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  199. package/dest/services/reqresp/protocols/index.js +2 -0
  200. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  201. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  202. package/dest/services/reqresp/protocols/status.d.ts +39 -7
  203. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  204. package/dest/services/reqresp/protocols/status.js +72 -5
  205. package/dest/services/reqresp/protocols/tx.d.ts +13 -2
  206. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  207. package/dest/services/reqresp/protocols/tx.js +34 -6
  208. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  209. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  210. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  212. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  213. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  214. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  215. package/dest/services/reqresp/reqresp.d.ts +24 -66
  216. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  217. package/dest/services/reqresp/reqresp.js +298 -207
  218. package/dest/services/reqresp/status.d.ts +10 -4
  219. package/dest/services/reqresp/status.d.ts.map +1 -1
  220. package/dest/services/reqresp/status.js +9 -2
  221. package/dest/services/service.d.ts +23 -19
  222. package/dest/services/service.d.ts.map +1 -1
  223. package/dest/services/tx_collection/config.d.ts +25 -0
  224. package/dest/services/tx_collection/config.d.ts.map +1 -0
  225. package/dest/services/tx_collection/config.js +58 -0
  226. package/dest/services/tx_collection/fast_tx_collection.d.ts +50 -0
  227. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  228. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  229. package/dest/services/tx_collection/index.d.ts +3 -0
  230. package/dest/services/tx_collection/index.d.ts.map +1 -0
  231. package/dest/services/tx_collection/index.js +2 -0
  232. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  233. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  234. package/dest/services/tx_collection/instrumentation.js +34 -0
  235. package/dest/services/tx_collection/slow_tx_collection.d.ts +52 -0
  236. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  237. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  238. package/dest/services/tx_collection/tx_collection.d.ts +109 -0
  239. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  240. package/dest/services/tx_collection/tx_collection.js +128 -0
  241. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  242. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  243. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  244. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  245. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  246. package/dest/services/tx_collection/tx_source.js +31 -0
  247. package/dest/services/tx_provider.d.ts +49 -0
  248. package/dest/services/tx_provider.d.ts.map +1 -0
  249. package/dest/services/tx_provider.js +210 -0
  250. package/dest/services/tx_provider_instrumentation.d.ts +13 -0
  251. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  252. package/dest/services/tx_provider_instrumentation.js +34 -0
  253. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  254. package/dest/test-helpers/get-ports.d.ts +1 -1
  255. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  256. package/dest/test-helpers/index.d.ts +2 -1
  257. package/dest/test-helpers/index.d.ts.map +1 -1
  258. package/dest/test-helpers/index.js +1 -0
  259. package/dest/test-helpers/make-enrs.d.ts +1 -1
  260. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  261. package/dest/test-helpers/make-enrs.js +4 -5
  262. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  263. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  264. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  265. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  266. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  267. package/dest/test-helpers/mock-pubsub.js +130 -0
  268. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  269. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  270. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  271. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  272. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  273. package/dest/test-helpers/reqresp-nodes.js +62 -28
  274. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  275. package/dest/testbench/p2p_client_testbench_worker.js +103 -29
  276. package/dest/testbench/parse_log_file.d.ts +1 -1
  277. package/dest/testbench/parse_log_file.js +4 -4
  278. package/dest/testbench/testbench.d.ts +1 -1
  279. package/dest/testbench/testbench.js +4 -4
  280. package/dest/testbench/worker_client_manager.d.ts +1 -6
  281. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  282. package/dest/testbench/worker_client_manager.js +11 -19
  283. package/dest/types/index.d.ts +4 -2
  284. package/dest/types/index.d.ts.map +1 -1
  285. package/dest/types/index.js +2 -0
  286. package/dest/util.d.ts +24 -16
  287. package/dest/util.d.ts.map +1 -1
  288. package/dest/util.js +75 -69
  289. package/dest/versioning.d.ts +4 -4
  290. package/dest/versioning.d.ts.map +1 -1
  291. package/dest/versioning.js +8 -3
  292. package/package.json +32 -27
  293. package/src/bootstrap/bootstrap.ts +27 -11
  294. package/src/client/factory.ts +136 -45
  295. package/src/client/index.ts +1 -0
  296. package/src/client/interface.ts +198 -0
  297. package/src/client/p2p_client.ts +469 -330
  298. package/src/config.ts +305 -134
  299. package/src/enr/generate-enr.ts +39 -6
  300. package/src/errors/attestation-pool.error.ts +13 -0
  301. package/src/index.ts +4 -0
  302. package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
  303. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +264 -65
  304. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +173 -34
  305. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
  306. package/src/mem_pools/attestation_pool/mocks.ts +11 -10
  307. package/src/mem_pools/instrumentation.ts +43 -44
  308. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
  309. package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
  310. package/src/mem_pools/tx_pool/priority.ts +1 -1
  311. package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
  312. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
  313. package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
  314. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  315. package/src/msg_validators/attestation_validator/index.ts +1 -0
  316. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
  317. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  318. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  319. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  320. package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
  321. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  322. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  323. package/src/msg_validators/tx_validator/factory.ts +109 -0
  324. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  325. package/src/msg_validators/tx_validator/index.ts +7 -0
  326. package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
  327. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  328. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  329. package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
  330. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  331. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  332. package/src/services/discv5/discV5_service.ts +84 -38
  333. package/src/services/dummy_service.ts +147 -9
  334. package/src/services/encoding.ts +80 -5
  335. package/src/services/index.ts +4 -0
  336. package/src/services/libp2p/instrumentation.ts +167 -0
  337. package/src/services/libp2p/libp2p_service.ts +866 -294
  338. package/src/services/peer-manager/interface.ts +29 -0
  339. package/src/services/peer-manager/metrics.ts +26 -1
  340. package/src/services/peer-manager/peer_manager.ts +654 -78
  341. package/src/services/peer-manager/peer_scoring.ts +46 -3
  342. package/src/services/reqresp/config.ts +26 -9
  343. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  344. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  345. package/src/services/reqresp/index.ts +2 -0
  346. package/src/services/reqresp/interface.ts +91 -36
  347. package/src/services/reqresp/metrics.ts +4 -1
  348. package/src/services/reqresp/protocols/auth.ts +83 -0
  349. package/src/services/reqresp/protocols/block.ts +24 -3
  350. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  351. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  352. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  353. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  354. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  355. package/src/services/reqresp/protocols/index.ts +2 -0
  356. package/src/services/reqresp/protocols/status.ts +117 -5
  357. package/src/services/reqresp/protocols/tx.ts +35 -6
  358. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  359. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  360. package/src/services/reqresp/reqresp.ts +387 -256
  361. package/src/services/reqresp/status.ts +12 -3
  362. package/src/services/service.ts +45 -21
  363. package/src/services/tx_collection/config.ts +84 -0
  364. package/src/services/tx_collection/fast_tx_collection.ts +340 -0
  365. package/src/services/tx_collection/index.ts +2 -0
  366. package/src/services/tx_collection/instrumentation.ts +43 -0
  367. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  368. package/src/services/tx_collection/tx_collection.ts +215 -0
  369. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  370. package/src/services/tx_collection/tx_source.ts +37 -0
  371. package/src/services/tx_provider.ts +216 -0
  372. package/src/services/tx_provider_instrumentation.ts +44 -0
  373. package/src/test-helpers/index.ts +1 -0
  374. package/src/test-helpers/make-enrs.ts +4 -5
  375. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  376. package/src/test-helpers/mock-pubsub.ts +188 -0
  377. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  378. package/src/test-helpers/reqresp-nodes.ts +86 -35
  379. package/src/testbench/p2p_client_testbench_worker.ts +151 -25
  380. package/src/testbench/parse_log_file.ts +4 -4
  381. package/src/testbench/testbench.ts +4 -4
  382. package/src/testbench/worker_client_manager.ts +17 -23
  383. package/src/types/index.ts +2 -0
  384. package/src/util.ts +105 -91
  385. package/src/versioning.ts +11 -4
@@ -1,19 +1,25 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
2
  import { L2Block } from '@aztec/stdlib/block';
3
- import { Tx, TxHash } from '@aztec/stdlib/tx';
3
+ import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
4
4
 
5
5
  import type { PeerId } from '@libp2p/interface';
6
6
 
7
+ import type { P2PReqRespConfig } from './config.js';
8
+ import { AuthRequest, AuthResponse } from './protocols/auth.js';
9
+ import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
10
+ import { StatusMessage } from './protocols/status.js';
7
11
  import type { ReqRespStatus } from './status.js';
8
12
 
9
13
  /*
10
14
  * Request Response Sub Protocols
11
15
  */
12
- export const PING_PROTOCOL = '/aztec/req/ping/0.1.0';
13
- export const STATUS_PROTOCOL = '/aztec/req/status/0.1.0';
14
- export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/0.1.0';
15
- export const TX_REQ_PROTOCOL = '/aztec/req/tx/0.1.0';
16
- export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/0.1.0';
16
+ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
17
+ export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
18
+ export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
19
+ export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
20
+ export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
21
+ export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
22
+ export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
17
23
 
18
24
  export enum ReqRespSubProtocol {
19
25
  PING = PING_PROTOCOL,
@@ -21,6 +27,8 @@ export enum ReqRespSubProtocol {
21
27
  GOODBYE = GOODBYE_PROTOCOL,
22
28
  TX = TX_REQ_PROTOCOL,
23
29
  BLOCK = BLOCK_REQ_PROTOCOL,
30
+ AUTH = AUTH_PROTOCOL,
31
+ BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
24
32
  }
25
33
 
26
34
  /**
@@ -36,12 +44,12 @@ export type ReqRespSubProtocolRateLimits = Record<ReqRespSubProtocol, ProtocolRa
36
44
 
37
45
  /**
38
46
  * The response from the ReqResp protocol
39
- * Consists of a status (Error code) and data
47
+ * Consists of a status
48
+ * And, optionally, a data buffer (in case status is SUCCESS)
40
49
  */
41
- export interface ReqRespResponse {
42
- status: ReqRespStatus;
43
- data: Buffer;
44
- }
50
+ export type ReqRespResponse =
51
+ | { status: ReqRespStatus.SUCCESS; data: Buffer }
52
+ | { status: Exclude<ReqRespStatus, ReqRespStatus.SUCCESS> };
45
53
 
46
54
  /**
47
55
  * A rate limit quota
@@ -91,33 +99,27 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
91
99
  [ReqRespSubProtocol.TX]: noopValidator,
92
100
  [ReqRespSubProtocol.GOODBYE]: noopValidator,
93
101
  [ReqRespSubProtocol.BLOCK]: noopValidator,
102
+ [ReqRespSubProtocol.AUTH]: noopValidator,
103
+ [ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
94
104
  };
95
105
 
106
+ /*
107
+ * Helper class to sub-protocol validation error*/
108
+ export class ValidationError extends Error {
109
+ constructor(message: string) {
110
+ super(message);
111
+ }
112
+ }
113
+
96
114
  /**
97
115
  * Sub protocol map determines the request and response types for each
98
116
  * Req Resp protocol
99
117
  */
100
118
  export type SubProtocolMap = {
101
- [S in ReqRespSubProtocol]: RequestResponsePair<any, any>;
102
- };
103
-
104
- /**
105
- * Default handler for unimplemented sub protocols, this SHOULD be overwritten
106
- * by the service, but is provided as a fallback
107
- */
108
- const defaultHandler = (_msg: any): Promise<Buffer> => {
109
- return Promise.resolve(Buffer.from('unimplemented'));
110
- };
111
-
112
- /**
113
- * Default sub protocol handlers - this SHOULD be overwritten by the service,
114
- */
115
- export const DEFAULT_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
116
- [ReqRespSubProtocol.PING]: defaultHandler,
117
- [ReqRespSubProtocol.STATUS]: defaultHandler,
118
- [ReqRespSubProtocol.TX]: defaultHandler,
119
- [ReqRespSubProtocol.GOODBYE]: defaultHandler,
120
- [ReqRespSubProtocol.BLOCK]: defaultHandler,
119
+ [S in ReqRespSubProtocol]: RequestResponsePair<
120
+ InstanceType<(typeof subProtocolMap)[S]['request']>,
121
+ InstanceType<(typeof subProtocolMap)[S]['response']>
122
+ >;
121
123
  };
122
124
 
123
125
  /**
@@ -138,6 +140,22 @@ interface RequestResponsePair<Req extends { toBuffer(): Buffer }, Res> {
138
140
  };
139
141
  }
140
142
 
143
+ /*
144
+ * Small helper function which parses buffer into specific response type
145
+ * It is needed to make TypeScript happy, as it cannot infer the type from the buffer
146
+ *
147
+ * @param proto - The sub protocol to parse the response for
148
+ * @param buffer - The buffer to parse
149
+ *
150
+ * @returns - The parsed response object
151
+ * */
152
+ export function responseFromBuffer<P extends ReqRespSubProtocol>(
153
+ proto: P,
154
+ buffer: Buffer,
155
+ ): InstanceType<(typeof subProtocolMap)[P]['response']> {
156
+ return subProtocolMap[proto].response.fromBuffer(buffer) as InstanceType<(typeof subProtocolMap)[P]['response']>;
157
+ }
158
+
141
159
  /**
142
160
  * RequestableBuffer is a wrapper around a buffer that allows it to be
143
161
  * used in generic request response protocols
@@ -161,18 +179,18 @@ export class RequestableBuffer {
161
179
  * This defines the request and response types for each sub protocol, used primarily
162
180
  * as a type rather than an object
163
181
  */
164
- export const subProtocolMap: SubProtocolMap = {
182
+ export const subProtocolMap = {
165
183
  [ReqRespSubProtocol.PING]: {
166
184
  request: RequestableBuffer,
167
185
  response: RequestableBuffer,
168
186
  },
169
187
  [ReqRespSubProtocol.STATUS]: {
170
- request: RequestableBuffer,
171
- response: RequestableBuffer,
188
+ request: StatusMessage,
189
+ response: StatusMessage,
172
190
  },
173
191
  [ReqRespSubProtocol.TX]: {
174
- request: TxHash,
175
- response: Tx,
192
+ request: TxHashArray,
193
+ response: TxArray,
176
194
  },
177
195
  [ReqRespSubProtocol.GOODBYE]: {
178
196
  request: RequestableBuffer,
@@ -182,4 +200,41 @@ export const subProtocolMap: SubProtocolMap = {
182
200
  request: Fr, // block number
183
201
  response: L2Block,
184
202
  },
203
+ [ReqRespSubProtocol.AUTH]: {
204
+ request: AuthRequest,
205
+ response: AuthResponse,
206
+ },
207
+ [ReqRespSubProtocol.BLOCK_TXS]: {
208
+ request: BlockTxsRequest,
209
+ response: BlockTxsResponse,
210
+ },
185
211
  };
212
+
213
+ export interface ReqRespInterface {
214
+ start(
215
+ subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
216
+ subProtocolValidators: ReqRespSubProtocolValidators,
217
+ ): Promise<void>;
218
+ addSubProtocol(
219
+ subProtocol: ReqRespSubProtocol,
220
+ handler: ReqRespSubProtocolHandler,
221
+ validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
222
+ ): Promise<void>;
223
+ stop(): Promise<void>;
224
+ sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
225
+ subProtocol: SubProtocol,
226
+ requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
227
+ pinnedPeer: PeerId | undefined,
228
+ timeoutMs?: number,
229
+ maxPeers?: number,
230
+ maxRetryAttempts?: number,
231
+ ): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
232
+ sendRequestToPeer(
233
+ peerId: PeerId,
234
+ subProtocol: ReqRespSubProtocol,
235
+ payload: Buffer,
236
+ dialTimeout?: number,
237
+ ): Promise<ReqRespResponse>;
238
+
239
+ updateConfig(config: Partial<P2PReqRespConfig>): void;
240
+ }
@@ -11,7 +11,10 @@ export class ReqRespMetrics {
11
11
  private readonly failedOutboundRequests: UpDownCounter;
12
12
  private readonly failedInboundRequests: UpDownCounter;
13
13
 
14
- constructor(readonly telemetryClient: TelemetryClient, name = 'ReqResp') {
14
+ constructor(
15
+ readonly telemetryClient: TelemetryClient,
16
+ name = 'ReqResp',
17
+ ) {
15
18
  this.tracer = telemetryClient.getTracer(name);
16
19
 
17
20
  const meter = telemetryClient.getMeter(name);
@@ -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';