@aztec/p2p 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.dbf9cec

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
@@ -2,13 +2,13 @@ import { type Tx, TxHash } from '@aztec/stdlib/tx';
2
2
 
3
3
  import type { PeerId } from '@libp2p/interface';
4
4
 
5
+ import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
5
6
  import { DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE } from './config.js';
6
7
  import type { ITxMetadataCollection } from './interface.js';
7
8
 
8
- export class MissingTxMetadata {
9
+ class MissingTxMetadata {
9
10
  constructor(
10
- public readonly txHash: TxHash,
11
- public fetched = false,
11
+ public readonly txHash: string,
12
12
  public requestedCount = 0,
13
13
  public inFlightCount = 0,
14
14
  public tx: Tx | undefined = undefined,
@@ -30,24 +30,6 @@ export class MissingTxMetadata {
30
30
  public isInFlight(): boolean {
31
31
  return this.inFlightCount > 0;
32
32
  }
33
-
34
- //Returns true if this is the first time we mark it as fetched
35
- public markAsFetched(peerId: PeerId, tx: Tx): boolean {
36
- if (this.fetched) {
37
- return false;
38
- }
39
-
40
- this.fetched = true;
41
- this.tx = tx;
42
-
43
- this.peers.add(peerId.toString());
44
-
45
- return true;
46
- }
47
-
48
- public toString() {
49
- return this.txHash.toString();
50
- }
51
33
  }
52
34
 
53
35
  /*
@@ -55,21 +37,18 @@ export class MissingTxMetadata {
55
37
  * This could be better optimized but given expected count of missing txs (N < 100)
56
38
  * At the moment there is no need for it. And benefit is that we have everything in single store
57
39
  * */
58
- export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata> implements ITxMetadataCollection {
40
+ export class MissingTxMetadataCollection implements ITxMetadataCollection {
41
+ private txMetadata = new Map<string, MissingTxMetadata>();
42
+
59
43
  constructor(
60
- entries?: readonly (readonly [string, MissingTxMetadata])[] | null,
44
+ private missingTxsTracker: IMissingTxsTracker,
61
45
  private readonly txBatchSize: number = DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
62
46
  ) {
63
- super(entries);
64
- }
65
- public getSortedByRequestedCountAsc(txs: string[]): MissingTxMetadata[] {
66
- return Array.from(this.values().filter(txMeta => txs.includes(txMeta.txHash.toString()))).sort(
67
- (a, b) => a.requestedCount - b.requestedCount,
68
- );
47
+ missingTxsTracker.missingTxHashes.forEach(hash => this.txMetadata.set(hash, new MissingTxMetadata(hash)));
69
48
  }
70
49
 
71
50
  public getPrioritizingNotInFlightAndLowerRequestCount(txs: string[]): MissingTxMetadata[] {
72
- const filtered = Array.from(this.values()).filter(txMeta => txs.includes(txMeta.txHash.toString()));
51
+ const filtered = Array.from(this.txMetadata.values()).filter(txMeta => txs.includes(txMeta.txHash.toString()));
73
52
 
74
53
  const [notInFlight, inFlight] = filtered.reduce<[MissingTxMetadata[], MissingTxMetadata[]]>(
75
54
  (buckets, tx) => {
@@ -85,43 +64,15 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
85
64
  return [...notInFlight, ...inFlight];
86
65
  }
87
66
 
88
- public getFetchedTxHashes(): Set<string> {
89
- return new Set(
90
- this.values()
91
- .filter(t => t.fetched)
92
- .map(t => t.txHash.toString()),
93
- );
94
- }
95
-
96
67
  public getMissingTxHashes(): Set<string> {
97
- return new Set(
98
- this.values()
99
- .filter(t => !t.fetched)
100
- .map(t => t.txHash.toString()),
101
- );
102
- }
103
-
104
- public getInFlightTxHashes(): Set<string> {
105
- return new Set(
106
- this.values()
107
- .filter(t => t.isInFlight())
108
- .map(t => t.txHash.toString()),
109
- );
110
- }
111
-
112
- public getFetchedTxs(): Tx[] {
113
- return Array.from(
114
- this.values()
115
- .map(t => t.tx)
116
- .filter(t => !!t),
117
- );
68
+ return this.missingTxsTracker.missingTxHashes;
118
69
  }
119
70
 
120
71
  public getTxsPeerHas(peer: PeerId): Set<string> {
121
72
  const peerIdStr = peer.toString();
122
73
  const txsPeerHas = new Set<string>();
123
74
 
124
- this.values().forEach(txMeta => {
75
+ this.txMetadata.values().forEach(txMeta => {
125
76
  if (txMeta.peers.has(peerIdStr)) {
126
77
  txsPeerHas.add(txMeta.txHash.toString());
127
78
  }
@@ -132,13 +83,13 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
132
83
 
133
84
  public getTxsToRequestFromThePeer(peer: PeerId): TxHash[] {
134
85
  const txsPeerHas = this.getTxsPeerHas(peer);
135
- const fetchedTxs = this.getFetchedTxHashes();
86
+ const missingTxHashes = this.getMissingTxHashes();
136
87
 
137
- const txsToRequest = txsPeerHas.difference(fetchedTxs);
88
+ const txsToRequest = txsPeerHas.intersection(missingTxHashes);
138
89
 
139
90
  if (txsToRequest.size >= this.txBatchSize) {
140
91
  return this.getPrioritizingNotInFlightAndLowerRequestCount(Array.from(txsToRequest))
141
- .map(t => t.txHash)
92
+ .map(t => TxHash.fromString(t.txHash))
142
93
  .slice(0, this.txBatchSize);
143
94
  }
144
95
 
@@ -150,13 +101,13 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
150
101
  Array.from(this.getMissingTxHashes().difference(txsToRequest)),
151
102
  )
152
103
  .slice(0, countToFill)
153
- .map(t => t.txHash);
104
+ .map(t => TxHash.fromString(t.txHash));
154
105
 
155
106
  return [...Array.from(txsToRequest).map(t => TxHash.fromString(t)), ...txsToFill];
156
107
  }
157
108
 
158
109
  public markRequested(txHash: TxHash) {
159
- this.get(txHash.toString())?.markAsRequested();
110
+ this.txMetadata.get(txHash.toString())?.markAsRequested();
160
111
  }
161
112
 
162
113
  /*
@@ -165,7 +116,7 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
165
116
  * "dumb" peer might return it, or might not - we don't know
166
117
  * */
167
118
  public markInFlightBySmartPeer(txHash: TxHash) {
168
- this.get(txHash.toString())?.markInFlight();
119
+ this.txMetadata.get(txHash.toString())?.markInFlight();
169
120
  }
170
121
 
171
122
  /*
@@ -173,16 +124,16 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
173
124
  * Because the smart peer should return this tx, whereas
174
125
  * "dumb" peer might return it, or might not - we don't know*/
175
126
  public markNotInFlightBySmartPeer(txHash: TxHash) {
176
- this.get(txHash.toString())?.markNotInFlight();
127
+ this.txMetadata.get(txHash.toString())?.markNotInFlight();
177
128
  }
178
129
 
179
130
  public alreadyFetched(txHash: TxHash): boolean {
180
- return this.get(txHash.toString())?.fetched ?? false;
131
+ return !this.missingTxsTracker.isMissing(txHash.toString());
181
132
  }
182
133
 
183
134
  public markFetched(peerId: PeerId, tx: Tx): boolean {
184
135
  const txHashStr = tx.txHash.toString();
185
- const txMeta = this.get(txHashStr);
136
+ const txMeta = this.txMetadata.get(txHashStr);
186
137
  if (!txMeta) {
187
138
  //TODO: what to do about peer which sent txs we didn't request?
188
139
  // 1. don't request from it in the scope of this batch request
@@ -192,7 +143,8 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
192
143
  return false;
193
144
  }
194
145
 
195
- return txMeta.markAsFetched(peerId, tx);
146
+ txMeta.peers.add(peerId.toString());
147
+ return this.missingTxsTracker.markFetched(tx);
196
148
  }
197
149
 
198
150
  public markPeerHas(peerId: PeerId, txHash: TxHash[]) {
@@ -200,7 +152,7 @@ export class MissingTxMetadataCollection extends Map<string, MissingTxMetadata>
200
152
  txHash
201
153
  .map(t => t.toString())
202
154
  .forEach(txh => {
203
- const txMeta = this.get(txh);
155
+ const txMeta = this.txMetadata.get(txh);
204
156
  if (txMeta) {
205
157
  txMeta.peers.add(peerIdStr);
206
158
  }
@@ -2,18 +2,22 @@ import type { DateProvider } from '@aztec/foundation/timer';
2
2
  import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
3
 
4
4
  import type { PeerId } from '@libp2p/interface';
5
+ import { peerIdFromString } from '@libp2p/peer-id';
5
6
 
7
+ import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
6
8
  import { DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD } from './config.js';
7
9
  import type { IPeerPenalizer } from './interface.js';
8
10
 
9
11
  export const RATE_LIMIT_EXCEEDED_PEER_CACHE_TTL = 1000; // 1s
10
12
 
11
13
  export interface IPeerCollection {
12
- getAllPeers(): Set<string>;
13
- getSmartPeers(): Set<string>;
14
14
  markPeerSmart(peerId: PeerId): void;
15
- getSmartPeersToQuery(): Array<string>;
16
- getDumbPeersToQuery(): Array<string>;
15
+
16
+ /** Sample next peer in round-robin fashion. No smart peers if returns undefined */
17
+ nextSmartPeerToQuery(): PeerId | undefined;
18
+ /** Sample next peer in round-robin fashion. No dumb peers if returns undefined */
19
+ nextDumbPeerToQuery(): PeerId | undefined;
20
+
17
21
  thereAreSomeDumbRatelimitExceededPeers(): boolean;
18
22
  penalisePeer(peerId: PeerId, severity: PeerErrorSeverity): void;
19
23
  unMarkPeerAsBad(peerId: PeerId): void;
@@ -28,8 +32,6 @@ export interface IPeerCollection {
28
32
  }
29
33
 
30
34
  export class PeerCollection implements IPeerCollection {
31
- private readonly peers;
32
-
33
35
  private readonly smartPeers = new Set<string>();
34
36
  private readonly inFlightPeers = new Set<string>();
35
37
  private readonly rateLimitExceededPeers = new Map<string, number>();
@@ -37,46 +39,60 @@ export class PeerCollection implements IPeerCollection {
37
39
  private readonly badPeers = new Set<string>();
38
40
 
39
41
  constructor(
40
- initialPeers: PeerId[],
42
+ private readonly connectionSampler: Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>,
41
43
  private readonly pinnedPeerId: PeerId | undefined,
42
44
  private readonly dateProvider: DateProvider,
43
45
  private readonly badPeerThreshold: number = DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD,
44
46
  private readonly peerPenalizer?: IPeerPenalizer,
45
47
  ) {
46
- this.peers = new Set(initialPeers.map(peer => peer.toString()));
47
-
48
- // Pinned peer is treaded specially, always mark it as in-flight
48
+ // Pinned peer is treated specially, always mark it as in-flight
49
49
  // and never return it as part of smart/dumb peers
50
50
  if (this.pinnedPeerId) {
51
51
  const peerIdStr = this.pinnedPeerId.toString();
52
52
  this.inFlightPeers.add(peerIdStr);
53
- this.peers.delete(peerIdStr);
54
53
  }
55
54
  }
56
55
 
57
- public getAllPeers(): Set<string> {
58
- return this.peers;
56
+ public markPeerSmart(peerId: PeerId): void {
57
+ this.smartPeers.add(peerId.toString());
59
58
  }
60
59
 
61
- public getSmartPeers(): Set<string> {
62
- return this.smartPeers;
60
+ // We keep track of all peers that are queried for peer sampling algorithm
61
+ private queriedSmartPeers: Set<string> = new Set<string>();
62
+ private queriedDumbPeers: Set<string> = new Set<string>();
63
+
64
+ private static nextPeer(allPeers: Set<string>, queried: Set<string>): PeerId | undefined {
65
+ if (allPeers.size === 0) {
66
+ return undefined;
67
+ }
68
+ const availablePeers = allPeers.difference(queried);
69
+ let [first] = availablePeers;
70
+ if (first === undefined) {
71
+ // We queried all peers. Start over
72
+ [first] = allPeers;
73
+ queried.clear();
74
+ }
75
+ queried.add(first);
76
+ return peerIdFromString(first);
63
77
  }
64
78
 
65
- public markPeerSmart(peerId: PeerId): void {
66
- this.smartPeers.add(peerId.toString());
79
+ public nextSmartPeerToQuery(): PeerId | undefined {
80
+ return PeerCollection.nextPeer(this.availableSmartPeers, this.queriedSmartPeers);
81
+ }
82
+
83
+ public nextDumbPeerToQuery(): PeerId | undefined {
84
+ return PeerCollection.nextPeer(this.availableDumbPeers, this.queriedDumbPeers);
67
85
  }
68
86
 
69
- public getSmartPeersToQuery(): Array<string> {
70
- return Array.from(
87
+ private get availableSmartPeers(): Set<string> {
88
+ return this.peers.intersection(
71
89
  this.smartPeers.difference(this.getBadPeers().union(this.inFlightPeers).union(this.getRateLimitExceededPeers())),
72
90
  );
73
91
  }
74
92
 
75
- public getDumbPeersToQuery(): Array<string> {
76
- return Array.from(
77
- this.peers.difference(
78
- this.smartPeers.union(this.getBadPeers()).union(this.inFlightPeers).union(this.getRateLimitExceededPeers()),
79
- ),
93
+ private get availableDumbPeers(): Set<string> {
94
+ return this.peers.difference(
95
+ this.smartPeers.union(this.getBadPeers()).union(this.inFlightPeers).union(this.getRateLimitExceededPeers()),
80
96
  );
81
97
  }
82
98
 
@@ -202,4 +218,27 @@ export class PeerCollection implements IPeerCollection {
202
218
 
203
219
  return minExpiry! - now;
204
220
  }
221
+
222
+ private orderedPeers: Set<string> = new Set();
223
+
224
+ private get peers(): Set<string> {
225
+ const pinnedStr = this.pinnedPeerId?.toString();
226
+ const currentlyConnected = new Set(
227
+ this.connectionSampler
228
+ .getPeerListSortedByConnectionCountAsc()
229
+ .map(p => p.toString())
230
+ .filter(p => p !== pinnedStr),
231
+ );
232
+
233
+ // Remove disconnected peers, preserving order of the rest.
234
+ this.orderedPeers = this.orderedPeers.intersection(currentlyConnected);
235
+
236
+ // Append newly connected peers at the end (lowest priority).
237
+ for (const peer of currentlyConnected) {
238
+ if (!this.orderedPeers.has(peer)) {
239
+ this.orderedPeers.add(peer);
240
+ }
241
+ }
242
+ return this.orderedPeers;
243
+ }
205
244
  }
@@ -1,7 +1,7 @@
1
1
  import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
2
2
  import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
3
3
 
4
- import { createTxReqRespValidator } from '../../../msg_validators/tx_validator/factory.js';
4
+ import { createTxValidatorForReqResponseReceivedTxs } from '../../../msg_validators/index.js';
5
5
 
6
6
  export interface BatchRequestTxValidatorConfig {
7
7
  l1ChainId: number;
@@ -29,7 +29,7 @@ export class BatchRequestTxValidator implements IBatchRequestTxValidator {
29
29
  }
30
30
 
31
31
  static createRequestedTxValidator(config: BatchRequestTxValidatorConfig): TxValidator {
32
- return createTxReqRespValidator(config.proofVerifier, {
32
+ return createTxValidatorForReqResponseReceivedTxs(config.proofVerifier, {
33
33
  l1ChainId: config.l1ChainId,
34
34
  rollupVersion: config.rollupVersion,
35
35
  });
@@ -627,7 +627,9 @@ export class ReqResp implements ReqRespInterface {
627
627
  // and that this stream should be dropped
628
628
  const isMessageToNotWarn =
629
629
  err instanceof Error &&
630
- ['stream reset', 'Cannot push value onto an ended pushable'].some(msg => err.message.includes(msg));
630
+ ['stream reset', 'Cannot push value onto an ended pushable', 'read ECONNRESET'].some(msg =>
631
+ err.message.includes(msg),
632
+ );
631
633
  const level = isMessageToNotWarn ? 'debug' : 'warn';
632
634
  this.logger[level]('Unknown stream error while handling the stream, aborting', {
633
635
  protocol,
@@ -1,7 +1,13 @@
1
1
  import type { SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
4
- import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore, Gossipable } from '@aztec/stdlib/p2p';
4
+ import type {
5
+ BlockProposal,
6
+ CheckpointAttestation,
7
+ CheckpointProposalCore,
8
+ Gossipable,
9
+ TopicType,
10
+ } from '@aztec/stdlib/p2p';
5
11
  import type { Tx } from '@aztec/stdlib/tx';
6
12
 
7
13
  import type { PeerId } from '@libp2p/interface';
@@ -130,7 +136,10 @@ export interface P2PService {
130
136
 
131
137
  getPeers(includePending?: boolean): PeerInfo[];
132
138
 
133
- validate(txs: Tx[]): Promise<void>;
139
+ /** Returns the number of peers in the GossipSub mesh for a given topic type. */
140
+ getGossipMeshPeerCount(topicType: TopicType): number;
141
+
142
+ validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void>;
134
143
 
135
144
  addReqRespSubProtocol(
136
145
  subProtocol: ReqRespSubProtocol,
@@ -37,6 +37,18 @@ export type TxCollectionConfig = {
37
37
  txCollectionFileStoreSlowDelayMs: number;
38
38
  /** Delay in ms before file store collection starts after fast collection is triggered */
39
39
  txCollectionFileStoreFastDelayMs: number;
40
+ /** Number of concurrent workers for fast file store collection */
41
+ txCollectionFileStoreFastWorkerCount: number;
42
+ /** Number of concurrent workers for slow file store collection */
43
+ txCollectionFileStoreSlowWorkerCount: number;
44
+ /** Base backoff time in ms for fast file store collection retries */
45
+ txCollectionFileStoreFastBackoffBaseMs: number;
46
+ /** Base backoff time in ms for slow file store collection retries */
47
+ txCollectionFileStoreSlowBackoffBaseMs: number;
48
+ /** Max backoff time in ms for fast file store collection retries */
49
+ txCollectionFileStoreFastBackoffMaxMs: number;
50
+ /** Max backoff time in ms for slow file store collection retries */
51
+ txCollectionFileStoreSlowBackoffMaxMs: number;
40
52
  };
41
53
 
42
54
  export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
@@ -121,4 +133,34 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
121
133
  description: 'Delay before file store collection starts after fast collection',
122
134
  ...numberConfigHelper(2_000),
123
135
  },
136
+ txCollectionFileStoreFastWorkerCount: {
137
+ env: 'TX_COLLECTION_FILE_STORE_FAST_WORKER_COUNT',
138
+ description: 'Number of concurrent workers for fast file store collection',
139
+ ...numberConfigHelper(5),
140
+ },
141
+ txCollectionFileStoreSlowWorkerCount: {
142
+ env: 'TX_COLLECTION_FILE_STORE_SLOW_WORKER_COUNT',
143
+ description: 'Number of concurrent workers for slow file store collection',
144
+ ...numberConfigHelper(2),
145
+ },
146
+ txCollectionFileStoreFastBackoffBaseMs: {
147
+ env: 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_BASE_MS',
148
+ description: 'Base backoff time in ms for fast file store collection retries',
149
+ ...numberConfigHelper(1_000),
150
+ },
151
+ txCollectionFileStoreSlowBackoffBaseMs: {
152
+ env: 'TX_COLLECTION_FILE_STORE_SLOW_BACKOFF_BASE_MS',
153
+ description: 'Base backoff time in ms for slow file store collection retries',
154
+ ...numberConfigHelper(5_000),
155
+ },
156
+ txCollectionFileStoreFastBackoffMaxMs: {
157
+ env: 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_MAX_MS',
158
+ description: 'Max backoff time in ms for fast file store collection retries',
159
+ ...numberConfigHelper(5_000),
160
+ },
161
+ txCollectionFileStoreSlowBackoffMaxMs: {
162
+ env: 'TX_COLLECTION_FILE_STORE_SLOW_BACKOFF_MAX_MS',
163
+ description: 'Max backoff time in ms for slow file store collection retries',
164
+ ...numberConfigHelper(30_000),
165
+ },
124
166
  };
@@ -14,6 +14,7 @@ import type { PeerId } from '@libp2p/interface';
14
14
  import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
15
15
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
16
16
  import type { TxCollectionConfig } from './config.js';
17
+ import { MissingTxsTracker } from './missing_txs_tracker.js';
17
18
  import {
18
19
  BatchTxRequesterCollector,
19
20
  type MissingTxsCollector,
@@ -83,8 +84,7 @@ export class FastTxCollection {
83
84
  ...input,
84
85
  blockInfo,
85
86
  promise,
86
- foundTxs: new Map<string, Tx>(),
87
- missingTxHashes: new Set(txHashes.map(t => t.toString())),
87
+ missingTxTracker: MissingTxsTracker.fromArray(txHashes),
88
88
  deadline: opts.deadline,
89
89
  };
90
90
 
@@ -92,15 +92,15 @@ export class FastTxCollection {
92
92
  clearTimeout(timeoutTimer);
93
93
 
94
94
  this.log.verbose(
95
- `Collected ${request.foundTxs.size} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
95
+ `Collected ${request.missingTxTracker.collectedTxs.length} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
96
96
  {
97
97
  ...blockInfo,
98
98
  duration,
99
99
  requestType: input.type,
100
- missingTxs: [...request.missingTxHashes],
100
+ missingTxs: [...request.missingTxTracker.missingTxHashes],
101
101
  },
102
102
  );
103
- return [...request.foundTxs.values()];
103
+ return request.missingTxTracker.collectedTxs;
104
104
  }
105
105
 
106
106
  protected async collectFast(
@@ -111,7 +111,7 @@ export class FastTxCollection {
111
111
  const { blockInfo } = request;
112
112
 
113
113
  this.log.debug(
114
- `Starting fast collection of ${request.missingTxHashes.size} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
114
+ `Starting fast collection of ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
115
115
  { ...blockInfo, requestType: request.type, deadline: opts.deadline },
116
116
  );
117
117
 
@@ -124,7 +124,7 @@ export class FastTxCollection {
124
124
  await Promise.race([request.promise.promise, waitBeforeReqResp]);
125
125
 
126
126
  // If we have collected all txs, we can stop here
127
- if (request.missingTxHashes.size === 0) {
127
+ if (request.missingTxTracker.allFetched()) {
128
128
  this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
129
129
  return;
130
130
  }
@@ -138,7 +138,7 @@ export class FastTxCollection {
138
138
  const logCtx = {
139
139
  ...blockInfo,
140
140
  errorMessage: err instanceof Error ? err.message : undefined,
141
- missingTxs: [...request.missingTxHashes].map(txHash => txHash.toString()),
141
+ missingTxs: request.missingTxTracker.missingTxHashes.values().map(txHash => txHash.toString()),
142
142
  };
143
143
  if (err instanceof Error && err.name === 'TimeoutError') {
144
144
  this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
@@ -166,7 +166,11 @@ export class FastTxCollection {
166
166
  }
167
167
 
168
168
  // Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
169
- const attemptsPerTx = [...request.missingTxHashes].map(txHash => ({ txHash, attempts: 0, found: false }));
169
+ const attemptsPerTx = [...request.missingTxTracker.missingTxHashes].map(txHash => ({
170
+ txHash,
171
+ attempts: 0,
172
+ found: false,
173
+ }));
170
174
 
171
175
  // Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
172
176
  await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx, opts)));
@@ -179,7 +183,7 @@ export class FastTxCollection {
179
183
  opts: { deadline: Date },
180
184
  ) {
181
185
  const notFinished = () =>
182
- this.dateProvider.now() <= +opts.deadline && request.missingTxHashes.size > 0 && this.requests.has(request);
186
+ this.dateProvider.now() <= +opts.deadline && !request.missingTxTracker.allFetched() && this.requests.has(request);
183
187
 
184
188
  const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
185
189
  const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
@@ -196,7 +200,7 @@ export class FastTxCollection {
196
200
  if (!txToRequest) {
197
201
  // No more txs to process
198
202
  break;
199
- } else if (!request.missingTxHashes.has(txToRequest.txHash)) {
203
+ } else if (!request.missingTxTracker.isMissing(txToRequest.txHash)) {
200
204
  // Mark as found if it was found somewhere else, we'll then remove it from the array.
201
205
  // We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
202
206
  txToRequest.found = true;
@@ -225,10 +229,17 @@ export class FastTxCollection {
225
229
  return;
226
230
  }
227
231
 
232
+ const txHashes = batch.map(({ txHash }) => txHash);
228
233
  // Collect this batch from the node
229
234
  await this.txCollectionSink.collect(
230
- txHashes => node.getTxsByHash(txHashes),
231
- batch.map(({ txHash }) => TxHash.fromString(txHash)),
235
+ async () => {
236
+ const result = await node.getTxsByHash(txHashes.map(TxHash.fromString));
237
+ for (const tx of result.validTxs) {
238
+ request.missingTxTracker.markFetched(tx);
239
+ }
240
+ return result;
241
+ },
242
+ txHashes,
232
243
  {
233
244
  description: `fast ${node.getInfo()}`,
234
245
  node: node.getInfo(),
@@ -268,32 +279,44 @@ export class FastTxCollection {
268
279
  }
269
280
 
270
281
  this.log.debug(
271
- `Starting fast reqresp for ${request.missingTxHashes.size} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
282
+ `Starting fast reqresp for ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
272
283
  { ...blockInfo, timeoutMs, pinnedPeer },
273
284
  );
274
285
 
275
286
  try {
276
287
  await this.txCollectionSink.collect(
277
- async txHashes => {
288
+ async () => {
289
+ let result: Tx[];
278
290
  if (request.type === 'proposal') {
279
- return await this.missingTxsCollector.collectTxs(txHashes, request.blockProposal, pinnedPeer, timeoutMs);
291
+ result = await this.missingTxsCollector.collectTxs(
292
+ request.missingTxTracker,
293
+ request.blockProposal,
294
+ pinnedPeer,
295
+ timeoutMs,
296
+ );
280
297
  } else if (request.type === 'block') {
281
298
  const blockTxsSource = {
282
299
  txHashes: request.block.body.txEffects.map(e => e.txHash),
283
300
  archive: request.block.archive.root,
284
301
  };
285
- return await this.missingTxsCollector.collectTxs(txHashes, blockTxsSource, pinnedPeer, timeoutMs);
302
+ result = await this.missingTxsCollector.collectTxs(
303
+ request.missingTxTracker,
304
+ blockTxsSource,
305
+ pinnedPeer,
306
+ timeoutMs,
307
+ );
286
308
  } else {
287
309
  throw new Error(`Unknown request type: ${(request as any).type}`);
288
310
  }
311
+ return { validTxs: result, invalidTxHashes: [] };
289
312
  },
290
- Array.from(request.missingTxHashes).map(txHash => TxHash.fromString(txHash)),
313
+ Array.from(request.missingTxTracker.missingTxHashes),
291
314
  { description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
292
315
  this.getAddContext(request),
293
316
  );
294
317
  } catch (err) {
295
318
  this.log.error(`Error sending fast reqresp request for txs`, err, {
296
- txs: [...request.missingTxHashes],
319
+ txs: [...request.missingTxTracker.missingTxHashes],
297
320
  ...blockInfo,
298
321
  });
299
322
  }
@@ -317,22 +340,20 @@ export class FastTxCollection {
317
340
  for (const tx of txs) {
318
341
  const txHash = tx.txHash.toString();
319
342
  // Remove the tx hash from the missing set, and add it to the found set.
320
- if (request.missingTxHashes.has(txHash)) {
321
- request.missingTxHashes.delete(txHash);
322
- request.foundTxs.set(txHash, tx);
343
+ if (request.missingTxTracker.markFetched(tx)) {
323
344
  this.log.trace(`Found tx ${txHash} for fast collection request`, {
324
345
  ...request.blockInfo,
325
346
  txHash: tx.txHash.toString(),
326
347
  type: request.type,
327
348
  });
328
- // If we found all txs for this request, we resolve the promise
329
- if (request.missingTxHashes.size === 0) {
330
- this.log.trace(`All txs found for fast collection request`, {
331
- ...request.blockInfo,
332
- type: request.type,
333
- });
334
- request.promise.resolve();
335
- }
349
+ }
350
+ // If we found all txs for this request, we resolve the promise
351
+ if (request.missingTxTracker.allFetched()) {
352
+ this.log.trace(`All txs found for fast collection request`, {
353
+ ...request.blockInfo,
354
+ type: request.type,
355
+ });
356
+ request.promise.resolve();
336
357
  }
337
358
  }
338
359
  }