@aztec/p2p 0.0.1-commit.4d79d1f2d → 0.0.1-commit.4d9804df

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 (499) 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 +9 -8
  6. package/dest/client/factory.d.ts.map +1 -1
  7. package/dest/client/factory.js +50 -34
  8. package/dest/client/interface.d.ts +59 -27
  9. package/dest/client/interface.d.ts.map +1 -1
  10. package/dest/client/p2p_client.d.ts +40 -34
  11. package/dest/client/p2p_client.d.ts.map +1 -1
  12. package/dest/client/p2p_client.js +162 -135
  13. package/dest/config.d.ts +164 -100
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +149 -49
  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 +1 -2
  26. package/dest/index.d.ts.map +1 -1
  27. package/dest/index.js +0 -1
  28. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +103 -59
  29. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/attestation_pool.js +278 -196
  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 +224 -65
  34. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  35. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  36. package/dest/mem_pools/attestation_pool/mocks.js +7 -5
  37. package/dest/mem_pools/index.d.ts +1 -2
  38. package/dest/mem_pools/index.d.ts.map +1 -1
  39. package/dest/mem_pools/instrumentation.d.ts +12 -5
  40. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  41. package/dest/mem_pools/instrumentation.js +38 -17
  42. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
  43. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
  44. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
  45. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +32 -15
  46. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  47. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +95 -24
  48. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  49. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  50. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  51. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +8 -4
  54. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  55. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  57. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +3 -2
  58. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/index.js +2 -1
  60. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
  63. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
  64. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  66. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  67. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -7
  68. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  69. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  70. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  71. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  72. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  73. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
  74. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  75. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  76. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
  77. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  78. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  79. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  80. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  81. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  82. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  83. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +60 -14
  84. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  85. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -1
  86. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +59 -15
  87. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  88. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +116 -20
  89. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +26 -3
  90. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  91. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +79 -43
  92. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +20 -7
  93. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  94. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +34 -12
  95. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +29 -7
  96. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  97. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +473 -211
  98. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
  99. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  100. package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
  101. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
  102. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
  104. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
  105. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
  106. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
  107. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
  108. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
  109. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
  110. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
  111. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
  113. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  114. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  115. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
  116. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
  117. package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
  118. package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
  119. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
  120. package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
  121. package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
  122. package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
  123. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
  124. package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
  125. package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
  126. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  127. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  128. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  129. package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
  130. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  131. package/dest/msg_validators/tx_validator/data_validator.js +36 -2
  132. package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
  133. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  134. package/dest/msg_validators/tx_validator/factory.js +261 -61
  135. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
  136. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
  137. package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
  138. package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
  139. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  140. package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
  141. package/dest/msg_validators/tx_validator/index.d.ts +5 -1
  142. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  143. package/dest/msg_validators/tx_validator/index.js +4 -0
  144. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  145. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  146. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  147. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  148. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  149. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  150. package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
  151. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  152. package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
  153. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  154. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  155. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  156. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
  157. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
  158. package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
  159. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
  160. package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
  161. package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
  162. package/dest/services/data_store.d.ts +1 -1
  163. package/dest/services/data_store.d.ts.map +1 -1
  164. package/dest/services/data_store.js +5 -5
  165. package/dest/services/discv5/discV5_service.d.ts +13 -2
  166. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  167. package/dest/services/discv5/discV5_service.js +119 -23
  168. package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
  169. package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
  170. package/dest/services/discv5/persisted_enr_store.js +145 -0
  171. package/dest/services/dummy_service.d.ts +18 -18
  172. package/dest/services/dummy_service.d.ts.map +1 -1
  173. package/dest/services/dummy_service.js +19 -20
  174. package/dest/services/encoding.d.ts +23 -6
  175. package/dest/services/encoding.d.ts.map +1 -1
  176. package/dest/services/encoding.js +41 -24
  177. package/dest/services/gossipsub/topic_score_params.d.ts +23 -17
  178. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  179. package/dest/services/gossipsub/topic_score_params.js +36 -24
  180. package/dest/services/libp2p/instrumentation.d.ts +3 -1
  181. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  182. package/dest/services/libp2p/instrumentation.js +14 -0
  183. package/dest/services/libp2p/libp2p_service.d.ts +57 -56
  184. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  185. package/dest/services/libp2p/libp2p_service.js +483 -373
  186. package/dest/services/peer-manager/metrics.d.ts +3 -1
  187. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  188. package/dest/services/peer-manager/metrics.js +6 -0
  189. package/dest/services/peer-manager/peer_manager.d.ts +20 -3
  190. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  191. package/dest/services/peer-manager/peer_manager.js +83 -26
  192. package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
  193. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  194. package/dest/services/peer-manager/peer_scoring.js +102 -13
  195. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +5 -8
  196. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  197. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +95 -127
  198. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
  199. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  200. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
  201. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  202. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
  203. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  204. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  205. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  206. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
  207. package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
  208. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
  209. package/dest/services/reqresp/config.d.ts +15 -3
  210. package/dest/services/reqresp/config.d.ts.map +1 -1
  211. package/dest/services/reqresp/config.js +11 -0
  212. package/dest/services/reqresp/interface.d.ts +16 -18
  213. package/dest/services/reqresp/interface.d.ts.map +1 -1
  214. package/dest/services/reqresp/interface.js +10 -20
  215. package/dest/services/reqresp/metrics.d.ts +1 -1
  216. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  217. package/dest/services/reqresp/metrics.js +0 -1
  218. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
  219. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  220. package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
  221. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
  222. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  223. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
  224. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
  225. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  226. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
  227. package/dest/services/reqresp/protocols/index.d.ts +1 -2
  228. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  229. package/dest/services/reqresp/protocols/index.js +0 -1
  230. package/dest/services/reqresp/protocols/tx.d.ts +1 -1
  231. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  232. package/dest/services/reqresp/protocols/tx.js +1 -3
  233. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
  234. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  235. package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
  236. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
  237. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  238. package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
  239. package/dest/services/reqresp/reqresp.d.ts +7 -29
  240. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  241. package/dest/services/reqresp/reqresp.js +75 -216
  242. package/dest/services/service.d.ts +29 -14
  243. package/dest/services/service.d.ts.map +1 -1
  244. package/dest/services/tx_collection/config.d.ts +8 -17
  245. package/dest/services/tx_collection/config.d.ts.map +1 -1
  246. package/dest/services/tx_collection/config.js +17 -40
  247. package/dest/services/tx_collection/file_store_tx_collection.d.ts +25 -32
  248. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  249. package/dest/services/tx_collection/file_store_tx_collection.js +96 -87
  250. package/dest/services/tx_collection/file_store_tx_source.d.ts +17 -6
  251. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  252. package/dest/services/tx_collection/file_store_tx_source.js +53 -10
  253. package/dest/services/tx_collection/index.d.ts +2 -3
  254. package/dest/services/tx_collection/index.d.ts.map +1 -1
  255. package/dest/services/tx_collection/index.js +0 -1
  256. package/dest/services/tx_collection/instrumentation.js +1 -2
  257. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  258. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  259. package/dest/services/tx_collection/request_tracker.js +84 -0
  260. package/dest/services/tx_collection/tx_collection.d.ts +39 -55
  261. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  262. package/dest/services/tx_collection/tx_collection.js +280 -108
  263. package/dest/services/tx_collection/tx_collection_sink.d.ts +7 -6
  264. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  265. package/dest/services/tx_collection/tx_collection_sink.js +15 -24
  266. package/dest/services/tx_collection/tx_source.d.ts +13 -7
  267. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  268. package/dest/services/tx_collection/tx_source.js +29 -7
  269. package/dest/services/tx_file_store/tx_file_store.d.ts +3 -4
  270. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  271. package/dest/services/tx_file_store/tx_file_store.js +13 -20
  272. package/dest/services/tx_provider.d.ts +5 -3
  273. package/dest/services/tx_provider.d.ts.map +1 -1
  274. package/dest/services/tx_provider.js +7 -4
  275. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  276. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  277. package/dest/test-helpers/make-test-p2p-clients.js +5 -3
  278. package/dest/test-helpers/mock-pubsub.d.ts +26 -12
  279. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  280. package/dest/test-helpers/mock-pubsub.js +51 -45
  281. package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
  282. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  283. package/dest/test-helpers/reqresp-nodes.js +17 -19
  284. package/dest/test-helpers/test_tx_provider.d.ts +3 -1
  285. package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
  286. package/dest/test-helpers/test_tx_provider.js +3 -0
  287. package/dest/test-helpers/testbench-utils.d.ts +22 -16
  288. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  289. package/dest/test-helpers/testbench-utils.js +56 -16
  290. package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
  291. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  292. package/dest/testbench/p2p_client_testbench_worker.js +111 -48
  293. package/dest/testbench/worker_client_manager.d.ts +12 -6
  294. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  295. package/dest/testbench/worker_client_manager.js +57 -11
  296. package/dest/util.d.ts +13 -8
  297. package/dest/util.d.ts.map +1 -1
  298. package/dest/util.js +35 -14
  299. package/dest/versioning.d.ts +3 -6
  300. package/dest/versioning.d.ts.map +1 -1
  301. package/dest/versioning.js +3 -24
  302. package/package.json +16 -16
  303. package/src/bootstrap/bootstrap.ts +17 -3
  304. package/src/client/factory.ts +95 -51
  305. package/src/client/interface.ts +59 -35
  306. package/src/client/p2p_client.ts +186 -196
  307. package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
  308. package/src/config.ts +259 -57
  309. package/src/errors/p2p-service.error.ts +11 -0
  310. package/src/errors/reqresp.error.ts +13 -19
  311. package/src/errors/tx-pool.error.ts +12 -0
  312. package/src/index.ts +0 -1
  313. package/src/mem_pools/attestation_pool/attestation_pool.ts +336 -242
  314. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +244 -69
  315. package/src/mem_pools/attestation_pool/mocks.ts +14 -8
  316. package/src/mem_pools/index.ts +0 -3
  317. package/src/mem_pools/instrumentation.ts +27 -17
  318. package/src/mem_pools/tx_pool_v2/README.md +52 -28
  319. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
  320. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +114 -27
  321. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  322. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +8 -4
  323. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  324. package/src/mem_pools/tx_pool_v2/eviction/index.ts +5 -0
  325. package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
  326. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
  327. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  328. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -8
  329. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  330. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
  331. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
  332. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  333. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  334. package/src/mem_pools/tx_pool_v2/interfaces.ts +61 -14
  335. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +170 -28
  336. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +91 -43
  337. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +54 -14
  338. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +527 -207
  339. package/src/msg_validators/attestation_validator/README.md +49 -0
  340. package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
  341. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
  342. package/src/msg_validators/proposal_validator/README.md +123 -0
  343. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
  344. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
  345. package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
  346. package/src/msg_validators/tx_validator/README.md +129 -0
  347. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +6 -15
  348. package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
  349. package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
  350. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  351. package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
  352. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  353. package/src/msg_validators/tx_validator/data_validator.ts +44 -1
  354. package/src/msg_validators/tx_validator/factory.ts +413 -80
  355. package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
  356. package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
  357. package/src/msg_validators/tx_validator/index.ts +4 -0
  358. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  359. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  360. package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
  361. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  362. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
  363. package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
  364. package/src/services/data_store.ts +5 -13
  365. package/src/services/discv5/discV5_service.ts +126 -14
  366. package/src/services/discv5/persisted_enr_store.ts +158 -0
  367. package/src/services/dummy_service.ts +26 -45
  368. package/src/services/encoding.ts +40 -24
  369. package/src/services/gossipsub/README.md +59 -22
  370. package/src/services/gossipsub/topic_score_params.ts +58 -31
  371. package/src/services/libp2p/instrumentation.ts +14 -0
  372. package/src/services/libp2p/libp2p_service.ts +554 -428
  373. package/src/services/peer-manager/metrics.ts +7 -0
  374. package/src/services/peer-manager/peer_manager.ts +91 -25
  375. package/src/services/peer-manager/peer_scoring.ts +102 -8
  376. package/src/services/reqresp/README.md +194 -0
  377. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  378. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +92 -138
  379. package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
  380. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
  381. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  382. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
  383. package/src/services/reqresp/config.ts +19 -2
  384. package/src/services/reqresp/interface.ts +21 -47
  385. package/src/services/reqresp/metrics.ts +0 -1
  386. package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
  387. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
  388. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
  389. package/src/services/reqresp/protocols/index.ts +0 -1
  390. package/src/services/reqresp/protocols/tx.ts +1 -3
  391. package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
  392. package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
  393. package/src/services/reqresp/reqresp.ts +87 -260
  394. package/src/services/service.ts +42 -30
  395. package/src/services/tx_collection/config.ts +24 -59
  396. package/src/services/tx_collection/file_store_tx_collection.ts +108 -107
  397. package/src/services/tx_collection/file_store_tx_source.ts +69 -10
  398. package/src/services/tx_collection/index.ts +1 -6
  399. package/src/services/tx_collection/instrumentation.ts +1 -1
  400. package/src/services/tx_collection/request_tracker.ts +127 -0
  401. package/src/services/tx_collection/tx_collection.ts +342 -156
  402. package/src/services/tx_collection/tx_collection_sink.ts +17 -31
  403. package/src/services/tx_collection/tx_source.ts +29 -8
  404. package/src/services/tx_file_store/tx_file_store.ts +11 -21
  405. package/src/services/tx_provider.ts +7 -2
  406. package/src/test-helpers/make-test-p2p-clients.ts +4 -3
  407. package/src/test-helpers/mock-pubsub.ts +59 -66
  408. package/src/test-helpers/reqresp-nodes.ts +15 -28
  409. package/src/test-helpers/test_tx_provider.ts +5 -0
  410. package/src/test-helpers/testbench-utils.ts +74 -31
  411. package/src/testbench/p2p_client_testbench_worker.ts +120 -63
  412. package/src/testbench/worker_client_manager.ts +72 -25
  413. package/src/util.ts +40 -19
  414. package/src/versioning.ts +3 -33
  415. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
  416. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
  417. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
  418. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
  419. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
  420. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
  421. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
  422. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  423. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
  424. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
  425. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
  426. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
  427. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
  428. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
  429. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
  430. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
  431. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
  432. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
  433. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
  434. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
  435. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
  436. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
  437. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
  438. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
  439. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
  440. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
  441. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
  442. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
  443. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
  444. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
  445. package/dest/mem_pools/tx_pool/index.d.ts +0 -3
  446. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  447. package/dest/mem_pools/tx_pool/index.js +0 -2
  448. package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
  449. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  450. package/dest/mem_pools/tx_pool/priority.js +0 -15
  451. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
  452. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  453. package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
  454. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  455. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  456. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
  457. package/dest/msg_validators/clock_tolerance.d.ts +0 -21
  458. package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
  459. package/dest/msg_validators/clock_tolerance.js +0 -37
  460. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
  461. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
  462. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
  463. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
  464. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  465. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
  466. package/dest/services/reqresp/protocols/block.d.ts +0 -9
  467. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  468. package/dest/services/reqresp/protocols/block.js +0 -32
  469. package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -54
  470. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
  471. package/dest/services/tx_collection/fast_tx_collection.js +0 -321
  472. package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
  473. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
  474. package/dest/services/tx_collection/proposal_tx_collector.js +0 -49
  475. package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -55
  476. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
  477. package/dest/services/tx_collection/slow_tx_collection.js +0 -206
  478. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
  479. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
  480. package/src/mem_pools/tx_pool/README.md +0 -270
  481. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
  482. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
  483. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
  484. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
  485. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
  486. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
  487. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
  488. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
  489. package/src/mem_pools/tx_pool/index.ts +0 -2
  490. package/src/mem_pools/tx_pool/priority.ts +0 -20
  491. package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
  492. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
  493. package/src/msg_validators/clock_tolerance.ts +0 -51
  494. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
  495. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
  496. package/src/services/reqresp/protocols/block.ts +0 -37
  497. package/src/services/tx_collection/fast_tx_collection.ts +0 -366
  498. package/src/services/tx_collection/proposal_tx_collector.ts +0 -112
  499. package/src/services/tx_collection/slow_tx_collection.ts +0 -262
