@aztec/p2p 0.0.1-commit.8f9871590 → 0.0.1-commit.9117c5f5a

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 (218) hide show
  1. package/dest/client/factory.d.ts +6 -6
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +18 -28
  4. package/dest/client/interface.d.ts +10 -19
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +7 -18
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +41 -72
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
  10. package/dest/config.d.ts +4 -6
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +0 -5
  13. package/dest/errors/tx-pool.error.d.ts +8 -0
  14. package/dest/errors/tx-pool.error.d.ts.map +1 -0
  15. package/dest/errors/tx-pool.error.js +9 -0
  16. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -1
  17. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  18. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
  19. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  20. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  21. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  22. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -3
  23. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  24. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  26. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  27. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  29. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  30. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  32. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +2 -2
  33. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -5
  34. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  35. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +12 -6
  37. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  38. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  40. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  41. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  43. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  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 -1
  46. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  47. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  48. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  49. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +16 -6
  50. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
  52. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +29 -5
  53. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +71 -6
  55. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
  56. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  57. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +21 -12
  58. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +6 -3
  59. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -5
  61. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +11 -5
  62. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +274 -149
  64. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  65. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  66. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  67. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  68. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  69. package/dest/msg_validators/tx_validator/factory.js +219 -58
  70. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  71. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  72. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  73. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  74. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/index.js +1 -0
  76. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  77. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  78. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  79. package/dest/services/dummy_service.d.ts +4 -4
  80. package/dest/services/dummy_service.d.ts.map +1 -1
  81. package/dest/services/dummy_service.js +4 -4
  82. package/dest/services/encoding.d.ts +2 -2
  83. package/dest/services/encoding.d.ts.map +1 -1
  84. package/dest/services/encoding.js +9 -8
  85. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  86. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  87. package/dest/services/gossipsub/topic_score_params.js +32 -10
  88. package/dest/services/libp2p/libp2p_service.d.ts +16 -13
  89. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  90. package/dest/services/libp2p/libp2p_service.js +69 -81
  91. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  92. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  93. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  94. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  95. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  96. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  97. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  98. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  99. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  100. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  101. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  102. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  103. package/dest/services/reqresp/reqresp.d.ts +1 -1
  104. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  105. package/dest/services/reqresp/reqresp.js +2 -1
  106. package/dest/services/service.d.ts +5 -3
  107. package/dest/services/service.d.ts.map +1 -1
  108. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  109. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  110. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  111. package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
  112. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  113. package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
  114. package/dest/services/tx_collection/file_store_tx_source.d.ts +15 -6
  115. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  116. package/dest/services/tx_collection/file_store_tx_source.js +47 -16
  117. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  118. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  119. package/dest/services/tx_collection/instrumentation.js +2 -1
  120. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  121. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  122. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  123. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  124. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  125. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  126. package/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
  127. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  128. package/dest/services/tx_collection/slow_tx_collection.js +10 -8
  129. package/dest/services/tx_collection/tx_collection.d.ts +5 -4
  130. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  131. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  132. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  133. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  134. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  135. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  136. package/dest/services/tx_collection/tx_source.js +19 -2
  137. package/dest/services/tx_file_store/tx_file_store.js +1 -1
  138. package/dest/services/tx_provider.d.ts +3 -3
  139. package/dest/services/tx_provider.d.ts.map +1 -1
  140. package/dest/services/tx_provider.js +4 -4
  141. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  142. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  143. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  144. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  145. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  146. package/dest/test-helpers/mock-pubsub.js +8 -2
  147. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  148. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  149. package/dest/test-helpers/reqresp-nodes.js +2 -2
  150. package/dest/test-helpers/testbench-utils.d.ts +6 -3
  151. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  152. package/dest/test-helpers/testbench-utils.js +1 -1
  153. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  154. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  155. package/dest/testbench/p2p_client_testbench_worker.js +11 -11
  156. package/dest/util.d.ts +2 -2
  157. package/dest/util.d.ts.map +1 -1
  158. package/package.json +14 -14
  159. package/src/client/factory.ts +27 -48
  160. package/src/client/interface.ts +11 -20
  161. package/src/client/p2p_client.ts +47 -104
  162. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
  163. package/src/config.ts +2 -10
  164. package/src/errors/tx-pool.error.ts +12 -0
  165. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
  166. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  167. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -3
  168. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  169. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  170. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  171. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +2 -2
  172. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  173. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -9
  174. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  175. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  176. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  177. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  178. package/src/mem_pools/tx_pool_v2/interfaces.ts +15 -6
  179. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +96 -10
  180. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +25 -14
  181. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +12 -7
  182. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +303 -144
  183. package/src/msg_validators/tx_validator/README.md +115 -0
  184. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  185. package/src/msg_validators/tx_validator/factory.ts +353 -77
  186. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  187. package/src/msg_validators/tx_validator/index.ts +1 -0
  188. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  189. package/src/services/dummy_service.ts +6 -6
  190. package/src/services/encoding.ts +7 -7
  191. package/src/services/gossipsub/README.md +29 -14
  192. package/src/services/gossipsub/topic_score_params.ts +49 -13
  193. package/src/services/libp2p/libp2p_service.ts +80 -90
  194. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  195. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  196. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  197. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  198. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  199. package/src/services/reqresp/reqresp.ts +3 -1
  200. package/src/services/service.ts +11 -2
  201. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  202. package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
  203. package/src/services/tx_collection/file_store_tx_source.ts +61 -17
  204. package/src/services/tx_collection/instrumentation.ts +7 -1
  205. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  206. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  207. package/src/services/tx_collection/slow_tx_collection.ts +8 -9
  208. package/src/services/tx_collection/tx_collection.ts +4 -3
  209. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  210. package/src/services/tx_collection/tx_source.ts +22 -3
  211. package/src/services/tx_file_store/tx_file_store.ts +1 -1
  212. package/src/services/tx_provider.ts +2 -2
  213. package/src/test-helpers/make-test-p2p-clients.ts +0 -2
  214. package/src/test-helpers/mock-pubsub.ts +13 -6
  215. package/src/test-helpers/reqresp-nodes.ts +2 -5
  216. package/src/test-helpers/testbench-utils.ts +3 -3
  217. package/src/testbench/p2p_client_testbench_worker.ts +20 -17
  218. package/src/util.ts +7 -1
