@aztec/p2p 0.0.1-commit.87a0206 → 0.0.1-commit.8f9871590

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 (213) hide show
  1. package/dest/client/factory.d.ts +3 -3
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +42 -8
  4. package/dest/client/interface.d.ts +30 -15
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +33 -35
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +107 -137
  9. package/dest/config.d.ts +22 -4
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +16 -1
  12. package/dest/index.d.ts +2 -1
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -0
  15. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
  16. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  17. package/dest/mem_pools/attestation_pool/attestation_pool.js +67 -37
  18. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  19. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  20. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +53 -53
  21. package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
  22. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  23. package/dest/mem_pools/attestation_pool/index.js +1 -1
  24. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  25. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  26. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  27. package/dest/mem_pools/index.d.ts +2 -1
  28. package/dest/mem_pools/index.d.ts.map +1 -1
  29. package/dest/mem_pools/interface.d.ts +3 -3
  30. package/dest/mem_pools/interface.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  32. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +102 -0
  33. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
  34. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +242 -0
  35. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  36. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -0
  38. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +5 -3
  39. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +3 -1
  40. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
  41. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +3 -1
  43. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -1
  44. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/index.js +1 -0
  46. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -3
  47. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
  49. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +28 -4
  50. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +37 -4
  52. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +8 -2
  53. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +15 -2
  55. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  56. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -2
  58. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +4 -2
  59. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +110 -78
  61. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
  62. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  63. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
  64. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  65. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  66. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
  67. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  68. package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
  69. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
  70. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  71. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  72. package/dest/services/dummy_service.d.ts +6 -2
  73. package/dest/services/dummy_service.d.ts.map +1 -1
  74. package/dest/services/dummy_service.js +3 -0
  75. package/dest/services/encoding.d.ts +2 -2
  76. package/dest/services/encoding.d.ts.map +1 -1
  77. package/dest/services/encoding.js +2 -2
  78. package/dest/services/gossipsub/index.d.ts +3 -0
  79. package/dest/services/gossipsub/index.d.ts.map +1 -0
  80. package/dest/services/gossipsub/index.js +2 -0
  81. package/dest/services/gossipsub/scoring.d.ts +21 -3
  82. package/dest/services/gossipsub/scoring.d.ts.map +1 -1
  83. package/dest/services/gossipsub/scoring.js +24 -7
  84. package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
  85. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
  86. package/dest/services/gossipsub/topic_score_params.js +324 -0
  87. package/dest/services/libp2p/libp2p_service.d.ts +11 -3
  88. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  89. package/dest/services/libp2p/libp2p_service.js +91 -67
  90. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  91. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  92. package/dest/services/peer-manager/peer_scoring.js +25 -2
  93. package/dest/services/reqresp/interface.d.ts +10 -1
  94. package/dest/services/reqresp/interface.d.ts.map +1 -1
  95. package/dest/services/reqresp/interface.js +15 -1
  96. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
  97. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  98. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
  99. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  100. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
  101. package/dest/services/reqresp/protocols/tx.d.ts +7 -1
  102. package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
  103. package/dest/services/reqresp/protocols/tx.js +20 -0
  104. package/dest/services/reqresp/reqresp.d.ts +1 -1
  105. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  106. package/dest/services/reqresp/reqresp.js +11 -4
  107. package/dest/services/service.d.ts +18 -1
  108. package/dest/services/service.d.ts.map +1 -1
  109. package/dest/services/tx_collection/config.d.ts +19 -1
  110. package/dest/services/tx_collection/config.d.ts.map +1 -1
  111. package/dest/services/tx_collection/config.js +46 -0
  112. package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
  113. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  114. package/dest/services/tx_collection/fast_tx_collection.js +17 -3
  115. package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
  116. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
  117. package/dest/services/tx_collection/file_store_tx_collection.js +165 -0
  118. package/dest/services/tx_collection/file_store_tx_source.d.ts +28 -0
  119. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
  120. package/dest/services/tx_collection/file_store_tx_source.js +59 -0
  121. package/dest/services/tx_collection/index.d.ts +2 -1
  122. package/dest/services/tx_collection/index.d.ts.map +1 -1
  123. package/dest/services/tx_collection/index.js +1 -0
  124. package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -2
  125. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  126. package/dest/services/tx_collection/slow_tx_collection.js +55 -23
  127. package/dest/services/tx_collection/tx_collection.d.ts +19 -7
  128. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  129. package/dest/services/tx_collection/tx_collection.js +75 -3
  130. package/dest/services/tx_collection/tx_collection_sink.d.ts +15 -6
  131. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  132. package/dest/services/tx_collection/tx_collection_sink.js +13 -7
  133. package/dest/services/tx_file_store/config.d.ts +1 -3
  134. package/dest/services/tx_file_store/config.d.ts.map +1 -1
  135. package/dest/services/tx_file_store/config.js +0 -4
  136. package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
  137. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  138. package/dest/services/tx_file_store/tx_file_store.js +8 -5
  139. package/dest/services/tx_provider.d.ts +3 -3
  140. package/dest/services/tx_provider.d.ts.map +1 -1
  141. package/dest/services/tx_provider.js +5 -4
  142. package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
  143. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  144. package/dest/test-helpers/mock-pubsub.d.ts +27 -1
  145. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  146. package/dest/test-helpers/mock-pubsub.js +97 -2
  147. package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
  148. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  149. package/dest/test-helpers/reqresp-nodes.js +2 -1
  150. package/dest/test-helpers/testbench-utils.d.ts +32 -24
  151. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  152. package/dest/test-helpers/testbench-utils.js +103 -36
  153. package/dest/testbench/p2p_client_testbench_worker.js +3 -3
  154. package/package.json +14 -14
  155. package/src/client/factory.ts +78 -9
  156. package/src/client/interface.ts +32 -13
  157. package/src/client/p2p_client.ts +135 -157
  158. package/src/config.ts +34 -2
  159. package/src/index.ts +1 -0
  160. package/src/mem_pools/attestation_pool/attestation_pool.ts +95 -44
  161. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +57 -53
  162. package/src/mem_pools/attestation_pool/index.ts +3 -3
  163. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  164. package/src/mem_pools/index.ts +3 -0
  165. package/src/mem_pools/interface.ts +2 -2
  166. package/src/mem_pools/tx_pool/README.md +1 -1
  167. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  168. package/src/mem_pools/tx_pool_v2/README.md +76 -10
  169. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +310 -0
  170. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -0
  171. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +3 -3
  172. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +1 -1
  173. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +3 -1
  174. package/src/mem_pools/tx_pool_v2/index.ts +1 -0
  175. package/src/mem_pools/tx_pool_v2/interfaces.ts +8 -2
  176. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +57 -7
  177. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +18 -2
  178. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +7 -1
  179. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +122 -80
  180. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
  181. package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
  182. package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
  183. package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
  184. package/src/services/dummy_service.ts +6 -0
  185. package/src/services/encoding.ts +2 -2
  186. package/src/services/gossipsub/README.md +626 -0
  187. package/src/services/gossipsub/index.ts +2 -0
  188. package/src/services/gossipsub/scoring.ts +29 -5
  189. package/src/services/gossipsub/topic_score_params.ts +451 -0
  190. package/src/services/libp2p/libp2p_service.ts +91 -70
  191. package/src/services/peer-manager/peer_scoring.ts +25 -0
  192. package/src/services/reqresp/interface.ts +26 -1
  193. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
  194. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
  195. package/src/services/reqresp/protocols/tx.ts +22 -0
  196. package/src/services/reqresp/reqresp.ts +13 -3
  197. package/src/services/service.ts +20 -0
  198. package/src/services/tx_collection/config.ts +68 -0
  199. package/src/services/tx_collection/fast_tx_collection.ts +14 -2
  200. package/src/services/tx_collection/file_store_tx_collection.ts +198 -0
  201. package/src/services/tx_collection/file_store_tx_source.ts +73 -0
  202. package/src/services/tx_collection/index.ts +1 -0
  203. package/src/services/tx_collection/slow_tx_collection.ts +64 -30
  204. package/src/services/tx_collection/tx_collection.ts +109 -13
  205. package/src/services/tx_collection/tx_collection_sink.ts +17 -7
  206. package/src/services/tx_file_store/config.ts +0 -6
  207. package/src/services/tx_file_store/tx_file_store.ts +9 -7
  208. package/src/services/tx_provider.ts +8 -7
  209. package/src/test-helpers/make-test-p2p-clients.ts +3 -3
  210. package/src/test-helpers/mock-pubsub.ts +133 -3
  211. package/src/test-helpers/reqresp-nodes.ts +2 -1
  212. package/src/test-helpers/testbench-utils.ts +117 -40
  213. package/src/testbench/p2p_client_testbench_worker.ts +3 -3