@@ -1,26 +1,9 @@
1
- import {
2
- type ConfigMappingsType,
3
- booleanConfigHelper,
4
- enumConfigHelper,
5
- numberConfigHelper,
6
- } from '@aztec/foundation/config';
1
+ import { type ConfigMappingsType, numberConfigHelper } from '@aztec/foundation/config';
7
2
  import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
8
3
 
9
- export type MissingTxsCollectorType = 'new' | 'old';
10
-
11
4
  export type TxCollectionConfig = {
12
5
  /** How long to wait before starting reqresp for fast collection */
13
6
  txCollectionFastNodesTimeoutBeforeReqRespMs: number;
14
- /** How often to collect from configured nodes */
15
- txCollectionSlowNodesIntervalMs: number;
16
- /** How ofter to collect from peers */
17
- txCollectionSlowReqRespIntervalMs: number;
18
- /** How long to wait for a reqresp response during slow collection */
19
- txCollectionSlowReqRespTimeoutMs: number;
20
- /** How often to reconcile found txs with the tx pool */
21
- txCollectionReconcileIntervalMs: number;
22
- /** Whether to disable the slow collection loop if we are dealing with any immediate requests */
23
- txCollectionDisableSlowDuringFastRequests: boolean;
24
7
  /** How many ms to wait between retried request to a node via RPC during fast collection */
25
8
  txCollectionFastNodeIntervalMs: number;
26
9
  /** A comma-separated list of Aztec node RPC URLs to use for tx collection */
@@ -29,14 +12,16 @@ export type TxCollectionConfig = {
29
12
  txCollectionFastMaxParallelRequestsPerNode: number;
30
13
  /** Maximum number of transactions to request from a node in a single batch */
31
14
  txCollectionNodeRpcMaxBatchSize: number;
32
- /** Which collector implementation to use for missing txs collection */
33
- txCollectionMissingTxsCollectorType: MissingTxsCollectorType;
34
15
  /** A comma-separated list of file store URLs (s3://, gs://, file://, http://) for tx collection */
35
16
  txCollectionFileStoreUrls: string[];
36
- /** Delay in ms before file store collection starts after slow collection is triggered */
37
- txCollectionFileStoreSlowDelayMs: number;
38
- /** Delay in ms before file store collection starts after fast collection is triggered */
17
+ /** Delay in ms from reqresp start before file store collection begins */
39
18
  txCollectionFileStoreFastDelayMs: number;
19
+ /** Number of concurrent workers for fast file store collection */
20
+ txCollectionFileStoreFastWorkerCount: number;
21
+ /** Base backoff time in ms for fast file store collection retries */
22
+ txCollectionFileStoreFastBackoffBaseMs: number;
23
+ /** Max backoff time in ms for fast file store collection retries */
24
+ txCollectionFileStoreFastBackoffMaxMs: number;
40
25
  };
41
26
 
42
27
  export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
@@ -45,31 +30,6 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
45
30
  description: 'How long to wait before starting reqresp for fast collection',
46
31
  ...numberConfigHelper(200),
47
32
  },
