@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
@@ -6,10 +6,14 @@ function _ts_decorate(decorators, target, key, desc) {
6
6
  }
7
7
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
8
8
  import { createLogger } from '@aztec/foundation/log';
9
+ import { DateProvider } from '@aztec/foundation/timer';
10
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
11
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
9
12
  import { Attributes, TraceableL2BlockStream, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
10
13
  import { getP2PDefaultConfig } from '../config.js';
11
14
  import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
12
- import { TxCollector } from '../services/tx_collector.js';
15
+ import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
16
+ import { TxProvider } from '../services/tx_provider.js';
13
17
  import { P2PClientState } from './interface.js';
14
18
  /**
15
19
  * The P2P client implementation.
@@ -17,6 +21,8 @@ import { P2PClientState } from './interface.js';
17
21
  store;
18
22
  l2BlockSource;
19
23
  p2pService;
24
+ txCollection;
25
+ _dateProvider;
20
26
  telemetry;
21
27
  log;
22
28
  /** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */ runningPromise;
@@ -35,6 +41,8 @@ import { P2PClientState } from './interface.js';
35
41
  attestationPool;
36
42
  config;
37
43
  blockStream;
44
+ txProvider;
45
+ validatorAddresses;
38
46
  /**
39
47
  * In-memory P2P client constructor.
40
48
  * @param store - The client's instance of the KV store.
@@ -42,20 +50,29 @@ import { P2PClientState } from './interface.js';
42
50
  * @param txPool - The client's instance of a transaction pool. Defaults to in-memory implementation.
43
51
  * @param p2pService - The concrete instance of p2p networking to use.
44
52
  * @param log - A logger.
45
- */ constructor(_clientType, store, l2BlockSource, mempools, p2pService, config = {}, telemetry = getTelemetryClient(), log = createLogger('p2p')){
46
- super(telemetry, 'P2PClient'), this.store = store, this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.telemetry = telemetry, this.log = log, this.currentState = P2PClientState.IDLE, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1, this.finalizedBlockNumberAtStart = -1;
53
+ */ constructor(_clientType, store, l2BlockSource, mempools, p2pService, txCollection, config = {}, _dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('p2p')){
54
+ super(telemetry, 'P2PClient'), this.store = store, this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.txCollection = txCollection, this._dateProvider = _dateProvider, this.telemetry = telemetry, this.log = log, this.currentState = P2PClientState.IDLE, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1, this.finalizedBlockNumberAtStart = -1, this.validatorAddresses = [];
47
55
  this.config = {
48
56
  ...getP2PDefaultConfig(),
49
57
  ...config
50
58
  };
51
59
  this.txPool = mempools.txPool;
52
60
  this.attestationPool = mempools.attestationPool;
61
+ this.txProvider = new TxProvider(this.txCollection, this.txPool, this, this.log.createChild('tx-provider'), this.telemetry);
53
62
  // Default to collecting all txs when we see a valid proposal
54
- // This can be overridden by the validator client to attest, and it will call collectForBlockProposal on its own
55
- const txCollector = new TxCollector(this, this.log);
63
+ // This can be overridden by the validator client to attest, and it will call getTxsForBlockProposal on its own
64
+ // TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
65
+ // validator-client code into here so we can validate a proposal is reasonable.
56
66
  this.registerBlockProposalHandler(async (block, sender)=>{
57
67
  this.log.debug(`Received block proposal from ${sender.toString()}`);
58
- await txCollector.collectForBlockProposal(block, sender);
68
+ // TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
69
+ const constants = this.txCollection.getConstants();
70
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(block.slotNumber.toBigInt() + 1n, constants));
71
+ const deadline = new Date(nextSlotTimestampSeconds * 1000);
72
+ await this.txProvider.getTxsForBlockProposal(block, {
73
+ pinnedPeer: sender,
74
+ deadline
75
+ });
59
76
  return undefined;
60
77
  });
61
78
  // REFACTOR: Try replacing these with an L2TipsStore
@@ -65,12 +82,21 @@ import { P2PClientState } from './interface.js';
65
82
  this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
66
83
  this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
67
84
  }
85
+ registerThisValidatorAddresses(addresses) {
86
+ this.validatorAddresses = [
87
+ ...addresses
88
+ ];
89
+ this.p2pService.registerThisValidatorAddresses(this.validatorAddresses);
90
+ }
68
91
  clear() {
69
92
  return this.store.clear();
70
93
  }
71
94
  isP2PClient() {
72
95
  return true;
73
96
  }
97
+ getTxProvider() {
98
+ return this.txProvider;
99
+ }
74
100
  getPeers(includePending) {
75
101
  return Promise.resolve(this.p2pService.getPeers(includePending));
76
102
  }
@@ -142,11 +168,13 @@ import { P2PClientState } from './interface.js';
142
168
  case 'chain-proven':
143
169
  {
144
170
  await this.setBlockHash(event.block);
171
+ this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
145
172
  await this.synchedProvenBlockNumber.set(event.block.number);
146
173
  break;
147
174
  }
148
175
  case 'chain-pruned':
149
176
  await this.setBlockHash(event.block);
177
+ this.txCollection.stopCollectingForBlocksAfter(event.block.number);
150
178
  await this.handlePruneL2Blocks(event.block.number);
151
179
  break;
152
180
  default:
@@ -218,8 +246,12 @@ import { P2PClientState } from './interface.js';
218
246
  });
