@aztec/p2p 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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 (605) hide show
  1. package/README.md +129 -3
  2. package/dest/bootstrap/bootstrap.d.ts +4 -3
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  4. package/dest/bootstrap/bootstrap.js +13 -5
  5. package/dest/client/factory.d.ts +13 -12
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +65 -21
  8. package/dest/client/index.d.ts +1 -1
  9. package/dest/client/interface.d.ts +72 -35
  10. package/dest/client/interface.d.ts.map +1 -1
  11. package/dest/client/p2p_client.d.ts +59 -86
  12. package/dest/client/p2p_client.d.ts.map +1 -1
  13. package/dest/client/p2p_client.js +677 -339
  14. package/dest/config.d.ts +169 -87
  15. package/dest/config.d.ts.map +1 -1
  16. package/dest/config.js +176 -56
  17. package/dest/enr/generate-enr.d.ts +1 -1
  18. package/dest/enr/index.d.ts +1 -1
  19. package/dest/errors/attestation-pool.error.d.ts +7 -0
  20. package/dest/errors/attestation-pool.error.d.ts.map +1 -0
  21. package/dest/errors/attestation-pool.error.js +12 -0
  22. package/dest/errors/p2p-service.error.d.ts +9 -0
  23. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  24. package/dest/errors/p2p-service.error.js +10 -0
  25. package/dest/errors/reqresp.error.d.ts +1 -20
  26. package/dest/errors/reqresp.error.d.ts.map +1 -1
  27. package/dest/errors/reqresp.error.js +0 -21
  28. package/dest/errors/tx-pool.error.d.ts +8 -0
  29. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  30. package/dest/errors/tx-pool.error.js +9 -0
  31. package/dest/index.d.ts +2 -2
  32. package/dest/index.d.ts.map +1 -1
  33. package/dest/index.js +1 -1
  34. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +154 -57
  35. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/attestation_pool.js +511 -3
  37. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  38. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +651 -294
  40. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  41. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  42. package/dest/mem_pools/attestation_pool/index.js +1 -2
  43. package/dest/mem_pools/attestation_pool/mocks.d.ts +234 -10
  44. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  45. package/dest/mem_pools/attestation_pool/mocks.js +19 -13
  46. package/dest/mem_pools/index.d.ts +3 -3
  47. package/dest/mem_pools/index.d.ts.map +1 -1
  48. package/dest/mem_pools/index.js +1 -1
  49. package/dest/mem_pools/instrumentation.d.ts +11 -1
  50. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  51. package/dest/mem_pools/instrumentation.js +55 -10
  52. package/dest/mem_pools/interface.d.ts +6 -7
  53. package/dest/mem_pools/interface.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  55. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  56. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  57. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +39 -0
  58. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  59. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +97 -0
  60. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  61. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +97 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +11 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/index.js +12 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
  90. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  91. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  92. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
  93. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  94. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  95. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  96. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  97. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  98. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  99. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  100. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  101. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  102. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +218 -0
  103. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  104. package/dest/mem_pools/tx_pool_v2/interfaces.js +10 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +137 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +223 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  113. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +337 -0
  114. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +62 -0
  115. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  116. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +167 -0
  117. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +78 -0
  118. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  119. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +914 -0
  120. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +14 -7
  121. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  122. package/dest/msg_validators/attestation_validator/attestation_validator.js +84 -26
  123. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +24 -0
  124. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
  125. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +75 -0
  126. package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
  127. package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
  128. package/dest/msg_validators/attestation_validator/index.js +1 -0
  129. package/dest/msg_validators/clock_tolerance.d.ts +32 -0
  130. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  131. package/dest/msg_validators/clock_tolerance.js +90 -0
  132. package/dest/msg_validators/index.d.ts +2 -2
  133. package/dest/msg_validators/index.d.ts.map +1 -1
  134. package/dest/msg_validators/index.js +1 -1
  135. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
  136. package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
  137. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +15 -0
  138. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  139. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +14 -0
  140. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +15 -0
  141. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  142. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +20 -0
  143. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  144. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  145. package/dest/msg_validators/proposal_validator/index.js +3 -0
  146. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +26 -0
  147. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  148. package/dest/msg_validators/proposal_validator/proposal_validator.js +150 -0
  149. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  150. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  151. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
  152. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  153. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  154. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  155. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  156. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  157. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  158. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  159. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  160. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
  161. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  162. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  163. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  164. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  165. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  166. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  167. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  168. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  169. package/dest/msg_validators/tx_validator/data_validator.d.ts +4 -1
  170. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  171. package/dest/msg_validators/tx_validator/data_validator.js +40 -3
  172. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
  173. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  174. package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
  175. package/dest/msg_validators/tx_validator/factory.d.ts +140 -6
  176. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  177. package/dest/msg_validators/tx_validator/factory.js +259 -58
  178. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  179. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  180. package/dest/msg_validators/tx_validator/fee_payer_balance.js +24 -0
  181. package/dest/msg_validators/tx_validator/gas_validator.d.ts +100 -3
  182. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  183. package/dest/msg_validators/tx_validator/gas_validator.js +146 -67
  184. package/dest/msg_validators/tx_validator/index.d.ts +6 -1
  185. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  186. package/dest/msg_validators/tx_validator/index.js +5 -0
  187. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
  188. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  189. package/dest/msg_validators/tx_validator/metadata_validator.js +6 -6
  190. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  191. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  192. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  193. package/dest/msg_validators/tx_validator/phases_validator.d.ts +24 -3
  194. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  195. package/dest/msg_validators/tx_validator/phases_validator.js +78 -28
  196. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  197. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  198. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  199. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  200. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  201. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +23 -5
  202. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  203. package/dest/msg_validators/tx_validator/timestamp_validator.js +8 -8
  204. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  205. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  206. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  207. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +4 -2
  208. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  209. package/dest/msg_validators/tx_validator/tx_proof_validator.js +4 -2
  210. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  211. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  212. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  213. package/dest/services/data_store.d.ts +1 -1
  214. package/dest/services/data_store.d.ts.map +1 -1
  215. package/dest/services/data_store.js +14 -10
  216. package/dest/services/discv5/discV5_service.d.ts +2 -1
  217. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  218. package/dest/services/discv5/discV5_service.js +36 -9
  219. package/dest/services/dummy_service.d.ts +36 -16
  220. package/dest/services/dummy_service.d.ts.map +1 -1
  221. package/dest/services/dummy_service.js +58 -14
  222. package/dest/services/encoding.d.ts +7 -3
  223. package/dest/services/encoding.d.ts.map +1 -1
  224. package/dest/services/encoding.js +23 -15
  225. package/dest/services/gossipsub/index.d.ts +3 -0
  226. package/dest/services/gossipsub/index.d.ts.map +1 -0
  227. package/dest/services/gossipsub/index.js +2 -0
  228. package/dest/services/gossipsub/scoring.d.ts +21 -3
  229. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  230. package/dest/services/gossipsub/scoring.js +24 -7
  231. package/dest/services/gossipsub/topic_score_params.d.ts +184 -0
  232. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  233. package/dest/services/gossipsub/topic_score_params.js +363 -0
  234. package/dest/services/index.d.ts +2 -1
  235. package/dest/services/index.d.ts.map +1 -1
  236. package/dest/services/index.js +1 -0
  237. package/dest/services/libp2p/instrumentation.d.ts +5 -1
  238. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  239. package/dest/services/libp2p/instrumentation.js +49 -70
  240. package/dest/services/libp2p/libp2p_service.d.ts +118 -109
  241. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  242. package/dest/services/libp2p/libp2p_service.js +1286 -430
  243. package/dest/services/peer-manager/interface.d.ts +1 -1
  244. package/dest/services/peer-manager/metrics.d.ts +11 -2
  245. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  246. package/dest/services/peer-manager/metrics.js +45 -16
  247. package/dest/services/peer-manager/peer_manager.d.ts +7 -34
  248. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  249. package/dest/services/peer-manager/peer_manager.js +46 -23
  250. package/dest/services/peer-manager/peer_scoring.d.ts +12 -2
  251. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  252. package/dest/services/peer-manager/peer_scoring.js +99 -13
  253. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +44 -0
  254. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  255. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +534 -0
  256. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  257. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  258. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  259. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  260. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  261. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  262. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +35 -0
  263. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  264. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +136 -0
  265. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +62 -0
  266. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  267. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +176 -0
  268. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +11 -0
  269. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  270. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +7 -0
  271. package/dest/services/reqresp/config.d.ts +3 -3
  272. package/dest/services/reqresp/config.d.ts.map +1 -1
  273. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -4
  274. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  275. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  276. package/dest/services/reqresp/constants.d.ts +12 -0
  277. package/dest/services/reqresp/constants.d.ts.map +1 -0
  278. package/dest/services/reqresp/constants.js +7 -0
  279. package/dest/services/reqresp/index.d.ts +1 -1
  280. package/dest/services/reqresp/interface.d.ts +27 -18
  281. package/dest/services/reqresp/interface.d.ts.map +1 -1
  282. package/dest/services/reqresp/interface.js +23 -19
  283. package/dest/services/reqresp/metrics.d.ts +6 -5
  284. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  285. package/dest/services/reqresp/metrics.js +16 -21
  286. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  287. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  288. package/dest/services/reqresp/protocols/auth.js +2 -2
  289. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +8 -3
  290. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  291. package/dest/services/reqresp/protocols/block_txs/bitvector.js +15 -2
  292. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  293. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  294. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +35 -14
  295. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +37 -11
  296. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  297. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +85 -21
  298. package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
  299. package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
  300. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  301. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  302. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  303. package/dest/services/reqresp/protocols/index.js +0 -1
  304. package/dest/services/reqresp/protocols/ping.d.ts +1 -1
  305. package/dest/services/reqresp/protocols/status.d.ts +6 -5
  306. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  307. package/dest/services/reqresp/protocols/status.js +7 -3
  308. package/dest/services/reqresp/protocols/tx.d.ts +8 -3
  309. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  310. package/dest/services/reqresp/protocols/tx.js +21 -3
  311. package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
  312. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -5
  313. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  314. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  315. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  316. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  317. package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
  318. package/dest/services/reqresp/reqresp.d.ts +12 -69
  319. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  320. package/dest/services/reqresp/reqresp.js +448 -199
  321. package/dest/services/reqresp/status.d.ts +2 -2
  322. package/dest/services/reqresp/status.d.ts.map +1 -1
  323. package/dest/services/service.d.ts +62 -13
  324. package/dest/services/service.d.ts.map +1 -1
  325. package/dest/services/tx_collection/config.d.ts +11 -11
  326. package/dest/services/tx_collection/config.d.ts.map +1 -1
  327. package/dest/services/tx_collection/config.js +28 -27
  328. package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
  329. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  330. package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
  331. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  332. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  333. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  334. package/dest/services/tx_collection/index.d.ts +3 -2
  335. package/dest/services/tx_collection/index.d.ts.map +1 -1
  336. package/dest/services/tx_collection/index.js +1 -0
  337. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  338. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  339. package/dest/services/tx_collection/instrumentation.js +9 -13
  340. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  341. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  342. package/dest/services/tx_collection/request_tracker.js +84 -0
  343. package/dest/services/tx_collection/tx_collection.d.ts +51 -57
  344. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  345. package/dest/services/tx_collection/tx_collection.js +298 -70
  346. package/dest/services/tx_collection/tx_collection_sink.d.ts +20 -10
  347. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  348. package/dest/services/tx_collection/tx_collection_sink.js +28 -31
  349. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  350. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  351. package/dest/services/tx_collection/tx_source.js +26 -7
  352. package/dest/services/tx_file_store/config.d.ts +16 -0
  353. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  354. package/dest/services/tx_file_store/config.js +22 -0
  355. package/dest/services/tx_file_store/index.d.ts +4 -0
  356. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  357. package/dest/services/tx_file_store/index.js +3 -0
  358. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  359. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  360. package/dest/services/tx_file_store/instrumentation.js +29 -0
  361. package/dest/services/tx_file_store/tx_file_store.d.ts +46 -0
  362. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  363. package/dest/services/tx_file_store/tx_file_store.js +142 -0
  364. package/dest/services/tx_provider.d.ts +9 -5
  365. package/dest/services/tx_provider.d.ts.map +1 -1
  366. package/dest/services/tx_provider.js +23 -10
  367. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  368. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  369. package/dest/services/tx_provider_instrumentation.js +14 -14
  370. package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
  371. package/dest/test-helpers/get-ports.d.ts +1 -1
  372. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  373. package/dest/test-helpers/index.d.ts +3 -1
  374. package/dest/test-helpers/index.d.ts.map +1 -1
  375. package/dest/test-helpers/index.js +2 -0
  376. package/dest/test-helpers/make-enrs.d.ts +1 -1
  377. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  378. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  379. package/dest/test-helpers/make-test-p2p-clients.js +5 -3
  380. package/dest/test-helpers/mock-pubsub.d.ts +48 -8
  381. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  382. package/dest/test-helpers/mock-pubsub.js +115 -14
  383. package/dest/test-helpers/mock-tx-helpers.d.ts +2 -2
  384. package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -1
  385. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  386. package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
  387. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  388. package/dest/test-helpers/reqresp-nodes.js +19 -20
  389. package/dest/test-helpers/test_tx_provider.d.ts +42 -0
  390. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  391. package/dest/test-helpers/test_tx_provider.js +44 -0
  392. package/dest/test-helpers/testbench-utils.d.ts +161 -0
  393. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  394. package/dest/test-helpers/testbench-utils.js +391 -0
  395. package/dest/testbench/p2p_client_testbench_worker.d.ts +26 -2
  396. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  397. package/dest/testbench/p2p_client_testbench_worker.js +275 -131
  398. package/dest/testbench/parse_log_file.d.ts +1 -1
  399. package/dest/testbench/testbench.d.ts +1 -1
  400. package/dest/testbench/worker_client_manager.d.ts +57 -6
  401. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  402. package/dest/testbench/worker_client_manager.js +277 -44
  403. package/dest/types/index.d.ts +1 -1
  404. package/dest/util.d.ts +14 -8
  405. package/dest/util.d.ts.map +1 -1
  406. package/dest/util.js +41 -11
  407. package/dest/versioning.d.ts +3 -6
  408. package/dest/versioning.d.ts.map +1 -1
  409. package/dest/versioning.js +3 -24
  410. package/package.json +20 -18
  411. package/src/bootstrap/bootstrap.ts +16 -5
  412. package/src/client/factory.ts +137 -46
  413. package/src/client/interface.ts +87 -43
  414. package/src/client/p2p_client.ts +352 -418
  415. package/src/client/test/p2p_client.batch_tx_requester.bench.README.md +197 -0
  416. package/src/config.ts +302 -65
  417. package/src/errors/attestation-pool.error.ts +13 -0
  418. package/src/errors/p2p-service.error.ts +11 -0
  419. package/src/errors/reqresp.error.ts +0 -25
  420. package/src/errors/tx-pool.error.ts +12 -0
  421. package/src/index.ts +1 -1
  422. package/src/mem_pools/attestation_pool/attestation_pool.ts +588 -56
  423. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +760 -319
  424. package/src/mem_pools/attestation_pool/index.ts +9 -2
  425. package/src/mem_pools/attestation_pool/mocks.ts +29 -17
  426. package/src/mem_pools/index.ts +2 -2
  427. package/src/mem_pools/instrumentation.ts +56 -10
  428. package/src/mem_pools/interface.ts +5 -7
  429. package/src/mem_pools/tx_pool_v2/README.md +283 -0
  430. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  431. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +112 -0
  432. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  433. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
  434. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +122 -0
  435. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +125 -0
  436. package/src/mem_pools/tx_pool_v2/eviction/index.ts +28 -0
  437. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  438. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
  439. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  440. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  441. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
  442. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
  443. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
  444. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  445. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  446. package/src/mem_pools/tx_pool_v2/interfaces.ts +250 -0
  447. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +349 -0
  448. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  449. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +430 -0
  450. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +238 -0
  451. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1090 -0
  452. package/src/msg_validators/attestation_validator/README.md +49 -0
  453. package/src/msg_validators/attestation_validator/attestation_validator.ts +78 -33
  454. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +101 -0
  455. package/src/msg_validators/attestation_validator/index.ts +1 -0
  456. package/src/msg_validators/clock_tolerance.ts +121 -0
  457. package/src/msg_validators/index.ts +1 -1
  458. package/src/msg_validators/proposal_validator/README.md +123 -0
  459. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +30 -0
  460. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +41 -0
  461. package/src/msg_validators/proposal_validator/index.ts +3 -0
  462. package/src/msg_validators/proposal_validator/proposal_validator.ts +159 -0
  463. package/src/msg_validators/tx_validator/README.md +127 -0
  464. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
  465. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  466. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  467. package/src/msg_validators/tx_validator/archive_cache.ts +2 -2
  468. package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
  469. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  470. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  471. package/src/msg_validators/tx_validator/data_validator.ts +62 -7
  472. package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
  473. package/src/msg_validators/tx_validator/factory.ts +427 -58
  474. package/src/msg_validators/tx_validator/fee_payer_balance.ts +44 -0
  475. package/src/msg_validators/tx_validator/gas_validator.ts +211 -77
  476. package/src/msg_validators/tx_validator/index.ts +5 -0
  477. package/src/msg_validators/tx_validator/metadata_validator.ts +31 -12
  478. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  479. package/src/msg_validators/tx_validator/phases_validator.ts +90 -31
  480. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  481. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  482. package/src/msg_validators/tx_validator/timestamp_validator.ts +30 -19
  483. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  484. package/src/msg_validators/tx_validator/tx_proof_validator.ts +10 -3
  485. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  486. package/src/services/data_store.ts +14 -19
  487. package/src/services/discv5/discV5_service.ts +39 -6
  488. package/src/services/dummy_service.ts +76 -38
  489. package/src/services/encoding.ts +22 -13
  490. package/src/services/gossipsub/README.md +641 -0
  491. package/src/services/gossipsub/index.ts +2 -0
  492. package/src/services/gossipsub/scoring.ts +29 -5
  493. package/src/services/gossipsub/topic_score_params.ts +519 -0
  494. package/src/services/index.ts +1 -0
  495. package/src/services/libp2p/instrumentation.ts +54 -72
  496. package/src/services/libp2p/libp2p_service.ts +1032 -480
  497. package/src/services/peer-manager/metrics.ts +51 -16
  498. package/src/services/peer-manager/peer_manager.ts +53 -15
  499. package/src/services/peer-manager/peer_scoring.ts +96 -7
  500. package/src/services/reqresp/README.md +215 -0
  501. package/src/services/reqresp/batch-tx-requester/README.md +344 -0
  502. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +660 -0
  503. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  504. package/src/services/reqresp/batch-tx-requester/interface.ts +61 -0
  505. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +168 -0
  506. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +249 -0
  507. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +24 -0
  508. package/src/services/reqresp/config.ts +2 -2
  509. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  510. package/src/services/reqresp/constants.ts +14 -0
  511. package/src/services/reqresp/interface.ts +48 -46
  512. package/src/services/reqresp/metrics.ts +35 -27
  513. package/src/services/reqresp/protocols/auth.ts +2 -2
  514. package/src/services/reqresp/protocols/block_txs/bitvector.ts +19 -2
  515. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +44 -17
  516. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +109 -17
  517. package/src/services/reqresp/protocols/index.ts +0 -1
  518. package/src/services/reqresp/protocols/status.ts +16 -12
  519. package/src/services/reqresp/protocols/tx.ts +24 -5
  520. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  521. package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
  522. package/src/services/reqresp/reqresp.ts +68 -224
  523. package/src/services/service.ts +83 -31
  524. package/src/services/tx_collection/config.ts +42 -37
  525. package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
  526. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  527. package/src/services/tx_collection/index.ts +2 -1
  528. package/src/services/tx_collection/instrumentation.ts +5 -13
  529. package/src/services/tx_collection/request_tracker.ts +127 -0
  530. package/src/services/tx_collection/tx_collection.ts +368 -115
  531. package/src/services/tx_collection/tx_collection_sink.ts +32 -36
  532. package/src/services/tx_collection/tx_source.ts +28 -8
  533. package/src/services/tx_file_store/config.ts +37 -0
  534. package/src/services/tx_file_store/index.ts +3 -0
  535. package/src/services/tx_file_store/instrumentation.ts +36 -0
  536. package/src/services/tx_file_store/tx_file_store.ts +163 -0
  537. package/src/services/tx_provider.ts +34 -12
  538. package/src/services/tx_provider_instrumentation.ts +24 -14
  539. package/src/test-helpers/index.ts +2 -0
  540. package/src/test-helpers/make-test-p2p-clients.ts +7 -6
  541. package/src/test-helpers/mock-pubsub.ts +138 -15
  542. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  543. package/src/test-helpers/reqresp-nodes.ts +18 -30
  544. package/src/test-helpers/test_tx_provider.ts +69 -0
  545. package/src/test-helpers/testbench-utils.ts +453 -0
  546. package/src/testbench/p2p_client_testbench_worker.ts +387 -128
  547. package/src/testbench/worker_client_manager.ts +355 -46
  548. package/src/util.ts +47 -16
  549. package/src/versioning.ts +3 -33
  550. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -30
  551. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  552. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -190
  553. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -25
  554. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  555. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -197
  556. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -150
  557. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  558. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -617
  559. package/dest/mem_pools/tx_pool/index.d.ts +0 -4
  560. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  561. package/dest/mem_pools/tx_pool/index.js +0 -3
  562. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
  563. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  564. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
  565. package/dest/mem_pools/tx_pool/priority.d.ts +0 -8
  566. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  567. package/dest/mem_pools/tx_pool/priority.js +0 -10
  568. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -122
  569. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  570. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  571. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  572. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  573. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -394
  574. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  575. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  576. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -70
  577. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  578. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  579. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  580. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -45
  581. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  582. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -92
  583. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  584. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  585. package/dest/services/reqresp/protocols/block.js +0 -31
  586. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -56
  587. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  588. package/dest/services/tx_collection/fast_tx_collection.js +0 -300
  589. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -54
  590. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  591. package/dest/services/tx_collection/slow_tx_collection.js +0 -176
  592. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -256
  593. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -253
  594. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -750
  595. package/src/mem_pools/tx_pool/index.ts +0 -3
  596. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
  597. package/src/mem_pools/tx_pool/priority.ts +0 -13
  598. package/src/mem_pools/tx_pool/tx_pool.ts +0 -135
  599. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -313
  600. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -81
  601. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
  602. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -100
  603. package/src/services/reqresp/protocols/block.ts +0 -36
  604. package/src/services/tx_collection/fast_tx_collection.ts +0 -340
  605. package/src/services/tx_collection/slow_tx_collection.ts +0 -232
