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

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 (196) hide show
  1. package/dest/client/factory.d.ts +3 -2
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +9 -5
  4. package/dest/client/interface.d.ts +11 -9
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +6 -7
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +49 -14
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +5 -5
  10. package/dest/config.d.ts +12 -2
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +5 -0
  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 +4 -1
  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 +10 -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 +5 -3
  43. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
  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 +8 -4
  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/instrumentation.d.ts +15 -0
  53. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  54. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  55. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +14 -2
  56. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
  58. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +9 -5
  59. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +30 -5
  61. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  62. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +27 -4
  64. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +8 -3
  65. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  66. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +11 -6
  67. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -4
  68. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  69. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +164 -37
  70. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  71. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  73. package/dest/services/dummy_service.d.ts +3 -2
  74. package/dest/services/dummy_service.d.ts.map +1 -1
  75. package/dest/services/dummy_service.js +3 -0
  76. package/dest/services/encoding.d.ts +1 -1
  77. package/dest/services/encoding.d.ts.map +1 -1
  78. package/dest/services/encoding.js +2 -1
  79. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  80. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  81. package/dest/services/gossipsub/topic_score_params.js +32 -10
  82. package/dest/services/libp2p/libp2p_service.d.ts +2 -1
  83. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  84. package/dest/services/libp2p/libp2p_service.js +7 -3
  85. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  86. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  87. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +5 -9
  88. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  89. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  90. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  91. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  92. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  93. package/dest/services/service.d.ts +4 -2
  94. package/dest/services/service.d.ts.map +1 -1
  95. package/dest/services/tx_collection/config.d.ts +13 -1
  96. package/dest/services/tx_collection/config.d.ts.map +1 -1
  97. package/dest/services/tx_collection/config.js +30 -0
  98. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  99. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  100. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  101. package/dest/services/tx_collection/file_store_tx_collection.d.ts +38 -29
  102. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  103. package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
  104. package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
  105. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  106. package/dest/services/tx_collection/file_store_tx_source.js +49 -16
  107. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  108. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  109. package/dest/services/tx_collection/instrumentation.js +2 -1
  110. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  111. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  112. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  113. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  114. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  115. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  116. package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
  117. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  118. package/dest/services/tx_collection/slow_tx_collection.js +17 -12
  119. package/dest/services/tx_collection/tx_collection.d.ts +9 -6
  120. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  121. package/dest/services/tx_collection/tx_collection.js +26 -10
  122. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  123. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  124. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  125. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  126. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  127. package/dest/services/tx_collection/tx_source.js +19 -2
  128. package/dest/services/tx_file_store/tx_file_store.d.ts +3 -2
  129. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  130. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  131. package/dest/test-helpers/mock-pubsub.d.ts +3 -2
  132. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  133. package/dest/test-helpers/mock-pubsub.js +6 -0
  134. package/dest/test-helpers/testbench-utils.d.ts +7 -2
  135. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  136. package/dest/test-helpers/testbench-utils.js +7 -1
  137. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  138. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  139. package/dest/testbench/p2p_client_testbench_worker.js +8 -8
  140. package/dest/util.d.ts +2 -2
  141. package/dest/util.d.ts.map +1 -1
  142. package/package.json +14 -14
  143. package/src/client/factory.ts +18 -3
  144. package/src/client/interface.ts +20 -9
  145. package/src/client/p2p_client.ts +57 -17
  146. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
  147. package/src/config.ts +9 -1
  148. package/src/errors/tx-pool.error.ts +12 -0
  149. package/src/mem_pools/attestation_pool/attestation_pool.ts +8 -0
  150. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  151. package/src/mem_pools/tx_pool/README.md +1 -1
  152. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  153. package/src/mem_pools/tx_pool_v2/README.md +43 -27
  154. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
  155. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  156. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +4 -1
  157. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
  158. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  159. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  160. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  161. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
  162. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +8 -7
  163. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  164. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  165. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  166. package/src/mem_pools/tx_pool_v2/interfaces.ts +14 -2
  167. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +44 -9
  168. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +32 -5
  169. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +17 -6
  170. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +186 -29
  171. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  172. package/src/services/dummy_service.ts +5 -1
  173. package/src/services/encoding.ts +2 -1
  174. package/src/services/gossipsub/README.md +29 -14
  175. package/src/services/gossipsub/topic_score_params.ts +49 -13
  176. package/src/services/libp2p/libp2p_service.ts +7 -2
  177. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +6 -6
  178. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  179. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  180. package/src/services/service.ts +10 -1
  181. package/src/services/tx_collection/config.ts +42 -0
  182. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  183. package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
  184. package/src/services/tx_collection/file_store_tx_source.ts +64 -17
  185. package/src/services/tx_collection/instrumentation.ts +7 -1
  186. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  187. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  188. package/src/services/tx_collection/slow_tx_collection.ts +17 -13
  189. package/src/services/tx_collection/tx_collection.ts +45 -14
  190. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  191. package/src/services/tx_collection/tx_source.ts +22 -3
  192. package/src/services/tx_file_store/tx_file_store.ts +6 -4
  193. package/src/test-helpers/mock-pubsub.ts +10 -0
  194. package/src/test-helpers/testbench-utils.ts +10 -2
  195. package/src/testbench/p2p_client_testbench_worker.ts +20 -13
  196. package/src/util.ts +7 -1
