@aztec/p2p 1.2.1 → 2.0.0-nightly.20250813

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 (221) hide show
  1. package/dest/client/factory.d.ts +5 -1
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +29 -12
  4. package/dest/client/interface.d.ts +8 -13
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +18 -22
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +86 -83
  9. package/dest/config.d.ts +30 -1
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +34 -1
  12. package/dest/index.d.ts +1 -0
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -0
  15. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +13 -1
  16. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  17. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +117 -10
  19. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +4 -1
  20. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +22 -1
  22. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +4 -1
  23. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  24. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +21 -1
  25. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
  26. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  27. package/dest/mem_pools/attestation_pool/mocks.js +2 -10
  28. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +8 -3
  29. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  30. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +64 -37
  31. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +8 -3
  32. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  33. package/dest/mem_pools/tx_pool/memory_tx_pool.js +18 -10
  34. package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -2
  35. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +73 -44
  38. package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
  39. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  40. package/dest/msg_validators/tx_validator/block_header_validator.js +2 -2
  41. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  42. package/dest/msg_validators/tx_validator/data_validator.js +35 -59
  43. package/dest/msg_validators/tx_validator/double_spend_validator.js +2 -2
  44. package/dest/msg_validators/tx_validator/gas_validator.js +4 -4
  45. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  46. package/dest/msg_validators/tx_validator/metadata_validator.js +21 -21
  47. package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
  48. package/dest/msg_validators/tx_validator/tx_proof_validator.js +3 -3
  49. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  50. package/dest/services/discv5/discV5_service.js +4 -1
  51. package/dest/services/dummy_service.d.ts +13 -3
  52. package/dest/services/dummy_service.d.ts.map +1 -1
  53. package/dest/services/dummy_service.js +26 -3
  54. package/dest/services/index.d.ts +3 -1
  55. package/dest/services/index.d.ts.map +1 -1
  56. package/dest/services/index.js +3 -1
  57. package/dest/services/libp2p/libp2p_service.d.ts +13 -20
  58. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  59. package/dest/services/libp2p/libp2p_service.js +123 -46
  60. package/dest/services/peer-manager/interface.d.ts +8 -1
  61. package/dest/services/peer-manager/interface.d.ts.map +1 -1
  62. package/dest/services/peer-manager/peer_manager.d.ts +70 -3
  63. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  64. package/dest/services/peer-manager/peer_manager.js +369 -39
  65. package/dest/services/reqresp/config.d.ts +3 -3
  66. package/dest/services/reqresp/config.d.ts.map +1 -1
  67. package/dest/services/reqresp/config.js +3 -3
  68. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +3 -4
  69. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  70. package/dest/services/reqresp/connection-sampler/connection_sampler.js +35 -52
  71. package/dest/services/reqresp/index.d.ts +2 -1
  72. package/dest/services/reqresp/index.d.ts.map +1 -1
  73. package/dest/services/reqresp/index.js +2 -1
  74. package/dest/services/reqresp/interface.d.ts +61 -10
  75. package/dest/services/reqresp/interface.d.ts.map +1 -1
  76. package/dest/services/reqresp/interface.js +41 -6
  77. package/dest/services/reqresp/protocols/auth.d.ts +43 -0
  78. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
  79. package/dest/services/reqresp/protocols/auth.js +71 -0
  80. package/dest/services/reqresp/protocols/block.d.ts +5 -0
  81. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  82. package/dest/services/reqresp/protocols/block.js +28 -5
  83. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
  84. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
  85. package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
  86. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
  87. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
  88. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
  89. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
  90. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
  91. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
  92. package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
  93. package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
  94. package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
  95. package/dest/services/reqresp/protocols/goodbye.js +3 -5
  96. package/dest/services/reqresp/protocols/index.d.ts +2 -0
  97. package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
  98. package/dest/services/reqresp/protocols/index.js +2 -0
  99. package/dest/services/reqresp/protocols/status.d.ts +2 -0
  100. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  101. package/dest/services/reqresp/protocols/status.js +7 -0
  102. package/dest/services/reqresp/protocols/tx.d.ts +12 -1
  103. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  104. package/dest/services/reqresp/protocols/tx.js +34 -6
  105. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
  106. package/dest/services/reqresp/rate-limiter/rate_limits.js +20 -0
  107. package/dest/services/reqresp/reqresp.d.ts +37 -39
  108. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  109. package/dest/services/reqresp/reqresp.js +220 -220
  110. package/dest/services/reqresp/status.d.ts +8 -3
  111. package/dest/services/reqresp/status.d.ts.map +1 -1
  112. package/dest/services/reqresp/status.js +6 -2
  113. package/dest/services/service.d.ts +10 -10
  114. package/dest/services/service.d.ts.map +1 -1
  115. package/dest/services/tx_collection/config.d.ts +25 -0
  116. package/dest/services/tx_collection/config.d.ts.map +1 -0
  117. package/dest/services/tx_collection/config.js +58 -0
  118. package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
  119. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
  120. package/dest/services/tx_collection/fast_tx_collection.js +295 -0
  121. package/dest/services/tx_collection/index.d.ts +3 -0
  122. package/dest/services/tx_collection/index.d.ts.map +1 -0
  123. package/dest/services/tx_collection/index.js +2 -0
  124. package/dest/services/tx_collection/instrumentation.d.ts +10 -0
  125. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
  126. package/dest/services/tx_collection/instrumentation.js +34 -0
  127. package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
  128. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
  129. package/dest/services/tx_collection/slow_tx_collection.js +176 -0
  130. package/dest/services/tx_collection/tx_collection.d.ts +109 -0
  131. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
  132. package/dest/services/tx_collection/tx_collection.js +127 -0
  133. package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
  134. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
  135. package/dest/services/tx_collection/tx_collection_sink.js +81 -0
  136. package/dest/services/tx_collection/tx_source.d.ts +18 -0
  137. package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
  138. package/dest/services/tx_collection/tx_source.js +31 -0
  139. package/dest/services/tx_provider.d.ts +49 -0
  140. package/dest/services/tx_provider.d.ts.map +1 -0
  141. package/dest/services/tx_provider.js +206 -0
  142. package/dest/services/{tx_collect_instrumentation.d.ts → tx_provider_instrumentation.d.ts} +2 -2
  143. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
  144. package/dest/services/{tx_collect_instrumentation.js → tx_provider_instrumentation.js} +5 -5
  145. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  146. package/dest/test-helpers/make-test-p2p-clients.js +4 -3
  147. package/dest/test-helpers/mock-pubsub.d.ts +2 -1
  148. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  149. package/dest/test-helpers/mock-pubsub.js +2 -1
  150. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  151. package/dest/test-helpers/reqresp-nodes.js +8 -4
  152. package/dest/testbench/p2p_client_testbench_worker.js +11 -5
  153. package/dest/util.d.ts +1 -1
  154. package/dest/util.d.ts.map +1 -1
  155. package/package.json +14 -15
  156. package/src/client/factory.ts +87 -12
  157. package/src/client/interface.ts +19 -15
  158. package/src/client/p2p_client.ts +108 -92
  159. package/src/config.ts +52 -1
  160. package/src/index.ts +1 -0
  161. package/src/mem_pools/attestation_pool/attestation_pool.ts +15 -1
  162. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +155 -4
  163. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +28 -1
  164. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +28 -2
  165. package/src/mem_pools/attestation_pool/mocks.ts +1 -3
  166. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +59 -41
  167. package/src/mem_pools/tx_pool/memory_tx_pool.ts +19 -9
  168. package/src/mem_pools/tx_pool/tx_pool.ts +7 -2
  169. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +63 -40
  170. package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
  171. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  172. package/src/msg_validators/tx_validator/data_validator.ts +36 -27
  173. package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
  174. package/src/msg_validators/tx_validator/gas_validator.ts +4 -4
  175. package/src/msg_validators/tx_validator/metadata_validator.ts +22 -28
  176. package/src/msg_validators/tx_validator/phases_validator.ts +2 -2
  177. package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -2
  178. package/src/services/discv5/discV5_service.ts +4 -1
  179. package/src/services/dummy_service.ts +44 -4
  180. package/src/services/index.ts +3 -1
  181. package/src/services/libp2p/libp2p_service.ts +147 -55
  182. package/src/services/peer-manager/interface.ts +10 -1
  183. package/src/services/peer-manager/peer_manager.ts +441 -41
  184. package/src/services/reqresp/config.ts +3 -3
  185. package/src/services/reqresp/connection-sampler/connection_sampler.ts +38 -63
  186. package/src/services/reqresp/index.ts +2 -0
  187. package/src/services/reqresp/interface.ts +63 -17
  188. package/src/services/reqresp/protocols/auth.ts +83 -0
  189. package/src/services/reqresp/protocols/block.ts +24 -3
  190. package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
  191. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
  192. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
  193. package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
  194. package/src/services/reqresp/protocols/goodbye.ts +3 -3
  195. package/src/services/reqresp/protocols/index.ts +2 -0
  196. package/src/services/reqresp/protocols/status.ts +20 -0
  197. package/src/services/reqresp/protocols/tx.ts +35 -6
  198. package/src/services/reqresp/rate-limiter/rate_limits.ts +20 -0
  199. package/src/services/reqresp/reqresp.ts +294 -264
  200. package/src/services/reqresp/status.ts +9 -3
  201. package/src/services/service.ts +23 -14
  202. package/src/services/tx_collection/config.ts +84 -0
  203. package/src/services/tx_collection/fast_tx_collection.ts +338 -0
  204. package/src/services/tx_collection/index.ts +2 -0
  205. package/src/services/tx_collection/instrumentation.ts +43 -0
  206. package/src/services/tx_collection/slow_tx_collection.ts +232 -0
  207. package/src/services/tx_collection/tx_collection.ts +214 -0
  208. package/src/services/tx_collection/tx_collection_sink.ts +98 -0
  209. package/src/services/tx_collection/tx_source.ts +37 -0
  210. package/src/services/tx_provider.ts +215 -0
  211. package/src/services/{tx_collect_instrumentation.ts → tx_provider_instrumentation.ts} +5 -5
  212. package/src/test-helpers/make-test-p2p-clients.ts +4 -2
  213. package/src/test-helpers/mock-pubsub.ts +1 -0
  214. package/src/test-helpers/reqresp-nodes.ts +7 -1
  215. package/src/testbench/p2p_client_testbench_worker.ts +9 -2
  216. package/src/util.ts +1 -1
  217. package/dest/services/tx_collect_instrumentation.d.ts.map +0 -1
  218. package/dest/services/tx_collector.d.ts +0 -23
  219. package/dest/services/tx_collector.d.ts.map +0 -1
  220. package/dest/services/tx_collector.js +0 -95
  221. package/src/services/tx_collector.ts +0 -134
