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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  2. package/dest/bootstrap/bootstrap.js +22 -9
  3. package/dest/client/factory.d.ts +13 -3
  4. package/dest/client/factory.d.ts.map +1 -1
  5. package/dest/client/factory.js +60 -24
  6. package/dest/client/index.d.ts +1 -0
  7. package/dest/client/index.d.ts.map +1 -1
  8. package/dest/client/index.js +1 -0
  9. package/dest/client/interface.d.ts +155 -0
  10. package/dest/client/interface.d.ts.map +1 -0
  11. package/dest/client/interface.js +9 -0
  12. package/dest/client/p2p_client.d.ts +72 -169
  13. package/dest/client/p2p_client.d.ts.map +1 -1
  14. package/dest/client/p2p_client.js +365 -174
  15. package/dest/config.d.ts +123 -103
  16. package/dest/config.d.ts.map +1 -1
  17. package/dest/config.js +173 -34
  18. package/dest/enr/generate-enr.d.ts +10 -2
  19. package/dest/enr/generate-enr.d.ts.map +1 -1
  20. package/dest/enr/generate-enr.js +27 -5
  21. package/dest/index.d.ts +3 -0
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +2 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
  25. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +204 -54
  28. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
  29. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
  31. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
  32. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
  35. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/mocks.js +9 -15
  37. package/dest/mem_pools/instrumentation.d.ts +7 -11
  38. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.js +25 -37
  40. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
  41. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
  43. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
  44. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
  46. package/dest/mem_pools/tx_pool/priority.js +1 -1
  47. package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
  48. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
  51. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
  52. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  53. package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
  54. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -1
  55. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
  56. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +61 -12
  57. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  58. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  59. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  60. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  61. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  62. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  63. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  64. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  65. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  66. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  68. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  70. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
  71. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  73. package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
  74. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  75. package/dest/msg_validators/tx_validator/factory.js +74 -0
  76. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  77. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  78. package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
  79. package/dest/msg_validators/tx_validator/index.d.ts +7 -0
  80. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/index.js +7 -0
  82. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +7 -3
  83. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  85. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  86. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/phases_validator.js +91 -0
  88. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  89. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  90. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  91. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
  92. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  93. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  94. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  95. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  96. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  97. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  98. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  99. package/dest/services/discv5/discV5_service.d.ts +9 -8
  100. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  101. package/dest/services/discv5/discV5_service.js +63 -36
  102. package/dest/services/dummy_service.d.ts +49 -10
  103. package/dest/services/dummy_service.d.ts.map +1 -1
  104. package/dest/services/dummy_service.js +88 -5
  105. package/dest/services/encoding.d.ts +25 -6
  106. package/dest/services/encoding.d.ts.map +1 -1
  107. package/dest/services/encoding.js +73 -5
  108. package/dest/services/index.d.ts +4 -0
  109. package/dest/services/index.d.ts.map +1 -1
  110. package/dest/services/index.js +4 -0
  111. package/dest/services/libp2p/instrumentation.d.ts +18 -0
  112. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  113. package/dest/services/libp2p/instrumentation.js +157 -0
  114. package/dest/services/libp2p/libp2p_service.d.ts +87 -42
  115. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  116. package/dest/services/libp2p/libp2p_service.js +500 -218
  117. package/dest/services/peer-manager/interface.d.ts +23 -0
  118. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  119. package/dest/services/peer-manager/interface.js +1 -0
  120. package/dest/services/peer-manager/metrics.d.ts +3 -1
  121. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  122. package/dest/services/peer-manager/metrics.js +11 -2
  123. package/dest/services/peer-manager/peer_manager.d.ts +126 -15
  124. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  125. package/dest/services/peer-manager/peer_manager.js +547 -72
  126. package/dest/services/reqresp/config.d.ts +10 -8
  127. package/dest/services/reqresp/config.d.ts.map +1 -1
  128. package/dest/services/reqresp/config.js +18 -4
  129. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
  130. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  131. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  132. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +30 -13
  133. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  134. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  135. package/dest/services/reqresp/index.d.ts +2 -1
  136. package/dest/services/reqresp/index.d.ts.map +1 -1
  137. package/dest/services/reqresp/index.js +2 -1
  138. package/dest/services/reqresp/interface.d.ts +72 -23
  139. package/dest/services/reqresp/interface.d.ts.map +1 -1
  140. package/dest/services/reqresp/interface.js +45 -26
  141. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  142. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  143. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  144. package/dest/services/reqresp/protocols/auth.js +71 -0
  145. package/dest/services/reqresp/protocols/block.d.ts +5 -0
  146. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  147. package/dest/services/reqresp/protocols/block.js +28 -5
  148. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  149. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  150. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  151. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  152. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  153. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  154. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
  155. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  156. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  157. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  158. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  159. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  160. package/dest/services/reqresp/protocols/goodbye.d.ts +2 -4
  161. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  162. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  163. package/dest/services/reqresp/protocols/index.d.ts +2 -0
  164. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  165. package/dest/services/reqresp/protocols/index.js +2 -0
  166. package/dest/services/reqresp/protocols/ping.d.ts +0 -2
  167. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  168. package/dest/services/reqresp/protocols/status.d.ts +38 -6
  169. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  170. package/dest/services/reqresp/protocols/status.js +72 -5
  171. package/dest/services/reqresp/protocols/tx.d.ts +12 -1
  172. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  173. package/dest/services/reqresp/protocols/tx.js +34 -6
  174. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +4 -2
  175. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  176. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  177. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  178. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  179. package/dest/services/reqresp/reqresp.d.ts +45 -47
  180. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  181. package/dest/services/reqresp/reqresp.js +298 -207
  182. package/dest/services/reqresp/status.d.ts +9 -3
  183. package/dest/services/reqresp/status.d.ts.map +1 -1
  184. package/dest/services/reqresp/status.js +9 -2
  185. package/dest/services/service.d.ts +22 -18
  186. package/dest/services/service.d.ts.map +1 -1
  187. package/dest/services/tx_collection/config.d.ts +25 -0
  188. package/dest/services/tx_collection/config.d.ts.map +1 -0
  189. package/dest/services/tx_collection/config.js +58 -0
  190. package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
  191. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  192. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  193. package/dest/services/tx_collection/index.d.ts +3 -0
  194. package/dest/services/tx_collection/index.d.ts.map +1 -0
  195. package/dest/services/tx_collection/index.js +2 -0
  196. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  197. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  198. package/dest/services/tx_collection/instrumentation.js +34 -0
  199. package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
  200. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  201. package/dest/services/tx_collection/slow_tx_collection.js +176 -0
  202. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  203. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  204. package/dest/services/tx_collection/tx_collection.js +128 -0
  205. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  206. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  207. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  208. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  209. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  210. package/dest/services/tx_collection/tx_source.js +31 -0
  211. package/dest/services/tx_provider.d.ts +49 -0
  212. package/dest/services/tx_provider.d.ts.map +1 -0
  213. package/dest/services/tx_provider.js +210 -0
  214. package/dest/services/tx_provider_instrumentation.d.ts +13 -0
  215. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  216. package/dest/services/tx_provider_instrumentation.js +34 -0
  217. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  218. package/dest/test-helpers/index.d.ts +1 -0
  219. package/dest/test-helpers/index.d.ts.map +1 -1
  220. package/dest/test-helpers/index.js +1 -0
  221. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  222. package/dest/test-helpers/make-enrs.js +4 -5
  223. package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
  224. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  225. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  226. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  227. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  228. package/dest/test-helpers/mock-pubsub.js +130 -0
  229. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  230. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  231. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  232. package/dest/test-helpers/reqresp-nodes.d.ts +14 -10
  233. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  234. package/dest/test-helpers/reqresp-nodes.js +62 -28
  235. package/dest/testbench/p2p_client_testbench_worker.js +96 -25
  236. package/dest/testbench/parse_log_file.js +4 -4
  237. package/dest/testbench/testbench.js +4 -4
  238. package/dest/testbench/worker_client_manager.d.ts +0 -5
  239. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  240. package/dest/testbench/worker_client_manager.js +11 -19
  241. package/dest/types/index.d.ts +3 -1
  242. package/dest/types/index.d.ts.map +1 -1
  243. package/dest/types/index.js +2 -0
  244. package/dest/util.d.ts +22 -15
  245. package/dest/util.d.ts.map +1 -1
  246. package/dest/util.js +64 -67
  247. package/dest/versioning.d.ts +3 -3
  248. package/dest/versioning.d.ts.map +1 -1
  249. package/dest/versioning.js +8 -3
  250. package/package.json +28 -24
  251. package/src/bootstrap/bootstrap.ts +27 -11
  252. package/src/client/factory.ts +136 -45
  253. package/src/client/index.ts +1 -0
  254. package/src/client/interface.ts +195 -0
  255. package/src/client/p2p_client.ts +460 -327
  256. package/src/config.ts +288 -134
  257. package/src/enr/generate-enr.ts +39 -6
  258. package/src/index.ts +4 -0
  259. package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
  260. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
  261. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
  262. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
  263. package/src/mem_pools/attestation_pool/mocks.ts +11 -10
  264. package/src/mem_pools/instrumentation.ts +32 -46
  265. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
  266. package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
  267. package/src/mem_pools/tx_pool/priority.ts +1 -1
  268. package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
  269. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
  270. package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
  271. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -14
  272. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  273. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  274. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  275. package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
  276. package/src/msg_validators/tx_validator/data_validator.ts +81 -69
  277. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  278. package/src/msg_validators/tx_validator/factory.ts +109 -0
  279. package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
  280. package/src/msg_validators/tx_validator/index.ts +7 -0
  281. package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
  282. package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
  283. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  284. package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
  285. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  286. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  287. package/src/services/discv5/discV5_service.ts +84 -38
  288. package/src/services/dummy_service.ts +147 -9
  289. package/src/services/encoding.ts +80 -5
  290. package/src/services/index.ts +4 -0
  291. package/src/services/libp2p/instrumentation.ts +158 -0
  292. package/src/services/libp2p/libp2p_service.ts +646 -263
  293. package/src/services/peer-manager/interface.ts +29 -0
  294. package/src/services/peer-manager/metrics.ts +16 -1
  295. package/src/services/peer-manager/peer_manager.ts +652 -78
  296. package/src/services/reqresp/config.ts +26 -9
  297. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  298. package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
  299. package/src/services/reqresp/index.ts +2 -0
  300. package/src/services/reqresp/interface.ts +91 -36
  301. package/src/services/reqresp/metrics.ts +4 -1
  302. package/src/services/reqresp/protocols/auth.ts +83 -0
  303. package/src/services/reqresp/protocols/block.ts +24 -3
  304. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  305. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  306. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  307. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  308. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  309. package/src/services/reqresp/protocols/index.ts +2 -0
  310. package/src/services/reqresp/protocols/status.ts +117 -5
  311. package/src/services/reqresp/protocols/tx.ts +35 -6
  312. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  313. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  314. package/src/services/reqresp/reqresp.ts +387 -256
  315. package/src/services/reqresp/status.ts +12 -3
  316. package/src/services/service.ts +45 -21
  317. package/src/services/tx_collection/config.ts +84 -0
  318. package/src/services/tx_collection/fast_tx_collection.ts +340 -0
  319. package/src/services/tx_collection/index.ts +2 -0
  320. package/src/services/tx_collection/instrumentation.ts +43 -0
  321. package/src/services/tx_collection/slow_tx_collection.ts +232 -0
  322. package/src/services/tx_collection/tx_collection.ts +215 -0
  323. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  324. package/src/services/tx_collection/tx_source.ts +37 -0
  325. package/src/services/tx_provider.ts +216 -0
  326. package/src/services/tx_provider_instrumentation.ts +44 -0
  327. package/src/test-helpers/index.ts +1 -0
  328. package/src/test-helpers/make-enrs.ts +4 -5
  329. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  330. package/src/test-helpers/mock-pubsub.ts +188 -0
  331. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  332. package/src/test-helpers/reqresp-nodes.ts +86 -35
  333. package/src/testbench/p2p_client_testbench_worker.ts +145 -22
  334. package/src/testbench/parse_log_file.ts +4 -4
  335. package/src/testbench/testbench.ts +4 -4
  336. package/src/testbench/worker_client_manager.ts +17 -23
  337. package/src/types/index.ts +2 -0
  338. package/src/util.ts +93 -89
  339. package/src/versioning.ts +11 -4
