@aztec/p2p 0.0.1-commit.9b94fc1 → 0.0.1-commit.c7c42ec

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 (163) hide show
  1. package/dest/client/factory.d.ts +2 -2
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +2 -3
  4. package/dest/client/p2p_client.d.ts +7 -7
  5. package/dest/client/p2p_client.d.ts.map +1 -1
  6. package/dest/client/p2p_client.js +30 -28
  7. package/dest/config.d.ts +4 -7
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +8 -11
  10. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +2 -2
  11. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +1 -1
  12. package/dest/mem_pools/attestation_pool/mocks.d.ts +3 -3
  13. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  14. package/dest/mem_pools/attestation_pool/mocks.js +1 -1
  15. package/dest/mem_pools/instrumentation.d.ts +7 -1
  16. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  17. package/dest/mem_pools/instrumentation.js +29 -2
  18. package/dest/mem_pools/interface.d.ts +3 -4
  19. package/dest/mem_pools/interface.d.ts.map +1 -1
  20. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +30 -25
  21. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +262 -324
  23. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
  24. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  25. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
  26. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
  27. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  28. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
  29. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
  30. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
  31. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
  32. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  33. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  34. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  35. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  36. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  37. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
  38. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  39. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  40. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  41. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  42. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/index.js +0 -1
  44. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  45. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool/priority.js +6 -1
  47. package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -6
  48. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  49. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  50. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +30 -24
  52. package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
  53. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +1 -1
  54. package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
  55. package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
  56. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
  57. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  58. package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
  59. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  60. package/dest/msg_validators/tx_validator/factory.js +1 -1
  61. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
  62. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  63. package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
  64. package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
  65. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
  66. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  67. package/dest/services/encoding.js +1 -1
  68. package/dest/services/libp2p/libp2p_service.d.ts +4 -4
  69. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  70. package/dest/services/libp2p/libp2p_service.js +14 -19
  71. package/dest/services/peer-manager/metrics.d.ts +6 -1
  72. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  73. package/dest/services/peer-manager/metrics.js +17 -0
  74. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  75. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  76. package/dest/services/peer-manager/peer_manager.js +4 -2
  77. package/dest/services/reqresp/interface.d.ts +2 -2
  78. package/dest/services/reqresp/interface.d.ts.map +1 -1
  79. package/dest/services/reqresp/interface.js +1 -1
  80. package/dest/services/reqresp/protocols/auth.d.ts +2 -2
  81. package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
  82. package/dest/services/reqresp/protocols/auth.js +2 -2
  83. package/dest/services/reqresp/protocols/block.d.ts +1 -1
  84. package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
  85. package/dest/services/reqresp/protocols/block.js +3 -2
  86. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +2 -2
  87. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  88. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
  89. package/dest/services/reqresp/protocols/status.d.ts +5 -4
  90. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  91. package/dest/services/reqresp/protocols/status.js +4 -3
  92. package/dest/services/reqresp/protocols/tx.d.ts +2 -3
  93. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  94. package/dest/services/tx_collection/config.js +1 -1
  95. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -3
  96. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  97. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -5
  98. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  99. package/dest/services/tx_collection/tx_collection.d.ts +11 -10
  100. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  101. package/dest/services/tx_provider.d.ts +6 -4
  102. package/dest/services/tx_provider.d.ts.map +1 -1
  103. package/dest/services/tx_provider.js +11 -2
  104. package/dest/services/tx_provider_instrumentation.d.ts +5 -2
  105. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  106. package/dest/services/tx_provider_instrumentation.js +14 -1
  107. package/dest/test-helpers/mock-tx-helpers.js +1 -1
  108. package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
  109. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  110. package/dest/testbench/p2p_client_testbench_worker.js +1 -0
  111. package/package.json +16 -16
  112. package/src/client/factory.ts +5 -10
  113. package/src/client/p2p_client.ts +52 -55
  114. package/src/config.ts +10 -16
  115. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +2 -2
  116. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +1 -1
  117. package/src/mem_pools/attestation_pool/mocks.ts +2 -2
  118. package/src/mem_pools/instrumentation.ts +33 -0
  119. package/src/mem_pools/interface.ts +2 -4
  120. package/src/mem_pools/tx_pool/README.md +255 -0
  121. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +314 -373
  122. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
  123. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
  124. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
  125. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  126. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
  127. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  128. package/src/mem_pools/tx_pool/index.ts +0 -1
  129. package/src/mem_pools/tx_pool/priority.ts +8 -1
  130. package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
  131. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
  132. package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
  133. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +1 -1
  134. package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
  135. package/src/msg_validators/tx_validator/block_header_validator.ts +1 -1
  136. package/src/msg_validators/tx_validator/factory.ts +3 -2
  137. package/src/msg_validators/tx_validator/metadata_validator.ts +1 -1
  138. package/src/msg_validators/tx_validator/test_utils.ts +1 -1
  139. package/src/msg_validators/tx_validator/timestamp_validator.ts +2 -1
  140. package/src/services/encoding.ts +1 -1
  141. package/src/services/libp2p/libp2p_service.ts +23 -28
  142. package/src/services/peer-manager/metrics.ts +22 -0
  143. package/src/services/peer-manager/peer_manager.ts +4 -2
  144. package/src/services/reqresp/interface.ts +1 -1
  145. package/src/services/reqresp/protocols/auth.ts +2 -2
  146. package/src/services/reqresp/protocols/block.ts +3 -2
  147. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
  148. package/src/services/reqresp/protocols/status.ts +9 -8
  149. package/src/services/reqresp/protocols/tx.ts +1 -2
  150. package/src/services/tx_collection/config.ts +1 -1
  151. package/src/services/tx_collection/fast_tx_collection.ts +3 -2
  152. package/src/services/tx_collection/slow_tx_collection.ts +5 -5
  153. package/src/services/tx_collection/tx_collection.ts +10 -9
  154. package/src/services/tx_provider.ts +21 -5
  155. package/src/services/tx_provider_instrumentation.ts +19 -2
  156. package/src/test-helpers/mock-pubsub.ts +1 -1
  157. package/src/test-helpers/mock-tx-helpers.ts +1 -1
  158. package/src/test-helpers/reqresp-nodes.ts +1 -1
  159. package/src/testbench/p2p_client_testbench_worker.ts +2 -1
  160. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
  161. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  162. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
  163. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
