@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,4 +1,4 @@
1
- import type { BlockAttestation } from '@aztec/stdlib/p2p';
1
+ import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
2
2
 
3
3
  /**
4
4
  * An Attestation Pool contains attestations collected by a validator
@@ -8,7 +8,30 @@ import type { BlockAttestation } from '@aztec/stdlib/p2p';
8
8
  */
9
9
  export interface AttestationPool {
10
10
  /**
11
- * AddAttestation
11
+ * Adds new block proposal to the pool
12
+ */
13
+ addBlockProposal(blockProposal: BlockProposal): Promise<void>;
14
+
15
+ /**
16
+ * Get block proposal by it's ID
17
+ *
18
+ * @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
19
+ *
20
+ * @return The block proposal if it exists, otherwise undefined.
21
+ */
22
+ getBlockProposal(id: string): Promise<BlockProposal | undefined>;
23
+
24
+ /**
25
+ * Check if a block proposal exists in the pool
26
+ *
27
+ * @param idOrProposal - The ID of the block proposal or the block proposal itself to check. The ID is proposal.payload.archive
28
+ *
29
+ * @return True if the block proposal exists, false otherwise.
30
+ */
31
+ hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
32
+
33
+ /**
34
+ * AddAttestations
12
35
  *
13
36
  * @param attestations - Attestations to add into the pool
14
37
  */
@@ -50,7 +73,17 @@ export interface AttestationPool {
50
73
  deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
51
74
 
52
75
  /**
53
- * Get Attestations for slot
76
+ * Get all Attestations for all proposals for a given slot
77
+ *
78
+ * Retrieve all of the attestations observed pertaining to a given slot
79
+ *
80
+ * @param slot - The slot to query
81
+ * @return BlockAttestations
82
+ */
83
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
84
+
85
+ /**
86
+ * Get Attestations for slot and given proposal
54
87
  *
55
88
  * Retrieve all of the attestations observed pertaining to a given slot
56
89
  *
@@ -58,5 +91,16 @@ export interface AttestationPool {
58
91
  * @param proposalId - The proposal to query
59
92
  * @return BlockAttestations
60
93
  */
61
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
94
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
95
+
96
+ /**
97
+ * Check if a specific attestation exists in the pool
98
+ *
99
+ * @param attestation - The attestation to check
100
+ * @return True if the attestation exists, false otherwise
101
+ */
102
+ hasAttestation(attestation: BlockAttestation): Promise<boolean>;
103
+
104
+ /** Returns whether the pool is empty. */
105
+ isEmpty(): Promise<boolean>;
62
106
  }
@@ -1,6 +1,13 @@
1
1
  import { Secp256k1Signer } from '@aztec/foundation/crypto';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
- import type { BlockAttestation } from '@aztec/stdlib/p2p';
3
+ import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
4
+ import {
5
+ BlockProposal as BlockProposalClass,
6
+ ConsensusPayload,
7
+ SignatureDomainSeparator,
8
+ getHashedSignaturePayloadEthSignedMessage,
9
+ } from '@aztec/stdlib/p2p';
10
+ import { makeL2BlockHeader } from '@aztec/stdlib/testing';
4
11
  import { TxHash } from '@aztec/stdlib/tx';
5
12
 
6
13
  import { jest } from '@jest/globals';
@@ -30,7 +37,19 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
30
37
 
31
38
  const createAttestationsForSlot = (slotNumber: number) => {
32
39
  const archive = Fr.random();
33
- return Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
40
+ return signers.map(signer => mockAttestation(signer, slotNumber, archive));
41
+ };
42
+
43
+ const mockBlockProposal = (signer: Secp256k1Signer, slotNumber: number, archive: Fr = Fr.random()): BlockProposal => {
44
+ const header = makeL2BlockHeader(1, 2, slotNumber);
45
+ const payload = new ConsensusPayload(header.toCheckpointHeader(), archive, header.state);
46
+
47
+ const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
48
+ const signature = signer.sign(hash);
49
+
50
+ const txHashes = [TxHash.random(), TxHash.random()]; // Mock tx hashes
51
+
52
+ return new BlockProposalClass(payload, signature, txHashes);
34
53
  };
35
54
 
36
55
  // We compare buffers as the objects can have cached values attached to them which are not serialised
@@ -45,155 +64,181 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
45
64
  it('should add attestations to pool', async () => {
46
65
  const slotNumber = 420;
47
66
  const archive = Fr.random();
48
- const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
67
+ const attestations = signers.slice(0, -1).map(signer => mockAttestation(signer, slotNumber, archive));
49
68
 
50
69
  await ap.addAttestations(attestations);
51
70
 
52
- // Check metrics have been updated.
53
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
71
+ const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
72
+ expect(retrievedAttestations.length).toBe(attestations.length);
73
+ compareAttestations(retrievedAttestations, attestations);
54
74
 
55
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
75
+ // Check hasAttestation for added attestations
76
+ for (const attestation of attestations) {
77
+ expect(await ap.hasAttestation(attestation)).toBe(true);
78
+ }
56
79
 
57
- expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
80
+ const retrievedAttestationsForSlot = await ap.getAttestationsForSlot(BigInt(slotNumber));
81
+ expect(retrievedAttestationsForSlot.length).toBe(attestations.length);
82
+ compareAttestations(retrievedAttestationsForSlot, attestations);
58
83
 
59
- compareAttestations(retreivedAttestations, attestations);
84
+ // Add another one
85
+ const newAttestation = mockAttestation(signers[NUMBER_OF_SIGNERS_PER_TEST - 1], slotNumber, archive);
86
+ await ap.addAttestations([newAttestation]);
87
+ const retrievedAttestationsAfterAdd = await ap.getAttestationsForSlotAndProposal(
88
+ BigInt(slotNumber),
89
+ archive.toString(),
90
+ );
91
+ expect(retrievedAttestationsAfterAdd.length).toBe(attestations.length + 1);
92
+ compareAttestations(retrievedAttestationsAfterAdd, [...attestations, newAttestation]);
93
+ expect(await ap.hasAttestation(newAttestation)).toBe(true);
94
+ const retrievedAttestationsForSlotAfterAdd = await ap.getAttestationsForSlot(BigInt(slotNumber));
95
+ expect(retrievedAttestationsForSlotAfterAdd.length).toBe(attestations.length + 1);
96
+ compareAttestations(retrievedAttestationsForSlotAfterAdd, [...attestations, newAttestation]);
60
97
 
61
98
  // Delete by slot
62
99
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
63
100
 
64
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
65
-
66
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
101
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(
102
+ BigInt(slotNumber),
103
+ archive.toString(),
104
+ );
67
105
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
106
+ // Check hasAttestation after deletion
107
+ for (const attestation of attestations) {
108
+ expect(await ap.hasAttestation(attestation)).toBe(false);
109
+ }
110
+ expect(await ap.hasAttestation(newAttestation)).toBe(false);
68
111
  });
69
112
 
70
- it('Should handle duplicate proposals in a slot', async () => {
113
+ it('should handle duplicate proposals in a slot', async () => {
71
114
  const slotNumber = 420;
72
115
  const archive = Fr.random();
73
- const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
74
116
 
75
117
  // Use the same signer for all attestations
76
118
  const attestations: BlockAttestation[] = [];
77
119
  const signer = signers[0];
78
120
  for (let i = 0; i < NUMBER_OF_SIGNERS_PER_TEST; i++) {
79
- attestations.push(await mockAttestation(signer, slotNumber, archive, txs));
121
+ attestations.push(mockAttestation(signer, slotNumber, archive));
80
122
  }
81
123
 
124
+ // Add them to store and check we end up with only one
82
125
  await ap.addAttestations(attestations);
83
126
 
84
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
127
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
85
128
  expect(retreivedAttestations.length).toBe(1);
86
129
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestations[0].toBuffer());
87
- expect(retreivedAttestations[0].payload.txHashes).toEqual(txs);
88
- expect((await retreivedAttestations[0].getSender()).toString()).toEqual(signer.address.toString());
130
+ expect(retreivedAttestations[0].getSender()?.toString()).toEqual(signer.address.toString());
131
+
132
+ // Try adding them on another operation and check they are still not duplicated
133
+ await ap.addAttestations([attestations[0]]);
134
+ expect(await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString())).toHaveLength(1);
89
135
  });
90
136
 
91
- it('Should store attestations by differing slot', async () => {
137
+ it('should store attestations by differing slot', async () => {
92
138
  const slotNumbers = [1, 2, 3, 4];
93
- const attestations = await Promise.all(signers.map((signer, i) => mockAttestation(signer, slotNumbers[i])));
139
+ const attestations = signers.map((signer, i) => mockAttestation(signer, slotNumbers[i]));
94
140
 
95
141
  await ap.addAttestations(attestations);
96
142
 
97
143
  for (const attestation of attestations) {
98
- const slot = attestation.payload.header.globalVariables.slotNumber;
144
+ const slot = attestation.payload.header.slotNumber;
99
145
  const archive = attestation.archive.toString();
100
146
 
101
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), archive);
147
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), archive);
102
148
  expect(retreivedAttestations.length).toBe(1);
103
149
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
104
- expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
150
+ expect(retreivedAttestations[0].payload.header.slotNumber).toEqual(slot);
105
151
  }
106
152
  });