@@ -0,0 +1,79 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { TxArray } from '@aztec/stdlib/tx';
4
+
5
+ import { BitVector } from './bitvector.js';
6
+
7
+ /**
8
+ * Request message for requesting specific transactions from a block
9
+ */
10
+ export class BlockTxsRequest {
11
+ constructor(
12
+ readonly blockHash: Fr, // 32 byte hash of the proposed block header
13
+ // BitVector indicating which txs from the proposal we are requesting
14
+ // 1 means we want the tx, 0 means we don't
15
+ readonly txIndices: BitVector,
16
+ ) {}
17
+
18
+ /**
19
+ * Deserializes the BlockTxRequest object from a Buffer
20
+ * @param buffer - Buffer or BufferReader object to deserialize
21
+ * @returns An instance of BlockTxRequest
22
+ */
23
+ static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
24
+ const reader = BufferReader.asReader(buffer);
25
+ const blockHash = Fr.fromBuffer(reader);
26
+ const txIndices = BitVector.fromBuffer(reader);
27
+
28
+ return new BlockTxsRequest(blockHash, txIndices);
29
+ }
30
+
31
+ /**
32
+ * Serializes the BlockTxRequest object into a Buffer
33
+ * @returns Buffer representation of the BlockTxRequest object
34
+ */
35
+ toBuffer(): Buffer {
36
+ return serializeToBuffer([this.blockHash, this.txIndices.toBuffer()]);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Response message containing requested transactions from a block
42
+ */
43
+ export class BlockTxsResponse {
44
+ constructor(
45
+ readonly blockHash: Fr,
46
+ readonly txs: TxArray, // List of transactions we requested and peer has
47
+ // BitVector indicating which txs from the proposal are available at the peer
48
+ // 1 means the tx is available, 0 means it is not
49
+ readonly txIndices: BitVector,
50
+ ) {}
51
+
52
+ /**
53
+ * Deserializes the BlockTxResponse object from a Buffer
54
+ * @param buffer - Buffer or BufferReader object to deserialize
55
+ * @returns An instance of BlockTxResponse
56
+ */
57
+ static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
58
+ const reader = BufferReader.asReader(buffer);
59
+ const blockHash = Fr.fromBuffer(reader);
60
+ const txs = TxArray.fromBuffer(reader);
61
+ const txIndices = BitVector.fromBuffer(reader);
62
+
63
+ return new BlockTxsResponse(blockHash, txs, txIndices);
64
+ }
65
+
66
+ /**
67
+ * Serializes the BlockTxResponse object into a Buffer
68
+ * @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
69
+ * thus we serialize it last
70
+ * @returns Buffer representation of the BlockTxResponse object
71
+ */
72
+ toBuffer(): Buffer {
73
+ return serializeToBuffer([this.blockHash, this.txs.toBuffer(), this.txIndices.toBuffer()]);
74
+ }
75
+
76
+ static empty(): BlockTxsResponse {
77
+ return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
78
+ }
79
+ }
@@ -0,0 +1,3 @@
1
+ export * from './block_txs_handler.js';
2
+ export * from './bitvector.js';
3
+ export * from './block_txs_reqresp.js';
@@ -90,14 +90,14 @@ export class GoodbyeProtocolHandler {
90
90
  * @returns A resolved promise with the goodbye response.
91
91
  */
92
92
  export function reqGoodbyeHandler(peerManager: PeerManagerInterface): ReqRespSubProtocolHandler {
93
- return (peerId: PeerId, _msg: Buffer) => {
94
- const reason = decodeGoodbyeReason(_msg);
93
+ return (peerId: PeerId, msg: Buffer) => {
94
+ const reason = decodeGoodbyeReason(msg);
95
95
 
96
96
  peerManager.goodbyeReceived(peerId, reason);
97
97
 
98
98
  // NOTE: In the current implementation this won't be sent to peer,
99
99
  // as the connection to peer has been already closed by peerManager.goodbyeReceived
100
100
  // We have this just to satisfy interface
101
- return Promise.resolve(Buffer.from([0x0]));
101
+ return Promise.resolve(Buffer.alloc(0));
102
102
  };
103
103
  }
@@ -6,3 +6,5 @@ export * from './status.js';
6
6
  export * from './tx.js';
7
7
  export * from './goodbye.js';
8
8
  export * from './block.js';
9
+ export * from './auth.js';
10
+ export * from './block_txs/index.js';
@@ -1,3 +1,4 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
1
2
  import type { Logger } from '@aztec/foundation/log';
2
3
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
4
  import { bufferToHex } from '@aztec/foundation/string';
@@ -69,10 +70,29 @@ export class StatusMessage {
69
70
  );
70
71
  }
71
72
 
73
+ static random(): StatusMessage {
74
+ return new StatusMessage(
75
+ '1.0.0',
76
+ Math.floor(Math.random() * 100),
77
+ Buffer32.random().toString(),
78
+ Math.floor(Math.random() * 100),
79
+ //TODO: add finalisedBlockHash
80
+ );
81
+ }
82
+
72
83
  validate(peerStatus: StatusMessage): boolean {
73
84
  // TODO: Validate other fields as well
74
85
  return this.compressedComponentsVersion === peerStatus.compressedComponentsVersion;
75
86
  }
87
+
88
+ equals(other: StatusMessage): boolean {
89
+ return (
90
+ this.compressedComponentsVersion === other.compressedComponentsVersion &&
91
+ this.latestBlockNumber === other.latestBlockNumber &&
92
+ this.latestBlockHash === other.latestBlockHash &&
93
+ this.finalisedBlockNumber === other.finalisedBlockNumber
94
+ );
95
+ }
76
96
  }
