@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.0b941701

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 (463) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +1 -1
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +22 -9
  4. package/dest/client/factory.d.ts +15 -5
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +60 -25
  7. package/dest/client/index.d.ts +2 -1
  8. package/dest/client/index.d.ts.map +1 -1
  9. package/dest/client/index.js +1 -0
  10. package/dest/client/interface.d.ts +170 -0
  11. package/dest/client/interface.d.ts.map +1 -0
  12. package/dest/client/interface.js +9 -0
  13. package/dest/client/p2p_client.d.ts +75 -193
  14. package/dest/client/p2p_client.d.ts.map +1 -1
  15. package/dest/client/p2p_client.js +757 -228
  16. package/dest/config.d.ts +148 -125
  17. package/dest/config.d.ts.map +1 -1
  18. package/dest/config.js +180 -34
  19. package/dest/enr/generate-enr.d.ts +11 -3
  20. package/dest/enr/generate-enr.d.ts.map +1 -1
  21. package/dest/enr/generate-enr.js +27 -5
  22. package/dest/enr/index.d.ts +1 -1
  23. package/dest/errors/attestation-pool.error.d.ts +7 -0
  24. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  25. package/dest/errors/attestation-pool.error.js +12 -0
  26. package/dest/errors/reqresp.error.d.ts +1 -1
  27. package/dest/errors/reqresp.error.d.ts.map +1 -1
  28. package/dest/index.d.ts +4 -1
  29. package/dest/index.d.ts.map +1 -1
  30. package/dest/index.js +2 -0
  31. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -25
  32. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  34. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  35. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +299 -174
  36. package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
  37. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +29 -11
  38. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +168 -62
  40. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +24 -10
  41. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +133 -82
  43. package/dest/mem_pools/attestation_pool/mocks.d.ts +234 -11
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +19 -21
  46. package/dest/mem_pools/index.d.ts +1 -1
  47. package/dest/mem_pools/instrumentation.d.ts +16 -12
  48. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  49. package/dest/mem_pools/instrumentation.js +55 -40
  50. package/dest/mem_pools/interface.d.ts +3 -4
  51. package/dest/mem_pools/interface.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +75 -16
  53. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +493 -142
  55. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
  56. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  57. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
  58. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
  59. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  60. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
  61. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  62. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  63. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  64. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  65. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  66. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  67. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  68. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  69. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
  70. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  71. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  72. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  73. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  74. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  75. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  76. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  77. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  78. package/dest/mem_pools/tx_pool/index.js +0 -1
  79. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  80. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  81. package/dest/mem_pools/tx_pool/priority.js +7 -2
  82. package/dest/mem_pools/tx_pool/tx_pool.d.ts +72 -11
  83. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  84. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  85. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  86. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +276 -45
  87. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -5
  88. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/attestation_validator/attestation_validator.js +79 -10
  90. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
  91. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  92. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +71 -0
  93. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  94. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  95. package/dest/msg_validators/attestation_validator/index.js +1 -0
  96. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  97. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  98. package/dest/msg_validators/clock_tolerance.js +37 -0
  99. package/dest/msg_validators/index.d.ts +2 -2
  100. package/dest/msg_validators/index.d.ts.map +1 -1
  101. package/dest/msg_validators/index.js +1 -1
  102. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
  103. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
  104. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
  105. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  106. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  107. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  108. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  109. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  110. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  111. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  112. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  113. package/dest/msg_validators/proposal_validator/index.js +3 -0
  114. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  115. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  116. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  117. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  118. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  119. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  120. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
  121. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
  123. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
  124. package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
  125. package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
  126. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
  127. package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
  128. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  129. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  130. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
  131. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  132. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  133. package/dest/msg_validators/tx_validator/data_validator.js +56 -86
  134. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
  135. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  136. package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
  137. package/dest/msg_validators/tx_validator/factory.d.ts +16 -0
  138. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  139. package/dest/msg_validators/tx_validator/factory.js +74 -0
  140. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  141. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  142. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  143. package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
  144. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
  145. package/dest/msg_validators/tx_validator/gas_validator.js +109 -0
  146. package/dest/msg_validators/tx_validator/index.d.ts +9 -1
  147. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  148. package/dest/msg_validators/tx_validator/index.js +8 -0
  149. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +9 -5
  150. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  151. package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
  152. package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
  153. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
  154. package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
  155. package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
  156. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  157. package/dest/msg_validators/tx_validator/size_validator.js +20 -0
  158. package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
  159. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
  160. package/dest/msg_validators/tx_validator/test_utils.js +22 -0
  161. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
  162. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
  163. package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
  164. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
  165. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
  166. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
  167. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
  168. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  169. package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
  170. package/dest/services/data_store.d.ts +1 -1
  171. package/dest/services/data_store.d.ts.map +1 -1
  172. package/dest/services/discv5/discV5_service.d.ts +10 -9
  173. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  174. package/dest/services/discv5/discV5_service.js +63 -36
  175. package/dest/services/dummy_service.d.ts +54 -11
  176. package/dest/services/dummy_service.d.ts.map +1 -1
  177. package/dest/services/dummy_service.js +91 -5
  178. package/dest/services/encoding.d.ts +26 -7
  179. package/dest/services/encoding.d.ts.map +1 -1
  180. package/dest/services/encoding.js +75 -6
  181. package/dest/services/gossipsub/scoring.d.ts +1 -1
  182. package/dest/services/index.d.ts +5 -1
  183. package/dest/services/index.d.ts.map +1 -1
  184. package/dest/services/index.js +4 -0
  185. package/dest/services/libp2p/instrumentation.d.ts +20 -0
  186. package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
  187. package/dest/services/libp2p/instrumentation.js +111 -0
  188. package/dest/services/libp2p/libp2p_service.d.ts +103 -97
  189. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  190. package/dest/services/libp2p/libp2p_service.js +1316 -310
  191. package/dest/services/peer-manager/interface.d.ts +23 -0
  192. package/dest/services/peer-manager/interface.d.ts.map +1 -0
  193. package/dest/services/peer-manager/interface.js +1 -0
  194. package/dest/services/peer-manager/metrics.d.ts +11 -2
  195. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  196. package/dest/services/peer-manager/metrics.js +29 -12
  197. package/dest/services/peer-manager/peer_manager.d.ts +103 -23
  198. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  199. package/dest/services/peer-manager/peer_manager.js +551 -82
  200. package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
  201. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  202. package/dest/services/peer-manager/peer_scoring.js +37 -2
  203. package/dest/services/reqresp/config.d.ts +11 -9
  204. package/dest/services/reqresp/config.d.ts.map +1 -1
  205. package/dest/services/reqresp/config.js +18 -4
  206. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
  207. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  208. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
  209. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
  210. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  211. package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
  212. package/dest/services/reqresp/constants.d.ts +12 -0
  213. package/dest/services/reqresp/constants.d.ts.map +1 -0
  214. package/dest/services/reqresp/constants.js +7 -0
  215. package/dest/services/reqresp/index.d.ts +3 -2
  216. package/dest/services/reqresp/index.d.ts.map +1 -1
  217. package/dest/services/reqresp/index.js +2 -1
  218. package/dest/services/reqresp/interface.d.ts +73 -24
  219. package/dest/services/reqresp/interface.d.ts.map +1 -1
  220. package/dest/services/reqresp/interface.js +46 -27
  221. package/dest/services/reqresp/metrics.d.ts +1 -1
  222. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  223. package/dest/services/reqresp/metrics.js +5 -21
  224. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  225. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  226. package/dest/services/reqresp/protocols/auth.js +71 -0
  227. package/dest/services/reqresp/protocols/block.d.ts +6 -1
  228. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  229. package/dest/services/reqresp/protocols/block.js +30 -6
  230. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  231. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  232. package/dest/services/reqresp/protocols/block_txs/bitvector.js +82 -0
  233. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  234. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  235. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  236. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
  237. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  238. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  239. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  240. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  241. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  242. package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
  243. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  244. package/dest/services/reqresp/protocols/goodbye.js +7 -7
  245. package/dest/services/reqresp/protocols/index.d.ts +3 -1
  246. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  247. package/dest/services/reqresp/protocols/index.js +2 -0
  248. package/dest/services/reqresp/protocols/ping.d.ts +1 -3
  249. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  250. package/dest/services/reqresp/protocols/status.d.ts +40 -7
  251. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  252. package/dest/services/reqresp/protocols/status.js +76 -5
  253. package/dest/services/reqresp/protocols/tx.d.ts +14 -4
  254. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  255. package/dest/services/reqresp/protocols/tx.js +34 -6
  256. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  257. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
  258. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  259. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
  260. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  261. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  262. package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
  263. package/dest/services/reqresp/reqresp.d.ts +24 -66
  264. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  265. package/dest/services/reqresp/reqresp.js +699 -230
  266. package/dest/services/reqresp/status.d.ts +10 -4
  267. package/dest/services/reqresp/status.d.ts.map +1 -1
  268. package/dest/services/reqresp/status.js +9 -2
  269. package/dest/services/service.d.ts +37 -20
  270. package/dest/services/service.d.ts.map +1 -1
  271. package/dest/services/tx_collection/config.d.ts +25 -0
  272. package/dest/services/tx_collection/config.d.ts.map +1 -0
  273. package/dest/services/tx_collection/config.js +58 -0
  274. package/dest/services/tx_collection/fast_tx_collection.d.ts +51 -0
  275. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  276. package/dest/services/tx_collection/fast_tx_collection.js +300 -0
  277. package/dest/services/tx_collection/index.d.ts +3 -0
  278. package/dest/services/tx_collection/index.d.ts.map +1 -0
  279. package/dest/services/tx_collection/index.js +2 -0
  280. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  281. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  282. package/dest/services/tx_collection/instrumentation.js +24 -0
  283. package/dest/services/tx_collection/slow_tx_collection.d.ts +53 -0
  284. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  285. package/dest/services/tx_collection/slow_tx_collection.js +177 -0
  286. package/dest/services/tx_collection/tx_collection.d.ts +110 -0
  287. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  288. package/dest/services/tx_collection/tx_collection.js +128 -0
  289. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  290. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  291. package/dest/services/tx_collection/tx_collection_sink.js +111 -0
  292. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  293. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  294. package/dest/services/tx_collection/tx_source.js +31 -0
  295. package/dest/services/tx_provider.d.ts +51 -0
  296. package/dest/services/tx_provider.d.ts.map +1 -0
  297. package/dest/services/tx_provider.js +219 -0
  298. package/dest/services/tx_provider_instrumentation.d.ts +16 -0
  299. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  300. package/dest/services/tx_provider_instrumentation.js +34 -0
  301. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  302. package/dest/test-helpers/get-ports.d.ts +1 -1
  303. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  304. package/dest/test-helpers/index.d.ts +2 -1
  305. package/dest/test-helpers/index.d.ts.map +1 -1
  306. package/dest/test-helpers/index.js +1 -0
  307. package/dest/test-helpers/make-enrs.d.ts +1 -1
  308. package/dest/test-helpers/make-enrs.d.ts.map +1 -1
  309. package/dest/test-helpers/make-enrs.js +4 -5
  310. package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
  311. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  312. package/dest/test-helpers/make-test-p2p-clients.js +86 -16
  313. package/dest/test-helpers/mock-pubsub.d.ts +59 -0
  314. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
  315. package/dest/test-helpers/mock-pubsub.js +130 -0
  316. package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
  317. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
  318. package/dest/test-helpers/mock-tx-helpers.js +19 -0
  319. package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
  320. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  321. package/dest/test-helpers/reqresp-nodes.js +62 -28
  322. package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
  323. package/dest/testbench/p2p_client_testbench_worker.js +127 -39
  324. package/dest/testbench/parse_log_file.d.ts +1 -1
  325. package/dest/testbench/parse_log_file.js +4 -4
  326. package/dest/testbench/testbench.d.ts +1 -1
  327. package/dest/testbench/testbench.js +4 -4
  328. package/dest/testbench/worker_client_manager.d.ts +1 -6
  329. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  330. package/dest/testbench/worker_client_manager.js +17 -20
  331. package/dest/types/index.d.ts +4 -2
  332. package/dest/types/index.d.ts.map +1 -1
  333. package/dest/types/index.js +2 -0
  334. package/dest/util.d.ts +24 -16
  335. package/dest/util.d.ts.map +1 -1
  336. package/dest/util.js +75 -69
  337. package/dest/versioning.d.ts +4 -4
  338. package/dest/versioning.d.ts.map +1 -1
  339. package/dest/versioning.js +8 -3
  340. package/package.json +32 -27
  341. package/src/bootstrap/bootstrap.ts +27 -11
  342. package/src/client/factory.ts +139 -53
  343. package/src/client/index.ts +1 -0
  344. package/src/client/interface.ts +213 -0
  345. package/src/client/p2p_client.ts +469 -383
  346. package/src/config.ts +299 -134
  347. package/src/enr/generate-enr.ts +39 -6
  348. package/src/errors/attestation-pool.error.ts +13 -0
  349. package/src/index.ts +4 -0
  350. package/src/mem_pools/attestation_pool/attestation_pool.ts +119 -24
  351. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +352 -201
  352. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +233 -72
  353. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +199 -96
  354. package/src/mem_pools/attestation_pool/mocks.ts +24 -17
  355. package/src/mem_pools/instrumentation.ts +71 -48
  356. package/src/mem_pools/interface.ts +2 -4
  357. package/src/mem_pools/tx_pool/README.md +270 -0
  358. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +580 -143
  359. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
  360. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
  361. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  362. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  363. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
  364. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  365. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  366. package/src/mem_pools/tx_pool/index.ts +0 -1
  367. package/src/mem_pools/tx_pool/priority.ts +9 -2
  368. package/src/mem_pools/tx_pool/tx_pool.ts +75 -10
  369. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +225 -36
  370. package/src/msg_validators/attestation_validator/attestation_validator.ts +72 -14
  371. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +88 -0
  372. package/src/msg_validators/attestation_validator/index.ts +1 -0
  373. package/src/msg_validators/clock_tolerance.ts +51 -0
  374. package/src/msg_validators/index.ts +1 -1
  375. package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
  376. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  377. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  378. package/src/msg_validators/proposal_validator/index.ts +3 -0
  379. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  380. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  381. package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
  382. package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
  383. package/src/msg_validators/tx_validator/block_header_validator.ts +7 -5
  384. package/src/msg_validators/tx_validator/data_validator.ts +89 -69
  385. package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
  386. package/src/msg_validators/tx_validator/factory.ts +110 -0
  387. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  388. package/src/msg_validators/tx_validator/gas_validator.ts +117 -0
  389. package/src/msg_validators/tx_validator/index.ts +8 -0
  390. package/src/msg_validators/tx_validator/metadata_validator.ts +67 -22
  391. package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
  392. package/src/msg_validators/tx_validator/size_validator.ts +18 -0
  393. package/src/msg_validators/tx_validator/test_utils.ts +43 -0
  394. package/src/msg_validators/tx_validator/timestamp_validator.ts +49 -0
  395. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
  396. package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
  397. package/src/services/discv5/discV5_service.ts +84 -38
  398. package/src/services/dummy_service.ts +153 -9
  399. package/src/services/encoding.ts +82 -6
  400. package/src/services/index.ts +4 -0
  401. package/src/services/libp2p/instrumentation.ts +113 -0
  402. package/src/services/libp2p/libp2p_service.ts +1142 -339
  403. package/src/services/peer-manager/interface.ts +29 -0
  404. package/src/services/peer-manager/metrics.ts +38 -12
  405. package/src/services/peer-manager/peer_manager.ts +657 -80
  406. package/src/services/peer-manager/peer_scoring.ts +42 -3
  407. package/src/services/reqresp/config.ts +26 -9
  408. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
  409. package/src/services/reqresp/connection-sampler/connection_sampler.ts +150 -95
  410. package/src/services/reqresp/constants.ts +14 -0
  411. package/src/services/reqresp/index.ts +2 -0
  412. package/src/services/reqresp/interface.ts +92 -37
  413. package/src/services/reqresp/metrics.ts +11 -24
  414. package/src/services/reqresp/protocols/auth.ts +83 -0
  415. package/src/services/reqresp/protocols/block.ts +26 -4
  416. package/src/services/reqresp/protocols/block_txs/bitvector.ts +99 -0
  417. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  418. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  419. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  420. package/src/services/reqresp/protocols/goodbye.ts +9 -7
  421. package/src/services/reqresp/protocols/index.ts +2 -0
  422. package/src/services/reqresp/protocols/status.ts +121 -5
  423. package/src/services/reqresp/protocols/tx.ts +36 -8
  424. package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
  425. package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
  426. package/src/services/reqresp/reqresp.ts +387 -256
  427. package/src/services/reqresp/status.ts +12 -3
  428. package/src/services/service.ts +61 -22
  429. package/src/services/tx_collection/config.ts +84 -0
  430. package/src/services/tx_collection/fast_tx_collection.ts +341 -0
  431. package/src/services/tx_collection/index.ts +2 -0
  432. package/src/services/tx_collection/instrumentation.ts +26 -0
  433. package/src/services/tx_collection/slow_tx_collection.ts +233 -0
  434. package/src/services/tx_collection/tx_collection.ts +216 -0
  435. package/src/services/tx_collection/tx_collection_sink.ts +129 -0
  436. package/src/services/tx_collection/tx_source.ts +37 -0
  437. package/src/services/tx_provider.ts +232 -0
  438. package/src/services/tx_provider_instrumentation.ts +48 -0
  439. package/src/test-helpers/index.ts +1 -0
  440. package/src/test-helpers/make-enrs.ts +4 -5
  441. package/src/test-helpers/make-test-p2p-clients.ts +111 -21
  442. package/src/test-helpers/mock-pubsub.ts +188 -0
  443. package/src/test-helpers/mock-tx-helpers.ts +24 -0
  444. package/src/test-helpers/reqresp-nodes.ts +87 -36
  445. package/src/testbench/p2p_client_testbench_worker.ts +183 -37
  446. package/src/testbench/parse_log_file.ts +4 -4
  447. package/src/testbench/testbench.ts +4 -4
  448. package/src/testbench/worker_client_manager.ts +23 -24
  449. package/src/types/index.ts +2 -0
  450. package/src/util.ts +105 -91
  451. package/src/versioning.ts +11 -4
  452. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
  453. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  454. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -141
  455. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
  456. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  457. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -21
  458. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  459. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  460. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  461. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -174
  462. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -29
  463. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,19 +1,26 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { L2Block } from '@aztec/stdlib/block';