@@ -10,7 +10,11 @@ import {
10
10
  makeCheckpointProposal,
11
11
  } from '@aztec/stdlib/testing';
12
12
 
13
- import { type AttestationPool, MAX_PROPOSALS_PER_POSITION, MAX_PROPOSALS_PER_SLOT } from './attestation_pool.js';
13
+ import {
14
+ type AttestationPool,
15
+ MAX_BLOCK_PROPOSALS_PER_POSITION,
16
+ MAX_CHECKPOINT_PROPOSALS_PER_SLOT,
17
+ } from './attestation_pool.js';
14
18
  import { mockCheckpointAttestation } from './mocks.js';
15
19
 
16
20
  const NUMBER_OF_SIGNERS_PER_TEST = 4;
@@ -191,7 +195,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
191
195
 
192
196
  expect(result.added).toBe(true);
193
197
  expect(result.alreadyExists).toBe(false);
194
- expect(result.totalForPosition).toBe(1);
198
+ expect(result.count).toBe(1);
195
199
 
196
200
  const retrievedProposal = await ap.getBlockProposal(proposalId);
197
201
 
@@ -258,7 +262,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
258
262
 
259
263
  expect(result.added).toBe(true);
260
264
  expect(result.alreadyExists).toBe(false);
261
- expect(result.totalForPosition).toBe(1);
265
+ expect(result.count).toBe(1);
262
266
 