@@ -1,13 +1,17 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { L2Block } from '@aztec/stdlib/block';
3
1
  import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
4
2
 
5
3
  import type { PeerId } from '@libp2p/interface';
6
4
 
7
5
  import type { P2PReqRespConfig } from './config.js';
6
+ import type { ConnectionSampler } from './connection-sampler/connection_sampler.js';
8
7
  import { AuthRequest, AuthResponse } from './protocols/auth.js';
9
- import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
8
+ import {
9
+ BlockTxsRequest,
10
+ BlockTxsResponse,
11
+ calculateBlockTxsResponseSize,
12
+ } from './protocols/block_txs/block_txs_reqresp.js';
10
13
  import { StatusMessage } from './protocols/status.js';
14
+ import { calculateTxResponseSize } from './protocols/tx.js';
11
15
  import type { ReqRespStatus } from './status.js';
12
16
 
13
17
  /*
@@ -17,7 +21,6 @@ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
17
21
  export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
18
22
  export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
19
23
  export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
20
- export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
21
24
  export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
22
25
  export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
23
26
 
@@ -26,7 +29,6 @@ export enum ReqRespSubProtocol {
26
29
  STATUS = STATUS_PROTOCOL,
27
30
  GOODBYE = GOODBYE_PROTOCOL,
28
31
  TX = TX_REQ_PROTOCOL,
29
- BLOCK = BLOCK_REQ_PROTOCOL,
30
32
  AUTH = AUTH_PROTOCOL,
31
33
  BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
32
34
  }
@@ -76,32 +78,28 @@ export interface ProtocolRateLimitQuota {
76
78
  globalLimit: RateLimitQuota;
77
79
  }
78
80
 
79
- export const noopValidator = () => Promise.resolve(true);
80
-
81
81
  /**
82
82
  * A type mapping from supprotocol to it's handling function
83
83
  */
