@aztec/p2p 0.74.0 → 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2

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 (217) hide show
  1. package/dest/bootstrap/bootstrap.js +41 -29
  2. package/dest/client/factory.js +8 -10
  3. package/dest/client/index.js +0 -1
  4. package/dest/client/p2p_client.js +513 -507
  5. package/dest/config.js +44 -39
  6. package/dest/errors/reqresp.error.js +6 -10
  7. package/dest/index.js +0 -1
  8. package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -2
  9. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +64 -32
  10. package/dest/mem_pools/attestation_pool/index.js +0 -1
  11. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +22 -19
  12. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +22 -26
  13. package/dest/mem_pools/attestation_pool/mocks.js +10 -6
  14. package/dest/mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js +1 -2
  15. package/dest/mem_pools/epoch_proof_quote_pool/index.js +0 -1
  16. package/dest/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js +5 -4
  17. package/dest/mem_pools/epoch_proof_quote_pool/test_utils.js +2 -3
  18. package/dest/mem_pools/index.js +1 -2
  19. package/dest/mem_pools/instrumentation.js +37 -42
  20. package/dest/mem_pools/interface.js +3 -2
  21. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +127 -134
  22. package/dest/mem_pools/tx_pool/index.js +0 -1
  23. package/dest/mem_pools/tx_pool/memory_tx_pool.js +45 -43
  24. package/dest/mem_pools/tx_pool/priority.js +1 -3
  25. package/dest/mem_pools/tx_pool/tx_pool.js +3 -2
  26. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +107 -37
  27. package/dest/mocks/index.js +47 -38
  28. package/dest/msg_validators/attestation_validator/attestation_validator.js +3 -3
  29. package/dest/msg_validators/attestation_validator/index.js +0 -1
  30. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +2 -2
  31. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  32. package/dest/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.js +2 -2
  33. package/dest/msg_validators/epoch_proof_quote_validator/index.js +0 -1
  34. package/dest/msg_validators/index.js +0 -1
  35. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +9 -11
  36. package/dest/msg_validators/tx_validator/block_header_validator.js +17 -12
  37. package/dest/msg_validators/tx_validator/data_validator.js +41 -32
  38. package/dest/msg_validators/tx_validator/double_spend_validator.js +22 -14
  39. package/dest/msg_validators/tx_validator/index.js +0 -1
  40. package/dest/msg_validators/tx_validator/metadata_validator.js +29 -26
  41. package/dest/msg_validators/tx_validator/tx_proof_validator.js +17 -12
  42. package/dest/services/data_store.js +57 -57
  43. package/dest/services/discv5/discV5_service.js +31 -23
  44. package/dest/services/dummy_service.js +40 -58
  45. package/dest/services/encoding.js +10 -9
  46. package/dest/services/index.js +0 -1
  47. package/dest/services/libp2p/libp2p_service.js +709 -695
  48. package/dest/services/peer-manager/metrics.js +14 -7
  49. package/dest/services/peer-manager/peer_manager.js +340 -342
  50. package/dest/services/peer-manager/peer_scoring.js +20 -18
  51. package/dest/services/reqresp/config.js +4 -5
  52. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +35 -28
  53. package/dest/services/reqresp/connection-sampler/connection_sampler.js +60 -59
  54. package/dest/services/reqresp/index.js +1 -3
  55. package/dest/services/reqresp/interface.js +25 -30
  56. package/dest/services/reqresp/metrics.js +23 -10
  57. package/dest/services/reqresp/protocols/block.js +1 -2
  58. package/dest/services/reqresp/protocols/goodbye.js +35 -40
  59. package/dest/services/reqresp/protocols/index.js +1 -3
  60. package/dest/services/reqresp/protocols/ping.js +1 -3
  61. package/dest/services/reqresp/protocols/status.js +1 -3
  62. package/dest/services/reqresp/protocols/tx.js +5 -8
  63. package/dest/services/reqresp/rate-limiter/index.js +0 -1
  64. package/dest/services/reqresp/rate-limiter/rate_limiter.js +42 -36
  65. package/dest/services/reqresp/rate-limiter/rate_limits.js +16 -17
  66. package/dest/services/reqresp/reqresp.js +461 -395
  67. package/dest/services/reqresp/status.js +51 -0
  68. package/dest/services/service.js +3 -4
  69. package/dest/services/types.js +16 -23
  70. package/dest/util.js +23 -34
  71. package/package.json +8 -8
  72. package/src/client/p2p_client.ts +159 -125
  73. package/src/mem_pools/index.ts +3 -3
  74. package/src/mem_pools/instrumentation.ts +3 -2
  75. package/src/services/reqresp/interface.ts +11 -0
  76. package/src/services/reqresp/rate-limiter/rate_limiter.ts +3 -1
  77. package/src/services/reqresp/rate-limiter/rate_limits.ts +2 -2
  78. package/src/services/reqresp/reqresp.ts +111 -24
  79. package/src/services/reqresp/status.ts +59 -0
  80. package/dest/bootstrap/bootstrap.d.ts +0 -38
  81. package/dest/bootstrap/bootstrap.d.ts.map +0 -1
  82. package/dest/client/factory.d.ts +0 -19
  83. package/dest/client/factory.d.ts.map +0 -1
  84. package/dest/client/index.d.ts +0 -3
  85. package/dest/client/index.d.ts.map +0 -1
  86. package/dest/client/p2p_client.d.ts +0 -321
  87. package/dest/client/p2p_client.d.ts.map +0 -1
  88. package/dest/config.d.ts +0 -171
  89. package/dest/config.d.ts.map +0 -1
  90. package/dest/errors/reqresp.error.d.ts +0 -28
  91. package/dest/errors/reqresp.error.d.ts.map +0 -1
  92. package/dest/index.d.ts +0 -9
  93. package/dest/index.d.ts.map +0 -1
  94. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +0 -57
  95. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +0 -1
  96. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +0 -3
  97. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +0 -1
  98. package/dest/mem_pools/attestation_pool/index.d.ts +0 -3
  99. package/dest/mem_pools/attestation_pool/index.d.ts.map +0 -1
  100. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -22
  101. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  102. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -17
  103. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  104. package/dest/mem_pools/attestation_pool/mocks.d.ts +0 -18
  105. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +0 -1
  106. package/dest/mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.d.ts +0 -7
  107. package/dest/mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.d.ts.map +0 -1
  108. package/dest/mem_pools/epoch_proof_quote_pool/index.d.ts +0 -4
  109. package/dest/mem_pools/epoch_proof_quote_pool/index.d.ts.map +0 -1
  110. package/dest/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.d.ts +0 -12
  111. package/dest/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.d.ts.map +0 -1
  112. package/dest/mem_pools/epoch_proof_quote_pool/test_utils.d.ts +0 -8
  113. package/dest/mem_pools/epoch_proof_quote_pool/test_utils.d.ts.map +0 -1
  114. package/dest/mem_pools/index.d.ts +0 -5
  115. package/dest/mem_pools/index.d.ts.map +0 -1
  116. package/dest/mem_pools/instrumentation.d.ts +0 -31
  117. package/dest/mem_pools/instrumentation.d.ts.map +0 -1
  118. package/dest/mem_pools/interface.d.ts +0 -13
  119. package/dest/mem_pools/interface.d.ts.map +0 -1
  120. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -66
  121. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
  122. package/dest/mem_pools/tx_pool/index.d.ts +0 -4
  123. package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
  124. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
  125. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  126. package/dest/mem_pools/tx_pool/priority.d.ts +0 -8
  127. package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
  128. package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -66
  129. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
  130. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
  131. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
  132. package/dest/mocks/index.d.ts +0 -54
  133. package/dest/mocks/index.d.ts.map +0 -1
  134. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +0 -8
  135. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +0 -1
  136. package/dest/msg_validators/attestation_validator/index.d.ts +0 -2
  137. package/dest/msg_validators/attestation_validator/index.d.ts.map +0 -1
  138. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
  139. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  140. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  141. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  142. package/dest/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.d.ts +0 -8
  143. package/dest/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.d.ts.map +0 -1
  144. package/dest/msg_validators/epoch_proof_quote_validator/index.d.ts +0 -2
  145. package/dest/msg_validators/epoch_proof_quote_validator/index.d.ts.map +0 -1
  146. package/dest/msg_validators/index.d.ts +0 -4
  147. package/dest/msg_validators/index.d.ts.map +0 -1
  148. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +0 -7
  149. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +0 -1
  150. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +0 -11
  151. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +0 -1
  152. package/dest/msg_validators/tx_validator/data_validator.d.ts +0 -6
  153. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +0 -1
  154. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -12
  155. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +0 -1
  156. package/dest/msg_validators/tx_validator/index.d.ts +0 -7
  157. package/dest/msg_validators/tx_validator/index.d.ts.map +0 -1
  158. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +0 -10
  159. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +0 -1
  160. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +0 -8
  161. package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +0 -1
  162. package/dest/services/data_store.d.ts +0 -27
  163. package/dest/services/data_store.d.ts.map +0 -1
  164. package/dest/services/discv5/discV5_service.d.ts +0 -36
  165. package/dest/services/discv5/discV5_service.d.ts.map +0 -1
  166. package/dest/services/dummy_service.d.ts +0 -82
  167. package/dest/services/dummy_service.d.ts.map +0 -1
  168. package/dest/services/encoding.d.ts +0 -31
  169. package/dest/services/encoding.d.ts.map +0 -1
  170. package/dest/services/index.d.ts +0 -3
  171. package/dest/services/index.d.ts.map +0 -1
  172. package/dest/services/libp2p/libp2p_service.d.ts +0 -225
  173. package/dest/services/libp2p/libp2p_service.d.ts.map +0 -1
  174. package/dest/services/peer-manager/metrics.d.ts +0 -12
  175. package/dest/services/peer-manager/metrics.d.ts.map +0 -1
  176. package/dest/services/peer-manager/peer_manager.d.ts +0 -76
  177. package/dest/services/peer-manager/peer_manager.d.ts.map +0 -1
  178. package/dest/services/peer-manager/peer_scoring.d.ts +0 -28
  179. package/dest/services/peer-manager/peer_scoring.d.ts.map +0 -1
  180. package/dest/services/reqresp/config.d.ts +0 -16
  181. package/dest/services/reqresp/config.d.ts.map +0 -1
  182. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -45
  183. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
  184. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +0 -61
  185. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +0 -1
  186. package/dest/services/reqresp/index.d.ts +0 -6
  187. package/dest/services/reqresp/index.d.ts.map +0 -1
  188. package/dest/services/reqresp/interface.d.ts +0 -107
  189. package/dest/services/reqresp/interface.d.ts.map +0 -1
  190. package/dest/services/reqresp/metrics.d.ts +0 -15
  191. package/dest/services/reqresp/metrics.d.ts.map +0 -1
  192. package/dest/services/reqresp/protocols/block.d.ts +0 -4
  193. package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
  194. package/dest/services/reqresp/protocols/goodbye.d.ts +0 -51
  195. package/dest/services/reqresp/protocols/goodbye.d.ts.map +0 -1
  196. package/dest/services/reqresp/protocols/index.d.ts +0 -9
  197. package/dest/services/reqresp/protocols/index.d.ts.map +0 -1
  198. package/dest/services/reqresp/protocols/ping.d.ts +0 -9
  199. package/dest/services/reqresp/protocols/ping.d.ts.map +0 -1
  200. package/dest/services/reqresp/protocols/status.d.ts +0 -9
  201. package/dest/services/reqresp/protocols/status.d.ts.map +0 -1
  202. package/dest/services/reqresp/protocols/tx.d.ts +0 -13
  203. package/dest/services/reqresp/protocols/tx.d.ts.map +0 -1
  204. package/dest/services/reqresp/rate-limiter/index.d.ts +0 -2
  205. package/dest/services/reqresp/rate-limiter/index.d.ts.map +0 -1
  206. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +0 -102
  207. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +0 -1
  208. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +0 -3
  209. package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +0 -1
  210. package/dest/services/reqresp/reqresp.d.ts +0 -161
  211. package/dest/services/reqresp/reqresp.d.ts.map +0 -1
  212. package/dest/services/service.d.ts +0 -85
  213. package/dest/services/service.d.ts.map +0 -1
  214. package/dest/services/types.d.ts +0 -38
  215. package/dest/services/types.d.ts.map +0 -1
  216. package/dest/util.d.ts +0 -53
  217. package/dest/util.d.ts.map +0 -1
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The error codes for the ReqResp protocol
3
+ */ export var ReqRespStatus = /*#__PURE__*/ function(ReqRespStatus) {
4
+ ReqRespStatus[ReqRespStatus["SUCCESS"] = 0] = "SUCCESS";
5
+ ReqRespStatus[ReqRespStatus["RATE_LIMIT_EXCEEDED"] = 1] = "RATE_LIMIT_EXCEEDED";
6
+ ReqRespStatus[ReqRespStatus["BADLY_FORMED_REQUEST"] = 2] = "BADLY_FORMED_REQUEST";
7
+ ReqRespStatus[ReqRespStatus["UNKNOWN"] = 127] = "UNKNOWN";
8
+ return ReqRespStatus;
9
+ }({});
10
+ export class ReqRespStatusError extends Error {
11
+ /**
12
+ * The status code
13
+ */ status;
14
+ constructor(status){
15
+ super(`ReqResp Error: ${prettyPrintReqRespStatus(status)}`);
16
+ this.status = status;
17
+ }
18
+ }
19
+ /**
20
+ * Parse the status chunk
21
+ * @param chunk
22
+ * @returns
23
+ *
24
+ * @throws ReqRespStatusError if the chunk is not valid
25
+ */ export function parseStatusChunk(chunk) {
26
+ if (chunk.length !== 1) {
27
+ throw new ReqRespStatusError(127);
28
+ }
29
+ const status = chunk[0];
30
+ // Check if status is a valid ReqRespStatus value
31
+ if (!(status in ReqRespStatus)) {
32
+ throw new ReqRespStatusError(127);
33
+ }
34
+ return status;
35
+ }
36
+ /**
37
+ * Pretty print the ReqResp status
38
+ * @param status
39
+ * @returns
40
+ */ export function prettyPrintReqRespStatus(status) {
41
+ switch(status){
42
+ case 0:
43
+ return 'SUCCESS';
44
+ case 1:
45
+ return 'RATE_LIMIT_EXCEEDED';
46
+ case 2:
47
+ return 'BADLY_FORMED_REQUEST';
48
+ case 127:
49
+ return 'UNKNOWN';
50
+ }
51
+ }
@@ -1,6 +1,5 @@
1
- export var PeerDiscoveryState;
2
- (function (PeerDiscoveryState) {
1
+ export var PeerDiscoveryState = /*#__PURE__*/ function(PeerDiscoveryState) {
3
2
  PeerDiscoveryState["RUNNING"] = "running";
4
3
  PeerDiscoveryState["STOPPED"] = "stopped";
5
- })(PeerDiscoveryState || (PeerDiscoveryState = {}));
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXJ2aWNlcy9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVFBLE1BQU0sQ0FBTixJQUFZLGtCQUdYO0FBSEQsV0FBWSxrQkFBa0I7SUFDNUIseUNBQW1CLENBQUE7SUFDbkIseUNBQW1CLENBQUE7QUFDckIsQ0FBQyxFQUhXLGtCQUFrQixLQUFsQixrQkFBa0IsUUFHN0IifQ==
4
+ return PeerDiscoveryState;
5
+ }({});
@@ -1,43 +1,36 @@
1
1
  /***************************************************
2
2
  * Events
3
- ***************************************************/
4
- /**
3
+ ***************************************************/ /**
5
4
  * Events emitted from the libp2p node.
6
- */
7
- export var PeerEvent;
8
- (function (PeerEvent) {
5
+ */ export var PeerEvent = /*#__PURE__*/ function(PeerEvent) {
9
6
  PeerEvent["DISCOVERED"] = "peer:discovered";
10
7
  PeerEvent["CONNECTED"] = "peer:connect";
11
8
  PeerEvent["DISCONNECTED"] = "peer:disconnect";
12
- })(PeerEvent || (PeerEvent = {}));
9
+ return PeerEvent;
10
+ }({});
13
11
  /**
14
12
  * Events emitted from the Discv5 service.
15
- */
16
- export var Discv5Event;
17
- (function (Discv5Event) {
13
+ */ export var Discv5Event = /*#__PURE__*/ function(Discv5Event) {
18
14
  Discv5Event["DISCOVERED"] = "discovered";
19
15
  Discv5Event["ENR_ADDED"] = "enrAdded";
20
- })(Discv5Event || (Discv5Event = {}));
16
+ return Discv5Event;
17
+ }({});
21
18
  /**
22
19
  * Events emitted from the GossipSub protocol.
23
- */
24
- export var GossipSubEvent;
25
- (function (GossipSubEvent) {
20
+ */ export var GossipSubEvent = /*#__PURE__*/ function(GossipSubEvent) {
26
21
  GossipSubEvent["MESSAGE"] = "gossipsub:message";
27
- })(GossipSubEvent || (GossipSubEvent = {}));
22
+ return GossipSubEvent;
23
+ }({});
28
24
  /***************************************************
29
25
  * Types
30
- ***************************************************/
31
- /**
26
+ ***************************************************/ /**
32
27
  * Aztec network specific types
33
- */
34
- export const AZTEC_ENR_KEY = 'aztec_network';
35
- export var AztecENR;
36
- (function (AztecENR) {
28
+ */ export const AZTEC_ENR_KEY = 'aztec_network';
29
+ export var AztecENR = /*#__PURE__*/ function(AztecENR) {
37
30
  AztecENR[AztecENR["devnet"] = 1] = "devnet";
38
31
  AztecENR[AztecENR["testnet"] = 2] = "testnet";
39
32
  AztecENR[AztecENR["mainnet"] = 3] = "mainnet";
40
- })(AztecENR || (AztecENR = {}));
33
+ return AztecENR;
34
+ }({});
41
35
  // TODO: Make this an env var