263
267
  const retrievedProposal = await ap.getCheckpointProposal(proposalId);
264
268
 
@@ -324,12 +328,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
324
328
  it('should return added=false when exceeding capacity', async () => {
325
329
  const slotNumber = 420;
326
330
 
327
- // Add MAX_PROPOSALS_PER_SLOT proposals
328
- for (let i = 0; i < MAX_PROPOSALS_PER_SLOT; i++) {
331
+ // Add MAX_CHECKPOINT_PROPOSALS_PER_SLOT proposals
332
+ for (let i = 0; i < MAX_CHECKPOINT_PROPOSALS_PER_SLOT; i++) {
329
333
  const proposal = await mockCheckpointProposalForPool(signers[i % NUMBER_OF_SIGNERS_PER_TEST], slotNumber);
330
334
  const result = await ap.tryAddCheckpointProposal(proposal);
331
335
  expect(result.added).toBe(true);
332
- expect(result.totalForPosition).toBe(i + 1);
336
+ expect(result.count).toBe(i + 1);
333
337
  }
334
338
 
335
339
  // The next proposal should not be added
@@ -337,7 +341,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
337
341
  const result = await ap.tryAddCheckpointProposal(extraProposal);
338
342
  expect(result.added).toBe(false);
339
343
  expect(result.alreadyExists).toBe(false);
340
- expect(result.totalForPosition).toBe(MAX_PROPOSALS_PER_SLOT);
344
+ expect(result.count).toBe(MAX_CHECKPOINT_PROPOSALS_PER_SLOT);
341
345
  });
342
346
  });
343
347
 
@@ -358,13 +362,13 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
358
362
  };
359
363
 
