@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (522) hide show
  1. package/README.md +130 -3
  2. package/dest/bootstrap/bootstrap.d.ts +1 -1
  3. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  4. package/dest/bootstrap/bootstrap.js +22 -6
  5. package/dest/client/factory.d.ts +11 -10
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +64 -17
  8. package/dest/client/interface.d.ts +86 -40
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +67 -64
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +251 -251
  13. package/dest/config.d.ts +173 -94
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +158 -44
  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 +106 -55
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool.js +302 -195
  31. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  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 +274 -115
  34. package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
  35. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/index.js +1 -1
  37. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  38. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  39. package/dest/mem_pools/attestation_pool/mocks.js +7 -5
  40. package/dest/mem_pools/index.d.ts +2 -2
  41. package/dest/mem_pools/index.d.ts.map +1 -1
  42. package/dest/mem_pools/instrumentation.d.ts +12 -5
  43. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  44. package/dest/mem_pools/instrumentation.js +38 -17
  45. package/dest/mem_pools/interface.d.ts +3 -3
  46. package/dest/mem_pools/interface.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +10 -5
  48. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +29 -20
  50. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  51. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  52. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  53. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  54. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  56. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  57. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +8 -4
  59. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  60. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  61. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +15 -5
  62. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +3 -2
  63. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/eviction/index.js +2 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  67. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
  68. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  69. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  71. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +1 -1
  72. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +6 -5
  74. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +1 -1
  75. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -8
  77. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  78. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +15 -6
  80. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  81. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  82. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  83. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  84. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  85. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  86. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  87. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  88. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  89. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +25 -0
  90. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  91. package/dest/mem_pools/tx_pool_v2/instrumentation.js +67 -0
  92. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +62 -16
  93. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  94. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -1
  95. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +81 -15
  96. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  97. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +147 -19
  98. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +26 -3
  99. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  100. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +79 -43
  101. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +27 -7
  102. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  103. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +94 -32
  104. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +62 -9
  105. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  106. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +537 -246
  107. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
  108. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
  110. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
  111. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  113. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
  114. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  115. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
  116. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
  117. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  118. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
  119. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
  120. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  121. package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
  122. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  123. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  124. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
  125. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  126. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  127. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  128. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  129. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  130. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  131. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  132. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  133. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  135. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  136. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  137. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  138. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  139. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  140. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  141. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  142. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  144. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  145. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  147. package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
  148. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  149. package/dest/msg_validators/tx_validator/factory.js +261 -61
  150. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  151. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  152. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  153. package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
  154. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  155. package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
  156. package/dest/msg_validators/tx_validator/index.d.ts +5 -1
  157. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  158. package/dest/msg_validators/tx_validator/index.js +4 -0
  159. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  160. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  161. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  162. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  163. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  164. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  165. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  166. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  167. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  168. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  169. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  170. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  171. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  172. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  173. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  174. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  175. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  176. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  177. package/dest/services/data_store.d.ts +1 -1
  178. package/dest/services/data_store.d.ts.map +1 -1
  179. package/dest/services/data_store.js +5 -5
  180. package/dest/services/discv5/discV5_service.d.ts +13 -2
  181. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  182. package/dest/services/discv5/discV5_service.js +119 -23
  183. package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
  184. package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
  185. package/dest/services/discv5/persisted_enr_store.js +145 -0
  186. package/dest/services/dummy_service.d.ts +25 -19
  187. package/dest/services/dummy_service.d.ts.map +1 -1
  188. package/dest/services/dummy_service.js +28 -20
  189. package/dest/services/encoding.d.ts +24 -7
  190. package/dest/services/encoding.d.ts.map +1 -1
  191. package/dest/services/encoding.js +43 -26
  192. package/dest/services/gossipsub/topic_score_params.d.ts +23 -17
  193. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  194. package/dest/services/gossipsub/topic_score_params.js +36 -24
  195. package/dest/services/libp2p/instrumentation.d.ts +6 -1
  196. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  197. package/dest/services/libp2p/instrumentation.js +21 -0
  198. package/dest/services/libp2p/libp2p_service.d.ts +71 -60
  199. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  200. package/dest/services/libp2p/libp2p_service.js +602 -407
  201. package/dest/services/peer-manager/metrics.d.ts +3 -1
  202. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  203. package/dest/services/peer-manager/metrics.js +6 -0
  204. package/dest/services/peer-manager/peer_manager.d.ts +31 -3
  205. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  206. package/dest/services/peer-manager/peer_manager.js +127 -26
  207. package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
  208. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  209. package/dest/services/peer-manager/peer_scoring.js +102 -13
  210. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +5 -8
  211. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  212. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +95 -127
  213. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
  214. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  215. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  216. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  217. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  218. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  219. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  220. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  221. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  222. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  223. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  224. package/dest/services/reqresp/config.d.ts +15 -3
  225. package/dest/services/reqresp/config.d.ts.map +1 -1
  226. package/dest/services/reqresp/config.js +11 -0
  227. package/dest/services/reqresp/interface.d.ts +25 -18
  228. package/dest/services/reqresp/interface.d.ts.map +1 -1
  229. package/dest/services/reqresp/interface.js +23 -19
  230. package/dest/services/reqresp/metrics.d.ts +1 -1
  231. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  232. package/dest/services/reqresp/metrics.js +0 -1
  233. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  234. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  235. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  236. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
  237. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  238. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
  239. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +18 -7
  240. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  241. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +57 -24
  242. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  243. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  244. package/dest/services/reqresp/protocols/index.js +0 -1
  245. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  246. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  247. package/dest/services/reqresp/protocols/tx.js +21 -3
  248. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  249. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  250. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  251. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  252. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  253. package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
  254. package/dest/services/reqresp/reqresp.d.ts +7 -29
  255. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  256. package/dest/services/reqresp/reqresp.js +85 -219
  257. package/dest/services/service.d.ts +63 -19
  258. package/dest/services/service.d.ts.map +1 -1
  259. package/dest/services/tx_collection/config.d.ts +11 -14
  260. package/dest/services/tx_collection/config.d.ts.map +1 -1
  261. package/dest/services/tx_collection/config.js +26 -33
  262. package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
  263. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  264. package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
  265. package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
  266. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  267. package/dest/services/tx_collection/file_store_tx_source.js +100 -0
  268. package/dest/services/tx_collection/index.d.ts +3 -3
  269. package/dest/services/tx_collection/index.d.ts.map +1 -1
  270. package/dest/services/tx_collection/index.js +1 -1
  271. package/dest/services/tx_collection/instrumentation.js +1 -2
  272. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  273. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  274. package/dest/services/tx_collection/request_tracker.js +84 -0
  275. package/dest/services/tx_collection/tx_collection.d.ts +45 -51
  276. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  277. package/dest/services/tx_collection/tx_collection.js +296 -68
  278. package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
  279. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  280. package/dest/services/tx_collection/tx_collection_sink.js +28 -31
  281. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  282. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  283. package/dest/services/tx_collection/tx_source.js +29 -7
  284. package/dest/services/tx_file_store/config.d.ts +1 -3
  285. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  286. package/dest/services/tx_file_store/config.js +0 -4
  287. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -5
  288. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  289. package/dest/services/tx_file_store/tx_file_store.js +13 -20
  290. package/dest/services/tx_provider.d.ts +6 -4
  291. package/dest/services/tx_provider.d.ts.map +1 -1
  292. package/dest/services/tx_provider.js +12 -8
  293. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  294. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  295. package/dest/test-helpers/make-test-p2p-clients.js +5 -3
  296. package/dest/test-helpers/mock-pubsub.d.ts +56 -6
  297. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  298. package/dest/test-helpers/mock-pubsub.js +128 -14
  299. package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
  300. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  301. package/dest/test-helpers/reqresp-nodes.js +17 -19
  302. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  303. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  304. package/dest/test-helpers/test_tx_provider.js +3 -0
  305. package/dest/test-helpers/testbench-utils.d.ts +49 -37
  306. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  307. package/dest/test-helpers/testbench-utils.js +142 -50
  308. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  309. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  310. package/dest/testbench/p2p_client_testbench_worker.js +112 -49
  311. package/dest/testbench/worker_client_manager.d.ts +12 -6
  312. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  313. package/dest/testbench/worker_client_manager.js +57 -11
  314. package/dest/util.d.ts +13 -8
  315. package/dest/util.d.ts.map +1 -1
  316. package/dest/util.js +35 -14
  317. package/dest/versioning.d.ts +3 -6
  318. package/dest/versioning.d.ts.map +1 -1
  319. package/dest/versioning.js +3 -24
  320. package/package.json +17 -17
  321. package/src/bootstrap/bootstrap.ts +17 -3
  322. package/src/client/factory.ts +129 -28
  323. package/src/client/interface.ts +88 -48
  324. package/src/client/p2p_client.ts +284 -317
  325. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  326. package/src/config.ts +280 -49
  327. package/src/errors/p2p-service.error.ts +11 -0
  328. package/src/errors/reqresp.error.ts +13 -19
  329. package/src/errors/tx-pool.error.ts +12 -0
  330. package/src/index.ts +1 -1
  331. package/src/mem_pools/attestation_pool/attestation_pool.ts +373 -236
  332. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +298 -119
  333. package/src/mem_pools/attestation_pool/index.ts +3 -3
  334. package/src/mem_pools/attestation_pool/mocks.ts +14 -8
  335. package/src/mem_pools/index.ts +1 -1
  336. package/src/mem_pools/instrumentation.ts +27 -17
  337. package/src/mem_pools/interface.ts +2 -2
  338. package/src/mem_pools/tx_pool_v2/README.md +85 -11
  339. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +30 -20
  340. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  341. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  342. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +6 -4
  343. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +21 -6
  344. package/src/mem_pools/tx_pool_v2/eviction/index.ts +5 -0
  345. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -0
  346. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  347. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +4 -6
  348. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -10
  349. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -10
  350. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  351. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  352. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  353. package/src/mem_pools/tx_pool_v2/instrumentation.ts +96 -0
  354. package/src/mem_pools/tx_pool_v2/interfaces.ts +63 -16
  355. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +215 -27
  356. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +91 -43
  357. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +122 -33
  358. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +602 -242
  359. package/src/msg_validators/attestation_validator/README.md +49 -0
  360. package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
  361. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
  362. package/src/msg_validators/proposal_validator/README.md +123 -0
  363. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
  364. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
  365. package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
  366. package/src/msg_validators/tx_validator/README.md +129 -0
  367. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
  368. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  369. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  370. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  371. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  372. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  373. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  374. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  375. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  376. package/src/msg_validators/tx_validator/factory.ts +413 -80
  377. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  378. package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
  379. package/src/msg_validators/tx_validator/index.ts +4 -0
  380. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  381. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  382. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  383. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  384. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  385. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  386. package/src/services/data_store.ts +5 -13
  387. package/src/services/discv5/discV5_service.ts +126 -14
  388. package/src/services/discv5/persisted_enr_store.ts +158 -0
  389. package/src/services/dummy_service.ts +38 -46
  390. package/src/services/encoding.ts +42 -26
  391. package/src/services/gossipsub/README.md +59 -22
  392. package/src/services/gossipsub/topic_score_params.ts +58 -31
  393. package/src/services/libp2p/instrumentation.ts +22 -0
  394. package/src/services/libp2p/libp2p_service.ts +687 -466
  395. package/src/services/peer-manager/metrics.ts +7 -0
  396. package/src/services/peer-manager/peer_manager.ts +140 -25
  397. package/src/services/peer-manager/peer_scoring.ts +102 -8
  398. package/src/services/reqresp/README.md +194 -0
  399. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  400. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +92 -138
  401. package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
  402. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  403. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  404. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  405. package/src/services/reqresp/config.ts +19 -2
  406. package/src/services/reqresp/interface.ts +45 -46
  407. package/src/services/reqresp/metrics.ts +0 -1
  408. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  409. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +36 -32
  410. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +64 -20
  411. package/src/services/reqresp/protocols/index.ts +0 -1
  412. package/src/services/reqresp/protocols/tx.ts +23 -3
  413. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  414. package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
  415. package/src/services/reqresp/reqresp.ts +100 -263
  416. package/src/services/service.ts +80 -35
  417. package/src/services/tx_collection/config.ts +40 -49
  418. package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
  419. package/src/services/tx_collection/file_store_tx_source.ts +129 -0
  420. package/src/services/tx_collection/index.ts +2 -6
  421. package/src/services/tx_collection/instrumentation.ts +1 -1
  422. package/src/services/tx_collection/request_tracker.ts +127 -0
  423. package/src/services/tx_collection/tx_collection.ts +362 -110
  424. package/src/services/tx_collection/tx_collection_sink.ts +32 -36
  425. package/src/services/tx_collection/tx_source.ts +29 -8
  426. package/src/services/tx_file_store/config.ts +0 -6
  427. package/src/services/tx_file_store/tx_file_store.ts +15 -25
  428. package/src/services/tx_provider.ts +15 -9
  429. package/src/test-helpers/make-test-p2p-clients.ts +7 -6
  430. package/src/test-helpers/mock-pubsub.ts +152 -14
  431. package/src/test-helpers/reqresp-nodes.ts +15 -28
  432. package/src/test-helpers/test_tx_provider.ts +5 -0
  433. package/src/test-helpers/testbench-utils.ts +171 -68
  434. package/src/testbench/p2p_client_testbench_worker.ts +121 -64
  435. package/src/testbench/worker_client_manager.ts +72 -25
  436. package/src/util.ts +40 -19
  437. package/src/versioning.ts +3 -33
  438. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  439. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  440. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
  441. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  442. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  443. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  444. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  445. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  446. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  447. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  448. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  449. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  450. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  451. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  452. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  453. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  454. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  455. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  456. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  457. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  458. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  459. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  460. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  461. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  462. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  463. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  464. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  465. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  466. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  467. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  468. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  469. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  470. package/dest/mem_pools/tx_pool/index.js +0 -2
  471. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  472. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  473. package/dest/mem_pools/tx_pool/priority.js +0 -15
  474. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  475. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  476. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  477. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  478. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  479. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  480. package/dest/msg_validators/clock_tolerance.d.ts +0 -21
  481. package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
  482. package/dest/msg_validators/clock_tolerance.js +0 -37
  483. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  484. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  485. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  486. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  487. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  488. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  489. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  490. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  491. package/dest/services/reqresp/protocols/block.js +0 -32
  492. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -52
  493. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  494. package/dest/services/tx_collection/fast_tx_collection.js +0 -307
  495. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
  496. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  497. package/dest/services/tx_collection/proposal_tx_collector.js +0 -49
  498. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
  499. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  500. package/dest/services/tx_collection/slow_tx_collection.js +0 -177
  501. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
  502. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  503. package/src/mem_pools/tx_pool/README.md +0 -270
  504. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  505. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  506. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  507. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  508. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  509. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  510. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  511. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  512. package/src/mem_pools/tx_pool/index.ts +0 -2
  513. package/src/mem_pools/tx_pool/priority.ts +0 -20
  514. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  515. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  516. package/src/msg_validators/clock_tolerance.ts +0 -51
  517. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
  518. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  519. package/src/services/reqresp/protocols/block.ts +0 -37
  520. package/src/services/tx_collection/fast_tx_collection.ts +0 -354
  521. package/src/services/tx_collection/proposal_tx_collector.ts +0 -112
  522. package/src/services/tx_collection/slow_tx_collection.ts +0 -233
