@aztec/p2p 0.0.1-commit.7cf39cb55 → 0.0.1-commit.808bf7f90

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 (187) hide show
  1. package/dest/client/factory.d.ts +3 -2
  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 +7 -9
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +4 -7
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +38 -14
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +5 -5
  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/attestation_pool/mocks.d.ts +2 -2
  17. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  19. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  20. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -1
  21. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
  23. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  24. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  26. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -3
  27. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  28. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  29. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +10 -4
  30. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  31. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  32. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  33. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  34. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  35. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  36. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +4 -4
  37. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -5
  38. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  39. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +12 -6
  41. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  42. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  44. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  45. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  46. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  47. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  48. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  49. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  50. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +12 -2
  51. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  52. package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
  53. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +7 -5
  54. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  55. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +29 -5
  56. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
  57. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  58. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +12 -2
  59. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +5 -2
  60. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  61. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -5
  62. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +10 -4
  63. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  64. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +240 -124
  65. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  66. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  67. package/dest/msg_validators/tx_validator/gas_validator.js +3 -3
  68. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  69. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  70. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  71. package/dest/services/dummy_service.d.ts +3 -2
  72. package/dest/services/dummy_service.d.ts.map +1 -1
  73. package/dest/services/dummy_service.js +3 -0
  74. package/dest/services/encoding.d.ts +1 -1
  75. package/dest/services/encoding.d.ts.map +1 -1
  76. package/dest/services/encoding.js +2 -1
  77. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  78. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  79. package/dest/services/gossipsub/topic_score_params.js +32 -10
  80. package/dest/services/libp2p/libp2p_service.d.ts +2 -1
  81. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  82. package/dest/services/libp2p/libp2p_service.js +7 -3
  83. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  84. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  85. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +5 -9
  86. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  87. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  88. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  89. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  90. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  91. package/dest/services/service.d.ts +4 -2
  92. package/dest/services/service.d.ts.map +1 -1
  93. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  94. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  95. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  96. package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
  97. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  98. package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
  99. package/dest/services/tx_collection/file_store_tx_source.d.ts +15 -6
  100. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  101. package/dest/services/tx_collection/file_store_tx_source.js +47 -16
  102. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  103. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  104. package/dest/services/tx_collection/instrumentation.js +2 -1
  105. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  106. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  107. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  108. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  109. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  110. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  111. package/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
  112. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  113. package/dest/services/tx_collection/slow_tx_collection.js +10 -8
  114. package/dest/services/tx_collection/tx_collection.d.ts +5 -4
  115. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  116. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  117. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  118. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  119. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  120. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  121. package/dest/services/tx_collection/tx_source.js +19 -2
  122. package/dest/services/tx_file_store/tx_file_store.js +1 -1
  123. package/dest/test-helpers/mock-pubsub.d.ts +3 -2
  124. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  125. package/dest/test-helpers/mock-pubsub.js +6 -0
  126. package/dest/test-helpers/testbench-utils.d.ts +5 -2
  127. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  128. package/dest/test-helpers/testbench-utils.js +1 -1
  129. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  130. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  131. package/dest/testbench/p2p_client_testbench_worker.js +8 -8
  132. package/dest/util.d.ts +2 -2
  133. package/dest/util.d.ts.map +1 -1
  134. package/package.json +14 -14
  135. package/src/client/factory.ts +6 -2
  136. package/src/client/interface.ts +14 -9
  137. package/src/client/p2p_client.ts +44 -17
  138. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
  139. package/src/config.ts +2 -10
  140. package/src/errors/tx-pool.error.ts +12 -0
  141. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  142. package/src/mem_pools/tx_pool/README.md +1 -1
  143. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  144. package/src/mem_pools/tx_pool_v2/README.md +1 -1
  145. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
  146. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  147. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -3
  148. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
  149. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  150. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  151. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +4 -4
  152. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  153. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -9
  154. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  155. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  156. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  157. package/src/mem_pools/tx_pool_v2/interfaces.ts +11 -2
  158. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +40 -9
  159. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +14 -3
  160. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +11 -6
  161. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +262 -117
  162. package/src/msg_validators/tx_validator/gas_validator.ts +11 -3
  163. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  164. package/src/services/dummy_service.ts +5 -1
  165. package/src/services/encoding.ts +2 -1
  166. package/src/services/gossipsub/README.md +29 -14
  167. package/src/services/gossipsub/topic_score_params.ts +49 -13
  168. package/src/services/libp2p/libp2p_service.ts +7 -2
  169. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +6 -6
  170. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  171. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  172. package/src/services/service.ts +10 -1
  173. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  174. package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
  175. package/src/services/tx_collection/file_store_tx_source.ts +61 -17
  176. package/src/services/tx_collection/instrumentation.ts +7 -1
  177. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  178. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  179. package/src/services/tx_collection/slow_tx_collection.ts +8 -9
  180. package/src/services/tx_collection/tx_collection.ts +4 -3
  181. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  182. package/src/services/tx_collection/tx_source.ts +22 -3
  183. package/src/services/tx_file_store/tx_file_store.ts +1 -1
  184. package/src/test-helpers/mock-pubsub.ts +10 -0
  185. package/src/test-helpers/testbench-utils.ts +2 -2
  186. package/src/testbench/p2p_client_testbench_worker.ts +20 -13
  187. 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,12 @@ 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();