360
364
  describe('tryAddBlockProposal duplicate detection', () => {
361
- it('should return totalForPosition=1 when pool is empty', async () => {
365
+ it('should return count=1 when pool is empty', async () => {
362
366
  const proposal = await mockBlockProposalWithIndex(signers[0], 100, 0);
363
367
  const result = await ap.tryAddBlockProposal(proposal);
364
368
 
365
369
  expect(result.added).toBe(true);
366
370
  expect(result.alreadyExists).toBe(false);
367
- expect(result.totalForPosition).toBe(1);
371
+ expect(result.count).toBe(1);
368
372
  });
369
373
 
370
374
  it('should return alreadyExists when same proposal exists', async () => {
@@ -375,17 +379,17 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
375
379
 
376
380
  expect(result.added).toBe(false);
377
381
  expect(result.alreadyExists).toBe(true);
378
- expect(result.totalForPosition).toBe(1);
382
+ expect(result.count).toBe(1);
379
383
  });
380
384
 
381
- it('should detect duplicate via totalForPosition when different proposal exists at same position', async () => {
385
+ it('should detect duplicate via count when different proposal exists at same position', async () => {
382
386
  const slotNumber = 100;
383
387
  const indexWithinCheckpoint = 2;
384
388
 
385
389
  // Add first proposal
386
390
  const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
387
391
  const result1 = await ap.tryAddBlockProposal(proposal1);
388
- expect(result1.totalForPosition).toBe(1);
392
+ expect(result1.count).toBe(1);
389
393
 
390
394
  // Add a different proposal at same position - this is a duplicate (equivocation)
391
395
  const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, indexWithinCheckpoint);
@@ -393,8 +397,8 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
393
397
 
394
398
  expect(result2.added).toBe(true);
395
399
  expect(result2.alreadyExists).toBe(false);
396
- // totalForPosition >= 2 indicates duplicate detection
397
- expect(result2.totalForPosition).toBe(2);
400
+ // count >= 2 indicates duplicate detection
401
+ expect(result2.count).toBe(2);
398
402
  });
399
403
 
400
404
  it('should not detect duplicate for different positions in same slot', async () => {
@@ -409,8 +413,8 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
409
413
  const result = await ap.tryAddBlockProposal(proposal2);
410
414
 
411
415
  expect(result.added).toBe(true);
412
- // totalForPosition = 1 means no duplicate for this position
413
- expect(result.totalForPosition).toBe(1);
416
+ // count = 1 means no duplicate for this position
417
+ expect(result.count).toBe(1);
414
418
  });
415
419
 
416
420
  it('should not detect duplicate for same position in different slots', async () => {
@@ -425,37 +429,37 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
425
429
  const result = await ap.tryAddBlockProposal(proposal2);
426
430
 
427
431
  expect(result.added).toBe(true);
428
- // totalForPosition = 1 means no duplicate for this position
429
- expect(result.totalForPosition).toBe(1);
432
+ // count = 1 means no duplicate for this position
433
+ expect(result.count).toBe(1);
430
434
  });
431
435
 
432
- it('should track multiple duplicates correctly via totalForPosition', async () => {
436
+ it('should track multiple duplicates correctly via count', async () => {
433
437
  const slotNumber = 100;
434
438
  const indexWithinCheckpoint = 0;
435
439
 
436
440
  // Add multiple proposals for same position
437
441
  const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
438
442
  const result1 = await ap.tryAddBlockProposal(proposal1);
439
- expect(result1.totalForPosition).toBe(1);
443
+ expect(result1.count).toBe(1);
440
444
 
441
445
  const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, indexWithinCheckpoint);
442
446
  const result2 = await ap.tryAddBlockProposal(proposal2);
443
- expect(result2.totalForPosition).toBe(2);
447
+ expect(result2.count).toBe(2);
444
448
 
445
449
  // Add a third proposal for same position
446
450
  const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
447
451
  const result3 = await ap.tryAddBlockProposal(proposal3);
448
452
 
449
453
  expect(result3.added).toBe(true);
450
- expect(result3.totalForPosition).toBe(3);
454
+ expect(result3.count).toBe(3);
451
455
  });
452
456
 
453
457
  it('should return added=false when exceeding capacity', async () => {
454
458
  const slotNumber = 100;
455
459
  const indexWithinCheckpoint = 0;
456
460
 
457
- // Add MAX_PROPOSALS_PER_POSITION proposals
458
- for (let i = 0; i < MAX_PROPOSALS_PER_POSITION; i++) {
461
+ // Add MAX_BLOCK_PROPOSALS_PER_POSITION proposals
462
+ for (let i = 0; i < MAX_BLOCK_PROPOSALS_PER_POSITION; i++) {
459
463
  const proposal = await mockBlockProposalWithIndex(
460
464
  signers[i % NUMBER_OF_SIGNERS_PER_TEST],
461
465
  slotNumber,
@@ -463,7 +467,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
463
467
  );
464
468
  const result = await ap.tryAddBlockProposal(proposal);
465
469
  expect(result.added).toBe(true);
466
- expect(result.totalForPosition).toBe(i + 1);
470
+ expect(result.count).toBe(i + 1);
467
471
  }
468
472
 
469
473
  // The next proposal should not be added
@@ -471,7 +475,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
471
475
  const result = await ap.tryAddBlockProposal(extraProposal);
472
476
  expect(result.added).toBe(false);
473
477
  expect(result.alreadyExists).toBe(false);
474
- expect(result.totalForPosition).toBe(MAX_PROPOSALS_PER_POSITION);
478
+ expect(result.count).toBe(MAX_BLOCK_PROPOSALS_PER_POSITION);
475
479
  });
476
480
 
477
481
  it('should clean up block position index when deleting old data', async () => {
@@ -482,18 +486,18 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
482
486
  const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
483
487
  await ap.tryAddBlockProposal(proposal1);
484
488
 
485
- // Verify it's tracked (adding another should show totalForPosition = 2)
489
+ // Verify it's tracked (adding another should show count = 2)
486
490
  const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, indexWithinCheckpoint);
487
491
  let result = await ap.tryAddBlockProposal(proposal2);
488
- expect(result.totalForPosition).toBe(2);
492
+ expect(result.count).toBe(2);
489
493
 
490
494
  // Delete old data
491
495
  await ap.deleteOlderThan(SlotNumber(slotNumber + 1));
492
496
 
493
- // Verify position index is cleaned up (totalForPosition should be 1 now)
497
+ // Verify position index is cleaned up (count should be 1 now)
494
498
  const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
495
499
  result = await ap.tryAddBlockProposal(proposal3);
496
- expect(result.totalForPosition).toBe(1);
500
+ expect(result.count).toBe(1);
497
501
  });
498
502
 
499
503
  it('should correctly delete block proposals at slot boundary', async () => {
@@ -514,16 +518,16 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
514
518
  // Slot 99 proposals should have their index cleaned up
515
519
  const newProposal99 = await mockBlockProposalWithIndex(signers[0], 99, 0);
516
520
  const result99 = await ap.tryAddBlockProposal(newProposal99);
517
- expect(result99.totalForPosition).toBe(1); // Index was cleaned up
521
+ expect(result99.count).toBe(1); // Index was cleaned up
518
522
 
519
523
  // Slot 100 and 101 should still be tracked
520
524
  const newProposal100 = await mockBlockProposalWithIndex(signers[1], 100, 0);
521
525
  const result100 = await ap.tryAddBlockProposal(newProposal100);
522
- expect(result100.totalForPosition).toBe(2); // Still has the original
526
+ expect(result100.count).toBe(2); // Still has the original
523
527
 
524
528
  const newProposal101 = await mockBlockProposalWithIndex(signers[2], 101, 0);
525
529
  const result101 = await ap.tryAddBlockProposal(newProposal101);
526
- expect(result101.totalForPosition).toBe(2); // Still has the original
530
+ expect(result101.count).toBe(2); // Still has the original
527
531
  });
528
532
 
529
533
  it('should delete all indices for a given slot', async () => {
@@ -544,15 +548,15 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
544
548
  // All indices should be cleaned up
545
549
  const newProposal0 = await mockBlockProposalWithIndex(signers[0], slotNumber, 0);
546
550
  const result0 = await ap.tryAddBlockProposal(newProposal0);
547
- expect(result0.totalForPosition).toBe(1);
551
+ expect(result0.count).toBe(1);
548
552
 
549
553
  const newProposal1 = await mockBlockProposalWithIndex(signers[1], slotNumber, 1);
550
554
  const result1 = await ap.tryAddBlockProposal(newProposal1);
551
- expect(result1.totalForPosition).toBe(1);
555
+ expect(result1.count).toBe(1);
552
556
 
553
557
  const newProposal2 = await mockBlockProposalWithIndex(signers[2], slotNumber, 2);
554
558
  const result2 = await ap.tryAddBlockProposal(newProposal2);
555
- expect(result2.totalForPosition).toBe(1);
559
+ expect(result2.count).toBe(1);
556
560
  });
557
561
 
558
562
  it('should delete block proposals from storage when deleting old data', async () => {
@@ -598,13 +602,13 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
598
602
  return proposal.toCore();
599
603
  };
600
604
 
601
- it('should return totalForPosition=1 when pool is empty', async () => {
605
+ it('should return count=1 when pool is empty', async () => {
602
606
  const proposal = await mockCheckpointProposalCoreForPool(signers[0], 100);
603
607
  const result = await ap.tryAddCheckpointProposal(proposal);
604
608
 
605
609
  expect(result.added).toBe(true);
606
610
  expect(result.alreadyExists).toBe(false);
607
- expect(result.totalForPosition).toBe(1);
611
+ expect(result.count).toBe(1);
608
612
  });
609
613
 
610
614
  it('should return alreadyExists when same proposal exists', async () => {
@@ -615,16 +619,16 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
615
619
 
616
620
  expect(result.added).toBe(false);
617
621
  expect(result.alreadyExists).toBe(true);
618
- expect(result.totalForPosition).toBe(1);
622
+ expect(result.count).toBe(1);
619
623
  });
620
624
 
621
- it('should detect duplicate via totalForPosition when different proposal exists for same slot', async () => {
625
+ it('should detect duplicate via count when different proposal exists for same slot', async () => {
622
626
  const slotNumber = 100;
623
627
 
624
628
  // Add first proposal
625
629
  const proposal1 = await mockCheckpointProposalCoreForPool(signers[0], slotNumber);
626
630
  const result1 = await ap.tryAddCheckpointProposal(proposal1);
627
- expect(result1.totalForPosition).toBe(1);
631
+ expect(result1.count).toBe(1);
628
632
 
629
633
  // Add a different proposal for same slot - this is a duplicate (equivocation)
630
634
  const proposal2 = await mockCheckpointProposalCoreForPool(signers[1], slotNumber);
@@ -632,8 +636,8 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
632
636
 
633
637
  expect(result2.added).toBe(true);
634
638
  expect(result2.alreadyExists).toBe(false);
635
- // totalForPosition >= 2 indicates duplicate detection
636
- expect(result2.totalForPosition).toBe(2);
639
+ // count >= 2 indicates duplicate detection
640
+ expect(result2.count).toBe(2);
637
641
  });
638
642
 
639
643
  it('should not detect duplicate for different slots', async () => {
@@ -646,28 +650,28 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
646
650
  const result = await ap.tryAddCheckpointProposal(proposal2);
647
651
 
648
652
  expect(result.added).toBe(true);
649
- // totalForPosition = 1 means no duplicate for this slot
650
- expect(result.totalForPosition).toBe(1);
653
+ // count = 1 means no duplicate for this slot
654
+ expect(result.count).toBe(1);
651
655
  });
652
656
 
653
- it('should track multiple duplicates correctly via totalForPosition', async () => {
657
+ it('should track multiple duplicates correctly via count', async () => {
654
658
  const slotNumber = 100;
655
659
 
656
660
  // Add multiple proposals for same slot
657
661
  const proposal1 = await mockCheckpointProposalCoreForPool(signers[0], slotNumber);
658
662
  const result1 = await ap.tryAddCheckpointProposal(proposal1);
659
- expect(result1.totalForPosition).toBe(1);
663
+ expect(result1.count).toBe(1);
660
664
 
661
665
  const proposal2 = await mockCheckpointProposalCoreForPool(signers[1], slotNumber);
662
666
  const result2 = await ap.tryAddCheckpointProposal(proposal2);
663
- expect(result2.totalForPosition).toBe(2);
667
+ expect(result2.count).toBe(2);
664
668
 
665
669
  // Add a third proposal for same slot
666
670
  const proposal3 = await mockCheckpointProposalCoreForPool(signers[2], slotNumber);
667
671
  const result3 = await ap.tryAddCheckpointProposal(proposal3);
668
672
 
669
673
  expect(result3.added).toBe(true);
670
- expect(result3.totalForPosition).toBe(3);
674
+ expect(result3.count).toBe(3);
671
675
  });
672
676
 
673
677
  it('should not count attestations as proposals for duplicate detection', async () => {
@@ -684,8 +688,8 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
684
688
 
685
689
  expect(result.added).toBe(true);
686
690
  expect(result.alreadyExists).toBe(false);
687
- // totalForPosition should be 1, NOT 2 - attestations should not count as proposals
688
- expect(result.totalForPosition).toBe(1);
691
+ // count should be 1, NOT 2 - attestations should not count as proposals
692
+ expect(result.count).toBe(1);
689
693
  });
690
694
 
691
695
  it('should not count attestations for different proposals as duplicates', async () => {
@@ -703,14 +707,14 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
703
707
  const result1 = await ap.tryAddCheckpointProposal(proposal1);
704
708
 
705
709
  expect(result1.added).toBe(true);
706
- expect(result1.totalForPosition).toBe(1);
710
+ expect(result1.count).toBe(1);
707
711
 
708
712
  // Add the second checkpoint proposal - this IS a duplicate (different archive, same slot)
709
713
  const proposal2 = await mockCheckpointProposalCoreForPool(signers[3], slotNumber, archive2);
710
714
  const result2 = await ap.tryAddCheckpointProposal(proposal2);
711
715
 
712
716
  expect(result2.added).toBe(true);
713
- expect(result2.totalForPosition).toBe(2);
717
+ expect(result2.count).toBe(2);
714
718
  });
715
719
  });
716
720
  });
@@ -3,7 +3,7 @@ export {
3
3
  type AttestationPoolApi,
4
4
  type TryAddResult,
5
5
  createTestAttestationPool,
6
- MAX_PROPOSALS_PER_SLOT,
7
- MAX_PROPOSALS_PER_POSITION,
8
- ATTESTATION_CAP_BUFFER,
6
+ MAX_CHECKPOINT_PROPOSALS_PER_SLOT,
7
+ MAX_BLOCK_PROPOSALS_PER_POSITION,
8
+ MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER,
9
9
  } from './attestation_pool.js';
@@ -34,9 +34,10 @@ export const mockCheckpointAttestation = (
34
34
  slot: number = 0,
35
35
  archive: Fr = Fr.random(),
36
36
  header?: CheckpointHeader,
37
+ feeAssetPriceModifier: bigint = 0n,
37
38
  ): CheckpointAttestation => {
38
39
  header = header ?? CheckpointHeader.random({ slotNumber: SlotNumber(slot) });
39
- const payload = new ConsensusPayload(header, archive);
40
+ const payload = new ConsensusPayload(header, archive, feeAssetPriceModifier);
40
41
 
41
42
  const attestationHash = getHashedSignaturePayloadEthSignedMessage(
42
43
  payload,
@@ -1,3 +1,6 @@
1
1
  export { AttestationPool, type AttestationPoolApi } from './attestation_pool/attestation_pool.js';
2
2
  export { type MemPools } from './interface.js';
3
+ // Old TxPool exports - kept temporarily for external consumers
3
4
  export { type TxPool } from './tx_pool/tx_pool.js';
5
+ // New TxPoolV2 exports
6
+ export { type TxPoolV2, type TxPoolV2Config, type TxPoolV2Events, type AddTxsResult } from './tx_pool_v2/index.js';
@@ -1,10 +1,10 @@
1
1
  import type { AttestationPoolApi } from './attestation_pool/attestation_pool.js';
2
- import type { TxPool } from './tx_pool/tx_pool.js';
2
+ import type { TxPoolV2 } from './tx_pool_v2/interfaces.js';
3
3
 
4
4
  /**
5
5
  * A interface the combines all mempools
6
6
  */
7
7
  export type MemPools = {
8
- txPool: TxPool;
8
+ txPool: TxPoolV2;
9
9
  attestationPool: AttestationPoolApi;
10
10
  };
@@ -213,7 +213,7 @@ The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
213
213
  Evicts transactions that become invalid after a block is mined:
214
214
 
215
215
  - Duplicate nullifiers: Txs with nullifiers already included in the mined block
216
- - Expired transactions: Txs with `includeByTimestamp` ≤ mined block timestamp
216
+ - Expired transactions: Txs with `expirationTimestamp` ≤ mined block timestamp
217
217
 
218
218
  #### 2. `InvalidTxsAfterReorgRule`
219
219
 
@@ -68,10 +68,10 @@ export class InvalidTxsAfterMiningRule implements EvictionRule {
68
68
  }
69
69
 
70
70
  // Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
71
- const includeByTimestamp = tx.data.includeByTimestamp;
72
- if (includeByTimestamp <= timestamp) {
71
+ const expirationTimestamp = tx.data.expirationTimestamp;
72
+ if (expirationTimestamp <= timestamp) {
73
73
  this.log.verbose(
74
- `Evicting tx ${txHash} from pool due to the tx being expired (includeByTimestamp: ${includeByTimestamp}, mined block timestamp: ${timestamp})`,
74
+ `Evicting tx ${txHash} from pool due to the tx being expired (expirationTimestamp: ${expirationTimestamp}, mined block timestamp: ${timestamp})`,
75
75
  );
76
76
  txsToEvict.push(txHash);
77
77
  continue;
@@ -28,13 +28,22 @@ TxPoolV2 manages transactions through a state machine with clear transitions:
28
28
  │ MINED │───────────────────┘
29
29
  │ (included in a block) │ handlePrunedBlocks()
30
30
  └─────────────────────────────────────┘ (reorg)
31
-
32
- │ handleFinalizedBlock()
33
-
34
- ┌─────────────────────────────────────┐
35
- │ DELETED │
36
- (optionally archived)
37
- └─────────────────────────────────────┘
31
+
32
+ │ handleFinalizedBlock() │ eviction after reorg
33
+ │ / eviction / failed exec │ (validation failure)
34
+ ▼ ▼
35
+ ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
36
+ SLOT-SOFT-DELETED │ PRUNE-SOFT-DELETED │
37
+ │ (kept in DB until next slot) │ │ (kept in DB until finalized) │
38
+ └─────────────────────────────────────┘ └─────────────────────────────────────┘
39
+ │ │
40
+ │ prepareForSlot() │ handleFinalizedBlock()
41
+ │ (slot advanced) │ (mined block finalized)
42
+ ▼ ▼
43
+ ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
44
+ │ HARD-DELETED │ │ HARD-DELETED │
45
+ │ (permanently removed from DB) │ │ (permanently removed from DB) │
46
+ └─────────────────────────────────────┘ └─────────────────────────────────────┘
38
47
  ```
39
48
 
40
49
  ## Key Components
@@ -52,6 +61,14 @@ Core implementation containing:
52
61
  - Pre-add rule execution
53
62
  - Post-event eviction rule execution
54
63
 
64
+ ### DeletedPool (`deleted_pool.ts`)
65
+
66
+ Manages all transaction deletions in the pool with two soft-deletion mechanisms:
67
+ - **Slot-based**: Non-pruned txs are kept in DB until the next slot, allowing other nodes to fetch them via reqresp
68
+ - **Prune-based**: Txs from pruned blocks are kept in DB until their original mined block is finalized
69
+
70
+ All deletions go through `DeletedPool.deleteTx()`, which routes to the appropriate path based on whether the tx is tracked as being from a pruned block.
71
+
55
72
  ### TxMetaData (`tx_metadata.ts`)
56
73
 
57
74
  Lightweight metadata stored alongside each transaction:
@@ -62,14 +79,60 @@ Lightweight metadata stored alongside each transaction:
62
79
  - `claimAmount`: Fee payer's claim from bridging
63
80
  - `feeLimit`: Maximum fee the tx can pay
64
81
  - `nullifiers`: For conflict detection
65
- - `includeByTimestamp`: Expiration timestamp
82
+ - `expirationTimestamp`: Expiration timestamp
66
83
  - `minedL2BlockId`: Set when mined (undefined otherwise)
67
84
 
68
85
  State is derived by TxPoolIndices:
69
86
  - `mined` if `minedL2BlockId` is set
70
87
  - `protected` if in protection map
88
+ - `deleted` if soft-deleted (slot-based or prune-based, evicted but kept in DB)
71
89
  - `pending` otherwise
72
90
 
91
+ ## Soft Deletion
92
+
93
+ Deleted transactions are kept in the database for a grace period before being permanently removed. There are two soft-deletion mechanisms:
94
+
95
+ ### Slot-Based Soft Deletion
96
+
97
+ When a transaction is deleted from the pool (eviction, validation failure, failed execution) and is **not** from a pruned block, it is "slot-soft-deleted":
98
+
99
+ 1. **Soft Delete**: The tx is removed from indices but kept in the database, tagged with the current slot number
100
+ 2. **Retrieval**: Slot-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
101
+ 3. **Hard Delete**: When `prepareForSlot` advances to a new slot, txs deleted in earlier slots are permanently removed
102
+ 4. **Re-addition**: If a slot-soft-deleted tx is re-added to the pool, the slot-deleted tracking is cleared
103
+
104
+ This allows other nodes to still fetch recently-deleted transactions via reqresp during the current slot.
105
+
106
+ ### Prune-Based Soft Deletion
107
+
108
+ When a chain reorganization occurs, transactions that were mined in pruned blocks are handled with longer retention:
109
+
110
+ 1. **Tracking**: When `handlePrunedBlocks` is called, all un-mined transactions are tracked by their original mined block number
111
+ 2. **Soft Delete**: If these transactions are later evicted (failed validation, nullifier conflict, etc.), they are "prune-soft-deleted" - removed from indices but kept in the database
112
+ 3. **Retrieval**: Prune-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
113
+ 4. **Hard Delete**: When `handleFinalizedBlock` is called and the finalized block number reaches or exceeds the transaction's original mined block, the transaction is permanently removed
114
+ 5. **Re-addition**: If a prune-soft-deleted tx is re-added, the `softDeleted` flag is reset to `false` but the prune tracking is preserved, so a subsequent deletion still uses the prune path
115
+
116
+ Prune-soft-deleted transactions are **not** affected by slot cleanup - they survive across slot boundaries until finalized.
117
+
118
+ **Prune example:**
119
+ 1. Tx mined at block 10
120
+ 2. Chain prunes to block 5 (tx becomes un-mined, tracked as minedAtBlock=10)
121
+ 3. Tx fails validation and is prune-soft-deleted
122
+ 4. Block 9 finalized → tx still in DB (minedAtBlock=10 > finalized=9)
123
+ 5. Block 10 finalized → tx hard-deleted (minedAtBlock=10 ≤ finalized=10)
124
+
125
+ If the tx is re-mined at a higher block before being soft-deleted:
126
+ 1. Tx mined at block 10, pruned (tracked as minedAtBlock=10)
127
+ 2. Tx re-mined at block 15, pruned again (updated to minedAtBlock=15)
128
+ 3. Tx soft-deleted
129
+ 4. Block 10 finalized → tx still in DB
130
+ 5. Block 15 finalized → tx hard-deleted
131
+
132
+ ### Hydration
133
+
134
+ On node restart, slot-soft-deleted transactions are immediately hard-deleted (they are stale by definition). Prune-soft-deleted transactions are loaded from the database and tracked normally.
135
+
73
136
  ## Architecture: Pre-add vs Post-event Rules
74
137
 
75
138
  **Pre-add rules** (run during `addPendingTxs`):
@@ -120,7 +183,7 @@ import { AztecKVTxPoolV2 } from './tx_pool_v2.js';
120
183
  const pool = new AztecKVTxPoolV2(txStore, archiveStore, {
121
184
  l2BlockSource: archiver,
122
185
  worldStateSynchronizer: worldState,
123
- pendingTxValidator: validator,
186
+ createTxValidator: () => validator,
124
187
  });
125
188
 
126
189
  await pool.start();
@@ -195,9 +258,12 @@ The archive uses FIFO eviction when `archivedTxLimit` is reached.
195
258
  ## Testing
196
259
 
197
260
  ```bash
198
- # Unit tests (131 tests)
261
+ # Unit tests (177 tests)
199
262
  yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts
200
263
 
264
+ # Deleted pool tests (17 tests)
265
+ yarn test src/mem_pools/tx_pool_v2/deleted_pool.test.ts
266
+
201
267
  # Compatibility tests (25 tests)
202
268
  yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.compat.test.ts
203
269