@@ -1,17 +1,16 @@
1
- import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
- import { SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { DateProvider } from '@aztec/foundation/timer';
5
5
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
6
6
  import type {
7
7
  EthAddress,
8
- L2Block,
9
8
  L2BlockId,
9
+ L2BlockNew,
10
10
  L2BlockSource,
11
11
  L2BlockStream,
12
12
  L2BlockStreamEvent,
13
13
  L2Tips,
14
- PublishedL2Block,
15
14
  } from '@aztec/stdlib/block';
16
15
  import type { ContractDataSource } from '@aztec/stdlib/contract';
17
16
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
@@ -63,14 +62,14 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
63
62
  private provenBlockNumberAtStart = -1;
64
63
  private finalizedBlockNumberAtStart = -1;
65
64
 
66
- private synchedBlockHashes: AztecAsyncMap<number, string>;
67
- private synchedLatestBlockNumber: AztecAsyncSingleton<number>;
68
- private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
69
- private synchedFinalizedBlockNumber: AztecAsyncSingleton<number>;
65
+ private synchedBlockHashes: AztecAsyncMap<BlockNumber, string>;
66
+ private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
67
+ private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
68
+ private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
70
69
  private synchedLatestSlot: AztecAsyncSingleton<bigint>;
71
70
 
72
71
  private txPool: TxPool;
73
- private attestationPool: T extends P2PClientType.Full ? AttestationPool : undefined;
72
+ private attestationPool: AttestationPool;
74
73
 
75
74
  private config: P2PConfig;
76
75
 
@@ -92,7 +91,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
92
91
  _clientType: T,
93
92
  private store: AztecAsyncKVStore,
94
93
  private l2BlockSource: L2BlockSource & ContractDataSource,
95
- mempools: MemPools<T>,
94
+ mempools: MemPools,
96
95
  private p2pService: P2PService,
97
96
  private txCollection: TxCollection,
98
97
  config: Partial<P2PConfig> = {},
@@ -104,7 +103,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
104
103
 
105
104
  this.config = { ...getP2PDefaultConfig(), ...config };
106
105
  this.txPool = mempools.txPool;
107
- this.attestationPool = mempools.attestationPool!;
106
+ this.attestationPool = mempools.attestationPool;
108
107
 
109
108
  this.txProvider = new TxProvider(
110
109
  this.txCollection,
@@ -129,7 +128,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
129
128
  this.log.debug(`Cannot collect txs for proposal as parent block not found`);
130
129
  return;
131
130
  }
132
- const blockNumber = parentBlock.getBlockNumber() + 1;
131
+ const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
133
132
  await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
134
133
  return undefined;
135
134
  });
