@aztec/p2p 0.0.1-commit.e310a4c8 → 0.0.1-commit.e558bd1c

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 (188) 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 +5 -3
  4. package/dest/client/interface.d.ts +9 -2
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +7 -4
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +17 -7
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -1
  10. package/dest/config.d.ts +9 -3
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +3 -1
  13. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
  14. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  15. package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
  16. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  17. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +351 -85
  19. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  20. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/index.js +1 -2
  22. package/dest/mem_pools/index.d.ts +2 -2
  23. package/dest/mem_pools/index.d.ts.map +1 -1
  24. package/dest/mem_pools/index.js +1 -1
  25. package/dest/mem_pools/interface.d.ts +3 -3
  26. package/dest/mem_pools/interface.d.ts.map +1 -1
  27. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  28. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  29. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  30. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  31. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  32. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  33. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  34. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  35. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  36. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  37. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  38. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  39. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  40. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  41. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  42. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  43. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  44. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  46. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  47. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  48. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  49. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  50. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  51. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  52. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  53. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  54. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  55. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  56. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  63. package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
  64. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/index.js +4 -0
  66. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  67. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  69. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
  70. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  73. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  75. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  76. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  78. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  79. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  81. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  82. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
  84. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  85. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  86. package/dest/services/dummy_service.d.ts +6 -2
  87. package/dest/services/dummy_service.d.ts.map +1 -1
  88. package/dest/services/dummy_service.js +3 -0
  89. package/dest/services/index.d.ts +2 -1
  90. package/dest/services/index.d.ts.map +1 -1
  91. package/dest/services/index.js +1 -0
  92. package/dest/services/libp2p/libp2p_service.d.ts +74 -33
  93. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  94. package/dest/services/libp2p/libp2p_service.js +299 -228
  95. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -4
  96. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  97. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +8 -8
  98. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
  99. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  100. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
  101. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -10
  102. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  103. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +12 -11
  104. package/dest/services/service.d.ts +18 -1
  105. package/dest/services/service.d.ts.map +1 -1
  106. package/dest/services/tx_collection/config.d.ts +3 -3
  107. package/dest/services/tx_collection/config.js +3 -3
  108. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -5
  109. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  110. package/dest/services/tx_collection/fast_tx_collection.js +10 -14
  111. package/dest/services/tx_collection/index.d.ts +1 -1
  112. package/dest/services/tx_collection/proposal_tx_collector.d.ts +12 -12
  113. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  114. package/dest/services/tx_collection/proposal_tx_collector.js +4 -5
  115. package/dest/services/tx_file_store/config.d.ts +18 -0
  116. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  117. package/dest/services/tx_file_store/config.js +26 -0
  118. package/dest/services/tx_file_store/index.d.ts +4 -0
  119. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  120. package/dest/services/tx_file_store/index.js +3 -0
  121. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  122. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  123. package/dest/services/tx_file_store/instrumentation.js +29 -0
  124. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  125. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  126. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  127. package/dest/test-helpers/testbench-utils.d.ts +10 -16
  128. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  129. package/dest/test-helpers/testbench-utils.js +32 -30
  130. package/dest/testbench/p2p_client_testbench_worker.js +1 -1
  131. package/package.json +14 -14
  132. package/src/client/factory.ts +7 -4
  133. package/src/client/interface.ts +13 -1
  134. package/src/client/p2p_client.ts +25 -8
  135. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -1
  136. package/src/config.ts +8 -1
  137. package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
  138. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
  139. package/src/mem_pools/attestation_pool/index.ts +9 -2
  140. package/src/mem_pools/index.ts +1 -1
  141. package/src/mem_pools/interface.ts +2 -2
  142. package/src/mem_pools/tx_pool_v2/README.md +209 -0
  143. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  144. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  145. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  146. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  147. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  148. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  149. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  150. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  151. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  152. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  153. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  154. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  155. package/src/mem_pools/tx_pool_v2/index.ts +11 -0
  156. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  157. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
  158. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  159. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  160. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  161. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
  162. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  163. package/src/services/dummy_service.ts +6 -0
  164. package/src/services/index.ts +1 -0
  165. package/src/services/libp2p/libp2p_service.ts +304 -230
  166. package/src/services/reqresp/batch-tx-requester/README.md +7 -7
  167. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +11 -11
  168. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +22 -13
  169. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +21 -15
  170. package/src/services/service.ts +20 -0
  171. package/src/services/tx_collection/config.ts +6 -6
  172. package/src/services/tx_collection/fast_tx_collection.ts +14 -24
  173. package/src/services/tx_collection/index.ts +1 -1
  174. package/src/services/tx_collection/proposal_tx_collector.ts +12 -14
  175. package/src/services/tx_file_store/config.ts +43 -0
  176. package/src/services/tx_file_store/index.ts +3 -0
  177. package/src/services/tx_file_store/instrumentation.ts +36 -0
  178. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  179. package/src/test-helpers/testbench-utils.ts +18 -39
  180. package/src/testbench/p2p_client_testbench_worker.ts +1 -1
  181. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  182. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  183. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  184. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  185. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  186. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  187. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  188. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/p2p",