@@ -6,7 +6,8 @@ import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
6
6
  import { Tx, TxHash } from '@aztec/stdlib/tx';
7
7
  import { TxArchive } from './archive/index.js';
8
8
  import { DeletedPool } from './deleted_pool.js';
9
- import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule } from './eviction/index.js';
9
+ import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule, TxPoolRejectionCode } from './eviction/index.js';
10
+ import { TxPoolV2Instrumentation } from './instrumentation.js';
10
11
  import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
11
12
  import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
12
13
  import { TxPoolIndices } from './tx_pool_indices.js';
@@ -30,9 +31,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
30
31
  #deletedPool;
31
32
  #evictionManager;
32
33
  #dateProvider;
34
+ #instrumentation;
35
+ #evictedTxHashes = new Set();
33
36
  #log;
34
37
  #callbacks;
35
- constructor(store, archiveStore, deps, callbacks, config = {}, dateProvider, log){
38
+ constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
36
39
  this.#store = store;
37
40
  this.#txsDB = store.openMap('txs');
38
41
  this.#l2BlockSource = deps.l2BlockSource;
@@ -45,6 +48,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
45
48
  this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
46
49
  this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
47
50
  this.#dateProvider = dateProvider;
51
+ this.#instrumentation = new TxPoolV2Instrumentation(telemetry, ()=>this.#indices.getTotalMetadataBytes());
48
52
  this.#log = log;
49
53
  this.#callbacks = callbacks;
50
54
  // Setup eviction manager with rules
@@ -122,8 +126,34 @@ import { TxPoolIndices } from './tx_pool_indices.js';
122
126
  const accepted = [];
123
127
  const ignored = [];
124
128
  const rejected = [];
129
+ const errors = new Map();
125
130
  const acceptedPending = new Set();
131
+ // Phase 1: Pre-compute all throwable I/O outside the transaction.
132
+ // If any pre-computation throws, the entire call fails before mutations happen.
133
+ const precomputed = new Map();
134
+ const validator = await this.#createTxValidator();
135
+ for (const tx of txs){
136
+ const txHash = tx.getTxHash();
137
+ const txHashStr = txHash.toString();
138
+ const meta = await buildTxMetaData(tx);
139
+ const minedBlockId = await this.#getMinedBlockId(txHash);
140
+ // Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
141
+ let isValid = true;
142
+ if (!minedBlockId) {
143
+ isValid = await this.#validateMeta(meta, validator);
144
+ }
145
+ precomputed.set(txHashStr, {
146
+ meta,
147
+ minedBlockId,
148
+ isValid
149
+ });
150
+ }
151
+ // Phase 2: Apply mutations inside the transaction using only pre-computed results,
152
+ // in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
126
153
  const poolAccess = this.#createPreAddPoolAccess();
154
+ const preAddContext = opts.feeComparisonOnly !== undefined ? {
155
+ feeComparisonOnly: opts.feeComparisonOnly
156
+ } : undefined;
127
157
  await this.#store.transactionAsync(async ()=>{
128
158
  for (const tx of txs){
129
159
  const txHash = tx.getTxHash();
@@ -133,85 +163,112 @@ import { TxPoolIndices } from './tx_pool_indices.js';
133
163
  ignored.push(txHash);
134
164
  continue;
135
165
  }
136
- // Check mined status first (applies to all paths)
137
- const minedBlockId = await this.#getMinedBlockId(txHash);
166
+ const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
138
167
  const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
139
168
  if (minedBlockId) {
140
169
  // Already mined - add directly (protection already set if pre-protected)
141
170
  await this.#addTx(tx, {
142
171
  mined: minedBlockId
143
- }, opts);
172
+ }, opts, meta);
144
173
  accepted.push(txHash);