48
- txCollectionSlowNodesIntervalMs: {
49
- env: 'TX_COLLECTION_SLOW_NODES_INTERVAL_MS',
50
- description: 'How often to collect from configured nodes in the slow collection loop',
51
- ...numberConfigHelper(12_000),
52
- },
53
- txCollectionSlowReqRespIntervalMs: {
54
- env: 'TX_COLLECTION_SLOW_REQ_RESP_INTERVAL_MS',
55
- description: 'How often to collect from peers via reqresp in the slow collection loop',
56
- ...numberConfigHelper(12_000),
57
- },
58
- txCollectionSlowReqRespTimeoutMs: {
59
- env: 'TX_COLLECTION_SLOW_REQ_RESP_TIMEOUT_MS',
60
- description: 'How long to wait for a reqresp response during slow collection',
61
- ...numberConfigHelper(20_000),
62
- },
63
- txCollectionReconcileIntervalMs: {
64
- env: 'TX_COLLECTION_RECONCILE_INTERVAL_MS',
65
- description: 'How often to reconcile found txs from the tx pool',
66
- ...numberConfigHelper(60_000),
67
- },
68
- txCollectionDisableSlowDuringFastRequests: {
69
- env: 'TX_COLLECTION_DISABLE_SLOW_DURING_FAST_REQUESTS',
70
- description: 'Whether to disable the slow collection loop if we are dealing with any immediate requests',
71
- ...booleanConfigHelper(true),
72
- },
73
33
  txCollectionFastNodeIntervalMs: {
74
34
  env: 'TX_COLLECTION_FAST_NODE_INTERVAL_MS',
75
35
  description: 'How many ms to wait between retried request to a node via RPC during fast collection',
@@ -96,11 +56,6 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
96
56
  description: 'Maximum number of transactions to request from a node in a single batch',
97
57
  ...numberConfigHelper(MAX_RPC_TXS_LEN),
98
58
  },