126
131
  const poolAccess = this.#createPreAddPoolAccess();
132
+ const preAddContext = opts.feeComparisonOnly !== undefined ? {
133
+ feeComparisonOnly: opts.feeComparisonOnly
134
+ } : undefined;
127
135
  await this.#store.transactionAsync(async ()=>{
128
136
  for (const tx of txs){
129
137
  const txHash = tx.getTxHash();
@@ -150,7 +158,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
150
158
  accepted.push(txHash);
151
159
  } else {
152
160
  // Regular pending tx - validate and run pre-add rules
153
- const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
161
+ const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
154
162
  if (result.status === 'accepted') {
155
163
  acceptedPending.add(txHashStr);
156
164
  } else if (result.status === 'rejected') {
@@ -160,26 +168,36 @@ import { TxPoolIndices } from './tx_pool_indices.js';
160
168
  }
161
169
  }
162
170
  }
171
+ // Run post-add eviction rules for pending txs (inside transaction for atomicity)
172
+ if (acceptedPending.size > 0) {
173
+ const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
174
+ const uniqueFeePayers = new Set(feePayers);
175
+ await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
176
+ ...uniqueFeePayers
177
+ ]);
178
+ }
163
179
  });
164
180
  // Build final accepted list for pending txs (excludes intra-batch evictions)
165
181
  for (const txHashStr of acceptedPending){
166
182
  accepted.push(TxHash.fromString(txHashStr));
167
183
  }
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
- ]);
184
+ // Record metrics
185
+ if (ignored.length > 0) {
186
+ this.#instrumentation.recordIgnored(ignored.length);
187
+ }
188
+ if (rejected.length > 0) {
189
+ this.#instrumentation.recordRejected(rejected.length);
175
190
  }
176
191
  return {
177
192
  accepted,
178
193
  ignored,
179
- rejected
194
+ rejected,
195
+ ...errors.size > 0 ? {
196
+ errors
197
+ } : {}
180
198
  };
181
199
  }
