@aztec/p2p 0.0.1-commit.858058eac → 0.0.1-commit.85d7d01

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 (243) hide show
  1. package/dest/client/factory.d.ts +6 -6
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +23 -30
  4. package/dest/client/interface.d.ts +14 -19
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +9 -18
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +52 -72
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
  10. package/dest/config.d.ts +13 -6
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +5 -5
  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/mem_pools/attestation_pool/attestation_pool.d.ts +4 -2
  17. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool.js +5 -0
  19. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  20. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  22. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  23. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +30 -13
  24. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +91 -20
  26. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  27. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  29. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  30. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
  32. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  33. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  34. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  35. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  36. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  38. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  39. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  41. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  42. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  43. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  44. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  46. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  47. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  49. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  50. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  52. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  53. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  55. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  56. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  57. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  58. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +20 -6
  59. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
  61. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +34 -8
  62. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +76 -10
  64. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  65. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  66. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
  67. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  68. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  69. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +11 -6
  70. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +13 -5
  71. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +297 -143
  73. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  74. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  76. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  77. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  78. package/dest/msg_validators/tx_validator/factory.js +219 -58
  79. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  80. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  82. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  83. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/index.js +1 -0
  85. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  86. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  88. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  89. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  91. package/dest/services/dummy_service.d.ts +4 -4
  92. package/dest/services/dummy_service.d.ts.map +1 -1
  93. package/dest/services/dummy_service.js +4 -4
  94. package/dest/services/encoding.d.ts +2 -2
  95. package/dest/services/encoding.d.ts.map +1 -1
  96. package/dest/services/encoding.js +9 -8
  97. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  98. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  99. package/dest/services/gossipsub/topic_score_params.js +32 -10
  100. package/dest/services/libp2p/libp2p_service.d.ts +16 -13
  101. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  102. package/dest/services/libp2p/libp2p_service.js +69 -81
  103. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  104. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  105. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  106. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  107. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  108. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  109. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  110. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  111. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  112. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  113. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  114. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  115. package/dest/services/reqresp/reqresp.d.ts +1 -1
  116. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  117. package/dest/services/reqresp/reqresp.js +2 -1
  118. package/dest/services/service.d.ts +5 -3
  119. package/dest/services/service.d.ts.map +1 -1
  120. package/dest/services/tx_collection/config.d.ts +13 -1
  121. package/dest/services/tx_collection/config.d.ts.map +1 -1
  122. package/dest/services/tx_collection/config.js +30 -0
  123. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  124. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  125. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  126. package/dest/services/tx_collection/file_store_tx_collection.d.ts +38 -29
  127. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  128. package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
  129. package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
  130. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  131. package/dest/services/tx_collection/file_store_tx_source.js +49 -16
  132. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  133. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  134. package/dest/services/tx_collection/instrumentation.js +2 -1
  135. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  136. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  137. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  138. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  139. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  140. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  141. package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
  142. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  143. package/dest/services/tx_collection/slow_tx_collection.js +17 -12
  144. package/dest/services/tx_collection/tx_collection.d.ts +9 -6
  145. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  146. package/dest/services/tx_collection/tx_collection.js +26 -10
  147. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  148. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  149. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  150. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  151. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  152. package/dest/services/tx_collection/tx_source.js +19 -2
  153. package/dest/services/tx_file_store/tx_file_store.d.ts +3 -2
  154. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  155. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  156. package/dest/services/tx_provider.d.ts +3 -3
  157. package/dest/services/tx_provider.d.ts.map +1 -1
  158. package/dest/services/tx_provider.js +4 -4
  159. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  160. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  161. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  162. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  163. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  164. package/dest/test-helpers/mock-pubsub.js +8 -2
  165. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  166. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  167. package/dest/test-helpers/reqresp-nodes.js +2 -2
  168. package/dest/test-helpers/testbench-utils.d.ts +8 -3
  169. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  170. package/dest/test-helpers/testbench-utils.js +7 -1
  171. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  172. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  173. package/dest/testbench/p2p_client_testbench_worker.js +13 -13
  174. package/dest/util.d.ts +2 -2
  175. package/dest/util.d.ts.map +1 -1
  176. package/package.json +14 -14
  177. package/src/client/factory.ts +39 -48
  178. package/src/client/interface.ts +17 -20
  179. package/src/client/p2p_client.ts +60 -104
  180. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
  181. package/src/config.ts +10 -10
  182. package/src/errors/tx-pool.error.ts +12 -0
  183. package/src/mem_pools/attestation_pool/attestation_pool.ts +8 -0
  184. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  185. package/src/mem_pools/tx_pool/README.md +1 -1
  186. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  187. package/src/mem_pools/tx_pool_v2/README.md +43 -27
  188. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
  189. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  190. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  191. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  192. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  193. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  194. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  195. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  196. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  197. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  198. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  199. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  200. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  201. package/src/mem_pools/tx_pool_v2/interfaces.ts +21 -6
  202. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +107 -17
  203. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
  204. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
  205. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +326 -138
  206. package/src/msg_validators/tx_validator/README.md +115 -0
  207. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  208. package/src/msg_validators/tx_validator/factory.ts +353 -77
  209. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  210. package/src/msg_validators/tx_validator/index.ts +1 -0
  211. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  212. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  213. package/src/services/dummy_service.ts +6 -6
  214. package/src/services/encoding.ts +7 -7
  215. package/src/services/gossipsub/README.md +29 -14
  216. package/src/services/gossipsub/topic_score_params.ts +49 -13
  217. package/src/services/libp2p/libp2p_service.ts +80 -90
  218. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  219. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  220. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  221. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  222. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  223. package/src/services/reqresp/reqresp.ts +3 -1
  224. package/src/services/service.ts +11 -2
  225. package/src/services/tx_collection/config.ts +42 -0
  226. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  227. package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
  228. package/src/services/tx_collection/file_store_tx_source.ts +64 -17
  229. package/src/services/tx_collection/instrumentation.ts +7 -1
  230. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  231. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  232. package/src/services/tx_collection/slow_tx_collection.ts +17 -13
  233. package/src/services/tx_collection/tx_collection.ts +45 -14
  234. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  235. package/src/services/tx_collection/tx_source.ts +22 -3
  236. package/src/services/tx_file_store/tx_file_store.ts +6 -4
  237. package/src/services/tx_provider.ts +2 -2
  238. package/src/test-helpers/make-test-p2p-clients.ts +0 -2
  239. package/src/test-helpers/mock-pubsub.ts +13 -6
  240. package/src/test-helpers/reqresp-nodes.ts +2 -5
  241. package/src/test-helpers/testbench-utils.ts +11 -3
  242. package/src/testbench/p2p_client_testbench_worker.ts +22 -19
  243. package/src/util.ts +7 -1