@@ -15,6 +15,8 @@ export type TopicScoringNetworkParams = {
15
15
  targetCommitteeSize: number;
16
16
  /** Duration per block in milliseconds when building multiple blocks per slot. If undefined, single block mode. */
17
17
  blockDurationMs?: number;
18
+ /** Expected number of block proposals per slot for scoring override. 0 disables scoring, undefined falls back to blocksPerSlot - 1. */
19
+ expectedBlockProposalsPerSlot?: number;
18
20
  };
19
21
 
20
22
  /**
@@ -89,18 +91,41 @@ export function computeThreshold(convergence: number, conservativeFactor: number
89
91
  return convergence * conservativeFactor;
90
92
  }
91
93
 
94
+ /**
95
+ * Determines the effective expected block proposals per slot for scoring.
96
+ * Returns undefined if scoring should be disabled, or a positive number if enabled.
97
+ *
98
+ * @param blocksPerSlot - Number of blocks per slot from timetable
99
+ * @param expectedBlockProposalsPerSlot - Config override. 0 disables scoring, undefined falls back to blocksPerSlot - 1.
100
+ * @returns Positive number of expected block proposals, or undefined if scoring is disabled
101
+ */
102
+ export function getEffectiveBlockProposalsPerSlot(
103
+ blocksPerSlot: number,
104
+ expectedBlockProposalsPerSlot?: number,
105
+ ): number | undefined {
106
+ if (expectedBlockProposalsPerSlot !== undefined) {
107
+ return expectedBlockProposalsPerSlot > 0 ? expectedBlockProposalsPerSlot : undefined;
108
+ }
109
+ // Fallback: In MBPS mode, N-1 block proposals per slot (last one bundled with checkpoint)
110
+ // In single block mode (blocksPerSlot=1), this is 0 → disabled
111
+ const fallback = Math.max(0, blocksPerSlot - 1);
112
+ return fallback > 0 ? fallback : undefined;
113
+ }
114
+
92
115
  /**
93
116
  * Gets the expected messages per slot for a given topic type.
94
117
  *
95
118
  * @param topicType - The topic type
96
119
  * @param targetCommitteeSize - Target committee size
97
120
  * @param blocksPerSlot - Number of blocks per slot
121
+ * @param expectedBlockProposalsPerSlot - Override for block proposals. 0 disables scoring, undefined falls back to blocksPerSlot - 1.
98
122
  * @returns Expected messages per slot, or undefined if unpredictable
99
123
  */