182
- /** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored) {
200
+ /** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
183
201
  const txHash = tx.getTxHash();
184
202
  const txHashStr = txHash.toString();
185
203
  // Build metadata and validate using metadata
@@ -190,26 +208,51 @@ import { TxPoolIndices } from './tx_pool_indices.js';
190
208
  };
191
209
  }
192
210
  // Run pre-add rules
193
- const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
211
+ const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess, preAddContext);
194
212
  if (preAddResult.shouldIgnore) {
195
- this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
213
+ this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
214
+ if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
215
+ errors.set(txHashStr, preAddResult.reason);
216
+ }
196
217
  return {
197
218
  status: 'ignored'
198
219
  };
199
220
  }
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));
221
+ // Evict conflicts, grouped by rule name for metrics
222
+ if (preAddResult.evictions && preAddResult.evictions.length > 0) {
223
+ const byReason = new Map();
224
+ for (const { txHash: evictHash, reason } of preAddResult.evictions){
225
+ const group = byReason.get(reason);
226
+ if (group) {
227
+ group.push(evictHash);
228
+ } else {
229
+ byReason.set(reason, [
230
+ evictHash
231
+ ]);
232
+ }
233
+ }
234
+ for (const [reason, hashes] of byReason){
235
+ await this.#evictTxs(hashes, reason);
236
+ }
237
+ for (const evictHashStr of preAddResult.txHashesToEvict){
238
+ this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
239
+ evictedTxHash: evictHashStr,
240
+ replacementTxHash: txHashStr
241
+ });
242
+ if (acceptedPending.has(evictHashStr)) {
243
+ // Evicted tx was from this batch - mark as ignored in result
244
+ acceptedPending.delete(evictHashStr);
245
+ ignored.push(TxHash.fromString(evictHashStr));
246
+ }
211
247
  }
212
248
  }
249
+ // Randomly drop the transaction for testing purposes (report as accepted so it propagates)
250
+ if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
251
+ this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
252
+ return {
253
+ status: 'accepted'
254
+ };
255
+ }
213
256
  // Add the transaction
214
257
  await this.#addTx(tx, 'pending', opts);
215
258
  return {
@@ -264,20 +307,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
264
307
  }
265
308
  });
266
309
  }
267
- protectTxs(txHashes, block) {
310
+ async protectTxs(txHashes, block) {
268
311
  const slotNumber = block.globalVariables.slotNumber;
269
312
  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);
313
+ let softDeletedHits = 0;
314
+ let missingPreviouslyEvicted = 0;
315
+ await this.#store.transactionAsync(async ()=>{
316
+ for (const txHash of txHashes){
317
+ const txHashStr = txHash.toString();
318
+ if (this.#indices.has(txHashStr)) {
319
+ // Update protection for existing tx
320
+ this.#indices.updateProtection(txHashStr, slotNumber);
321
+ } else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
322
+ // Resurrect soft-deleted tx as protected
323
+ const buffer = await this.#txsDB.getAsync(txHashStr);
324
+ if (buffer) {
325
+ const tx = Tx.fromBuffer(buffer);
326
+ await this.#addTx(tx, {
327
+ protected: slotNumber
328
+ });
329
+ softDeletedHits++;
330
+ } else {
331
+ // Data missing despite soft-delete flag — treat as truly missing
332
+ this.#indices.setProtection(txHashStr, slotNumber);
333
+ missing.push(txHash);
334
+ }
335
+ } else {
336
+ // Truly missing — pre-record protection for tx we don't have yet
337
+ this.#indices.setProtection(txHashStr, slotNumber);
338
+ missing.push(txHash);
339
+ if (this.#evictedTxHashes.has(txHashStr)) {
340
+ missingPreviouslyEvicted++;
341
+ }
342
+ }
279
343
  }
344
+ });
345
+ // Record metrics
346
+ if (softDeletedHits > 0) {
347
+ this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
280
348
  }
349
+ if (missing.length > 0) {
350
+ this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
351
+ this.#instrumentation.recordMissingOnProtect(missing.length);
352
+ }
353
+ if (missingPreviouslyEvicted > 0) {
354
+ this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
355
+ }
356
+ this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
281
357
  return missing;
282
358
  }
283
359
  async addMinedTxs(txs, block, opts) {
@@ -316,47 +392,50 @@ import { TxPoolIndices } from './tx_pool_indices.js';
316
392
  found.push(meta);
317
393
  }
318
394
  }
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);
395
+ await this.#store.transactionAsync(async ()=>{
396
+ // Step 4: Mark txs as mined (only those we have in the pool)
397
+ for (const meta of found){
398
+ this.#indices.markAsMined(meta, blockId);
399
+ await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
400
+ }
401
+ // Step 5: Run post-event eviction rules (inside transaction for atomicity)
402
+ await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
403
+ });
326
404
  this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
327
405
  }
328
406
  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
- }
407
+ await this.#store.transactionAsync(async ()=>{
408
+ // Step 0: Clean up slot-deleted txs from previous slots
409
+ await this.#deletedPool.cleanupSlotDeleted(slotNumber);
410
+ // Step 1: Find expired protected txs
411
+ const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
412
+ // Step 2: Clear protection for all expired entries (including those without metadata)
413
+ this.#indices.clearProtection(expiredProtected);
414
+ // Step 3: Filter to only txs that have metadata and are not mined
415
+ const txsToRestore = this.#indices.filterRestorable(expiredProtected);
416
+ if (txsToRestore.length === 0) {
417
+ this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
418
+ return;
419
+ }
420
+ this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
421
+ // Step 4: Validate for pending pool
422
+ const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
423
+ // Step 5: Resolve nullifier conflicts and add winners to pending indices
424
+ const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
425
+ // Step 6: Delete invalid txs and evict conflict losers
426
+ await this.#deleteTxsBatch(invalid);
427
+ await this.#evictTxs(toEvict, 'NullifierConflict');
428
+ // Step 7: Run eviction rules (enforce pool size limit)
429
+ if (added.length > 0) {
430
+ const feePayers = added.map((meta)=>meta.feePayer);
431
+ const uniqueFeePayers = new Set(feePayers);
432
+ await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
433
+ ...uniqueFeePayers
434
+ ]);
435
+ }
436
+ });
358
437
  }
359
- async handlePrunedBlocks(latestBlock) {
438
+ async handlePrunedBlocks(latestBlock, options) {
360
439
  // Step 1: Find transactions mined after the prune point
361
440
  const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
362
441
  if (txsToUnmine.length === 0) {
@@ -364,40 +443,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
364
443
  return;
365
444
  }
366
445
  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
446
+ await this.#store.transactionAsync(async ()=>{
447
+ // Step 2: Mark ALL un-mined txs with their original mined block number
448
+ // This ensures they get soft-deleted if removed later, and only hard-deleted
449
+ // when their original mined block is finalized
450
+ await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
451
+ txHash: m.txHash,
452
+ minedAtBlock: BlockNumber(m.minedL2BlockId.number)
453
+ })));
454
+ // Step 3: Unmine - clear mined status from metadata
455
+ for (const meta of txsToUnmine){
456
+ this.#indices.markAsUnmined(meta);
457
+ }
458
+ // If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
459
+ if (options?.deleteAllTxs) {
460
+ const allTxHashes = txsToUnmine.map((m)=>m.txHash);
461
+ await this.#deleteTxsBatch(allTxHashes);
462
+ this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
463
+ return;
464
+ }
465
+ // Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
466
+ const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
467
+ // Step 5: Validate for pending pool
468
+ const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
469
+ // Step 6: Resolve nullifier conflicts and add winners to pending indices
470
+ const { toEvict } = this.#applyNullifierConflictResolution(valid);
471
+ // Step 7: Delete invalid txs and evict conflict losers
472
+ await this.#deleteTxsBatch(invalid);
473
+ await this.#evictTxs(toEvict, 'NullifierConflict');
474
+ 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`, {
475
+ txHashesRestored: valid.map((m)=>m.txHash),
476
+ txHashesInvalid: invalid,
477
+ txHashesEvicted: toEvict
478
+ });
479
+ // Step 8: Run eviction rules for ALL pending txs (not just restored ones)
480
+ // This handles cases like existing pending txs with invalid fee payer balances
481
+ await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
393
482
  });
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
483
  }
398
484
  async handleFailedExecution(txHashes) {
399
- // Delete failed txs
400
- await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
485
+ await this.#store.transactionAsync(async ()=>{
486
+ await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
487
+ });
401
488
  this.#log.info(`Deleted ${txHashes.length} failed txs`, {
402
489
  txHashes: txHashes.map((h)=>h.toString())
403
490
  });
@@ -406,24 +493,26 @@ import { TxPoolIndices } from './tx_pool_indices.js';
406
493
  const blockNumber = block.globalVariables.blockNumber;
407
494
  // Step 1: Find mined txs at or before finalized block
408
495
  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));
496
+ await this.#store.transactionAsync(async ()=>{
497
+ // Step 2: Collect mined txs for archiving (before deletion)
498
+ const txsToArchive = [];
499
+ if (this.#archive.isEnabled()) {
500
+ for (const txHashStr of minedTxsToFinalize){
501
+ const buffer = await this.#txsDB.getAsync(txHashStr);
502
+ if (buffer) {
503
+ txsToArchive.push(Tx.fromBuffer(buffer));
504
+ }
416
505
  }
417
506
  }
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
- }
507
+ // Step 3: Delete mined txs from active pool
508
+ await this.#deleteTxsBatch(minedTxsToFinalize);
509
+ // Step 4: Finalize soft-deleted txs
510
+ await this.#deletedPool.finalizeBlock(blockNumber);
511
+ // Step 5: Archive mined txs
512
+ if (txsToArchive.length > 0) {
513
+ await this.#archive.archiveTxs(txsToArchive);
514
+ }
515
+ });
427
516
  if (minedTxsToFinalize.length > 0) {
428
517
  this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
429
518
  txHashes: minedTxsToFinalize
@@ -528,7 +617,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
528
617
  }
529
618
  // === Metrics ===
530
619
  countTxs() {
531
- return this.#indices.countTxs();
620
+ return {
621
+ ...this.#indices.countTxs(),
622
+ softDeleted: this.#deletedPool.getSoftDeletedCount()
623
+ };
532
624
  }
533
625
  // ============================================================================
534
626
  // PRIVATE HELPERS - Transaction Management
@@ -554,9 +646,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
554
646
  this.#indices.addMined(meta);
555
647
  }
556
648
  const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
557
- this.#log.verbose(`Added ${stateStr} tx ${txHashStr}`, {
649
+ this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
558
650
  eventName: 'tx-added-to-pool',
559
- state: stateStr
651
+ txHash: txHashStr,
652
+ state: stateStr,
653
+ source: opts.source
560
654
  });
561
655
  return meta;
562
656
  }
@@ -579,6 +673,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
579
673
  await this.#deleteTx(txHashStr);
580
674
  }
581
675
  }
676
+ /** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
677
+ if (txHashes.length === 0) {
678
+ return;
679
+ }
680
+ this.#instrumentation.recordEvictions(txHashes.length, reason);
681
+ for (const txHashStr of txHashes){
682
+ this.#log.debug(`Evicting tx ${txHashStr}`, {
683
+ txHash: txHashStr,
684
+ reason
685
+ });
686
+ this.#addToEvictedCache(txHashStr);
687
+ }
688
+ await this.#deleteTxsBatch(txHashes);
689
+ }
690
+ /** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
691
+ if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
692
+ // FIFO eviction: remove the first (oldest) entry
693
+ const oldest = this.#evictedTxHashes.values().next().value;
694
+ this.#evictedTxHashes.delete(oldest);
695
+ }
696
+ this.#evictedTxHashes.add(txHashStr);
697
+ }
582
698
  // ============================================================================
583
699
  // PRIVATE HELPERS - Validation & Conflict Resolution
584
700
  // ============================================================================
@@ -717,7 +833,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
717
833
  if (preAddResult.shouldIgnore) {
718
834
  // Transaction rejected - mark for deletion from DB
719
835
  rejected.push(meta.txHash);
720
- this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
836
+ this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
721
837
  continue;
722
838
  }
723
839
  // Evict any conflicting txs identified by pre-add rules
@@ -753,7 +869,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
753
869
  getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
754
870
  getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
755
871
  getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
756
- deleteTxs: (txHashes)=>this.#deleteTxsBatch(txHashes)
872
+ deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
757
873
  };
758
874
  }
759
875
  #createPreAddPoolAccess() {
@@ -9,4 +9,4 @@ export declare class GasTxValidator implements TxValidator<Tx> {
9
9
  validateTx(tx: Tx): Promise<TxValidationResult>;
10
10
  validateTxFee(tx: Tx): Promise<TxValidationResult>;
11
11
  }
12
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2FzX3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci9nYXNfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBZSxLQUFLLGNBQWMsRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUV2RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQU8sT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDakQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM3RCxPQUFPLEVBS0wsS0FBSyxFQUFFLEVBQ1AsS0FBSyxrQkFBa0IsRUFDdkIsS0FBSyxXQUFXLEVBQ2pCLE1BQU0sa0JBQWtCLENBQUM7QUFJMUIscUJBQWEsY0FBZSxZQUFXLFdBQVcsQ0FBQyxFQUFFLENBQUM7O0lBTXBELFlBQ0UsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQ25DLGVBQWUsRUFBRSxZQUFZLEVBQzdCLE9BQU8sRUFBRSxPQUFPLEVBQ2hCLFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFNMUI7SUFFSyxVQUFVLENBQUMsRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FTcEQ7SUFtRFksYUFBYSxDQUFDLEVBQUUsRUFBRSxFQUFFLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBeUI5RDtDQUNGIn0=
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2FzX3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci9nYXNfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sRUFBZSxLQUFLLGNBQWMsRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUV2RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQU8sT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDakQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM3RCxPQUFPLEVBS0wsS0FBSyxFQUFFLEVBQ1AsS0FBSyxrQkFBa0IsRUFDdkIsS0FBSyxXQUFXLEVBQ2pCLE1BQU0sa0JBQWtCLENBQUM7QUFJMUIscUJBQWEsY0FBZSxZQUFXLFdBQVcsQ0FBQyxFQUFFLENBQUM7O0lBTXBELFlBQ0UsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQ25DLGVBQWUsRUFBRSxZQUFZLEVBQzdCLE9BQU8sRUFBRSxPQUFPLEVBQ2hCLFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFNMUI7SUFFSyxVQUFVLENBQUMsRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FTcEQ7SUFzRFksYUFBYSxDQUFDLEVBQUUsRUFBRSxFQUFFLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBeUI5RDtDQUNGIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"gas_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/gas_validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAEvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAO,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAKL,KAAK,EAAE,EACP,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAI1B,qBAAa,cAAe,YAAW,WAAW,CAAC,EAAE,CAAC;;IAMpD,YACE,gBAAgB,EAAE,iBAAiB,EACnC,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,cAAc,EAM1B;IAEK,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CASpD;IAmDY,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAyB9D;CACF"}
1
+ {"version":3,"file":"gas_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/gas_validator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAEvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAO,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAKL,KAAK,EAAE,EACP,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAI1B,qBAAa,cAAe,YAAW,WAAW,CAAC,EAAE,CAAC;;IAMpD,YACE,gBAAgB,EAAE,iBAAiB,EACnC,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,cAAc,EAM1B;IAEK,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CASpD;IAsDY,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAyB9D;CACF"}
@@ -1,4 +1,4 @@
1
- import { AVM_MAX_PROCESSABLE_L2_GAS, FIXED_DA_GAS, FIXED_L2_GAS } from '@aztec/constants';
1
+ import { MAX_PROCESSABLE_L2_GAS, PRIVATE_TX_L2_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
4
  import { Gas } from '@aztec/stdlib/gas';
@@ -52,7 +52,7 @@ export class GasTxValidator {
52
52
  * Check whether the tx's gas limit is above the minimum amount.
53
53
  */ #validateGasLimit(tx) {
