@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.03f7ef2

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 (387) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +22 -9
  4. package/dest/client/factory.d.ts +15 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -25
  7. package/dest/client/index.d.ts +2 -1
  8. package/dest/client/index.d.ts.map +1 -1
  9. package/dest/client/index.js +1 -0
  10. package/dest/client/interface.d.ts +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 +75 -190
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +381 -183
  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 +216 -65
  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 +127 -26
  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 +227 -7
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +10 -16
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +16 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +57 -35
  50. package/dest/mem_pools/interface.d.ts +3 -4
  51. package/dest/mem_pools/interface.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +64 -14
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +472 -97
  55. package/dest/mem_pools/tx_pool/index.d.ts +1 -1
  56. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +36 -11
  57. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool/memory_tx_pool.js +137 -36
  59. package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
  60. package/dest/mem_pools/tx_pool/priority.js +1 -1
  61. package/dest/mem_pools/tx_pool/tx_pool.d.ts +67 -10
  62. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  64. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +273 -42
  66. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
  67. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  68. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  69. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  70. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  71. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
  72. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  73. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  74. package/dest/msg_validators/attestation_validator/index.js +1 -0
  75. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
  76. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  77. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
  78. package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
  79. package/dest/msg_validators/index.d.ts +1 -1
  80. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  81. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  82. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  83. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  84. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  85. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  86. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  88. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  89. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  90. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  91. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  92. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  93. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  94. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  95. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  96. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  97. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  98. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  99. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  100. package/dest/msg_validators/tx_validator/factory.d.ts +16 -0
  101. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  102. package/dest/msg_validators/tx_validator/factory.js +74 -0
  103. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  104. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  105. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  106. package/dest/msg_validators/tx_validator/index.d.ts +8 -1
  107. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  108. package/dest/msg_validators/tx_validator/index.js +7 -0
  109. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +9 -5
  110. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  111. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  112. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  113. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  114. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  115. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  116. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  117. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  118. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  119. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  120. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  121. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  122. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  123. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  124. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  125. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  126. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  127. package/dest/services/data_store.d.ts +1 -1
  128. package/dest/services/data_store.d.ts.map +1 -1
  129. package/dest/services/discv5/discV5_service.d.ts +10 -9
  130. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  131. package/dest/services/discv5/discV5_service.js +63 -36
  132. package/dest/services/dummy_service.d.ts +50 -11
  133. package/dest/services/dummy_service.d.ts.map +1 -1
  134. package/dest/services/dummy_service.js +88 -5
  135. package/dest/services/encoding.d.ts +26 -7
  136. package/dest/services/encoding.d.ts.map +1 -1
  137. package/dest/services/encoding.js +74 -6
  138. package/dest/services/gossipsub/scoring.d.ts +1 -1
  139. package/dest/services/index.d.ts +5 -1
  140. package/dest/services/index.d.ts.map +1 -1
  141. package/dest/services/index.js +4 -0
  142. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  143. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  144. package/dest/services/libp2p/instrumentation.js +164 -0
  145. package/dest/services/libp2p/libp2p_service.d.ts +78 -89
  146. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  147. package/dest/services/libp2p/libp2p_service.js +695 -248
  148. package/dest/services/peer-manager/interface.d.ts +23 -0
  149. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  150. package/dest/services/peer-manager/interface.js +1 -0
  151. package/dest/services/peer-manager/metrics.d.ts +6 -2
  152. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  153. package/dest/services/peer-manager/metrics.js +22 -2
  154. package/dest/services/peer-manager/peer_manager.d.ts +102 -22
  155. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  156. package/dest/services/peer-manager/peer_manager.js +549 -72
  157. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  158. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  159. package/dest/services/peer-manager/peer_scoring.js +40 -2
  160. package/dest/services/reqresp/config.d.ts +11 -9
  161. package/dest/services/reqresp/config.d.ts.map +1 -1
  162. package/dest/services/reqresp/config.js +18 -4
  163. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  164. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  165. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  166. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  167. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  168. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  169. package/dest/services/reqresp/index.d.ts +3 -2
  170. package/dest/services/reqresp/index.d.ts.map +1 -1
  171. package/dest/services/reqresp/index.js +2 -1
  172. package/dest/services/reqresp/interface.d.ts +73 -24
  173. package/dest/services/reqresp/interface.d.ts.map +1 -1
  174. package/dest/services/reqresp/interface.js +46 -27
  175. package/dest/services/reqresp/metrics.d.ts +1 -1
  176. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  177. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  178. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  179. package/dest/services/reqresp/protocols/auth.js +71 -0
  180. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  181. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  182. package/dest/services/reqresp/protocols/block.js +30 -6
  183. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  184. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  185. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  186. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  187. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  188. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  189. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  190. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  191. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  192. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  193. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  194. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  195. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  196. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  197. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  198. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  199. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  200. package/dest/services/reqresp/protocols/index.js +2 -0
  201. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  202. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  203. package/dest/services/reqresp/protocols/status.d.ts +40 -7
  204. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  205. package/dest/services/reqresp/protocols/status.js +73 -5
  206. package/dest/services/reqresp/protocols/tx.d.ts +14 -4
  207. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  208. package/dest/services/reqresp/protocols/tx.js +34 -6
  209. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  210. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  211. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  212. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  213. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  214. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  215. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  216. package/dest/services/reqresp/reqresp.d.ts +24 -66
  217. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  218. package/dest/services/reqresp/reqresp.js +298 -207
  219. package/dest/services/reqresp/status.d.ts +10 -4
  220. package/dest/services/reqresp/status.d.ts.map +1 -1
  221. package/dest/services/reqresp/status.js +9 -2
  222. package/dest/services/service.d.ts +23 -19
  223. package/dest/services/service.d.ts.map +1 -1
  224. package/dest/services/tx_collection/config.d.ts +25 -0
  225. package/dest/services/tx_collection/config.d.ts.map +1 -0
  226. package/dest/services/tx_collection/config.js +58 -0
  227. package/dest/services/tx_collection/fast_tx_collection.d.ts +51 -0
  228. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  229. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  230. package/dest/services/tx_collection/index.d.ts +3 -0
  231. package/dest/services/tx_collection/index.d.ts.map +1 -0
  232. package/dest/services/tx_collection/index.js +2 -0
  233. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  234. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  235. package/dest/services/tx_collection/instrumentation.js +34 -0
  236. package/dest/services/tx_collection/slow_tx_collection.d.ts +53 -0
  237. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  238. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  239. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  240. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  241. package/dest/services/tx_collection/tx_collection.js +128 -0
  242. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  243. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  244. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  245. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  246. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  247. package/dest/services/tx_collection/tx_source.js +31 -0
  248. package/dest/services/tx_provider.d.ts +51 -0
  249. package/dest/services/tx_provider.d.ts.map +1 -0
  250. package/dest/services/tx_provider.js +217 -0
  251. package/dest/services/tx_provider_instrumentation.d.ts +16 -0
  252. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  253. package/dest/services/tx_provider_instrumentation.js +47 -0
  254. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  255. package/dest/test-helpers/get-ports.d.ts +1 -1
  256. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  257. package/dest/test-helpers/index.d.ts +2 -1
  258. package/dest/test-helpers/index.d.ts.map +1 -1
  259. package/dest/test-helpers/index.js +1 -0
  260. package/dest/test-helpers/make-enrs.d.ts +1 -1
  261. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  262. package/dest/test-helpers/make-enrs.js +4 -5
  263. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  264. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  265. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  266. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  267. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  268. package/dest/test-helpers/mock-pubsub.js +130 -0
  269. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  270. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  271. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  272. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  273. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  274. package/dest/test-helpers/reqresp-nodes.js +62 -28
  275. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  276. package/dest/testbench/p2p_client_testbench_worker.js +103 -29
  277. package/dest/testbench/parse_log_file.d.ts +1 -1
  278. package/dest/testbench/parse_log_file.js +4 -4
  279. package/dest/testbench/testbench.d.ts +1 -1
  280. package/dest/testbench/testbench.js +4 -4
  281. package/dest/testbench/worker_client_manager.d.ts +1 -6
  282. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  283. package/dest/testbench/worker_client_manager.js +11 -19
  284. package/dest/types/index.d.ts +4 -2
  285. package/dest/types/index.d.ts.map +1 -1
  286. package/dest/types/index.js +2 -0
  287. package/dest/util.d.ts +24 -16
  288. package/dest/util.d.ts.map +1 -1
  289. package/dest/util.js +75 -69
  290. package/dest/versioning.d.ts +4 -4
  291. package/dest/versioning.d.ts.map +1 -1
  292. package/dest/versioning.js +8 -3
  293. package/package.json +32 -27
  294. package/src/bootstrap/bootstrap.ts +27 -11
  295. package/src/client/factory.ts +139 -53
  296. package/src/client/index.ts +1 -0
  297. package/src/client/interface.ts +198 -0
  298. package/src/client/p2p_client.ts +484 -348
  299. package/src/config.ts +305 -134
  300. package/src/enr/generate-enr.ts +39 -6
  301. package/src/errors/attestation-pool.error.ts +13 -0
  302. package/src/index.ts +4 -0
  303. package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
  304. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +266 -67
  305. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +174 -35
  306. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
  307. package/src/mem_pools/attestation_pool/mocks.ts +13 -12
  308. package/src/mem_pools/instrumentation.ts +70 -40
  309. package/src/mem_pools/interface.ts +2 -4
  310. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +555 -110
  311. package/src/mem_pools/tx_pool/memory_tx_pool.ts +160 -46
  312. package/src/mem_pools/tx_pool/priority.ts +1 -1
  313. package/src/mem_pools/tx_pool/tx_pool.ts +69 -9
  314. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +224 -35
  315. package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
  316. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
  317. package/src/msg_validators/attestation_validator/index.ts +1 -0
  318. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
  319. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  320. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  321. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  322. package/src/msg_validators/tx_validator/block_header_validator.ts +5 -5
  323. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  324. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  325. package/src/msg_validators/tx_validator/factory.ts +110 -0
  326. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  327. package/src/msg_validators/tx_validator/index.ts +7 -0
  328. package/src/msg_validators/tx_validator/metadata_validator.ts +59 -22
  329. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  330. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  331. package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
  332. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  333. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  334. package/src/services/discv5/discV5_service.ts +84 -38
  335. package/src/services/dummy_service.ts +147 -9
  336. package/src/services/encoding.ts +81 -6
  337. package/src/services/index.ts +4 -0
  338. package/src/services/libp2p/instrumentation.ts +167 -0
  339. package/src/services/libp2p/libp2p_service.ts +865 -298
  340. package/src/services/peer-manager/interface.ts +29 -0
  341. package/src/services/peer-manager/metrics.ts +26 -1
  342. package/src/services/peer-manager/peer_manager.ts +654 -78
  343. package/src/services/peer-manager/peer_scoring.ts +46 -3
  344. package/src/services/reqresp/config.ts +26 -9
  345. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  346. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  347. package/src/services/reqresp/index.ts +2 -0
  348. package/src/services/reqresp/interface.ts +92 -37
  349. package/src/services/reqresp/metrics.ts +4 -1
  350. package/src/services/reqresp/protocols/auth.ts +83 -0
  351. package/src/services/reqresp/protocols/block.ts +26 -4
  352. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  353. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  354. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  355. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  356. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  357. package/src/services/reqresp/protocols/index.ts +2 -0
  358. package/src/services/reqresp/protocols/status.ts +118 -5
  359. package/src/services/reqresp/protocols/tx.ts +36 -8
  360. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  361. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  362. package/src/services/reqresp/reqresp.ts +387 -256
  363. package/src/services/reqresp/status.ts +12 -3
  364. package/src/services/service.ts +45 -21
  365. package/src/services/tx_collection/config.ts +84 -0
  366. package/src/services/tx_collection/fast_tx_collection.ts +341 -0
  367. package/src/services/tx_collection/index.ts +2 -0
  368. package/src/services/tx_collection/instrumentation.ts +43 -0
  369. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  370. package/src/services/tx_collection/tx_collection.ts +216 -0
  371. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  372. package/src/services/tx_collection/tx_source.ts +37 -0
  373. package/src/services/tx_provider.ts +229 -0
  374. package/src/services/tx_provider_instrumentation.ts +61 -0
  375. package/src/test-helpers/index.ts +1 -0
  376. package/src/test-helpers/make-enrs.ts +4 -5
  377. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  378. package/src/test-helpers/mock-pubsub.ts +188 -0
  379. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  380. package/src/test-helpers/reqresp-nodes.ts +87 -36
  381. package/src/testbench/p2p_client_testbench_worker.ts +151 -25
  382. package/src/testbench/parse_log_file.ts +4 -4
  383. package/src/testbench/testbench.ts +4 -4
  384. package/src/testbench/worker_client_manager.ts +17 -23
  385. package/src/types/index.ts +2 -0
  386. package/src/util.ts +105 -91
  387. package/src/versioning.ts +11 -4
