@aztec/p2p 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (575) hide show
  1. package/README.md +130 -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 +26 -10
  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 +70 -21
  8. package/dest/client/interface.d.ts +104 -41
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +72 -70
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +681 -346
  13. package/dest/config.d.ts +171 -89
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +169 -58
  16. package/dest/errors/p2p-service.error.d.ts +9 -0
  17. package/dest/errors/p2p-service.error.d.ts.map +1 -0
  18. package/dest/errors/p2p-service.error.js +10 -0
  19. package/dest/errors/reqresp.error.d.ts +9 -16
  20. package/dest/errors/reqresp.error.d.ts.map +1 -1
  21. package/dest/errors/reqresp.error.js +10 -17
  22. package/dest/errors/tx-pool.error.d.ts +8 -0
  23. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  24. package/dest/errors/tx-pool.error.js +9 -0
  25. package/dest/index.d.ts +2 -2
  26. package/dest/index.d.ts.map +1 -1
  27. package/dest/index.js +1 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +154 -77
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool.js +518 -3
  31. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  32. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +694 -295
  34. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  35. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/index.js +1 -2
  37. package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/mocks.js +19 -13
  40. package/dest/mem_pools/index.d.ts +3 -3
  41. package/dest/mem_pools/index.d.ts.map +1 -1
  42. package/dest/mem_pools/index.js +1 -1
  43. package/dest/mem_pools/instrumentation.d.ts +14 -1
  44. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  45. package/dest/mem_pools/instrumentation.js +51 -12
  46. package/dest/mem_pools/interface.d.ts +6 -7
  47. package/dest/mem_pools/interface.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  49. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  50. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  51. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +39 -0
  52. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  53. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +97 -0
  54. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  55. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  56. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  64. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +97 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +11 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/index.js +12 -0
  69. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  70. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  72. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
  73. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
  75. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  76. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
  78. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  79. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
  81. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  82. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
  84. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  85. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  86. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
  87. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  88. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  89. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  90. package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
  91. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  92. package/dest/mem_pools/tx_pool_v2/index.js +5 -0
  93. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  94. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  95. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  96. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +243 -0
  97. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  98. package/dest/mem_pools/tx_pool_v2/interfaces.js +11 -0
  99. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +137 -0
  100. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  101. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +223 -0
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +122 -0
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  107. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +368 -0
  108. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +68 -0
  109. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  110. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +178 -0
  111. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +91 -0
  112. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  113. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +1013 -0
  114. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +12 -5
  115. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  116. package/dest/msg_validators/attestation_validator/attestation_validator.js +78 -22
  117. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +11 -7
  118. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  119. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +25 -17
  120. package/dest/msg_validators/index.d.ts +2 -2
  121. package/dest/msg_validators/index.d.ts.map +1 -1
  122. package/dest/msg_validators/index.js +1 -1
  123. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +16 -0
  124. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  125. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +14 -0
  126. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +16 -0
  127. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  128. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +26 -0
  129. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  130. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  131. package/dest/msg_validators/proposal_validator/index.js +3 -0
  132. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +40 -0
  133. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  134. package/dest/msg_validators/proposal_validator/proposal_validator.js +186 -0
  135. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  136. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
  138. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  139. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  141. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  142. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  143. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  144. package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
  145. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
  147. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  148. package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
  149. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  150. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  151. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  152. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  153. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  154. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  155. package/dest/msg_validators/tx_validator/data_validator.d.ts +4 -1
  156. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  157. package/dest/msg_validators/tx_validator/data_validator.js +40 -3
  158. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
  159. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  160. package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
  161. package/dest/msg_validators/tx_validator/factory.d.ts +137 -6
  162. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  163. package/dest/msg_validators/tx_validator/factory.js +268 -58
  164. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  165. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  166. package/dest/msg_validators/tx_validator/fee_payer_balance.js +24 -0
  167. package/dest/msg_validators/tx_validator/gas_validator.d.ts +105 -3
  168. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  169. package/dest/msg_validators/tx_validator/gas_validator.js +146 -67
  170. package/dest/msg_validators/tx_validator/index.d.ts +6 -1
  171. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  172. package/dest/msg_validators/tx_validator/index.js +5 -0
  173. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
  174. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  175. package/dest/msg_validators/tx_validator/metadata_validator.js +6 -6
  176. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  177. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  178. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  179. package/dest/msg_validators/tx_validator/phases_validator.d.ts +24 -3
  180. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  181. package/dest/msg_validators/tx_validator/phases_validator.js +75 -27
  182. package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
  183. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  184. package/dest/msg_validators/tx_validator/size_validator.js +23 -0
  185. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  186. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  187. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +22 -5
  188. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  189. package/dest/msg_validators/tx_validator/timestamp_validator.js +8 -8
  190. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
  191. package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
  192. package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
  193. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +4 -2
  194. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  195. package/dest/msg_validators/tx_validator/tx_proof_validator.js +4 -2
  196. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  197. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  198. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  199. package/dest/services/data_store.d.ts +1 -1
  200. package/dest/services/data_store.d.ts.map +1 -1
  201. package/dest/services/data_store.js +14 -10
  202. package/dest/services/discv5/discV5_service.d.ts +13 -2
  203. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  204. package/dest/services/discv5/discV5_service.js +120 -24
  205. package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
  206. package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
  207. package/dest/services/discv5/persisted_enr_store.js +145 -0
  208. package/dest/services/dummy_service.d.ts +40 -16
  209. package/dest/services/dummy_service.d.ts.map +1 -1
  210. package/dest/services/dummy_service.js +61 -14
  211. package/dest/services/encoding.d.ts +24 -7
  212. package/dest/services/encoding.d.ts.map +1 -1
  213. package/dest/services/encoding.js +48 -30
  214. package/dest/services/gossipsub/index.d.ts +3 -0
  215. package/dest/services/gossipsub/index.d.ts.map +1 -0
  216. package/dest/services/gossipsub/index.js +2 -0
  217. package/dest/services/gossipsub/scoring.d.ts +21 -3
  218. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  219. package/dest/services/gossipsub/scoring.js +24 -7
  220. package/dest/services/gossipsub/topic_score_params.d.ts +167 -0
  221. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  222. package/dest/services/gossipsub/topic_score_params.js +336 -0
  223. package/dest/services/index.d.ts +2 -1
  224. package/dest/services/index.d.ts.map +1 -1
  225. package/dest/services/index.js +1 -0
  226. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  227. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  228. package/dest/services/libp2p/instrumentation.js +43 -71
  229. package/dest/services/libp2p/libp2p_service.d.ts +127 -54
  230. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  231. package/dest/services/libp2p/libp2p_service.js +1324 -556
  232. package/dest/services/peer-manager/metrics.d.ts +9 -2
  233. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  234. package/dest/services/peer-manager/metrics.js +39 -21
  235. package/dest/services/peer-manager/peer_manager.d.ts +21 -4
  236. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  237. package/dest/services/peer-manager/peer_manager.js +87 -38
  238. package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
  239. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  240. package/dest/services/peer-manager/peer_scoring.js +134 -19
  241. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +44 -0
  242. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
  243. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +534 -0
  244. package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
  245. package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
  246. package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
  247. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
  248. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
  249. package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
  250. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +35 -0
  251. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
  252. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +136 -0
  253. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +62 -0
  254. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
  255. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +176 -0
  256. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +11 -0
  257. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
  258. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +7 -0
  259. package/dest/services/reqresp/config.d.ts +15 -3
  260. package/dest/services/reqresp/config.d.ts.map +1 -1
  261. package/dest/services/reqresp/config.js +11 -0
  262. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
  263. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  264. package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
  265. package/dest/services/reqresp/constants.d.ts +12 -0
  266. package/dest/services/reqresp/constants.d.ts.map +1 -0
  267. package/dest/services/reqresp/constants.js +7 -0
  268. package/dest/services/reqresp/interface.d.ts +27 -18
  269. package/dest/services/reqresp/interface.d.ts.map +1 -1
  270. package/dest/services/reqresp/interface.js +23 -19
  271. package/dest/services/reqresp/metrics.d.ts +6 -5
  272. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  273. package/dest/services/reqresp/metrics.js +16 -21
  274. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  275. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  276. package/dest/services/reqresp/protocols/auth.js +2 -2
  277. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +8 -3
  278. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  279. package/dest/services/reqresp/protocols/block_txs/bitvector.js +15 -2
  280. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
  281. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  282. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +35 -14
  283. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +37 -9
  284. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  285. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +85 -21
  286. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  287. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  288. package/dest/services/reqresp/protocols/index.js +0 -1
  289. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  290. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  291. package/dest/services/reqresp/protocols/status.js +4 -1
  292. package/dest/services/reqresp/protocols/tx.d.ts +8 -3
  293. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  294. package/dest/services/reqresp/protocols/tx.js +21 -3
  295. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  296. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  297. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  298. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  299. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  300. package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
  301. package/dest/services/reqresp/reqresp.d.ts +12 -29
  302. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  303. package/dest/services/reqresp/reqresp.js +480 -200
  304. package/dest/services/service.d.ts +78 -13
  305. package/dest/services/service.d.ts.map +1 -1
  306. package/dest/services/tx_collection/config.d.ts +11 -11
  307. package/dest/services/tx_collection/config.d.ts.map +1 -1
  308. package/dest/services/tx_collection/config.js +28 -27
  309. package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
  310. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  311. package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
  312. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  313. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  314. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  315. package/dest/services/tx_collection/index.d.ts +3 -2
  316. package/dest/services/tx_collection/index.d.ts.map +1 -1
  317. package/dest/services/tx_collection/index.js +1 -0
  318. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  319. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  320. package/dest/services/tx_collection/instrumentation.js +9 -13
  321. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  322. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  323. package/dest/services/tx_collection/request_tracker.js +84 -0
  324. package/dest/services/tx_collection/tx_collection.d.ts +49 -55
  325. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  326. package/dest/services/tx_collection/tx_collection.js +299 -71
  327. package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
  328. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  329. package/dest/services/tx_collection/tx_collection_sink.js +28 -31
  330. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  331. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  332. package/dest/services/tx_collection/tx_source.js +29 -7
  333. package/dest/services/tx_file_store/config.d.ts +16 -0
  334. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  335. package/dest/services/tx_file_store/config.js +22 -0
  336. package/dest/services/tx_file_store/index.d.ts +4 -0
  337. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  338. package/dest/services/tx_file_store/index.js +3 -0
  339. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  340. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  341. package/dest/services/tx_file_store/instrumentation.js +29 -0
  342. package/dest/services/tx_file_store/tx_file_store.d.ts +46 -0
  343. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  344. package/dest/services/tx_file_store/tx_file_store.js +142 -0
  345. package/dest/services/tx_provider.d.ts +9 -6
  346. package/dest/services/tx_provider.d.ts.map +1 -1
  347. package/dest/services/tx_provider.js +23 -10
  348. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  349. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  350. package/dest/services/tx_provider_instrumentation.js +14 -14
  351. package/dest/test-helpers/index.d.ts +3 -1
  352. package/dest/test-helpers/index.d.ts.map +1 -1
  353. package/dest/test-helpers/index.js +2 -0
  354. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  355. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  356. package/dest/test-helpers/make-test-p2p-clients.js +5 -3
  357. package/dest/test-helpers/mock-pubsub.d.ts +46 -6
  358. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  359. package/dest/test-helpers/mock-pubsub.js +115 -14
  360. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  361. package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
  362. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  363. package/dest/test-helpers/reqresp-nodes.js +19 -20
  364. package/dest/test-helpers/test_tx_provider.d.ts +42 -0
  365. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
  366. package/dest/test-helpers/test_tx_provider.js +44 -0
  367. package/dest/test-helpers/testbench-utils.d.ts +164 -0
  368. package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
  369. package/dest/test-helpers/testbench-utils.js +400 -0
  370. package/dest/testbench/p2p_client_testbench_worker.d.ts +26 -2
  371. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  372. package/dest/testbench/p2p_client_testbench_worker.js +289 -131
  373. package/dest/testbench/worker_client_manager.d.ts +57 -6
  374. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  375. package/dest/testbench/worker_client_manager.js +277 -44
  376. package/dest/util.d.ts +13 -8
  377. package/dest/util.d.ts.map +1 -1
  378. package/dest/util.js +35 -14
  379. package/dest/versioning.d.ts +3 -6
  380. package/dest/versioning.d.ts.map +1 -1
  381. package/dest/versioning.js +3 -24
  382. package/package.json +18 -18
  383. package/src/bootstrap/bootstrap.ts +24 -7
  384. package/src/client/factory.ts +141 -46
  385. package/src/client/interface.ts +113 -49
  386. package/src/client/p2p_client.ts +342 -418
  387. package/src/client/test/p2p_client.batch_tx_requester.bench.README.md +197 -0
  388. package/src/config.ts +298 -66
  389. package/src/errors/p2p-service.error.ts +11 -0
  390. package/src/errors/reqresp.error.ts +13 -19
  391. package/src/errors/tx-pool.error.ts +12 -0
  392. package/src/index.ts +1 -1
  393. package/src/mem_pools/attestation_pool/attestation_pool.ts +594 -76
  394. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +796 -329
  395. package/src/mem_pools/attestation_pool/index.ts +9 -2
  396. package/src/mem_pools/attestation_pool/mocks.ts +29 -17
  397. package/src/mem_pools/index.ts +2 -2
  398. package/src/mem_pools/instrumentation.ts +48 -13
  399. package/src/mem_pools/interface.ts +5 -7
  400. package/src/mem_pools/tx_pool_v2/README.md +283 -0
  401. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  402. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +112 -0
  403. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  404. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
  405. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +122 -0
  406. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +125 -0
  407. package/src/mem_pools/tx_pool_v2/eviction/index.ts +28 -0
  408. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  409. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
  410. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  411. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  412. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
  413. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
  414. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
  415. package/src/mem_pools/tx_pool_v2/index.ts +12 -0
  416. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  417. package/src/mem_pools/tx_pool_v2/interfaces.ts +274 -0
  418. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +349 -0
  419. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  420. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +465 -0
  421. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +252 -0
  422. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1215 -0
  423. package/src/msg_validators/attestation_validator/README.md +49 -0
  424. package/src/msg_validators/attestation_validator/attestation_validator.ts +71 -24
  425. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +34 -23
  426. package/src/msg_validators/index.ts +1 -1
  427. package/src/msg_validators/proposal_validator/README.md +123 -0
  428. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +32 -0
  429. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +49 -0
  430. package/src/msg_validators/proposal_validator/index.ts +3 -0
  431. package/src/msg_validators/proposal_validator/proposal_validator.ts +198 -0
  432. package/src/msg_validators/tx_validator/README.md +129 -0
  433. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
  434. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  435. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  436. package/src/msg_validators/tx_validator/archive_cache.ts +2 -2
  437. package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
  438. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  439. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  440. package/src/msg_validators/tx_validator/data_validator.ts +62 -7
  441. package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
  442. package/src/msg_validators/tx_validator/factory.ts +431 -57
  443. package/src/msg_validators/tx_validator/fee_payer_balance.ts +44 -0
  444. package/src/msg_validators/tx_validator/gas_validator.ts +206 -76
  445. package/src/msg_validators/tx_validator/index.ts +5 -0
  446. package/src/msg_validators/tx_validator/metadata_validator.ts +31 -12
  447. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  448. package/src/msg_validators/tx_validator/phases_validator.ts +87 -30
  449. package/src/msg_validators/tx_validator/size_validator.ts +22 -0
  450. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  451. package/src/msg_validators/tx_validator/timestamp_validator.ts +29 -19
  452. package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
  453. package/src/msg_validators/tx_validator/tx_proof_validator.ts +10 -3
  454. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  455. package/src/services/data_store.ts +14 -19
  456. package/src/services/discv5/discV5_service.ts +127 -15
  457. package/src/services/discv5/persisted_enr_store.ts +158 -0
  458. package/src/services/dummy_service.ts +82 -38
  459. package/src/services/encoding.ts +46 -29
  460. package/src/services/gossipsub/README.md +663 -0
  461. package/src/services/gossipsub/index.ts +2 -0
  462. package/src/services/gossipsub/scoring.ts +29 -5
  463. package/src/services/gossipsub/topic_score_params.ts +478 -0
  464. package/src/services/index.ts +1 -0
  465. package/src/services/libp2p/instrumentation.ts +48 -75
  466. package/src/services/libp2p/libp2p_service.ts +1073 -607
  467. package/src/services/peer-manager/metrics.ts +46 -21
  468. package/src/services/peer-manager/peer_manager.ts +96 -29
  469. package/src/services/peer-manager/peer_scoring.ts +130 -12
  470. package/src/services/reqresp/README.md +194 -0
  471. package/src/services/reqresp/batch-tx-requester/README.md +344 -0
  472. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +660 -0
  473. package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
  474. package/src/services/reqresp/batch-tx-requester/interface.ts +61 -0
  475. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +168 -0
  476. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +249 -0
  477. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +24 -0
  478. package/src/services/reqresp/config.ts +19 -2
  479. package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
  480. package/src/services/reqresp/constants.ts +14 -0
  481. package/src/services/reqresp/interface.ts +48 -46
  482. package/src/services/reqresp/metrics.ts +35 -27
  483. package/src/services/reqresp/protocols/auth.ts +2 -2
  484. package/src/services/reqresp/protocols/block_txs/bitvector.ts +19 -2
  485. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +44 -17
  486. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +109 -17
  487. package/src/services/reqresp/protocols/index.ts +0 -1
  488. package/src/services/reqresp/protocols/status.ts +7 -4
  489. package/src/services/reqresp/protocols/tx.ts +24 -5
  490. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  491. package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
  492. package/src/services/reqresp/reqresp.ts +107 -223
  493. package/src/services/service.ts +102 -31
  494. package/src/services/tx_collection/config.ts +42 -37
  495. package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
  496. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  497. package/src/services/tx_collection/index.ts +2 -1
  498. package/src/services/tx_collection/instrumentation.ts +5 -13
  499. package/src/services/tx_collection/request_tracker.ts +127 -0
  500. package/src/services/tx_collection/tx_collection.ts +367 -115
  501. package/src/services/tx_collection/tx_collection_sink.ts +32 -36
  502. package/src/services/tx_collection/tx_source.ts +29 -8
  503. package/src/services/tx_file_store/config.ts +37 -0
  504. package/src/services/tx_file_store/index.ts +3 -0
  505. package/src/services/tx_file_store/instrumentation.ts +36 -0
  506. package/src/services/tx_file_store/tx_file_store.ts +163 -0
  507. package/src/services/tx_provider.ts +34 -13
  508. package/src/services/tx_provider_instrumentation.ts +24 -14
  509. package/src/test-helpers/index.ts +2 -0
  510. package/src/test-helpers/make-test-p2p-clients.ts +7 -6
  511. package/src/test-helpers/mock-pubsub.ts +138 -15
  512. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  513. package/src/test-helpers/reqresp-nodes.ts +18 -30
  514. package/src/test-helpers/test_tx_provider.ts +69 -0
  515. package/src/test-helpers/testbench-utils.ts +465 -0
  516. package/src/testbench/p2p_client_testbench_worker.ts +406 -130
  517. package/src/testbench/worker_client_manager.ts +355 -46
  518. package/src/util.ts +40 -19
  519. package/src/versioning.ts +3 -33
  520. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -37
  521. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  522. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -213
  523. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -30
  524. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  525. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -219
  526. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -116
  527. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  528. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -617
  529. package/dest/mem_pools/tx_pool/index.d.ts +0 -4
  530. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  531. package/dest/mem_pools/tx_pool/index.js +0 -3
  532. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
  533. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  534. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -239
  535. package/dest/mem_pools/tx_pool/priority.d.ts +0 -8
  536. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  537. package/dest/mem_pools/tx_pool/priority.js +0 -10
  538. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -123
  539. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  540. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  541. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  542. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  543. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -395
  544. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  545. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  546. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  547. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  548. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  549. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  550. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -45
  551. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  552. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -92
  553. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  554. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  555. package/dest/services/reqresp/protocols/block.js +0 -32
  556. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -51
  557. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  558. package/dest/services/tx_collection/fast_tx_collection.js +0 -300
  559. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
  560. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  561. package/dest/services/tx_collection/slow_tx_collection.js +0 -177
  562. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -298
  563. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -287
  564. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -751
  565. package/src/mem_pools/tx_pool/index.ts +0 -3
  566. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -285
  567. package/src/mem_pools/tx_pool/priority.ts +0 -13
  568. package/src/mem_pools/tx_pool/tx_pool.ts +0 -136
  569. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -314
  570. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  571. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
  572. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -100
  573. package/src/services/reqresp/protocols/block.ts +0 -37
  574. package/src/services/tx_collection/fast_tx_collection.ts +0 -341
  575. package/src/services/tx_collection/slow_tx_collection.ts +0 -233