54
54
  const gasLimits = tx.data.constants.txContext.gasSettings.gasLimits;
55
- const minGasLimits = new Gas(FIXED_DA_GAS, FIXED_L2_GAS);
55
+ const minGasLimits = new Gas(TX_DA_GAS_OVERHEAD, tx.data.forPublic ? PUBLIC_TX_L2_GAS_OVERHEAD : PRIVATE_TX_L2_GAS_OVERHEAD);
56
56
  if (minGasLimits.gtAny(gasLimits)) {
57
57
  this.#log.verbose(`Rejecting transaction due to the gas limit(s) not being above the minimum gas limit`, {
58
58
  gasLimits,
@@ -65,7 +65,7 @@ export class GasTxValidator {
65
65
  ]
66
66
  };
67
67
  }
68
- if (gasLimits.l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
68
+ if (gasLimits.l2Gas > MAX_PROCESSABLE_L2_GAS) {
69
69
  this.#log.verbose(`Rejecting transaction due to the gas limit(s) being higher than the maximum processable gas`, {
70
70
  gasLimits,
71
71
  minGasLimits
@@ -8,7 +8,7 @@ export interface HasTimestampData {
8
8
  toString(): string;
9
9
  };
10
10
  data: {
11
- includeByTimestamp: bigint;
11
+ expirationTimestamp: bigint;
12
12
  constants: {
13
13
  anchorBlockHeader: {
14
14
  globalVariables: {
@@ -27,4 +27,4 @@ export declare class TimestampTxValidator<T extends HasTimestampData> implements
27
27
  }, bindings?: LoggerBindings);
28
28
  validateTx(tx: T): Promise<TxValidationResult>;
29
29
  }
30
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZXN0YW1wX3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci90aW1lc3RhbXBfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ25FLE9BQU8sRUFBZSxLQUFLLGNBQWMsRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUN2RixPQUFPLEVBQXlDLEtBQUssa0JBQWtCLEVBQUUsS0FBSyxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNwSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUVsRCxxREFBcUQ7QUFDckQsTUFBTSxXQUFXLGdCQUFnQjtJQUMvQixNQUFNLEVBQUU7UUFBRSxRQUFRLElBQUksTUFBTSxDQUFBO0tBQUUsQ0FBQztJQUMvQixJQUFJLEVBQUU7UUFDSixrQkFBa0IsRUFBRSxNQUFNLENBQUM7UUFDM0IsU0FBUyxFQUFFO1lBQ1QsaUJBQWlCLEVBQUU7Z0JBQ2pCLGVBQWUsRUFBRTtvQkFDZixXQUFXLEVBQUUsV0FBVyxDQUFDO2lCQUMxQixDQUFDO2FBQ0gsQ0FBQztTQUNILENBQUM7S0FDSCxDQUFDO0NBQ0g7QUFFRCxxQkFBYSxvQkFBb0IsQ0FBQyxDQUFDLFNBQVMsZ0JBQWdCLENBQUUsWUFBVyxXQUFXLENBQUMsQ0FBQyxDQUFDOztJQUluRixPQUFPLENBQUMsTUFBTTtJQURoQixZQUNVLE1BQU0sRUFBRTtRQUdkLFNBQVMsRUFBRSxNQUFNLENBQUM7UUFFbEIsV0FBVyxFQUFFLFdBQVcsQ0FBQztLQUMxQixFQUNELFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFHMUI7SUFFRCxVQUFVLENBQUMsRUFBRSxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FtQjdDO0NBQ0YifQ==
30
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZXN0YW1wX3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci90aW1lc3RhbXBfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ25FLE9BQU8sRUFBZSxLQUFLLGNBQWMsRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUN2RixPQUFPLEVBQXlDLEtBQUssa0JBQWtCLEVBQUUsS0FBSyxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNwSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUVsRCxxREFBcUQ7QUFDckQsTUFBTSxXQUFXLGdCQUFnQjtJQUMvQixNQUFNLEVBQUU7UUFBRSxRQUFRLElBQUksTUFBTSxDQUFBO0tBQUUsQ0FBQztJQUMvQixJQUFJLEVBQUU7UUFDSixtQkFBbUIsRUFBRSxNQUFNLENBQUM7UUFDNUIsU0FBUyxFQUFFO1lBQ1QsaUJBQWlCLEVBQUU7Z0JBQ2pCLGVBQWUsRUFBRTtvQkFDZixXQUFXLEVBQUUsV0FBVyxDQUFDO2lCQUMxQixDQUFDO2FBQ0gsQ0FBQztTQUNILENBQUM7S0FDSCxDQUFDO0NBQ0g7QUFFRCxxQkFBYSxvQkFBb0IsQ0FBQyxDQUFDLFNBQVMsZ0JBQWdCLENBQUUsWUFBVyxXQUFXLENBQUMsQ0FBQyxDQUFDOztJQUluRixPQUFPLENBQUMsTUFBTTtJQURoQixZQUNVLE1BQU0sRUFBRTtRQUdkLFNBQVMsRUFBRSxNQUFNLENBQUM7UUFFbEIsV0FBVyxFQUFFLFdBQVcsQ0FBQztLQUMxQixFQUNELFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFHMUI7SUFFRCxVQUFVLENBQUMsRUFBRSxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FtQjdDO0NBQ0YifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"timestamp_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/timestamp_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAyC,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAC;IAC/B,IAAI,EAAE;QACJ,kBAAkB,EAAE,MAAM,CAAC;QAC3B,SAAS,EAAE;YACT,iBAAiB,EAAE;gBACjB,eAAe,EAAE;oBACf,WAAW,EAAE,WAAW,CAAC;iBAC1B,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,qBAAa,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;IAInF,OAAO,CAAC,MAAM;IADhB,YACU,MAAM,EAAE;QAGd,SAAS,EAAE,MAAM,CAAC;QAElB,WAAW,EAAE,WAAW,CAAC;KAC1B,EACD,QAAQ,CAAC,EAAE,cAAc,EAG1B;IAED,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAmB7C;CACF"}
1
+ {"version":3,"file":"timestamp_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/timestamp_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAyC,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAC;IAC/B,IAAI,EAAE;QACJ,mBAAmB,EAAE,MAAM,CAAC;QAC5B,SAAS,EAAE;YACT,iBAAiB,EAAE;gBACjB,eAAe,EAAE;oBACf,WAAW,EAAE,WAAW,CAAC;iBAC1B,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,qBAAa,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;IAInF,OAAO,CAAC,MAAM;IADhB,YACU,MAAM,EAAE;QAGd,SAAS,EAAE,MAAM,CAAC;QAElB,WAAW,EAAE,WAAW,CAAC;KAC1B,EACD,QAAQ,CAAC,EAAE,cAAc,EAG1B;IAED,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAmB7C;CACF"}
@@ -1,5 +1,5 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import { TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP } from '@aztec/stdlib/tx';
2
+ import { TX_ERROR_INVALID_EXPIRATION_TIMESTAMP } from '@aztec/stdlib/tx';
3
3
  export class TimestampTxValidator {
4
4
  values;
5
5
  #log;
@@ -8,19 +8,19 @@ export class TimestampTxValidator {
8
8
  this.#log = createLogger('p2p:tx_validator:timestamp', bindings);
9
9
  }
10
10
  validateTx(tx) {
11
- const includeByTimestamp = tx.data.includeByTimestamp;
12
- // If building block 1, we skip the expiration check. For details on why see the `validate_include_by_timestamp`
11
+ const expirationTimestamp = tx.data.expirationTimestamp;
12
+ // If building block 1, we skip the expiration check. For details on why see the `validate_expiration_timestamp`
13
13
  // function in `noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/validation_requests.nr`.
14
14
  const buildingBlock1 = this.values.blockNumber === 1;
15
- if (!buildingBlock1 && includeByTimestamp < this.values.timestamp) {
15
+ if (!buildingBlock1 && expirationTimestamp < this.values.timestamp) {
16
16
  if (tx.data.constants.anchorBlockHeader.globalVariables.blockNumber === 0) {
17
17
  this.#log.warn(`A tx built against a genesis block failed to be included in block 1 which is the only block in which txs built against a genesis block are allowed to be included.`);
18
18
  }
19
- this.#log.verbose(`Rejecting tx ${tx.txHash} for low expiration timestamp. Tx expiration timestamp: ${includeByTimestamp}, timestamp: ${this.values.timestamp}.`);
19
+ this.#log.verbose(`Rejecting tx ${tx.txHash} for low expiration timestamp. Tx expiration timestamp: ${expirationTimestamp}, timestamp: ${this.values.timestamp}.`);
20
20
  return Promise.resolve({
21
21
  result: 'invalid',
22
22
  reason: [
23
- TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP
23
+ TX_ERROR_INVALID_EXPIRATION_TIMESTAMP
24
24
  ]
25
25
  });
26
26
  } else {