@aztec/p2p 0.0.1-commit.7ac86ea28 → 0.0.1-commit.7b86788

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 (124) hide show
  1. package/dest/client/factory.d.ts +4 -5
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +15 -26
  4. package/dest/client/interface.d.ts +6 -13
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +5 -13
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +3 -58
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -2
  10. package/dest/config.d.ts +2 -5
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +0 -5
  13. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +1 -1
  14. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
  15. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  16. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
  17. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
  18. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  19. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  20. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +10 -6
  21. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  22. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  23. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  24. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
  25. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  26. package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
  27. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +26 -4
  28. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  29. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +48 -7
  30. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
  31. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  32. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +9 -10
  33. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +2 -2
  34. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  35. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -2
  36. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +173 -146
  38. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  39. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  40. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  41. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  42. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  43. package/dest/msg_validators/tx_validator/factory.js +219 -58
  44. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  45. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  46. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  47. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  48. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  49. package/dest/msg_validators/tx_validator/index.js +1 -0
  50. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  51. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  52. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  53. package/dest/services/dummy_service.d.ts +2 -3
  54. package/dest/services/dummy_service.d.ts.map +1 -1
  55. package/dest/services/dummy_service.js +1 -4
  56. package/dest/services/encoding.d.ts +2 -2
  57. package/dest/services/encoding.d.ts.map +1 -1
  58. package/dest/services/encoding.js +7 -7
  59. package/dest/services/libp2p/libp2p_service.d.ts +15 -13
  60. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  61. package/dest/services/libp2p/libp2p_service.js +64 -80
  62. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -1
  63. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  64. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +14 -37
  65. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  66. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  67. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  68. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  69. package/dest/services/reqresp/reqresp.d.ts +1 -1
  70. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  71. package/dest/services/reqresp/reqresp.js +2 -1
  72. package/dest/services/service.d.ts +2 -2
  73. package/dest/services/service.d.ts.map +1 -1
  74. package/dest/services/tx_provider.d.ts +3 -3
  75. package/dest/services/tx_provider.d.ts.map +1 -1
  76. package/dest/services/tx_provider.js +4 -4
  77. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  78. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  79. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  80. package/dest/test-helpers/mock-pubsub.d.ts +2 -3
  81. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  82. package/dest/test-helpers/mock-pubsub.js +2 -2
  83. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  84. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  85. package/dest/test-helpers/reqresp-nodes.js +2 -2
  86. package/dest/test-helpers/testbench-utils.d.ts +2 -2
  87. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  88. package/dest/testbench/p2p_client_testbench_worker.js +5 -5
  89. package/package.json +14 -14
  90. package/src/client/factory.ts +22 -46
  91. package/src/client/interface.ts +5 -19
  92. package/src/client/p2p_client.ts +4 -88
  93. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -2
  94. package/src/config.ts +1 -9
  95. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +1 -1
  96. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
  97. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +2 -2
  98. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +10 -6
  99. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  100. package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
  101. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +65 -10
  102. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +11 -11
  103. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +1 -1
  104. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +179 -148
  105. package/src/msg_validators/tx_validator/README.md +115 -0
  106. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  107. package/src/msg_validators/tx_validator/factory.ts +353 -77
  108. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  109. package/src/msg_validators/tx_validator/index.ts +1 -0
  110. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  111. package/src/services/dummy_service.ts +1 -5
  112. package/src/services/encoding.ts +5 -6
  113. package/src/services/libp2p/libp2p_service.ts +75 -90
  114. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +14 -42
  115. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  116. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  117. package/src/services/reqresp/reqresp.ts +3 -1
  118. package/src/services/service.ts +1 -1
  119. package/src/services/tx_provider.ts +2 -2
  120. package/src/test-helpers/make-test-p2p-clients.ts +0 -2
  121. package/src/test-helpers/mock-pubsub.ts +3 -6
  122. package/src/test-helpers/reqresp-nodes.ts +2 -5
  123. package/src/test-helpers/testbench-utils.ts +1 -1
  124. package/src/testbench/p2p_client_testbench_worker.ts +2 -6