@@ -163,7 +162,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
163
162
  return Promise.resolve(this.p2pService.getPeers(includePending));
164
163
  }
165
164
 
166
- public getL2BlockHash(number: number): Promise<string | undefined> {
165
+ public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
167
166
  return this.synchedBlockHashes.getAsync(number);
168
167
  }
169
168
 
@@ -204,10 +203,12 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
204
203
  }
205
204
  }
206
205
 
206
+ const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
207
+
207
208
  return {
208
- latest: { hash: latestBlockHash!, number: latestBlockNumber },
209
- proven: { hash: provenBlockHash!, number: provenBlockNumber },
210
- finalized: { hash: finalizedBlockHash!, number: finalizedBlockNumber },
209
+ latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
210
+ proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
211
+ finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
211
212
  };
212
213
  }
213
214
 
@@ -215,15 +216,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
215
216
  this.log.debug(`Handling block stream event ${event.type}`);
216
217
  switch (event.type) {
217
218
  case 'blocks-added':
218
- await this.handleLatestL2Blocks(event.blocks);
219
+ await this.handleLatestL2Blocks(event.blocks.map(b => b.block.toL2Block()));
219
220
  break;
220
221
  case 'chain-finalized': {
221
222
  // TODO (alexg): I think we can prune the block hashes map here
222
223
  await this.setBlockHash(event.block);
223
- const from = (await this.getSyncedFinalizedBlockNum()) + 1;
224
+ const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
224
225
  const limit = event.block.number - from + 1;
225
226
  if (limit > 0) {
226
- await this.handleFinalizedL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
227
+ const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
228
+ await this.handleFinalizedL2Blocks(oldBlocks.map(b => b.toL2Block()));
227
229
  }
228
230
  break;
229
231
  }
@@ -280,12 +282,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
280
282
  const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
281
283
  const syncedFinalizedBlock = (await this.getSyncedFinalizedBlockNum()) + 1;
282
284
 
283
- if (
284
- (await this.txPool.isEmpty()) &&
285
- (this.attestationPool === undefined || (await this.attestationPool?.isEmpty()))
286
- ) {
285
+ if ((await this.txPool.isEmpty()) && (await this.attestationPool.isEmpty())) {
287
286
  // if mempools are empty, we don't care about syncing prior blocks
288
- this.initBlockStream(this.latestBlockNumberAtStart);
287
+ this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
289
288
  this.setCurrentState(P2PClientState.RUNNING);
290
289
  this.syncPromise = Promise.resolve();
291
290
  await this.p2pService.start();
@@ -333,7 +332,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
333
332
  return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
334
333
  }
335
334
 
336
- private initBlockStream(startingBlock?: number) {
335
+ private initBlockStream(startingBlock?: BlockNumber) {
337
336
  if (!this.blockStream) {
338
337
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
339
338
  this.blockStream = new TraceableL2BlockStream(
@@ -387,19 +386,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
387
386
  }
388
387
 
389
388
  public async getAttestationsForSlot(slot: SlotNumber, proposalId?: string): Promise<BlockAttestation[]> {
390
- return (
391
- (await (proposalId
392
- ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
393
- : this.attestationPool?.getAttestationsForSlot(slot))) ?? []
394
- );
389
+ return await (proposalId
390
+ ? this.attestationPool.getAttestationsForSlotAndProposal(slot, proposalId)
391
+ : this.attestationPool.getAttestationsForSlot(slot));
395
392
  }
396
393
 
397
394
  public addAttestations(attestations: BlockAttestation[]): Promise<void> {
398
- return this.attestationPool?.addAttestations(attestations) ?? Promise.resolve();
395
+ return this.attestationPool.addAttestations(attestations);
399
396
  }
400
397
 
401
398
  public deleteAttestation(attestation: BlockAttestation): Promise<void> {
402
- return this.attestationPool?.deleteAttestations([attestation]) ?? Promise.resolve();
399
+ return this.attestationPool.deleteAttestations([attestation]);
403
400
  }
404
401
 
405
402
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
@@ -649,20 +646,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
649
646
  * Public function to check the latest block number that the P2P client is synced to.
650
647
  * @returns Block number of latest L2 Block we've synced with.
651
648
  */
652
- public async getSyncedLatestBlockNum(): Promise<number> {
653
- return (await this.synchedLatestBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
649
+ public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
650
+ return (await this.synchedLatestBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
654
651
  }
655
652
 
656
653
  /**
657
654
  * Public function to check the latest proven block number that the P2P client is synced to.
658
655
  * @returns Block number of latest proven L2 Block we've synced with.
659
656
  */
660
- public async getSyncedProvenBlockNum(): Promise<number> {
661
- return (await this.synchedProvenBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
657
+ public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
658
+ return (await this.synchedProvenBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
662
659
  }
663
660
 
664
- public async getSyncedFinalizedBlockNum(): Promise<number> {
665
- return (await this.synchedFinalizedBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
661
+ public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
662
+ return (await this.synchedFinalizedBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
666
663
  }
667
664
 
668
665
  /** Returns latest L2 slot for which we have seen an L2 block. */
@@ -678,7 +675,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
678
675
  const blockNumber = await this.getSyncedLatestBlockNum();
679
676
  const blockHash =
680
677
  blockNumber === 0
681
- ? ''
678
+ ? GENESIS_BLOCK_HEADER_HASH.toString()
682
679
  : await this.l2BlockSource
683
680
  .getBlockHeader(blockNumber)
684
681
  .then(header => header?.hash())
@@ -686,8 +683,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
686
683
 
687
684
  return {
688
685
  state: this.currentState,
689
- syncedToL2Block: { number: blockNumber, hash: blockHash },
690
- } as P2PSyncState;
686
+ syncedToL2Block: { number: blockNumber, hash: blockHash! },
687
+ };
691
688
  }
692
689
 
693
690
  /**
@@ -695,10 +692,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
695
692
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
696
693
  * @returns Empty promise.
697
694
  */
698
- private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
695
+ private async markTxsAsMinedFromBlocks(blocks: L2BlockNew[]): Promise<void> {
699
696
  for (const block of blocks) {
700
697
  const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
701
- await this.txPool.markAsMined(txHashes, block.getBlockHeader());
698
+ await this.txPool.markAsMined(txHashes, block.header);
702
699
  }
703
700
  }
704
701
 
@@ -707,21 +704,22 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
707
704
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
708
705
  * @returns Empty promise.
709
706
  */
710
- private async handleLatestL2Blocks(blocks: PublishedL2Block[]): Promise<void> {
707
+ private async handleLatestL2Blocks(blocks: L2BlockNew[]): Promise<void> {
711
708
  if (!blocks.length) {
712
709
  return Promise.resolve();
713
710
  }
714
711
 
715
- await this.markTxsAsMinedFromBlocks(blocks.map(b => b.block));
716
- await this.startCollectingMissingTxs(blocks.map(b => b.block));
712
+ await this.markTxsAsMinedFromBlocks(blocks);
713
+ await this.txPool.clearNonEvictableTxs();
714
+ await this.startCollectingMissingTxs(blocks);
717
715
 
718
- const lastBlock = blocks.at(-1)!.block;
716
+ const lastBlock = blocks.at(-1)!;
719
717
 
720
718
  await Promise.all(
721
719
  blocks.map(async block =>
722
720
  this.setBlockHash({
723
- number: block.block.number,
724
- hash: await block.block.hash().then(h => h.toString()),
721
+ number: block.number,
722
+ hash: await block.hash().then(h => h.toString()),
725
723
  }),
726
724
  ),
727
725
  );
@@ -733,7 +731,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
733
731
  }
734
732
 
735
733
  /** Request txs for unproven blocks so the prover node has more chances to get them. */
736
- private async startCollectingMissingTxs(blocks: L2Block[]): Promise<void> {
734
+ private async startCollectingMissingTxs(blocks: L2BlockNew[]): Promise<void> {
737
735
  try {
738
736
  // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
739
737
  // be much lower than the actual one, and it does not update until the pending chain is
@@ -766,7 +764,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
766
764
  * @param blocks - A list of finalized L2 blocks.
767
765
  * @returns Empty promise.
768
766
  */
769
- private async handleFinalizedL2Blocks(blocks: L2Block[]): Promise<void> {
767
+ private async handleFinalizedL2Blocks(blocks: L2BlockNew[]): Promise<void> {
770
768
  if (!blocks.length) {
771
769
  return Promise.resolve();
772
770
  }
@@ -780,7 +778,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
780
778
  await this.txPool.deleteTxs(txHashes, { permanently: true });
781
779
  await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
782
780
 
783
- await this.attestationPool?.deleteAttestationsOlderThan(lastBlockSlot);
781
+ await this.attestationPool.deleteAttestationsOlderThan(lastBlockSlot);
784
782
 
785
783
  await this.synchedFinalizedBlockNumber.set(lastBlockNum);
786
784
  this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
@@ -792,7 +790,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
792
790
  * Updates the tx pool after a chain prune.
793
791
  * @param latestBlock - The block number the chain was pruned to.
794
792
  */
795
- private async handlePruneL2Blocks(latestBlock: number): Promise<void> {
793
+ private async handlePruneL2Blocks(latestBlock: BlockNumber): Promise<void> {
796
794
  const txsToDelete = new Map<string, TxHash>();
797
795
  const minedTxs = await this.txPool.getMinedTxHashes();
798
796
 
@@ -831,8 +829,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
831
829
  this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
832
830
  await this.txPool.deleteTxs(minedTxsFromReorg);
833
831
  } else {
834
- this.log.info(`Moving ${minedTxsFromReorg.length} mined txs from reorg back to pending`);
835
- await this.txPool.markMinedAsPending(minedTxsFromReorg);
832
+ await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
836
833
  }
837
834
 
838
835
  await this.synchedLatestBlockNumber.set(latestBlock);
package/src/config.ts CHANGED
@@ -9,9 +9,9 @@ import {
9
9
  pickConfigMappings,
10
10
  secretStringConfigHelper,
11
11
  } from '@aztec/foundation/config';
12
- import { Fr } from '@aztec/foundation/fields';
12
+ import { Fr } from '@aztec/foundation/curves/bn254';
13
13
  import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
14
- import { FunctionSelector } from '@aztec/stdlib/abi';
14
+ import { FunctionSelector } from '@aztec/stdlib/abi/function-selector';
15
15
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
16
16
  import { type AllowedElement, type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
17
17
 
@@ -133,11 +133,8 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
133
133
  /** Which calls are allowed in the public setup phase of a tx. */
134
134
  txPublicSetupAllowList: AllowedElement[];
135
135
 
136
- /** The maximum cumulative tx size (in bytes) of pending txs before evicting lower priority txs. */
137
- maxTxPoolSize: number;
138
-
139
- /** If the pool is full, it will still accept a few more txs until it reached maxTxPoolOverspillFactor * maxTxPoolSize. Then it will evict */
140
- txPoolOverflowFactor: number;
136
+ /** The maximum number of pending txs before evicting lower priority txs. */
137
+ maxPendingTxCount: number;
141
138
 
142
139
  /** The node's seen message ID cache size */
143
140
  seenMessageCacheSize: number;
@@ -375,15 +372,12 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
375
372
  printDefault: () =>
376
373
  'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
377
374
  },
378
- maxTxPoolSize: {
379
- env: 'P2P_MAX_TX_POOL_SIZE',
380
- description: 'The maximum cumulative tx size of pending txs (in bytes) before evicting lower priority txs.',
381
- ...numberConfigHelper(100_000_000), // 100MB
382
- },
383
- txPoolOverflowFactor: {
384
- env: 'P2P_TX_POOL_OVERFLOW_FACTOR',
385
- description: 'How much the tx pool can overflow before it starts evicting txs. Must be greater than 1',
386
- ...floatConfigHelper(1.1), // 10% overflow
375
+ maxPendingTxCount: {
376
+ env: 'P2P_MAX_PENDING_TX_COUNT',
377
+ description: 'The maximum number of pending txs before evicting lower priority txs.',
378
+ // Worst case scenario: Uncompressed public/private tx is ~ 156kb
379
+ // This implies we are using ~156MB of memory for pending pool
380
+ ...numberConfigHelper(1_000),
387
381
  },
388
382
  seenMessageCacheSize: {
389
383
  env: 'P2P_SEEN_MSG_CACHE_SIZE',
@@ -1,6 +1,6 @@
1
1
  import { SlotNumber } from '@aztec/foundation/branded-types';
2
- import { Secp256k1Signer } from '@aztec/foundation/crypto';
3
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
5
5
  import {
6
6
  BlockProposal as BlockProposalClass,
@@ -1,5 +1,5 @@
1
1
  import { SlotNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { toArray } from '@aztec/foundation/iterable';
4
4
  import { createLogger } from '@aztec/foundation/log';
5
5
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
@@ -1,5 +1,5 @@
1
- import type { Secp256k1Signer } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import {
4
4
  BlockAttestation,
5
5
  ConsensusPayload,
@@ -1,4 +1,5 @@
1
1
  import type { Gossipable } from '@aztec/stdlib/p2p';
2
+ import type { Tx } from '@aztec/stdlib/tx';
2
3
  import {
3
4
  Attributes,
4
5
  type BatchObservableResult,
@@ -22,6 +23,7 @@ type MetricsLabels = {
22
23
  objectInMempool: MetricsType;
23
24
  objectSize: MetricsType;
24
25
  itemsAdded: MetricsType;
26
+ itemMinedDelay: MetricsType;
25
27
  };
26
28
 
27
29
  /**
@@ -35,12 +37,14 @@ function getMetricsLabels(name: PoolName): MetricsLabels {
35
37
  objectInMempool: Metrics.MEMPOOL_TX_COUNT,
36
38
  objectSize: Metrics.MEMPOOL_TX_SIZE,
37
39
  itemsAdded: Metrics.MEMPOOL_TX_ADDED_COUNT,
40
+ itemMinedDelay: Metrics.MEMPOOL_TX_MINED_DELAY,
38
41
  };
39
42
  } else if (name === PoolName.ATTESTATION_POOL) {
40
43
  return {
41
44
  objectInMempool: Metrics.MEMPOOL_ATTESTATIONS_COUNT,
42
45
  objectSize: Metrics.MEMPOOL_ATTESTATIONS_SIZE,
43
46
  itemsAdded: Metrics.MEMPOOL_ATTESTATIONS_ADDED_COUNT,
47
+ itemMinedDelay: Metrics.MEMPOOL_ATTESTATIONS_MINED_DELAY,
44
48
  };
45
49
  }
46
50
 
@@ -60,12 +64,16 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
60
64
  private addObjectCounter: UpDownCounter;
61
65
  /** Tracks tx size */
62
66
  private objectSize: Histogram;
67
+ /** Track delay between transaction added and evicted */
68
+ private minedDelay: Histogram;
63
69
 
64
70
  private dbMetrics: LmdbMetrics;
65
71
 
66
72
  private defaultAttributes;
67
73
  private meter: Meter;
68
74
 
75
+ private txAddedTimestamp: Map<bigint, number> = new Map<bigint, number>();
76
+
69
77
  constructor(
70
78
  telemetry: TelemetryClient,
71
79
  name: PoolName,
@@ -98,6 +106,10 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
98
106
  description: 'The number of transactions added to the mempool',
99
107
  });
100
108
 
109
+ this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay, {
110
+ description: 'Delay between transaction added and evicted from the mempool',
111
+ });
112
+
101
113
  this.meter.addBatchObservableCallback(this.observeStats, [this.objectsInMempool]);
102
114
  }
103
115
 
@@ -109,6 +121,27 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
109
121
  this.addObjectCounter.add(count);
110
122
  }
111
123
 
124
+ public transactionsAdded(transactions: Tx[]) {
125
+ const timestamp = Date.now();
126
+ for (const transaction of transactions) {
127
+ this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
128
+ }
129
+ }
130
+
131
+ public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
132
+ const timestamp = Date.now();
133
+ for (const hash of hashes) {
134
+ const key = BigInt(hash);
135
+ const addedAt = this.txAddedTimestamp.get(key);
136
+ if (addedAt !== undefined) {
137
+ this.txAddedTimestamp.delete(key);
138
+ if (addedAt < timestamp) {
139
+ this.minedDelay.record(timestamp - addedAt);
140
+ }
141
+ }
142
+ }
143
+ }
144
+
112
145
  private observeStats = async (observer: BatchObservableResult) => {
113
146
  const { itemCount } = await this.poolStats();
114
147
  if (typeof itemCount === 'number') {
@@ -1,12 +1,10 @@
1
- import type { P2PClientType } from '@aztec/stdlib/p2p';
2
-
3
1
  import type { AttestationPool } from './attestation_pool/attestation_pool.js';
4
2
  import type { TxPool } from './tx_pool/tx_pool.js';
5
3
 
6
4
  /**
7
5
  * A interface the combines all mempools
8
6
  */
9
- export type MemPools<T extends P2PClientType = P2PClientType.Full> = {
7
+ export type MemPools = {
10
8
  txPool: TxPool;
11
- attestationPool?: T extends P2PClientType.Full ? AttestationPool : undefined;
9
+ attestationPool: AttestationPool;
12
10
  };