145
174
  } else if (preProtectedSlot !== undefined) {
146
175
  // Pre-protected and not mined - add as protected (bypass validation)
147
176
  await this.#addTx(tx, {
148
177
  protected: preProtectedSlot
149
- }, opts);
178
+ }, opts, meta);
150
179
  accepted.push(txHash);
180
+ } else if (!isValid) {
181
+ // Failed pre-computed validation
182
+ rejected.push(txHash);
151
183
  } else {
152
- // Regular pending tx - validate and run pre-add rules
153
- const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
184
+ // Regular pending tx - run pre-add rules using pre-computed metadata
185
+ const result = await this.#tryAddRegularPendingTx(tx, meta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
154
186
  if (result.status === 'accepted') {
155
187
  acceptedPending.add(txHashStr);
156
- } else if (result.status === 'rejected') {
157
- rejected.push(txHash);
158
188
  } else {
159
189
  ignored.push(txHash);
160
190
  }
161
191
  }
162
192
  }
193
+ // Run post-add eviction rules for pending txs (inside transaction for atomicity)
194
+ if (acceptedPending.size > 0) {
195
+ const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
196
+ const uniqueFeePayers = new Set(feePayers);
197
+ await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
198
+ ...uniqueFeePayers
199
+ ]);
200
+ }
163
201
  });
164
202
  // Build final accepted list for pending txs (excludes intra-batch evictions)
165
203
  for (const txHashStr of acceptedPending){
166
204
  accepted.push(TxHash.fromString(txHashStr));
167
205
  }
168
- // Run post-add eviction rules for pending txs
169
- if (acceptedPending.size > 0) {
170
- const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
171
- const uniqueFeePayers = new Set(feePayers);
172
- await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
173
- ...uniqueFeePayers
174
- ]);
206
+ // Record metrics
207
+ if (ignored.length > 0) {
208
+ this.#instrumentation.recordIgnored(ignored.length);
209
+ }
210
+ if (rejected.length > 0) {
211
+ this.#instrumentation.recordRejected(rejected.length);
175
212
  }
176
213
  return {
177
214
  accepted,
178
215
  ignored,
179
- rejected
216
+ rejected,
217
+ ...errors.size > 0 ? {
218
+ errors
219
+ } : {}
180
220
  };
181
221
  }
182
- /** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored) {
183
- const txHash = tx.getTxHash();
184
- const txHashStr = txHash.toString();
185
- // Build metadata and validate using metadata
186
- const meta = await buildTxMetaData(tx);
187
- if (!await this.#validateMeta(meta)) {
188
- return {
189
- status: 'rejected'
190
- };
191
- }
222
+ /** Adds a validated pending tx, running pre-add rules and evicting conflicts. */ async #tryAddRegularPendingTx(tx, precomputedMeta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
223
+ const txHashStr = tx.getTxHash().toString();
192
224
  // Run pre-add rules
