@aztec/p2p 0.0.1-commit.8f9871590 → 0.0.1-commit.934299a21

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 (202) 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 +13 -23
  4. package/dest/client/interface.d.ts +9 -18
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +5 -16
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +40 -71
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +5 -5
  10. package/dest/config.d.ts +4 -6
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +0 -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/tx_pool_v2/deleted_pool.d.ts +3 -1
  17. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  18. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
  19. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  20. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  21. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  22. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -3
  23. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  24. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +10 -4
  26. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  27. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  29. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  30. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  32. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +2 -2
  33. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -5
  34. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  35. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +12 -6
  37. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  38. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  40. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  41. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  43. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  44. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  45. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  46. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +16 -6
  47. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
  49. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +12 -2
  50. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +37 -1
  52. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
  53. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +12 -2
  55. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +6 -3
  56. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -5
  58. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +11 -5
  59. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +241 -130
  61. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  62. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  63. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  64. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  65. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  66. package/dest/msg_validators/tx_validator/factory.js +219 -58
  67. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  68. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  70. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  71. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/index.js +1 -0
  73. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  74. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  75. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  76. package/dest/services/dummy_service.d.ts +4 -4
  77. package/dest/services/dummy_service.d.ts.map +1 -1
  78. package/dest/services/dummy_service.js +4 -4
  79. package/dest/services/encoding.d.ts +1 -1
  80. package/dest/services/encoding.d.ts.map +1 -1
  81. package/dest/services/encoding.js +2 -1
  82. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  83. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  84. package/dest/services/gossipsub/topic_score_params.js +32 -10
  85. package/dest/services/libp2p/libp2p_service.d.ts +11 -7
  86. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  87. package/dest/services/libp2p/libp2p_service.js +62 -71
  88. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  89. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  90. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  91. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  92. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  93. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  94. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  95. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  96. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  97. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  98. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  99. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  100. package/dest/services/service.d.ts +5 -3
  101. package/dest/services/service.d.ts.map +1 -1
  102. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  103. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  104. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  105. package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
  106. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  107. package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
  108. package/dest/services/tx_collection/file_store_tx_source.d.ts +15 -6
  109. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  110. package/dest/services/tx_collection/file_store_tx_source.js +47 -16
  111. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  112. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  113. package/dest/services/tx_collection/instrumentation.js +2 -1
  114. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  115. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  116. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  117. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  118. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  119. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  120. package/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
  121. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  122. package/dest/services/tx_collection/slow_tx_collection.js +10 -8
  123. package/dest/services/tx_collection/tx_collection.d.ts +5 -4
  124. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  125. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  126. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  127. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  128. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  129. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  130. package/dest/services/tx_collection/tx_source.js +19 -2
  131. package/dest/services/tx_file_store/tx_file_store.js +1 -1
  132. package/dest/services/tx_provider.d.ts +3 -3
  133. package/dest/services/tx_provider.d.ts.map +1 -1
  134. package/dest/services/tx_provider.js +4 -4
  135. package/dest/test-helpers/mock-pubsub.d.ts +3 -2
  136. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  137. package/dest/test-helpers/mock-pubsub.js +6 -0
  138. package/dest/test-helpers/testbench-utils.d.ts +6 -3
  139. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  140. package/dest/test-helpers/testbench-utils.js +1 -1
  141. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  142. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  143. package/dest/testbench/p2p_client_testbench_worker.js +6 -6
  144. package/dest/util.d.ts +2 -2
  145. package/dest/util.d.ts.map +1 -1
  146. package/package.json +14 -14
  147. package/src/client/factory.ts +19 -35
  148. package/src/client/interface.ts +16 -19
  149. package/src/client/p2p_client.ts +46 -93
  150. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
  151. package/src/config.ts +2 -10
  152. package/src/errors/tx-pool.error.ts +12 -0
  153. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
  154. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  155. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -3
  156. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
  157. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  158. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  159. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +2 -2
  160. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  161. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -9
  162. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  163. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  164. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  165. package/src/mem_pools/tx_pool_v2/interfaces.ts +15 -6
  166. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +46 -2
  167. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +14 -3
  168. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +12 -7
  169. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +264 -125
  170. package/src/msg_validators/tx_validator/README.md +115 -0
  171. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  172. package/src/msg_validators/tx_validator/factory.ts +353 -77
  173. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  174. package/src/msg_validators/tx_validator/index.ts +1 -0
  175. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  176. package/src/services/dummy_service.ts +6 -6
  177. package/src/services/encoding.ts +2 -1
  178. package/src/services/gossipsub/README.md +29 -14
  179. package/src/services/gossipsub/topic_score_params.ts +49 -13
  180. package/src/services/libp2p/libp2p_service.ts +75 -79
  181. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  182. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  183. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  184. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  185. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  186. package/src/services/service.ts +11 -2
  187. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  188. package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
  189. package/src/services/tx_collection/file_store_tx_source.ts +61 -17
  190. package/src/services/tx_collection/instrumentation.ts +7 -1
  191. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  192. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  193. package/src/services/tx_collection/slow_tx_collection.ts +8 -9
  194. package/src/services/tx_collection/tx_collection.ts +4 -3
  195. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  196. package/src/services/tx_collection/tx_source.ts +22 -3
  197. package/src/services/tx_file_store/tx_file_store.ts +1 -1
  198. package/src/services/tx_provider.ts +2 -2
  199. package/src/test-helpers/mock-pubsub.ts +10 -0
  200. package/src/test-helpers/testbench-utils.ts +3 -3
  201. package/src/testbench/p2p_client_testbench_worker.ts +18 -11
  202. package/src/util.ts +7 -1