84
84
  export type ReqRespSubProtocolHandlers = Record<ReqRespSubProtocol, ReqRespSubProtocolHandler>;
85
85
 
86
- type ResponseValidator<RequestIdentifier, Response> = (
87
- request: RequestIdentifier,
88
- response: Response,
89
- peerId: PeerId,
90
- ) => Promise<boolean>;
91
-
92
- export type ReqRespSubProtocolValidators = {
93
- [S in ReqRespSubProtocol]: ResponseValidator<any, any>;
94
- };
86
+ /**
87
+ * Protocols that are always allowed without authentication, even when p2pAllowOnlyValidators is enabled.
88
+ * These are needed for the handshake and connection management flow.
89
+ * All other protocols require the remote peer to be authenticated.
90
+ */
91
+ export const UNAUTHENTICATED_ALLOWED_PROTOCOLS: ReadonlySet<ReqRespSubProtocol> = new Set([
92
+ ReqRespSubProtocol.PING,
93
+ ReqRespSubProtocol.STATUS,
94
+ ReqRespSubProtocol.AUTH,
95
+ ReqRespSubProtocol.GOODBYE,
96
+ ]);
95
97
 
96
- export const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
97
- [ReqRespSubProtocol.PING]: noopValidator,
98
- [ReqRespSubProtocol.STATUS]: noopValidator,
99
- [ReqRespSubProtocol.TX]: noopValidator,
100
- [ReqRespSubProtocol.GOODBYE]: noopValidator,
101
- [ReqRespSubProtocol.BLOCK]: noopValidator,
102
- [ReqRespSubProtocol.AUTH]: noopValidator,
103
- [ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
104
- };
98
+ /**
99
+ * Callback that checks whether a peer should be rejected from req/resp data protocols.
100
+ * Returns true if the peer should be rejected (i.e. p2pAllowOnlyValidators is on and peer is unauthenticated).
101
+ */
102
+ export type ShouldRejectPeer = (peerId: string) => boolean;
105
103
 