193
- const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
225
+ const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
194
226
  if (preAddResult.shouldIgnore) {
195
- this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
227
+ this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
228
+ if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
229
+ errors.set(txHashStr, preAddResult.reason);
230
+ }
196
231
  return {
197
232
  status: 'ignored'
198
233
  };
199
234
  }
200
- // Evict conflicts
201
- for (const evictHashStr of preAddResult.txHashesToEvict){
202
- await this.#deleteTx(evictHashStr);
203
- this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
204
- evictedTxHash: evictHashStr,
205
- replacementTxHash: txHashStr
206
- });
207
- if (acceptedPending.has(evictHashStr)) {
208
- // Evicted tx was from this batch - mark as ignored in result
209
- acceptedPending.delete(evictHashStr);
210
- ignored.push(TxHash.fromString(evictHashStr));
235
+ // Evict conflicts, grouped by rule name for metrics
236
+ if (preAddResult.evictions && preAddResult.evictions.length > 0) {
237
+ const byReason = new Map();
238
+ for (const { txHash: evictHash, reason } of preAddResult.evictions){
239
+ const group = byReason.get(reason);
240
+ if (group) {
241
+ group.push(evictHash);
242
+ } else {
243
+ byReason.set(reason, [
244
+ evictHash
245
+ ]);
246
+ }
247
+ }
248
+ for (const [reason, hashes] of byReason){
249
+ await this.#evictTxs(hashes, reason);
250
+ }
251
+ for (const evictHashStr of preAddResult.txHashesToEvict){
252
+ this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
253
+ evictedTxHash: evictHashStr,
254
+ replacementTxHash: txHashStr
255
+ });
256
+ if (acceptedPending.has(evictHashStr)) {
257
+ // Evicted tx was from this batch - mark as ignored in result
258
+ acceptedPending.delete(evictHashStr);
259
+ ignored.push(TxHash.fromString(evictHashStr));
260
+ }
211
261
  }
212
262
  }
263
+ // Randomly drop the transaction for testing purposes (report as accepted so it propagates)
264
+ if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
265
+ this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
266
+ return {
267
+ status: 'accepted'
268
+ };
269
+ }
213
270
  // Add the transaction
214
- await this.#addTx(tx, 'pending', opts);
271
+ await this.#addTx(tx, 'pending', opts, precomputedMeta);
215
272
  return {
216
273
  status: 'accepted'
217
274
  };
@@ -222,13 +279,8 @@ import { TxPoolIndices } from './tx_pool_indices.js';
222
279
  if (this.#indices.has(txHashStr)) {
223
280
  return 'ignored';
224
281
  }
225
- // Build metadata and validate using metadata
282
+ // Build metadata and check pre-add rules
226
283
  const meta = await buildTxMetaData(tx);
227
- const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
228
- if (validationResult !== true) {
229
- return 'rejected';
230
- }
231
- // Use pre-add rules
232
284
  const poolAccess = this.#createPreAddPoolAccess();
233
285
  const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
234
286
  return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
@@ -264,20 +316,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
264
316
  }
265
317
  });
266
318
  }