99
- txCollectionMissingTxsCollectorType: {
100
- env: 'TX_COLLECTION_MISSING_TXS_COLLECTOR_TYPE',
101
- description: 'Which collector implementation to use for missing txs collection (new or old)',
102
- ...enumConfigHelper(['new', 'old'] as const, 'new'),
103
- },
104
59
  txCollectionFileStoreUrls: {
105
60
  env: 'TX_COLLECTION_FILE_STORE_URLS',
106
61
  description: 'A comma-separated list of file store URLs (s3://, gs://, file://, http://) for tx collection',
@@ -111,14 +66,24 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
111
66
  .filter(url => url.length > 0),
112
67
  defaultValue: [],
113
68
  },
114
- txCollectionFileStoreSlowDelayMs: {
115
- env: 'TX_COLLECTION_FILE_STORE_SLOW_DELAY_MS',
116
- description: 'Delay before file store collection starts after slow collection',
117
- ...numberConfigHelper(24_000),
118
- },
119
69
  txCollectionFileStoreFastDelayMs: {
120
70
  env: 'TX_COLLECTION_FILE_STORE_FAST_DELAY_MS',
121
- description: 'Delay before file store collection starts after fast collection',
71
+ description: 'Delay in ms from reqresp start before file store collection begins',
122
72
  ...numberConfigHelper(2_000),
123
73
  },
74
+ txCollectionFileStoreFastWorkerCount: {
75
+ env: 'TX_COLLECTION_FILE_STORE_FAST_WORKER_COUNT',
76
+ description: 'Number of concurrent workers for fast file store collection',
77
+ ...numberConfigHelper(5),
78
+ },
79
+ txCollectionFileStoreFastBackoffBaseMs: {
80
+ env: 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_BASE_MS',
81
+ description: 'Base backoff time in ms for fast file store collection retries',
82
+ ...numberConfigHelper(1_000),
83
+ },
84
+ txCollectionFileStoreFastBackoffMaxMs: {
85
+ env: 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_MAX_MS',
86
+ description: 'Max backoff time in ms for fast file store collection retries',
87
+ ...numberConfigHelper(5_000),
88
+ },
124
89
  };
