@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.72dcdcda8

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 (316) hide show
  1. package/dest/client/factory.d.ts +10 -10
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +39 -15
  4. package/dest/client/interface.d.ts +46 -33
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +39 -51
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +145 -200
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +7 -8
  10. package/dest/config.d.ts +24 -8
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +16 -6
  13. package/dest/errors/tx-pool.error.d.ts +8 -0
  14. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  15. package/dest/errors/tx-pool.error.js +9 -0
  16. package/dest/index.d.ts +2 -1
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +1 -0
  19. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
  20. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
  22. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  23. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
  25. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  26. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/index.js +1 -2
  28. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  29. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  30. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  31. package/dest/mem_pools/index.d.ts +3 -2
  32. package/dest/mem_pools/index.d.ts.map +1 -1
  33. package/dest/mem_pools/index.js +1 -1
  34. package/dest/mem_pools/interface.d.ts +5 -5
  35. package/dest/mem_pools/interface.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  37. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
  38. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  39. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
  40. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  41. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  43. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  44. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
  46. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  47. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  49. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  50. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  52. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  53. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  55. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  56. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  57. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  58. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  60. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  61. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  62. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  63. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  64. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  65. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  66. package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
  67. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  68. package/dest/mem_pools/tx_pool_v2/index.js +2 -1
  69. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  70. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  72. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -8
  73. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  74. package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
  75. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +56 -8
  76. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  77. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +108 -10
  78. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  79. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  80. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
  81. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  82. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +11 -6
  84. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +13 -5
  85. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  86. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +342 -185
  87. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  88. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
  90. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  91. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  92. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  93. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  94. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  95. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  96. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  98. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  99. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/factory.js +219 -58
  101. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  102. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  104. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  105. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  106. package/dest/msg_validators/tx_validator/index.js +1 -0
  107. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  108. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  109. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  110. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  111. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  112. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  113. package/dest/services/dummy_service.d.ts +13 -5
  114. package/dest/services/dummy_service.d.ts.map +1 -1
  115. package/dest/services/dummy_service.js +10 -4
  116. package/dest/services/encoding.d.ts +3 -3
  117. package/dest/services/encoding.d.ts.map +1 -1
  118. package/dest/services/encoding.js +11 -10
  119. package/dest/services/gossipsub/index.d.ts +3 -0
  120. package/dest/services/gossipsub/index.d.ts.map +1 -0
  121. package/dest/services/gossipsub/index.js +2 -0
  122. package/dest/services/gossipsub/scoring.d.ts +21 -3
  123. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  124. package/dest/services/gossipsub/scoring.js +24 -7
  125. package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
  126. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  127. package/dest/services/gossipsub/topic_score_params.js +346 -0
  128. package/dest/services/libp2p/libp2p_service.d.ts +95 -43
  129. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  130. package/dest/services/libp2p/libp2p_service.js +418 -331
  131. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  132. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  133. package/dest/services/peer-manager/peer_scoring.js +25 -2
  134. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  135. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  136. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  137. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  138. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  139. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  140. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  141. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  142. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  143. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  144. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  145. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  146. package/dest/services/reqresp/interface.d.ts +10 -1
  147. package/dest/services/reqresp/interface.d.ts.map +1 -1
  148. package/dest/services/reqresp/interface.js +15 -1
  149. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
  150. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  151. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  152. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  153. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  154. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  155. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  156. package/dest/services/reqresp/protocols/tx.js +20 -0
  157. package/dest/services/reqresp/reqresp.d.ts +1 -1
  158. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  159. package/dest/services/reqresp/reqresp.js +13 -5
  160. package/dest/services/service.d.ts +39 -3
  161. package/dest/services/service.d.ts.map +1 -1
  162. package/dest/services/tx_collection/config.d.ts +19 -1
  163. package/dest/services/tx_collection/config.d.ts.map +1 -1
  164. package/dest/services/tx_collection/config.js +46 -0
  165. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
  166. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  167. package/dest/services/tx_collection/fast_tx_collection.js +56 -36
  168. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  169. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  170. package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
  171. package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
  172. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  173. package/dest/services/tx_collection/file_store_tx_source.js +90 -0
  174. package/dest/services/tx_collection/index.d.ts +2 -1
  175. package/dest/services/tx_collection/index.d.ts.map +1 -1
  176. package/dest/services/tx_collection/index.js +1 -0
  177. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  178. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  179. package/dest/services/tx_collection/instrumentation.js +2 -1
  180. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  181. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  182. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  183. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  184. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  185. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  186. package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
  187. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  188. package/dest/services/tx_collection/slow_tx_collection.js +60 -26
  189. package/dest/services/tx_collection/tx_collection.d.ts +23 -10
  190. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  191. package/dest/services/tx_collection/tx_collection.js +75 -3
  192. package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
  193. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  194. package/dest/services/tx_collection/tx_collection_sink.js +26 -29
  195. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  196. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  197. package/dest/services/tx_collection/tx_source.js +19 -2
  198. package/dest/services/tx_file_store/config.d.ts +1 -3
  199. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  200. package/dest/services/tx_file_store/config.js +0 -4
  201. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  202. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  203. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  204. package/dest/services/tx_provider.d.ts +4 -4
  205. package/dest/services/tx_provider.d.ts.map +1 -1
  206. package/dest/services/tx_provider.js +9 -8
  207. package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
  208. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  209. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  210. package/dest/test-helpers/mock-pubsub.d.ts +30 -4
  211. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  212. package/dest/test-helpers/mock-pubsub.js +105 -4
  213. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  214. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  215. package/dest/test-helpers/reqresp-nodes.js +4 -3
  216. package/dest/test-helpers/testbench-utils.d.ts +43 -38
  217. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  218. package/dest/test-helpers/testbench-utils.js +128 -59
  219. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  220. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  221. package/dest/testbench/p2p_client_testbench_worker.js +15 -15
  222. package/dest/util.d.ts +2 -2
  223. package/dest/util.d.ts.map +1 -1
  224. package/package.json +14 -14
  225. package/src/client/factory.ts +74 -27
  226. package/src/client/interface.ts +56 -34
  227. package/src/client/p2p_client.ts +180 -247
  228. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
  229. package/src/config.ts +35 -11
  230. package/src/errors/tx-pool.error.ts +12 -0
  231. package/src/index.ts +1 -0
  232. package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
  233. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
  234. package/src/mem_pools/attestation_pool/index.ts +9 -2
  235. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  236. package/src/mem_pools/index.ts +4 -1
  237. package/src/mem_pools/interface.ts +4 -4
  238. package/src/mem_pools/tx_pool/README.md +1 -1
  239. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  240. package/src/mem_pools/tx_pool_v2/README.md +76 -10
  241. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
  242. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  243. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  244. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  245. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  246. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  247. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  248. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  249. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  250. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  251. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  252. package/src/mem_pools/tx_pool_v2/index.ts +2 -1
  253. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  254. package/src/mem_pools/tx_pool_v2/interfaces.ts +23 -8
  255. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +153 -17
  256. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
  257. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
  258. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +383 -182
  259. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  260. package/src/msg_validators/tx_validator/README.md +115 -0
  261. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
  262. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  263. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  264. package/src/msg_validators/tx_validator/factory.ts +353 -77
  265. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  266. package/src/msg_validators/tx_validator/index.ts +1 -0
  267. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  268. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  269. package/src/services/dummy_service.ts +18 -6
  270. package/src/services/encoding.ts +9 -9
  271. package/src/services/gossipsub/README.md +641 -0
  272. package/src/services/gossipsub/index.ts +2 -0
  273. package/src/services/gossipsub/scoring.ts +29 -5
  274. package/src/services/gossipsub/topic_score_params.ts +487 -0
  275. package/src/services/libp2p/libp2p_service.ts +436 -355
  276. package/src/services/peer-manager/peer_scoring.ts +25 -0
  277. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  278. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  279. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  280. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  281. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  282. package/src/services/reqresp/interface.ts +26 -1
  283. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
  284. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  285. package/src/services/reqresp/protocols/tx.ts +22 -0
  286. package/src/services/reqresp/reqresp.ts +16 -4
  287. package/src/services/service.ts +51 -2
  288. package/src/services/tx_collection/config.ts +68 -0
  289. package/src/services/tx_collection/fast_tx_collection.ts +65 -32
  290. package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
  291. package/src/services/tx_collection/file_store_tx_source.ts +117 -0
  292. package/src/services/tx_collection/index.ts +1 -0
  293. package/src/services/tx_collection/instrumentation.ts +7 -1
  294. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  295. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  296. package/src/services/tx_collection/slow_tx_collection.ts +66 -33
  297. package/src/services/tx_collection/tx_collection.ts +113 -16
  298. package/src/services/tx_collection/tx_collection_sink.ts +30 -34
  299. package/src/services/tx_collection/tx_source.ts +22 -3
  300. package/src/services/tx_file_store/config.ts +0 -6
  301. package/src/services/tx_file_store/tx_file_store.ts +10 -8
  302. package/src/services/tx_provider.ts +10 -9
  303. package/src/test-helpers/make-test-p2p-clients.ts +3 -5
  304. package/src/test-helpers/mock-pubsub.ts +146 -9
  305. package/src/test-helpers/reqresp-nodes.ts +4 -6
  306. package/src/test-helpers/testbench-utils.ts +127 -71
  307. package/src/testbench/p2p_client_testbench_worker.ts +24 -21
  308. package/src/util.ts +7 -1
  309. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  310. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  311. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  312. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  313. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  314. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  315. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  316. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