267
- protectTxs(txHashes, block) {
319
+ async protectTxs(txHashes, block) {
268
320
  const slotNumber = block.globalVariables.slotNumber;
269
321
  const missing = [];
270
- for (const txHash of txHashes){
271
- const txHashStr = txHash.toString();
272
- if (this.#indices.has(txHashStr)) {
273
- // Update protection for existing tx
274
- this.#indices.updateProtection(txHashStr, slotNumber);
275
- } else {
276
- // Pre-record protection for tx we don't have yet
277
- this.#indices.setProtection(txHashStr, slotNumber);
278
- missing.push(txHash);
322
+ let softDeletedHits = 0;
323
+ let missingPreviouslyEvicted = 0;
324
+ await this.#store.transactionAsync(async ()=>{
325
+ for (const txHash of txHashes){
326
+ const txHashStr = txHash.toString();
327
+ if (this.#indices.has(txHashStr)) {
328
+ // Update protection for existing tx
329
+ this.#indices.updateProtection(txHashStr, slotNumber);
330
+ } else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
331
+ // Resurrect soft-deleted tx as protected
332
+ const buffer = await this.#txsDB.getAsync(txHashStr);
333
+ if (buffer) {
334
+ const tx = Tx.fromBuffer(buffer);
335
+ await this.#addTx(tx, {
336
+ protected: slotNumber
337
+ });
338
+ softDeletedHits++;
339
+ } else {
340
+ // Data missing despite soft-delete flag — treat as truly missing
341
+ this.#indices.setProtection(txHashStr, slotNumber);
342
+ missing.push(txHash);
343
+ }
344
+ } else {
345
+ // Truly missing — pre-record protection for tx we don't have yet
346
+ this.#indices.setProtection(txHashStr, slotNumber);
347
+ missing.push(txHash);
348
+ if (this.#evictedTxHashes.has(txHashStr)) {
349
+ missingPreviouslyEvicted++;
350
+ }
351
+ }
279
352
  }
353
+ });
354
+ // Record metrics
355
+ if (softDeletedHits > 0) {
356
+ this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
280
357
  }
358
+ if (missing.length > 0) {
359
+ this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
360
+ this.#instrumentation.recordMissingOnProtect(missing.length);
361
+ }
362
+ if (missingPreviouslyEvicted > 0) {
363
+ this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
364
+ }
365
+ this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
281
366
  return missing;
282
367
  }
283
368
  async addMinedTxs(txs, block, opts) {
@@ -316,47 +401,50 @@ import { TxPoolIndices } from './tx_pool_indices.js';
316
401
  found.push(meta);
317
402
  }
318
403
  }
319
- // Step 4: Mark txs as mined (only those we have in the pool)
320
- for (const meta of found){
321
- this.#indices.markAsMined(meta, blockId);
322
- await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
323
- }
324
- // Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
325
- await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
404
+ await this.#store.transactionAsync(async ()=>{
405
+ // Step 4: Mark txs as mined (only those we have in the pool)
406
+ for (const meta of found){
407
+ this.#indices.markAsMined(meta, blockId);
408
+ await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
409
+ }
410
+ // Step 5: Run post-event eviction rules (inside transaction for atomicity)
411
+ await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
412
+ });
326
413
  this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
327
414
  }
328
415
  async prepareForSlot(slotNumber) {
329
- // Step 0: Clean up slot-deleted txs from previous slots
330
- await this.#deletedPool.cleanupSlotDeleted(slotNumber);
331
- // Step 1: Find expired protected txs
332
- const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
333
- // Step 2: Clear protection for all expired entries (including those without metadata)
334
- this.#indices.clearProtection(expiredProtected);
335
- // Step 3: Filter to only txs that have metadata and are not mined
336
- const txsToRestore = this.#indices.filterRestorable(expiredProtected);
337
- if (txsToRestore.length === 0) {
338
- return;
339
- }
340
- this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
341
- // Step 4: Validate for pending pool
342
- const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
343
- // Step 5: Resolve nullifier conflicts and add winners to pending indices
344
- const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
345
- // Step 6: Delete invalid and evicted txs
346
- await this.#deleteTxsBatch([
347
- ...invalid,
348
- ...toEvict
349
- ]);
350
- // Step 7: Run eviction rules (enforce pool size limit)
351
- if (added.length > 0) {
352
- const feePayers = added.map((meta)=>meta.feePayer);
353
- const uniqueFeePayers = new Set(feePayers);
354
- await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
355
- ...uniqueFeePayers
356
- ]);
357
- }
416
+ await this.#store.transactionAsync(async ()=>{
417
+ // Step 0: Clean up slot-deleted txs from previous slots
418
+ await this.#deletedPool.cleanupSlotDeleted(slotNumber);
419
+ // Step 1: Find expired protected txs
420
+ const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
421
+ // Step 2: Clear protection for all expired entries (including those without metadata)
422
+ this.#indices.clearProtection(expiredProtected);
423
+ // Step 3: Filter to only txs that have metadata and are not mined
424
+ const txsToRestore = this.#indices.filterRestorable(expiredProtected);
425
+ if (txsToRestore.length === 0) {
426
+ this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
427
+ return;
428
+ }
429
+ this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
430
+ // Step 4: Validate for pending pool
431
+ const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
432
+ // Step 5: Resolve nullifier conflicts and add winners to pending indices
433
+ const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
434
+ // Step 6: Delete invalid txs and evict conflict losers
435
+ await this.#deleteTxsBatch(invalid);
436
+ await this.#evictTxs(toEvict, 'NullifierConflict');
437
+ // Step 7: Run eviction rules (enforce pool size limit)
438
+ if (added.length > 0) {
439
+ const feePayers = added.map((meta)=>meta.feePayer);
440
+ const uniqueFeePayers = new Set(feePayers);
441
+ await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
442
+ ...uniqueFeePayers
443
+ ]);
444
+ }
445
+ });
358
446
  }