@@ -69,9 +69,11 @@ import {
69
69
  } from '../../msg_validators/index.js';
70
70
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
71
71
  import {
72
- type MessageValidator,
73
- createTxMessageValidators,
74
- createTxReqRespValidator,
72
+ type TransactionValidator,
73
+ createFirstStageTxValidationsForGossipedTransactions,
74
+ createSecondStageTxValidationsForGossipedTransactions,
75
+ createTxValidatorForBlockProposalReceivedTxs,
76
+ createTxValidatorForReqResponseReceivedTxs,
75
77
  } from '../../msg_validators/tx_validator/factory.js';
76
78
  import { GossipSubEvent } from '../../types/index.js';
77
79
  import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
@@ -87,6 +89,9 @@ import { PeerScoring } from '../peer-manager/peer_scoring.js';
87
89
  import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
88
90
  import type { P2PReqRespConfig } from '../reqresp/config.js';
89
91
  import {
92
+ AuthRequest,
93
+ BlockTxsRequest,
94
+ BlockTxsResponse,
90
95
  DEFAULT_SUB_PROTOCOL_VALIDATORS,
91
96
  type ReqRespInterface,
92
97
  type ReqRespResponse,
@@ -94,14 +99,9 @@ import {
94
99
  type ReqRespSubProtocolHandler,
95
100
  type ReqRespSubProtocolHandlers,
96
101
  type ReqRespSubProtocolValidators,
102
+ StatusMessage,
97
103
  type SubProtocolMap,
98
104
  ValidationError,
99
- } from '../reqresp/index.js';
100
- import {
101
- AuthRequest,
102
- BlockTxsRequest,
103
- BlockTxsResponse,
104
- StatusMessage,
105
105
  pingHandler,
106
106
  reqGoodbyeHandler,
107
107
  reqRespBlockHandler,
@@ -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
 
@@ -901,15 +906,45 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
901
906
  protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
902
907
  const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
903
908
  const tx = Tx.fromBuffer(payloadData);
904
- const isValid = await this.validatePropagatedTx(tx, source);
905
- if (!isValid) {
906
- this.logger.trace(`Rejecting invalid propagated tx`, {
907
- [Attributes.P2P_ID]: source.toString(),
908
- });
909
+
910
+ const currentBlockNumber = await this.archiver.getBlockNumber();
911
+ const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
912
+
913
+ // Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
914
+ const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
915
+ const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
916
+ if (!firstStageOutcome.allPassed) {
917
+ const { name } = firstStageOutcome.failure;
918
+ let { severity } = firstStageOutcome.failure;
919
+
920
+ // Double spend validator has a special case handler. We perform more detailed examination
921
+ // as to how recently the nullifier was entered into the tree and if the transaction should
922
+ // have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
923
+ if (name === 'doubleSpendValidator') {
924
+ const txBlockNumber = BlockNumber(currentBlockNumber + 1);
925
+ severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
926
+ }
927
+
928
+ this.peerManager.penalizePeer(source, severity);
929
+ return { result: TopicValidatorResult.Reject };
930
+ }
931
+
932
+ // Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
933
+ const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
934
+ if (canAdd === 'ignored') {
935
+ return { result: TopicValidatorResult.Ignore, obj: tx };
936
+ }
937
+
938
+ // Stage 2: expensive proof verification
939
+ const secondStageValidators = this.createSecondStageMessageValidators();
940
+ const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
941
+ if (!secondStageOutcome.allPassed) {
942
+ const { severity } = secondStageOutcome.failure;
943
+ this.peerManager.penalizePeer(source, severity);
909
944
  return { result: TopicValidatorResult.Reject };
910
945
  }
911
946
 
912
- // Propagate only on pool acceptance
947
+ // Pool add: persist the tx
913
948
  const txHash = tx.getTxHash();
914
949
  const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
915
950
 
@@ -917,7 +952,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
917
952
  const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
918
953
 
919
954
  this.logger.trace(`Validate propagated tx`, {
920
- isValid,
921
955
  wasAccepted,
922
956
  wasIgnored,
923
957
  [Attributes.P2P_ID]: source.toString(),
@@ -1532,43 +1566,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1532
1566
  }
1533
1567
 
1534
1568
  protected createRequestedTxValidator(): TxValidator {
1535
- return createTxReqRespValidator(this.proofVerifier, {
1569
+ return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
1536
1570
  l1ChainId: this.config.l1ChainId,
1537
1571
  rollupVersion: this.config.rollupVersion,
1538
1572
  });
1539
1573
  }
1540
1574
 
1541
- @trackSpan('Libp2pService.validatePropagatedTx', tx => ({
1542
- [Attributes.TX_HASH]: tx.getTxHash().toString(),
1543
- }))
1544
- protected async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
1545
- const currentBlockNumber = await this.archiver.getBlockNumber();
1546
-
1547
- // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1548
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1549
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1550
-
1551
- for (const validator of messageValidators) {
1552
- const outcome = await this.runValidations(tx, validator);
1553
-
1554
- if (outcome.allPassed) {
1555
- continue;
1556
- }
1557
- const { name } = outcome.failure;
1558
- let { severity } = outcome.failure;
1559
-
1560
- // Double spend validator has a special case handler
1561
- if (name === 'doubleSpendValidator') {
1562
- const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
1563
- severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
1564
- }
1565
-
1566
- this.peerManager.penalizePeer(peerId, severity);
1567
- return false;
1568
- }
1569
- return true;
1570
- }
1571
-
1572
1575
  private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
1573
1576
  if (blockNumber === this.feesCache?.blockNumber) {
1574
1577
  return this.feesCache.gasFees;
@@ -1596,60 +1599,53 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1596
1599
  };
1597
1600
  }
1598
1601
 
1599
- public async validate(txs: Tx[]): Promise<void> {
1600
- const currentBlockNumber = await this.archiver.getBlockNumber();
1601
-
1602
- // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1603
- const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1604
- const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
1602
+ public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
1603
+ const validator = createTxValidatorForBlockProposalReceivedTxs(
1604
+ this.proofVerifier,
1605
+ { l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
1606
+ this.logger.getBindings(),
1607
+ );
1605
1608
 
1606
- await Promise.all(
1609
+ const results = await Promise.all(
1607
1610
  txs.map(async tx => {
1608
- for (const validator of messageValidators) {
1609
- const outcome = await this.runValidations(tx, validator);
1610
- if (!outcome.allPassed) {
1611
- throw new Error('Invalid tx detected', { cause: { outcome } });
1612
- }
1613
- }
1611
+ const result = await validator.validateTx(tx);
1612
+ return result.result !== 'invalid';
1614
1613
  }),
1615
1614
  );
1615
+ if (results.some(value => value === false)) {
1616
+ throw new Error('Invalid tx detected');
1617
+ }
1616
1618
  }
1617
1619
 
1618
- /**
1619
- * Create message validators for the given block number and timestamp.
1620
- *
1621
- * Each validator is a pair of a validator and a severity.
1622
- * If a validator fails, the peer is penalized with the severity of the validator.
1623
- *
1624
- * @param currentBlockNumber - The current synced block number.
1625
- * @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
1626
- * @returns The message validators.
1627
- */
1628
- private async createMessageValidators(
1620
+ /** Creates the first stage (fast) validators for gossiped transactions. */
1621
+ protected async createFirstStageMessageValidators(
1629
1622
  currentBlockNumber: BlockNumber,
1630
1623
  nextSlotTimestamp: UInt64,
1631
- ): Promise<Record<string, MessageValidator>[]> {
1624
+ ): Promise<Record<string, TransactionValidator>> {
1632
1625
  const gasFees = await this.getGasFees(currentBlockNumber);
1633
1626
  const allowedInSetup = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
1627
+ const blockNumber = BlockNumber(currentBlockNumber + 1);
1634
1628
 
1635
- const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
1636
-
1637
- return createTxMessageValidators(
1629
+ return createFirstStageTxValidationsForGossipedTransactions(
1638
1630
  nextSlotTimestamp,
1639
- blockNumberInWhichTheTxIsConsideredToBeIncluded,
1631
+ blockNumber,
1640
1632
  this.worldStateSynchronizer,
1641
1633
  gasFees,
1642
1634
  this.config.l1ChainId,
1643
1635
  this.config.rollupVersion,
1644
1636
  protocolContractsHash,
1645
1637
  this.archiver,
1646
- this.proofVerifier,
1647
1638
  !this.config.disableTransactions,
1648
1639
  allowedInSetup,
1649
1640
  this.logger.getBindings(),
1650
1641
  );
1651
1642
  }
1652
1643
 
1644
+ /** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
1645
+ protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
1646
+ return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
1647
+ }
1648
+
1653
1649
  /**
1654
1650
  * Run validations on a tx.
1655
1651
  * @param tx - The tx to validate.
@@ -1658,7 +1654,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1658
1654
  */
1659
1655
  private async runValidations(
1660
1656
  tx: Tx,
1661
- messageValidators: Record<string, MessageValidator>,
1657
+ messageValidators: Record<string, TransactionValidator>,
1662
1658
  ): Promise<ValidationOutcome> {
1663
1659
  const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
1664
1660
  const { result } = await validator.validateTx(tx);
@@ -8,8 +8,8 @@ import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
8
8
  import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
9
9
 
10
10
  import type { PeerId } from '@libp2p/interface';
11
- import { peerIdFromString } from '@libp2p/peer-id';
12
11
 
12
+ import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
13
13
  import { ReqRespSubProtocol } from '.././interface.js';
14
14
  import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
15
15
  import { ReqRespStatus } from '.././status.js';
@@ -20,7 +20,7 @@ import {
20
20
  DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
21
21
  } from './config.js';
22
22
  import type { BatchTxRequesterLibP2PService, BatchTxRequesterOptions, ITxMetadataCollection } from './interface.js';
23
- import { MissingTxMetadata, MissingTxMetadataCollection } from './missing_txs.js';
23
+ import { MissingTxMetadataCollection } from './missing_txs.js';
24
24
  import { type IPeerCollection, PeerCollection } from './peer_collection.js';
25
25
  import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_validator.js';
26
26
 
@@ -60,7 +60,7 @@ export class BatchTxRequester {
60
60
  private readonly txBatchSize: number;
61
61
 
62
62
  constructor(
63
- missingTxs: TxHash[],
63
+ missingTxsTracker: IMissingTxsTracker,
64
64
  blockTxsSource: BlockTxsSource,
65
65
  pinnedPeer: PeerId | undefined,
66
66
  timeoutMs: number,
@@ -89,18 +89,16 @@ export class BatchTxRequester {
89
89
  if (this.opts.peerCollection) {
90
90
  this.peers = this.opts.peerCollection;
91
91
  } else {
92
- const initialPeers = this.p2pService.connectionSampler.getPeerListSortedByConnectionCountAsc();
93
92
  const badPeerThreshold = this.opts.badPeerThreshold ?? DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD;
94
93
  this.peers = new PeerCollection(
95
- initialPeers,
94
+ this.p2pService.connectionSampler,
96
95
  this.pinnedPeer,
97
96
  this.dateProvider,
98
97
  badPeerThreshold,
99
98
  this.p2pService.peerScoring,
100
99
  );
101
100
  }
102
- const entries: Array<[string, MissingTxMetadata]> = missingTxs.map(h => [h.toString(), new MissingTxMetadata(h)]);
103
- this.txsMetadata = new MissingTxMetadataCollection(entries, this.txBatchSize);
101
+ this.txsMetadata = new MissingTxMetadataCollection(missingTxsTracker, this.txBatchSize);
104
102
  this.smartRequesterSemaphore = this.opts.semaphore ?? new Semaphore(0);
105
103
  }
106
104
 
@@ -227,7 +225,6 @@ export class BatchTxRequester {
227
225
  * Starts dumb worker loops
228
226
  * */
229
227
  private async dumbRequester() {
230
- const nextPeerIndex = this.makeRoundRobinIndexer();
231
228
  const nextBatchIndex = this.makeRoundRobinIndexer();
232
229
 
233
230
  // Chunk missing tx hashes into batches of txBatchSize, wrapping around to ensure no peer gets less than txBatchSize
@@ -263,15 +260,9 @@ export class BatchTxRequester {
263
260
  return { blockRequest, txs };
264
261
  };
265
262
 
266
- const nextPeer = () => {
267
- const peers = this.peers.getDumbPeersToQuery();
268
- const idx = nextPeerIndex(() => peers.length);
269
- return idx === undefined ? undefined : peerIdFromString(peers[idx]);
270
- };
271
-
272
- const workerCount = Math.min(this.dumbParallelWorkerCount, this.peers.getAllPeers().size);
263
+ const workerCount = this.dumbParallelWorkerCount;
273
264
  const workers = Array.from({ length: workerCount }, (_, index) =>
274
- this.dumbWorkerLoop(nextPeer, makeRequest, index + 1),
265
+ this.dumbWorkerLoop(this.peers.nextDumbPeerToQuery.bind(this.peers), makeRequest, index + 1),
275
266
  );
276
267
 
277
268
  await Promise.allSettled(workers);
@@ -332,14 +323,6 @@ export class BatchTxRequester {
332
323
  * Starts smart worker loops
333
324
  * */
334
325
  private async smartRequester() {
335
- const nextPeerIndex = this.makeRoundRobinIndexer();
336
-
337
- const nextPeer = () => {
338
- const peers = this.peers.getSmartPeersToQuery();
339
- const idx = nextPeerIndex(() => peers.length);
340
- return idx === undefined ? undefined : peerIdFromString(peers[idx]);
341
- };
342
-
343
326
  const makeRequest = (pid: PeerId) => {
344
327
  const txs = this.txsMetadata.getTxsToRequestFromThePeer(pid);
345
328
  const blockRequest = BlockTxsRequest.fromTxsSourceAndMissingTxs(this.blockTxsSource, txs);
@@ -350,9 +333,8 @@ export class BatchTxRequester {
350
333
  return { blockRequest, txs };
351
334
  };
352
335
 
353
- const workers = Array.from(
354
- { length: Math.min(this.smartParallelWorkerCount, this.peers.getAllPeers().size) },
355
- (_, index) => this.smartWorkerLoop(nextPeer, makeRequest, index + 1),
336
+ const workers = Array.from({ length: this.smartParallelWorkerCount }, (_, index) =>
337
+ this.smartWorkerLoop(this.peers.nextSmartPeerToQuery.bind(this.peers), makeRequest, index + 1),
356
338
  );
357
339
 
358
340
  await Promise.allSettled(workers);
@@ -387,26 +369,18 @@ export class BatchTxRequester {
387
369
  if (weRanOutOfPeersToQuery) {
388
370
  this.logger.debug(`Worker loop smart: No more peers to query`);
389
371
 
390
- // If there are no more dumb peers to query then none of our peers can become smart,
391
- // thus we can simply exit this worker
392
- const noMoreDumbPeersToQuery = this.peers.getDumbPeersToQuery().length === 0;
393
- if (noMoreDumbPeersToQuery) {
394
- // These might be either smart peers that will get unblocked after _some time_
395
- const nextSmartPeerDelay = this.peers.getNextSmartPeerAvailabilityDelayMs();
396
- const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
397
- if (thereAreSomeRateLimitedSmartPeers) {
398
- await this.sleepClampedToDeadline(nextSmartPeerDelay);
399
- continue;
400
- }
401
-
402
- this.logger.debug(`Worker loop smart: No more smart peers to query killing ${workerIndex}`);
403
- break;
372
+ // If we have rate limited peers wait for them.
373
+ const nextSmartPeerDelay = this.peers.getNextSmartPeerAvailabilityDelayMs();
374
+ const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
375
+ if (thereAreSomeRateLimitedSmartPeers) {
376
+ await this.sleepClampedToDeadline(nextSmartPeerDelay);
377
+ continue;
404
378
  }
405
379
 
406
- // Otherwise there are still some dumb peers that could become smart.
407
380
  // We end up here when all known smart peers became temporarily unavailable via combination of
408
381
  // (bad, in-flight, or rate-limited) or in some weird scenario all current smart peers turn bad which is permanent
409
- // but dumb peers still exist that could become smart.
382
+ // but there are dumb peers that could be promoted
383
+ // or new peer can join as dumb and be promoted later
410
384
  //
411
385
  // When a dumb peer responds with valid txIndices, it gets
412
386
  // promoted to smart and releases the semaphore, waking this worker.
@@ -599,9 +573,7 @@ export class BatchTxRequester {
599
573
  this.markTxsPeerHas(peerId, response);
600
574
 
601
575
  // Unblock smart workers
602
- if (this.peers.getSmartPeersToQuery().length <= this.smartParallelWorkerCount) {
603
- this.smartRequesterSemaphore.release();
604
- }
576
+ this.smartRequesterSemaphore.release();
605
577
  }
606
578
 
607
579
  private isBlockResponseValid(response: BlockTxsResponse): boolean {
@@ -661,7 +633,7 @@ export class BatchTxRequester {
661
633
  /*
662
634
  * @returns true if all missing txs have been fetched */
663
635
  private fetchedAllTxs() {
664
- return Array.from(this.txsMetadata.values()).every(tx => tx.fetched);
636
+ return this.txsMetadata.getMissingTxHashes().size == 0;
665
637
  }
666
638
 
667
639
  /*
@@ -679,7 +651,7 @@ export class BatchTxRequester {
679
651
  this.unlockSmartRequesterSemaphores();
680
652
  }
681
653
 
682
- return aborted || this.txsMetadata.size === 0 || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
654
+ return aborted || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
683
655
  }
684
656
 
685
657
  /*
@@ -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
  }