@@ -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';
@@ -7,6 +7,8 @@ import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib
7
7
 
8
8
  import type { PeerId } from '@libp2p/interface';
9
9
 
10
+ import { MAX_BLOCK_HASH_STRING_LENGTH, MAX_VERSION_STRING_LENGTH } from '../constants.js';
11
+
10
12
  /*
11
13
  * P2P Status Message
12
14
  * It is used to establish Status handshake between to peers
@@ -19,9 +21,10 @@ export class StatusMessage {
19
21
  readonly latestBlockNumber: BlockNumber,
20
22
  readonly latestBlockHash: string,
21
23
  readonly finalizedBlockNumber: BlockNumber,
24
+ ) {
22
25
  //TODO: add finalizedBlockHash
23
26
  //readonly finalizedBlockHash: string,
24
- ) {}
27
+ }
25
28
 
26
29
  /**
27
30
  * Deserializes the StatusMessage object from a Buffer.
@@ -31,12 +34,12 @@ export class StatusMessage {
31
34
  static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
32
35
  const reader = BufferReader.asReader(buffer);
33
36
  return new StatusMessage(
34
- reader.readString(), // compressedComponentsVersion
37
+ reader.readString(MAX_VERSION_STRING_LENGTH), // compressedComponentsVersion
35
38
  BlockNumber(reader.readNumber()), // latestBlockNumber
36
- reader.readString(), // latestBlockHash
39
+ reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // latestBlockHash
37
40
  BlockNumber(reader.readNumber()), // finalizedBlockNumber
38
41
  //TODO: add finalizedBlockHash
39
- //reader.readString(), // finalizedBlockHash
42
+ //reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // finalizedBlockHash
40
43
  );
41
44
  }
42
45
 
@@ -1,5 +1,5 @@
1
1
  import { chunk } from '@aztec/foundation/collection';
2
- import type { P2PClientType } from '@aztec/stdlib/p2p';
2
+ import { MAX_TX_SIZE_KB } from '@aztec/stdlib/p2p';
3
3
  import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
4
4
 
5
5
  import type { PeerId } from '@libp2p/interface';
@@ -16,7 +16,7 @@ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
16
16
  * @param mempools - the mempools
17
17
  * @returns the Tx request handler
18
18
  */