359
- async handlePrunedBlocks(latestBlock) {
447
+ async handlePrunedBlocks(latestBlock, options) {
360
448
  // Step 1: Find transactions mined after the prune point
361
449
  const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
362
450
  if (txsToUnmine.length === 0) {
@@ -364,40 +452,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
364
452
  return;
365
453
  }
366
454
  this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
367
- // Step 2: Mark ALL un-mined txs with their original mined block number
368
- // This ensures they get soft-deleted if removed later, and only hard-deleted
369
- // when their original mined block is finalized
370
- await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
371
- txHash: m.txHash,
372
- minedAtBlock: BlockNumber(m.minedL2BlockId.number)
373
- })));
374
- // Step 3: Unmine - clear mined status from metadata
375
- for (const meta of txsToUnmine){
376
- this.#indices.markAsUnmined(meta);
377
- }
378
- // Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
379
- const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
380
- // Step 4: Validate for pending pool
381
- const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
382
- // Step 6: Resolve nullifier conflicts and add winners to pending indices
383
- const { toEvict } = this.#applyNullifierConflictResolution(valid);
384
- // Step 7: Delete invalid and evicted txs
385
- await this.#deleteTxsBatch([
386
- ...invalid,
387
- ...toEvict
388
- ]);
389
- this.#log.info(`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`, {
390
- txHashesRestored: valid.map((m)=>m.txHash),
391
- txHashesInvalid: invalid,
392
- txHashesEvicted: toEvict
455
+ await this.#store.transactionAsync(async ()=>{
456
+ // Step 2: Mark ALL un-mined txs with their original mined block number
457
+ // This ensures they get soft-deleted if removed later, and only hard-deleted
458
+ // when their original mined block is finalized
459
+ await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
460
+ txHash: m.txHash,
461
+ minedAtBlock: BlockNumber(m.minedL2BlockId.number)
462
+ })));
463
+ // Step 3: Unmine - clear mined status from metadata
464
+ for (const meta of txsToUnmine){
465
+ this.#indices.markAsUnmined(meta);
466
+ }
467
+ // If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
468
+ if (options?.deleteAllTxs) {
469
+ const allTxHashes = txsToUnmine.map((m)=>m.txHash);
470
+ await this.#deleteTxsBatch(allTxHashes);
471
+ this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
472
+ return;
473
+ }
474
+ // Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
475
+ const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
476
+ // Step 5: Validate for pending pool
477
+ const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
478
+ // Step 6: Resolve nullifier conflicts and add winners to pending indices
479
+ const { toEvict } = this.#applyNullifierConflictResolution(valid);
480
+ // Step 7: Delete invalid txs and evict conflict losers
481
+ await this.#deleteTxsBatch(invalid);
482
+ await this.#evictTxs(toEvict, 'NullifierConflict');
483
+ this.#log.info(`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`, {
484
+ txHashesRestored: valid.map((m)=>m.txHash),
485
+ txHashesInvalid: invalid,
486
+ txHashesEvicted: toEvict
487
+ });
488
+ // Step 8: Run eviction rules for ALL pending txs (not just restored ones)
489
+ // This handles cases like existing pending txs with invalid fee payer balances
490
+ await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
393
491
  });
394
- // Step 8: Run eviction rules for ALL pending txs (not just restored ones)
395
- // This handles cases like existing pending txs with invalid fee payer balances
396
- await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
397
492
  }
398
493
  async handleFailedExecution(txHashes) {
399
- // Delete failed txs
400
- await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
494
+ await this.#store.transactionAsync(async ()=>{
495
+ await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
496
+ });
401
497
  this.#log.info(`Deleted ${txHashes.length} failed txs`, {