@@ -1,136 +1,96 @@
1
+ import { times } from '@aztec/foundation/collection';
1
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
- import { FifoMemoryQueue } from '@aztec/foundation/queue';
3
- import { Tx, TxHash } from '@aztec/stdlib/tx';
3
+ import { sleep } from '@aztec/foundation/sleep';
4
+ import { DateProvider } from '@aztec/foundation/timer';
5
+ import { TxHash } from '@aztec/stdlib/tx';
4
6
 
5
7
  import type { FileStoreTxSource } from './file_store_tx_source.js';
8
+ import type { IRequestTracker } from './request_tracker.js';
6
9
  import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
7
10
 
8
- // Internal constants (not configurable by node operators)
9
- const FILE_STORE_DOWNLOAD_CONCURRENCY = 5; // Max concurrent downloads
11
+ /** Configuration for a FileStoreTxCollection instance. */
12
+ export type FileStoreCollectionConfig = {
13
+ workerCount: number;
14
+ backoffBaseMs: number;
15
+ backoffMaxMs: number;
16
+ };
17
+
18
+ type FileStoreTxEntry = {
19
+ txHash: string;
20
+ attempts: number;
21
+ lastAttemptTime: number;
22
+ nextSourceIndex: number;
23
+ };
10
24
 
11
25
  /**
12
26
  * Collects txs from file stores as a fallback after P2P methods have been tried.
13
- * Runs in parallel to slow/fast collection. The delay before starting file store
14
- * collection is managed by the TxCollection orchestrator, not this class.
27
+ * Each call to startCollecting spins up its own worker pool which pulls entries with priority
28
+ * (fewest attempts first), retries with round-robin across sources, and applies exponential
29
+ * backoff between full cycles through all sources. Workers self-terminate when the request
30
+ * tracker is cancelled (deadline / all-fetched / external) or when there is nothing left to do.
15
31
  */