@@ -1,152 +1,202 @@
1
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
- import { FifoMemoryQueue } from '@aztec/foundation/queue';
2
+ import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
3
+ import { sleep } from '@aztec/foundation/sleep';
4
+ import { DateProvider } from '@aztec/foundation/timer';
3
5
  import { Tx, TxHash } from '@aztec/stdlib/tx';
4
6
 
5
7
  import type { FileStoreTxSource } from './file_store_tx_source.js';
6
8
  import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
7
9
 
8
- // Internal constants (not configurable by node operators)
9
- const FILE_STORE_DOWNLOAD_CONCURRENCY = 5; // Max concurrent downloads
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
+ };
10
25
 
11
26
  /**
12
27
  * 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.
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.
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>();
33
+ /** Map from tx hash string to entry for all pending downloads. */
34
+ private entries = new Map<string, FileStoreTxEntry>();
19
35
 
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. */
36
+ /** Worker promises for the shared worker pool. */
31
37
  private workers: Promise<void>[] = [];
32
38
 
33
- /** Whether the collection has been started. */
34
- private started = false;
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>;
35
44
 
36
45
  constructor(
37
- private readonly fileStoreSources: FileStoreTxSource[],
46
+ private readonly sources: FileStoreTxSource[],
38
47
  private readonly txCollectionSink: TxCollectionSink,
48
+ private readonly config: FileStoreCollectionConfig,
49
+ private readonly dateProvider: DateProvider = new DateProvider(),
39
50
  private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
40
- ) {}
51
+ ) {
52
+ this.wakeSignal = promiseWithResolvers<void>();
53
+ }
41
54
 
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');
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');
46
59
  return;
47
60
  }
48
-
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)));
61
+ this.running = true;
62
+ for (let i = 0; i < this.config.workerCount; i++) {
63
+ this.workers.push(this.workerLoop());
55
64
  }
56
-
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
65
  }
62
66
 