402
498
  txHashes: txHashes.map((h)=>h.toString())
403
499
  });
@@ -406,24 +502,26 @@ import { TxPoolIndices } from './tx_pool_indices.js';
406
502
  const blockNumber = block.globalVariables.blockNumber;
407
503
  // Step 1: Find mined txs at or before finalized block
408
504
  const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
409
- // Step 2: Collect mined txs for archiving (before deletion)
410
- const txsToArchive = [];
411
- if (this.#archive.isEnabled()) {
412
- for (const txHashStr of minedTxsToFinalize){
413
- const buffer = await this.#txsDB.getAsync(txHashStr);
414
- if (buffer) {
415
- txsToArchive.push(Tx.fromBuffer(buffer));
505
+ await this.#store.transactionAsync(async ()=>{
506
+ // Step 2: Collect mined txs for archiving (before deletion)
507
+ const txsToArchive = [];
508
+ if (this.#archive.isEnabled()) {
509
+ for (const txHashStr of minedTxsToFinalize){
510
+ const buffer = await this.#txsDB.getAsync(txHashStr);
511
+ if (buffer) {
512
+ txsToArchive.push(Tx.fromBuffer(buffer));
513
+ }
416
514
  }
417
515
  }
418
- }
419
- // Step 3: Delete mined txs from active pool
420
- await this.#deleteTxsBatch(minedTxsToFinalize);
421
- // Step 4: Finalize soft-deleted txs
422
- await this.#deletedPool.finalizeBlock(blockNumber);
423
- // Step 5: Archive mined txs
424
- if (txsToArchive.length > 0) {
425
- await this.#archive.archiveTxs(txsToArchive);
426
- }
516
+ // Step 3: Delete mined txs from active pool
517
+ await this.#deleteTxsBatch(minedTxsToFinalize);
518
+ // Step 4: Finalize soft-deleted txs
519
+ await this.#deletedPool.finalizeBlock(blockNumber);
520
+ // Step 5: Archive mined txs
521
+ if (txsToArchive.length > 0) {
522
+ await this.#archive.archiveTxs(txsToArchive);
523
+ }
524
+ });
427
525
  if (minedTxsToFinalize.length > 0) {
428
526
  this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
429
527
  txHashes: minedTxsToFinalize
@@ -528,7 +626,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
528
626
  }
529
627
  // === Metrics ===
530
628
  countTxs() {
531
- return this.#indices.countTxs();
629
+ return {
630
+ ...this.#indices.countTxs(),
631
+ softDeleted: this.#deletedPool.getSoftDeletedCount()
632
+ };
532
633
  }
533
634
  // ============================================================================
534
635
  // PRIVATE HELPERS - Transaction Management
@@ -536,9 +637,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
536
637
  /**
537
638
  * Adds a new transaction to the pool with the specified state.
538
639
  * Emits onTxsAdded callback immediately after DB write.
539
- */ async #addTx(tx, state, opts = {}) {
640
+ */ async #addTx(tx, state, opts = {}, precomputedMeta) {
540
641
  const txHashStr = tx.getTxHash().toString();
541
- const meta = await buildTxMetaData(tx);
642
+ const meta = precomputedMeta ?? await buildTxMetaData(tx);
542
643
  meta.receivedAt = this.#dateProvider.now();
543
644
  await this.#txsDB.set(txHashStr, tx.toBuffer());
544
645
  await this.#deletedPool.clearSoftDeleted(txHashStr);
@@ -554,9 +655,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
554
655
  this.#indices.addMined(meta);
555
656
  }
556
657
  const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
557
- this.#log.verbose(`Added ${stateStr} tx ${txHashStr}`, {
658
+ this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
558
659
  eventName: 'tx-added-to-pool',
559
- state: stateStr
660
+ txHash: txHashStr,
661
+ state: stateStr,
662
+ source: opts.source
560
663
  });
561
664
  return meta;
562
665
  }
@@ -579,6 +682,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
579
682
  await this.#deleteTx(txHashStr);
580
683
  }
581
684
  }