77
97
 
78
98
  /**
@@ -1,10 +1,12 @@
1
+ import { chunk } from '@aztec/foundation/collection';
1
2
  import type { P2PClientType } from '@aztec/stdlib/p2p';
2
- import { TxHash } from '@aztec/stdlib/tx';
3
+ import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
3
4
 
4
5
  import type { PeerId } from '@libp2p/interface';
5
6
 
6
7
  import type { MemPools } from '../../../mem_pools/interface.js';
7
8
  import type { ReqRespSubProtocolHandler } from '../interface.js';
9
+ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
8
10
 
9
11
  /**
10
12
  * We want to keep the logic of the req resp handler in this file, but we do not have a reference to the mempools here
@@ -12,18 +14,45 @@ import type { ReqRespSubProtocolHandler } from '../interface.js';
12
14
  *
13
15
  * Handler for tx requests
14
16
  * @param mempools - the mempools
15
- * @returns the tx response message
17
+ * @returns the Tx request handler
16
18
  */
17
19
  export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): ReqRespSubProtocolHandler {
18
20
  /**
19
21
  * Handler for tx requests
20
22
  * @param msg - the tx request message
21
23
  * @returns the tx response message
24
+ * @throws if msg is not a valid tx hash
22
25
  */
23
26
  return async (_peerId: PeerId, msg: Buffer) => {
24
- const txHash = TxHash.fromBuffer(msg);
25
- const foundTx = await mempools.txPool.getTxByHash(txHash);
26
- const buf = foundTx ? foundTx.toBuffer() : Buffer.alloc(0);
27
- return buf;
27
+ let txHashes: TxHashArray;
28
+ try {
29
+ txHashes = TxHashArray.fromBuffer(msg);
30
+ } catch (err: any) {
31
+ throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
32
+ }
33
+
34
+ try {
35
+ const txs = new TxArray(
36
+ ...(await Promise.all(txHashes.map(txHash => mempools.txPool.getTxByHash(txHash)))).filter(t => !!t),
37
+ );
38
+ return txs.toBuffer();
39
+ } catch (err: any) {
40
+ throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
41
+ }
28
42
  };
29
43
  }