@@ -1,15 +1,14 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { DateProvider } from '@aztec/foundation/timer';
4
5
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
6
  import type { DataStoreConfig } from '@aztec/kv-store/config';
6
7
  import { AztecLMDBStoreV2, createStore } from '@aztec/kv-store/lmdb-v2';
7
- import type { BlockHash, L2BlockSource } from '@aztec/stdlib/block';
8
+ import type { L2BlockSource } from '@aztec/stdlib/block';
8
9
  import type { ChainConfig } from '@aztec/stdlib/config';
9
10
  import type { ContractDataSource } from '@aztec/stdlib/contract';
10
11
  import type { AztecNode, ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
11
- import { P2PClientType } from '@aztec/stdlib/p2p';
12
- import { MerkleTreeId } from '@aztec/stdlib/trees';
13
12
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
14
13
 
15
14
  import { P2PClient } from '../client/p2p_client.js';
@@ -17,11 +16,8 @@ import type { P2PConfig } from '../config.js';
17
16
  import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
18
17
  import type { MemPools } from '../mem_pools/interface.js';
19
18
  import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
20
- import type { TxMetaData } from '../mem_pools/tx_pool_v2/tx_metadata.js';
21
19
  import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
22
- import { AggregateTxValidator } from '../msg_validators/tx_validator/aggregate_tx_validator.js';
23
- import { BlockHeaderTxValidator } from '../msg_validators/tx_validator/block_header_validator.js';
24
- import { DoubleSpendTxValidator } from '../msg_validators/tx_validator/double_spend_validator.js';
20
+ import { createTxValidatorForTransactionsEnteringPendingTxPool } from '../msg_validators/index.js';
25
21
  import { DummyP2PService } from '../services/dummy_service.js';
26
22
  import { LibP2PService } from '../services/index.js';
27
23
  import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
@@ -30,14 +26,14 @@ import { NodeRpcTxSource, type TxSource, createNodeRpcTxSources } from '../servi
30
26
  import { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
31
27
  import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';
32
28
 
33
- export type P2PClientDeps<T extends P2PClientType> = {
29
+ export type P2PClientDeps = {
34
30
  txPool?: TxPoolV2;
35
31
  store?: AztecAsyncKVStore;
36
32
  attestationPool?: AttestationPoolApi;
37
33
  logger?: Logger;
38
34
  txCollectionNodeSources?: TxSource[];
39
35
  rpcTxProviders?: AztecNode[];
40
- p2pServiceFactory?: (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService<T>>;
36
+ p2pServiceFactory?: (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService>;
41
37
  };
42
38
 
43
39
  export const P2P_STORE_NAME = 'p2p';
@@ -45,8 +41,7 @@ export const P2P_ARCHIVE_STORE_NAME = 'p2p-archive';
45
41
  export const P2P_PEER_STORE_NAME = 'p2p-peers';
46
42
  export const P2P_ATTESTATION_STORE_NAME = 'p2p-attestation';
47
43
 
48
- export async function createP2PClient<T extends P2PClientType>(
49
- clientType: T,
44
+ export async function createP2PClient(
50
45
  inputConfig: P2PConfig & DataStoreConfig & ChainConfig,
51
46
  archiver: L2BlockSource & ContractDataSource,
52
47
  proofVerifier: ClientProtocolCircuitVerifier,
@@ -55,7 +50,7 @@ export async function createP2PClient<T extends P2PClientType>(
55
50
  packageVersion: string,
56
51
  dateProvider: DateProvider = new DateProvider(),
57
52
  telemetry: TelemetryClient = getTelemetryClient(),
58
- deps: P2PClientDeps<T> = {},
53
+ deps: P2PClientDeps = {},
59
54
  ) {
60
55
  const config = await configureP2PClientAddresses({
61
56
  ...inputConfig,
@@ -80,32 +75,6 @@ export async function createP2PClient<T extends P2PClientType>(
80
75
  const rollupAddress = inputConfig.l1Contracts.rollupAddress.toString().toLowerCase().replace(/^0x/, '');
81
76
  const txFileStoreBasePath = `aztec-${inputConfig.l1ChainId}-${inputConfig.rollupVersion}-0x${rollupAddress}`;
82
77
 
83
- /** Validator factory for pool re-validation (double-spend + block header only). */
84
- const createPoolTxValidator = async () => {
85
- await worldStateSynchronizer.syncImmediate();
86
- return new AggregateTxValidator<TxMetaData>(
87
- new DoubleSpendTxValidator<TxMetaData>(
88
- {
89
- nullifiersExist: async (nullifiers: Buffer[]) => {
90
- const merkleTree = worldStateSynchronizer.getCommitted();
91
- const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
92
- return indices.map(index => index !== undefined);
93
- },
94
- },
95
- bindings,
96
- ),
97
- new BlockHeaderTxValidator<TxMetaData>(
98
- {
99
- getArchiveIndices: (archives: BlockHash[]) => {
100
- const merkleTree = worldStateSynchronizer.getCommitted();
101
- return merkleTree.findLeafIndices(MerkleTreeId.ARCHIVE, archives);
102
- },
103
- },
104
- bindings,
105
- ),
106
- );
107
- };
108
-
109
78
  const txPool =
110
79
  deps.txPool ??
111
80
  new AztecKVTxPoolV2(
@@ -114,13 +83,23 @@ export async function createP2PClient<T extends P2PClientType>(
114
83
  {
115
84
  l2BlockSource: archiver,
116
85
  worldStateSynchronizer,
117
- createTxValidator: createPoolTxValidator,
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
+ return createTxValidatorForTransactionsEnteringPendingTxPool(
91
+ worldStateSynchronizer,
92
+ nextSlotTimestamp,
93
+ BlockNumber(currentBlockNumber + 1),
94
+ );
95
+ },
118
96
  },
119
97
  telemetry,
120
98
  {
121
99
  maxPendingTxCount: config.maxPendingTxCount,
122
100
  archivedTxLimit: config.archivedTxLimit,
123
101
  minTxPoolAgeMs: config.minTxPoolAgeMs,
102
+ dropTransactionsProbability: config.dropTransactionsProbability,
124
103
  },
125
104
  dateProvider,
126
105
  );
@@ -130,9 +109,8 @@ export async function createP2PClient<T extends P2PClientType>(
130
109
  attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry),
131
110
  };
132
111
 
133
- const p2pService = await createP2PService<T>(
112
+ const p2pService = await createP2PService(
134
113
  config,
135
- clientType,
136
114
  archiver,
137
115
  proofVerifier,
138
116
  worldStateSynchronizer,
@@ -190,7 +168,6 @@ export async function createP2PClient<T extends P2PClientType>(
190
168
  );
191
169
 
192
170
  return new P2PClient(
193
- clientType,
194
171
  store,
195
172
  archiver,
196
173
  mempools,
@@ -204,9 +181,8 @@ export async function createP2PClient<T extends P2PClientType>(
204
181
  );
205
182
  }
206
183
 
207
- async function createP2PService<T extends P2PClientType>(
184
+ async function createP2PService(
208
185
  config: P2PConfig & DataStoreConfig,
209
- clientType: T,
210
186
  archiver: L2BlockSource & ContractDataSource,
211
187
  proofVerifier: ClientProtocolCircuitVerifier,
212
188
  worldStateSynchronizer: WorldStateSynchronizer,
@@ -214,7 +190,7 @@ async function createP2PService<T extends P2PClientType>(
214
190
  store: AztecAsyncKVStore,
215
191
  peerStore: AztecLMDBStoreV2,
216
192
  mempools: MemPools,
217
- p2pServiceFactory: P2PClientDeps<T>['p2pServiceFactory'],
193
+ p2pServiceFactory: P2PClientDeps['p2pServiceFactory'],
218
194
  packageVersion: string,
219
195
  logger: Logger,
220
196
  telemetry: TelemetryClient,
@@ -230,7 +206,7 @@ async function createP2PService<T extends P2PClientType>(
230
206
  const peerIdPrivateKey = await getPeerIdPrivateKey(config, store, logger);
231
207
  const peerId = await createLibP2PPeerIdFromPrivateKey(peerIdPrivateKey.getValue());
232
208
 
233
- const p2pService = await (p2pServiceFactory ?? LibP2PService.new<T>)(clientType, config, peerId, {
209
+ const p2pService = await (p2pServiceFactory ?? LibP2PService.new)(config, peerId, {
234
210
  packageVersion,
235
211
  mempools,
236
212
  l2BlockSource: archiver,
@@ -1,13 +1,7 @@
1
1
  import type { SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
3
- import type { ITxProvider, P2PApiFull } from '@aztec/stdlib/interfaces/server';
4
- import type {
5
- BlockProposal,
6
- CheckpointAttestation,
7
- CheckpointProposal,
8
- P2PClientType,
9
- TopicType,
10
- } from '@aztec/stdlib/p2p';
3
+ import type { ITxProvider, P2PClient } from '@aztec/stdlib/interfaces/server';
4
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
11
5
  import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
12
6
 
13
7
  import type { PeerId } from '@libp2p/interface';
@@ -54,7 +48,7 @@ export interface P2PSyncState {
54
48
  /**
55
49
  * Interface of a P2P client.
56
50
  **/
57
- export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> & {
51
+ export type P2P = P2PClient & {
58
52
  /**
59
53
  * Broadcasts a block proposal to other peers.
60
54
  *
@@ -140,14 +134,6 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
140
134
  */
141
135
  hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]>;
142
136
 
143
- /**
144
- * Returns transactions in the transaction pool by hash, requesting from the network if not found.
145
- * @param txHashes - Hashes of tx to return.
146
- * @param pinnedPeerId - An optional peer id that will be used to request the tx from (in addition to other random peers).
147
- * @returns An array of tx or undefined.
148
- */
149
- getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]>;
150
-
151
137
  /**
152
138
  * Returns an archived transaction from the transaction pool by its hash.
153
139
  * @param txHash - Hash of tx to return.
@@ -224,8 +210,8 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
224
210
 
225
211
  updateP2PConfig(config: Partial<P2PConfig>): Promise<void>;
226
212
 
227
- /** Validates a set of txs. */
228
- validate(txs: Tx[]): Promise<void>;
213
+ /** Validates a set of txs received in a block proposal. */
214
+ validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void>;
229
215
 
230
216
  /** Clears the db. */
231
217
  clear(): Promise<void>;
@@ -20,13 +20,7 @@ import {
20
20
  import type { ContractDataSource } from '@aztec/stdlib/contract';
21
21
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
22
22
  import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
23
- import {
24
- type BlockProposal,
25
- CheckpointAttestation,
26
- type CheckpointProposal,
27
- type P2PClientType,
28
- type TopicType,
29
- } from '@aztec/stdlib/p2p';
23
+ import { type BlockProposal, CheckpointAttestation, type CheckpointProposal, type TopicType } from '@aztec/stdlib/p2p';
30
24
  import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
31
25
  import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
32
26
 
@@ -44,7 +38,6 @@ import {
44
38
  type ReqRespSubProtocolHandler,
45
39
  type ReqRespSubProtocolValidators,
46
40
  } from '../services/reqresp/interface.js';
47
- import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
48
41
  import type {
49
42
  DuplicateAttestationInfo,
50
43
  DuplicateProposalInfo,
@@ -60,10 +53,7 @@ import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
60
53
  /**
61
54
  * The P2P client implementation.
62
55
  */
63
- export class P2PClient<T extends P2PClientType = P2PClientType.Full>
64
- extends WithTracer
65
- implements P2P, P2P<P2PClientType.Prover>
66
- {
56
+ export class P2PClient extends WithTracer implements P2P {
67
57
  /** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */
68
58
  private runningPromise!: Promise<void>;
69
59
 
@@ -95,7 +85,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
95
85
  private slotMonitor: RunningPromise | undefined;
96
86
 
97
87
  constructor(
98
- _clientType: T,
99
88
  private store: AztecAsyncKVStore,
100
89
  private l2BlockSource: L2BlockSource & ContractDataSource,
101
90
  mempools: MemPools,
@@ -433,36 +422,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
433
422
  this.p2pService.registerDuplicateAttestationCallback(callback);
434
423
  }
435
424
 
436
- /**
437
- * Uses the batched Request Response protocol to request a set of transactions from the network.
438
- */
439
- private async requestTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<Tx[]> {
440
- const timeoutMs = 8000; // Longer timeout for now
441
- const maxRetryAttempts = 10; // Keep retrying within the timeout
442
- const requests = chunkTxHashesRequest(txHashes);
443
- const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
444
-
445
- const txBatches = await this.p2pService.sendBatchRequest(
446
- ReqRespSubProtocol.TX,
447
- requests,
448
- pinnedPeerId,
449
- timeoutMs,
450
- maxPeers,
451
- maxRetryAttempts,
452
- );
453
-
454
- const txs = txBatches.flat();
455
- if (txs.length > 0) {
456
- await this.txPool.addPendingTxs(txs);
457
- }
458
-
459
- const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
460
- this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
461
-
462
- // We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
463
- return txs;
464
- }
465
-
466
425
  public async getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
467
426
  if (limit !== undefined && limit <= 0) {
468
427
  throw new TypeError('limit must be greater than 0');
@@ -530,49 +489,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
530
489
  return this.txPool.hasTxs(txHashes);
531
490
  }
532
491
 
533
- /**
534
- * Returns transactions in the transaction pool by hash.
535
- * If a transaction is not in the pool, it will be requested from the network.
536
- * @param txHashes - Hashes of the transactions to look for.
537
- * @returns The txs found, or undefined if not found in the order requested.
538
- */
539
- async getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]> {
540
- const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
541
- const missingTxHashes = txs
542
- .map((tx, index) => [tx, index] as const)
543
- .filter(([tx, _index]) => !tx)
544
- .map(([_tx, index]) => txHashes[index]);
545
-
546
- if (missingTxHashes.length === 0) {
547
- return txs as Tx[];
548
- }
549
-
550
- const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
551
- // TODO: optimize
552
- // Merge the found txs in order
553
- const mergingTxs = txHashes.map(txHash => {
554
- // Is it in the txs list from the mempool?
555
- for (const tx of txs) {
556
- if (tx !== undefined && tx.getTxHash().equals(txHash)) {
557
- return tx;
558
- }
559
- }
560
-
561
- // Is it in the fetched missing txs?
562
- // Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
563
- for (const tx of missingTxs) {
564
- if (tx.getTxHash().equals(txHash)) {
565
- return tx;
566
- }
567
- }
568
-
569
- // Otherwise return undefined
570
- return undefined;
571
- });
572
-
573
- return mergingTxs;
574
- }
575
-
576
492
  /**
577
493
  * Returns an archived transaction in the transaction pool by its hash.
578
494
  * @param txHash - Hash of the archived transaction to look for.
@@ -839,8 +755,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
839
755
  this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
840
756
  }
841
757
 
842
- public validate(txs: Tx[]): Promise<void> {
843
- return this.p2pService.validate(txs);
758
+ public validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
759
+ return this.p2pService.validateTxsReceivedInBlockProposal(txs);
844
760
  }
845
761
 
846
762
  /**
@@ -8,7 +8,7 @@ import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
8
8
  import type { L2BlockSource } from '@aztec/stdlib/block';
9
9
  import type { ContractDataSource } from '@aztec/stdlib/contract';
10
10
  import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
11
- import { P2PClientType, PeerErrorSeverity } from '@aztec/stdlib/p2p';
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';
14
14
 
@@ -114,7 +114,6 @@ async function startClient(config: P2PConfig, clientIndex: number) {
114
114
  };
115
115
 
116
116
  client = await createP2PClient(
117
- P2PClientType.Full,
118
117
  config as P2PConfig & DataStoreConfig,
119
118
  l2BlockSource as L2BlockSource & ContractDataSource,
120
119
  proofVerifier as ClientProtocolCircuitVerifier,
package/src/config.ts CHANGED
@@ -173,10 +173,7 @@ export interface P2PConfig
173
173
  /** Whether transactions are disabled for this node. This means transactions will be rejected at the RPC and P2P layers. */
174
174
  disableTransactions: boolean;
175
175
 
176
- /** True to simulate discarding transactions. - For testing purposes only*/
177
- dropTransactions: boolean;
178
-
179
- /** The probability that a transaction is discarded. - For testing purposes only */
176
+ /** The probability that a transaction is discarded (0 = disabled). - For testing purposes only */
180
177
  dropTransactionsProbability: number;
181
178
 
182
179
  /** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
@@ -430,11 +427,6 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
430
427
  description: 'Number of auth attempts to allow before peer is banned. Number is inclusive',
431
428
  ...numberConfigHelper(3),
432
429
  },
433
- dropTransactions: {
434
- env: 'P2P_DROP_TX',
435
- description: 'True to simulate discarding transactions. - For testing purposes only',
436
- ...booleanConfigHelper(false),
437
- },
438
430
  dropTransactionsProbability: {
439
431
  env: 'P2P_DROP_TX_CHANCE',
440
432
  description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
@@ -34,7 +34,7 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
34
34
  }
35
35
 
36
36
  if (context.event === EvictionEvent.CHAIN_PRUNED) {
37
- await this.worldState.syncImmediate(context.blockNumber);
37
+ await this.worldState.syncImmediate();
38
38
  const feePayers = pool.getPendingFeePayers();
39
39
  return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), pool);
40
40
  }
@@ -35,6 +35,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
35
35
  // Create combined list with incoming tx
36
36
  const allTxs: Array<{
37
37
  txHash: string;
38
+ txHashBigInt: bigint;
38
39
  priorityFee: bigint;
39
40
  feeLimit: bigint;
40
41
  claimAmount: bigint;
@@ -42,6 +43,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
42
43
  }> = [
43
44
  ...existingTxs.map(t => ({
44
45
  txHash: t.txHash,
46
+ txHashBigInt: t.txHashBigInt,
45
47
  priorityFee: t.priorityFee,
46
48
  feeLimit: t.feeLimit,
47
49
  claimAmount: t.claimAmount,
@@ -49,6 +51,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
49
51
  })),
50
52
  {
51
53
  txHash: incomingMeta.txHash,
54
+ txHashBigInt: incomingMeta.txHashBigInt,
52
55
  priorityFee: incomingMeta.priorityFee,
53
56
  feeLimit: incomingMeta.feeLimit,
54
57
  claimAmount: incomingMeta.claimAmount,
@@ -45,8 +45,8 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
45
45
  txsByBlockHash.get(blockHashStr)!.push(meta.txHash);
46
46
  }
47
47
 
48
- // Ensure world state is synced to this block before accessing the snapshot
49
- await this.worldState.syncImmediate(context.blockNumber);
48
+ // Sync without a block number to ensure the world state processes the prune event.
49
+ await this.worldState.syncImmediate();
50
50
  const db = this.worldState.getSnapshot(context.blockNumber);
51
51
 
52
52
  // Check which blocks exist in the archive
@@ -5,7 +5,7 @@ import { EvictionEvent } from './interfaces.js';
5
5
 
6
6
  /**
7
7
  * Eviction rule that removes low-priority transactions when the pool exceeds configured limits.
8
- * Only triggers on TXS_ADDED events.
8
+ * Triggers on TXS_ADDED and CHAIN_PRUNED events.
9
9
  */
10
10
  export class LowPriorityEvictionRule implements EvictionRule {
11
11
  public readonly name = 'LowPriorityEviction';
@@ -18,7 +18,7 @@ export class LowPriorityEvictionRule implements EvictionRule {
18
18
  }
19
19
 
20
20
  async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
21
- if (context.event !== EvictionEvent.TXS_ADDED) {
21
+ if (context.event !== EvictionEvent.TXS_ADDED && context.event !== EvictionEvent.CHAIN_PRUNED) {
22
22
  return {
23
23
  reason: 'low_priority',
24
24
  success: true,
@@ -51,15 +51,19 @@ export class LowPriorityEvictionRule implements EvictionRule {
51
51
  this.log.info(`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${this.maxPoolSize}`);
52
52
  const numberToEvict = currentTxCount - this.maxPoolSize;
53
53
  const txsToEvict = pool.getLowestPriorityPending(numberToEvict);
54
- const toEvictSet = new Set(txsToEvict);
55
- const numNewTxsEvicted = context.newTxHashes.filter(newTxHash => toEvictSet.has(newTxHash)).length;
56
54
 
57
55
  if (txsToEvict.length > 0) {
58
- this.log.info(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`);
56
+ if (context.event === EvictionEvent.TXS_ADDED) {
57
+ const toEvictSet = new Set(txsToEvict);
58
+ const numNewTxsEvicted = context.newTxHashes.filter(newTxHash => toEvictSet.has(newTxHash)).length;
59
+ this.log.info(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`);
60
+ } else {
61
+ this.log.info(`Evicted ${txsToEvict.length} low priority txs after chain prune`);
62
+ }
59
63
  await pool.deleteTxs(txsToEvict, this.name);
60
64
  }
61
65
 
62
- this.log.debug(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`, {
66
+ this.log.debug(`Evicted ${txsToEvict.length} low priority txs`, {
63
67
  txHashes: txsToEvict,
64
68
  });
65
69
 
@@ -7,6 +7,6 @@ export {
7
7
  type PoolReadAccess,
8
8
  DEFAULT_TX_POOL_V2_CONFIG,
9
9
  } from './interfaces.js';
10
- export { type TxMetaData, type TxState, buildTxMetaData, comparePriority } from './tx_metadata.js';
10
+ export { type TxMetaData, type TxState, buildTxMetaData, comparePriority, stubTxMetaData } from './tx_metadata.js';
11
11
  export { TxArchive } from './archive/index.js';
12
12
  export { DeletedPool } from './deleted_pool.js';
@@ -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
  };
48
50
 
49
51
  /**
@@ -54,6 +56,7 @@ export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
54
56
  archivedTxLimit: 0, // 0 = disabled
55
57
  minTxPoolAgeMs: 2_000,
56
58
  evictedTxCacheSize: 10_000,
59
+ dropTransactionsProbability: 0,
57
60
  };
58
61
 
59
62
  /**
@@ -107,12 +110,12 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
107
110
  addPendingTxs(txs: Tx[], opts?: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult>;
108
111
 
109
112
  /**
110
- * Checks if a transaction can be added without modifying the pool.
111
- * Performs the same validation as addPendingTxs but doesn't persist changes.
113
+ * Checks if the pool would accept a transaction without modifying state.
114
+ * Used as a pre-check before expensive proof verification.
112
115
  * @param tx - Transaction to check
113
- * @returns Result: 'accepted', 'ignored' (if already in pool or undesirable), or 'rejected' (if validation fails)
116
+ * @returns 'accepted' if the pool would accept, 'ignored' if already in pool or undesirable
114
117
  */
115
- canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored' | 'rejected'>;
118
+ canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'>;
116
119
 
117
120
  /**
118
121
  * Adds transactions as immediately protected for a given slot.