219
247
  }
220
248
  this.blockStream.start();
249
+ await this.txCollection.start();
221
250
  return this.syncPromise;
222
251
  }
252
+ addReqRespSubProtocol(subProtocol, handler, validator) {
253
+ return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
254
+ }
223
255
  initBlockStream(startingBlock) {
224
256
  if (!this.blockStream) {
225
257
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
@@ -235,6 +267,8 @@ import { P2PClientState } from './interface.js';
235
267
  * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
236
268
  */ async stop() {
237
269
  this.log.debug('Stopping p2p client...');
270
+ await tryStop(this.txCollection);
271
+ this.log.debug('Stopped tx collection service');
238
272
  await this.p2pService.stop();
239
273
  this.log.debug('Stopped p2p service');
240
274
  await this.blockStream?.stop();
@@ -263,39 +297,19 @@ import { P2PClientState } from './interface.js';
263
297
  this.p2pService.registerBlockReceivedCallback(handler);
264
298
  }
265
299
  /**
266
- * Uses the Request Response protocol to request a transaction from the network.
267
- *
268
- * If the underlying request response protocol fails, then we return undefined.
269
- * If it succeeds then we add the transaction to our transaction pool and return.
270
- *
271
- * @param txHash - The hash of the transaction to request.
272
- * @returns A promise that resolves to a transaction or undefined.
273
- */ async requestTxByHash(txHash) {
274
- const tx = await this.p2pService.sendRequest(ReqRespSubProtocol.TX, txHash);
275
- if (tx) {
276
- this.log.debug(`Received tx ${txHash.toString()} from peer`);
277
- await this.txPool.addTxs([
278
- tx
279
- ]);
280
- } else {
281
- this.log.debug(`Failed to receive tx ${txHash.toString()} from peer`);
282
- }
283
- return tx;
284
- }
285
- /**
286
300
  * Uses the batched Request Response protocol to request a set of transactions from the network.
287
301
  */ async requestTxsByHash(txHashes, pinnedPeerId) {
288
302
  const timeoutMs = 8000; // Longer timeout for now
289
- const maxPeers = Math.min(Math.ceil(txHashes.length / 3), 10);
290
303
  const maxRetryAttempts = 10; // Keep retrying within the timeout
291
- const txs = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes, pinnedPeerId, timeoutMs, maxPeers, maxRetryAttempts);
292
- // Some transactions may return undefined, so we filter them out
293
- const filteredTxs = txs.filter((tx)=>!!tx);
294
- if (filteredTxs.length > 0) {
295
- await this.txPool.addTxs(filteredTxs);
304
+ const requests = chunkTxHashesRequest(txHashes);
305
+ const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
306
+ const txBatches = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, requests, pinnedPeerId, timeoutMs, maxPeers, maxRetryAttempts);
307
+ const txs = txBatches.flat();
308
+ if (txs.length > 0) {
309
+ await this.txPool.addTxs(txs);
296
310
  }
297
311
  const txHashesStr = txHashes.map((tx)=>tx.toString()).join(', ');
298
- this.log.debug(`Requested txs ${txHashesStr} (${filteredTxs.length} / ${txHashes.length}) from peers`);
312
+ this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
299
313
  // We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
300
314
  return txs;
301
315
  }
@@ -378,18 +392,6 @@ import { P2PClientState } from './interface.js';
378
392
  return this.txPool.hasTxs(txHashes);
379
393
  }