44
+
45
+ /**
46
+ * Helper function to chunk an array of transaction hashes into chunks of a specified size.
47
+ * This is mainly used in ReqResp in order not to request too many transactions at once from the single peer.
48
+ *
49
+ * @param hashes - The array of transaction hashes to chunk.
50
+ * @param chunkSize - The size of each chunk. Default is 8. Reasoning:
51
+ * Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
52
+ * we define Q as max number of transactions per batch, the comment explains why we use 8.
53
+ */
54
+ //TODO: (mralj) chunk size should by default be 8, this is just temporary until the protocol is implemented correctly
55
+ //more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
56
+ export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
57
+ return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
58
+ }
@@ -22,6 +22,16 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
22
22
  quotaCount: 10,
23
23
  },
24
24
  },
25
+ [ReqRespSubProtocol.AUTH]: {
26
+ peerLimit: {
27
+ quotaTimeMs: 1000,
28
+ quotaCount: 5,
29
+ },
30
+ globalLimit: {
31
+ quotaTimeMs: 1000,
32
+ quotaCount: 10,
33
+ },
34
+ },
25
35
  [ReqRespSubProtocol.TX]: {
26
36
  peerLimit: {
27
37
  quotaTimeMs: 1000,
@@ -52,4 +62,14 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
52
62
  quotaCount: 10,
53
63
  },
54
64
  },
65
+ [ReqRespSubProtocol.BLOCK_TXS]: {
66
+ peerLimit: {
67
+ quotaTimeMs: 1000,
68
+ quotaCount: 10,
69
+ },
70
+ globalLimit: {
71
+ quotaTimeMs: 1000,
72
+ quotaCount: 200,
73
+ },
74
+ },
55
75
  };