@@ -0,0 +1,202 @@
1
+ import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
3
+ import { sleep } from '@aztec/foundation/sleep';
4
+ import { DateProvider } from '@aztec/foundation/timer';
5
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
6
+
7
+ import type { FileStoreTxSource } from './file_store_tx_source.js';
8
+ import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
9
+
10
+ /** Configuration for a FileStoreTxCollection instance. */
11
+ export type FileStoreCollectionConfig = {
12
+ workerCount: number;
13
+ backoffBaseMs: number;
14
+ backoffMaxMs: number;
15
+ };
16
+
17
+ type FileStoreTxEntry = {
18
+ txHash: string;
19
+ context: TxAddContext;
20
+ deadline: Date;
21
+ attempts: number;
22
+ lastAttemptTime: number;
23
+ nextSourceIndex: number;
24
+ };
25
+
26
+ /**
27
+ * Collects txs from file stores as a fallback after P2P methods have been tried.
28
+ * Uses a shared worker pool that pulls entries with priority (fewest attempts first),
29
+ * retries with round-robin across sources, and applies exponential backoff between
30
+ * full cycles through all sources.
31
+ */
32
+ export class FileStoreTxCollection {
33
+ /** Map from tx hash string to entry for all pending downloads. */
34
+ private entries = new Map<string, FileStoreTxEntry>();
35
+
36
+ /** Worker promises for the shared worker pool. */
37
+ private workers: Promise<void>[] = [];
38
+
39
+ /** Whether the worker pool is running. */
40
+ private running = false;
41
+
42
+ /** Signal used to wake sleeping workers when new entries arrive or stop is called. */
43
+ private wakeSignal: PromiseWithResolvers<void>;
44
+
45
+ constructor(
46
+ private readonly sources: FileStoreTxSource[],
47
+ private readonly txCollectionSink: TxCollectionSink,
48
+ private readonly config: FileStoreCollectionConfig,
49
+ private readonly dateProvider: DateProvider = new DateProvider(),
50
+ private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
51
+ ) {
52
+ this.wakeSignal = promiseWithResolvers<void>();
53
+ }
54
+
55
+ /** Starts the shared worker pool. */
56
+ public start(): void {
57
+ if (this.sources.length === 0) {
58
+ this.log.debug('No file store sources configured');
59
+ return;
60
+ }
61
+ this.running = true;
62
+ for (let i = 0; i < this.config.workerCount; i++) {
63
+ this.workers.push(this.workerLoop());
64
+ }
65
+ }
66
+
67
+ /** Stops all workers and clears state. */
68
+ public async stop(): Promise<void> {
69
+ this.running = false;
70
+ this.wake();
71
+ await Promise.all(this.workers);
72
+ this.workers = [];
73
+ this.entries.clear();
74
+ }
75
+
76
+ /** Adds entries to the shared map and wakes workers. */
77
+ public startCollecting(txHashes: TxHash[], context: TxAddContext, deadline: Date): void {
78
+ if (this.sources.length === 0 || txHashes.length === 0) {
79
+ return;
80
+ }
81
+ if (+deadline <= this.dateProvider.now()) {
82
+ return;
83
+ }
84
+
85
+ for (const txHash of txHashes) {
86
+ const hashStr = txHash.toString();
87
+ if (!this.entries.has(hashStr)) {
88
+ this.entries.set(hashStr, {
89
+ txHash: hashStr,
90
+ context,
91
+ deadline,
92
+ attempts: 0,
93
+ lastAttemptTime: 0,
94
+ nextSourceIndex: Math.floor(Math.random() * this.sources.length),
95
+ });
96
+ }
97
+ }
98
+ this.wake();
99
+ }
100
+
101
+ /** Removes entries for txs that have been found elsewhere. */
102
+ public foundTxs(txs: Tx[]): void {
103
+ for (const tx of txs) {
104
+ this.entries.delete(tx.getTxHash().toString());
105
+ }
106
+ }
107
+
108
+ /** Clears all pending entries. */
109
+ public clearPending(): void {
110
+ this.entries.clear();
111
+ }
112
+
113
+ private async workerLoop(): Promise<void> {
114
+ while (this.running) {
115
+ const action = this.getNextAction();
116
+ if (action.type === 'sleep') {
117
+ await action.promise;
118
+ continue;
119
+ }
120
+
121
+ const entry = action.entry;
122
+ const source = this.sources[entry.nextSourceIndex % this.sources.length];
123
+ entry.nextSourceIndex++;
124
+ entry.attempts++;
125
+ entry.lastAttemptTime = this.dateProvider.now();
126
+
127
+ try {
128
+ const result = await this.txCollectionSink.collect(
129
+ () => source.getTxsByHash([TxHash.fromString(entry.txHash)]),
130
+ [entry.txHash],
131
+ {
132
+ description: `file-store ${source.getInfo()}`,
133
+ method: 'file-store',
134
+ fileStore: source.getInfo(),
135
+ },
136
+ entry.context,
137
+ );
138
+ if (result.txs.length > 0) {
139
+ this.entries.delete(entry.txHash);
140
+ }
141
+ } catch (err) {
142
+ this.log.trace(`Error downloading tx ${entry.txHash} from ${source.getInfo()}`, { err });
143
+ }
144
+ }
145
+ }
146
+
147
+ /** Single-pass scan: removes expired entries, finds the best ready entry, or computes sleep time. */
148
+ private getNextAction(): { type: 'process'; entry: FileStoreTxEntry } | { type: 'sleep'; promise: Promise<void> } {
149
+ const now = this.dateProvider.now();
150
+ let best: FileStoreTxEntry | undefined;
151
+ let earliestReadyAt = Infinity;
152
+
153
+ for (const [key, entry] of this.entries) {
154
+ if (+entry.deadline <= now) {
155
+ this.entries.delete(key);
156
+ continue;
157
+ }
158
+ const backoffMs = this.getBackoffMs(entry);
159
+ const readyAt = entry.lastAttemptTime + backoffMs;
160
+ if (readyAt > now) {
161
+ earliestReadyAt = Math.min(earliestReadyAt, readyAt);
162
+ continue;
163
+ }
164
+ if (!best || entry.attempts < best.attempts) {
165
+ best = entry;
166
+ }
167
+ }
168
+
169
+ if (best) {
170
+ return { type: 'process', entry: best };
171
+ }
172
+ if (earliestReadyAt < Infinity) {
173
+ return { type: 'sleep', promise: this.sleepOrWake(earliestReadyAt - now) };
174
+ }
175
+ return { type: 'sleep', promise: this.waitForWake() };
176
+ }
177
+
178
+ /** Computes backoff for an entry. Backoff applies after a full cycle through all sources. */
179
+ private getBackoffMs(entry: FileStoreTxEntry): number {
180
+ const fullCycles = Math.floor(entry.attempts / this.sources.length);
181
+ if (fullCycles === 0) {
182
+ return 0;
183
+ }
184
+ return Math.min(this.config.backoffBaseMs * Math.pow(2, fullCycles - 1), this.config.backoffMaxMs);
185
+ }
186
+
187
+ /** Resolves the current wake signal and creates a new one. */
188
+ private wake(): void {
189
+ this.wakeSignal.resolve();
190
+ this.wakeSignal = promiseWithResolvers<void>();
191
+ }
192
+
193
+ /** Waits until the wake signal is resolved. */
194
+ private async waitForWake(): Promise<void> {
195
+ await this.wakeSignal.promise;
196
+ }
197
+
198
+ /** Sleeps for the given duration or until the wake signal is resolved. */
199
+ private async sleepOrWake(ms: number): Promise<void> {
200
+ await Promise.race([sleep(ms), this.wakeSignal.promise]);
201
+ }
202
+ }
@@ -0,0 +1,117 @@
1
+ import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { Timer } from '@aztec/foundation/timer';
3
+ import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
4
+ import { Tx, type TxHash } from '@aztec/stdlib/tx';
5
+ import {
6
+ type Histogram,
7
+ Metrics,
8
+ type TelemetryClient,
9
+ type UpDownCounter,
10
+ getTelemetryClient,
11
+ } from '@aztec/telemetry-client';
12
+
13
+ import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
14
+
15
+ /** TxSource implementation that downloads txs from a file store. */
16
+ export class FileStoreTxSource implements TxSource {
17
+ private downloadsSuccess: UpDownCounter;
18
+ private downloadsFailed: UpDownCounter;
19
+ private downloadDuration: Histogram;
20
+ private downloadSize: Histogram;
21
+
22
+ private constructor(
23
+ private readonly fileStore: ReadOnlyFileStore,
24
+ private readonly baseUrl: string,
25
+ private readonly basePath: string,
26
+ private readonly log: Logger,
27
+ telemetry: TelemetryClient,
28
+ ) {
29
+ const meter = telemetry.getMeter('file-store-tx-source');
30
+ this.downloadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_SUCCESS);
31
+ this.downloadsFailed = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_FAILED);
32
+ this.downloadDuration = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_DURATION);
33
+ this.downloadSize = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_SIZE);
34
+ }
35
+
36
+ /**
37
+ * Creates a FileStoreTxSource from a URL.
38
+ * @param url - The file store URL (s3://, gs://, file://, http://, https://).
39
+ * @param basePath - Base path for tx files within the store.
40
+ * @param log - Optional logger.
41
+ * @param telemetry - Optional telemetry client.
42
+ * @returns The FileStoreTxSource instance, or undefined if creation fails.
43
+ */
44
+ public static async create(
45
+ url: string,
46
+ basePath: string,
47
+ log: Logger = createLogger('p2p:file_store_tx_source'),
48
+ telemetry: TelemetryClient = getTelemetryClient(),
49
+ ): Promise<FileStoreTxSource | undefined> {
50
+ try {
51
+ const fileStore = await createReadOnlyFileStore(url, log);
52
+ if (!fileStore) {
53
+ log.warn(`Failed to create file store for URL: ${url}`);
54
+ return undefined;
55
+ }
56
+ return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
57
+ } catch (err) {
58
+ log.warn(`Error creating file store for URL: ${url}`, { error: err });
59
+ return undefined;
60
+ }
61
+ }
62
+
63
+ public getInfo(): string {
64
+ return `file-store:${this.baseUrl}`;
65
+ }
66
+
67
+ public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
68
+ const invalidTxHashes: string[] = [];
69
+ return {
70
+ validTxs: (
71
+ await Promise.all(
72
+ txHashes.map(async txHash => {
73
+ const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
74
+ const timer = new Timer();
75
+ try {
76
+ const buffer = await this.fileStore.read(path);
77
+ const tx = Tx.fromBuffer(buffer);
78
+ if ((await tx.validateTxHash()) && txHash.equals(tx.txHash)) {
79
+ this.downloadsSuccess.add(1);
80
+ this.downloadDuration.record(Math.ceil(timer.ms()));
81
+ this.downloadSize.record(buffer.length);
82
+ return tx;
83
+ } else {
84
+ invalidTxHashes.push(tx.txHash.toString());
85
+ this.downloadsFailed.add(1);
86
+ return undefined;
87
+ }
88
+ } catch {
89
+ // Tx not found or error reading - return undefined
90
+ this.downloadsFailed.add(1);
91
+ return undefined;
92
+ }
93
+ }),
94
+ )
95
+ ).filter(tx => tx !== undefined),
96
+ invalidTxHashes: invalidTxHashes,
97
+ };
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Creates FileStoreTxSource instances from URLs.
103
+ * @param urls - Array of file store URLs.
104
+ * @param basePath - Base path for tx files within each store.
105
+ * @param log - Optional logger.
106
+ * @param telemetry - Optional telemetry client.
107
+ * @returns Array of successfully created FileStoreTxSource instances.
108
+ */
109
+ export async function createFileStoreTxSources(
110
+ urls: string[],
111
+ basePath: string,
112
+ log: Logger = createLogger('p2p:file_store_tx_source'),
113
+ telemetry: TelemetryClient = getTelemetryClient(),
114
+ ): Promise<FileStoreTxSource[]> {
115
+ const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, basePath, log, telemetry)));
116
+ return sources.filter((s): s is FileStoreTxSource => s !== undefined);
117
+ }
@@ -5,3 +5,4 @@ export {
5
5
  BatchTxRequesterCollector,
6
6
  SendBatchRequestCollector,
7
7
  } from './proposal_tx_collector.js';