106
104
  /*
107
105
  * Helper class to sub-protocol validation error*/
@@ -196,10 +194,6 @@ export const subProtocolMap = {
196
194
  request: RequestableBuffer,
197
195
  response: RequestableBuffer,
198
196
  },
199
- [ReqRespSubProtocol.BLOCK]: {
200
- request: Fr, // block number
201
- response: L2Block,
202
- },
203
197
  [ReqRespSubProtocol.AUTH]: {
204
198
  request: AuthRequest,
205
199
  response: AuthResponse,
@@ -210,25 +204,28 @@ export const subProtocolMap = {
210
204
  },
211
205
  };
212
206
 
207
+ /**
208
+ * Type for a function that calculates the expected response size in KB for a given request.
209
+ */
210
+ export type ExpectedResponseSizeCalculator = (requestBuffer: Buffer) => number;
211
+
212
+ /**
213
+ * Map of sub-protocols to their expected response size calculators.
214
+ * These are used to validate that responses don't exceed expected sizes based on request parameters.
215
+ */
216
+ export const subProtocolSizeCalculators: Record<ReqRespSubProtocol, ExpectedResponseSizeCalculator> = {
217
+ [ReqRespSubProtocol.TX]: calculateTxResponseSize,
218
+ [ReqRespSubProtocol.BLOCK_TXS]: calculateBlockTxsResponseSize,
219
+ [ReqRespSubProtocol.STATUS]: () => 1,
220
+ [ReqRespSubProtocol.PING]: () => 1,
221
+ [ReqRespSubProtocol.AUTH]: () => 1,
222
+ [ReqRespSubProtocol.GOODBYE]: () => 1, // No response expected, but provide minimal limit
223
+ };
224
+
213
225
  export interface ReqRespInterface {
214
- start(
215
- subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
216
- subProtocolValidators: ReqRespSubProtocolValidators,
217
- ): Promise<void>;
218
- addSubProtocol(
219
- subProtocol: ReqRespSubProtocol,
220
- handler: ReqRespSubProtocolHandler,
221
- validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
222
- ): Promise<void>;
226
+ start(subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>): Promise<void>;
227
+ addSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void>;
223
228
  stop(): Promise<void>;
224
- sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
225
- subProtocol: SubProtocol,
226
- requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
227
- pinnedPeer: PeerId | undefined,
228
- timeoutMs?: number,
229
- maxPeers?: number,
230
- maxRetryAttempts?: number,
231
- ): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
232
229
  sendRequestToPeer(
233
230
  peerId: PeerId,
234
231
  subProtocol: ReqRespSubProtocol,
@@ -237,4 +234,9 @@ export interface ReqRespInterface {
237
234
  ): Promise<ReqRespResponse>;
238
235
 
239
236
  updateConfig(config: Partial<P2PReqRespConfig>): void;
237
+
238
+ /** Sets the callback used to reject unauthenticated peers on gated req/resp protocols. */
239
+ setShouldRejectPeer(checker: ShouldRejectPeer): void;
240
+
241
+ getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>;
240
242
  }