3
- import { Tx, TxHash } from '@aztec/stdlib/tx';
3
+ import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
4
+ import { AuthRequest, AuthResponse } from './protocols/auth.js';
5
+ import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
6
+ import { StatusMessage } from './protocols/status.js';
4
7
  /*
5
8
  * Request Response Sub Protocols
6
- */ export const PING_PROTOCOL = '/aztec/req/ping/0.1.0';
7
- export const STATUS_PROTOCOL = '/aztec/req/status/0.1.0';
8
- export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/0.1.0';
9
- export const TX_REQ_PROTOCOL = '/aztec/req/tx/0.1.0';
10
- export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/0.1.0';
9
+ */ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
10
+ export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
11
+ export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
12
+ export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
13
+ export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
14
+ export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
15
+ export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
11
16
  export var ReqRespSubProtocol = /*#__PURE__*/ function(ReqRespSubProtocol) {
12
17
  ReqRespSubProtocol[ReqRespSubProtocol["PING"] = PING_PROTOCOL] = "PING";
13
18
  ReqRespSubProtocol[ReqRespSubProtocol["STATUS"] = STATUS_PROTOCOL] = "STATUS";
14
19
  ReqRespSubProtocol[ReqRespSubProtocol["GOODBYE"] = GOODBYE_PROTOCOL] = "GOODBYE";
15
20
  ReqRespSubProtocol[ReqRespSubProtocol["TX"] = TX_REQ_PROTOCOL] = "TX";
16
21
  ReqRespSubProtocol[ReqRespSubProtocol["BLOCK"] = BLOCK_REQ_PROTOCOL] = "BLOCK";
22
+ ReqRespSubProtocol[ReqRespSubProtocol["AUTH"] = AUTH_PROTOCOL] = "AUTH";
23
+ ReqRespSubProtocol[ReqRespSubProtocol["BLOCK_TXS"] = BLOCK_TXS_REQ_PROTOCOL] = "BLOCK_TXS";
17
24
  return ReqRespSubProtocol;
18
25
  }({});