685
+ /** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
686
+ if (txHashes.length === 0) {
687
+ return;
688
+ }
689
+ this.#instrumentation.recordEvictions(txHashes.length, reason);
690
+ for (const txHashStr of txHashes){
691
+ this.#log.debug(`Evicting tx ${txHashStr}`, {
692
+ txHash: txHashStr,
693
+ reason
694
+ });
695
+ this.#addToEvictedCache(txHashStr);
696
+ }
697
+ await this.#deleteTxsBatch(txHashes);
698
+ }
699
+ /** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
700
+ if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
701
+ // FIFO eviction: remove the first (oldest) entry
702
+ const oldest = this.#evictedTxHashes.values().next().value;
703
+ this.#evictedTxHashes.delete(oldest);
704
+ }
705
+ this.#evictedTxHashes.add(txHashStr);
706
+ }
582
707
  // ============================================================================
583
708
  // PRIVATE HELPERS - Validation & Conflict Resolution
584
709
  // ============================================================================
@@ -717,7 +842,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
717
842
  if (preAddResult.shouldIgnore) {
718
843
  // Transaction rejected - mark for deletion from DB
719
844
  rejected.push(meta.txHash);
720
- this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
845
+ this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
721
846
  continue;
722
847
  }
723
848
  // Evict any conflicting txs identified by pre-add rules
@@ -753,7 +878,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
753
878
  getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
754
879
  getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
755
880
  getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
756
- deleteTxs: (txHashes)=>this.#deleteTxsBatch(txHashes)
881
+ deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
757
882
  };
758
883
  }
759
884
  #createPreAddPoolAccess() {
@@ -1,7 +1,7 @@
1
1
  import type { TxValidationResult, TxValidator } from '@aztec/stdlib/tx';
2
2
  export declare class AggregateTxValidator<T> implements TxValidator<T> {
3
- #private;
3
+ readonly validators: TxValidator<T>[];
4
4
  constructor(...validators: TxValidator<T>[]);
5
5
  validateTx(tx: T): Promise<TxValidationResult>;
6
6
  }
7
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdncmVnYXRlX3R4X3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci9hZ2dyZWdhdGVfdHhfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLFdBQVcsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXhFLHFCQUFhLG9CQUFvQixDQUFDLENBQUMsQ0FBRSxZQUFXLFdBQVcsQ0FBQyxDQUFDLENBQUM7O0lBRTVELFlBQVksR0FBRyxVQUFVLEVBQUUsV0FBVyxDQUFDLENBQUMsQ0FBQyxFQUFFLEVBTTFDO0lBRUssVUFBVSxDQUFDLEVBQUUsRUFBRSxDQUFDLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBa0JuRDtDQUNGIn0=
7
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdncmVnYXRlX3R4X3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci9hZ2dyZWdhdGVfdHhfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLFdBQVcsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXhFLHFCQUFhLG9CQUFvQixDQUFDLENBQUMsQ0FBRSxZQUFXLFdBQVcsQ0FBQyxDQUFDLENBQUM7SUFDNUQsUUFBUSxDQUFDLFVBQVUsRUFBRSxXQUFXLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQztJQUN0QyxZQUFZLEdBQUcsVUFBVSxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUMsRUFBRSxFQU0xQztJQUVLLFVBQVUsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQWtCbkQ7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate_tx_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/aggregate_tx_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,oBAAoB,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;IAE5D,YAAY,GAAG,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAM1C;IAEK,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkBnD;CACF"}
1
+ {"version":3,"file":"aggregate_tx_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/aggregate_tx_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,oBAAoB,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,YAAY,GAAG,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAM1C;IAEK,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkBnD;CACF"}
@@ -1,17 +1,17 @@
1
1
  export class AggregateTxValidator {
2
- #validators;
2
+ validators;
3
3
  constructor(...validators){
4
4
  if (validators.length === 0) {
5
5
  throw new Error('At least one validator must be provided');
6
6
  }
7
- this.#validators = validators;
7
+ this.validators = validators;
8
8
  }
9
9
  async validateTx(tx) {
10
10
  const aggregate = {
11
11
  result: 'valid',
12
12
  reason: []
13
13
  };
14
- for (const validator of this.#validators){
14
+ for (const validator of this.validators){
15
15
  const result = await validator.validateTx(tx);
16
16
  if (result.result === 'invalid') {
17
17
  aggregate.result = 'invalid';