107
153
 
108
- it('Should store attestations by differing slot and archive', async () => {
154
+ it('should store attestations by differing slot and archive', async () => {
109
155
  const slotNumbers = [1, 1, 2, 3];
110
156
  const archives = [Fr.random(), Fr.random(), Fr.random(), Fr.random()];
111
- const attestations = await Promise.all(
112
- signers.map((signer, i) => mockAttestation(signer, slotNumbers[i], archives[i])),
113
- );
157
+ const attestations = signers.map((signer, i) => mockAttestation(signer, slotNumbers[i], archives[i]));
114
158
 
115
159
  await ap.addAttestations(attestations);
116
160
 
117
161
  for (const attestation of attestations) {
118
- const slot = attestation.payload.header.globalVariables.slotNumber;
162
+ const slot = attestation.payload.header.slotNumber;
119
163
  const proposalId = attestation.archive.toString();
120
164
 
121
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), proposalId);
165
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), proposalId);
122
166
  expect(retreivedAttestations.length).toBe(1);
123
167
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
124
- expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
168
+ expect(retreivedAttestations[0].payload.header.slotNumber).toEqual(slot);
125
169
  }
126
170
  });
127
171
 
128
- it('Should delete attestations', async () => {
172
+ it('should delete attestations', async () => {
129
173
  const slotNumber = 420;
130
174
  const archive = Fr.random();
131
- const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
175
+ const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
132
176
  const proposalId = attestations[0].archive.toString();
133
177
 
134
178
  await ap.addAttestations(attestations);
135
179
 
136
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
137
-
138
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
180
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
139
181
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
140
182
  compareAttestations(retreivedAttestations, attestations);
141
183
 
142
- await ap.deleteAttestations(attestations);
184
+ // Check hasAttestation before deletion
185
+ for (const attestation of attestations) {
186
+ expect(await ap.hasAttestation(attestation)).toBe(true);
187
+ }
143
188
 
144
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
189
+ await ap.deleteAttestations(attestations);
145
190
 
146
- const gottenAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
191
+ const gottenAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
147
192
  expect(gottenAfterDelete.length).toBe(0);
193
+
194
+ // Check hasAttestation after deletion
195
+ for (const attestation of attestations) {
196
+ expect(await ap.hasAttestation(attestation)).toBe(false);
197
+ }
148
198
  });
149
199
 
150
- it('Should blanket delete attestations per slot', async () => {
200
+ it('should blanket delete attestations per slot', async () => {
151
201
  const slotNumber = 420;
152
202
  const archive = Fr.random();
153
- const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
203
+ const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
154
204
  const proposalId = attestations[0].archive.toString();
155
205
 
156
206
  await ap.addAttestations(attestations);
157
207
 
158
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
208
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
159
209
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
160
210
  compareAttestations(retreivedAttestations, attestations);
161
211
 
162
212
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
163
213
 
164
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
214
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
165
215
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
166
216
  });
167
217
 
168
- it('Should blanket delete attestations per slot and proposal', async () => {
218
+ it('should blanket delete attestations per slot and proposal', async () => {
169
219
  const slotNumber = 420;
170
220
  const archive = Fr.random();
171
- const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
221
+ const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
172
222
  const proposalId = attestations[0].archive.toString();
173
223
 
174
224
  // Add another set of attestations with a different proposalId, yet the same slot
175
225
  const archive2 = Fr.random();
176
- const attestations2 = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive2)));
226
+ const attestations2 = signers.map(signer => mockAttestation(signer, slotNumber, archive2));
177
227
  const proposalId2 = attestations2[0].archive.toString();
178
228
 
179
229
  await ap.addAttestations(attestations);
180
230
  await ap.addAttestations(attestations2);
181
231
 
182
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
183
- expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations2.length);
184
-
185
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
232
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
186
233
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
187
234
  compareAttestations(retreivedAttestations, attestations);
188
235
 
189
236
  await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
190
237
 
191
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
192
-
193
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
238
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
194
239
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
195
240
 
196
- const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlot(
241
+ const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlotAndProposal(
197
242
  BigInt(slotNumber),
198
243
  proposalId2,
199
244
  );
@@ -201,7 +246,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
201
246
  compareAttestations(retreivedAttestationsAfterDeleteForOtherProposal, attestations2);
202
247
  });
203
248
 
204
- it('Should delete attestations older than a given slot', async () => {
249
+ it('should delete attestations older than a given slot', async () => {
205
250
  const slotNumbers = [1, 2, 3, 69, 72, 74, 88, 420];
206
251
  const attestations = (
207
252
  await Promise.all(slotNumbers.map(slotNumber => createAttestationsForSlot(slotNumber)))
@@ -210,14 +255,14 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
210
255
 
211
256
  await ap.addAttestations(attestations);
212
257
 
213
- const attestationsForSlot1 = await ap.getAttestationsForSlot(BigInt(1), proposalId);
258
+ const attestationsForSlot1 = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
214
259
  expect(attestationsForSlot1.length).toBe(signers.length);
215
260
 
216
261
  const deleteAttestationsSpy = jest.spyOn(ap, 'deleteAttestationsForSlot');
217
262
 
218
263
  await ap.deleteAttestationsOlderThan(BigInt(73));
219
264
 
220
- const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlot(BigInt(1), proposalId);
265
+ const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
221
266
  expect(attestationsForSlot1AfterDelete.length).toBe(0);
222
267
 
223
268
  expect(deleteAttestationsSpy).toHaveBeenCalledTimes(5);
@@ -227,4 +272,145 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
227
272
  expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(69));
228
273
  expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(72));
229
274
  });
275
+
276
+ describe('BlockProposal in attestation pool', () => {
277
+ it('should add and retrieve block proposal', async () => {
278
+ const slotNumber = 420;
279
+ const archive = Fr.random();
280
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
281
+ const proposalId = proposal.archive.toString();
282
+
283
+ await ap.addBlockProposal(proposal);
284
+
285
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
286
+
287
+ expect(retrievedProposal).toBeDefined();
288
+ expect(retrievedProposal!).toEqual(proposal);
289
+
290
+ // Check hasBlockProposal with both id and object
291
+ expect(await ap.hasBlockProposal(proposalId)).toBe(true);
292
+ expect(await ap.hasBlockProposal(proposal)).toBe(true);
293
+ });
294
+
295
+ it('should return undefined for non-existent block proposal', async () => {
296
+ const nonExistentId = Fr.random().toString();
297
+ const retrievedProposal = await ap.getBlockProposal(nonExistentId);
298
+ expect(retrievedProposal).toBeUndefined();
299
+
300
+ // Check hasBlockProposal returns false for non-existent proposal
301
+ expect(await ap.hasBlockProposal(nonExistentId)).toBe(false);
302
+ });
303
+
304
+ it('should update block proposal if added twice with same id', async () => {
305
+ const slotNumber = 420;
306
+ const archive = Fr.random();
307
+ const proposal1 = mockBlockProposal(signers[0], slotNumber, archive);
308
+ const proposalId = proposal1.archive.toString();
309
+
310
+ await ap.addBlockProposal(proposal1);
311
+
312
+ // Create a new proposal with same archive but different signer
313
+ const proposal2 = mockBlockProposal(signers[1], slotNumber, archive);
314
+
315
+ await ap.addBlockProposal(proposal2);
316
+
317
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
318
+ expect(retrievedProposal).toBeDefined();
319
+ // Should have the second proposal
320
+ expect(retrievedProposal!.toBuffer()).toEqual(proposal2.toBuffer());
321
+ expect(retrievedProposal!.getSender()?.toString()).toBe(signers[1].address.toString());
322
+ });
323
+
324
+ it('should handle block proposals with different slots and same archive', async () => {
325
+ const archive = Fr.random();
326
+ const proposal1 = mockBlockProposal(signers[0], 100, archive);
327
+ const proposal2 = mockBlockProposal(signers[1], 200, archive);
328
+ const proposalId = archive.toString();
329
+
330
+ await ap.addBlockProposal(proposal1);
331
+ await ap.addBlockProposal(proposal2);
332
+
333
+ // Should get the latest one added
334
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
335
+ expect(retrievedProposal).toBeDefined();
336
+ expect(retrievedProposal!.toBuffer()).toEqual(proposal2.toBuffer());
337
+ expect(retrievedProposal!.slotNumber.toBigInt()).toBe(BigInt(200));
338
+ });
339
+
340
+ it('should delete block proposal when deleting attestations for slot and proposal', async () => {
341
+ const slotNumber = 420;
342
+ const archive = Fr.random();
343
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
344
+ const proposalId = proposal.archive.toString();
345
+
346
+ // Add proposal and some attestations
347
+ await ap.addBlockProposal(proposal);
348
+ const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
349
+ await ap.addAttestations(attestations);
350
+
351
+ // Verify proposal exists
352
+ let retrievedProposal = await ap.getBlockProposal(proposalId);
353
+ expect(retrievedProposal).toBeDefined();
354
+ expect(await ap.hasBlockProposal(proposalId)).toBe(true);
355
+
356
+ // Delete attestations for slot and proposal
357
+ await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
358
+
359
+ // Proposal should be deleted
360
+ retrievedProposal = await ap.getBlockProposal(proposalId);
361
+ expect(retrievedProposal).toBeUndefined();
362
+ expect(await ap.hasBlockProposal(proposalId)).toBe(false);
363
+ });
364
+
365
+ it('should delete block proposal when deleting attestations for slot', async () => {
366
+ const slotNumber = 420;
367
+ const archive = Fr.random();
368
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
369
+ const proposalId = proposal.archive.toString();
370
+
371
+ // Add proposal
372
+ await ap.addBlockProposal(proposal);
373
+
374
+ // Verify proposal exists
375
+ let retrievedProposal = await ap.getBlockProposal(proposalId);
376
+ expect(retrievedProposal).toBeDefined();
377
+ expect(await ap.hasBlockProposal(proposal)).toBe(true);
378
+
379
+ // Delete attestations for slot
380
+ await ap.deleteAttestationsForSlot(BigInt(slotNumber));
381
+
382
+ // Proposal should be deleted
383
+ retrievedProposal = await ap.getBlockProposal(proposalId);
384
+ expect(retrievedProposal).toBeUndefined();
385
+ expect(await ap.hasBlockProposal(proposal)).toBe(false);
386
+ });
387
+
388
+ it('should be able to fetch both block proposal and attestations', async () => {
389
+ const slotNumber = 420;
390
+ const archive = Fr.random();
391
+ const proposal = mockBlockProposal(signers[0], slotNumber, archive);
392
+ const proposalId = proposal.archive.toString();
393
+
394
+ // Add proposal first
395
+ await ap.addBlockProposal(proposal);
396
+
397
+ // Add attestations for the same proposal
398
+ const attestations = signers.slice(1).map(signer => mockAttestation(signer, slotNumber, archive));
399
+ await ap.addAttestations(attestations);
400
+
401
+ // Retrieve both proposal and attestations
402
+ const retrievedProposal = await ap.getBlockProposal(proposalId);
403
+ const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
404
+
405
+ expect(retrievedProposal).toBeDefined();
406
+ expect(retrievedProposal).toEqual(proposal);
407
+ expect(await ap.hasBlockProposal(proposalId)).toBe(true);
408
+
409
+ compareAttestations(retrievedAttestations, attestations);
410
+ // Check hasAttestation for all attestations
411
+ for (const attestation of attestations) {
412
+ expect(await ap.hasAttestation(attestation)).toBe(true);
413
+ }
414
+ });
415
+ });
230
416
  }