@@ -1,13 +1,14 @@
1
1
  import { emptyChainConfig } from '@aztec/stdlib/config';
2
- import { ENR, SignableENR } from '@chainsafe/enr';
3
2
  import { multiaddr } from '@multiformats/multiaddr';
4
- import { AZTEC_ENR_KEY } from '../types/index.js';
3
+ import { ENR, SignableENR } from '@nethermindeth/enr';
4
+ import { AZTEC_ENR_CLIENT_VERSION_KEY, AZTEC_ENR_KEY } from '../types/index.js';
5
5
  import { convertToMultiaddr, createLibP2PPeerIdFromPrivateKey } from '../util.js';
6
- import { setAztecEnrKey } from '../versioning.js';
7
- export async function createBootnodeENRandPeerId(privateKey, udpAnnounceAddress, l1ChainId) {
6
+ import { setAztecClientVersionEnrKey, setAztecEnrKey } from '../versioning.js';
7
+ export { ENR };
8
+ export async function createBootnodeENRandPeerId(privateKey, p2pIp, p2pBroadcastPort, l1ChainId) {
8
9
  const peerId = await createLibP2PPeerIdFromPrivateKey(privateKey);
9
10
  const enr = SignableENR.createFromPeerId(peerId);
10
- const publicAddr = multiaddr(convertToMultiaddr(udpAnnounceAddress, 'udp'));
11
+ const publicAddr = multiaddr(convertToMultiaddr(p2pIp, p2pBroadcastPort, 'udp'));
11
12
  enr.setLocationMultiaddr(publicAddr);
12
13
  const config = {
13
14
  ...emptyChainConfig,
@@ -19,6 +20,25 @@ export async function createBootnodeENRandPeerId(privateKey, udpAnnounceAddress,
19
20
  peerId
20
21
  };
21
22
  }
23
+ export function createNodeENR(peerId, multiAddrUdp, multiAddrTcp, chainConfig, packageVersion) {
24
+ // create ENR from PeerId
25
+ const enr = SignableENR.createFromPeerId(peerId);
26
+ // Add aztec identification to ENR
27
+ const versions = setAztecEnrKey(enr, chainConfig);
28
+ // Add aztec client version to ENR
29
+ setAztecClientVersionEnrKey(enr, packageVersion);
30
+ // set location multiaddr in ENR record
31
+ if (multiAddrUdp) {
32
+ enr.setLocationMultiaddr(multiAddrUdp);
33
+ }
34
+ if (multiAddrTcp) {
35
+ enr.setLocationMultiaddr(multiAddrTcp);
36
+ }
37
+ return {
38
+ enr,
39
+ versions
40
+ };
41
+ }
22
42
  export async function printENR(enr, log) {
23
43
  const decoded = ENR.decodeTxt(enr);
24
44
  log(`PeerID: ${await decoded.peerId()}`);
@@ -27,4 +47,6 @@ export async function printENR(enr, log) {
27
47
  log(`TCP: ${decoded.tcp}`);
28
48
  const aztec = decoded.kvs.get(AZTEC_ENR_KEY);
29
49
  log(`Aztec version: ${aztec?.toString()}`);
50
+ const aztecClientVersion = decoded.kvs.get(AZTEC_ENR_CLIENT_VERSION_KEY);
51
+ log(`Aztec client version ${aztecClientVersion ? aztecClientVersion.toString() : 'N/A'}`);
30
52
  }
package/dest/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ export { createSecp256k1PeerId } from '@libp2p/peer-id-factory';
2
+ export type { PeerId } from '@libp2p/interface';
1
3
  export * from './bootstrap/bootstrap.js';
2
4
  export * from './client/index.js';
5
+ export * from './enr/index.js';
3
6
  export * from './config.js';
4
7
  export * from './mem_pools/attestation_pool/index.js';
5
8
  export * from './mem_pools/tx_pool/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC"}
package/dest/index.js CHANGED
@@ -1,5 +1,7 @@
1
+ export { createSecp256k1PeerId } from '@libp2p/peer-id-factory';
1
2
  export * from './bootstrap/bootstrap.js';
2
3
  export * from './client/index.js';
4
+ export * from './enr/index.js';
3
5
  export * from './config.js';
4
6
  export * from './mem_pools/attestation_pool/index.js';
5
7
  export * from './mem_pools/tx_pool/index.js';
@@ -1,4 +1,4 @@
1
- import type { BlockAttestation } from '@aztec/stdlib/p2p';
1
+ import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
2
2
  /**
3
3
  * An Attestation Pool contains attestations collected by a validator
4
4
  *
@@ -7,7 +7,27 @@ import type { BlockAttestation } from '@aztec/stdlib/p2p';
7
7
  */
8
8
  export interface AttestationPool {
9
9
  /**
10
- * AddAttestation
10
+ * Adds new block proposal to the pool
11
+ */
12
+ addBlockProposal(blockProposal: BlockProposal): Promise<void>;
13
+ /**
14
+ * Get block proposal by it's ID
15
+ *
16
+ * @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
17
+ *
18
+ * @return The block proposal if it exists, otherwise undefined.
19
+ */
20
+ getBlockProposal(id: string): Promise<BlockProposal | undefined>;
21
+ /**
22
+ * Check if a block proposal exists in the pool
23
+ *
24
+ * @param idOrProposal - The ID of the block proposal or the block proposal itself to check. The ID is proposal.payload.archive
25
+ *
26
+ * @return True if the block proposal exists, false otherwise.
27
+ */
28
+ hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
29
+ /**
30
+ * AddAttestations
11
31
  *
12
32
  * @param attestations - Attestations to add into the pool
13
33
  */
@@ -44,7 +64,16 @@ export interface AttestationPool {
44
64
  */
45
65
  deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
46
66
  /**
47
- * Get Attestations for slot
67
+ * Get all Attestations for all proposals for a given slot
68
+ *
69
+ * Retrieve all of the attestations observed pertaining to a given slot
70
+ *
71
+ * @param slot - The slot to query
72
+ * @return BlockAttestations
73
+ */
74
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
75
+ /**
76
+ * Get Attestations for slot and given proposal
48
77
  *
49
78
  * Retrieve all of the attestations observed pertaining to a given slot
50
79
  *
@@ -52,6 +81,15 @@ export interface AttestationPool {
52
81
  * @param proposalId - The proposal to query
53
82
  * @return BlockAttestations
54
83
  */
55
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
84
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
85
+ /**
86
+ * Check if a specific attestation exists in the pool
87
+ *
88
+ * @param attestation - The attestation to check
89
+ * @return True if the attestation exists, false otherwise
90
+ */
91
+ hasAttestation(attestation: BlockAttestation): Promise<boolean>;
92
+ /** Returns whether the pool is empty. */
93
+ isEmpty(): Promise<boolean>;
56
94
  }
57
95
  //# sourceMappingURL=attestation_pool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;;;OAMG;IACH,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;;;;;OAMG;IACH,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvD;;;;;;;OAOG;IACH,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtF;;;;;;;;OAQG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CACvF"}
1
+ {"version":3,"file":"attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAEjE;;;;;;OAMG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzE;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;;;OAMG;IACH,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;;;;;OAMG;IACH,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvD;;;;;;;OAOG;IACH,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtF;;;;;;;OAOG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAElE;;;;;;;;OAQG;IACH,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAEjG;;;;;OAKG;IACH,cAAc,CAAC,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhE,yCAAyC;IACzC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"attestation_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool_test_suite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAgB,uBAAuB,CAAC,kBAAkB,EAAE,MAAM,eAAe,QAuNhF"}
1
+ {"version":3,"file":"attestation_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool_test_suite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAgB,uBAAuB,CAAC,kBAAkB,EAAE,MAAM,eAAe,QA0YhF"}
@@ -1,5 +1,7 @@
1
1
  import { Secp256k1Signer } from '@aztec/foundation/crypto';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
+ import { BlockProposal as BlockProposalClass, ConsensusPayload, SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from '@aztec/stdlib/p2p';
4
+ import { makeL2BlockHeader } from '@aztec/stdlib/testing';
3
5
  import { TxHash } from '@aztec/stdlib/tx';
4
6
  import { jest } from '@jest/globals';
5
7
  import { mock } from 'jest-mock-extended';
@@ -21,7 +23,18 @@ export function describeAttestationPool(getAttestationPool) {
21
23
  });
22
24
  const createAttestationsForSlot = (slotNumber)=>{
23
25
  const archive = Fr.random();
24
- return Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
26
+ return signers.map((signer)=>mockAttestation(signer, slotNumber, archive));
27
+ };
28
+ const mockBlockProposal = (signer, slotNumber, archive = Fr.random())=>{
29
+ const header = makeL2BlockHeader(1, 2, slotNumber);
30
+ const payload = new ConsensusPayload(header.toCheckpointHeader(), archive, header.state);
31
+ const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
32
+ const signature = signer.sign(hash);
33
+ const txHashes = [
34
+ TxHash.random(),
35
+ TxHash.random()
36
+ ]; // Mock tx hashes
37
+ return new BlockProposalClass(payload, signature, txHashes);
25
38
  };
26
39
  // We compare buffers as the objects can have cached values attached to them which are not serialised
27
40
  // using array containing as the kv store does not respect insertion order
@@ -34,62 +47,86 @@ export function describeAttestationPool(getAttestationPool) {
34
47
  it('should add attestations to pool', async ()=>{
35
48
  const slotNumber = 420;
36
49
  const archive = Fr.random();
37
- const attestations = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
50
+ const attestations = signers.slice(0, -1).map((signer)=>mockAttestation(signer, slotNumber, archive));
38
51
  await ap.addAttestations(attestations);
39
- // Check metrics have been updated.
40
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
41
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
42
- expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
43
- compareAttestations(retreivedAttestations, attestations);
52
+ const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
53
+ expect(retrievedAttestations.length).toBe(attestations.length);
54
+ compareAttestations(retrievedAttestations, attestations);
55
+ // Check hasAttestation for added attestations
56
+ for (const attestation of attestations){
57
+ expect(await ap.hasAttestation(attestation)).toBe(true);
58
+ }
59
+ const retrievedAttestationsForSlot = await ap.getAttestationsForSlot(BigInt(slotNumber));
60
+ expect(retrievedAttestationsForSlot.length).toBe(attestations.length);
61
+ compareAttestations(retrievedAttestationsForSlot, attestations);
62
+ // Add another one
63
+ const newAttestation = mockAttestation(signers[NUMBER_OF_SIGNERS_PER_TEST - 1], slotNumber, archive);
64
+ await ap.addAttestations([
65
+ newAttestation
66
+ ]);
67
+ const retrievedAttestationsAfterAdd = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
68
+ expect(retrievedAttestationsAfterAdd.length).toBe(attestations.length + 1);
69
+ compareAttestations(retrievedAttestationsAfterAdd, [
70
+ ...attestations,
71
+ newAttestation
72
+ ]);
73
+ expect(await ap.hasAttestation(newAttestation)).toBe(true);
74
+ const retrievedAttestationsForSlotAfterAdd = await ap.getAttestationsForSlot(BigInt(slotNumber));
75
+ expect(retrievedAttestationsForSlotAfterAdd.length).toBe(attestations.length + 1);
76
+ compareAttestations(retrievedAttestationsForSlotAfterAdd, [
77
+ ...attestations,
78
+ newAttestation
79
+ ]);
44
80
  // Delete by slot
45
81
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
46
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
47
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
82
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
48
83
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
84
+ // Check hasAttestation after deletion
85
+ for (const attestation of attestations){
86
+ expect(await ap.hasAttestation(attestation)).toBe(false);
87
+ }
88
+ expect(await ap.hasAttestation(newAttestation)).toBe(false);
49
89
  });
50
- it('Should handle duplicate proposals in a slot', async ()=>{
90
+ it('should handle duplicate proposals in a slot', async ()=>{
51
91
  const slotNumber = 420;
52
92
  const archive = Fr.random();
53
- const txs = [
54
- 0,
55
- 1,
56
- 2,
57
- 3,
58
- 4,
59
- 5
60
- ].map(()=>TxHash.random());
61
93
  // Use the same signer for all attestations
62
94
  const attestations = [];
63
95
  const signer = signers[0];
64
96
  for(let i = 0; i < NUMBER_OF_SIGNERS_PER_TEST; i++){
65
- attestations.push(await mockAttestation(signer, slotNumber, archive, txs));
97
+ attestations.push(mockAttestation(signer, slotNumber, archive));
66
98
  }
99
+ // Add them to store and check we end up with only one
67
100
  await ap.addAttestations(attestations);
68
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
101
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
69
102
  expect(retreivedAttestations.length).toBe(1);
70
103
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestations[0].toBuffer());
71
- expect(retreivedAttestations[0].payload.txHashes).toEqual(txs);
72
- expect((await retreivedAttestations[0].getSender()).toString()).toEqual(signer.address.toString());
104
+ expect(retreivedAttestations[0].getSender()?.toString()).toEqual(signer.address.toString());
105
+ // Try adding them on another operation and check they are still not duplicated
106
+ await ap.addAttestations([
107
+ attestations[0]
108
+ ]);
109
+ expect(await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString())).toHaveLength(1);
73
110
  });
74
- it('Should store attestations by differing slot', async ()=>{
111
+ it('should store attestations by differing slot', async ()=>{
75
112
  const slotNumbers = [
76
113
  1,
77
114
  2,
78
115
  3,
79
116
  4
80
117
  ];
81
- const attestations = await Promise.all(signers.map((signer, i)=>mockAttestation(signer, slotNumbers[i])));
118
+ const attestations = signers.map((signer, i)=>mockAttestation(signer, slotNumbers[i]));
82
119
  await ap.addAttestations(attestations);
83
120
  for (const attestation of attestations){
84
- const slot = attestation.payload.header.globalVariables.slotNumber;
121
+ const slot = attestation.payload.header.slotNumber;
85
122
  const archive = attestation.archive.toString();
86
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), archive);
123
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), archive);
87
124
  expect(retreivedAttestations.length).toBe(1);
88
125
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
89
- expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
126
+ expect(retreivedAttestations[0].payload.header.slotNumber).toEqual(slot);
90
127
  }
91
128
  });
92
- it('Should store attestations by differing slot and archive', async ()=>{
129
+ it('should store attestations by differing slot and archive', async ()=>{
93
130
  const slotNumbers = [
94
131
  1,
95
132
  1,
@@ -102,70 +139,73 @@ export function describeAttestationPool(getAttestationPool) {
102
139
  Fr.random(),
103
140
  Fr.random()
104
141
  ];
105
- const attestations = await Promise.all(signers.map((signer, i)=>mockAttestation(signer, slotNumbers[i], archives[i])));
142
+ const attestations = signers.map((signer, i)=>mockAttestation(signer, slotNumbers[i], archives[i]));
106
143
  await ap.addAttestations(attestations);
107
144
  for (const attestation of attestations){
108
- const slot = attestation.payload.header.globalVariables.slotNumber;
145
+ const slot = attestation.payload.header.slotNumber;
109
146
  const proposalId = attestation.archive.toString();
110
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), proposalId);
147
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), proposalId);
111
148
  expect(retreivedAttestations.length).toBe(1);
112
149
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
113
- expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
150
+ expect(retreivedAttestations[0].payload.header.slotNumber).toEqual(slot);
114
151
  }
115
152
  });
116
- it('Should delete attestations', async ()=>{
153
+ it('should delete attestations', async ()=>{
117
154
  const slotNumber = 420;
118
155
  const archive = Fr.random();
119
- const attestations = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
156
+ const attestations = signers.map((signer)=>mockAttestation(signer, slotNumber, archive));
120
157
  const proposalId = attestations[0].archive.toString();
121
158
  await ap.addAttestations(attestations);
122
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
123
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
159
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
124
160
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
125
161
  compareAttestations(retreivedAttestations, attestations);
162
+ // Check hasAttestation before deletion
163
+ for (const attestation of attestations){
164
+ expect(await ap.hasAttestation(attestation)).toBe(true);
165
+ }
126
166
  await ap.deleteAttestations(attestations);
127
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
128
- const gottenAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
167
+ const gottenAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
129
168
  expect(gottenAfterDelete.length).toBe(0);
169
+ // Check hasAttestation after deletion
170
+ for (const attestation of attestations){
171
+ expect(await ap.hasAttestation(attestation)).toBe(false);
172
+ }
130
173
  });
131
- it('Should blanket delete attestations per slot', async ()=>{
174
+ it('should blanket delete attestations per slot', async ()=>{
132
175
  const slotNumber = 420;
133
176
  const archive = Fr.random();
134
- const attestations = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
177
+ const attestations = signers.map((signer)=>mockAttestation(signer, slotNumber, archive));
135
178
  const proposalId = attestations[0].archive.toString();
136
179
  await ap.addAttestations(attestations);
137
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
180
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
138
181
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
139
182
  compareAttestations(retreivedAttestations, attestations);
140
183
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
141
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
184
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
142
185
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
143
186
  });
144
- it('Should blanket delete attestations per slot and proposal', async ()=>{
187
+ it('should blanket delete attestations per slot and proposal', async ()=>{
145
188
  const slotNumber = 420;
146
189
  const archive = Fr.random();
147
- const attestations = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
190
+ const attestations = signers.map((signer)=>mockAttestation(signer, slotNumber, archive));
148
191
  const proposalId = attestations[0].archive.toString();
149
192
  // Add another set of attestations with a different proposalId, yet the same slot
150
193
  const archive2 = Fr.random();
151
- const attestations2 = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive2)));
194
+ const attestations2 = signers.map((signer)=>mockAttestation(signer, slotNumber, archive2));
152
195
  const proposalId2 = attestations2[0].archive.toString();
153
196
  await ap.addAttestations(attestations);
154
197
  await ap.addAttestations(attestations2);
155
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
156
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations2.length);
157
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
198
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
158
199
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
159
200
  compareAttestations(retreivedAttestations, attestations);
160
201
  await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
161
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
162
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
202
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
163
203
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
164
- const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId2);
204
+ const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId2);
165
205
  expect(retreivedAttestationsAfterDeleteForOtherProposal.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
166
206
  compareAttestations(retreivedAttestationsAfterDeleteForOtherProposal, attestations2);
167
207
  });
168
- it('Should delete attestations older than a given slot', async ()=>{
208
+ it('should delete attestations older than a given slot', async ()=>{
169
209
  const slotNumbers = [
170
210
  1,
171
211
  2,
@@ -179,11 +219,11 @@ export function describeAttestationPool(getAttestationPool) {
179
219
  const attestations = (await Promise.all(slotNumbers.map((slotNumber)=>createAttestationsForSlot(slotNumber)))).flat();
180
220
  const proposalId = attestations[0].archive.toString();
181
221
  await ap.addAttestations(attestations);
182
- const attestationsForSlot1 = await ap.getAttestationsForSlot(BigInt(1), proposalId);
222
+ const attestationsForSlot1 = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
183
223
  expect(attestationsForSlot1.length).toBe(signers.length);
184
224
  const deleteAttestationsSpy = jest.spyOn(ap, 'deleteAttestationsForSlot');
185
225
  await ap.deleteAttestationsOlderThan(BigInt(73));
186
- const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlot(BigInt(1), proposalId);
226
+ const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
187
227
  expect(attestationsForSlot1AfterDelete.length).toBe(0);
188
228
  expect(deleteAttestationsSpy).toHaveBeenCalledTimes(5);
189
229
  expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(1));
@@ -192,4 +232,114 @@ export function describeAttestationPool(getAttestationPool) {
192
232
  expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(69));
193
233
  expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(72));
194
234
  });
235
+ describe('BlockProposal in attestation pool', ()=>{
236
+ it('should add and retrieve block proposal', async ()=>{
237
+ const slotNumber = 420;
238
+ const archive = Fr.random();
239
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
240
+ const proposalId = proposal.archive.toString();
241
+ await ap.addBlockProposal(proposal);
242
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
243
+ expect(retrievedProposal).toBeDefined();
244
+ expect(retrievedProposal).toEqual(proposal);
245
+ // Check hasBlockProposal with both id and object
246
+ expect(await ap.hasBlockProposal(proposalId)).toBe(true);
247
+ expect(await ap.hasBlockProposal(proposal)).toBe(true);
248
+ });
249
+ it('should return undefined for non-existent block proposal', async ()=>{
250
+ const nonExistentId = Fr.random().toString();
251
+ const retrievedProposal = await ap.getBlockProposal(nonExistentId);
252
+ expect(retrievedProposal).toBeUndefined();
253
+ // Check hasBlockProposal returns false for non-existent proposal
254
+ expect(await ap.hasBlockProposal(nonExistentId)).toBe(false);
255
+ });
256
+ it('should update block proposal if added twice with same id', async ()=>{
257
+ const slotNumber = 420;
258
+ const archive = Fr.random();
259
+ const proposal1 = mockBlockProposal(signers[0], slotNumber, archive);
260
+ const proposalId = proposal1.archive.toString();
261
+ await ap.addBlockProposal(proposal1);
262
+ // Create a new proposal with same archive but different signer
263
+ const proposal2 = mockBlockProposal(signers[1], slotNumber, archive);
264
+ await ap.addBlockProposal(proposal2);
265
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
266
+ expect(retrievedProposal).toBeDefined();
267
+ // Should have the second proposal
268
+ expect(retrievedProposal.toBuffer()).toEqual(proposal2.toBuffer());
269
+ expect(retrievedProposal.getSender()?.toString()).toBe(signers[1].address.toString());
270
+ });
271
+ it('should handle block proposals with different slots and same archive', async ()=>{
272
+ const archive = Fr.random();
273
+ const proposal1 = mockBlockProposal(signers[0], 100, archive);
274
+ const proposal2 = mockBlockProposal(signers[1], 200, archive);
275
+ const proposalId = archive.toString();
276
+ await ap.addBlockProposal(proposal1);
277
+ await ap.addBlockProposal(proposal2);
278
+ // Should get the latest one added
279
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
280
+ expect(retrievedProposal).toBeDefined();
281
+ expect(retrievedProposal.toBuffer()).toEqual(proposal2.toBuffer());
282
+ expect(retrievedProposal.slotNumber.toBigInt()).toBe(BigInt(200));
283
+ });
284
+ it('should delete block proposal when deleting attestations for slot and proposal', async ()=>{
285
+ const slotNumber = 420;
286
+ const archive = Fr.random();
287
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
288
+ const proposalId = proposal.archive.toString();
289
+ // Add proposal and some attestations
290
+ await ap.addBlockProposal(proposal);
291
+ const attestations = signers.map((signer)=>mockAttestation(signer, slotNumber, archive));
292
+ await ap.addAttestations(attestations);
293
+ // Verify proposal exists
294
+ let retrievedProposal = await ap.getBlockProposal(proposalId);
295
+ expect(retrievedProposal).toBeDefined();
296
+ expect(await ap.hasBlockProposal(proposalId)).toBe(true);
297
+ // Delete attestations for slot and proposal
298
+ await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
299
+ // Proposal should be deleted
300
+ retrievedProposal = await ap.getBlockProposal(proposalId);
301
+ expect(retrievedProposal).toBeUndefined();
302
+ expect(await ap.hasBlockProposal(proposalId)).toBe(false);
303
+ });
304
+ it('should delete block proposal when deleting attestations for slot', async ()=>{
305
+ const slotNumber = 420;
306
+ const archive = Fr.random();
307
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
308
+ const proposalId = proposal.archive.toString();
309
+ // Add proposal
310
+ await ap.addBlockProposal(proposal);
311
+ // Verify proposal exists
312
+ let retrievedProposal = await ap.getBlockProposal(proposalId);
313
+ expect(retrievedProposal).toBeDefined();
314
+ expect(await ap.hasBlockProposal(proposal)).toBe(true);
315
+ // Delete attestations for slot
316
+ await ap.deleteAttestationsForSlot(BigInt(slotNumber));
317
+ // Proposal should be deleted
318
+ retrievedProposal = await ap.getBlockProposal(proposalId);
319
+ expect(retrievedProposal).toBeUndefined();
320
+ expect(await ap.hasBlockProposal(proposal)).toBe(false);
321
+ });
322
+ it('should be able to fetch both block proposal and attestations', async ()=>{
323
+ const slotNumber = 420;
324
+ const archive = Fr.random();
325
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
326
+ const proposalId = proposal.archive.toString();
327
+ // Add proposal first
328
+ await ap.addBlockProposal(proposal);
329
+ // Add attestations for the same proposal
330
+ const attestations = signers.slice(1).map((signer)=>mockAttestation(signer, slotNumber, archive));
331
+ await ap.addAttestations(attestations);
332
+ // Retrieve both proposal and attestations
333
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
334
+ const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
335
+ expect(retrievedProposal).toBeDefined();
336
+ expect(retrievedProposal).toEqual(proposal);
337
+ expect(await ap.hasBlockProposal(proposalId)).toBe(true);
338
+ compareAttestations(retrievedAttestations, attestations);
339
+ // Check hasAttestation for all attestations
340
+ for (const attestation of attestations){
341
+ expect(await ap.hasAttestation(attestation)).toBe(true);
342
+ }
343
+ });
344
+ });
195
345
  }
@@ -1,5 +1,5 @@
1
1
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
- import { BlockAttestation } from '@aztec/stdlib/p2p';
2
+ import { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
3
3
  import { type TelemetryClient } from '@aztec/telemetry-client';
4
4
  import type { AttestationPool } from './attestation_pool.js';
5
5
  export declare class KvAttestationPool implements AttestationPool {
@@ -7,16 +7,24 @@ export declare class KvAttestationPool implements AttestationPool {
7
7
  private log;
8
8
  private metrics;
9
9
  private attestations;
10
+ private proposals;
10
11
  private proposalsForSlot;
11
12
  private attestationsForProposal;
12
13
  constructor(store: AztecAsyncKVStore, telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
14
+ private poolStats;
15
+ isEmpty(): Promise<boolean>;
13
16
  private getProposalKey;
14
17
  private getAttestationKey;
15
18
  addAttestations(attestations: BlockAttestation[]): Promise<void>;
16
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
19
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
20
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
17
21
  deleteAttestationsOlderThan(oldestSlot: bigint): Promise<void>;
18
22
  deleteAttestationsForSlot(slot: bigint): Promise<void>;
19
23
  deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
20
24
  deleteAttestations(attestations: BlockAttestation[]): Promise<void>;
25
+ hasAttestation(attestation: BlockAttestation): Promise<boolean>;
26
+ getBlockProposal(id: string): Promise<BlockProposal | undefined>;
27
+ hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
28
+ addBlockProposal(blockProposal: BlockProposal): Promise<void>;
21
29
  }
22
30
  //# sourceMappingURL=kv_attestation_pool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kv_attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/kv_attestation_pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAGnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,qBAAa,iBAAkB,YAAW,eAAe;IAQrD,OAAO,CAAC,KAAK;IAEb,OAAO,CAAC,GAAG;IATb,OAAO,CAAC,OAAO,CAAwC;IAEvD,OAAO,CAAC,YAAY,CAAgC;IACpD,OAAO,CAAC,gBAAgB,CAAqC;IAC7D,OAAO,CAAC,uBAAuB,CAAqC;gBAG1D,KAAK,EAAE,iBAAiB,EAChC,SAAS,GAAE,eAAsC,EACzC,GAAG,yCAAyC;IAStD,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,iBAAiB;IAIZ,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhE,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAsBrF,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9D,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBtD,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrF,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBjF"}
1
+ {"version":3,"file":"kv_attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/kv_attestation_pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAGnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,qBAAa,iBAAkB,YAAW,eAAe;IAYrD,OAAO,CAAC,KAAK;IAEb,OAAO,CAAC,GAAG;IAbb,OAAO,CAAC,OAAO,CAAwC;IAEvD,OAAO,CAAC,YAAY,CAAgC;IACpD,OAAO,CAAC,SAAS,CAGf;IACF,OAAO,CAAC,gBAAgB,CAAqC;IAC7D,OAAO,CAAC,uBAAuB,CAAqC;gBAG1D,KAAK,EAAE,iBAAiB,EAChC,SAAS,GAAE,eAAsC,EACzC,GAAG,yCAAyC;IAUtD,OAAO,CAAC,SAAS,CAIf;IAEW,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAOxC,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,iBAAiB;IAIZ,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqChE,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAYjE,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAsBhG,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9D,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBtD,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrF,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BnE,cAAc,CAAC,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB/D,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAahE,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxE,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAM3E"}