16
32
  export class FileStoreTxCollection {
17
- /** Map from tx hash to add context for txs queued for download. */
18
- private pendingTxs = new Map<string, TxAddContext>();
19
-
20
- /**
21
- * Tracks tx hashes found elsewhere, even before startCollecting is called.
22
- * Needed because the orchestrator delays startCollecting via a real sleep, but foundTxs
23
- * may arrive during that delay — before the hashes are added to pendingTxs.
24
- */
25
- private foundTxHashes = new Set<string>();
26
-
27
- /** Queue of tx hashes to be downloaded. */
28
- private downloadQueue = new FifoMemoryQueue<TxHash>();
29
-
30
- /** Worker promises for concurrent downloads. */
31
- private workers: Promise<void>[] = [];
32
-
33
- /** Whether the collection has been started. */
34
- private started = false;
35
-
36
33
  constructor(
37
- private readonly fileStoreSources: FileStoreTxSource[],
34
+ private readonly sources: FileStoreTxSource[],
38
35
  private readonly txCollectionSink: TxCollectionSink,
36
+ private readonly config: FileStoreCollectionConfig,
37
+ private readonly dateProvider: DateProvider = new DateProvider(),
39
38
  private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
40
39
  ) {}
41
40
 
42
- /** Starts the file store collection workers. */
43
- public start() {
44
- if (this.fileStoreSources.length === 0) {
45
- this.log.debug('No file store sources configured, skipping file store collection');
41
+ /**
42
+ * Spins up workers to download all txs still missing from the tracker, racing across the
43
+ * configured file store sources. Resolves once all workers settle.
44
+ */
45
+ public async startCollecting(requestTracker: IRequestTracker, context: TxAddContext): Promise<void> {
46
+ if (this.sources.length === 0 || requestTracker.checkCancelled()) {
46
47
  return;
47
48
  }
48
49
 
49
- this.started = true;
50
- this.downloadQueue = new FifoMemoryQueue<TxHash>();
51
-
52
- // Start concurrent download workers
53
- for (let i = 0; i < FILE_STORE_DOWNLOAD_CONCURRENCY; i++) {
54
- this.workers.push(this.downloadQueue.process(txHash => this.processDownload(txHash)));
50
+ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
51
+ const entries: Set<FileStoreTxEntry> = new Set();
52
+ for (const hashStr of requestTracker.missingTxHashes) {
53
+ entries.add({
54
+ txHash: hashStr,
55
+ attempts: 0,
56
+ lastAttemptTime: 0,
57
+ nextSourceIndex: Math.floor(Math.random() * this.sources.length),
58
+ });
55
59
  }
56
60
 
57
- this.log.info(`Started file store tx collection with ${this.fileStoreSources.length} sources`, {
58
- sources: this.fileStoreSources.map(s => s.getInfo()),
59
- concurrency: FILE_STORE_DOWNLOAD_CONCURRENCY,
60
- });
61
- }
62
-
63
- /** Stops all collection activity. */
64
- public async stop() {
65
- if (!this.started) {
61
+ // Yield before spawning so the synchronous caller can finish any follow-up (eg. marking a tx
62
+ // as fetched on the tracker, or cancelling it) before workers begin scanning entries.
63
+ await Promise.resolve();
64
+ if (requestTracker.checkCancelled()) {
66
65
  return;
67
66
  }
68
- this.started = false;
69
- this.downloadQueue.end();
70
- await Promise.all(this.workers);
71
- this.workers = [];
72
- this.pendingTxs.clear();
73
- this.foundTxHashes.clear();
74
- }
75
-
76
- /** Remove the given tx hashes from pending. */
77
- public stopCollecting(txHashes: TxHash[]) {
78
- for (const txHash of txHashes) {
79
- const hashStr = txHash.toString();
80
- this.pendingTxs.delete(hashStr);
81
- }
82
- }
83
67
 
84
- /** Clears all pending state. Items already in the download queue will still be processed but won't be re-queued. */
85
- public clearPending() {
86
- this.pendingTxs.clear();
87
- this.foundTxHashes.clear();
68
+ await Promise.allSettled(times(this.config.workerCount, () => this.workerLoop(entries, requestTracker, context)));
88
69
  }
89
70
 
90
- /** Queue the given tx hashes for file store collection. */
91
- public startCollecting(txHashes: TxHash[], context: TxAddContext) {
92
- for (const txHash of txHashes) {
93
- const hashStr = txHash.toString();
94
- if (!this.pendingTxs.has(hashStr) && !this.foundTxHashes.has(hashStr)) {
95
- this.pendingTxs.set(hashStr, context);
96
- this.downloadQueue.put(txHash);
71
+ private async workerLoop(
72
+ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
73
+ entries: Set<FileStoreTxEntry>,
74
+ requestTracker: IRequestTracker,
75
+ context: TxAddContext,
76
+ ): Promise<void> {
77
+ while (!requestTracker.checkCancelled() && entries.size > 0) {
78
+ const action = this.getNextAction(entries, requestTracker);
79
+ if (action.type === 'sleep') {
80
+ await Promise.race([sleep(action.ms), requestTracker.cancellationToken]);
81
+ continue;
97
82
  }
98
- }
99
- }
100
83
 
101
- /** Stop tracking txs that were found elsewhere. */
102
- public foundTxs(txs: Tx[]) {
103
- for (const tx of txs) {
104
- const hashStr = tx.getTxHash().toString();
105
- this.pendingTxs.delete(hashStr);
106
- this.foundTxHashes.add(hashStr);
107
- }
108
- }
109
-
110
- /** Processes a single tx hash from the download queue. */
111
- private async processDownload(txHash: TxHash) {
112
- const hashStr = txHash.toString();
113
- const context = this.pendingTxs.get(hashStr);
114
-
115
- // Skip if already found by another method
116
- if (!context) {
117
- return;
118
- }
119
-
120
- await this.downloadTx(txHash, context);
121
- this.pendingTxs.delete(hashStr);
122
- }
123
-
124
- /** Attempt to download a tx from file stores (round-robin). */
125
- private async downloadTx(txHash: TxHash, context: TxAddContext) {
126
- const startIndex = Math.floor(Math.random() * this.fileStoreSources.length);
127
- for (let i = startIndex; i < startIndex + this.fileStoreSources.length; i++) {
128
- const source = this.fileStoreSources[i % this.fileStoreSources.length];
84
+ const entry = action.entry;
85
+ const source = this.sources[entry.nextSourceIndex % this.sources.length];
86
+ entry.nextSourceIndex++;
87
+ entry.attempts++;
88
+ entry.lastAttemptTime = this.dateProvider.now();
129
89
 
130
90
  try {
131
91
  const result = await this.txCollectionSink.collect(
132
- hashes => source.getTxsByHash(hashes),
133
- [txHash],
92
+ () => source.getTxsByHash([TxHash.fromString(entry.txHash)]),
93
+ [entry.txHash],
134
94
  {
135
95
  description: `file-store ${source.getInfo()}`,
136
96
  method: 'file-store',
@@ -138,15 +98,56 @@ export class FileStoreTxCollection {
138
98
  },
139
99
  context,
140
100
  );
141
-
142
101
  if (result.txs.length > 0) {
143
- return;
102
+ entries.delete(entry);
144
103
  }
145
104
  } catch (err) {
146
- this.log.trace(`Failed to download tx ${txHash} from ${source.getInfo()}`, { err });
105
+ this.log.trace(`Error downloading tx ${entry.txHash} from ${source.getInfo()}`, { err });
147
106
  }
148
107
  }
108
+ }
149
109
 
150
- this.log.trace(`Tx ${txHash} not found in any file store`);
110
+ /** Single-pass scan: removes stale entries, finds the best ready entry, or computes sleep time. */
111
+ private getNextAction(
112
+ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
113
+ entries: Set<FileStoreTxEntry>,
114
+ requestTracker: IRequestTracker,
115
+ ): { type: 'process'; entry: FileStoreTxEntry } | { type: 'sleep'; ms: number } {
116
+ const now = this.dateProvider.now();
117
+ let best: FileStoreTxEntry | undefined;
118
+ let earliestReadyAt = Infinity;
119
+
120
+ for (const entry of entries) {
121
+ // Drop entries whose tx was already found via another collection path.
122
+ if (!requestTracker.isMissing(entry.txHash)) {
123
+ entries.delete(entry);
124
+ continue;
125
+ }
126
+ const backoffMs = this.getBackoffMs(entry);
127
+ const readyAt = entry.lastAttemptTime + backoffMs;
128
+ if (readyAt > now) {
129
+ earliestReadyAt = Math.min(earliestReadyAt, readyAt);
130
+ continue;
131
+ }
132
+ if (!best || entry.attempts < best.attempts) {
133
+ best = entry;
134
+ }
135
+ }
136
+
137
+ if (best) {
138
+ return { type: 'process', entry: best };
139
+ }
140
+ // earliestReadyAt is finite whenever there are surviving entries; if entries became empty,
141
+ // the outer worker loop will exit on its next iteration via entries.size === 0.
142
+ return { type: 'sleep', ms: earliestReadyAt === Infinity ? 0 : earliestReadyAt - now };
143
+ }
144
+
145
+ /** Computes backoff for an entry. Backoff applies after a full cycle through all sources. */
146
+ private getBackoffMs(entry: FileStoreTxEntry): number {
147
+ const fullCycles = Math.floor(entry.attempts / this.sources.length);
148
+ if (fullCycles === 0) {
149
+ return 0;
150
+ }
151
+ return Math.min(this.config.backoffBaseMs * Math.pow(2, fullCycles - 1), this.config.backoffMaxMs);
151
152
  }
152
153
  }
@@ -1,26 +1,54 @@
1
+ import { partitionAsync } from '@aztec/foundation/collection';
1
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
+ import { Timer } from '@aztec/foundation/timer';
2
4
  import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
3
- import { Tx, type TxHash } from '@aztec/stdlib/tx';
5
+ import { Tx, type TxHash, type TxValidator } from '@aztec/stdlib/tx';
6
+ import {
7
+ type Histogram,
8
+ Metrics,
9
+ type TelemetryClient,
10
+ type UpDownCounter,
11
+ getTelemetryClient,
12
+ } from '@aztec/telemetry-client';
4
13
 
5
- import type { TxSource } from './tx_source.js';
14
+ import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
6
15
 
7
16
  /** TxSource implementation that downloads txs from a file store. */
8
17
  export class FileStoreTxSource implements TxSource {
18
+ private downloadsSuccess: UpDownCounter;
19
+ private downloadsFailed: UpDownCounter;
20
+ private downloadDuration: Histogram;
21
+ private downloadSize: Histogram;
22
+
9
23
  private constructor(
10
24
  private readonly fileStore: ReadOnlyFileStore,
11
25
  private readonly baseUrl: string,
26
+ private readonly basePath: string,
27
+ private readonly txValidator: TxValidator,
12
28
  private readonly log: Logger,
13
- ) {}
29
+ telemetry: TelemetryClient,
30
+ ) {
31
+ const meter = telemetry.getMeter('file-store-tx-source');
32
+ this.downloadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_SUCCESS);
33
+ this.downloadsFailed = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_FAILED);
34
+ this.downloadDuration = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_DURATION);
35
+ this.downloadSize = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_SIZE);
36
+ }
14
37
 
15
38
  /**
16
39
  * Creates a FileStoreTxSource from a URL.
17
40
  * @param url - The file store URL (s3://, gs://, file://, http://, https://).
41
+ * @param basePath - Base path for tx files within the store.
18
42
  * @param log - Optional logger.
43
+ * @param telemetry - Optional telemetry client.
19
44
  * @returns The FileStoreTxSource instance, or undefined if creation fails.
20
45
  */
21
46
  public static async create(
22
47
  url: string,
48
+ basePath: string,
49
+ txValidator: TxValidator,
23
50
  log: Logger = createLogger('p2p:file_store_tx_source'),
51
+ telemetry: TelemetryClient = getTelemetryClient(),
24
52
  ): Promise<FileStoreTxSource | undefined> {
25
53
  try {
26
54
  const fileStore = await createReadOnlyFileStore(url, log);
@@ -28,7 +56,7 @@ export class FileStoreTxSource implements TxSource {
28
56
  log.warn(`Failed to create file store for URL: ${url}`);
29
57
  return undefined;
30
58
  }
31
- return new FileStoreTxSource(fileStore, url, log);
59
+ return new FileStoreTxSource(fileStore, url, basePath, txValidator, log, telemetry);
32
60
  } catch (err) {
33
61
  log.warn(`Error creating file store for URL: ${url}`, { error: err });
34
62
  return undefined;
@@ -39,32 +67,63 @@ export class FileStoreTxSource implements TxSource {
39
67
  return `file-store:${this.baseUrl}`;
40
68
  }
41
69
 
42
- public getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
43
- return Promise.all(
70
+ public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
71
+ const results = await Promise.all(
44
72
  txHashes.map(async txHash => {
45
- const path = `txs/${txHash.toString()}.bin`;
73
+ const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
74
+ const timer = new Timer();
46
75
  try {
47
76
  const buffer = await this.fileStore.read(path);
48
- return Tx.fromBuffer(buffer);
77
+ const tx = Tx.fromBuffer(buffer);
78
+ return { tx, downloadDuration: timer.ms(), downloadSize: buffer.length };
49
79
  } catch {
50
- // Tx not found or error reading - return undefined
80
+ this.downloadsFailed.add(1);
51
81
  return undefined;
52
82
  }
53
83
  }),
54
84
  );
85
+
86
+ const txs = results.filter(tx => tx !== undefined);
87
+ const [validTxs, invalidTxs] = await partitionAsync(
88
+ txs,
89
+ async ({ tx, downloadDuration, downloadSize }): Promise<boolean> => {
90
+ const valid = await this.txValidator.validateTx(tx);
91
+ if (valid.result === 'valid') {
92
+ this.downloadsSuccess.add(1);
93
+ this.downloadDuration.record(Math.ceil(downloadDuration));
94
+ this.downloadSize.record(downloadSize);
95
+ return true;
96
+ } else {
97
+ this.downloadsFailed.add(1);
98
+ return false;
99
+ }
100
+ },
101
+ );
102
+
103
+ return {
104
+ validTxs: validTxs.map(({ tx }) => tx),
105
+ invalidTxHashes: invalidTxs.map(({ tx }) => tx.getTxHash().toString()),
106
+ };
55
107
  }
56
108
  }
57
109
 
58
110
  /**
59
111
  * Creates FileStoreTxSource instances from URLs.
60
112
  * @param urls - Array of file store URLs.
113
+ * @param basePath - Base path for tx files within each store.
61
114
  * @param log - Optional logger.
115
+ * @param telemetry - Optional telemetry client.
62
116
  * @returns Array of successfully created FileStoreTxSource instances.
63
117
  */
64
118
  export async function createFileStoreTxSources(
65
119
  urls: string[],
120
+ basePath: string,
121
+ txValidator: TxValidator,
66
122
  log: Logger = createLogger('p2p:file_store_tx_source'),
123
+ telemetry: TelemetryClient = getTelemetryClient(),
67
124
  ): Promise<FileStoreTxSource[]> {
68
- const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, log)));
125
+ const sources = await Promise.all(
126
+ urls.map(url => FileStoreTxSource.create(url, basePath, txValidator, log, telemetry)),
127
+ );
69
128
  return sources.filter((s): s is FileStoreTxSource => s !== undefined);
70
129
  }
@@ -1,8 +1,3 @@
1
- export { TxCollection, type FastCollectionRequestInput } from './tx_collection.js';
1
+ export { TxCollection, type FastCollectionRequestInput, type IReqRespTxsCollector } from './tx_collection.js';
2
2
  export { type TxSource, createNodeRpcTxSources, NodeRpcTxSource } from './tx_source.js';
3
- export {
4
- type MissingTxsCollector,
5
- BatchTxRequesterCollector,
6
- SendBatchRequestCollector,
7
- } from './proposal_tx_collector.js';
8
3
  export { FileStoreTxSource, createFileStoreTxSources } from './file_store_tx_source.js';
@@ -18,7 +18,7 @@ export class TxCollectionInstrumentation {
18
18
  const meter = client.getMeter(name);
19
19
 
20
20
  this.txsCollected = createUpDownCounterWithDefault(meter, Metrics.TX_COLLECTOR_COUNT, {
21
- [Attributes.TX_COLLECTION_METHOD]: ['fast-req-resp', 'fast-node-rpc', 'slow-req-resp', 'slow-node-rpc'],
21
+ [Attributes.TX_COLLECTION_METHOD]: ['fast-req-resp', 'fast-node-rpc', 'file-store'],
22
22
  });
23
23
 
24
24
  this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
@@ -0,0 +1,127 @@
1
+ import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
2
+ import type { DateProvider } from '@aztec/foundation/timer';
3
+ import { TxHash } from '@aztec/stdlib/tx';
4
+ import type { Tx } from '@aztec/stdlib/tx';
5
+
6
+ /**
7
+ * Tracks which transactions are still missing and need to be fetched.
8
+ * Manages the request deadline and serves as the sole source of cancellation signal.
9
+ * The request is cancelled when all txs are fetched or the deadline expires.
10
+ */
11
+ export interface IRequestTracker {
12
+ /** Returns the set of transaction hashes that are still missing. */
13
+ get missingTxHashes(): Set<string>;
14
+ /** Size of this.missingTxHashes */
15
+ get numberOfMissingTxs(): number;
16
+ /** Are all requested txs fetched */
17
+ allFetched(): boolean;
18
+ /** Checks that transaction is still missing */
19
+ isMissing(txHash: string): boolean;
20
+ /** Marks a transaction as fetched. Returns true if it was previously missing. */
21
+ markFetched(tx: Tx): boolean;
22
+ /** Get list of collected txs */
23
+ get collectedTxs(): Tx[];
24
+ /** The deadline for this request. */
25
+ get deadline(): Date;
26
+ /** Remaining time in milliseconds until deadline. Returns 0 if already past. */
27
+ get timeoutMs(): number;
28
+ /** Checks whether the request is cancelled (deadline expired or all fetched). May trigger cancellation if deadline has passed. */
29
+ checkCancelled(): boolean;
30
+ /** Resolves when deadline expires or all txs are fetched. */
31
+ get cancellationToken(): Promise<void>;
32
+ /** Externally cancel the request. */
33
+ cancel(): void;
34
+ }
35
+
36
+ export class RequestTracker implements IRequestTracker {
37
+ public readonly collectedTxs: Tx[] = [];
38
+ private done = false;
39
+ private readonly cancellationTokenPromise: PromiseWithResolvers<void>;
40
+ private readonly deadlineTimer: ReturnType<typeof setTimeout> | undefined;
41
+
42
+ private constructor(
43
+ public readonly missingTxHashes: Set<string>,
44
+ public readonly deadline: Date,
45
+ private readonly dateProvider?: DateProvider,
46
+ ) {
47
+ this.cancellationTokenPromise = promiseWithResolvers<void>();
48
+
49
+ if (missingTxHashes.size === 0) {
50
+ this.finish();
51
+ return;
52
+ }
53
+
54
+ const now = this.dateProvider?.now() ?? Date.now();
55
+ const remaining = deadline.getTime() - now;
56
+ if (remaining <= 0) {
57
+ this.finish();
58
+ } else {
59
+ this.deadlineTimer = setTimeout(() => this.finish(), remaining);
60
+ }
61
+ }
62
+
63
+ public static create(hashes: TxHash[] | string[], deadline: Date, dateProvider?: DateProvider) {
64
+ return new RequestTracker(new Set(hashes.map(hash => hash.toString())), deadline, dateProvider);
65
+ }
66
+
67
+ markFetched(tx: Tx): boolean {
68
+ if (this.missingTxHashes.delete(tx.txHash.toString())) {
69
+ this.collectedTxs.push(tx);
70
+ if (this.allFetched()) {
71
+ this.finish();
72
+ }
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+
78
+ get numberOfMissingTxs(): number {
79
+ return this.missingTxHashes.size;
80
+ }
81
+
82
+ allFetched(): boolean {
83
+ return this.numberOfMissingTxs === 0;
84
+ }
85
+
86
+ isMissing(txHash: string): boolean {
87
+ return this.missingTxHashes.has(txHash.toString());
88
+ }
89
+
90
+ get timeoutMs(): number {
91
+ const now = this.dateProvider?.now() ?? Date.now();
92
+ return Math.max(0, this.deadline.getTime() - now);
93
+ }
94
+
95
+ checkCancelled(): boolean {
96
+ if (this.done) {
97
+ return true;
98
+ }
99
+ // Synchronous fallback: check deadline even if setTimeout hasn't fired yet.
100
+ // This prevents macrotask starvation in tight async loops from blocking cancellation.
101
+ const now = this.dateProvider?.now() ?? Date.now();
102
+ if (now >= this.deadline.getTime()) {
103
+ this.finish();
104
+ return true;
105
+ }
106
+ return false;
107
+ }
108
+
109
+ get cancellationToken(): Promise<void> {
110
+ return this.cancellationTokenPromise.promise;
111
+ }
112
+
113
+ cancel(): void {
114
+ this.finish();
115
+ }
116
+
117
+ private finish() {
118
+ if (this.done) {
119
+ return;
120
+ }
121
+ this.done = true;
122
+ if (this.deadlineTimer) {
123
+ clearTimeout(this.deadlineTimer);
124
+ }
125
+ this.cancellationTokenPromise.resolve();
126
+ }
127
+ }