@@ -0,0 +1,233 @@
1
+ import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { chunk } from '@aztec/foundation/collection';
3
+ import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { boundInclusive } from '@aztec/foundation/number';
5
+ import { RunningPromise } from '@aztec/foundation/promise';
6
+ import { DateProvider } from '@aztec/foundation/timer';
7
+ import type { L2BlockNew } from '@aztec/stdlib/block';
8
+ import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
9
+ import { type Tx, TxHash } from '@aztec/stdlib/tx';
10
+
11
+ import { type ReqRespInterface, ReqRespSubProtocol } from '../reqresp/interface.js';
12
+ import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
13
+ import type { TxCollectionConfig } from './config.js';
14
+ import type { FastTxCollection } from './fast_tx_collection.js';
15
+ import type { MissingTxInfo } from './tx_collection.js';
16
+ import type { TxCollectionSink } from './tx_collection_sink.js';
17
+ import type { TxSource } from './tx_source.js';
18
+
19
+ export class SlowTxCollection {
20
+ /** Map from tx hash to missing tx info to collect via slow loop */
21
+ private missingTxs: Map<string, MissingTxInfo> = new Map();
22
+
23
+ /** One slow collection loop for each node tx source we have */
24
+ private nodesSlowCollectionLoops: RunningPromise[];
25
+
26
+ /** Slow collection loop for reqresp which collects txs from peers */
27
+ private reqrespSlowCollectionLoop: RunningPromise;
28
+
29
+ constructor(
30
+ private reqResp: Pick<ReqRespInterface, 'sendBatchRequest'>,
31
+ private nodes: TxSource[],
32
+ private txCollectionSink: TxCollectionSink,
33
+ private fastCollection: Pick<FastTxCollection, 'getFastCollectionRequests'>,
34
+ private constants: L1RollupConstants,
35
+ private config: TxCollectionConfig,
36
+ private dateProvider: DateProvider = new DateProvider(),
37
+ private log: Logger = createLogger('p2p:tx_collection_service'),
38
+ ) {
39
+ this.nodesSlowCollectionLoops = this.nodes.map(
40
+ node =>
41
+ new RunningPromise(
42
+ () => this.collectMissingTxsFromNode(node),
43
+ this.log,
44
+ this.config.txCollectionSlowNodesIntervalMs,
45
+ ),
46
+ );
47
+
48
+ this.reqrespSlowCollectionLoop = new RunningPromise(
49
+ () => this.collectMissingTxsViaReqResp(),
50
+ this.log,
51
+ this.config.txCollectionSlowReqRespIntervalMs,
52
+ );
53
+ }
54
+
55
+ public getMissingTxHashes() {
56
+ return Array.from(this.missingTxs.keys()).map(TxHash.fromString);
57
+ }
58
+
59
+ public start() {
60
+ this.nodesSlowCollectionLoops.forEach(loop => loop.start());
61
+ this.reqrespSlowCollectionLoop.start();
62
+ }
63
+
64
+ public async stop() {
65
+ await Promise.all([
66
+ this.reqrespSlowCollectionLoop.stop(),
67
+ ...this.nodesSlowCollectionLoops.map(loop => loop.stop()),
68
+ ]);
69
+ }
70
+
71
+ public async trigger() {
72
+ await Promise.all([
73
+ this.reqrespSlowCollectionLoop.trigger(),
74
+ ...this.nodesSlowCollectionLoops.map(loop => loop.trigger()),
75
+ ]);
76
+ }
77
+
78
+ /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
79
+ public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
80
+ const slot = block.header.getSlot();
81
+ const deadline = this.getDeadlineForSlot(slot);
82
+ if (+deadline < this.dateProvider.now()) {
83
+ this.log.debug(`Skipping collection of txs for block ${block.number} at slot ${slot} as it is already expired`, {
84
+ blockNumber: block.number,
85
+ slot: slot.toString(),
86
+ txHashes: txHashes.map(txHash => txHash.toString()),
87
+ deadline: +deadline,
88
+ now: this.dateProvider.now(),
89
+ });
90
+ }
91
+
92
+ for (const txHash of txHashes) {
93
+ this.missingTxs.set(txHash.toString(), {
94
+ blockNumber: block.number,
95
+ deadline: this.getDeadlineForSlot(block.header.getSlot()),
96
+ readyForReqResp: this.nodes.length === 0, // If we have no nodes, we can start reqresp immediately
97
+ });
98
+ }
99
+ }
100
+
101
+ /** Entrypoint for the node slow collection loop */
102
+ private async collectMissingTxsFromNode(node: TxSource) {
103
+ // If we have any fast requests, we skip the slow collection for this node if configured to do so
104
+ const requests = this.fastCollection.getFastCollectionRequests();
105
+ if (this.config.txCollectionDisableSlowDuringFastRequests && requests.size > 0) {
106
+ this.log.trace(`Skipping node slow collection due to active fast requests`);
107
+ return;
108
+ }
109
+
110
+ // Gather all missing txs that are not in fast collection and request them from the node
111
+ const missingTxs = this.getMissingTxsForSlowCollection();
112
+ const missingTxHashes = missingTxs.map(([txHash]) => txHash).map(TxHash.fromString);
113
+ if (missingTxHashes.length === 0) {
114
+ return;
115
+ }
116
+
117
+ // Request in chunks to avoid hitting RPC limits
118
+ for (const batch of chunk(missingTxHashes, this.config.txCollectionNodeRpcMaxBatchSize)) {
119
+ await this.txCollectionSink.collect(txHashes => node.getTxsByHash(txHashes), batch, {
120
+ description: `node ${node.getInfo()}`,
121
+ node: node.getInfo(),
122
+ method: 'slow-node-rpc',
123
+ });
124
+ }
125
+
126
+ // Mark every tx that is still missing as ready for reqresp.
127
+ // Note that we can just mark all requested txs as ready for reqresp, without filtering out the ones
128
+ // we retrieved, since the ones already found will have been removed from `missingTxs`.
129
+ missingTxs.forEach(([_txHash, info]) => {
130
+ info.readyForReqResp = true;
131
+ });
132
+ }
133
+
134
+ /** Entrypoint for the reqresp slow collection loop */
135
+ private async collectMissingTxsViaReqResp() {
136
+ // If we have any fast requests, we skip the slow collection if configured to do so
137
+ const requests = this.fastCollection.getFastCollectionRequests();
138
+ if (this.config.txCollectionDisableSlowDuringFastRequests && requests.size > 0) {
139
+ this.log.trace(`Skipping reqresp slow collection due to active fast requests`);
140
+ return;
141
+ }
142
+
143
+ // Gather all missing txs that are not in fast collection and are ready for reqresp
144
+ // A tx is flagged as ready for reqresp if it has been requested from a node at least once
145
+ const missingTxs = this.getMissingTxsForSlowCollection({ onlyReqRespReady: true });
146
+ if (missingTxs.length === 0) {
147
+ return;
148
+ }
149
+
150
+ const pinnedPeer = undefined;
151
+ const timeoutMs = this.config.txCollectionSlowReqRespTimeoutMs;
152
+ const maxPeers = boundInclusive(Math.ceil(missingTxs.length / 3), 4, 16);
153
+ const maxRetryAttempts = 3;
154
+ // Send a batch request via reqresp for the missing txs
155
+ await this.txCollectionSink.collect(
156
+ async txHashes => {
157
+ const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
158
+ ReqRespSubProtocol.TX,
159
+ chunkTxHashesRequest(txHashes),
160
+ pinnedPeer,
161
+ timeoutMs,
162
+ maxPeers,
163
+ maxRetryAttempts,
164
+ );
165
+
166
+ return txs.flat();
167
+ },
168
+ missingTxs.map(([txHash]) => TxHash.fromString(txHash)),
169
+ { description: 'slow reqresp', timeoutMs, method: 'slow-req-resp' },
170
+ );
171
+ }
172
+
173
+ /** Retrieves all missing txs for the slow collection process. This is, all missing txs that are not part of a fast request. */
174
+ private getMissingTxsForSlowCollection(opts: { onlyReqRespReady?: boolean } = {}): [string, MissingTxInfo][] {
175
+ // Remove expired txs from missingTxs
176
+ const now = this.dateProvider.now();
177
+ const expiredTxs = Array.from(this.missingTxs.entries()).filter(([_, value]) => +value.deadline < now);
178
+ expiredTxs.forEach(([txHash]) => this.missingTxs.delete(txHash));
179
+
180
+ // Gather all txs that are marked for fast collection, we do not want to collect them via slow collection.
181
+ // There are some situations where a tx is in both slow and fast collection, for example when a prover node
182
+ // is fast-collecting missing txs for proving an epoch, and still has the tx in the slow collection loops
183
+ // from mined unproven blocks it has seen in the past.
184
+ const fastRequests = this.fastCollection.getFastCollectionRequests();
185
+ const fastCollectionTxs: Set<string> = new Set(
186
+ ...Array.from(fastRequests.values()).flatMap(r => r.missingTxHashes),
187
+ );
188
+
189
+ // Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
190
+ return Array.from(this.missingTxs.entries())
191
+ .filter(([txHash, _]) => !fastCollectionTxs.has(txHash))
192
+ .filter(([_, value]) => !opts.onlyReqRespReady || value.readyForReqResp);
193
+ }
194
+
195
+ /** Stop collecting the given txs since we have found them. Called whenever tx pool emits a tx-added event. */
196
+ public foundTxs(txs: Tx[]): void {
197
+ for (const txHash of txs.map(tx => tx.txHash)) {
198
+ this.missingTxs.delete(txHash.toString());
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Stop collecting all txs for blocks less than or requal to the block number specified.
204
+ * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
205
+ */
206
+ public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
207
+ for (const [txHash, info] of this.missingTxs.entries()) {
208
+ if (info.blockNumber <= blockNumber) {
209
+ this.missingTxs.delete(txHash);
210
+ }
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Stop collecting all txs for blocks greater than the block number specified.
216
+ * To be called when there is a chain prune and previously mined txs are no longer relevant.
217
+ */
218
+ public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
219
+ for (const [txHash, info] of this.missingTxs.entries()) {
220
+ if (info.blockNumber > blockNumber) {
221
+ this.missingTxs.delete(txHash);
222
+ }
223
+ }
224
+ }
225
+
226
+ /** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
227
+ private getDeadlineForSlot(slotNumber: SlotNumber): Date {
228
+ const epoch = getEpochAtSlot(slotNumber, this.constants);
229
+ const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
230
+ const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
231
+ return new Date(Number(submissionEndTimestamp) * 1000);
232
+ }
233
+ }
@@ -0,0 +1,216 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { compactArray } from '@aztec/foundation/collection';
3
+ import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
5
+ import { DateProvider } from '@aztec/foundation/timer';
6
+ import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
7
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
8
+ import type { BlockProposal } from '@aztec/stdlib/p2p';
9
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
10
+ import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
11
+
12
+ import type { PeerId } from '@libp2p/interface';
13
+
14
+ import type { TxPool } from '../../mem_pools/index.js';
15
+ import type { TxPoolEvents } from '../../mem_pools/tx_pool/tx_pool.js';
16
+ import type { ReqRespInterface } from '../reqresp/interface.js';
17
+ import type { TxCollectionConfig } from './config.js';
18
+ import { FastTxCollection } from './fast_tx_collection.js';
19
+ import { SlowTxCollection } from './slow_tx_collection.js';
20
+ import { TxCollectionSink } from './tx_collection_sink.js';
21
+ import type { TxSource } from './tx_source.js';
22
+
23
+ export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-resp' | 'slow-node-rpc';
24
+
25
+ export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
26
+
27
+ export type FastCollectionRequestInput =
28
+ | { type: 'block'; block: L2BlockNew }
29
+ | { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
30
+
31
+ export type FastCollectionRequest = FastCollectionRequestInput & {
32
+ missingTxHashes: Set<string>;
33
+ deadline: Date;
34
+ blockInfo: L2BlockInfo;
35
+ promise: PromiseWithResolvers<void>;
36
+ foundTxs: Map<string, Tx>;
37
+ };
38
+
39
+ /**
40
+ * Coordinates tx collection from remote RPC nodes and reqresp.
41
+ *
42
+ * The slow collection loops are used for periodically collecting missing txs from mined blocks,
43
+ * from remote RPC nodes and via reqresp. The fast collection methods are used to quickly gather
44
+ * txs, usually for attesting to block proposals or preparing to prove an epoch. The slow and fast
45
+ * collection instances both send their txs to the collection sink, which handles metrics and adds
46
+ * them to the tx pool. Whenever a tx is added to either the sink or the pool, this service is notified
47
+ * via events and notifies the slow and fast collection loops to stop collecting that tx, so that we don't
48
+ * collect the same tx multiple times.
49
+ */
50
+ export class TxCollection {
51
+ /** Slow collection background loops */
52
+ protected readonly slowCollection: SlowTxCollection;
53
+
54
+ /** Fast collection methods */
55
+ protected readonly fastCollection: FastTxCollection;
56
+
57
+ /** Loop for periodically reconciling found transactions from the tx pool in case we missed some */
58
+ private readonly reconcileFoundTxsLoop: RunningPromise;
59
+
60
+ /** Handles txs found by the slow and fast collection loops */
61
+ private readonly txCollectionSink: TxCollectionSink;
62
+
63
+ /** Handler for the txs-added event from the tx pool */
64
+ protected readonly handleTxsAddedToPool: TxPoolEvents['txs-added'];
65
+
66
+ /** Handler for the txs-added event from the tx collection sink */
67
+ protected readonly handleTxsFound: TxPoolEvents['txs-added'];
68
+
69
+ constructor(
70
+ private readonly reqResp: Pick<ReqRespInterface, 'sendBatchRequest'>,
71
+ private readonly nodes: TxSource[],
72
+ private readonly constants: L1RollupConstants,
73
+ private readonly txPool: TxPool,
74
+ private readonly config: TxCollectionConfig,
75
+ private readonly dateProvider: DateProvider = new DateProvider(),
76
+ telemetryClient: TelemetryClient = getTelemetryClient(),
77
+ private readonly log: Logger = createLogger('p2p:tx_collection_service'),
78
+ ) {
79
+ this.txCollectionSink = new TxCollectionSink(this.txPool, telemetryClient, this.log);
80
+
81
+ this.fastCollection = new FastTxCollection(
82
+ this.reqResp,
83
+ this.nodes,
84
+ this.txCollectionSink,
85
+ this.config,
86
+ this.dateProvider,
87
+ this.log,
88
+ );
89
+
90
+ this.slowCollection = new SlowTxCollection(
91
+ this.reqResp,
92
+ this.nodes,
93
+ this.txCollectionSink,
94
+ this.fastCollection,
95
+ constants,
96
+ this.config,
97
+ this.dateProvider,
98
+ this.log,
99
+ );
100
+
101
+ this.reconcileFoundTxsLoop = new RunningPromise(
102
+ () => this.reconcileFoundTxsWithPool(),
103
+ this.log,
104
+ this.config.txCollectionReconcileIntervalMs,
105
+ );
106
+
107
+ this.handleTxsFound = (args: Parameters<TxPoolEvents['txs-added']>[0]) => {
108
+ this.foundTxs(args.txs);
109
+ };
110
+ this.txCollectionSink.on('txs-added', this.handleTxsFound);
111
+
112
+ this.handleTxsAddedToPool = (args: Parameters<TxPoolEvents['txs-added']>[0]) => {
113
+ const { txs, source } = args;
114
+ if (source !== 'tx-collection') {
115
+ this.foundTxs(txs);
116
+ }
117
+ };
118
+ this.txPool.on('txs-added', this.handleTxsAddedToPool);
119
+ }
120
+
121
+ /** Starts all collection loops. */
122
+ public start(): Promise<void> {
123
+ this.slowCollection.start();
124
+ this.reconcileFoundTxsLoop.start();
125
+
126
+ // TODO(palla/txs): Collect mined unproven tx hashes for txs we dont have in the pool and populate missingTxs on startup
127
+ return Promise.resolve();
128
+ }
129
+
130
+ /** Stops all activity. */
131
+ public async stop() {
132
+ await Promise.all([this.slowCollection.stop(), this.fastCollection.stop(), this.reconcileFoundTxsLoop.stop()]);
133
+
134
+ this.txPool.removeListener('txs-added', this.handleTxsAddedToPool);
135
+ this.txCollectionSink.removeListener('txs-added', this.handleTxsFound);
136
+ }
137
+
138
+ /** Force trigger the slow collection and reconciliation loops */
139
+ public async trigger() {
140
+ await Promise.all([this.reconcileFoundTxsLoop.trigger(), this.slowCollection.trigger()]);
141
+ }
142
+
143
+ /** Returns L1 rollup constants. */
144
+ public getConstants(): L1RollupConstants {
145
+ return this.constants;
146
+ }
147
+
148
+ /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
149
+ public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
150
+ return this.slowCollection.startCollecting(block, txHashes);
151
+ }
152
+
153
+ /** Collects the set of txs for the given block proposal as fast as possible */
154
+ public collectFastForProposal(
155
+ blockProposal: BlockProposal,
156
+ blockNumber: BlockNumber,
157
+ txHashes: TxHash[] | string[],
158
+ opts: { deadline: Date; pinnedPeer?: PeerId },
159
+ ) {
160
+ return this.collectFastFor({ type: 'proposal', blockProposal, blockNumber }, txHashes, opts);
161
+ }
162
+
163
+ /** Collects the set of txs for the given mined block as fast as possible */
164
+ public collectFastForBlock(
165
+ block: L2BlockNew,
166
+ txHashes: TxHash[] | string[],
167
+ opts: { deadline: Date; pinnedPeer?: PeerId },
168
+ ) {
169
+ return this.collectFastFor({ type: 'block', block }, txHashes, opts);
170
+ }
171
+
172
+ /** Collects the set of txs for the given proposal or block as fast as possible */
173
+ public collectFastFor(
174
+ input: FastCollectionRequestInput,
175
+ txHashes: TxHash[] | string[],
176
+ opts: { deadline: Date; pinnedPeer?: PeerId },
177
+ ) {
178
+ return this.fastCollection.collectFastFor(input, txHashes, opts);
179
+ }
180
+
181
+ /** Mark the given txs as found. Stops collecting them. */
182
+ private foundTxs(txs: Tx[]) {
183
+ this.slowCollection.foundTxs(txs);
184
+ this.fastCollection.foundTxs(txs);
185
+ }
186
+
187
+ /**
188
+ * Stop collecting all txs for blocks less than or requal to the block number specified.
189
+ * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
190
+ */
191
+ public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
192
+ this.slowCollection.stopCollectingForBlocksUpTo(blockNumber);
193
+ this.fastCollection.stopCollectingForBlocksUpTo(blockNumber);
194
+ }
195
+
196
+ /**
197
+ * Stop collecting all txs for blocks greater than the block number specified.
198
+ * To be called when there is a chain prune and previously mined txs are no longer relevant.
199
+ */
200
+ public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
201
+ this.slowCollection.stopCollectingForBlocksAfter(blockNumber);
202
+ this.fastCollection.stopCollectingForBlocksAfter(blockNumber);
203
+ }
204
+
205
+ /** Every now and then, check if the pool has received one of the txs we are looking for, just to catch any race conditions */
206
+ private async reconcileFoundTxsWithPool() {
207
+ const missingTxHashes = this.slowCollection.getMissingTxHashes();
208
+ const foundTxs = compactArray(await this.txPool.getTxsByHash(missingTxHashes));
209
+ if (foundTxs.length > 0) {
210
+ this.log.verbose(`Found ${foundTxs.length} txs in the pool during reconciliation`, {
211
+ foundTxs: foundTxs.map(t => t.getTxHash().toString()),
212
+ });
213
+ this.foundTxs(foundTxs);
214
+ }
215
+ }
216
+ }
@@ -0,0 +1,129 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { elapsed } from '@aztec/foundation/timer';
3
+ import type { TypedEventEmitter } from '@aztec/foundation/types';
4
+ import { Tx, type TxHash } from '@aztec/stdlib/tx';
5
+ import type { TelemetryClient } from '@aztec/telemetry-client';
6
+
7
+ import EventEmitter from 'node:events';
8
+
9
+ import type { TxPool, TxPoolEvents } from '../../mem_pools/tx_pool/tx_pool.js';
10
+ import { TxCollectionInstrumentation } from './instrumentation.js';
11
+ import type { CollectionMethod } from './tx_collection.js';
12
+
13
+ /**
14
+ * Executes collection requests from the fast and slow collection loops, and handles collected txs
15
+ * by adding them to the tx pool and emitting events, as well as handling logging and metrics.
16
+ */
17
+ export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitter<TxPoolEvents>) {
18
+ private readonly instrumentation: TxCollectionInstrumentation;
19
+
20
+ constructor(
21
+ private readonly txPool: TxPool,
22
+ telemetryClient: TelemetryClient,
23
+ private readonly log: Logger,
24
+ ) {
25
+ super();
26
+ this.instrumentation = new TxCollectionInstrumentation(telemetryClient, 'TxCollection');
27
+ }
28
+
29
+ public async collect(
30
+ collectValidTxsFn: (txHashes: TxHash[]) => Promise<(Tx | undefined)[]>,
31
+ requested: TxHash[],
32
+ info: Record<string, any> & { description: string; method: CollectionMethod },
33
+ ) {
34
+ this.log.trace(`Requesting ${requested.length} txs via ${info.description}`, {
35
+ ...info,
36
+ requestedTxs: requested.map(t => t.toString()),
37
+ });
38
+
39
+ // Execute collection function and measure the time taken, catching any errors.
40
+ const [duration, txs] = await elapsed(async () => {
41
+ try {
42
+ const response = await collectValidTxsFn(requested);
43
+ return response.filter(tx => tx !== undefined);
44
+ } catch (err) {
45
+ this.log.error(`Error collecting txs via ${info.description}`, err, {
46
+ ...info,
47
+ requestedTxs: requested.map(hash => hash.toString()),
48
+ });
49
+ return [] as Tx[];
50
+ }
51
+ });
52
+
53
+ if (txs.length === 0) {
54
+ this.log.trace(`No txs found via ${info.description}`, {
55
+ ...info,
56
+ requestedTxs: requested.map(t => t.toString()),
57
+ });
58
+ return { txs, requested, duration };
59
+ }
60
+
61
+ // Validate tx hashes for all collected txs from external sources
62
+ const validTxs: Tx[] = [];
63
+ const invalidTxHashes: string[] = [];
64
+ await Promise.all(
65
+ txs.map(async tx => {
66
+ const isValid = await tx.validateTxHash();
67
+ if (isValid) {
68
+ validTxs.push(tx);
69
+ } else {
70
+ invalidTxHashes.push(tx.getTxHash().toString());
71
+ }
72
+ }),
73
+ );
74
+
75
+ if (invalidTxHashes.length > 0) {
76
+ this.log.warn(`Rejecting ${invalidTxHashes.length} txs with invalid hashes from ${info.description}`, {
77
+ ...info,
78
+ invalidTxHashes,
79
+ });
80
+ }
81
+
82
+ if (validTxs.length === 0) {
83
+ this.log.trace(`No valid txs found via ${info.description} after validation`, {
84
+ ...info,
85
+ requestedTxs: requested.map(t => t.toString()),
86
+ invalidTxHashes,
87
+ });
88
+ return { txs: [], requested, duration };
89
+ }
90
+
91
+ this.log.verbose(
92
+ `Collected ${validTxs.length} txs out of ${requested.length} requested via ${info.description} in ${duration}ms`,
93
+ {
94
+ ...info,
95
+ duration,
96
+ txs: validTxs.map(t => t.getTxHash().toString()),
97
+ requestedTxs: requested.map(t => t.toString()),
98
+ rejectedCount: invalidTxHashes.length,
99
+ },
100
+ );
101
+
102
+ return await this.foundTxs(validTxs, { ...info, duration });
103
+ }
104
+
105
+ private async foundTxs(
106
+ txs: Tx[],
107
+ info: Record<string, any> & { description: string; method: CollectionMethod; duration: number },
108
+ ) {
109
+ // Report metrics for the collection
110
+ this.instrumentation.increaseTxsFor(info.method, txs.length, info.duration);
111
+
112
+ // Mark txs as found in the slow missing txs set and all fast requests
113
+ this.emit('txs-added', { txs });
114
+
115
+ // Add the txs to the tx pool (should not fail, but we catch it just in case)
116
+ try {
117
+ await this.txPool.addTxs(txs, { source: `tx-collection` });
118
+ } catch (err) {
119
+ this.log.error(`Error adding txs to the pool via ${info.description}`, err, {
120
+ ...info,
121
+ txs: txs.map(tx => tx.txHash.toString()),
122
+ });
123
+ // Return no txs since none have been added
124
+ return { txs: [] };
125
+ }
126
+
127
+ return { txs };
128
+ }
129
+ }
@@ -0,0 +1,37 @@
1
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
2
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
3
+ import type { ChainConfig } from '@aztec/stdlib/config';
4
+ import { type AztecNode, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
5
+ import type { Tx, TxHash } from '@aztec/stdlib/tx';
6
+ import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
7
+ import { makeTracedFetch } from '@aztec/telemetry-client';
8
+
9
+ export interface TxSource {
10
+ getInfo(): string;
11
+ getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
12
+ }
13
+
14
+ export class NodeRpcTxSource implements TxSource {
15
+ constructor(
16
+ private readonly client: Pick<AztecNode, 'getTxsByHash'>,
17
+ private readonly info: string,
18
+ ) {}
19
+
20
+ public static fromUrl(nodeUrl: string, versions: ComponentsVersions): NodeRpcTxSource {
21
+ const client = createAztecNodeClient(nodeUrl, versions, makeTracedFetch([1, 2, 3], false));
22
+ return new NodeRpcTxSource(client, nodeUrl);
23
+ }
24
+
25
+ public getInfo() {
26
+ return this.info;
27
+ }
28
+
29
+ public getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
30
+ return this.client.getTxsByHash(txHashes);
31
+ }
32
+ }
33
+
34
+ export function createNodeRpcTxSources(urls: string[], chainConfig: ChainConfig) {
35
+ const versions = getComponentsVersionsFromConfig(chainConfig, protocolContractsHash, getVKTreeRoot());
36
+ return urls.map(url => NodeRpcTxSource.fromUrl(url, versions));
37
+ }