19
26
  export const noopValidator = ()=>Promise.resolve(true);
@@ -22,23 +29,27 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS = {
22
29
  [ReqRespSubProtocol.STATUS]: noopValidator,
23
30
  [ReqRespSubProtocol.TX]: noopValidator,
24
31
  [ReqRespSubProtocol.GOODBYE]: noopValidator,
25
- [ReqRespSubProtocol.BLOCK]: noopValidator
26
- };
27
- /**
28
- * Default handler for unimplemented sub protocols, this SHOULD be overwritten
29
- * by the service, but is provided as a fallback
30
- */ const defaultHandler = (_msg)=>{
31
- return Promise.resolve(Buffer.from('unimplemented'));
32
- };
33
- /**
34
- * Default sub protocol handlers - this SHOULD be overwritten by the service,
35
- */ export const DEFAULT_SUB_PROTOCOL_HANDLERS = {
36
- [ReqRespSubProtocol.PING]: defaultHandler,
37
- [ReqRespSubProtocol.STATUS]: defaultHandler,
38
- [ReqRespSubProtocol.TX]: defaultHandler,
39
- [ReqRespSubProtocol.GOODBYE]: defaultHandler,
40
- [ReqRespSubProtocol.BLOCK]: defaultHandler
32
+ [ReqRespSubProtocol.BLOCK]: noopValidator,
33
+ [ReqRespSubProtocol.AUTH]: noopValidator,
34
+ [ReqRespSubProtocol.BLOCK_TXS]: noopValidator
41
35
  };
