@aztec/p2p 0.0.1-commit.381b1a9 → 0.0.1-commit.3a4ae741b

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 (161) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +2 -2
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +20 -12
  5. package/dest/client/p2p_client.d.ts +1 -1
  6. package/dest/client/p2p_client.d.ts.map +1 -1
  7. package/dest/client/p2p_client.js +16 -10
  8. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +3 -3
  9. package/dest/config.d.ts +6 -6
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +6 -6
  12. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
  13. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  14. package/dest/mem_pools/attestation_pool/attestation_pool.js +8 -4
  15. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
  16. package/dest/mem_pools/instrumentation.d.ts +4 -2
  17. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  18. package/dest/mem_pools/instrumentation.js +16 -14
  19. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  20. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  21. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
  22. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  23. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  24. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
  25. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
  26. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  27. package/dest/mem_pools/tx_pool_v2/interfaces.js +1 -0
  28. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +13 -7
  29. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  30. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +7 -1
  31. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  32. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  33. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
  34. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  35. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -0
  37. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -1
  38. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +29 -5
  40. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  41. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  42. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  43. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  44. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  45. package/dest/msg_validators/clock_tolerance.js +4 -3
  46. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +1 -1
  47. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  48. package/dest/msg_validators/proposal_validator/proposal_validator.js +5 -5
  49. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  50. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  51. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  52. package/dest/msg_validators/tx_validator/factory.d.ts +9 -1
  53. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  54. package/dest/msg_validators/tx_validator/factory.js +15 -2
  55. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  56. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  57. package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
  58. package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
  59. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  60. package/dest/msg_validators/tx_validator/phases_validator.js +28 -1
  61. package/dest/services/encoding.d.ts +5 -1
  62. package/dest/services/encoding.d.ts.map +1 -1
  63. package/dest/services/encoding.js +7 -1
  64. package/dest/services/libp2p/libp2p_service.d.ts +4 -9
  65. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  66. package/dest/services/libp2p/libp2p_service.js +105 -54
  67. package/dest/services/peer-manager/metrics.d.ts +3 -1
  68. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  69. package/dest/services/peer-manager/metrics.js +6 -0
  70. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  71. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  72. package/dest/services/peer-manager/peer_manager.js +6 -3
  73. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
  74. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  75. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +82 -101
  76. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
  77. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  78. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  79. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  80. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  81. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
  82. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  83. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
  84. package/dest/services/reqresp/reqresp.d.ts +1 -1
  85. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  86. package/dest/services/reqresp/reqresp.js +19 -10
  87. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
  88. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  89. package/dest/services/tx_collection/fast_tx_collection.js +57 -73
  90. package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
  91. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  92. package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
  93. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  94. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  95. package/dest/services/tx_collection/request_tracker.js +84 -0
  96. package/dest/services/tx_collection/slow_tx_collection.js +1 -1
  97. package/dest/services/tx_collection/tx_collection.d.ts +3 -6
  98. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  99. package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
  100. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  101. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  102. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  103. package/dest/test-helpers/testbench-utils.d.ts +1 -1
  104. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  105. package/dest/test-helpers/testbench-utils.js +20 -2
  106. package/dest/testbench/p2p_client_testbench_worker.js +3 -3
  107. package/dest/testbench/worker_client_manager.d.ts +1 -1
  108. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  109. package/dest/testbench/worker_client_manager.js +2 -1
  110. package/dest/util.d.ts +1 -1
  111. package/package.json +14 -14
  112. package/src/client/factory.ts +36 -18
  113. package/src/client/p2p_client.ts +19 -10
  114. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +4 -6
  115. package/src/config.ts +10 -10
  116. package/src/mem_pools/attestation_pool/attestation_pool.ts +8 -7
  117. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
  118. package/src/mem_pools/instrumentation.ts +17 -13
  119. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  120. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  121. package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
  122. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +15 -5
  123. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
  124. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +16 -1
  125. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +31 -5
  126. package/src/msg_validators/attestation_validator/README.md +49 -0
  127. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  128. package/src/msg_validators/clock_tolerance.ts +4 -3
  129. package/src/msg_validators/proposal_validator/README.md +123 -0
  130. package/src/msg_validators/proposal_validator/proposal_validator.ts +6 -5
  131. package/src/msg_validators/tx_validator/README.md +5 -1
  132. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  133. package/src/msg_validators/tx_validator/factory.ts +21 -1
  134. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  135. package/src/msg_validators/tx_validator/phases_validator.ts +31 -1
  136. package/src/services/encoding.ts +9 -1
  137. package/src/services/libp2p/libp2p_service.ts +97 -65
  138. package/src/services/peer-manager/metrics.ts +7 -0
  139. package/src/services/peer-manager/peer_manager.ts +7 -3
  140. package/src/services/reqresp/README.md +229 -0
  141. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  142. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +78 -111
  143. package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
  144. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  145. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
  146. package/src/services/reqresp/reqresp.ts +22 -12
  147. package/src/services/tx_collection/fast_tx_collection.ts +57 -83
  148. package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
  149. package/src/services/tx_collection/request_tracker.ts +127 -0
  150. package/src/services/tx_collection/slow_tx_collection.ts +1 -1
  151. package/src/services/tx_collection/tx_collection.ts +3 -5
  152. package/src/test-helpers/make-test-p2p-clients.ts +1 -1
  153. package/src/test-helpers/reqresp-nodes.ts +1 -1
  154. package/src/test-helpers/testbench-utils.ts +28 -3
  155. package/src/testbench/p2p_client_testbench_worker.ts +4 -6
  156. package/src/testbench/worker_client_manager.ts +2 -1
  157. package/src/util.ts +1 -1
  158. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  159. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  160. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  161. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/p2p",