63
- /** Stops all collection activity. */
64
- public async stop() {
65
- if (!this.started) {
66
- return;
67
- }
68
- this.started = false;
69
- this.downloadQueue.end();
67
+ /** Stops all workers and clears state. */
68
+ public async stop(): Promise<void> {
69
+ this.running = false;
70
+ this.wake();
70
71
  await Promise.all(this.workers);
71
72
  this.workers = [];
72
- this.pendingTxs.clear();
73
- this.foundTxHashes.clear();
73
+ this.entries.clear();
74
74
  }
75
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);
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;
81
83
  }
82
- }
83
-
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();
88
- }
89
84
 
90
- /** Queue the given tx hashes for file store collection. */
91
- public startCollecting(txHashes: TxHash[], context: TxAddContext) {
92
85
  for (const txHash of txHashes) {
93
86
  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);
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
+ });
97
96
  }
98
97
  }
98
+ this.wake();
99
99
  }
100
100
 
101
- /** Stop tracking txs that were found elsewhere. */
102
- public foundTxs(txs: Tx[]) {
101
+ /** Removes entries for txs that have been found elsewhere. */
102
+ public foundTxs(txs: Tx[]): void {
103
103
  for (const tx of txs) {
104
- const hashStr = tx.getTxHash().toString();
105
- this.pendingTxs.delete(hashStr);
106
- this.foundTxHashes.add(hashStr);
104
+ this.entries.delete(tx.getTxHash().toString());
107
105
  }
108
106
  }
109
107
 
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);
108
+ /** Clears all pending entries. */
109
+ public clearPending(): void {
110
+ this.entries.clear();
122
111
  }
123
112
 
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];
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();
129
126
 
130
127
  try {
131
128
  const result = await this.txCollectionSink.collect(
132
- hashes => source.getTxsByHash(hashes),
133
- [txHash],
129
+ () => source.getTxsByHash([TxHash.fromString(entry.txHash)]),
130
+ [entry.txHash],
134
131
  {
135
132
  description: `file-store ${source.getInfo()}`,
136
133
  method: 'file-store',
137
134
  fileStore: source.getInfo(),
138
135
  },
139
- context,
136
+ entry.context,
140
137
  );
141
-
142
138
  if (result.txs.length > 0) {
143
- return;
139
+ this.entries.delete(entry.txHash);
144
140
  }
145
141
  } catch (err) {
146
- this.log.trace(`Failed to download tx ${txHash} from ${source.getInfo()}`, { 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;
147
166
  }
148
167
  }
149
168
 
150
- this.log.trace(`Tx ${txHash} not found in any file store`);
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]);
151
201
  }
152
202
  }
@@ -1,26 +1,51 @@
1
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { Timer } from '@aztec/foundation/timer';
2
3
  import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
3
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';
4
12
 
5
- import type { TxSource } from './tx_source.js';
13
+ import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
6
14
 
7
15
  /** TxSource implementation that downloads txs from a file store. */
8
16
  export class FileStoreTxSource implements TxSource {
17
+ private downloadsSuccess: UpDownCounter;
18
+ private downloadsFailed: UpDownCounter;
19
+ private downloadDuration: Histogram;
20
+ private downloadSize: Histogram;
21
+
9
22
  private constructor(
10
23
  private readonly fileStore: ReadOnlyFileStore,
11
24
  private readonly baseUrl: string,
25
+ private readonly basePath: string,
12
26
  private readonly log: Logger,
13
- ) {}
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
+ }
14
35
 
15
36
  /**
16
37
  * Creates a FileStoreTxSource from a URL.
17
38
  * @param url - The file store URL (s3://, gs://, file://, http://, https://).
39
+ * @param basePath - Base path for tx files within the store.
18
40
  * @param log - Optional logger.
41
+ * @param telemetry - Optional telemetry client.
19
42
  * @returns The FileStoreTxSource instance, or undefined if creation fails.
20
43
  */