8
+ export { FileStoreTxSource, createFileStoreTxSources } from './file_store_tx_source.js';
@@ -18,7 +18,13 @@ 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]: [
22
+ 'fast-req-resp',
23
+ 'fast-node-rpc',
24
+ 'slow-req-resp',
25
+ 'slow-node-rpc',
26
+ 'file-store',
27
+ ],
22
28
  });
23
29
 
24
30
  this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
@@ -0,0 +1,52 @@
1
+ import { TxHash } from '@aztec/stdlib/tx';
2
+ import type { Tx } from '@aztec/stdlib/tx';
3
+
4
+ /**
5
+ * Tracks which transactions are still missing and need to be fetched.
6
+ * Allows external code to mark transactions as fetched, enabling coordination
7
+ * between multiple fetching mechanisms (e.g., BatchTxRequester and Rpc Node requests).
8
+ */
9
+ export interface IMissingTxsTracker {
10
+ /** Returns the set of transaction hashes that are still missing. */
11
+ get missingTxHashes(): Set<string>;
12
+ /** Size of this.missingTxHashes */
13
+ get numberOfMissingTxs(): number;
14
+ /** Are all requested txs are fetched */
15
+ allFetched(): boolean;
16
+ /** Checks that transaction is still missing */
17
+ isMissing(txHash: string): boolean;
18
+ /** Marks a transaction as fetched. Returns true if it was previously missing. */
19
+ markFetched(tx: Tx): boolean;
20
+ /** Get list of collected txs */
21
+ get collectedTxs(): Tx[];
22
+ }
23
+
24
+ export class MissingTxsTracker implements IMissingTxsTracker {
25
+ public readonly collectedTxs: Tx[] = [];
26
+
27
+ private constructor(public readonly missingTxHashes: Set<string>) {}
28
+
29
+ public static fromArray(hashes: TxHash[] | string[]) {
30
+ return new MissingTxsTracker(new Set(hashes.map(hash => hash.toString())));
31
+ }
32
+
33
+ markFetched(tx: Tx): boolean {
34
+ if (this.missingTxHashes.delete(tx.txHash.toString())) {
35
+ this.collectedTxs.push(tx);
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+
41
+ get numberOfMissingTxs(): number {
42
+ return this.missingTxHashes.size;
43
+ }
44
+
45
+ allFetched(): boolean {
46
+ return this.numberOfMissingTxs === 0;
47
+ }
48
+
49
+ isMissing(txHash: string): boolean {
50
+ return this.missingTxHashes.has(txHash.toString());
51
+ }
52
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '@aztec/foundation/log';
2
2
  import type { DateProvider } from '@aztec/foundation/timer';
3
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
3
+ import { type Tx, TxHash } from '@aztec/stdlib/tx';
4
4
 
5
5
  import type { PeerId } from '@libp2p/interface';
6
6
 
@@ -9,6 +9,7 @@ import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/confi
9
9
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
10
10
  import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
11
11
  import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
12
+ import type { IMissingTxsTracker } from './missing_txs_tracker.js';
12
13
 
13
14
  /**
14
15
  * Strategy interface for collecting missing transactions for a block or proposal.
@@ -17,14 +18,14 @@ import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '.
17
18
  export interface MissingTxsCollector {
18
19
  /**
19
20
  * Collect missing transactions for a block or proposal.
20
- * @param txHashes - The transaction hashes to collect
21
+ * @param missingTxsTracker - The missing transactions tracker
21
22
  * @param blockTxsSource - The block or proposal containing the transactions
22
23
  * @param pinnedPeer - Optional peer expected to have the transactions
23
24
  * @param timeoutMs - Timeout in milliseconds
24
25
  * @returns The collected transactions
25
26
  */
26
27
  collectTxs(
27
- txHashes: TxHash[],
28
+ missingTxsTracker: IMissingTxsTracker,
28
29
  blockTxsSource: BlockTxsSource,
29
30
  pinnedPeer: PeerId | undefined,
30
31
  timeoutMs: number,
@@ -45,7 +46,7 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
45
46
  ) {}
46
47
 
47
48
  async collectTxs(
48
- txHashes: TxHash[],
49
+ missingTxsTracker: IMissingTxsTracker,
49
50
  blockTxsSource: BlockTxsSource,
50
51
  pinnedPeer: PeerId | undefined,
51
52
  timeoutMs: number,
@@ -58,7 +59,7 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
58
59
  } = this.batchTxRequesterConfig ?? {};
59
60
 
60
61
  const batchRequester = new BatchTxRequester(
61
- txHashes,
62
+ missingTxsTracker,
62
63
  blockTxsSource,
63
64
  pinnedPeer,
64
65
  timeoutMs,
@@ -93,14 +94,14 @@ export class SendBatchRequestCollector implements MissingTxsCollector {
93
94
  ) {}
94
95
 
95
96
  async collectTxs(
96
- txHashes: TxHash[],
97
+ missingTxsTracker: IMissingTxsTracker,
97
98
  _blockTxsSource: BlockTxsSource,
98
99
  pinnedPeer: PeerId | undefined,
99
100
  timeoutMs: number,
100
101
  ): Promise<Tx[]> {
101
102
  const txs = await this.p2pService.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
102
103
  ReqRespSubProtocol.TX,
103
- chunkTxHashesRequest(txHashes),
104
+ chunkTxHashesRequest(Array.from(missingTxsTracker.missingTxHashes).map(TxHash.fromString)),
104
105
  pinnedPeer,
105
106
  timeoutMs,
106
107
  this.maxPeers,
@@ -8,8 +8,7 @@ import type { L2Block } from '@aztec/stdlib/block';
8
8
  import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
9
9
  import { type Tx, TxHash } from '@aztec/stdlib/tx';
10
10
 
11
- import { type ReqRespInterface, ReqRespSubProtocol } from '../reqresp/interface.js';
12
- import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
11
+ import { type ReqRespInterface, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
13
12
  import type { TxCollectionConfig } from './config.js';
14
13
  import type { FastTxCollection } from './fast_tx_collection.js';
15
14
  import type { MissingTxInfo } from './tx_collection.js';
@@ -91,6 +90,7 @@ export class SlowTxCollection {
91
90
 
92
91
  for (const txHash of txHashes) {
93
92
  this.missingTxs.set(txHash.toString(), {
93
+ block,
94
94
  blockNumber: block.number,
95
95
  deadline: this.getDeadlineForSlot(block.header.getSlot()),
96
96
  readyForReqResp: this.nodes.length === 0, // If we have no nodes, we can start reqresp immediately
@@ -109,18 +109,26 @@ export class SlowTxCollection {
109
109
 
110
110
  // Gather all missing txs that are not in fast collection and request them from the node
111
111
  const missingTxs = this.getMissingTxsForSlowCollection();
112
- const missingTxHashes = missingTxs.map(([txHash]) => txHash).map(TxHash.fromString);
113
- if (missingTxHashes.length === 0) {
112
+ if (missingTxs.length === 0) {
114
113
  return;
115
114
  }
116
115
 
117
- // Request in chunks to avoid hitting RPC limits
118
- for (const batch of chunk(missingTxHashes, this.config.txCollectionNodeRpcMaxBatchSize)) {
119
- await this.txCollectionSink.collect(txHashes => node.getTxsByHash(txHashes), batch, {
120
- description: `node ${node.getInfo()}`,
121
- node: node.getInfo(),
122
- method: 'slow-node-rpc',
123
- });
116
+ // Group by block so we pass the correct mined context to the sink
117
+ for (const entries of this.groupByBlock(missingTxs)) {
118
+ const block = entries[0][1].block;
119
+ const txHashes = entries.map(([txHash]) => TxHash.fromString(txHash));
120
+ for (const batch of chunk(txHashes, this.config.txCollectionNodeRpcMaxBatchSize)) {
121
+ await this.txCollectionSink.collect(
122
+ () => node.getTxsByHash(batch),
123
+ batch.map(h => h.toString()),
124
+ {
125
+ description: `node ${node.getInfo()}`,
126
+ node: node.getInfo(),
127
+ method: 'slow-node-rpc',
128
+ },
129
+ { type: 'mined', block },
130
+ );
131
+ }
124
132
  }
125
133
 
126
134
  // Mark every tx that is still missing as ready for reqresp.
@@ -149,25 +157,30 @@ export class SlowTxCollection {
149
157
 
150
158
  const pinnedPeer = undefined;
151
159
  const timeoutMs = this.config.txCollectionSlowReqRespTimeoutMs;
152
- const maxPeers = boundInclusive(Math.ceil(missingTxs.length / 3), 4, 16);
153
160
  const maxRetryAttempts = 3;
154
- // Send a batch request via reqresp for the missing txs
155
- await this.txCollectionSink.collect(
156
- async txHashes => {
157
- const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
158
- ReqRespSubProtocol.TX,
159
- chunkTxHashesRequest(txHashes),
160
- pinnedPeer,
161
- timeoutMs,
162
- maxPeers,
163
- maxRetryAttempts,
164
- );
165
161
 
166
- return txs.flat();
167
- },
168
- missingTxs.map(([txHash]) => TxHash.fromString(txHash)),
169
- { description: 'slow reqresp', timeoutMs, method: 'slow-req-resp' },
170
- );
162
+ // Group by block so we pass the correct mined context to the sink
163
+ for (const entries of this.groupByBlock(missingTxs)) {
164
+ const block = entries[0][1].block;
165
+ const txHashes = entries.map(([txHash]) => TxHash.fromString(txHash));
166
+ const maxPeers = boundInclusive(Math.ceil(txHashes.length / 3), 4, 16);
167
+ await this.txCollectionSink.collect(
168
+ async () => {
169
+ const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
170
+ ReqRespSubProtocol.TX,
171
+ chunkTxHashesRequest(txHashes),
172
+ pinnedPeer,
173
+ timeoutMs,
174
+ maxPeers,
175
+ maxRetryAttempts,
176
+ );
177
+ return { validTxs: txs.flat(), invalidTxHashes: [] };
178
+ },
179
+ txHashes.map(h => h.toString()),
180
+ { description: 'slow reqresp', timeoutMs, method: 'slow-req-resp' },
181
+ { type: 'mined', block },
182
+ );
183
+ }
171
184
  }
172
185
 
173
186
  /** Retrieves all missing txs for the slow collection process. This is, all missing txs that are not part of a fast request. */
@@ -183,7 +196,7 @@ export class SlowTxCollection {
183
196
  // from mined unproven blocks it has seen in the past.
184
197
  const fastRequests = this.fastCollection.getFastCollectionRequests();
185
198
  const fastCollectionTxs: Set<string> = new Set(
186
- ...Array.from(fastRequests.values()).flatMap(r => r.missingTxHashes),
199
+ fastRequests.values().flatMap(r => Array.from(r.missingTxTracker.missingTxHashes)),
187
200
  );
188
201
 
189
202
  // Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
@@ -223,11 +236,31 @@ export class SlowTxCollection {
223
236
  }
224
237
  }
225
238
 
239
+ /** Groups missing tx entries by block number. */
240
+ private groupByBlock(entries: [string, MissingTxInfo][]): [string, MissingTxInfo][][] {
241
+ const groups = new Map<number, [string, MissingTxInfo][]>();
242
+ for (const entry of entries) {
243
+ const bn = +entry[1].blockNumber;
244
+ let group = groups.get(bn);
245
+ if (!group) {
246
+ group = [];
247
+ groups.set(bn, group);
248
+ }
249
+ group.push(entry);
250
+ }
251
+ return [...groups.values()];
252
+ }
253
+
226
254
  /** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
227
255
  private getDeadlineForSlot(slotNumber: SlotNumber): Date {
228
- const epoch = getEpochAtSlot(slotNumber, this.constants);
229
- const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
230
- const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
231
- return new Date(Number(submissionEndTimestamp) * 1000);
256
+ return getProofDeadlineForSlot(slotNumber, this.constants);
232
257
  }
233
258
  }
259
+
260
+ /** Computes the proof submission deadline for a given slot. A tx mined in this slot is no longer interesting after this deadline. */
261
+ export function getProofDeadlineForSlot(slotNumber: SlotNumber, constants: L1RollupConstants): Date {
262
+ const epoch = getEpochAtSlot(slotNumber, constants);
263
+ const submissionEndEpoch = EpochNumber(epoch + constants.proofSubmissionEpochs);
264
+ const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, constants)[1];
265
+ return new Date(Number(submissionEndTimestamp) * 1000);
266
+ }