100
124
  export function getExpectedMessagesPerSlot(
101
125
  topicType: TopicType,
102
126
  targetCommitteeSize: number,
103
127
  blocksPerSlot: number,
128
+ expectedBlockProposalsPerSlot?: number,
104
129
  ): number | undefined {
105
130
  switch (topicType) {
106
131
  case TopicType.tx:
@@ -108,9 +133,7 @@ export function getExpectedMessagesPerSlot(
108
133
  return undefined;
109
134
 
110
135
  case TopicType.block_proposal:
111
- // In MBPS mode, N-1 block proposals per slot (last one bundled with checkpoint)
112
- // In single block mode (blocksPerSlot=1), this is 0
113
- return Math.max(0, blocksPerSlot - 1);
136
+ return getEffectiveBlockProposalsPerSlot(blocksPerSlot, expectedBlockProposalsPerSlot);
114
137
 
115
138
  case TopicType.checkpoint_proposal:
116
139
  // Exactly 1 checkpoint proposal per slot
@@ -190,10 +213,12 @@ const P2_DECAY_WINDOW_SLOTS = 2;
190
213
  // |P3| > 8 + 25 = 33
191
214
  //
192
215
  // We set P3 max = -34 per topic (slightly more than P1+P2) to ensure pruning.
193
- // With 3 topics having P3 enabled, total P3b after pruning = -102.
216
+ // The number of P3-enabled topics depends on config: by default 2 (checkpoint_proposal +
217
+ // checkpoint_attestation), or 3 if block proposal scoring is enabled via
218
+ // expectedBlockProposalsPerSlot. Total P3b after pruning = -68 (2 topics) or -102 (3 topics).
194
219
  //
195
- // With appSpecificWeight=10, ~20 HighTolerance errors (-40 app score) plus max P3b (-102)
196
- // would cross gossipThreshold (-500). This keeps non-contributors from being disconnected
220
+ // With appSpecificWeight=10, ~20 HighTolerance errors (-40 app score) plus max P3b (-68 or -102)
221
+ // would not cross gossipThreshold (-500). This keeps non-contributors from being disconnected
197
222
  // unless they also accrue app-level penalties.
198
223
  //
199
224
  // The weight formula ensures max penalty equals MAX_P3_PENALTY_PER_TOPIC:
@@ -203,12 +228,6 @@ const P2_DECAY_WINDOW_SLOTS = 2;
203
228
  /** Maximum P3 penalty per topic (must exceed P1 + P2 to cause pruning) */
204
229
  export const MAX_P3_PENALTY_PER_TOPIC = -(MAX_P1_SCORE + MAX_P2_SCORE + 1); // -34
205
230
 
206
- /** Number of topics with P3 enabled in MBPS mode (block_proposal + checkpoint_proposal + checkpoint_attestation) */
207
- export const NUM_P3_ENABLED_TOPICS = 3;
208
-
209
- /** Total maximum P3b penalty across all topics after pruning in MBPS mode */
210
- export const TOTAL_MAX_P3B_PENALTY = MAX_P3_PENALTY_PER_TOPIC * NUM_P3_ENABLED_TOPICS; // -102
211
-
212
231
  /**
213
232
  * Factory class for creating gossipsub topic scoring parameters.
214
233
  * Computes shared values once and reuses them across all topics.
@@ -384,6 +403,18 @@ export class TopicScoreParamsFactory {
384
403
  });
385
404
  }
386
405
 
406
+ /** Number of topics with P3 enabled, computed from config. Always 2 (checkpoint_proposal + checkpoint_attestation) plus optionally block_proposal. */
407
+ get numP3EnabledTopics(): number {
408
+ const blockProposalP3Enabled =
409
+ getEffectiveBlockProposalsPerSlot(this.blocksPerSlot, this.params.expectedBlockProposalsPerSlot) !== undefined;
410
+ return blockProposalP3Enabled ? 3 : 2;
411
+ }
412
+
413
+ /** Total maximum P3b penalty across all topics after pruning, computed from config */
414
+ get totalMaxP3bPenalty(): number {
415
+ return MAX_P3_PENALTY_PER_TOPIC * this.numP3EnabledTopics;
416
+ }
417
+
387
418
  /**
388
419
  * Creates topic score parameters for a specific topic type.
389
420
  *
@@ -391,7 +422,12 @@ export class TopicScoreParamsFactory {
391
422
  * @returns TopicScoreParams for the topic
392
423
  */
393
424
  createForTopic(topicType: TopicType): ReturnType<typeof createTopicScoreParams> {
394
- const expectedPerSlot = getExpectedMessagesPerSlot(topicType, this.params.targetCommitteeSize, this.blocksPerSlot);
425
+ const expectedPerSlot = getExpectedMessagesPerSlot(
426
+ topicType,
427
+ this.params.targetCommitteeSize,
428
+ this.blocksPerSlot,
429
+ this.params.expectedBlockProposalsPerSlot,
430
+ );
395
431
 
396
432
  // For unpredictable topics (tx) or topics with 0 expected messages, disable P3/P3b
397
433
  if (expectedPerSlot === undefined || expectedPerSlot === 0) {
@@ -341,6 +341,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
341
341
  heartbeatIntervalMs: config.gossipsubInterval,
342
342
  targetCommitteeSize: l1Constants.targetCommitteeSize,
343
343
  blockDurationMs: config.blockDurationMs,
344
+ expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
344
345
  });
345
346
 
346
347
  const node = await createLibp2p({
@@ -614,6 +615,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
614
615
  return this.peerManager.getPeers(includePending);
615
616
  }
616
617
 
618
+ public getGossipMeshPeerCount(topicType: TopicType): number {
619
+ return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
620
+ }
621
+
617
622
  private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
618
623
  this.logger.trace(`Received PUBSUB message.`);
619
624
 
@@ -1544,7 +1549,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1544
1549
  protected async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
1545
1550
  const currentBlockNumber = await this.archiver.getBlockNumber();
1546
1551
 
1547
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1552
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1548
1553
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1549
1554
  const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1550
1555
 
@@ -1599,7 +1604,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1599
1604
  public async validate(txs: Tx[]): Promise<void> {
1600
1605
  const currentBlockNumber = await this.archiver.getBlockNumber();
1601
1606
 
1602
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1607
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1603
1608
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1604
1609
  const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1605
1610
 
@@ -10,6 +10,7 @@ import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
10
10
  import type { PeerId } from '@libp2p/interface';
11
11
  import { peerIdFromString } from '@libp2p/peer-id';
12
12
 
13
+ import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
13
14
  import { ReqRespSubProtocol } from '.././interface.js';
14
15
  import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
15
16
  import { ReqRespStatus } from '.././status.js';
@@ -20,7 +21,7 @@ import {
20
21
  DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
21
22
  } from './config.js';
22
23
  import type { BatchTxRequesterLibP2PService, BatchTxRequesterOptions, ITxMetadataCollection } from './interface.js';
23
- import { MissingTxMetadata, MissingTxMetadataCollection } from './missing_txs.js';
24
+ import { MissingTxMetadataCollection } from './missing_txs.js';
24
25
  import { type IPeerCollection, PeerCollection } from './peer_collection.js';
25
26
  import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_validator.js';
26
27
 
@@ -60,7 +61,7 @@ export class BatchTxRequester {
60
61
  private readonly txBatchSize: number;
61
62
 
62
63
  constructor(
63
- missingTxs: TxHash[],
64
+ missingTxsTracker: IMissingTxsTracker,
64
65
  blockTxsSource: BlockTxsSource,
65
66
  pinnedPeer: PeerId | undefined,
66
67
  timeoutMs: number,
@@ -99,8 +100,7 @@ export class BatchTxRequester {
99
100
  this.p2pService.peerScoring,
100
101
  );
101
102
  }
102
- const entries: Array<[string, MissingTxMetadata]> = missingTxs.map(h => [h.toString(), new MissingTxMetadata(h)]);
103
- this.txsMetadata = new MissingTxMetadataCollection(entries, this.txBatchSize);
103
+ this.txsMetadata = new MissingTxMetadataCollection(missingTxsTracker, this.txBatchSize);
104
104
  this.smartRequesterSemaphore = this.opts.semaphore ?? new Semaphore(0);
105
105
  }
106
106
 
@@ -661,7 +661,7 @@ export class BatchTxRequester {
661
661
  /*
662
662
  * @returns true if all missing txs have been fetched */
663
663
  private fetchedAllTxs() {
664
- return Array.from(this.txsMetadata.values()).every(tx => tx.fetched);
664
+ return this.txsMetadata.getMissingTxHashes().size == 0;
665
665
  }
666
666
 
667
667
  /*
@@ -679,7 +679,7 @@ export class BatchTxRequester {
679
679
  this.unlockSmartRequesterSemaphores();
680
680
  }
681
681
 
682
- return aborted || this.txsMetadata.size === 0 || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
682
+ return aborted || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
683
683
  }
684
684
 
685
685
  /*
@@ -6,7 +6,6 @@ import type { PeerId } from '@libp2p/interface';
6
6
 
7
7
  import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
8
8
  import type { ReqRespInterface } from '../interface.js';
9
- import type { MissingTxMetadata } from './missing_txs.js';
10
9
  import type { IPeerCollection } from './peer_collection.js';
11
10
  import type { BatchRequestTxValidatorConfig, IBatchRequestTxValidator } from './tx_validator.js';
12
11
 
@@ -15,18 +14,15 @@ export interface IPeerPenalizer {
15
14
  }
16
15
 
17
16
  export interface ITxMetadataCollection {
18
- size: number;
19
- values(): IterableIterator<MissingTxMetadata>;
20
17
  getMissingTxHashes(): Set<string>;
18
+ markFetched(peerId: PeerId, tx: Tx): boolean;
21
19
  getTxsToRequestFromThePeer(peer: PeerId): TxHash[];
22
20
  markRequested(txHash: TxHash): void;
23
21
  markInFlightBySmartPeer(txHash: TxHash): void;
24
22
  markNotInFlightBySmartPeer(txHash: TxHash): void;
25
23
  alreadyFetched(txHash: TxHash): boolean;
26
24
  // Returns true if tx was marked as fetched, false if it was already marked as fetched
27
- markFetched(peerId: PeerId, tx: Tx): boolean;
28
25
  markPeerHas(peerId: PeerId, txHashes: TxHash[]): void;
29
- getFetchedTxs(): Tx[];
30
26
  }
31
27
 
32
28
  /**
@@ -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
  }
@@ -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,6 +136,9 @@ export interface P2PService {
130
136
 
131
137
  getPeers(includePending?: boolean): PeerInfo[];
132
138
 
139
+ /** Returns the number of peers in the GossipSub mesh for a given topic type. */
140
+ getGossipMeshPeerCount(topicType: TopicType): number;
141
+
133
142
  validate(txs: Tx[]): Promise<void>;
134
143
 
135
144
  addReqRespSubProtocol(
@@ -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
  };