@@ -1,7 +1,9 @@
1
1
  // Request response metrics
2
- import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
2
+ import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
3
3
  import type { TelemetryClient, Tracer, UpDownCounter } from '@aztec/telemetry-client';
4
4
 
5
+ import { ReqRespSubProtocol } from './interface.js';
6
+
5
7
  export class ReqRespMetrics {
6
8
  public readonly tracer: Tracer;
7
9
 
@@ -18,43 +20,49 @@ export class ReqRespMetrics {
18
20
  this.tracer = telemetryClient.getTracer(name);
19
21
 
20
22
  const meter = telemetryClient.getMeter(name);
21
- this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS, {
22
- description: 'Number of requests sent to peers',
23
- unit: 'requests',
24
- valueType: ValueType.INT,
25
- });
26
- this.receivedRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS, {
27
- description: 'Number of requests received from peers',
28
- unit: 'requests',
29
- valueType: ValueType.INT,
30
- });
31
-
32
- this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS, {
33
- description: 'Number of failed outbound requests - nodes not getting valid responses',
34
- unit: 'requests',
35
- valueType: ValueType.INT,
36
- });
37
-
38
- this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS, {
39
- description: 'Number of failed inbound requests - node failing to respond to requests',
40
- unit: 'requests',
41
- valueType: ValueType.INT,
42
- });
23
+ const protocolAttrs = {
24
+ [Attributes.P2P_REQ_RESP_PROTOCOL]: [
25
+ ReqRespSubProtocol.PING,
26
+ ReqRespSubProtocol.STATUS,
27
+ ReqRespSubProtocol.GOODBYE,
28
+ ReqRespSubProtocol.TX,
29
+ ReqRespSubProtocol.AUTH,
30
+ ReqRespSubProtocol.BLOCK_TXS,
31
+ ],
32
+ };
33
+ this.sentRequests = createUpDownCounterWithDefault(meter, Metrics.P2P_REQ_RESP_SENT_REQUESTS, protocolAttrs);
34
+ this.receivedRequests = createUpDownCounterWithDefault(
35
+ meter,
36
+ Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS,
37
+ protocolAttrs,
38
+ );
39
+
40
+ this.failedOutboundRequests = createUpDownCounterWithDefault(
41
+ meter,
42
+ Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS,
43
+ protocolAttrs,
44
+ );
45
+
46
+ this.failedInboundRequests = createUpDownCounterWithDefault(
47
+ meter,
48
+ Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS,
49
+ protocolAttrs,
50
+ );
43
51
  }
44
52
 