3
- "version": "0.0.1-commit.e310a4c8",
3
+ "version": "0.0.1-commit.e558bd1c",
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.e310a4c8",
71
- "@aztec/epoch-cache": "0.0.1-commit.e310a4c8",
72
- "@aztec/ethereum": "0.0.1-commit.e310a4c8",
73
- "@aztec/foundation": "0.0.1-commit.e310a4c8",
74
- "@aztec/kv-store": "0.0.1-commit.e310a4c8",
75
- "@aztec/noir-contracts.js": "0.0.1-commit.e310a4c8",
76
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.e310a4c8",
77
- "@aztec/protocol-contracts": "0.0.1-commit.e310a4c8",
78
- "@aztec/simulator": "0.0.1-commit.e310a4c8",
79
- "@aztec/stdlib": "0.0.1-commit.e310a4c8",
80
- "@aztec/telemetry-client": "0.0.1-commit.e310a4c8",
70
+ "@aztec/constants": "0.0.1-commit.e558bd1c",
71
+ "@aztec/epoch-cache": "0.0.1-commit.e558bd1c",
72
+ "@aztec/ethereum": "0.0.1-commit.e558bd1c",
73
+ "@aztec/foundation": "0.0.1-commit.e558bd1c",
74
+ "@aztec/kv-store": "0.0.1-commit.e558bd1c",
75
+ "@aztec/noir-contracts.js": "0.0.1-commit.e558bd1c",
76
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.e558bd1c",
77
+ "@aztec/protocol-contracts": "0.0.1-commit.e558bd1c",
78
+ "@aztec/simulator": "0.0.1-commit.e558bd1c",
79
+ "@aztec/stdlib": "0.0.1-commit.e558bd1c",
80
+ "@aztec/telemetry-client": "0.0.1-commit.e558bd1c",
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.e310a4c8",
108
- "@aztec/world-state": "0.0.1-commit.e310a4c8",
107
+ "@aztec/archiver": "0.0.1-commit.e558bd1c",
108
+ "@aztec/world-state": "0.0.1-commit.e558bd1c",
109
109
  "@jest/globals": "^30.0.0",
110
110
  "@types/jest": "^30.0.0",
111
111
  "@types/node": "^22.15.17",
@@ -13,20 +13,20 @@ import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-clien
13
13
 
14
14
  import { P2PClient } from '../client/p2p_client.js';
15
15
  import type { P2PConfig } from '../config.js';