42
- export const AZTEC_NET = AztecENR.devnet;
43
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VydmljZXMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O3FEQUVxRDtBQUVyRDs7R0FFRztBQUNILE1BQU0sQ0FBTixJQUFZLFNBSVg7QUFKRCxXQUFZLFNBQVM7SUFDbkIsMkNBQThCLENBQUE7SUFDOUIsdUNBQTBCLENBQUE7SUFDMUIsNkNBQWdDLENBQUE7QUFDbEMsQ0FBQyxFQUpXLFNBQVMsS0FBVCxTQUFTLFFBSXBCO0FBRUQ7O0dBRUc7QUFDSCxNQUFNLENBQU4sSUFBWSxXQUdYO0FBSEQsV0FBWSxXQUFXO0lBQ3JCLHdDQUF5QixDQUFBO0lBQ3pCLHFDQUFzQixDQUFBO0FBQ3hCLENBQUMsRUFIVyxXQUFXLEtBQVgsV0FBVyxRQUd0QjtBQUVEOztHQUVHO0FBQ0gsTUFBTSxDQUFOLElBQVksY0FFWDtBQUZELFdBQVksY0FBYztJQUN4QiwrQ0FBNkIsQ0FBQTtBQUMvQixDQUFDLEVBRlcsY0FBYyxLQUFkLGNBQWMsUUFFekI7QUFFRDs7cURBRXFEO0FBQ3JEOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sYUFBYSxHQUFHLGVBQWUsQ0FBQztBQUU3QyxNQUFNLENBQU4sSUFBWSxRQUlYO0FBSkQsV0FBWSxRQUFRO0lBQ2xCLDJDQUFhLENBQUE7SUFDYiw2Q0FBYyxDQUFBO0lBQ2QsNkNBQWMsQ0FBQTtBQUNoQixDQUFDLEVBSlcsUUFBUSxLQUFSLFFBQVEsUUFJbkI7QUFFRCw2QkFBNkI7QUFDN0IsTUFBTSxDQUFDLE1BQU0sU0FBUyxHQUFHLFFBQVEsQ0FBQyxNQUFNLENBQUMifQ==
36
+ export const AZTEC_NET = 1;
package/dest/util.js CHANGED
@@ -8,8 +8,7 @@ import { resolve } from 'dns/promises';
8
8
  * const udpAddr = '[2001:db8::1]:8080' -> /ip6/2001:db8::1/udp/8080