3
- "version": "0.0.1-commit.381b1a9",
3
+ "version": "0.0.1-commit.3a4ae741b",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -67,17 +67,17 @@
67
67
  ]
68
68
  },
69
69
  "dependencies": {
70
- "@aztec/constants": "0.0.1-commit.381b1a9",
71
- "@aztec/epoch-cache": "0.0.1-commit.381b1a9",
72
- "@aztec/ethereum": "0.0.1-commit.381b1a9",
73
- "@aztec/foundation": "0.0.1-commit.381b1a9",
74
- "@aztec/kv-store": "0.0.1-commit.381b1a9",
75
- "@aztec/noir-contracts.js": "0.0.1-commit.381b1a9",
76
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.381b1a9",
77
- "@aztec/protocol-contracts": "0.0.1-commit.381b1a9",
78
- "@aztec/simulator": "0.0.1-commit.381b1a9",
79
- "@aztec/stdlib": "0.0.1-commit.381b1a9",
80
- "@aztec/telemetry-client": "0.0.1-commit.381b1a9",
70
+ "@aztec/constants": "0.0.1-commit.3a4ae741b",
71
+ "@aztec/epoch-cache": "0.0.1-commit.3a4ae741b",
72
+ "@aztec/ethereum": "0.0.1-commit.3a4ae741b",
73
+ "@aztec/foundation": "0.0.1-commit.3a4ae741b",
74
+ "@aztec/kv-store": "0.0.1-commit.3a4ae741b",
75
+ "@aztec/noir-contracts.js": "0.0.1-commit.3a4ae741b",
76
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.3a4ae741b",
77
+ "@aztec/protocol-contracts": "0.0.1-commit.3a4ae741b",
78
+ "@aztec/simulator": "0.0.1-commit.3a4ae741b",
79
+ "@aztec/stdlib": "0.0.1-commit.3a4ae741b",
80
+ "@aztec/telemetry-client": "0.0.1-commit.3a4ae741b",
81
81
  "@chainsafe/libp2p-gossipsub": "13.0.0",
82
82
  "@chainsafe/libp2p-noise": "^15.0.0",
83
83
  "@chainsafe/libp2p-yamux": "^6.0.2",
@@ -104,8 +104,8 @@
104
104
  "xxhash-wasm": "^1.1.0"
105
105
  },