36
+ /*
37
+ * Helper class to sub-protocol validation error*/ export class ValidationError extends Error {
38
+ constructor(message){
39
+ super(message);
40
+ }
41
+ }
42
+ /*
43
+ * Small helper function which parses buffer into specific response type
44
+ * It is needed to make TypeScript happy, as it cannot infer the type from the buffer
45
+ *
46
+ * @param proto - The sub protocol to parse the response for
47
+ * @param buffer - The buffer to parse
48
+ *
49
+ * @returns - The parsed response object
50
+ * */ export function responseFromBuffer(proto, buffer) {
51
+ return subProtocolMap[proto].response.fromBuffer(buffer);
52
+ }
42
53
  /**
43
54
  * RequestableBuffer is a wrapper around a buffer that allows it to be
44
55
  * used in generic request response protocols
@@ -66,12 +77,12 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS = {
66
77
  response: RequestableBuffer
67
78
  },
68
79
  [ReqRespSubProtocol.STATUS]: {
69
- request: RequestableBuffer,
70
- response: RequestableBuffer
80
+ request: StatusMessage,
81
+ response: StatusMessage
71
82
  },
72
83
  [ReqRespSubProtocol.TX]: {
73
- request: TxHash,
74
- response: Tx
84
+ request: TxHashArray,
85
+ response: TxArray
75
86
  },
76
87
  [ReqRespSubProtocol.GOODBYE]: {
77
88
  request: RequestableBuffer,
@@ -80,5 +91,13 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS = {
80
91
  [ReqRespSubProtocol.BLOCK]: {
81
92
  request: Fr,
82
93
  response: L2Block
94
+ },
95
+ [ReqRespSubProtocol.AUTH]: {
96
+ request: AuthRequest,
97
+ response: AuthResponse
98
+ },
99
+ [ReqRespSubProtocol.BLOCK_TXS]: {
100
+ request: BlockTxsRequest,
101
+ response: BlockTxsResponse
83
102
  }
84
103
  };
@@ -12,4 +12,4 @@ export declare class ReqRespMetrics {
12
12
  recordRequestError(protocol: string): void;
13
13
  recordResponseError(protocol: string): void;
14
14
  }
15
- //# sourceMappingURL=metrics.d.ts.map
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0cmljcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NlcnZpY2VzL3JlcXJlc3AvbWV0cmljcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxFQUFpQixNQUFNLHlCQUF5QixDQUFDO0FBRXRGLHFCQUFhLGNBQWM7SUFVdkIsUUFBUSxDQUFDLGVBQWUsRUFBRSxlQUFlO0lBVDNDLFNBQWdCLE1BQU0sRUFBRSxNQUF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;CAG5C"}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAC;AAEtF,qBAAa,cAAc;IAUvB,QAAQ,CAAC,eAAe,EAAE,eAAe;IAT3C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAC7C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IAEjD,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAgB;IACvD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAgB;IAEtD,YACW,eAAe,EAAE,eAAe,EACzC,IAAI,SAAY,EAWjB;IAEM,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QAExC;IAEM,qBAAqB,CAAC,QAAQ,EAAE,MAAM,QAE5C;IAEM,kBAAkB,CAAC,QAAQ,EAAE,MAAM,QAEzC;IAEM,mBAAmB,CAAC,QAAQ,EAAE,MAAM,QAE1C;CACF"}
@@ -1,5 +1,5 @@
1
1
  // Request response metrics
2
- import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
2
+ import { Attributes, Metrics } from '@aztec/telemetry-client';
3
3
  export class ReqRespMetrics {
4
4
  telemetryClient;
5
5
  tracer;
@@ -11,26 +11,10 @@ export class ReqRespMetrics {
11
11
  this.telemetryClient = telemetryClient;
12
12
  this.tracer = telemetryClient.getTracer(name);
13
13
  const meter = telemetryClient.getMeter(name);
14
- this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS, {
15
- description: 'Number of requests sent to peers',
16
- unit: 'requests',
17
- valueType: ValueType.INT
18
- });
19
- this.receivedRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS, {
20
- description: 'Number of requests received from peers',
21
- unit: 'requests',
22
- valueType: ValueType.INT
23
- });
24
- this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS, {
25
- description: 'Number of failed outbound requests - nodes not getting valid responses',
26
- unit: 'requests',
27
- valueType: ValueType.INT
28
- });
29
- this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS, {
30
- description: 'Number of failed inbound requests - node failing to respond to requests',
31
- unit: 'requests',
32
- valueType: ValueType.INT
33
- });
14
+ this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS);
15
+ this.receivedRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS);
16
+ this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS);
17
+ this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS);
34
18
  }
35
19
  recordRequestSent(protocol) {
36
20
  this.sentRequests.add(1, {
@@ -0,0 +1,43 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { Signature } from '@aztec/foundation/eth-signature';
4
+ import { BufferReader } from '@aztec/foundation/serialize';
5
+ import { StatusMessage } from './status.js';
6
+ export declare const VALIDATOR_AUTH_DOMAIN_SEPARATOR = "Aztec Validator Challenge:";
7
+ export declare const VALIDATOR_AUTH_FULL_CHALLENGE_ENCODED_LENGTH: number;
8
+ export declare class AuthRequest {
9
+ readonly status: StatusMessage;
10
+ readonly challenge: Fr;
11
+ constructor(status: StatusMessage, challenge: Fr);
12
+ /**
13
+ * Deserializes the AuthRequest object from a Buffer.
14
+ * @param buffer - Buffer or BufferReader object to deserialize.
15
+ * @returns An instance of StatusMessage.
16
+ */
17
+ static fromBuffer(buffer: Buffer | BufferReader): AuthRequest;
18
+ /**
19
+ * Serializes the AuthRequest object into a Buffer.
20
+ * @returns Buffer representation of the StatusMessage object.
21
+ */
22
+ toBuffer(): Buffer<ArrayBufferLike>;
23
+ getPayloadToSign(): Buffer32;
24
+ static random(): AuthRequest;
25
+ }
26
+ export declare class AuthResponse {
27
+ readonly status: StatusMessage;
28
+ readonly signature: Signature;
29
+ constructor(status: StatusMessage, signature: Signature);
30
+ /**
31
+ * Deserializes the AuthResponse object from a Buffer.
32
+ * @param buffer - Buffer or BufferReader object to deserialize.
33
+ * @returns An instance of StatusMessage.
34
+ */
35
+ static fromBuffer(buffer: Buffer | BufferReader): AuthResponse;
36
+ /**
37
+ * Serializes the AuthRequest object into a Buffer.
38
+ * @returns Buffer representation of the StatusMessage object.
39
+ */
40
+ toBuffer(): Buffer<ArrayBufferLike>;
41
+ static random(): AuthResponse;
42
+ }
43
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3NlcnZpY2VzL3JlcXJlc3AvcHJvdG9jb2xzL2F1dGgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRXBELE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDNUQsT0FBTyxFQUFFLFlBQVksRUFBcUIsTUFBTSw2QkFBNkIsQ0FBQztBQUU5RSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRTVDLGVBQU8sTUFBTSwrQkFBK0IsK0JBQStCLENBQUM7QUFDNUUsZUFBTyxNQUFNLDRDQUE0QyxRQUNlLENBQUM7QUFNekUscUJBQWEsV0FBVztJQUVwQixRQUFRLENBQUMsTUFBTSxFQUFF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5C,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAC5E,eAAO,MAAM,4CAA4C,QACe,CAAC;AAMzE,qBAAa,WAAW;IAEpB,QAAQ,CAAC,MAAM,EAAE,aAAa;IAC9B,QAAQ,CAAC,SAAS,EAAE,EAAE;IAFxB,YACW,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,EAAE,EACpB;IAEJ;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,WAAW,CAM5D;IAED;;;OAGG;IACH,QAAQ,4BAEP;IAED,gBAAgB,IAAI,QAAQ,CAG3B;IAED,MAAM,CAAC,MAAM,IAAI,WAAW,CAE3B;CACF;AAED,qBAAa,YAAY;IAErB,QAAQ,CAAC,MAAM,EAAE,aAAa;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS;IAF/B,YACW,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS,EAC3B;IACJ;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,YAAY,CAM7D;IAED;;;OAGG;IACH,QAAQ,4BAEP;IAED,MAAM,CAAC,MAAM,IAAI,YAAY,CAE5B;CACF"}
@@ -0,0 +1,71 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { Signature } from '@aztec/foundation/eth-signature';
5
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
6
+ import { StatusMessage } from './status.js';
7
+ export const VALIDATOR_AUTH_DOMAIN_SEPARATOR = 'Aztec Validator Challenge:';
8
+ export const VALIDATOR_AUTH_FULL_CHALLENGE_ENCODED_LENGTH = VALIDATOR_AUTH_DOMAIN_SEPARATOR.length + Fr.random().toString().length;
9
+ /*
10
+ * P2P Auth Message
11
+ * Superset of the StatusMessage, used to establish a handshake between peers and authenticate them.
12
+ */ export class AuthRequest {
13
+ status;
14
+ challenge;
15
+ constructor(status, challenge){
16
+ this.status = status;
17
+ this.challenge = challenge;
18
+ }
19
+ /**
20
+ * Deserializes the AuthRequest object from a Buffer.
21
+ * @param buffer - Buffer or BufferReader object to deserialize.
22
+ * @returns An instance of StatusMessage.
23
+ */ static fromBuffer(buffer) {
24
+ const reader = BufferReader.asReader(buffer);
25
+ return new AuthRequest(StatusMessage.fromBuffer(reader), Fr.fromBuffer(reader));
26
+ }
27
+ /**
28
+ * Serializes the AuthRequest object into a Buffer.
29
+ * @returns Buffer representation of the StatusMessage object.
30
+ */ toBuffer() {
31
+ return serializeToBuffer([
32
+ this.status,
33
+ this.challenge
34
+ ]);
35
+ }
36
+ getPayloadToSign() {
37
+ const fullChallenge = VALIDATOR_AUTH_DOMAIN_SEPARATOR + this.challenge.toString();
38
+ return Buffer32.fromBuffer(keccak256(Buffer.from(fullChallenge, 'utf-8')));
39
+ }
40
+ static random() {
41
+ return new AuthRequest(StatusMessage.random(), Fr.random());
42
+ }
43
+ }
44
+ export class AuthResponse {
45
+ status;
46
+ signature;
47
+ constructor(status, signature){
48
+ this.status = status;
49
+ this.signature = signature;
50
+ }
51
+ /**
52
+ * Deserializes the AuthResponse object from a Buffer.
53
+ * @param buffer - Buffer or BufferReader object to deserialize.
54
+ * @returns An instance of StatusMessage.
55
+ */ static fromBuffer(buffer) {
56
+ const reader = BufferReader.asReader(buffer);
57
+ return new AuthResponse(StatusMessage.fromBuffer(reader), Signature.fromBuffer(reader));
58
+ }
59
+ /**
60
+ * Serializes the AuthRequest object into a Buffer.
61
+ * @returns Buffer representation of the StatusMessage object.
62
+ */ toBuffer() {
63
+ return serializeToBuffer([
64
+ this.status,
65
+ this.signature
66
+ ]);
67
+ }
68
+ static random() {
69
+ return new AuthResponse(StatusMessage.random(), Signature.random());
70
+ }
71
+ }
@@ -1,4 +1,9 @@
1
1
  import type { L2BlockSource } from '@aztec/stdlib/block';