@@ -1,307 +0,0 @@
1
- import { times } from '@aztec/foundation/collection';
2
- import { AbortError, TimeoutError } from '@aztec/foundation/error';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { promiseWithResolvers } from '@aztec/foundation/promise';
5
- import { sleep } from '@aztec/foundation/sleep';
6
- import { DateProvider, elapsed } from '@aztec/foundation/timer';
7
- import { TxHash } from '@aztec/stdlib/tx';
8
- import { BatchTxRequesterCollector, SendBatchRequestCollector } from './proposal_tx_collector.js';
9
- export class FastTxCollection {
10
- nodes;
11
- txCollectionSink;
12
- config;
13
- dateProvider;
14
- log;
15
- // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
16
- requests;
17
- missingTxsCollector;
18
- constructor(p2pService, nodes, txCollectionSink, config, dateProvider = new DateProvider(), log = createLogger('p2p:tx_collection_service'), missingTxsCollector){
19
- this.nodes = nodes;
20
- this.txCollectionSink = txCollectionSink;
21
- this.config = config;
22
- this.dateProvider = dateProvider;
23
- this.log = log;
24
- this.requests = new Set();
25
- const batchTxRequesterConfig = this.config;
26
- const missingTxsCollectorType = this.config.txCollectionMissingTxsCollectorType;
27
- this.missingTxsCollector = missingTxsCollector ?? (missingTxsCollectorType === 'old' ? new SendBatchRequestCollector(p2pService) : new BatchTxRequesterCollector(p2pService, log, dateProvider, undefined, batchTxRequesterConfig));
28
- }
29
- async stop() {
30
- this.requests.forEach((request)=>request.promise.reject(new AbortError(`Stopped collection service`)));
31
- await Promise.resolve();
32
- }
33
- getFastCollectionRequests() {
34
- return this.requests;
35
- }
36
- async collectFastFor(input, txHashes, opts) {
37
- const timeout = opts.deadline.getTime() - this.dateProvider.now();
38
- if (timeout <= 0) {
39
- this.log.warn(`Deadline for fast tx collection is in the past (${timeout}ms)`, {
40
- deadline: opts.deadline.getTime(),
41
- now: this.dateProvider.now()
42
- });
43
- return [];
44
- }
45
- const blockInfo = input.type === 'proposal' ? {
46
- ...input.blockProposal.toBlockInfo(),
47
- blockNumber: input.blockNumber
48
- } : {
49
- ...input.block.toBlockInfo()
50
- };
51
- // This promise is used to await for the collection to finish during the main collectFast method.
52
- // It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
53
- const promise = promiseWithResolvers();
54
- setTimeout(()=>promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
55
- const request = {
56
- ...input,
57
- blockInfo,
58
- promise,
59
- foundTxs: new Map(),
60
- missingTxHashes: new Set(txHashes.map((t)=>t.toString())),
61
- deadline: opts.deadline
62
- };
63
- const [duration] = await elapsed(()=>this.collectFast(request, {
64
- ...opts
65
- }));
66
- this.log.verbose(`Collected ${request.foundTxs.size} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`, {
67
- ...blockInfo,
68
- duration,
69
- requestType: input.type,
70
- missingTxs: [
71
- ...request.missingTxHashes
72
- ]
73
- });
74
- return [
75
- ...request.foundTxs.values()
76
- ];
77
- }
78
- async collectFast(request, opts) {
79
- this.requests.add(request);
80
- const { blockInfo } = request;
81
- this.log.debug(`Starting fast collection of ${request.missingTxHashes.size} txs for ${request.type} at slot ${blockInfo.slotNumber}`, {
82
- ...blockInfo,
83
- requestType: request.type,
84
- deadline: opts.deadline
85
- });
86
- try {
87
- // Start blasting all nodes for the txs. We give them a little time to respond before we start reqresp.
88
- // And keep an eye on the request promise to ensure we don't wait longer than the deadline or return as soon
89
- // as we have collected all txs, whatever the source.
90
- const nodeCollectionPromise = this.collectFastFromNodes(request, opts);
91
- const waitBeforeReqResp = sleep(this.config.txCollectionFastNodesTimeoutBeforeReqRespMs);
92
- await Promise.race([
93
- request.promise.promise,
94
- waitBeforeReqResp
95
- ]);
96
- // If we have collected all txs, we can stop here
97
- if (request.missingTxHashes.size === 0) {
98
- this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
99
- return;
100
- }
101
- // Start blasting reqresp for the remaining txs. Note that node collection keeps running in parallel.
102
- // We stop when we have collected all txs, timed out, or both node collection and reqresp have given up.
103
- const collectionPromise = Promise.allSettled([
104
- this.collectFastViaReqResp(request, opts),
105
- nodeCollectionPromise
106
- ]);
107
- await Promise.race([
108
- collectionPromise,
109
- request.promise.promise
110
- ]);
111
- } catch (err) {
112
- // Log and swallow all errors
113
- const logCtx = {
114
- ...blockInfo,
115
- errorMessage: err instanceof Error ? err.message : undefined,
116
- missingTxs: [
117
- ...request.missingTxHashes
118
- ].map((txHash)=>txHash.toString())
119
- };
120
- if (err instanceof Error && err.name === 'TimeoutError') {
121
- this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
122
- } else if (err instanceof Error && err.name === 'AbortError') {
123
- this.log.warn(`Aborted collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
124
- } else {
125
- this.log.error(`Error collecting txs for ${request.type} for slot ${blockInfo.slotNumber}`, err, logCtx);
126
- }
127
- } finally{
128
- // Ensure no unresolved promises and remove the request from the set
129
- request.promise.resolve();
130
- this.requests.delete(request);
131
- }
132
- }
133
- /**
134
- * Starts collecting txs from all configured nodes. We send `txCollectionFastMaxParallelRequestsPerNode` requests
135
- * in parallel to each node. We keep track of the number of attempts made to collect each tx, so we can prioritize
136
- * the txs that have been requested less often whenever we need to send a new batch of requests. We ensure that no
137
- * tx is requested more than once at the same time to the same node.
138
- */ async collectFastFromNodes(request, opts) {
139
- if (this.nodes.length === 0) {
140
- return;
141
- }
142
- // Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
143
- const attemptsPerTx = [
144
- ...request.missingTxHashes
145
- ].map((txHash)=>({
146
- txHash,
147
- attempts: 0,
148
- found: false
149
- }));
150
- // Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
151
- await Promise.allSettled(this.nodes.map((node)=>this.collectFastFromNode(request, node, attemptsPerTx, opts)));
152
- }
153
- async collectFastFromNode(request, node, attemptsPerTx, opts) {
154
- const notFinished = ()=>this.dateProvider.now() <= +opts.deadline && request.missingTxHashes.size > 0 && this.requests.has(request);
155
- const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
156
- const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
157
- const activeRequestsToThisNode = new Set(); // Track the txs being actively requested to this node
158
- const processBatch = async ()=>{
159
- while(notFinished()){
160
- // Pull tx hashes from the attemptsPerTx array, which is sorted by attempts,
161
- // so we prioritize txs that have been requested less often.
162
- const batch = [];
163
- let index = 0;
164
- while(batch.length < maxBatchSize){
165
- const txToRequest = attemptsPerTx[index++];
166
- if (!txToRequest) {
167
- break;
168
- } else if (!request.missingTxHashes.has(txToRequest.txHash)) {
169
- // Mark as found if it was found somewhere else, we'll then remove it from the array.
170
- // We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
171
- txToRequest.found = true;
172
- } else if (!activeRequestsToThisNode.has(txToRequest.txHash)) {
173
- // If the tx is not alredy being requested to this node, add it to the current batch and increase attempts.
174
- // Note that we increase the attempts *before* making the request, so the next `collectFastFromNode` that
175
- // needs to grab txs to send, will pick txs that have been requested less often, instead of all requesting
176
- // the same txs at the same time.
177
- batch.push(txToRequest);
178
- activeRequestsToThisNode.add(txToRequest.txHash);
179
- txToRequest.attempts++;
180
- }
181
- }
182
- // After modifying the array by removing txs or updating attempts, re-sort it and trim the found txs from the end.
183
- attemptsPerTx.sort((a, b)=>a.found === b.found ? a.attempts - b.attempts : Number(a.found) - Number(b.found));
184
- const firstFoundTxIndex = attemptsPerTx.findIndex((tx)=>tx.found);
185
- if (firstFoundTxIndex !== -1) {
186
- attemptsPerTx.length = firstFoundTxIndex;
187
- }
188
- // If we see no more txs to request, we can stop this "process" loop
189
- if (batch.length === 0) {
190
- return;
191
- }
192
- // Collect this batch from the node
193
- await this.txCollectionSink.collect((txHashes)=>node.getTxsByHash(txHashes), batch.map(({ txHash })=>TxHash.fromString(txHash)), {
194
- description: `fast ${node.getInfo()}`,
195
- node: node.getInfo(),
196
- method: 'fast-node-rpc',
197
- ...request.blockInfo
198
- });
199
- // Clear from the active requests the txs we just requested
200
- for (const requestedTx of batch){
201
- activeRequestsToThisNode.delete(requestedTx.txHash);
202
- }
203
- // Sleep a bit until hitting the node again (or not, depending on config)
204
- if (notFinished()) {
205
- await sleep(this.config.txCollectionFastNodeIntervalMs);
206
- }
207
- }
208
- };
209
- // Kick off N parallel requests to the node, up to the maxParallelRequests limit
210
- await Promise.all(times(maxParallelRequests, processBatch));
211
- }
212
- async collectFastViaReqResp(request, opts) {
213
- const timeoutMs = +request.deadline - this.dateProvider.now();
214
- const pinnedPeer = opts.pinnedPeer;
215
- const blockInfo = request.blockInfo;
216
- const slotNumber = blockInfo.slotNumber;
217
- if (timeoutMs < 100) {
218
- this.log.warn(`Not initiating fast reqresp for txs for ${request.type} at slot ${blockInfo.slotNumber} due to timeout`, {
219
- timeoutMs,
220
- ...blockInfo
221
- });
222
- return;
223
- }
224
- this.log.debug(`Starting fast reqresp for ${request.missingTxHashes.size} txs for ${request.type} at slot ${blockInfo.slotNumber}`, {
225
- ...blockInfo,
226
- timeoutMs,
227
- pinnedPeer
228
- });
229
- try {
230
- await this.txCollectionSink.collect(async (txHashes)=>{
231
- if (request.type === 'proposal') {
232
- return await this.missingTxsCollector.collectTxs(txHashes, request.blockProposal, pinnedPeer, timeoutMs);
233
- } else if (request.type === 'block') {
234
- const blockTxsSource = {
235
- txHashes: request.block.body.txEffects.map((e)=>e.txHash),
236
- archive: request.block.archive.root
237
- };
238
- return await this.missingTxsCollector.collectTxs(txHashes, blockTxsSource, pinnedPeer, timeoutMs);
239
- } else {
240
- throw new Error(`Unknown request type: ${request.type}`);
241
- }
242
- }, Array.from(request.missingTxHashes).map((txHash)=>TxHash.fromString(txHash)), {
243
- description: `reqresp for slot ${slotNumber}`,
244
- method: 'fast-req-resp',
245
- ...opts,
246
- ...request.blockInfo
247
- });
248
- } catch (err) {
249
- this.log.error(`Error sending fast reqresp request for txs`, err, {
250
- txs: [
251
- ...request.missingTxHashes
252
- ],
253
- ...blockInfo
254
- });
255
- }
256
- }
257
- /**
258
- * Handle txs by marking them as found for the requests that are waiting for them, and resolves the request if all its txs have been found.
259
- * Called internally and from the main tx collection manager whenever the tx pool emits a tx-added event.
260
- */ foundTxs(txs) {
261
- for (const request of this.requests){
262
- for (const tx of txs){
263
- const txHash = tx.txHash.toString();
264
- // Remove the tx hash from the missing set, and add it to the found set.
265
- if (request.missingTxHashes.has(txHash)) {
266
- request.missingTxHashes.delete(txHash);
267
- request.foundTxs.set(txHash, tx);
268
- this.log.trace(`Found tx ${txHash} for fast collection request`, {
269
- ...request.blockInfo,
270
- txHash: tx.txHash.toString(),
271
- type: request.type
272
- });
273
- // If we found all txs for this request, we resolve the promise
274
- if (request.missingTxHashes.size === 0) {
275
- this.log.trace(`All txs found for fast collection request`, {
276
- ...request.blockInfo,
277
- type: request.type
278
- });
279
- request.promise.resolve();
280
- }
281
- }
282
- }
283
- }
284
- }
285
- /**
286
- * Stop collecting all txs for blocks less than or requal to the block number specified.
287
- * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
288
- */ stopCollectingForBlocksUpTo(blockNumber) {
289
- for (const request of this.requests){
290
- if (request.blockInfo.blockNumber <= blockNumber) {
291
- request.promise.reject(new AbortError(`Stopped collecting txs up to block ${blockNumber}`));
292
- this.requests.delete(request);
293
- }
294
- }
295
- }
296
- /**
297
- * Stop collecting all txs for blocks greater than the block number specified.
298
- * To be called when there is a chain prune and previously mined txs are no longer relevant.
299
- */ stopCollectingForBlocksAfter(blockNumber) {
300
- for (const request of this.requests){
301
- if (request.blockInfo.blockNumber > blockNumber) {
302
- request.promise.reject(new AbortError(`Stopped collecting txs after block ${blockNumber}`));
303
- this.requests.delete(request);
304
- }
305
- }
306
- }
307
- }
@@ -1,48 +0,0 @@
1
- import type { Logger } from '@aztec/foundation/log';
2
- import type { DateProvider } from '@aztec/foundation/timer';
3
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
4
- import type { PeerId } from '@libp2p/interface';
5
- import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
6
- import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
7
- import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
8
- import { type BlockTxsSource } from '../reqresp/index.js';
9
- /**
10
- * Strategy interface for collecting missing transactions for a block or proposal.
11
- * Allows swapping between different tx collection implementations for benchmarking.
12
- */
13
- export interface MissingTxsCollector {
14
- /**
15
- * Collect missing transactions for a block or proposal.
16
- * @param txHashes - The transaction hashes to collect
17
- * @param blockTxsSource - The block or proposal containing the transactions
18
- * @param pinnedPeer - Optional peer expected to have the transactions
19
- * @param timeoutMs - Timeout in milliseconds
20
- * @returns The collected transactions
21
- */
22
- collectTxs(txHashes: TxHash[], blockTxsSource: BlockTxsSource, pinnedPeer: PeerId | undefined, timeoutMs: number): Promise<Tx[]>;
23
- }
24
- /**
25
- * Collects transactions using the BatchTxRequester implementation.
26
- * This uses a smart/dumb peer strategy with parallel workers.
27
- */
28
- export declare class BatchTxRequesterCollector implements MissingTxsCollector {
29
- private p2pService;
30
- private log;
31
- private dateProvider;
32
- private txValidator?;
33
- private batchTxRequesterConfig?;
34
- constructor(p2pService: BatchTxRequesterLibP2PService, log: Logger, dateProvider: DateProvider, txValidator?: IBatchRequestTxValidator | undefined, batchTxRequesterConfig?: Partial<BatchTxRequesterConfig> | undefined);
35
- collectTxs(txHashes: TxHash[], blockTxsSource: BlockTxsSource, pinnedPeer: PeerId | undefined, timeoutMs: number): Promise<Tx[]>;
36
- }
37
- /**
38
- * Collects transactions using the sendBatchRequest implementation from ReqResp.
39
- * This is the original implementation that balances requests across peers.
40
- */
41
- export declare class SendBatchRequestCollector implements MissingTxsCollector {
42
- private p2pService;
43
- private maxPeers;
44
- private maxRetryAttempts;
45
- constructor(p2pService: BatchTxRequesterLibP2PService, maxPeers?: number, maxRetryAttempts?: number);
46
- collectTxs(txHashes: TxHash[], _blockTxsSource: BlockTxsSource, pinnedPeer: PeerId | undefined, timeoutMs: number): Promise<Tx[]>;
47
- }
48
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvcG9zYWxfdHhfY29sbGVjdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc2VydmljZXMvdHhfY29sbGVjdGlvbi9wcm9wb3NhbF90eF9jb2xsZWN0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDNUQsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRW5ELE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBR2hELE9BQU8sS0FBSyxFQUFFLHNCQUFzQixFQUFFLE1BQU0seUNBQXlDLENBQUM7QUFDdEYsT0FBTyxLQUFLLEVBQUUsNkJBQTZCLEVBQUUsTUFBTSw0Q0FBNEMsQ0FBQztBQUNoRyxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLCtDQUErQyxDQUFDO0FBQzlGLE9BQU8sRUFBRSxLQUFLLGNBQWMsRUFBNEMsTUFBTSxxQkFBcUIsQ0FBQztBQUVwRzs7O0dBR0c7QUFDSCxNQUFNLFdBQVcsbUJBQW1CO0lBQ2xDOzs7Ozs7O09BT0c7SUFDSCxVQUFVLENBQ1IsUUFBUSxFQUFFLE1BQU0sRUFBRSxFQUNsQixjQUFjLEVBQUUsY0FBYyxFQUM5QixVQUFVLEVBQUUsT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FNBQVMsRUFDOUIsU0FBUyxFQUFFLE1BQU0sR0FDaEIsT0FBTyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBV2Y7Q0FDRiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"proposal_tx_collector.d.ts","sourceRoot":"","sources":["../../../src/services/tx_collection/proposal_tx_collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAChG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAE,KAAK,cAAc,EAA4C,MAAM,qBAAqB,CAAC;AAEpG;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IAEjE,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,WAAW,CAAC;IACpB,OAAO,CAAC,sBAAsB,CAAC;IALjC,YACU,UAAU,EAAE,6BAA6B,EACzC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,YAAY,EAC1B,WAAW,CAAC,sCAA0B,EACtC,sBAAsB,CAAC,6CAAiC,EAC9D;IAEE,UAAU,CACd,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,EAAE,EAAE,CAAC,CA0Bf;CACF;AAKD;;;GAGG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IAEjE,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,gBAAgB;IAH1B,YACU,UAAU,EAAE,6BAA6B,EACzC,QAAQ,GAAE,MAA0B,EACpC,gBAAgB,GAAE,MAAmC,EAC3D;IAEE,UAAU,CACd,QAAQ,EAAE,MAAM,EAAE,EAClB,eAAe,EAAE,cAAc,EAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,EAAE,EAAE,CAAC,CAWf;CACF"}
@@ -1,49 +0,0 @@
1
- import { BatchTxRequester } from '../reqresp/batch-tx-requester/batch_tx_requester.js';
2
- import { ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
3
- /**
4
- * Collects transactions using the BatchTxRequester implementation.
5
- * This uses a smart/dumb peer strategy with parallel workers.
6
- */ export class BatchTxRequesterCollector {
7
- p2pService;
8
- log;
9
- dateProvider;
10
- txValidator;
11
- batchTxRequesterConfig;
12
- constructor(p2pService, log, dateProvider, txValidator, batchTxRequesterConfig){
13
- this.p2pService = p2pService;
14
- this.log = log;
15
- this.dateProvider = dateProvider;
16
- this.txValidator = txValidator;
17
- this.batchTxRequesterConfig = batchTxRequesterConfig;
18
- }
19
- async collectTxs(txHashes, blockTxsSource, pinnedPeer, timeoutMs) {
20
- const { batchTxRequesterSmartParallelWorkerCount: smartParallelWorkerCount, batchTxRequesterDumbParallelWorkerCount: dumbParallelWorkerCount, batchTxRequesterTxBatchSize: txBatchSize, batchTxRequesterBadPeerThreshold: badPeerThreshold } = this.batchTxRequesterConfig ?? {};
21
- const batchRequester = new BatchTxRequester(txHashes, blockTxsSource, pinnedPeer, timeoutMs, this.p2pService, this.log, this.dateProvider, {
22
- smartParallelWorkerCount,
23
- dumbParallelWorkerCount,
24
- txBatchSize,
25
- badPeerThreshold,
26
- txValidator: this.txValidator
27
- });
28
- return await BatchTxRequester.collectAllTxs(batchRequester.run());
29
- }
30
- }
31
- const DEFAULT_MAX_PEERS = 10;
32
- const DEFAULT_MAX_RETRY_ATTEMPTS = 3;
33
- /**
34
- * Collects transactions using the sendBatchRequest implementation from ReqResp.
35
- * This is the original implementation that balances requests across peers.
36
- */ export class SendBatchRequestCollector {
37
- p2pService;
38
- maxPeers;
39
- maxRetryAttempts;
40
- constructor(p2pService, maxPeers = DEFAULT_MAX_PEERS, maxRetryAttempts = DEFAULT_MAX_RETRY_ATTEMPTS){
41
- this.p2pService = p2pService;
42
- this.maxPeers = maxPeers;
43
- this.maxRetryAttempts = maxRetryAttempts;
44
- }
45
- async collectTxs(txHashes, _blockTxsSource, pinnedPeer, timeoutMs) {
46
- const txs = await this.p2pService.reqResp.sendBatchRequest(ReqRespSubProtocol.TX, chunkTxHashesRequest(txHashes), pinnedPeer, timeoutMs, this.maxPeers, this.maxRetryAttempts);
47
- return txs.flat();
48
- }
49
- }
@@ -1,53 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { type Logger } from '@aztec/foundation/log';
3
- import { DateProvider } from '@aztec/foundation/timer';
4
- import type { L2Block } from '@aztec/stdlib/block';
5
- import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
6
- import { type Tx, TxHash } from '@aztec/stdlib/tx';
7
- import { type ReqRespInterface } from '../reqresp/interface.js';
8
- import type { TxCollectionConfig } from './config.js';
9
- import type { FastTxCollection } from './fast_tx_collection.js';
10
- import type { TxCollectionSink } from './tx_collection_sink.js';
11
- import type { TxSource } from './tx_source.js';
12
- export declare class SlowTxCollection {
13
- private reqResp;
14
- private nodes;
15
- private txCollectionSink;
16
- private fastCollection;
17
- private constants;
18
- private config;
19
- private dateProvider;
20
- private log;
21
- /** Map from tx hash to missing tx info to collect via slow loop */
22
- private missingTxs;
23
- /** One slow collection loop for each node tx source we have */
24
- private nodesSlowCollectionLoops;
25
- /** Slow collection loop for reqresp which collects txs from peers */
26
- private reqrespSlowCollectionLoop;
27
- constructor(reqResp: Pick<ReqRespInterface, 'sendBatchRequest'>, nodes: TxSource[], txCollectionSink: TxCollectionSink, fastCollection: Pick<FastTxCollection, 'getFastCollectionRequests'>, constants: L1RollupConstants, config: TxCollectionConfig, dateProvider?: DateProvider, log?: Logger);
28
- getMissingTxHashes(): TxHash[];
29
- start(): void;
30
- stop(): Promise<void>;
31
- trigger(): Promise<void>;
32
- /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
33
- startCollecting(block: L2Block, txHashes: TxHash[]): void;
34
- private collectMissingTxsFromNode;
35
- private collectMissingTxsViaReqResp;
36
- /** Retrieves all missing txs for the slow collection process. This is, all missing txs that are not part of a fast request. */
37
- private getMissingTxsForSlowCollection;
38
- /** Stop collecting the given txs since we have found them. Called whenever tx pool emits a tx-added event. */
39
- foundTxs(txs: Tx[]): void;
40
- /**
41
- * Stop collecting all txs for blocks less than or requal to the block number specified.
42
- * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
43
- */
44
- stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void;
45
- /**
46
- * Stop collecting all txs for blocks greater than the block number specified.
47
- * To be called when there is a chain prune and previously mined txs are no longer relevant.
48
- */
49
- stopCollectingForBlocksAfter(blockNumber: BlockNumber): void;
50
- /** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
51
- private getDeadlineForSlot;
52
- }
53
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xvd190eF9jb2xsZWN0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uL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CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EACnD,KAAK,EAAE,QAAQ,EAAE,EACjB,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,IAAI,CAAC,gBAAgB,EAAE,2BAA2B,CAAC,EACnE,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,kBAAkB,EAC1B,YAAY,GAAE,YAAiC,EAC/C,GAAG,GAAE,MAAkD,EAgBhE;IAEM,kBAAkB,aAExB;IAEM,KAAK,SAGX;IAEY,IAAI,kBAKhB;IAEY,OAAO,kBAKnB;IAED,mFAAmF;IAC5E,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAoBxD;YAGa,yBAAyB;YAiCzB,2BAA2B;IAsCzC,+HAA+H;IAC/H,OAAO,CAAC,8BAA8B;IAqBtC,8GAA8G;IACvG,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,IAAI,CAI/B;IAED;;;OAGG;IACI,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAMjE;IAED;;;OAGG;IACI,4BAA4B,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAMlE;IAED,oIAAoI;IACpI,OAAO,CAAC,kBAAkB;CAM3B"}
@@ -1,177 +0,0 @@
1
- import { EpochNumber } from '@aztec/foundation/branded-types';
2
- import { chunk } from '@aztec/foundation/collection';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { boundInclusive } from '@aztec/foundation/number';
5
- import { RunningPromise } from '@aztec/foundation/promise';
6
- import { DateProvider } from '@aztec/foundation/timer';
7
- import { getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
8
- import { TxHash } from '@aztec/stdlib/tx';
9
- import { ReqRespSubProtocol } from '../reqresp/interface.js';
10
- import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
11
- export class SlowTxCollection {
12
- reqResp;
13
- nodes;
14
- txCollectionSink;
15
- fastCollection;
16
- constants;
17
- config;
18
- dateProvider;
19
- log;
20
- /** Map from tx hash to missing tx info to collect via slow loop */ missingTxs;
21
- /** One slow collection loop for each node tx source we have */ nodesSlowCollectionLoops;
22
- /** Slow collection loop for reqresp which collects txs from peers */ reqrespSlowCollectionLoop;
23
- constructor(reqResp, nodes, txCollectionSink, fastCollection, constants, config, dateProvider = new DateProvider(), log = createLogger('p2p:tx_collection_service')){
24
- this.reqResp = reqResp;
25
- this.nodes = nodes;
26
- this.txCollectionSink = txCollectionSink;
27
- this.fastCollection = fastCollection;
28
- this.constants = constants;
29
- this.config = config;
30
- this.dateProvider = dateProvider;
31
- this.log = log;
32
- this.missingTxs = new Map();
33
- this.nodesSlowCollectionLoops = this.nodes.map((node)=>new RunningPromise(()=>this.collectMissingTxsFromNode(node), this.log, this.config.txCollectionSlowNodesIntervalMs));
34
- this.reqrespSlowCollectionLoop = new RunningPromise(()=>this.collectMissingTxsViaReqResp(), this.log, this.config.txCollectionSlowReqRespIntervalMs);
35
- }
36
- getMissingTxHashes() {
37
- return Array.from(this.missingTxs.keys()).map(TxHash.fromString);
38
- }
39
- start() {
40
- this.nodesSlowCollectionLoops.forEach((loop)=>loop.start());
41
- this.reqrespSlowCollectionLoop.start();
42
- }
43
- async stop() {
44
- await Promise.all([
45
- this.reqrespSlowCollectionLoop.stop(),
46
- ...this.nodesSlowCollectionLoops.map((loop)=>loop.stop())
47
- ]);
48
- }
49
- async trigger() {
50
- await Promise.all([
51
- this.reqrespSlowCollectionLoop.trigger(),
52
- ...this.nodesSlowCollectionLoops.map((loop)=>loop.trigger())
53
- ]);
54
- }
55
- /** Starts collecting the given tx hashes for the given L2Block in the slow loop */ startCollecting(block, txHashes) {
56
- const slot = block.header.getSlot();
57
- const deadline = this.getDeadlineForSlot(slot);
58
- if (+deadline < this.dateProvider.now()) {
59
- this.log.debug(`Skipping collection of txs for block ${block.number} at slot ${slot} as it is already expired`, {
60
- blockNumber: block.number,
61
- slot: slot.toString(),
62
- txHashes: txHashes.map((txHash)=>txHash.toString()),
63
- deadline: +deadline,
64
- now: this.dateProvider.now()
65
- });
66
- }
67
- for (const txHash of txHashes){
68
- this.missingTxs.set(txHash.toString(), {
69
- blockNumber: block.number,
70
- deadline: this.getDeadlineForSlot(block.header.getSlot()),
71
- readyForReqResp: this.nodes.length === 0
72
- });
73
- }
74
- }
75
- /** Entrypoint for the node slow collection loop */ async collectMissingTxsFromNode(node) {
76
- // If we have any fast requests, we skip the slow collection for this node if configured to do so
77
- const requests = this.fastCollection.getFastCollectionRequests();
78
- if (this.config.txCollectionDisableSlowDuringFastRequests && requests.size > 0) {
79
- this.log.trace(`Skipping node slow collection due to active fast requests`);
80
- return;
81
- }
82
- // Gather all missing txs that are not in fast collection and request them from the node
83
- const missingTxs = this.getMissingTxsForSlowCollection();
84
- const missingTxHashes = missingTxs.map(([txHash])=>txHash).map(TxHash.fromString);
85
- if (missingTxHashes.length === 0) {
86
- return;
87
- }
88
- // Request in chunks to avoid hitting RPC limits
89
- for (const batch of chunk(missingTxHashes, this.config.txCollectionNodeRpcMaxBatchSize)){
90
- await this.txCollectionSink.collect((txHashes)=>node.getTxsByHash(txHashes), batch, {
91
- description: `node ${node.getInfo()}`,
92
- node: node.getInfo(),
93
- method: 'slow-node-rpc'
94
- });
95
- }
96
- // Mark every tx that is still missing as ready for reqresp.
97
- // Note that we can just mark all requested txs as ready for reqresp, without filtering out the ones
98
- // we retrieved, since the ones already found will have been removed from `missingTxs`.
99
- missingTxs.forEach(([_txHash, info])=>{
100
- info.readyForReqResp = true;
101
- });
102
- }
103
- /** Entrypoint for the reqresp slow collection loop */ async collectMissingTxsViaReqResp() {
104
- // If we have any fast requests, we skip the slow collection if configured to do so
105
- const requests = this.fastCollection.getFastCollectionRequests();
106
- if (this.config.txCollectionDisableSlowDuringFastRequests && requests.size > 0) {
107
- this.log.trace(`Skipping reqresp slow collection due to active fast requests`);
108
- return;
109
- }
110
- // Gather all missing txs that are not in fast collection and are ready for reqresp
111
- // A tx is flagged as ready for reqresp if it has been requested from a node at least once
112
- const missingTxs = this.getMissingTxsForSlowCollection({
113
- onlyReqRespReady: true
114
- });
115
- if (missingTxs.length === 0) {
116
- return;
117
- }
118
- const pinnedPeer = undefined;
119
- const timeoutMs = this.config.txCollectionSlowReqRespTimeoutMs;
120
- const maxPeers = boundInclusive(Math.ceil(missingTxs.length / 3), 4, 16);
121
- const maxRetryAttempts = 3;
122
- // Send a batch request via reqresp for the missing txs
123
- await this.txCollectionSink.collect(async (txHashes)=>{
124
- const txs = await this.reqResp.sendBatchRequest(ReqRespSubProtocol.TX, chunkTxHashesRequest(txHashes), pinnedPeer, timeoutMs, maxPeers, maxRetryAttempts);
125
- return txs.flat();
126
- }, missingTxs.map(([txHash])=>TxHash.fromString(txHash)), {
127
- description: 'slow reqresp',
128
- timeoutMs,
129
- method: 'slow-req-resp'
130
- });
131
- }
132
- /** Retrieves all missing txs for the slow collection process. This is, all missing txs that are not part of a fast request. */ getMissingTxsForSlowCollection(opts = {}) {
133
- // Remove expired txs from missingTxs
134
- const now = this.dateProvider.now();
135
- const expiredTxs = Array.from(this.missingTxs.entries()).filter(([_, value])=>+value.deadline < now);
136
- expiredTxs.forEach(([txHash])=>this.missingTxs.delete(txHash));
137
- // Gather all txs that are marked for fast collection, we do not want to collect them via slow collection.
138
- // There are some situations where a tx is in both slow and fast collection, for example when a prover node
139
- // is fast-collecting missing txs for proving an epoch, and still has the tx in the slow collection loops
140
- // from mined unproven blocks it has seen in the past.
141
- const fastRequests = this.fastCollection.getFastCollectionRequests();
142
- const fastCollectionTxs = new Set(...Array.from(fastRequests.values()).flatMap((r)=>r.missingTxHashes));
143
- // Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
144
- return Array.from(this.missingTxs.entries()).filter(([txHash, _])=>!fastCollectionTxs.has(txHash)).filter(([_, value])=>!opts.onlyReqRespReady || value.readyForReqResp);
145
- }
146
- /** Stop collecting the given txs since we have found them. Called whenever tx pool emits a tx-added event. */ foundTxs(txs) {
147
- for (const txHash of txs.map((tx)=>tx.txHash)){
148
- this.missingTxs.delete(txHash.toString());
149
- }
150
- }
151
- /**
152
- * Stop collecting all txs for blocks less than or requal to the block number specified.
153
- * To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
154
- */ stopCollectingForBlocksUpTo(blockNumber) {
155
- for (const [txHash, info] of this.missingTxs.entries()){
156
- if (info.blockNumber <= blockNumber) {
157
- this.missingTxs.delete(txHash);
158
- }
159
- }
160
- }
161
- /**
162
- * Stop collecting all txs for blocks greater than the block number specified.
163
- * To be called when there is a chain prune and previously mined txs are no longer relevant.
164
- */ stopCollectingForBlocksAfter(blockNumber) {
165
- for (const [txHash, info] of this.missingTxs.entries()){
166
- if (info.blockNumber > blockNumber) {
167
- this.missingTxs.delete(txHash);
168
- }
169
- }
170
- }
171
- /** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */ getDeadlineForSlot(slotNumber) {
172
- const epoch = getEpochAtSlot(slotNumber, this.constants);
173
- const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
174
- const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
175
- return new Date(Number(submissionEndTimestamp) * 1000);
176
- }
177
- }