19
- export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): ReqRespSubProtocolHandler {
19
+ export function reqRespTxHandler(mempools: MemPools): ReqRespSubProtocolHandler {
20
20
  /**
21
21
  * Handler for tx requests
22
22
  * @param msg - the tx request message
@@ -51,8 +51,27 @@ export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>)
51
51
  * Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
52
52
  * we define Q as max number of transactions per batch, the comment explains why we use 8.
53
53
  */
54
- //TODO: (mralj) chunk size should by default be 8, this is just temporary until the protocol is implemented correctly
55
- //more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
56
- export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
54
+ export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 8): Array<TxHashArray> {
57
55
  return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
58
56
  }
57
+
58
+ /**
59
+ * Calculate the expected response size for a TX request.
60
+ * @param requestBuffer - The serialized request buffer containing TxHashArray
61
+ * @returns Expected response size in KB
62
+ */
63
+ export function calculateTxResponseSize(requestBuffer: Buffer): number {
64
+ try {
65
+ const txHashes = TxHashArray.fromBuffer(requestBuffer);
66
+ // TxHashArray.fromBuffer returns empty array on parse failure, so check for that
67
+ if (txHashes.length === 0 && requestBuffer.length > 0) {
68
+ // If we got an empty array but had a non-empty buffer, parsing likely failed
69
+ // Fall back to allowing a single transaction response
70
+ return MAX_TX_SIZE_KB + 1;
71
+ }
72
+ return Math.max(txHashes.length, 1) * MAX_TX_SIZE_KB + 1; // +1 KB overhead, at least 1 tx
73
+ } catch {
74
+ // If we can't parse the request, fall back to allowing a single transaction response
75
+ return MAX_TX_SIZE_KB + 1;
76
+ }
77
+ }