2
2
  import type { ReqRespSubProtocolHandler } from '../interface.js';
3
+ /**
4
+ * Handler for L2 Block requests
5
+ * @param l2BlockSource - source for L2 blocks
6
+ * @returns the Block request handler
7
+ * */
3
8
  export declare function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubProtocolHandler;
4
- //# sourceMappingURL=block.d.ts.map
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2suZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9zZXJ2aWNlcy9yZXFyZXNwL3Byb3RvY29scy9ibG9jay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUl6RCxPQUFPLEtBQUssRUFBRSx5QkFBeUIsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBR2pFOzs7O0tBSUs7QUFDTCx3QkFBZ0IsbUJBQW1CLENBQUMsYUFBYSxFQUFFLGFBQWEsR0FBRyx5QkFBeUIsQ0FzQjNGIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/block.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,yBAAyB,CAO3F"}
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/block.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;KAIK;AACL,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,yBAAyB,CAsB3F"}
@@ -1,8 +1,32 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- export function reqRespBlockHandler(l2BlockSource) {
3
- return async (_peerId, msg)=>{
4
- const blockNumber = Fr.fromBuffer(msg);
5
- const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
6
- return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
4
+ /**
5
+ * Handler for L2 Block requests
6
+ * @param l2BlockSource - source for L2 blocks
7
+ * @returns the Block request handler
8
+ * */ export function reqRespBlockHandler(l2BlockSource) {
9
+ /**
10
+ * @param peerId - the peer ID of the requester
11
+ * @param msg - the block request message, which is expected to contain valid block number as a Buffer
12
+ * @returns a Buffer containing the requested block data, or an empty Buffer if the block is not found
13
+ * @throws ReqRespStatusError if the input msg is not a valid block number
14
+ * */ return async (_peerId, msg)=>{
15
+ let blockNumber;
16
+ try {
17
+ blockNumber = Fr.fromBuffer(msg);
18
+ } catch (err) {
19
+ throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
20
+ cause: err
21
+ });
22
+ }
23
+ try {
24
+ const foundBlock = await l2BlockSource.getBlock(BlockNumber(Number(blockNumber)));
25
+ return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
26
+ } catch (err) {
27
+ throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, {
28
+ cause: err
29
+ });
30
+ }
7
31
  };