21
44
  public static async create(
22
45
  url: string,
46
+ basePath: string,
23
47
  log: Logger = createLogger('p2p:file_store_tx_source'),
48
+ telemetry: TelemetryClient = getTelemetryClient(),
24
49
  ): Promise<FileStoreTxSource | undefined> {
25
50
  try {
26
51
  const fileStore = await createReadOnlyFileStore(url, log);
@@ -28,7 +53,7 @@ export class FileStoreTxSource implements TxSource {
28
53
  log.warn(`Failed to create file store for URL: ${url}`);
29
54
  return undefined;
30
55
  }
31
- return new FileStoreTxSource(fileStore, url, log);
56
+ return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
32
57
  } catch (err) {
33
58
  log.warn(`Error creating file store for URL: ${url}`, { error: err });
34
59
  return undefined;
@@ -39,32 +64,54 @@ export class FileStoreTxSource implements TxSource {
39
64
  return `file-store:${this.baseUrl}`;
40
65
  }
41
66
 
42
- public getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
43
- return Promise.all(
44
- txHashes.map(async txHash => {
45
- const path = `txs/${txHash.toString()}.bin`;
46
- try {
47
- const buffer = await this.fileStore.read(path);
48
- return Tx.fromBuffer(buffer);
49
- } catch {
50
- // Tx not found or error reading - return undefined
51
- return undefined;
52
- }
53
- }),
54
- );
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
+ };
55
98
  }
56
99
  }
57
100
 
58
101
  /**
59
102
  * Creates FileStoreTxSource instances from URLs.
60
103
  * @param urls - Array of file store URLs.
104
+ * @param basePath - Base path for tx files within each store.
61
105
  * @param log - Optional logger.
106
+ * @param telemetry - Optional telemetry client.
62
107
  * @returns Array of successfully created FileStoreTxSource instances.
63
108
  */
64
109
  export async function createFileStoreTxSources(
65
110
  urls: string[],
111
+ basePath: string,
66
112
  log: Logger = createLogger('p2p:file_store_tx_source'),
113
+ telemetry: TelemetryClient = getTelemetryClient(),
67
114
  ): Promise<FileStoreTxSource[]> {
68
- const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, log)));
115
+ const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, basePath, log, telemetry)));
69
116
  return sources.filter((s): s is FileStoreTxSource => s !== undefined);
70
117
  }
@@ -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';
@@ -120,8 +119,8 @@ export class SlowTxCollection {
120
119
  const txHashes = entries.map(([txHash]) => TxHash.fromString(txHash));
121
120
  for (const batch of chunk(txHashes, this.config.txCollectionNodeRpcMaxBatchSize)) {
122
121
  await this.txCollectionSink.collect(
123
- hashes => node.getTxsByHash(hashes),
124
- batch,
122
+ () => node.getTxsByHash(batch),
123
+ batch.map(h => h.toString()),
125
124
  {
126
125
  description: `node ${node.getInfo()}`,
127
126
  node: node.getInfo(),
@@ -166,18 +165,18 @@ export class SlowTxCollection {
166
165
  const txHashes = entries.map(([txHash]) => TxHash.fromString(txHash));
167
166
  const maxPeers = boundInclusive(Math.ceil(txHashes.length / 3), 4, 16);
168
167
  await this.txCollectionSink.collect(
169
- async hashes => {
168
+ async () => {
170
169
  const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
171
170
  ReqRespSubProtocol.TX,
172
- chunkTxHashesRequest(hashes),
171
+ chunkTxHashesRequest(txHashes),
173
172
  pinnedPeer,
174
173
  timeoutMs,
175
174
  maxPeers,
176
175
  maxRetryAttempts,
177
176
  );
178
- return txs.flat();
177
+ return { validTxs: txs.flat(), invalidTxHashes: [] };
179
178
  },
180
- txHashes,
179
+ txHashes.map(h => h.toString()),
181
180
  { description: 'slow reqresp', timeoutMs, method: 'slow-req-resp' },
182
181
  { type: 'mined', block },
183
182
  );
@@ -197,7 +196,7 @@ export class SlowTxCollection {
197
196
  // from mined unproven blocks it has seen in the past.
198
197
  const fastRequests = this.fastCollection.getFastCollectionRequests();
199
198
  const fastCollectionTxs: Set<string> = new Set(
200
- ...Array.from(fastRequests.values()).flatMap(r => r.missingTxHashes),
199
+ fastRequests.values().flatMap(r => Array.from(r.missingTxTracker.missingTxHashes)),
201
200
  );
202
201
 
203
202
  // Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
@@ -254,9 +253,14 @@ export class SlowTxCollection {
254
253
 
255
254
  /** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
256
255
  private getDeadlineForSlot(slotNumber: SlotNumber): Date {
257
- const epoch = getEpochAtSlot(slotNumber, this.constants);
258
- const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
259
- const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
260
- return new Date(Number(submissionEndTimestamp) * 1000);
256
+ return getProofDeadlineForSlot(slotNumber, this.constants);
261
257
  }
262
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
+ }