16
- import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
17
- import { KvAttestationPool } from '../mem_pools/attestation_pool/kv_attestation_pool.js';
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 { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js';
20
19
  import { DummyP2PService } from '../services/dummy_service.js';
21
20
  import { LibP2PService } from '../services/index.js';
22
21
  import { TxCollection } from '../services/tx_collection/tx_collection.js';
23
22
  import { type TxSource, createNodeRpcTxSources } from '../services/tx_collection/tx_source.js';
23
+ import { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
24
24
  import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';
25
25
 
26
26
  export type P2PClientDeps<T extends P2PClientType> = {
27
27
  txPool?: TxPool;
28
28
  store?: AztecAsyncKVStore;
29
- attestationPool?: AttestationPool;
29
+ attestationPool?: AttestationPoolApi;
30
30
  logger?: Logger;
31
31
  txCollectionNodeSources?: TxSource[];
32
32
  p2pServiceFactory?: (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService<T>>;
@@ -76,7 +76,7 @@ export async function createP2PClient<T extends P2PClientType>(
76
76
  maxPendingTxCount: config.maxPendingTxCount,
77
77
  archivedTxLimit: config.archivedTxLimit,
78
78
  }),
79
- attestationPool: deps.attestationPool ?? new KvAttestationPool(attestationStore, telemetry),
79
+ attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry),
80
80
  };
81
81
 
82
82
  const p2pService = await createP2PService<T>(
@@ -116,6 +116,8 @@ export async function createP2PClient<T extends P2PClientType>(
116
116
  logger.createChild('tx-collection'),
117
117
  );
118
118
 
119
+ const txFileStore = await TxFileStore.create(mempools.txPool, config, logger.createChild('tx-file-store'), telemetry);
120
+
119
121
  return new P2PClient(
120
122
  clientType,
121
123
  store,
@@ -123,6 +125,7 @@ export async function createP2PClient<T extends P2PClientType>(
123
125
  mempools,
124
126
  p2pService,
125
127
  txCollection,
128
+ txFileStore,
126
129
  config,
127
130
  dateProvider,
128
131
  telemetry,
@@ -13,7 +13,11 @@ import type {
13
13
  ReqRespSubProtocolHandler,
14
14
  ReqRespSubProtocolValidators,
15
15
  } from '../services/reqresp/interface.js';
16
- import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback } from '../services/service.js';
16
+ import type {
17
+ DuplicateProposalInfo,
18
+ P2PBlockReceivedCallback,
19
+ P2PCheckpointReceivedCallback,
20
+ } from '../services/service.js';
17
21
 
18
22
  /**
19
23
  * Enum defining the possible states of the p2p client.
@@ -78,6 +82,14 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
78
82
  */
79
83
  registerCheckpointProposalHandler(callback: P2PCheckpointReceivedCallback): void;
80
84
 
85
+ /**
86
+ * Registers a callback invoked when a duplicate proposal is detected (equivocation).
87
+ * The callback is triggered on the first duplicate (when count goes from 1 to 2).
88
+ *
89
+ * @param callback - Function called with info about the duplicate proposal
90
+ */
91
+ registerDuplicateProposalCallback(callback: (info: DuplicateProposalInfo) => void): void;
92
+
81
93
  /**
82
94
  * Request a list of transactions from another peer by their tx hashes.
83
95
  * @param txHashes - Hashes of the txs to query.
@@ -29,7 +29,7 @@ import type { PeerId } from '@libp2p/interface';
29
29
  import type { ENR } from '@nethermindeth/enr';
30
30
 
31
31
  import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
32
- import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
32
+ import type { AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
33
33
  import type { MemPools } from '../mem_pools/interface.js';
34
34
  import type { TxPool } from '../mem_pools/tx_pool/index.js';
35
35
  import type { AuthRequest, StatusMessage } from '../services/index.js';
@@ -39,8 +39,14 @@ import {
39
39
  type ReqRespSubProtocolValidators,
40
40
  } from '../services/reqresp/interface.js';
41
41
  import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
42
- import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
42
+ import type {
43
+ DuplicateProposalInfo,
44
+ P2PBlockReceivedCallback,
45
+ P2PCheckpointReceivedCallback,
46
+ P2PService,
47
+ } from '../services/service.js';
43
48
  import { TxCollection } from '../services/tx_collection/tx_collection.js';
49
+ import type { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
44
50
  import { TxProvider } from '../services/tx_provider.js';
45
51
  import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
46
52
 
@@ -65,7 +71,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
65
71
  private synchedLatestSlot: AztecAsyncSingleton<bigint>;
66
72
 
67
73
  private txPool: TxPool;
68
- private attestationPool: AttestationPool;
74
+ private attestationPool: AttestationPoolApi;
69
75
 
70
76
  private config: P2PConfig;
71
77
 
@@ -90,6 +96,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
90
96
  mempools: MemPools,
91
97
  private p2pService: P2PService,
92
98
  private txCollection: TxCollection,
99
+ private txFileStore: TxFileStore | undefined,
93
100
  config: Partial<P2PConfig> = {},
94
101
  private _dateProvider: DateProvider = new DateProvider(),
95
102
  private telemetry: TelemetryClient = getTelemetryClient(),
@@ -274,6 +281,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
274
281
 
275
282
  this.blockStream!.start();
276
283
  await this.txCollection.start();
284
+ this.txFileStore?.start();
277
285
  return this.syncPromise;
278
286
  }
279
287
 
@@ -306,6 +314,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
306
314
  this.log.debug('Stopping p2p client...');
307
315
  await tryStop(this.txCollection);
308
316
  this.log.debug('Stopped tx collection service');
317
+ await this.txFileStore?.stop();
318
+ this.log.debug('Stopped tx file store');
309
319
  await this.p2pService.stop();
310
320
  this.log.debug('Stopped p2p service');
311
321
  await this.blockStream?.stop();
@@ -329,7 +339,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
329
339
  public async broadcastProposal(proposal: BlockProposal): Promise<void> {
330
340
  this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
331
341
  // Store our own proposal so we can respond to req/resp requests for it
332
- await this.attestationPool.addBlockProposal(proposal);
342
+ const { totalForPosition } = await this.attestationPool.tryAddBlockProposal(proposal);
343
+ if (totalForPosition > 1) {
344
+ throw new Error(`Attempted to broadcast a duplicate block proposal for slot ${proposal.slotNumber}`);
345
+ }
333
346
  return this.p2pService.propagate(proposal);
334
347
  }
335
348
 
@@ -343,7 +356,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
343
356
  const blockProposal = proposal.getBlockProposal();
344
357
  if (blockProposal) {
345
358
  // Store our own last-block proposal so we can respond to req/resp requests for it.
346
- await this.attestationPool.addBlockProposal(blockProposal);
359
+ await this.attestationPool.tryAddBlockProposal(blockProposal);
347
360
  }
348
361
  return this.p2pService.propagate(proposal);
349
362
  }
@@ -362,8 +375,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
362
375
  : this.attestationPool.getCheckpointAttestationsForSlot(slot));
363
376
  }
364
377
 
365
- public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
366
- return this.attestationPool.addCheckpointAttestations(attestations);
378
+ public addOwnCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
379
+ return this.attestationPool.addOwnCheckpointAttestations(attestations);
367
380
  }
368
381
 
369
382
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
@@ -376,6 +389,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
376
389
  this.p2pService.registerCheckpointReceivedCallback(handler);
377
390
  }
378
391
 
392
+ public registerDuplicateProposalCallback(callback: (info: DuplicateProposalInfo) => void): void {
393
+ this.p2pService.registerDuplicateProposalCallback(callback);
394
+ }
395
+
379
396
  /**
380
397
  * Uses the batched Request Response protocol to request a set of transactions from the network.
381
398
  */
@@ -740,7 +757,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
740
757
  await this.txPool.deleteTxs(txHashes, { permanently: true });
741
758
  await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
742
759
 
743
- await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
760
+ await this.attestationPool.deleteOlderThan(lastBlockSlot);
744
761
 
745
762
  this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
746
763
  }
@@ -301,7 +301,7 @@ process.on('message', (msg: WorkerCommand) => {
301
301
  throw new Error('Attestation pool not initialized');
302
302
  }
303
303
  const proposal = deserializeBlockProposal(msg.blockProposal);
304
- await attestationPool.addBlockProposal(proposal);
304
+ await attestationPool.tryAddBlockProposal(proposal);
305
305
  await sendMessage({ type: 'BLOCK_PROPOSAL_SET', requestId, archiveRoot: proposal.archive.toString() });
306
306
  break;
307
307
  }
package/src/config.ts CHANGED
@@ -21,11 +21,17 @@ import {
21
21
  } from './services/reqresp/batch-tx-requester/config.js';
22
22
  import { type P2PReqRespConfig, p2pReqRespConfigMappings } from './services/reqresp/config.js';
23
23
  import { type TxCollectionConfig, txCollectionConfigMappings } from './services/tx_collection/config.js';
24
+ import { type TxFileStoreConfig, txFileStoreConfigMappings } from './services/tx_file_store/config.js';
24
25
 
25
26
  /**
26
27
  * P2P client configuration values.
27
28
  */
28
- export interface P2PConfig extends P2PReqRespConfig, BatchTxRequesterConfig, ChainConfig, TxCollectionConfig {
29
+ export interface P2PConfig
30
+ extends P2PReqRespConfig,
31
+ BatchTxRequesterConfig,
32
+ ChainConfig,
33
+ TxCollectionConfig,
34
+ TxFileStoreConfig {
29
35
  /** A flag dictating whether the P2P subsystem should be enabled. */
30
36
  p2pEnabled: boolean;
31
37
 
@@ -439,6 +445,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
439
445
  ...batchTxRequesterConfigMappings,
440
446
  ...chainConfigMappings,
441
447
  ...txCollectionConfigMappings,
448
+ ...txFileStoreConfigMappings,
442
449
  };
443
450
 
444
451
  /**