8
32
  }
@@ -0,0 +1,30 @@
1
+ import { BufferReader } from '@aztec/foundation/serialize';
2
+ /**
3
+ * BitVector helper class for representing and serializing bit vectors
4
+ */
5
+ export declare class BitVector {
6
+ private buffer;
7
+ private length;
8
+ constructor(buffer: Buffer, length: number);
9
+ static init(length: number, indices: number[]): BitVector;
10
+ getLength(): number;
11
+ isSet(index: number): boolean;
12
+ /**
13
+ * Returns all indices which are set to true
14
+ * */
15
+ getTrueIndices(): number[];
16
+ /**
17
+ * Serializes the BitVector object into a Buffer
18
+ *
19
+ * @returns Buffer representation of the BitVector object
20
+ * */
21
+ toBuffer(): Buffer;
22
+ /**
23
+ * Deserializes buffer into new BitVector
24
+ *
25
+ * @returns A new BitVector instance
26
+ * */
27
+ static fromBuffer(buffer: Buffer | BufferReader): BitVector;
28
+ static byteLength(length: number): number;
29
+ }
30
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYml0dmVjdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvc2VydmljZXMvcmVxcmVzcC9wcm90b2NvbHMvYmxvY2tfdHhzL2JpdHZlY3Rvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsWUFBWSxFQUFxQixNQUFNLDZCQUE2QixDQUFDO0FBSTlFOztHQUVHO0FBQ0gscUJBQWEsU0FBUztJQUNwQixPQUFPLENBQUMsTUFBTSxDQUFTO0lBQ3ZCLE9BQU8sQ0FBQyxNQUFNLENBQVM7SUFFdkIsWUFBWSxNQUFNLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxNQUFNLEVBR3pDO0lBU0QsTUFBTSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLE9BQU8sRUFBRSxNQUFNLEVBQUUsR0FBRyxTQUFTLENBbUJ4RDtJQUVELFNBQVMsSUFBSSxNQUFNLENBRWxCO0lBU0QsS0FBSyxDQUFDLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUU1QjtJQUVEOztTQUVLO0lBQ0wsY0FBYyxJQUFJLE1BQU0sRUFBRSxDQUV6QjtJQUVEOzs7O1NBSUs7SUFDTCxRQUFRLElBQUksTUFBTSxDQUVqQjtJQUVEOzs7O1NBSUs7SUFDTCxNQUFNLENBQUMsVUFBVSxDQUFDLE1BQU0sRUFBRSxNQUFNLEdBQUcsWUFBWSxHQUFHLFNBQVMsQ0FhMUQ7SUFFRCxNQUFNLENBQUMsVUFBVSxDQUFDLE1BQU0sRUFBRSxNQUFNLFVBRS9CO0NBQ0YifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitvector.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/bitvector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAI9E;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IAEvB,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAGzC;IASD,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAmBxD;IAED,SAAS,IAAI,MAAM,CAElB;IASD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5B;IAED;;SAEK;IACL,cAAc,IAAI,MAAM,EAAE,CAEzB;IAED;;;;SAIK;IACL,QAAQ,IAAI,MAAM,CAEjB;IAED;;;;SAIK;IACL,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAa1D;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,UAE/B;CACF"}
@@ -0,0 +1,82 @@
1
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
2
+ import { MAX_TXS_PER_BLOCK } from '../../constants.js';
3
+ /**
4
+ * BitVector helper class for representing and serializing bit vectors
5
+ */ export class BitVector {
6
+ buffer;
7
+ length;
8
+ constructor(buffer, length){
9
+ this.buffer = buffer;
10
+ this.length = length;
11
+ }
12
+ /*
13
+ * Creates new BitVector instance
14
+ * @param length - Length of the bit vector
15
+ * @param indices - Array of indices to set to 1 in the bit vector
16
+ *
17
+ * @returns A new BitVector instance with specified length and set indices
18
+ * */ static init(length, indices) {
19
+ if (indices.length > length) {
20
+ throw new Error('Indices length exceeds specified length');
21
+ }
22
+ const buffer = Buffer.alloc(BitVector.byteLength(length));
23
+ indices.forEach((idx)=>{
24
+ const invalidIndex = idx < 0 || idx >= length;
25
+ if (invalidIndex) {
26
+ throw new Error(`Index ${idx} is out of bounds for BitVector of length ${length}`);
27
+ }
28
+ const byteIndex = Math.floor(idx / 8);
29
+ const bitIndex = idx % 8;
30
+ buffer[byteIndex] |= 1 << bitIndex;
31
+ });
32
+ return new BitVector(buffer, length);
33
+ }
34
+ getLength() {
35
+ return this.length;
36
+ }
37
+ /*
38
+ * Checks if element at index is set to true
39
+ *
40
+ * @param index - Index of the bit to check
41
+ *
42
+ * @returns True if the bit at index is set, false otherwise
43
+ * */ isSet(index) {
44
+ return index >= 0 && index < this.length && !!(this.buffer[Math.floor(index / 8)] & 1 << index % 8);
45
+ }
46
+ /**
47
+ * Returns all indices which are set to true
48
+ * */ getTrueIndices() {
49
+ return Array.from({
50
+ length: this.length
51
+ }, (_, i)=>i).filter((i)=>this.isSet(i));
52
+ }
53
+ /**
54
+ * Serializes the BitVector object into a Buffer
55
+ *
56
+ * @returns Buffer representation of the BitVector object
57
+ * */ toBuffer() {
58
+ return serializeToBuffer([
59
+ this.length,
60
+ this.buffer
61
+ ]);
62
+ }
63
+ /**
64
+ * Deserializes buffer into new BitVector
65
+ *
66
+ * @returns A new BitVector instance
67
+ * */ static fromBuffer(buffer) {
68
+ const reader = BufferReader.asReader(buffer);
69
+ const length = reader.readNumber();
70
+ if (length < 0) {
71
+ throw new Error(`BitVector length ${length} cannot be negative`);
72
+ }
73
+ if (length > MAX_TXS_PER_BLOCK) {
74
+ throw new Error(`BitVector length ${length} exceeds maximum ${MAX_TXS_PER_BLOCK}`);
75
+ }
76
+ const bitBuffer = reader.readBytes(BitVector.byteLength(length));
77
+ return new BitVector(bitBuffer, length);
78
+ }
79
+ static byteLength(length) {
80
+ return Math.ceil(length / 8);
81
+ }
82
+ }
@@ -0,0 +1,11 @@
1
+ import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
2
+ import type { TxPool } from '../../../../mem_pools/index.js';
3
+ import type { ReqRespSubProtocolHandler } from '../../interface.js';
4
+ /**
5
+ * Handler for block txs requests
6
+ * @param attestationPool - the attestation pool to check for block proposals
7
+ * @param mempools - the mempools containing the tx pool
8
+ * @returns the BlockTxs request handler
9
+ */
10
+ export declare function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler;
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfdHhzX2hhbmRsZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9zZXJ2aWNlcy9yZXFyZXNwL3Byb3RvY29scy9ibG9ja190eHMvYmxvY2tfdHhzX2hhbmRsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxLQUFLLEVBQUUsZUFBZSxFQUFFLE1BQU0sNERBQTRELENBQUM7QUFDbEcsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUseUJBQXlCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUtwRTs7Ozs7R0FLRztBQUNILHdCQUFnQixzQkFBc0IsQ0FBQyxlQUFlLEVBQUUsZUFBZSxFQUFFLE1BQU0sRUFBRSxNQUFNLEdBQUcseUJBQXlCLENBbUNsSCJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_txs_handler.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/block_txs_handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAKpE;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAmClH"}
@@ -0,0 +1,39 @@
1
+ import { TxArray } from '@aztec/stdlib/tx';
2
+ import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
3
+ import { BitVector } from './bitvector.js';
4
+ import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
5
+ /**
6
+ * Handler for block txs requests
7
+ * @param attestationPool - the attestation pool to check for block proposals
8
+ * @param mempools - the mempools containing the tx pool
9
+ * @returns the BlockTxs request handler
10
+ */ export function reqRespBlockTxsHandler(attestationPool, txPool) {
11
+ /**
12
+ * Handler for block txs requests
13
+ * @param msg - the block txs request message
14
+ * @returns the block txs response message
15
+ * @throws if msg is not a valid block txs request
16
+ */ return async (_peerId, msg)=>{
17
+ let request;
18
+ try {
19
+ request = BlockTxsRequest.fromBuffer(msg);
20
+ } catch (err) {
21
+ throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
22
+ cause: err
23
+ });
24
+ }
25
+ const blockProposal = await attestationPool.getBlockProposal(request.blockHash.toString());
26
+ if (!blockProposal) {
27
+ throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
28
+ }
29
+ const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
30
+ //Map txs in the pool to their indices in the block proposal
31
+ const availableIndices = txsAvailableInPool.map((hasTx, idx)=>hasTx ? idx : -1).filter((idx)=>idx !== -1);
32
+ const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
33
+ const requestedIndices = new Set(request.txIndices.getTrueIndices());
34
+ const requestedTxsHashes = blockProposal.txHashes.filter((_, idx)=>requestedIndices.has(idx));
35
+ const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter((tx)=>!!tx);
36
+ const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
37
+ return response.toBuffer();
38
+ };
39
+ }
@@ -0,0 +1,47 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { BufferReader } from '@aztec/foundation/serialize';
3
+ import { TxArray } from '@aztec/stdlib/tx';
4
+ import { BitVector } from './bitvector.js';
5
+ /**
6
+ * Request message for requesting specific transactions from a block
7
+ */
8
+ export declare class BlockTxsRequest {
9
+ readonly blockHash: Fr;
10
+ readonly txIndices: BitVector;
11
+ constructor(blockHash: Fr, txIndices: BitVector);
12
+ /**
13
+ * Deserializes the BlockTxRequest object from a Buffer
14
+ * @param buffer - Buffer or BufferReader object to deserialize
15
+ * @returns An instance of BlockTxRequest
16
+ */
17
+ static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest;
18
+ /**
19
+ * Serializes the BlockTxRequest object into a Buffer
20
+ * @returns Buffer representation of the BlockTxRequest object
21
+ */
22
+ toBuffer(): Buffer;
23
+ }
24
+ /**
25
+ * Response message containing requested transactions from a block
26
+ */
27
+ export declare class BlockTxsResponse {
28
+ readonly blockHash: Fr;
29
+ readonly txs: TxArray;
30
+ readonly txIndices: BitVector;
31
+ constructor(blockHash: Fr, txs: TxArray, txIndices: BitVector);
32
+ /**
33
+ * Deserializes the BlockTxResponse object from a Buffer
34
+ * @param buffer - Buffer or BufferReader object to deserialize
35
+ * @returns An instance of BlockTxResponse
36
+ */
37
+ static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse;
38
+ /**
39
+ * Serializes the BlockTxResponse object into a Buffer
40
+ * @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
41
+ * thus we serialize it last
42
+ * @returns Buffer representation of the BlockTxResponse object
43
+ */
44
+ toBuffer(): Buffer;
45
+ static empty(): BlockTxsResponse;
46
+ }
47
+ //# sourceM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C,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,gBAAgB,CAOjE;IAED;;;;;OAKG;IACH,QAAQ,IAAI,MAAM,CAEjB;IAED,MAAM,CAAC,KAAK,IAAI,gBAAgB,CAE/B;CACF"}
@@ -0,0 +1,75 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { TxArray } from '@aztec/stdlib/tx';
4
+ import { BitVector } from './bitvector.js';
5
+ /**
6
+ * Request message for requesting specific transactions from a block
7
+ */ export class BlockTxsRequest {
8
+ blockHash;
9
+ txIndices;
10
+ constructor(blockHash, // BitVector indicating which txs from the proposal we are requesting
11
+ // 1 means we want the tx, 0 means we don't
12
+ txIndices){
13
+ this.blockHash = blockHash;
14
+ this.txIndices = txIndices;
15
+ }
16
+ /**
17
+ * Deserializes the BlockTxRequest object from a Buffer
18
+ * @param buffer - Buffer or BufferReader object to deserialize
19
+ * @returns An instance of BlockTxRequest
20
+ */ static fromBuffer(buffer) {
21
+ const reader = BufferReader.asReader(buffer);
22
+ const blockHash = Fr.fromBuffer(reader);
23
+ const txIndices = BitVector.fromBuffer(reader);
24
+ return new BlockTxsRequest(blockHash, txIndices);
25
+ }
26
+ /**
27
+ * Serializes the BlockTxRequest object into a Buffer
28
+ * @returns Buffer representation of the BlockTxRequest object
29
+ */ toBuffer() {
30
+ return serializeToBuffer([
31
+ this.blockHash,
32
+ this.txIndices.toBuffer()
33
+ ]);
34
+ }
35
+ }
36
+ /**
37
+ * Response message containing requested transactions from a block
38
+ */ export class BlockTxsResponse {
39
+ blockHash;
40
+ txs;
41
+ txIndices;
42
+ constructor(blockHash, txs, // BitVector indicating which txs from the proposal are available at the peer
43
+ // 1 means the tx is available, 0 means it is not
44
+ txIndices){
45
+ this.blockHash = blockHash;
46
+ this.txs = txs;
47
+ this.txIndices = txIndices;
48
+ }
49
+ /**
50
+ * Deserializes the BlockTxResponse object from a Buffer
51
+ * @param buffer - Buffer or BufferReader object to deserialize
52
+ * @returns An instance of BlockTxResponse
53
+ */ static fromBuffer(buffer) {
54
+ const reader = BufferReader.asReader(buffer);
55
+ const blockHash = Fr.fromBuffer(reader);
56
+ const txs = TxArray.fromBuffer(reader);
57
+ const txIndices = BitVector.fromBuffer(reader);
58
+ return new BlockTxsResponse(blockHash, txs, txIndices);
59
+ }
60
+ /**
61
+ * Serializes the BlockTxResponse object into a Buffer
62
+ * @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
63
+ * thus we serialize it last
64
+ * @returns Buffer representation of the BlockTxResponse object
65
+ */ toBuffer() {
66
+ return serializeToBuffer([
67
+ this.blockHash,
68
+ this.txs.toBuffer(),
69
+ this.txIndices.toBuffer()
70
+ ]);
71
+ }
72
+ static empty() {
73
+ return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
74
+ }
75
+ }