9
9
  * @param address - The address string to convert. Has to be in the format <addr>:<port>.
10
10
  * @param protocol - The protocol to use in the multiaddr string.
11
- * @returns A multiaddr compliant string. */
12
- export function convertToMultiaddr(address, protocol) {
11
+ * @returns A multiaddr compliant string. */ export function convertToMultiaddr(address, protocol) {
13
12
  const [addr, port] = splitAddressPort(address, false);
14
13
  const multiaddrPrefix = addressToMultiAddressType(addr);
15
14
  if (multiaddrPrefix === 'dns') {
@@ -20,8 +19,7 @@ export function convertToMultiaddr(address, protocol) {
20
19
  /**
21
20
  * Splits an <address>:<port> string into its components.
22
21
  * @returns The ip6 or ip4 address & port separately
23
- */
24
- export function splitAddressPort(address, allowEmptyAddress) {
22
+ */ export function splitAddressPort(address, allowEmptyAddress) {
25
23
  let addr;
26
24
  let port;
27
25
  if (address.startsWith('[')) {
@@ -31,20 +29,21 @@ export function splitAddressPort(address, allowEmptyAddress) {
31
29
  throw new Error(`Invalid IPv6 address format:${address}. Expected format: [<addr>]:<port>`);
32
30
  }
33
31
  [, addr, port] = match;
34
- }
35
- else {
32
+ } else {
36
33
  // IPv4 address
37
34
  [addr, port] = address.split(':');
38
- if ((!addr && !allowEmptyAddress) || !port) {
35
+ if (!addr && !allowEmptyAddress || !port) {
39
36
  throw new Error(`Invalid address format: ${address}. Expected format: <addr>:<port>`);
40
37
  }
41
38
  }
42
- return [addr, port];
39
+ return [
40
+ addr,
41
+ port
42
+ ];
43
43
  }
44
44
  /**
45
45
  * Queries the public IP address of the machine.
46
- */
47
- export async function getPublicIp() {
46
+ */ export async function getPublicIp() {
48
47
  const resp = await fetch('http://checkip.amazonaws.com/');
49
48
  const text = await resp.text();
50
49
  return text.trim();
@@ -58,8 +57,7 @@ export async function resolveAddressIfNecessary(address) {
58
57
  throw new Error(`Could not resolve address: ${addr}`);
59
58
  }
60
59
  return `${resolvedAddresses[0]}:${port}`;
61
- }
62
- else {
60
+ } else {
63
61
  return address;
64
62
  }
65
63
  }
@@ -68,23 +66,19 @@ export async function resolveAddressIfNecessary(address) {
68
66
  function addressToMultiAddressType(address) {
69
67
  if (address.includes(':')) {
70
68
  return 'ip6';
71
- }
72
- else if (address.match(/^[\d.]+$/)) {
69
+ } else if (address.match(/^[\d.]+$/)) {
73
70
  return 'ip4';
74
- }
75
- else {
71
+ } else {
76
72
  return 'dns';
77
73
  }
78
74
  }
79
75
  export async function configureP2PClientAddresses(_config) {
80
- const config = { ..._config };
81
- const { tcpAnnounceAddress: configTcpAnnounceAddress, udpAnnounceAddress: configUdpAnnounceAddress, queryForIp, } = config;
82
- config.tcpAnnounceAddress = configTcpAnnounceAddress
83
- ? await resolveAddressIfNecessary(configTcpAnnounceAddress)
84
- : undefined;
85
- config.udpAnnounceAddress = configUdpAnnounceAddress
86
- ? await resolveAddressIfNecessary(configUdpAnnounceAddress)
87
- : undefined;
76
+ const config = {
77
+ ..._config
78
+ };
79
+ const { tcpAnnounceAddress: configTcpAnnounceAddress, udpAnnounceAddress: configUdpAnnounceAddress, queryForIp } = config;
80
+ config.tcpAnnounceAddress = configTcpAnnounceAddress ? await resolveAddressIfNecessary(configTcpAnnounceAddress) : undefined;
81
+ config.udpAnnounceAddress = configUdpAnnounceAddress ? await resolveAddressIfNecessary(configUdpAnnounceAddress) : undefined;
88
82
  // create variable for re-use if needed
89
83
  let publicIp;
90
84
  // check if no announce IP was provided
@@ -94,8 +88,7 @@ export async function configureP2PClientAddresses(_config) {
94
88
  publicIp = await getPublicIp();
95
89
  const tcpAnnounceAddress = `${publicIp}:${splitTcpAnnounceAddress[1]}`;
96
90
  config.tcpAnnounceAddress = tcpAnnounceAddress;
97
- }
98
- else {
91
+ } else {
99
92
  throw new Error(`Invalid announceTcpAddress provided: ${configTcpAnnounceAddress}. Expected format: <addr>:<port>`);
100
93
  }
101
94
  }
@@ -104,9 +97,8 @@ export async function configureP2PClientAddresses(_config) {
104
97
  // If announceUdpAddress is not provided, use announceTcpAddress
105
98
  if (!queryForIp && config.tcpAnnounceAddress) {
106
99
  config.udpAnnounceAddress = config.tcpAnnounceAddress;
107
- }
108
- else if (queryForIp) {
109
- const udpPublicIp = publicIp || (await getPublicIp());
100
+ } else if (queryForIp) {
101
+ const udpPublicIp = publicIp || await getPublicIp();
110
102
  const udpAnnounceAddress = `${udpPublicIp}:${splitUdpAnnounceAddress[1]}`;
111
103
  config.udpAnnounceAddress = udpAnnounceAddress;
112
104
  }
@@ -120,8 +112,7 @@ export async function configureP2PClientAddresses(_config) {
120
112
  * 2. If not, check we have a peer id private key persisted in the node
121
113
  * 3. If not, create a new one, then persist it in the node
122
114
  *
123
- */
124
- export async function getPeerIdPrivateKey(config, store) {
115
+ */ export async function getPeerIdPrivateKey(config, store) {
125
116
  const peerIdPrivateKeySingleton = store.openSingleton('peerIdPrivateKey');
126
117
  if (config.peerIdPrivateKey) {
127
118
  await peerIdPrivateKeySingleton.set(config.peerIdPrivateKey);
@@ -140,12 +131,10 @@ export async function getPeerIdPrivateKey(config, store) {
140
131
  * Create a libp2p peer ID from the private key.
141
132
  * @param privateKey - peer ID private key as hex string
142
133
  * @returns The peer ID.
143
- */
144
- export async function createLibP2PPeerIdFromPrivateKey(privateKey) {
134
+ */ export async function createLibP2PPeerIdFromPrivateKey(privateKey) {
145
135
  if (!privateKey?.length) {
146
136
  throw new Error('No peer private key provided');
147
137
  }
148
138
  const asLibp2pPrivateKey = await unmarshalPrivateKey(new Uint8Array(Buffer.from(privateKey, 'hex')));
149
139
  return await createFromPrivKey(asLibp2pPrivateKey);
150
140
  }
151
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy91dGlsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLE9BQU8sRUFBRSxlQUFlLEVBQUUsaUJBQWlCLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUc5RixPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sY0FBYyxDQUFDO0FBY3ZDOzs7Ozs7OzZDQU82QztBQUM3QyxNQUFNLFVBQVUsa0JBQWtCLENBQUMsT0FBZSxFQUFFLFFBQXVCO0lBQ3pFLE1BQU0sQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLEdBQUcsZ0JBQWdCLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFDO0lBRXRELE1BQU0sZUFBZSxHQUFHLHlCQUF5QixDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ3hELElBQUksZUFBZSxLQUFLLEtBQUssRUFBRSxDQUFDO1FBQzlCLE1BQU0sSUFBSSxLQUFLLENBQUMsMkRBQTJELENBQUMsQ0FBQztJQUMvRSxDQUFDO0lBRUQsT0FBTyxJQUFJLGVBQWUsSU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QyxDQUFDLENBQy9DLENBQUM7SUFDRixPQUFPLE1BQU0saUJBQWlCLENBQUMsa0JBQWtCLENBQUMsQ0FBQztBQUNyRCxDQUFDIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/p2p",
3
- "version": "0.74.0",
3
+ "version": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -22,7 +22,7 @@
22
22
  "clean": "rm -rf ./dest .tsbuildinfo",
23
23
  "formatting": "run -T prettier --check ./src && run -T eslint ./src",
24
24
  "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
25
- "test": "HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16} RAYON_NUM_THREADS=${RAYON_NUM_THREADS:-4} NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
25
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
26
26
  "start": "node ./dest",
27
27
  "start:dev": "tsc-watch -p tsconfig.json --onSuccess 'yarn start'"
28
28
  },
@@ -63,12 +63,12 @@
63
63
  ]
64
64
  },
65
65
  "dependencies": {
66
- "@aztec/circuit-types": "0.74.0",
67
- "@aztec/circuits.js": "0.74.0",
68
- "@aztec/epoch-cache": "0.74.0",
69
- "@aztec/foundation": "0.74.0",
70
- "@aztec/kv-store": "0.74.0",
71
- "@aztec/telemetry-client": "0.74.0",
66
+ "@aztec/circuit-types": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
67
+ "@aztec/circuits.js": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
68
+ "@aztec/epoch-cache": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
69
+ "@aztec/foundation": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
70
+ "@aztec/kv-store": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
71
+ "@aztec/telemetry-client": "0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2",
72
72
  "@chainsafe/discv5": "9.0.0",
73
73
  "@chainsafe/enr": "3.0.0",
74
74
  "@chainsafe/libp2p-gossipsub": "13.0.0",
@@ -10,6 +10,7 @@ import {
10
10
  type P2PApi,
11
11
  type P2PClientType,
12
12
  type PeerInfo,
13
+ type ProverCoordination,
13
14
  type Tx,
14
15
  type TxHash,
15
16
  } from '@aztec/circuit-types';
@@ -62,130 +63,131 @@ export interface P2PSyncState {
62
63
  /**
63
64
  * Interface of a P2P client.
64
65
  **/
65
- export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApi<T> & {
66
- /**
67
- * Broadcasts a block proposal to other peers.
68
- *
69
- * @param proposal - the block proposal
70
- */
71
- broadcastProposal(proposal: BlockProposal): void;
72
-
73
- /**
74
- * Queries the EpochProofQuote pool for quotes for the given epoch
75
- *
76
- * @param epoch - the epoch to query
77
- * @returns EpochProofQuotes
78
- */
79
- getEpochProofQuotes(epoch: bigint): Promise<EpochProofQuote[]>;
80
-
81
- /**
82
- * Adds an EpochProofQuote to the pool and broadcasts an EpochProofQuote to other peers.
83
- *
84
- * @param quote - the quote to broadcast
85
- */
86
- addEpochProofQuote(quote: EpochProofQuote): Promise<void>;
87
-
88
- /**
89
- * Registers a callback from the validator client that determines how to behave when
90
- * foreign block proposals are received
91
- *
92
- * @param handler - A function taking a received block proposal and producing an attestation
93
- */
94
- // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
95
- // ^ This pattern is not my favorite (md)
96
- registerBlockProposalHandler(handler: (block: BlockProposal) => Promise<BlockAttestation | undefined>): void;
97
-
98
- /**
99
- * Request a list of transactions from another peer by their tx hashes.
100
- * @param txHashes - Hashes of the txs to query.
101
- * @returns A list of transactions or undefined if the transactions are not found.
102
- */
103
- requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
104
-
105
- /**
106
- * Request a transaction from another peer by its tx hash.
107
- * @param txHash - Hash of the tx to query.
108
- */
109
- requestTxByHash(txHash: TxHash): Promise<Tx | undefined>;
110
-
111
- /**
112
- * Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers.
113
- * @param tx - The transaction.
114
- **/
115
- sendTx(tx: Tx): Promise<void>;
116
-
117
- /**
118
- * Deletes 'txs' from the pool, given hashes.
119
- * NOT used if we use sendTx as reconcileTxPool will handle this.
120
- * @param txHashes - Hashes to check.
121
- **/
122
- deleteTxs(txHashes: TxHash[]): Promise<void>;
123
-
124
- /**
125
- * Returns a transaction in the transaction pool by its hash.
126
- * @param txHash - Hash of tx to return.
127
- * @returns A single tx or undefined.
128
- */
129
- getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined>;
130
-
131
- /**
132
- * Returns a transaction in the transaction pool by its hash, requesting it from the network if it is not found.
133
- * @param txHash - Hash of tx to return.
134
- * @returns A single tx or undefined.
135
- */
136
- getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
137
-
138
- /**
139
- * Returns an archived transaction from the transaction pool by its hash.
140
- * @param txHash - Hash of tx to return.
141
- * @returns A single tx or undefined.
142
- */
143
- getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
144
-
145
- /**
146
- * Returns whether the given tx hash is flagged as pending or mined.
147
- * @param txHash - Hash of the tx to query.
148
- * @returns Pending or mined depending on its status, or undefined if not found.
149
- */
150
- getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
151
-
152
- /** Returns an iterator over pending txs on the mempool. */
153
- iteratePendingTxs(): AsyncIterableIterator<Tx>;
154
-
155
- /** Returns the number of pending txs in the mempool. */
156
- getPendingTxCount(): Promise<number>;
157
-
158
- /**
159
- * Starts the p2p client.
160
- * @returns A promise signalling the completion of the block sync.
161
- */
162
- start(): Promise<void>;
163
-
164
- /**
165
- * Stops the p2p client.
166
- * @returns A promise signalling the completion of the stop process.
167
- */
168
- stop(): Promise<void>;
169
-
170
- /**
171
- * Indicates if the p2p client is ready for transaction submission.
172
- * @returns A boolean flag indicating readiness.
173
- */
174
- isReady(): boolean;
175
-
176
- /**
177
- * Returns the current status of the p2p client.
178
- */
179
- getStatus(): Promise<P2PSyncState>;
180
-
181
- /**
182
- * Returns the ENR of this node, if any.
183
- */
184
- getEnr(): ENR | undefined;
185
-
186
- /** Identifies a p2p client. */
187
- isP2PClient(): true;
188
- };
66
+ export type P2P<T extends P2PClientType = P2PClientType.Full> = ProverCoordination &
67
+ P2PApi<T> & {
68
+ /**
69
+ * Broadcasts a block proposal to other peers.
70
+ *
71
+ * @param proposal - the block proposal
72
+ */
73
+ broadcastProposal(proposal: BlockProposal): void;
74
+
75
+ /**
76
+ * Queries the EpochProofQuote pool for quotes for the given epoch
77
+ *
78
+ * @param epoch - the epoch to query
79
+ * @returns EpochProofQuotes
80
+ */
81
+ getEpochProofQuotes(epoch: bigint): Promise<EpochProofQuote[]>;
82
+
83
+ /**
84
+ * Adds an EpochProofQuote to the pool and broadcasts an EpochProofQuote to other peers.
85
+ *
86
+ * @param quote - the quote to broadcast
87
+ */
88
+ addEpochProofQuote(quote: EpochProofQuote): Promise<void>;
89
+
90
+ /**
91
+ * Registers a callback from the validator client that determines how to behave when
92
+ * foreign block proposals are received
93
+ *
94
+ * @param handler - A function taking a received block proposal and producing an attestation
95
+ */
96
+ // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
97
+ // ^ This pattern is not my favorite (md)
98
+ registerBlockProposalHandler(handler: (block: BlockProposal) => Promise<BlockAttestation | undefined>): void;
99
+
100
+ /**
101
+ * Request a list of transactions from another peer by their tx hashes.
102
+ * @param txHashes - Hashes of the txs to query.
103
+ * @returns A list of transactions or undefined if the transactions are not found.
104
+ */
105
+ requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
106
+
107
+ /**
108
+ * Request a transaction from another peer by its tx hash.
109
+ * @param txHash - Hash of the tx to query.
110
+ */
111
+ requestTxByHash(txHash: TxHash): Promise<Tx | undefined>;
112
+
113
+ /**
114
+ * Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers.
115
+ * @param tx - The transaction.
116
+ **/
117
+ sendTx(tx: Tx): Promise<void>;
118
+
119
+ /**
120
+ * Deletes 'txs' from the pool, given hashes.
121
+ * NOT used if we use sendTx as reconcileTxPool will handle this.
122
+ * @param txHashes - Hashes to check.
123
+ **/
124
+ deleteTxs(txHashes: TxHash[]): Promise<void>;
125
+
126
+ /**
127
+ * Returns a transaction in the transaction pool by its hash.
128
+ * @param txHash - Hash of tx to return.
129
+ * @returns A single tx or undefined.
130
+ */
131
+ getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined>;
132
+
133
+ /**
134
+ * Returns a transaction in the transaction pool by its hash, requesting it from the network if it is not found.
135
+ * @param txHash - Hash of tx to return.
136
+ * @returns A single tx or undefined.
137
+ */
138
+ getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
139
+
140
+ /**
141
+ * Returns an archived transaction from the transaction pool by its hash.
142
+ * @param txHash - Hash of tx to return.
143
+ * @returns A single tx or undefined.
144
+ */
145
+ getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
146
+
147
+ /**
148
+ * Returns whether the given tx hash is flagged as pending or mined.
149
+ * @param txHash - Hash of the tx to query.
150
+ * @returns Pending or mined depending on its status, or undefined if not found.
151
+ */
152
+ getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
153
+
154
+ /** Returns an iterator over pending txs on the mempool. */
155
+ iteratePendingTxs(): AsyncIterableIterator<Tx>;
156
+
157
+ /** Returns the number of pending txs in the mempool. */
158
+ getPendingTxCount(): Promise<number>;
159
+
160
+ /**
161
+ * Starts the p2p client.
162
+ * @returns A promise signalling the completion of the block sync.
163
+ */
164
+ start(): Promise<void>;
165
+
166
+ /**
167
+ * Stops the p2p client.
168
+ * @returns A promise signalling the completion of the stop process.
169
+ */
170
+ stop(): Promise<void>;
171
+
172
+ /**
173
+ * Indicates if the p2p client is ready for transaction submission.
174
+ * @returns A boolean flag indicating readiness.
175
+ */
176
+ isReady(): boolean;
177
+
178
+ /**
179
+ * Returns the current status of the p2p client.
180
+ */
181
+ getStatus(): Promise<P2PSyncState>;
182
+
183
+ /**
184
+ * Returns the ENR of this node, if any.
185
+ */
186
+ getEnr(): ENR | undefined;
187
+
188
+ /** Identifies a p2p client. */
189
+ isP2PClient(): true;
190
+ };
189
191
 
190
192
  /**
191
193
  * The P2P client implementation.
@@ -467,6 +469,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
467
469
  return tx;
468
470
  }
469
471
 
472
+ /**
473
+ * Uses the batched Request Response protocol to request a set of transactions from the network.
474
+ */
475
+ public async requestTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
476
+ const txs = (await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes)) ?? [];
477
+ await this.txPool.addTxs(txs);
478
+ const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
479
+ this.log.debug(`Received batched txs ${txHashesStr} (${txs.length} / ${txHashes.length}}) from peers`);
480
+ return txs as Tx[];
481
+ }
482
+
470
483
  public getPendingTxs(): Promise<Tx[]> {
471
484
  return Promise.resolve(this.getTxs('pending'));
472
485
  }
@@ -529,6 +542,27 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
529
542
  return this.requestTxByHash(txHash);
530
543
  }
531
544
 
545
+ /**
546
+ * Returns transactions in the transaction pool by hash.
547
+ * If a transaction is not in the pool, it will be requested from the network.
548
+ * @param txHashes - Hashes of the transactions to look for.
549
+ * @returns The txs found, not necessarily on the same order as the hashes.
550
+ */
551
+ async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
552
+ const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
553
+ const missingTxHashes = txs
554
+ .map((tx, index) => [tx, index] as const)
555
+ .filter(([tx, _index]) => !tx)
556
+ .map(([_tx, index]) => txHashes[index]);
557
+
558
+ if (missingTxHashes.length === 0) {
559
+ return txs as Tx[];
560
+ }
561
+
562
+ const missingTxs = await this.requestTxsByHash(missingTxHashes);
563
+ return txs.filter((tx): tx is Tx => !!tx).concat(missingTxs);
564
+ }
565
+
532
566
  /**
533
567
  * Returns an archived transaction in the transaction pool by its hash.
534
568
  * @param txHash - Hash of the archived transaction to look for.
@@ -662,7 +696,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
662
696
  blocks.map(async block => this.synchedBlockHashes.set(block.number, (await block.hash()).toString())),
663
697
  );
664
698
  await this.synchedLatestBlockNumber.set(lastBlockNum);
665
- this.log.debug(`Synched to latest block ${lastBlockNum}`);
699
+ this.log.verbose(`Synched to latest block ${lastBlockNum}`);
666
700
  await this.startServiceIfSynched();
667
701
  }
668
702
 
@@ -1,4 +1,4 @@
1
- export { TxPool } from './tx_pool/tx_pool.js';
2
- export { AttestationPool } from './attestation_pool/attestation_pool.js';
3
- export { EpochProofQuotePool } from './epoch_proof_quote_pool/epoch_proof_quote_pool.js';
1
+ export type { TxPool } from './tx_pool/tx_pool.js';
2
+ export type { AttestationPool } from './attestation_pool/attestation_pool.js';
3
+ export type { EpochProofQuotePool } from './epoch_proof_quote_pool/epoch_proof_quote_pool.js';
4
4
  export { type MemPools } from './interface.js';
@@ -5,6 +5,7 @@ import {
5
5
  LmdbMetrics,
6
6
  type LmdbStatsCallback,
7
7
  Metrics,
8
+ type MetricsType,
8
9
  type TelemetryClient,
9
10
  type UpDownCounter,
10
11
  } from '@aztec/telemetry-client';
@@ -16,8 +17,8 @@ export enum PoolName {
16
17
  }
17
18
 
18
19
  type MetricsLabels = {
19
- objectInMempool: Metrics;
20
- objectSize: Metrics;
20
+ objectInMempool: MetricsType;
21
+ objectSize: MetricsType;
21
22
  };
22
23
 
23
24
  /**