106
106
  "devDependencies": {
107
- "@aztec/archiver": "0.0.1-commit.381b1a9",
108
- "@aztec/world-state": "0.0.1-commit.381b1a9",
107
+ "@aztec/archiver": "0.0.1-commit.3a4ae741b",
108
+ "@aztec/world-state": "0.0.1-commit.3a4ae741b",
109
109
  "@jest/globals": "^30.0.0",
110
110
  "@types/jest": "^30.0.0",
111
111
  "@types/node": "^22.15.17",
@@ -3,12 +3,12 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { DateProvider } from '@aztec/foundation/timer';
5
5
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
6
- import type { DataStoreConfig } from '@aztec/kv-store/config';
7
6
  import { AztecLMDBStoreV2, createStore } from '@aztec/kv-store/lmdb-v2';
8
7
  import type { L2BlockSource } from '@aztec/stdlib/block';
9
8
  import type { ChainConfig } from '@aztec/stdlib/config';
10
9
  import type { ContractDataSource } from '@aztec/stdlib/contract';
11
10
  import type { AztecNode, ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
11
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
12
12
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
13
13
 
14
14
  import { P2PClient } from '../client/p2p_client.js';
@@ -17,7 +17,11 @@ import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestati
17
17
  import type { MemPools } from '../mem_pools/interface.js';
18
18
  import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
19
19
  import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
20
- import { createTxValidatorForTransactionsEnteringPendingTxPool } from '../msg_validators/index.js';
20
+ import {
21
+ createCheckAllowedSetupCalls,
22
+ createTxValidatorForTransactionsEnteringPendingTxPool,
23
+ getDefaultAllowedSetupFunctions,
24
+ } from '../msg_validators/index.js';
21
25
  import { DummyP2PService } from '../services/dummy_service.js';
22
26
  import { LibP2PService } from '../services/index.js';
23
27
  import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
@@ -75,6 +79,33 @@ export async function createP2PClient(
75
79
  const rollupAddress = inputConfig.l1Contracts.rollupAddress.toString().toLowerCase().replace(/^0x/, '');
76
80
  const txFileStoreBasePath = `aztec-${inputConfig.l1ChainId}-${inputConfig.rollupVersion}-0x${rollupAddress}`;
77
81
 
82
+ const allowedInSetup = [
83
+ ...(await getDefaultAllowedSetupFunctions()),
84
+ ...(inputConfig.txPublicSetupAllowListExtend ?? []),
85
+ ];
86
+ const checkAllowedSetupCalls = createCheckAllowedSetupCalls(
87
+ archiver,
88
+ allowedInSetup,
89
+ () => epochCache.getEpochAndSlotInNextL1Slot().ts,
90
+ );
91
+
92
+ const createTxValidator = async () => {
93
+ // We accept transactions if they are not expired by the next slot and block number (checked based on the ExpirationTimestamp field)
94
+ const currentBlockNumber = await archiver.getBlockNumber();
95
+ const { ts: nextSlotTimestamp } = epochCache.getEpochAndSlotInNextL1Slot();
96
+ const l1Constants = await archiver.getL1Constants();
97
+ return createTxValidatorForTransactionsEnteringPendingTxPool(
98
+ worldStateSynchronizer,
99
+ nextSlotTimestamp,
100
+ BlockNumber(currentBlockNumber + 1),
101
+ {
102
+ rollupManaLimit: l1Constants.rollupManaLimit,
103
+ maxBlockL2Gas: config.validateMaxL2BlockGas,
104
+ maxBlockDAGas: config.validateMaxDABlockGas,
105
+ },
106
+ );
107
+ };
108
+
78
109
  const txPool =
79
110
  deps.txPool ??
80
111
  new AztecKVTxPoolV2(
@@ -83,28 +114,15 @@ export async function createP2PClient(
83
114
  {
84
115
  l2BlockSource: archiver,
85
116
  worldStateSynchronizer,
86
- createTxValidator: async () => {
87
- // We accept transactions if they are not expired by the next slot and block number (checked based on the ExpirationTimestamp field)
88
- const currentBlockNumber = await archiver.getBlockNumber();
89
- const { ts: nextSlotTimestamp } = epochCache.getEpochAndSlotInNextL1Slot();
90
- const l1Constants = await archiver.getL1Constants();
91
- return createTxValidatorForTransactionsEnteringPendingTxPool(
92
- worldStateSynchronizer,
93
- nextSlotTimestamp,
94
- BlockNumber(currentBlockNumber + 1),
95
- {
96
- rollupManaLimit: l1Constants.rollupManaLimit,
97
- maxBlockL2Gas: config.validateMaxL2BlockGas,
98
- maxBlockDAGas: config.validateMaxDABlockGas,
99
- },
100
- );
101
- },
117
+ checkAllowedSetupCalls,
118
+ createTxValidator,
102
119
  },
103
120
  telemetry,
104
121
  {
105
122
  maxPendingTxCount: config.maxPendingTxCount,
106
123
  archivedTxLimit: config.archivedTxLimit,
107
124
  minTxPoolAgeMs: config.minTxPoolAgeMs,
125
+ dropTransactionsProbability: config.dropTransactionsProbability,
108
126
  priceBumpPercentage: config.priceBumpPercentage,
109
127
  },
110
128
  dateProvider,
@@ -669,32 +669,41 @@ export class P2PClient extends WithTracer implements P2P {
669
669
  }
670
670
 
671
671
  /**
672
- * Returns true if the prune crossed a checkpoint boundary.
673
- * If the old and new checkpoint numbers are the same, the prune is within a single checkpoint.
674
- * If they differ, the prune spans across checkpoints (epoch prune).
672
+ * Returns true if the prune is an epoch prune (new checkpoint number is less than old).
673
+ * If the checkpoint number stays the same or increases, the prune is within a checkpoint.
675
674
  */
676
675
  private async isEpochPrune(newCheckpoint: CheckpointId): Promise<boolean> {
677
676
  const tips = await this.l2Tips.getL2Tips();
678
677
  const oldCheckpointNumber = tips.checkpointed.checkpoint.number;
679
- if (oldCheckpointNumber <= CheckpointNumber.ZERO) {
678
+ if (oldCheckpointNumber <= CheckpointNumber.INITIAL) {
680
679
  return false;
681
680
  }
682
681
  const newCheckpointNumber = newCheckpoint.number;
683
- const isEpochPrune = oldCheckpointNumber !== newCheckpointNumber;
682
+ // We check that the new checkpoint number is less than the old checkpoint number in order to consider it an epoch prune.
683
+ // To be more certain that it is an epoch prune, we will check that at least 2 checkpoints were removed.
684
+ // This means we should avoid thinking checkpoints removed by L1 re-orgs are epoch prunes
685
+ const thresholdForEpochPrune = CheckpointNumber(oldCheckpointNumber - 2);
686
+ const isEpochPrune = newCheckpointNumber <= thresholdForEpochPrune;
684
687
  if (isEpochPrune) {
685
- this.log.info(`Detected epoch prune to ${newCheckpointNumber}`, { oldCheckpointNumber, newCheckpointNumber });
688
+ this.log.info(`Detected epoch prune to ${newCheckpointNumber}`, {
689
+ oldCheckpointNumber,
690
+ newCheckpointNumber,
691
+ thresholdForEpochPrune,
692
+ });
686
693
  }
687
694
  return isEpochPrune;
688
695
  }
689
696
 
690
697
  /** Checks if the slot has changed and calls prepareForSlot if so. */
691
698
  private async maybeCallPrepareForSlot(): Promise<void> {
692
- const { currentSlot } = this.epochCache.getCurrentAndNextSlot();
693
- if (currentSlot <= this.lastSlotProcessed) {
699
+ // If we have a pending checkpoint available, we want to prepare the target slot - otherwise we prepare the current slot
700
+ // Knowledege of pending checkpoints is in the PR above
701
+ const { targetSlot } = this.epochCache.getTargetAndNextSlot();
702
+ if (targetSlot <= this.lastSlotProcessed) {
694
703
  return;
695
704
  }
696
- this.lastSlotProcessed = currentSlot;
697
- await this.txPool.prepareForSlot(currentSlot);
705
+ this.lastSlotProcessed = targetSlot;
706
+ await this.txPool.prepareForSlot(targetSlot);
698
707
  }
699
708
 
700
709
  private async startServiceIfSynched() {
@@ -3,11 +3,11 @@ import { SecretValue } from '@aztec/foundation/config';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { sleep } from '@aztec/foundation/sleep';
5
5
  import { DateProvider, Timer, executeTimeout } from '@aztec/foundation/timer';
6
- import type { DataStoreConfig } from '@aztec/kv-store/config';
7
6
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
8
7
  import type { L2BlockSource } from '@aztec/stdlib/block';
9
8
  import type { ContractDataSource } from '@aztec/stdlib/contract';
10
9
  import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
10
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
11
11
  import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
12
12
  import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
13
13
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
@@ -19,7 +19,7 @@ import type { P2PConfig } from '../../../config.js';
19
19
  import { BatchTxRequesterCollector, SendBatchRequestCollector } from '../../../services/index.js';
20
20
  import type { IBatchRequestTxValidator } from '../../../services/reqresp/batch-tx-requester/tx_validator.js';
21
21
  import { RateLimitStatus } from '../../../services/reqresp/rate-limiter/rate_limiter.js';
22
- import { MissingTxsTracker } from '../../../services/tx_collection/missing_txs_tracker.js';
22
+ import { RequestTracker } from '../../../services/tx_collection/request_tracker.js';
23
23
  import {
24
24
  AlwaysTrueCircuitVerifier,
25
25
  BENCHMARK_CONSTANTS,
@@ -213,10 +213,9 @@ async function runCollector(cmd: Extract<WorkerCommand, { type: 'RUN_COLLECTOR'
213
213
  const fetched = await executeTimeout(
214
214
  (_signal: AbortSignal) =>
215
215
  collector.collectTxs(
216
- MissingTxsTracker.fromArray(parsedTxHashes),
216
+ RequestTracker.create(parsedTxHashes, new Date(Date.now() + internalTimeoutMs)),
217
217
  parsedProposal,
218
218
  pinnedPeer,
219
- internalTimeoutMs,
220
219
  ),
221
220
  timeoutMs,
222
221
  () => new Error(`Collector timed out after ${timeoutMs}ms`),
@@ -231,10 +230,9 @@ async function runCollector(cmd: Extract<WorkerCommand, { type: 'RUN_COLLECTOR'
231
230
  const fetched = await executeTimeout(
232
231
  (_signal: AbortSignal) =>
233
232
  collector.collectTxs(
234
- MissingTxsTracker.fromArray(parsedTxHashes),
233
+ RequestTracker.create(parsedTxHashes, new Date(Date.now() + internalTimeoutMs)),
235
234
  parsedProposal,
236
235
  pinnedPeer,
237
- internalTimeoutMs,
238
236
  ),
239
237
  timeoutMs,
240
238
  () => new Error(`Collector timed out after ${timeoutMs}ms`),
package/src/config.ts CHANGED
@@ -11,7 +11,6 @@ import {
11
11
  secretStringConfigHelper,
12
12
  } from '@aztec/foundation/config';
13
13
  import { Fr } from '@aztec/foundation/curves/bn254';
14
- import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
15
14
  import { FunctionSelector } from '@aztec/stdlib/abi/function-selector';
16
15
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
17
16
  import {
@@ -21,6 +20,7 @@ import {
21
20
  chainConfigMappings,
22
21
  sharedSequencerConfigMappings,
23
22
  } from '@aztec/stdlib/config';
23
+ import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
24
24
 
25
25
  import {
26
26
  type BatchTxRequesterConfig,
@@ -70,6 +70,9 @@ export interface P2PConfig
70
70
  /** The frequency in which to check for new peers. */
71
71
  peerCheckIntervalMS: number;
72
72
 
73
+ /** How long to ban a peer after it fails MAX_DIAL_ATTEMPTS dials. */
74
+ peerFailedBanTimeMs: number;
75
+
73
76
  /** Size of queue of L2 blocks to store. */
74
77
  l2QueueSize: number;
75
78
 
@@ -186,10 +189,7 @@ export interface P2PConfig
186
189
  /** Whether transactions are disabled for this node. This means transactions will be rejected at the RPC and P2P layers. */
187
190
  disableTransactions: boolean;
188
191
 
189
- /** True to simulate discarding transactions. - For testing purposes only*/
190
- dropTransactions: boolean;
191
-
192
- /** The probability that a transaction is discarded. - For testing purposes only */
192
+ /** The probability that a transaction is discarded (0 = disabled). - For testing purposes only */
193
193
  dropTransactionsProbability: number;
194
194
 
195
195
  /** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
@@ -266,6 +266,11 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
266
266
  description: 'The frequency in which to check for new peers.',
267
267
  ...numberConfigHelper(30_000),
268
268
  },
269
+ peerFailedBanTimeMs: {
270
+ env: 'P2P_PEER_FAILED_BAN_TIME_MS',
271
+ description: 'How long to ban a peer after it fails maximum dial attempts.',
272
+ ...numberConfigHelper(5 * 60 * 1000),
273
+ },
269
274
  l2QueueSize: {
270
275
  env: 'P2P_L2_QUEUE_SIZE',
271
276
  description: 'Size of queue of L2 blocks to store.',
@@ -469,11 +474,6 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
469
474
  description: 'Number of auth attempts to allow before peer is banned. Number is inclusive',
470
475
  ...numberConfigHelper(3),
471
476
  },
472
- dropTransactions: {
473
- env: 'P2P_DROP_TX',
474
- description: 'True to simulate discarding transactions. - For testing purposes only',
475
- ...booleanConfigHelper(false),
476
- },
477
477
  dropTransactionsProbability: {
478
478
  env: 'P2P_DROP_TX_CHANCE',
479
479
  description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
@@ -26,10 +26,10 @@ export type TryAddResult = {
26
26
  count: number;
27
27
  };
28
28
 
29
- export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 5;
30
- export const MAX_BLOCK_PROPOSALS_PER_POSITION = 3;
29
+ export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 2;
30
+ export const MAX_BLOCK_PROPOSALS_PER_POSITION = 2;
31
31
  /** Maximum attestations a single signer can make per slot before being rejected. */
32
- export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 3;
32
+ export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 2;
33
33
 
34
34
  /** Public API interface for attestation pools. Used for typing mocks and test implementations. */
35
35
  export type AttestationPoolApi = Pick<
@@ -359,11 +359,10 @@ export class AttestationPool {
359
359
  }
360
360
 
361
361
  const address = sender.toString();
362
+ const ownKey = this.getAttestationKey(slotNumber, proposalId, address);
362
363
 
363
- await this.checkpointAttestations.set(
364
- this.getAttestationKey(slotNumber, proposalId, address),
365
- attestation.toBuffer(),
366
- );
364
+ await this.checkpointAttestations.set(ownKey, attestation.toBuffer());
365
+ this.metrics.trackMempoolItemAdded(ownKey);
367
366
 
368
367
  this.log.debug(`Added own checkpoint attestation for slot ${slotNumber} from ${address}`, {
369
368
  signature: attestation.signature.toString(),
@@ -429,6 +428,7 @@ export class AttestationPool {
429
428
  const attestationEndKey = new Fr(oldestSlot).toString();
430
429
  for await (const key of this.checkpointAttestations.keysAsync({ end: attestationEndKey })) {
431
430
  await this.checkpointAttestations.delete(key);
431
+ this.metrics.trackMempoolItemRemoved(key);
432
432
  numberOfAttestations++;
433
433
  }
434
434
 
@@ -526,6 +526,7 @@ export class AttestationPool {
526
526
 
527
527
  // Add the attestation
528
528
  await this.checkpointAttestations.set(key, attestation.toBuffer());
529
+ this.metrics.trackMempoolItemAdded(key);
529
530
 
530
531
  // Track this attestation in the per-signer-per-slot index for duplicate detection
531
532
  const slotSignerKey = this.getSlotSignerKey(slotNumber, signerAddress);
@@ -446,12 +446,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
446
446
  const result2 = await ap.tryAddBlockProposal(proposal2);
447
447
  expect(result2.count).toBe(2);
448
448
 
449
- // Add a third proposal for same position
449
+ // Third proposal for same position should be rejected (cap is 2)
450
450
  const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
451
451
  const result3 = await ap.tryAddBlockProposal(proposal3);
452
452
 
453
- expect(result3.added).toBe(true);
454
- expect(result3.count).toBe(3);
453
+ expect(result3.added).toBe(false);
454
+ expect(result3.count).toBe(2);
455
455
  });
456
456
 
457
457
  it('should return added=false when exceeding capacity', async () => {
@@ -666,12 +666,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
666
666
  const result2 = await ap.tryAddCheckpointProposal(proposal2);
667
667
  expect(result2.count).toBe(2);
668
668
 
669
- // Add a third proposal for same slot
669
+ // Third proposal for same slot should be rejected (cap is 2)
670
670
  const proposal3 = await mockCheckpointProposalCoreForPool(signers[2], slotNumber);
671
671
  const result3 = await ap.tryAddCheckpointProposal(proposal3);
672
672
 
673
- expect(result3.added).toBe(true);
674
- expect(result3.count).toBe(3);
673
+ expect(result3.added).toBe(false);
674
+ expect(result3.count).toBe(2);
675
675
  });
676
676
 
677
677
  it('should not count attestations as proposals for duplicate detection', async () => {
@@ -73,7 +73,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
73
73
  private defaultAttributes;
74
74
  private meter: Meter;
75
75
 
76
- private txAddedTimestamp: Map<bigint, number> = new Map<bigint, number>();
76
+ private mempoolItemAddedTimestamp: Map<bigint | string, number> = new Map<bigint | string, number>();
77
77
 
78
78
  constructor(
79
79
  telemetry: TelemetryClient,
@@ -114,22 +114,26 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
114
114
  }
115
115
 
116
116
  public transactionsAdded(transactions: Tx[]) {
117
- const timestamp = Date.now();
118
- for (const transaction of transactions) {
119
- this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
120
- }
117
+ transactions.forEach(tx => this.trackMempoolItemAdded(tx.txHash.toBigInt()));
121
118
  }
122
119
 
123
120
  public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
124
- const timestamp = Date.now();
125
121
  for (const hash of hashes) {
126
- const key = BigInt(hash);
127
- const addedAt = this.txAddedTimestamp.get(key);
128
- if (addedAt !== undefined) {
129
- this.txAddedTimestamp.delete(key);
130
- if (addedAt < timestamp) {
131
- this.minedDelay.record(timestamp - addedAt);
132
- }
122
+ this.trackMempoolItemRemoved(BigInt(hash));
123
+ }
124
+ }
125
+
126
+ public trackMempoolItemAdded(key: bigint | string): void {
127
+ this.mempoolItemAddedTimestamp.set(key, Date.now());
128
+ }
129
+
130
+ public trackMempoolItemRemoved(key: bigint | string): void {
131
+ const timestamp = Date.now();
132
+ const addedAt = this.mempoolItemAddedTimestamp.get(key);
133
+ if (addedAt !== undefined) {
134
+ this.mempoolItemAddedTimestamp.delete(key);
135
+ if (addedAt < timestamp) {
136
+ this.minedDelay.record(timestamp - addedAt);
133
137
  }
134
138
  }
135
139
  }
@@ -32,10 +32,11 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
32
32
 
33
33
  if (context.event === EvictionEvent.BLOCK_MINED) {
34
34
  const blockNumber = context.block.getBlockNumber();
35
+ const blockHash = await context.block.hash();
35
36
  // Ensure world state is synced to this block before accessing the snapshot.
36
37
  // This handles the race where a block is added to the archiver
37
38
  // but the world state hasn't synced it yet.
38
- await this.worldState.syncImmediate(blockNumber);
39
+ await this.worldState.syncImmediate(blockNumber, blockHash);
39
40
  return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), txPool);
40
41
  }
41
42
 
@@ -29,7 +29,8 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
29
29
 
30
30
  if (context.event === EvictionEvent.BLOCK_MINED) {
31
31
  const blockNumber = context.block.getBlockNumber();
32
- await this.worldState.syncImmediate(blockNumber);
32
+ const blockHash = await context.block.hash();
33
+ await this.worldState.syncImmediate(blockNumber, blockHash);
33
34
  return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), pool);
34
35
  }
35
36
 
@@ -44,6 +44,8 @@ export type TxPoolV2Config = {
44
44
  minTxPoolAgeMs: number;
45
45
  /** Maximum number of evicted tx hashes to remember for metrics tracking */
46
46
  evictedTxCacheSize: number;
47
+ /** The probability (0-1) that a transaction is discarded. 0 disables dropping. For testing purposes only. */
48
+ dropTransactionsProbability: number;
47
49
  /** Minimum percentage fee increase required to replace an existing tx via RPC (0 = no bump). */
48
50
  priceBumpPercentage: bigint;
49
51
  };
@@ -56,6 +58,7 @@ export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
56
58
  archivedTxLimit: 0, // 0 = disabled
57
59
  minTxPoolAgeMs: 2_000,
58
60
  evictedTxCacheSize: 10_000,
61
+ dropTransactionsProbability: 0,
59
62
  priceBumpPercentage: 10n,
60
63
  };
61
64
 
@@ -69,6 +72,8 @@ export type TxPoolV2Dependencies = {
69
72
  worldStateSynchronizer: WorldStateSynchronizer;
70
73
  /** Factory that creates a validator for re-validating pool transactions using metadata */
71
74
  createTxValidator: () => Promise<TxValidator<TxMetaData>>;
75
+ /** Checks whether a tx's setup-phase calls are on the allow list. Precomputed at receipt time. */
76
+ checkAllowedSetupCalls: (tx: Tx) => Promise<boolean>;
72
77
  };
73
78
 
74
79
  /**
@@ -155,10 +160,10 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
155
160
  handleMinedBlock(block: L2Block): Promise<void>;
156
161
 
157
162
  /**
158
- * Prepares the pool for a new slot.
159
- * Unprotects transactions from earlier slots and validates them before
160
- * returning to pending state.
161
- * @param slotNumber - The slot number to prepare for
163
+ * Prepares the pool for a new slot by unprotecting transactions from earlier
164
+ * slots and re-validating them before returning to pending state.
165
+ * @param slotNumber - The pipeline slot we are building for (i.e. the slot
166
+ * the resulting blocks will target on L1).
162
167
  */
163
168
  prepareForSlot(slotNumber: SlotNumber): Promise<void>;
164
169
 
@@ -67,6 +67,9 @@ export type TxMetaData = {
67
67
  /** Timestamp by which the transaction must be included (for expiration checks) */
68
68
  readonly expirationTimestamp: bigint;
69
69
 
70
+ /** Whether the tx's setup-phase calls pass the allow list check. Computed at receipt time. */
71
+ readonly allowedSetupCalls: boolean;
72
+
70
73
  /** Validator-compatible data, providing the same access patterns as Tx.data */
71
74
  readonly data: TxMetaValidationData;
72
75
 
@@ -84,8 +87,12 @@ export type TxState = 'pending' | 'protected' | 'mined' | 'deleted';
84
87
  * Builds TxMetaData from a full Tx object.
85
88
  * Extracts all relevant fields for efficient in-memory storage and querying.
86
89
  * Fr values are captured in closures for zero-cost re-validation.
90
+ *
91
+ * @param allowedSetupCalls - Whether the tx's setup-phase calls pass the allow list.
92
+ * For gossip/RPC txs this is always `true` (already validated by PhasesTxValidator).
93
+ * For req/resp txs this should be computed by the caller using the phases validator.
87
94
  */
88
- export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
95
+ export async function buildTxMetaData(tx: Tx, allowedSetupCalls: boolean = true): Promise<TxMetaData> {
89
96
  const txHashObj = tx.getTxHash();
90
97
  const txHash = txHashObj.toString();
91
98
  const txHashBigInt = txHashObj.toBigInt();
@@ -112,6 +119,7 @@ export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
112
119
  feeLimit,
113
120
  nullifiers,
114
121
  expirationTimestamp,
122
+ allowedSetupCalls,
115
123
  receivedAt: 0,
116
124
  estimatedSizeBytes,
117
125
  data: {
@@ -158,13 +166,13 @@ export function txHashFromBigInt(value: bigint): string {
158
166
  }
159
167
 
160
168
  /** Minimal fields required for priority comparison. */
161
- type PriorityComparable = Pick<TxMetaData, 'txHashBigInt' | 'priorityFee'>;
169
+ export type PriorityComparable = Pick<TxMetaData, 'txHash' | 'txHashBigInt' | 'priorityFee'>;
162
170
 
163
171
  /**
164
172
  * Compares two priority fees in ascending order.
165
173
  * Returns negative if a < b, positive if a > b, 0 if equal.
166
174
  */
167
- export function compareFee(a: bigint, b: bigint): number {
175
+ export function compareFee(a: bigint, b: bigint): -1 | 0 | 1 {
168
176
  return a < b ? -1 : a > b ? 1 : 0;
169
177
  }
170
178
 
@@ -173,7 +181,7 @@ export function compareFee(a: bigint, b: bigint): number {
173
181
  * Uses field element comparison for deterministic ordering.
174
182
  * Returns negative if a < b, positive if a > b, 0 if equal.
175
183
  */
176
- export function compareTxHash(a: bigint, b: bigint): number {
184
+ export function compareTxHash(a: bigint, b: bigint): -1 | 0 | 1 {
177
185
  return Fr.cmpAsBigInt(a, b);
178
186
  }
179
187
 
@@ -182,7 +190,7 @@ export function compareTxHash(a: bigint, b: bigint): number {
182
190
  * Returns negative if a < b, positive if a > b, 0 if equal.
183
191
  * Use with sort() for ascending order, or negate/reverse for descending.
184
192
  */
185
- export function comparePriority(a: PriorityComparable, b: PriorityComparable): number {
193
+ export function comparePriority(a: PriorityComparable, b: PriorityComparable): -1 | 0 | 1 {
186
194
  const feeComparison = compareFee(a.priorityFee, b.priorityFee);
187
195
  if (feeComparison !== 0) {
188
196
  return feeComparison;
@@ -304,6 +312,7 @@ export function stubTxMetaData(
304
312
  nullifiers?: string[];
305
313
  expirationTimestamp?: bigint;
306
314
  anchorBlockHeaderHash?: string;
315
+ allowedSetupCalls?: boolean;
307
316
  } = {},
308
317
  ): TxMetaData {
309
318
  const txHashBigInt = Fr.fromHexString(txHash).toBigInt();
@@ -320,6 +329,7 @@ export function stubTxMetaData(
320
329
  feeLimit: overrides.feeLimit ?? 100n,
321
330
  nullifiers: overrides.nullifiers ?? [`0x${normalizedTxHash.slice(2)}null1`],
322
331
  expirationTimestamp,
332
+ allowedSetupCalls: overrides.allowedSetupCalls ?? true,
323
333
  receivedAt: 0,
324
334
  estimatedSizeBytes: 0,
325
335
  data: stubTxMetaValidationData({ expirationTimestamp }),