380
394
  /**
381
- * Returns a transaction in the transaction pool by its hash.
382
- * If the transaction is not in the pool, it will be requested from the network.
383
- * @param txHash - Hash of the transaction to look for in the pool.
384
- * @returns A single tx or undefined.
385
- */ async getTxByHash(txHash) {
386
- const tx = await this.txPool.getTxByHash(txHash);
387
- if (tx) {
388
- return tx;
389
- }
390
- return this.requestTxByHash(txHash);
391
- }
392
- /**
393
395
  * Returns transactions in the transaction pool by hash.
394
396
  * If a transaction is not in the pool, it will be requested from the network.
395
397
  * @param txHashes - Hashes of the transactions to look for.
@@ -404,26 +406,26 @@ import { P2PClientState } from './interface.js';
404
406
  return txs;
405
407
  }
406
408
  const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
407
- const fetchedMissingTxs = missingTxs.filter((tx)=>!!tx);
408
409
  // TODO: optimize
409
410
  // Merge the found txs in order
410
- const mergingTxsPromises = txHashes.map(async (txHash)=>{
411
+ const mergingTxs = txHashes.map((txHash)=>{
411
412
  // Is it in the txs list from the mempool?
412
413
  for (const tx of txs){
413
- if (tx !== undefined && (await tx.getTxHash()).equals(txHash)) {
414
+ if (tx !== undefined && tx.getTxHash().equals(txHash)) {
414
415
  return tx;
415
416
  }
416
417
  }
417
418
  // Is it in the fetched missing txs?
418
- for (const tx of fetchedMissingTxs){
419
- if (tx !== undefined && (await tx.getTxHash()).equals(txHash)) {
419
+ // Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
420
+ for (const tx of missingTxs){
421
+ if (tx.getTxHash().equals(txHash)) {
420
422
  return tx;
421
423
  }
422
424
  }
423
425
  // Otherwise return undefined
424
426
  return undefined;
425
427
  });
426
- return await Promise.all(mergingTxsPromises);
428
+ return mergingTxs;
427
429
  }
428
430
  /**
429
431
  * Returns an archived transaction in the transaction pool by its hash.
@@ -542,7 +544,7 @@ import { P2PClientState } from './interface.js';
542
544
  return Promise.resolve();
543
545
  }
544
546
  await this.markTxsAsMinedFromBlocks(blocks.map((b)=>b.block));
545
- void this.requestMissingTxsFromUnprovenBlocks(blocks.map((b)=>b.block));
547
+ await this.startCollectingMissingTxs(blocks.map((b)=>b.block));
546
548
  const lastBlock = blocks.at(-1).block;
547
549
  await Promise.all(blocks.map(async (block)=>this.setBlockHash({
548
550
  number: block.block.number,
@@ -553,23 +555,30 @@ import { P2PClientState } from './interface.js';
553
555
  this.log.verbose(`Synched to latest block ${lastBlock.number}`);
554
556
  await this.startServiceIfSynched();
555
557
  }
556
- /** Request txs for unproven blocks so the prover node has more chances to get them. */ async requestMissingTxsFromUnprovenBlocks(blocks) {
558
+ /** Request txs for unproven blocks so the prover node has more chances to get them. */ async startCollectingMissingTxs(blocks) {
557
559
  try {
558
- const provenBlockNumber = Math.max(await this.getSyncedProvenBlockNum(), this.provenBlockNumberAtStart);
560
+ // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
561
+ // be much lower than the actual one, and it does not update until the pending chain is
562
+ // fully synced. This could lead to a ton of tx collection requests for blocks that
563
+ // are already proven, but the archiver has not yet updated its state. Until this is properly
564
+ // fixed, it is mitigated by the expiration date of collection requests, which depends on
565
+ // the slot number of the block.
566
+ const provenBlockNumber = await this.l2BlockSource.getProvenBlockNumber();
559
567
  const unprovenBlocks = blocks.filter((block)=>block.number > provenBlockNumber);
560
- const txHashes = unprovenBlocks.flatMap((block)=>block.body.txEffects.map((txEffect)=>txEffect.txHash));
561
- const missingTxHashes = await this.txPool.hasTxs(txHashes).then((availability)=>txHashes.filter((_, index)=>!availability[index]));
562
- if (missingTxHashes.length > 0) {
563
- this.log.verbose(`Requesting ${missingTxHashes.length} missing txs from peers for ${unprovenBlocks.length} unproven mined blocks`, {
564
- missingTxHashes,
565
- unprovenBlockNumbers: unprovenBlocks.map((block)=>block.number)
566
- });
567
- await this.requestTxsByHash(missingTxHashes, undefined);
568
+ for (const block of unprovenBlocks){
569
+ const txHashes = block.body.txEffects.map((txEffect)=>txEffect.txHash);
570
+ const missingTxHashes = await this.txPool.hasTxs(txHashes).then((availability)=>txHashes.filter((_, index)=>!availability[index]));
571
+ if (missingTxHashes.length > 0) {
572
+ this.log.verbose(`Starting collection of ${missingTxHashes.length} missing txs for unproven mined block ${block.number}`, {
573
+ missingTxHashes,
574
+ blockNumber: block.number,
575
+ blockHash: await block.hash().then((h)=>h.toString())
576
+ });
577
+ this.txCollection.startCollecting(block, missingTxHashes);
578
+ }
568
579
  }
569
580
  } catch (err) {
570
- this.log.error(`Error requesting missing txs from unproven blocks`, err, {
571
- blocks: blocks.map((block)=>block.number)
572
- });
581
+ this.log.error(`Error while starting collection of missing txs for unproven blocks`, err);
573
582
  }
574
583
  }
575
584
  /**
@@ -593,20 +602,13 @@ import { P2PClientState } from './interface.js';
593
602
  * Updates the tx pool after a chain prune.
594
603
  * @param latestBlock - The block number the chain was pruned to.
595
604
  */ async handlePruneL2Blocks(latestBlock) {
596
- // NOTE: temporary fix for alphanet, deleting ALL txs that were in the epoch from the pool #13723
597
- // TODO: undo once fixed: #13770
598
605
  const txsToDelete = new Map();
599
606
  const minedTxs = await this.txPool.getMinedTxHashes();
600
- for (const [txHash, blockNumber] of minedTxs){
601
- if (blockNumber > latestBlock) {
602
- txsToDelete.set(txHash.toString(), txHash);
603
- }
604
- }
605
607
  // Find transactions that reference pruned blocks in their historical header
606
608
  for (const tx of (await this.txPool.getAllTxs())){
607
609
  // every tx that's been generated against a block that has now been pruned is no longer valid
608
610
  if (tx.data.constants.historicalHeader.globalVariables.blockNumber > latestBlock) {
609
- const txHash = await tx.getTxHash();
611
+ const txHash = tx.getTxHash();
610
612
  txsToDelete.set(txHash.toString(), txHash);
611
613
  }
612
614
  }
@@ -617,16 +619,14 @@ import { P2PClientState } from './interface.js';
617
619
  // move back to pending the txs that were reorged out of the chain
618
620
  // NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
619
621
  // (see this.keepProvenTxsFor)
620
- // NOTE: given current fix for alphanet, the code below is redundant as all these txs will be deleted.
621
- // TODO: bring back once fixed: #13770
622
- // const txsToMoveToPending: TxHash[] = [];
623
- // for (const [txHash, blockNumber] of minedTxs) {
624
- // if (blockNumber > latestBlock) {
625
- // txsToMoveToPending.push(txHash);
626
- // }
627
- // }
628
- // this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
629
- // await this.txPool.markMinedAsPending(txsToMoveToPending);
622
+ const txsToMoveToPending = [];
623
+ for (const [txHash, blockNumber] of minedTxs){
624
+ if (blockNumber > latestBlock) {
625
+ txsToMoveToPending.push(txHash);
626
+ }
627
+ }
628
+ this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
629
+ await this.txPool.markMinedAsPending(txsToMoveToPending);
630
630
  await this.synchedLatestBlockNumber.set(latestBlock);
631
631
  // no need to update block hashes, as they will be updated as new blocks are added
632
632
  }
@@ -667,6 +667,9 @@ import { P2PClientState } from './interface.js';
667
667
  */ markTxsAsNonEvictable(txHashes) {
668
668
  return this.txPool.markTxsAsNonEvictable(txHashes);
669
669
  }
670
+ handleAuthRequestFromPeer(authRequest, peerId) {
671
+ return this.p2pService.handleAuthRequestFromPeer(authRequest, peerId);
672
+ }
670
673
  }
671
674
  _ts_decorate([
672
675
  trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
package/dest/config.d.ts CHANGED
@@ -2,10 +2,11 @@ import { type ConfigMappingsType, SecretValue } from '@aztec/foundation/config';
2
2
  import { type DataStoreConfig } from '@aztec/kv-store/config';
3
3
  import { type AllowedElement, type ChainConfig } from '@aztec/stdlib/config';
4
4
  import { type P2PReqRespConfig } from './services/reqresp/config.js';
5
+ import { type TxCollectionConfig } from './services/tx_collection/config.js';
5
6
  /**
6
7
  * P2P client configuration values.
7
8
  */
8
- export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
9
+ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionConfig {
9
10
  /** A flag dictating whether the P2P subsystem should be enabled. */
10
11
  p2pEnabled: boolean;
11
12
  /** The frequency in which to check for new L2 blocks. */
@@ -74,6 +75,8 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
74
75
  trustedPeers: string[];
75
76
  /** A list of private peers. */
76
77
  privatePeers: string[];
78
+ /** A list of preferred peers. */
79
+ preferredPeers: string[];
77
80
  /** The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKB. */
78
81
  p2pStoreMapSizeKb?: number;
79
82
  /** Which calls are allowed in the public setup phase of a tx. */
@@ -86,6 +89,16 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
86
89
  seenMessageCacheSize: number;
87
90
  /** True to disable the status handshake on peer connected. */
88
91
  p2pDisableStatusHandshake?: boolean;
92
+ /** True to only permit validators to connect */
93
+ p2pAllowOnlyValidators?: boolean;
94
+ /** True to disable participating in discovery */
95
+ p2pDiscoveryDisabled?: boolean;
96
+ /** Number of auth attempts to allow before peer is banned. Number is inclusive*/
97
+ p2pMaxFailedAuthAttemptsAllowed: number;
98
+ /** True to simulate discarding transactions. - For testing purposes only*/
99
+ dropTransactions: boolean;
100
+ /** The probability that a transaction is discarded. - For testing purposes only */
101
+ dropTransactionsProbability: number;
89
102
  }
90
103
  export declare const DEFAULT_P2P_PORT = 40400;
91
104
  export declare const p2pConfigMappings: ConfigMappingsType<P2PConfig>;
@@ -109,6 +122,16 @@ export declare const bootnodeConfigMappings: ConfigMappingsType<Pick<{
109
122
  individualRequestTimeoutMs: unknown;
110
123
  p2pOptimisticNegotiation: unknown;
111
124
  dialTimeoutMs: unknown;
125
+ txCollectionFastNodesTimeoutBeforeReqRespMs: unknown;
126
+ txCollectionSlowNodesIntervalMs: unknown;
127
+ txCollectionSlowReqRespIntervalMs: unknown;
128
+ txCollectionSlowReqRespTimeoutMs: unknown;
129
+ txCollectionReconcileIntervalMs: unknown;
130
+ txCollectionDisableSlowDuringFastRequests: unknown;
131
+ txCollectionFastNodeIntervalMs: unknown;
132
+ txCollectionNodeRpcUrls: unknown;
133
+ txCollectionFastMaxParallelRequestsPerNode: unknown;
134
+ txCollectionNodeRpcMaxBatchSize: unknown;
112
135
  p2pEnabled: unknown;
113
136
  blockCheckIntervalMS: unknown;
114
137
  blockRequestBatchSize: unknown;
@@ -143,12 +166,18 @@ export declare const bootnodeConfigMappings: ConfigMappingsType<Pick<{
143
166
  archivedTxLimit: unknown;
144
167
  trustedPeers: unknown;
145
168
  privatePeers: unknown;
169
+ preferredPeers: unknown;
146
170
  p2pStoreMapSizeKb: unknown;
147
171
  txPublicSetupAllowList: unknown;
148
172
  maxTxPoolSize: unknown;
149
173
  txPoolOverflowFactor: unknown;
150
174
  seenMessageCacheSize: unknown;
151
175
  p2pDisableStatusHandshake: unknown;
176
+ p2pAllowOnlyValidators: unknown;
177
+ p2pDiscoveryDisabled: unknown;
178
+ p2pMaxFailedAuthAttemptsAllowed: unknown;
179
+ dropTransactions: unknown;
180
+ dropTransactionsProbability: unknown;
152
181
  }, "p2pPort" | "p2pBroadcastPort" | "p2pIp" | "listenAddress" | "peerIdPrivateKey" | "peerIdPrivateKeyPath" | "bootstrapNodes" | "l1ChainId" | "dataDirectory" | "dataStoreMapSizeKB">>;
153
182
  /**
154
183
  * Parses a string to a list of allowed elements.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,WAAW,EAQZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAGlF,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAElG,OAAO,EAAE,KAAK,g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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uLAGlC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,CAqC9D"}
package/dest/config.js CHANGED
@@ -5,6 +5,7 @@ import { FunctionSelector } from '@aztec/stdlib/abi';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
6
  import { chainConfigMappings } from '@aztec/stdlib/config';
7
7
  import { p2pReqRespConfigMappings } from './services/reqresp/config.js';
8
+ import { txCollectionConfigMappings } from './services/tx_collection/config.js';
8
9
  export const DEFAULT_P2P_PORT = 40400;
9
10
  export const p2pConfigMappings = {
10
11
  p2pEnabled: {
@@ -12,6 +13,11 @@ export const p2pConfigMappings = {
12
13
  description: 'A flag dictating whether the P2P subsystem should be enabled.',
13
14
  ...booleanConfigHelper()
14
15
  },
16
+ p2pDiscoveryDisabled: {
17
+ env: 'P2P_DISCOVERY_DISABLED',
18
+ description: 'A flag dictating whether the P2P discovery system should be disabled.',
19
+ ...booleanConfigHelper(false)
20
+ },
15
21
  blockCheckIntervalMS: {
16
22
  env: 'P2P_BLOCK_CHECK_INTERVAL_MS',
17
23
  description: 'The frequency in which to check for new L2 blocks.',
@@ -182,6 +188,12 @@ export const p2pConfigMappings = {
182
188
  description: 'A list of private peer ENRs that will always be persisted and not be used for discovery. Separated by commas.',
183
189
  defaultValue: []
184
190
  },
191
+ preferredPeers: {
192
+ env: 'P2P_PREFERRED_PEERS',
193
+ parseEnv: (val)=>val.split(','),
194
+ description: 'A list of preferred peer ENRs that will always be persisted and not be used for discovery. Separated by commas.',
195
+ defaultValue: []
196
+ },
185
197
  p2pStoreMapSizeKb: {
186
198
  env: 'P2P_STORE_MAP_SIZE_KB',
187
199
  parseEnv: (val)=>val ? +val : undefined,
@@ -213,8 +225,29 @@ export const p2pConfigMappings = {
213
225
  description: 'True to disable the status handshake on peer connected.',
214
226
  ...booleanConfigHelper(false)
215
227
  },
228
+ p2pAllowOnlyValidators: {
229
+ env: 'P2P_ALLOW_ONLY_VALIDATORS',
230
+ description: 'True to only permit validators to connect.',
231
+ ...booleanConfigHelper(false)
232
+ },
233
+ p2pMaxFailedAuthAttemptsAllowed: {
234
+ env: 'P2P_MAX_AUTH_FAILED_ATTEMPTS_ALLOWED',
235
+ description: 'Number of auth attempts to allow before peer is banned. Number is inclusive',
236
+ ...numberConfigHelper(3)
237
+ },
238
+ dropTransactions: {
239
+ env: 'P2P_DROP_TX',
240
+ description: 'True to simulate discarding transactions. - For testing purposes only',
241
+ ...booleanConfigHelper(false)
242
+ },
243
+ dropTransactionsProbability: {
244
+ env: 'P2P_DROP_TX_CHANCE',
245
+ description: 'The probability that a transaction is discarded. - For testing purposes only',
246
+ ...floatConfigHelper(0)
247
+ },
216
248
  ...p2pReqRespConfigMappings,
217
- ...chainConfigMappings
249
+ ...chainConfigMappings,
250
+ ...txCollectionConfigMappings
218
251
  };
219
252
  /**
220
253
  * Gets the config values for p2p client from environment variables.
package/dest/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { createSecp256k1PeerId } from '@libp2p/peer-id-factory';
1
2
  export type { PeerId } from '@libp2p/interface';
2
3
  export * from './bootstrap/bootstrap.js';
3
4
  export * from './client/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC"}
package/dest/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { createSecp256k1PeerId } from '@libp2p/peer-id-factory';
1
2
  export * from './bootstrap/bootstrap.js';
2
3
  export * from './client/index.js';
3
4
  export * from './enr/index.js';
@@ -1,4 +1,4 @@
1
- import type { BlockAttestation } from '@aztec/stdlib/p2p';
1
+ import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
2
2
  /**
3
3
  * An Attestation Pool contains attestations collected by a validator
4
4
  *
@@ -6,6 +6,18 @@ import type { BlockAttestation } from '@aztec/stdlib/p2p';
6
6
  * from the validator to produce a block, or to serve to other peers.
7
7
  */
8
8
  export interface AttestationPool {
9
+ /**
10
+ * Adds new block proposal to the pool
11
+ */
12
+ addBlockProposal(blockProposal: BlockProposal): Promise<void>;
13
+ /**
14
+ * Get block proposal by it's ID
15
+ *
16
+ * @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
17
+ *
18
+ * @return The block proposal if it exists, otherwise undefined.
19
+ */
20
+ getBlockProposal(id: string): Promise<BlockProposal | undefined>;
9
21
  /**
10
22
  * AddAttestations
11
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;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E,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;;;OAMG;IACH,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;;;;;OAMG;IACH,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvD;;;;;;;OAOG;IACH,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtF;;;;;;;OAOG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAElE;;;;;;;;OAQG;IACH,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAEjG,yCAAyC;IACzC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"attestation_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool_test_suite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAgB,uBAAuB,CAAC,kBAAkB,EAAE,MAAM,eAAe,QA8NhF"}
1
+ {"version":3,"file":"attestation_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool_test_suite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAgB,uBAAuB,CAAC,kBAAkB,EAAE,MAAM,eAAe,QA8WhF"}