45
- public recordRequestSent(protocol: string) {
53
+ public recordRequestSent(protocol: ReqRespSubProtocol) {
46
54
  this.sentRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
47
55
  }
48
56
 
49
- public recordRequestReceived(protocol: string) {
57
+ public recordRequestReceived(protocol: ReqRespSubProtocol) {
50
58
  this.receivedRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
51
59
  }
52
60
 
53
- public recordRequestError(protocol: string) {
61
+ public recordRequestError(protocol: ReqRespSubProtocol) {
54
62
  this.failedOutboundRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
55
63
  }
56
64
 
57
- public recordResponseError(protocol: string) {
65
+ public recordResponseError(protocol: ReqRespSubProtocol) {
58
66
  this.failedInboundRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
59
67
  }
60
68
  }
@@ -1,7 +1,7 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256 } from '@aztec/foundation/crypto';
2
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { Signature } from '@aztec/foundation/eth-signature';
4
- import { Fr } from '@aztec/foundation/fields';
5
5
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
6
6
 
7
7
  import { StatusMessage } from './status.js';
@@ -1,5 +1,7 @@
1
1
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
2
2
 
3
+ import { MAX_TXS_PER_BLOCK } from '../../constants.js';
4
+
3
5
  /**
4
6
  * BitVector helper class for representing and serializing bit vectors
5
7
  */
@@ -56,12 +58,20 @@ export class BitVector {
56
58
  }
57
59
 
58
60
  /**
59
- * Returns all indices which are set to true
60
- * */
61
+ * Returns all indices which are set to true.
62
+ * Ordered by index. No duplicates.
63
+ */
61
64
  getTrueIndices(): number[] {
62
65
  return Array.from({ length: this.length }, (_, i) => i).filter(i => this.isSet(i));
63
66
  }
64
67
 
68
+ /**
69
+ * Returns true if no indices are set to true
70
+ * */
71
+ isEmpty(): boolean {
72
+ return this.getTrueIndices().length === 0;
73
+ }
74
+
65
75
  /**
66
76
  * Serializes the BitVector object into a Buffer
67
77
  *
@@ -80,6 +90,13 @@ export class BitVector {
80
90
  const reader = BufferReader.asReader(buffer);
81
91
  const length = reader.readNumber();
82
92
 
93
+ if (length < 0) {
94
+ throw new Error(`BitVector length ${length} cannot be negative`);
95
+ }
96
+ if (length > MAX_TXS_PER_BLOCK) {
97
+ throw new Error(`BitVector length ${length} exceeds maximum ${MAX_TXS_PER_BLOCK}`);
98
+ }
99
+
83
100
  const bitBuffer = reader.readBytes(BitVector.byteLength(length));
84
101
  return new BitVector(bitBuffer, length);
85
102
  }
@@ -1,9 +1,10 @@
1
- import { TxArray } from '@aztec/stdlib/tx';
1
+ import type { L2BlockSource } from '@aztec/stdlib/block';
2
+ import { TxArray, TxHash } from '@aztec/stdlib/tx';
2
3
 
3
4
  import type { PeerId } from '@libp2p/interface';
4
5
 
5
- import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
6
- import type { TxPool } from '../../../../mem_pools/index.js';
6
+ import type { AttestationPoolApi } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
7
+ import type { TxPoolV2 } from '../../../../mem_pools/tx_pool_v2/interfaces.js';
7
8
  import type { ReqRespSubProtocolHandler } from '../../interface.js';
8
9
  import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
9
10
  import { BitVector } from './bitvector.js';
@@ -12,10 +13,15 @@ import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
12
13
  /**
13
14
  * Handler for block txs requests
14
15
  * @param attestationPool - the attestation pool to check for block proposals
15
- * @param mempools - the mempools containing the tx pool
16
+ * @param archiver - the archiver to look up blocks by archive root
17
+ * @param txPool - the tx pool to fetch transactions from
16
18
  * @returns the BlockTxs request handler
17
19
  */
18
- export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler {
20
+ export function reqRespBlockTxsHandler(
21
+ attestationPool: AttestationPoolApi,
22
+ archiver: L2BlockSource,
23
+ txPool: TxPoolV2,
24
+ ): ReqRespSubProtocolHandler {
19
25
  /**
20
26
  * Handler for block txs requests
21
27
  * @param msg - the block txs request message
@@ -30,23 +36,44 @@ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool:
30
36
  throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
31
37
  }
32
38
 
33
- const blockProposal = await attestationPool.getBlockProposal(request.blockHash.toString());
39
+ // In principle assume we haven't found the block. This is how that is signaled to the requester.
40
+ let availableIndicesBitVector: BitVector = BitVector.init(0, []);
41
+ // We always try to service the explicitly requested tx hashes, even if we don't have the block.
42
+ const requestedTxsHashes: Set<string> = new Set(request.txHashes.map(h => h.toString()));
34
43
 
35
- if (!blockProposal) {
36
- throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
44
+ // First try attestation pool, then fall back to archiver.
45
+ let blockTxHashes = (await attestationPool.getBlockProposalByArchive(request.archiveRoot.toString()))?.txHashes;
46
+ if (!blockTxHashes) {
47
+ blockTxHashes = (await archiver.getBlock({ archive: request.archiveRoot }))?.body.txEffects.map(
48
+ effect => effect.txHash,
49
+ );
37
50
  }
38
51
 
39
- const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
40
- //Map txs in the pool to their indices in the block proposal
41
- const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
42
- const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
52
+ // If we have found the block,
53
+ if (blockTxHashes) {
54
+ // First confirm that we are talking about the same block (up to tx hashes and order).
55
+ // If we are not, then we can't:
56
+ // 1. Use the indices from the request to get the txs from the pool.
57
+ // 2. Respond to the peer with the txs we have using indices.
58
+ const blockTxHashesCommitment = BlockTxsRequest.computeBlockTxHashesCommitment(blockTxHashes);
59
+ if (blockTxHashesCommitment.equals(request.blockTxHashesCommitment)) {
60
+ // In that case, we can also get the available indices from the pool.
61
+ const txsAvailableInPool = await txPool.hasTxs(blockTxHashes);
62
+ // Map txs in the pool to their indices in the block
63
+ const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
64
+ availableIndicesBitVector = BitVector.init(blockTxHashes.length, availableIndices);
43
65
 
44
- const requestedIndices = new Set(request.txIndices.getTrueIndices());
45
- const requestedTxsHashes = blockProposal.txHashes.filter((_, idx) => requestedIndices.has(idx));
46
-
47
- const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
66
+ // We add the requested tx hashes (by index) to the list of tx hashes we are sending to the peer.
67
+ const requestedIndices = new Set(request.txIndices.getTrueIndices());
68
+ blockTxHashes.filter((_, idx) => requestedIndices.has(idx)).forEach(h => requestedTxsHashes.add(h.toString()));
69
+ }
70
+ }
48
71
 
49
- const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
72
+ // Finally, get the txs from the pool and create the response.
73
+ const responseTxs = (
74
+ await txPool.getTxsByHash(Array.from(requestedTxsHashes).map(h => TxHash.fromString(h)))
75
+ ).filter(tx => !!tx);
76
+ const response = new BlockTxsResponse(new TxArray(...responseTxs), availableIndicesBitVector);
50
77
 
51
78
  return response.toBuffer();
52
79
  };
@@ -1,20 +1,82 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
- import { TxArray } from '@aztec/stdlib/tx';
4
+ import { MAX_TX_SIZE_KB } from '@aztec/stdlib/p2p';
5
+ import { TxArray, type TxHash, TxHashArray } from '@aztec/stdlib/tx';
6
+
7
+ import { createHash } from 'node:crypto';
4
8
 
5
9
  import { BitVector } from './bitvector.js';
6
10
 
11
+ /** Minimal interface for a block source that provides tx hashes and an archive root. */
12
+ export interface BlockTxsSource {
13
+ txHashes: TxHash[];
14
+ archive: Fr;
15
+ }
16
+
7
17
  /**
8
18
  * Request message for requesting specific transactions from a block
9
19
  */
10
20
  export class BlockTxsRequest {
11
21
  constructor(
12
- readonly blockHash: Fr, // 32 byte hash of the proposed block header
13
- // BitVector indicating which txs from the proposal we are requesting
14
- // 1 means we want the tx, 0 means we don't
22
+ // Archive root after the proposed block is applied (proposal identifier).
23
+ readonly archiveRoot: Fr,
24
+ // BitVector indicating which txs from the block (proposal) we are requesting
25
+ // 1 means we want the tx, 0 means we don't.
26
+ // This will only return txs in the response if the peer has the block (proposal).
15
27
  readonly txIndices: BitVector,
28
+ // If we ask for txs via indices, the responder needs to be sure that we are talking about the same block.
29
+ // Unfortunately, the archive root is not enough, since it's possible for the peer to have seen a different
30
+ // block (proposal) with the same archive root but different txs. We include a commitment to the tx hashes
31
+ // so that the responder can verify this (for its own sake, and not be penalized).
32
+ readonly blockTxHashesCommitment: Buffer32,
33
+ // Explicit hashes of txs we are requesting (optional). The peer will try to serve these txs even if
34
+ // it doesn't have the block. If the requester lists txs from the block here, this serves as a fallback.
35
+ // Note: if a hash here is NOT part of the block (proposal), the peer can decide to return it or not.
36
+ readonly txHashes: TxHashArray,
16
37
  ) {}
17
38
 
39
+ static computeBlockTxHashesCommitment(blockTxHashes: TxHash[]): Buffer32 {
40
+ return Buffer32.fromBuffer(createHash('sha256').update(serializeToBuffer(blockTxHashes)).digest());
41
+ }
42
+
43
+ /**
44
+ * Creates new BlockTxsRequest given a block txs source and missing tx hashes.
45
+ *
46
+ * @param blockTxsSource - The block or proposal for which we are making the request
47
+ * @param missingTxHashes - Tx hashes from the source we are missing
48
+ * @param includeFullTxHashes - Whether to include full list of missing tx hashes in the request or just Bitvector indices
49
+ *
50
+ * @returns undefined if there were no missingTxHashes matching the source hashes, otherwise
51
+ * returns new BlockTxsRequest
52
+ */
53
+ static fromTxsSourceAndMissingTxs(
54
+ blockTxsSource: BlockTxsSource,
55
+ missingTxHashes: TxHash[],
56
+ includeFullTxHashes = false,
57
+ ): BlockTxsRequest | undefined {
58
+ if (missingTxHashes.length === 0) {
59
+ return undefined; // No missing txs to request
60
+ }
61
+
62
+ const missingHashesSet = new Set(missingTxHashes.map(t => t.toString()));
63
+
64
+ // We cannot request txs that are not part of the block
65
+ if (!missingHashesSet.isSubsetOf(new Set(blockTxsSource.txHashes.map(t => t.toString())))) {
66
+ return undefined;
67
+ }
68
+
69
+ const missingIndices = blockTxsSource.txHashes
70
+ .map((hash, idx) => (missingHashesSet.has(hash.toString()) ? idx : -1))
71
+ .filter(i => i != -1);
72
+
73
+ const requestBitVector = BitVector.init(blockTxsSource.txHashes.length, missingIndices);
74
+ const hashes = includeFullTxHashes ? new TxHashArray(...missingTxHashes) : new TxHashArray();
75
+ const commitment = BlockTxsRequest.computeBlockTxHashesCommitment(blockTxsSource.txHashes);
76
+
77
+ return new BlockTxsRequest(blockTxsSource.archive, requestBitVector, commitment, hashes);
78
+ }
79
+
18
80
  /**
19
81
  * Deserializes the BlockTxRequest object from a Buffer
20
82
  * @param buffer - Buffer or BufferReader object to deserialize
@@ -22,10 +84,12 @@ export class BlockTxsRequest {
22
84
  */
23
85
  static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
24
86
  const reader = BufferReader.asReader(buffer);
25
- const blockHash = Fr.fromBuffer(reader);
87
+ const archiveRoot = Fr.fromBuffer(reader);
26
88
  const txIndices = BitVector.fromBuffer(reader);
89
+ const commitment = Buffer32.fromBuffer(reader);
90
+ const txHashes = TxHashArray.fromBuffer(reader);
27
91
 
28
- return new BlockTxsRequest(blockHash, txIndices);
92
+ return new BlockTxsRequest(archiveRoot, txIndices, commitment, txHashes);
29
93
  }
30
94
 
31
95
  /**
@@ -33,7 +97,12 @@ export class BlockTxsRequest {
33
97
  * @returns Buffer representation of the BlockTxRequest object
34
98
  */
35
99
  toBuffer(): Buffer {
36
- return serializeToBuffer([this.blockHash, this.txIndices.toBuffer()]);
100
+ return serializeToBuffer([
101
+ this.archiveRoot,
102
+ this.txIndices.toBuffer(),
103
+ this.blockTxHashesCommitment.toBuffer(),
104
+ this.txHashes.toBuffer(),
105
+ ]);
37
106
  }
38
107
  }
39
108
 
@@ -42,13 +111,23 @@ export class BlockTxsRequest {
42
111
  */
43
112
  export class BlockTxsResponse {
44
113
  constructor(
45
- readonly blockHash: Fr,
46
- readonly txs: TxArray, // List of transactions we requested and peer has
114
+ // List of transactions we requested and peer has.
115
+ readonly txs: TxArray,
47
116
  // BitVector indicating which txs from the proposal are available at the peer
48
- // 1 means the tx is available, 0 means it is not
117
+ // 1 means the tx is available, 0 means it is not.
118
+ // The vector should be empty to signal that the peer doesn't have the block.
119
+ // Otherwise, it should be a subset of the indices of the block tx hashes.
49
120
  readonly txIndices: BitVector,
50
121
  ) {}
51
122
 
123
+ /**
124
+ * Whether the response indicates that the peer has the block.
125
+ * @returns True if the peer has the block, false otherwise.
126
+ */
127
+ peerHasBlock(): boolean {
128
+ return this.txIndices.getLength() > 0;
129
+ }
130
+
52
131
  /**
53
132
  * Deserializes the BlockTxResponse object from a Buffer
54
133
  * @param buffer - Buffer or BufferReader object to deserialize
@@ -56,24 +135,37 @@ export class BlockTxsResponse {
56
135
  */
57
136
  static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
58
137
  const reader = BufferReader.asReader(buffer);
59
- const blockHash = Fr.fromBuffer(reader);
60
138
  const txs = TxArray.fromBuffer(reader);
61
139
  const txIndices = BitVector.fromBuffer(reader);
62
140
 
63
- return new BlockTxsResponse(blockHash, txs, txIndices);
141
+ return new BlockTxsResponse(txs, txIndices);
64
142
  }
65
143
 
66
144
  /**
67
145
  * Serializes the BlockTxResponse object into a Buffer
68
- * @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
69
- * thus we serialize it last
70
146
  * @returns Buffer representation of the BlockTxResponse object
71
147
  */
72
148
  toBuffer(): Buffer {
73
- return serializeToBuffer([this.blockHash, this.txs.toBuffer(), this.txIndices.toBuffer()]);
149
+ return serializeToBuffer([this.txs.toBuffer(), this.txIndices.toBuffer()]);
74
150
  }
75
151
 
76
152
  static empty(): BlockTxsResponse {
77
- return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
153
+ return new BlockTxsResponse(new TxArray(), BitVector.init(0, []));
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Calculate the expected response size for a BLOCK_TXS request.
159
+ * @param requestBuffer - The serialized request buffer containing BlockTxsRequest
160
+ * @returns Expected response size in KB
161
+ */
162
+ export function calculateBlockTxsResponseSize(requestBuffer: Buffer): number {
163
+ try {
164
+ const request = BlockTxsRequest.fromBuffer(requestBuffer);
165
+ const requestedTxCount = request.txIndices.getTrueIndices().length;
166
+ return requestedTxCount * MAX_TX_SIZE_KB + 1; // +1 KB overhead for serialization
167
+ } catch {
168
+ // If we can't parse the request, fall back to allowing a single transaction response
169
+ return MAX_TX_SIZE_KB + 1;
78
170
  }
79
171
  }
@@ -5,6 +5,5 @@ export * from './ping.js';
5
5
  export * from './status.js';
6
6
  export * from './tx.js';
7
7
  export * from './goodbye.js';
8
- export * from './block.js';
9
8
  export * from './auth.js';
10
9
  export * from './block_txs/index.js';
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { Buffer32 } from '@aztec/foundation/buffer';
2
3
  import type { Logger } from '@aztec/foundation/log';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -6,6 +7,8 @@ import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib
6
7
 
7
8
  import type { PeerId } from '@libp2p/interface';
8
9
 
10
+ import { MAX_BLOCK_HASH_STRING_LENGTH, MAX_VERSION_STRING_LENGTH } from '../constants.js';
11
+
9
12
  /*
10
13
  * P2P Status Message
11
14
  * It is used to establish Status handshake between to peers
@@ -15,12 +18,13 @@ import type { PeerId } from '@libp2p/interface';
15
18
  export class StatusMessage {
16
19
  constructor(
17
20
  readonly compressedComponentsVersion: string,
18
- readonly latestBlockNumber: number,
21
+ readonly latestBlockNumber: BlockNumber,
19
22
  readonly latestBlockHash: string,
20
- readonly finalizedBlockNumber: number,
23
+ readonly finalizedBlockNumber: BlockNumber,
24
+ ) {
21
25
  //TODO: add finalizedBlockHash
22
26
  //readonly finalizedBlockHash: string,
23
- ) {}
27
+ }
24
28
 
25
29
  /**
26
30
  * Deserializes the StatusMessage object from a Buffer.
@@ -30,12 +34,12 @@ export class StatusMessage {
30
34
  static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
31
35
  const reader = BufferReader.asReader(buffer);
32
36
  return new StatusMessage(
33
- reader.readString(), // compressedComponentsVersion
34
- reader.readNumber(), // latestBlockNumber
35
- reader.readString(), // latestBlockHash
36
- reader.readNumber(), // finalizedBlockNumber
37
+ reader.readString(MAX_VERSION_STRING_LENGTH), // compressedComponentsVersion
38
+ BlockNumber(reader.readNumber()), // latestBlockNumber
39
+ reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // latestBlockHash
40
+ BlockNumber(reader.readNumber()), // finalizedBlockNumber
37
41
  //TODO: add finalizedBlockHash
38
- //reader.readString(), // finalizedBlockHash
42
+ //reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // finalizedBlockHash
39
43
  );
40
44
  }
41
45
 
@@ -63,9 +67,9 @@ export class StatusMessage {
63
67
  static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
64
68
  return new StatusMessage(
65
69
  version,
66
- syncStatus.latestBlockNumber,
70
+ BlockNumber(syncStatus.latestBlockNumber),
67
71
  syncStatus.latestBlockHash,
68
- syncStatus.finalizedBlockNumber,
72
+ BlockNumber(syncStatus.finalizedBlockNumber),
69
73
  //TODO: add finalizedBlockHash
70
74
  );
71
75
  }
@@ -73,9 +77,9 @@ export class StatusMessage {
73
77
  static random(): StatusMessage {
74
78
  return new StatusMessage(
75
79
  '1.0.0',
76
- Math.floor(Math.random() * 100),
80
+ BlockNumber(Math.floor(Math.random() * 100)),
77
81
  Buffer32.random().toString(),
78
- Math.floor(Math.random() * 100),
82
+ BlockNumber(Math.floor(Math.random() * 100)),
79
83
  //TODO: add finalizedBlockHash
80
84
  );
81
85
  }