@aztec/p2p 0.0.1-commit.858058eac → 0.0.1-commit.85d7d01

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 (243) 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 +23 -30
  4. package/dest/client/interface.d.ts +14 -19
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +9 -18
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +52 -72
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
  10. package/dest/config.d.ts +13 -6
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +5 -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/attestation_pool.d.ts +4 -2
  17. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool.js +5 -0
  19. package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
  20. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  22. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
  23. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +30 -13
  24. package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool_v2/deleted_pool.js +91 -20
  26. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
  27. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
  29. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  30. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
  32. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
  33. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
  34. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
  35. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
  36. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
  38. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
  39. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
  41. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
  42. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
  43. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
  44. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  45. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
  46. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
  47. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
  48. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
  49. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
  50. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
  51. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
  52. package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
  53. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
  54. package/dest/mem_pools/tx_pool_v2/index.js +1 -1
  55. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
  56. package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
  57. package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
  58. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +20 -6
  59. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  60. package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
  61. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +34 -8
  62. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  63. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +76 -10
  64. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
  65. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
  66. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
  67. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
  68. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  69. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +11 -6
  70. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +13 -5
  71. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +297 -143
  73. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
  74. package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
  76. package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
  77. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  78. package/dest/msg_validators/tx_validator/factory.js +219 -58
  79. package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
  80. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  81. package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
  82. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  83. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  84. package/dest/msg_validators/tx_validator/index.js +1 -0
  85. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
  86. package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
  87. package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
  88. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
  89. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  90. package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
  91. package/dest/services/dummy_service.d.ts +4 -4
  92. package/dest/services/dummy_service.d.ts.map +1 -1
  93. package/dest/services/dummy_service.js +4 -4
  94. package/dest/services/encoding.d.ts +2 -2
  95. package/dest/services/encoding.d.ts.map +1 -1
  96. package/dest/services/encoding.js +9 -8
  97. package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
  98. package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
  99. package/dest/services/gossipsub/topic_score_params.js +32 -10
  100. package/dest/services/libp2p/libp2p_service.d.ts +16 -13
  101. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  102. package/dest/services/libp2p/libp2p_service.js +69 -81
  103. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
  104. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  105. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
  106. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
  107. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  108. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
  109. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  110. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
  111. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
  112. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  113. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
  114. package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
  115. package/dest/services/reqresp/reqresp.d.ts +1 -1
  116. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  117. package/dest/services/reqresp/reqresp.js +2 -1
  118. package/dest/services/service.d.ts +5 -3
  119. package/dest/services/service.d.ts.map +1 -1
  120. package/dest/services/tx_collection/config.d.ts +13 -1
  121. package/dest/services/tx_collection/config.d.ts.map +1 -1
  122. package/dest/services/tx_collection/config.js +30 -0
  123. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
  124. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  125. package/dest/services/tx_collection/fast_tx_collection.js +39 -33
  126. package/dest/services/tx_collection/file_store_tx_collection.d.ts +38 -29
  127. package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
  128. package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
  129. package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
  130. package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
  131. package/dest/services/tx_collection/file_store_tx_source.js +49 -16
  132. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  133. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  134. package/dest/services/tx_collection/instrumentation.js +2 -1
  135. package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
  136. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
  137. package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
  138. package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
  139. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  140. package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
  141. package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
  142. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  143. package/dest/services/tx_collection/slow_tx_collection.js +17 -12
  144. package/dest/services/tx_collection/tx_collection.d.ts +9 -6
  145. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  146. package/dest/services/tx_collection/tx_collection.js +26 -10
  147. package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
  148. package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
  149. package/dest/services/tx_collection/tx_collection_sink.js +13 -22
  150. package/dest/services/tx_collection/tx_source.d.ts +8 -3
  151. package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
  152. package/dest/services/tx_collection/tx_source.js +19 -2
  153. package/dest/services/tx_file_store/tx_file_store.d.ts +3 -2
  154. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
  155. package/dest/services/tx_file_store/tx_file_store.js +9 -6
  156. package/dest/services/tx_provider.d.ts +3 -3
  157. package/dest/services/tx_provider.d.ts.map +1 -1
  158. package/dest/services/tx_provider.js +4 -4
  159. package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
  160. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  161. package/dest/test-helpers/make-test-p2p-clients.js +1 -2
  162. package/dest/test-helpers/mock-pubsub.d.ts +4 -4
  163. package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
  164. package/dest/test-helpers/mock-pubsub.js +8 -2
  165. package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
  166. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  167. package/dest/test-helpers/reqresp-nodes.js +2 -2
  168. package/dest/test-helpers/testbench-utils.d.ts +8 -3
  169. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  170. package/dest/test-helpers/testbench-utils.js +7 -1
  171. package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
  172. package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
  173. package/dest/testbench/p2p_client_testbench_worker.js +13 -13
  174. package/dest/util.d.ts +2 -2
  175. package/dest/util.d.ts.map +1 -1
  176. package/package.json +14 -14
  177. package/src/client/factory.ts +39 -48
  178. package/src/client/interface.ts +17 -20
  179. package/src/client/p2p_client.ts +60 -104
  180. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
  181. package/src/config.ts +10 -10
  182. package/src/errors/tx-pool.error.ts +12 -0
  183. package/src/mem_pools/attestation_pool/attestation_pool.ts +8 -0
  184. package/src/mem_pools/attestation_pool/mocks.ts +2 -1
  185. package/src/mem_pools/tx_pool/README.md +1 -1
  186. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
  187. package/src/mem_pools/tx_pool_v2/README.md +43 -27
  188. package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
  189. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
  190. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
  191. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
  192. package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
  193. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
  194. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
  195. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
  196. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
  197. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
  198. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
  199. package/src/mem_pools/tx_pool_v2/index.ts +1 -1
  200. package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
  201. package/src/mem_pools/tx_pool_v2/interfaces.ts +21 -6
  202. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +107 -17
  203. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
  204. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
  205. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +326 -138
  206. package/src/msg_validators/tx_validator/README.md +115 -0
  207. package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
  208. package/src/msg_validators/tx_validator/factory.ts +353 -77
  209. package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
  210. package/src/msg_validators/tx_validator/index.ts +1 -0
  211. package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
  212. package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
  213. package/src/services/dummy_service.ts +6 -6
  214. package/src/services/encoding.ts +7 -7
  215. package/src/services/gossipsub/README.md +29 -14
  216. package/src/services/gossipsub/topic_score_params.ts +49 -13
  217. package/src/services/libp2p/libp2p_service.ts +80 -90
  218. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
  219. package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
  220. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
  221. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
  222. package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
  223. package/src/services/reqresp/reqresp.ts +3 -1
  224. package/src/services/service.ts +11 -2
  225. package/src/services/tx_collection/config.ts +42 -0
  226. package/src/services/tx_collection/fast_tx_collection.ts +51 -30
  227. package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
  228. package/src/services/tx_collection/file_store_tx_source.ts +64 -17
  229. package/src/services/tx_collection/instrumentation.ts +7 -1
  230. package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
  231. package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
  232. package/src/services/tx_collection/slow_tx_collection.ts +17 -13
  233. package/src/services/tx_collection/tx_collection.ts +45 -14
  234. package/src/services/tx_collection/tx_collection_sink.ts +15 -29
  235. package/src/services/tx_collection/tx_source.ts +22 -3
  236. package/src/services/tx_file_store/tx_file_store.ts +6 -4
  237. package/src/services/tx_provider.ts +2 -2
  238. package/src/test-helpers/make-test-p2p-clients.ts +0 -2
  239. package/src/test-helpers/mock-pubsub.ts +13 -6
  240. package/src/test-helpers/reqresp-nodes.ts +2 -5
  241. package/src/test-helpers/testbench-utils.ts +11 -3
  242. package/src/testbench/p2p_client_testbench_worker.ts +22 -19
  243. package/src/util.ts +7 -1
package/src/config.ts CHANGED
@@ -38,7 +38,7 @@ export interface P2PConfig
38
38
  ChainConfig,
39
39
  TxCollectionConfig,
40
40
  TxFileStoreConfig,
41
- Pick<SequencerConfig, 'blockDurationMs'> {
41
+ Pick<SequencerConfig, 'blockDurationMs' | 'expectedBlockProposalsPerSlot'> {
42
42
  /** A flag dictating whether the P2P subsystem should be enabled. */
43
43
  p2pEnabled: boolean;
44
44
 
@@ -173,10 +173,7 @@ export interface P2PConfig
173
173
  /** Whether transactions are disabled for this node. This means transactions will be rejected at the RPC and P2P layers. */
174
174
  disableTransactions: boolean;
175
175
 
176
- /** True to simulate discarding transactions. - For testing purposes only*/
177
- dropTransactions: boolean;
178
-
179
- /** The probability that a transaction is discarded. - For testing purposes only */
176
+ /** The probability that a transaction is discarded (0 = disabled). - For testing purposes only */
180
177
  dropTransactionsProbability: number;
181
178
 
182
179
  /** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
@@ -190,6 +187,9 @@ export interface P2PConfig
190
187
 
191
188
  /** Broadcast block proposals even when a conflicting proposal for the same slot already exists in the pool (for testing purposes only). */
192
189
  broadcastEquivocatedProposals?: boolean;
190
+
191
+ /** Minimum age (ms) a transaction must have been in the pool before it's eligible for block building. */
192
+ minTxPoolAgeMs: number;
193
193
  }
194
194
 
195
195
  export const DEFAULT_P2P_PORT = 40400;
@@ -427,11 +427,6 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
427
427
  description: 'Number of auth attempts to allow before peer is banned. Number is inclusive',
428
428
  ...numberConfigHelper(3),
429
429
  },
430
- dropTransactions: {
431
- env: 'P2P_DROP_TX',
432
- description: 'True to simulate discarding transactions. - For testing purposes only',
433
- ...booleanConfigHelper(false),
434
- },
435
430
  dropTransactionsProbability: {
436
431
  env: 'P2P_DROP_TX_CHANCE',
437
432
  description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
@@ -464,6 +459,11 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
464
459
  'Broadcast block proposals even when a conflicting proposal for the same slot already exists in the pool (for testing purposes only).',
465
460
  ...booleanConfigHelper(false),
466
461
  },
462
+ minTxPoolAgeMs: {
463
+ env: 'P2P_MIN_TX_POOL_AGE_MS',
464
+ description: 'Minimum age (ms) a transaction must have been in the pool before it is eligible for block building.',
465
+ ...numberConfigHelper(2_000),
466
+ },
467
467
  ...sharedSequencerConfigMappings,
468
468
  ...p2pReqRespConfigMappings,
469
469
  ...batchTxRequesterConfigMappings,
@@ -0,0 +1,12 @@
1
+ import type { TxPoolRejectionError } from '../mem_pools/tx_pool_v2/eviction/interfaces.js';
2
+
3
+ /** Error thrown when a transaction is not added to the mempool. */
4
+ export class TxPoolError extends Error {
5
+ public readonly data: TxPoolRejectionError;
6
+
7
+ constructor(public readonly reason: TxPoolRejectionError) {
8
+ super(reason.message);
9
+ this.name = 'TxPoolError';
10
+ this.data = reason;
11
+ }
12
+ }
@@ -43,6 +43,7 @@ export type AttestationPoolApi = Pick<
43
43
  | 'deleteOlderThan'
44
44
  | 'getCheckpointAttestationsForSlot'
45
45
  | 'getCheckpointAttestationsForSlotAndProposal'
46
+ | 'hasBlockProposalsForSlot'
46
47
  | 'isEmpty'
47
48
  >;
48
49
 
@@ -254,6 +255,13 @@ export class AttestationPool {
254
255
  return undefined;
255
256
  }
256
257
 
258
+ /** Checks if any block proposals exist for a given slot (at index 0). */
259
+ public async hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean> {
260
+ const positionKey = this.getBlockPositionKey(slot, 0);
261
+ const count = await this.blockProposalsForSlotAndIndex.getValueCountAsync(positionKey);
262
+ return count > 0;
263
+ }
264
+
257
265
  /**
258
266
  * Attempts to add a checkpoint proposal to the pool.
259
267
  *
@@ -34,9 +34,10 @@ export const mockCheckpointAttestation = (
34
34
  slot: number = 0,
35
35
  archive: Fr = Fr.random(),
36
36
  header?: CheckpointHeader,
37
+ feeAssetPriceModifier: bigint = 0n,
37
38
  ): CheckpointAttestation => {
38
39
  header = header ?? CheckpointHeader.random({ slotNumber: SlotNumber(slot) });
39
- const payload = new ConsensusPayload(header, archive);
40
+ const payload = new ConsensusPayload(header, archive, feeAssetPriceModifier);
40
41
 
41
42
  const attestationHash = getHashedSignaturePayloadEthSignedMessage(
42
43
  payload,
@@ -213,7 +213,7 @@ The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
213
213
  Evicts transactions that become invalid after a block is mined:
214
214
 
215
215
  - Duplicate nullifiers: Txs with nullifiers already included in the mined block
216
- - Expired transactions: Txs with `includeByTimestamp` ≤ mined block timestamp
216
+ - Expired transactions: Txs with `expirationTimestamp` ≤ mined block timestamp
217
217
 
218
218
  #### 2. `InvalidTxsAfterReorgRule`
219
219
 
@@ -68,10 +68,10 @@ export class InvalidTxsAfterMiningRule implements EvictionRule {
68
68
  }
69
69
 
70
70
  // Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
71
- const includeByTimestamp = tx.data.includeByTimestamp;
72
- if (includeByTimestamp <= timestamp) {
71
+ const expirationTimestamp = tx.data.expirationTimestamp;
72
+ if (expirationTimestamp <= timestamp) {
73
73
  this.log.verbose(
74
- `Evicting tx ${txHash} from pool due to the tx being expired (includeByTimestamp: ${includeByTimestamp}, mined block timestamp: ${timestamp})`,
74
+ `Evicting tx ${txHash} from pool due to the tx being expired (expirationTimestamp: ${expirationTimestamp}, mined block timestamp: ${timestamp})`,
75
75
  );
76
76
  txsToEvict.push(txHash);
77
77
  continue;
@@ -30,19 +30,20 @@ TxPoolV2 manages transactions through a state machine with clear transitions:
30
30
  └─────────────────────────────────────┘ (reorg)
31
31
  │ │
32
32
  │ handleFinalizedBlock() │ eviction after reorg
33
+ │ / eviction / failed exec │ (validation failure)
33
34
  ▼ ▼
34
35
  ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
35
- DELETED │ │ SOFT-DELETED
36
- (hard-deleted or archived) │ │ (kept in DB for debugging)
36
+ SLOT-SOFT-DELETED │ │ PRUNE-SOFT-DELETED
37
+ (kept in DB until next slot) │ │ (kept in DB until finalized)
38
+ └─────────────────────────────────────┘ └─────────────────────────────────────┘
39
+ │ │
40
+ │ prepareForSlot() │ handleFinalizedBlock()
41
+ │ (slot advanced) │ (mined block finalized)
42
+ ▼ ▼
43
+ ┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
44
+ │ HARD-DELETED │ │ HARD-DELETED │
45
+ │ (permanently removed from DB) │ │ (permanently removed from DB) │
37
46
  └─────────────────────────────────────┘ └─────────────────────────────────────┘
38
-
39
- │ handleFinalizedBlock()
40
- │ (mined block finalized)
41
-
42
- ┌─────────────────────────────────────┐
43
- │ HARD-DELETED │
44
- │ (permanently removed from DB) │
45
- └─────────────────────────────────────┘
46
47
  ```
47
48
 
48
49
  ## Key Components
@@ -62,13 +63,11 @@ Core implementation containing:
62
63
 
63
64
  ### DeletedPool (`deleted_pool.ts`)
64
65
 
65
- Manages soft deletion of transactions from pruned blocks:
66
- - When a reorg (chain prune) occurs, transactions from pruned blocks are tracked with their original mined block number
67
- - When these transactions are later evicted (e.g., failed validation, nullifier conflict), they are "soft-deleted" instead of removed
68
- - Soft-deleted transactions remain in the database for debugging and potential resubmission
69
- - When the original mined block is finalized on the new chain, soft-deleted transactions are permanently hard-deleted
66
+ Manages all transaction deletions in the pool with two soft-deletion mechanisms:
67
+ - **Slot-based**: Non-pruned txs are kept in DB until the next slot, allowing other nodes to fetch them via reqresp
68
+ - **Prune-based**: Txs from pruned blocks are kept in DB until their original mined block is finalized
70
69
 
71
- This ensures transactions from reorged blocks are kept around until we're certain they won't be needed.
70
+ All deletions go through `DeletedPool.deleteTx()`, which routes to the appropriate path based on whether the tx is tracked as being from a pruned block.
72
71
 
73
72
  ### TxMetaData (`tx_metadata.ts`)
74
73
 
@@ -80,33 +79,46 @@ Lightweight metadata stored alongside each transaction:
80
79
  - `claimAmount`: Fee payer's claim from bridging
81
80
  - `feeLimit`: Maximum fee the tx can pay
82
81
  - `nullifiers`: For conflict detection
83
- - `includeByTimestamp`: Expiration timestamp
82
+ - `expirationTimestamp`: Expiration timestamp
84
83
  - `minedL2BlockId`: Set when mined (undefined otherwise)
85
84
 
86
85
  State is derived by TxPoolIndices:
87
86
  - `mined` if `minedL2BlockId` is set
88
87
  - `protected` if in protection map
89
- - `deleted` if soft-deleted (from a pruned block, evicted but kept in DB)
88
+ - `deleted` if soft-deleted (slot-based or prune-based, evicted but kept in DB)
90
89
  - `pending` otherwise
91
90
 
92
91
  ## Soft Deletion
93
92
 
94
- When a chain reorganization occurs, transactions that were mined in pruned blocks are handled specially:
93
+ Deleted transactions are kept in the database for a grace period before being permanently removed. There are two soft-deletion mechanisms:
94
+
95
+ ### Slot-Based Soft Deletion
96
+
97
+ When a transaction is deleted from the pool (eviction, validation failure, failed execution) and is **not** from a pruned block, it is "slot-soft-deleted":
98
+
99
+ 1. **Soft Delete**: The tx is removed from indices but kept in the database, tagged with the current slot number
100
+ 2. **Retrieval**: Slot-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
101
+ 3. **Hard Delete**: When `prepareForSlot` advances to a new slot, txs deleted in earlier slots are permanently removed
102
+ 4. **Re-addition**: If a slot-soft-deleted tx is re-added to the pool, the slot-deleted tracking is cleared
103
+
104
+ This allows other nodes to still fetch recently-deleted transactions via reqresp during the current slot.
105
+
106
+ ### Prune-Based Soft Deletion
107
+
108
+ When a chain reorganization occurs, transactions that were mined in pruned blocks are handled with longer retention:
95
109
 
96
110
  1. **Tracking**: When `handlePrunedBlocks` is called, all un-mined transactions are tracked by their original mined block number
97
- 2. **Soft Delete**: If these transactions are later evicted (failed validation, nullifier conflict, etc.), they are "soft-deleted" - removed from indices but kept in the database
98
- 3. **Retrieval**: Soft-deleted transactions can still be retrieved via `getTxByHash` and `hasTxs`, and return status `'deleted'` from `getTxStatus`
111
+ 2. **Soft Delete**: If these transactions are later evicted (failed validation, nullifier conflict, etc.), they are "prune-soft-deleted" - removed from indices but kept in the database
112
+ 3. **Retrieval**: Prune-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
99
113
  4. **Hard Delete**: When `handleFinalizedBlock` is called and the finalized block number reaches or exceeds the transaction's original mined block, the transaction is permanently removed
114
+ 5. **Re-addition**: If a prune-soft-deleted tx is re-added, the `softDeleted` flag is reset to `false` but the prune tracking is preserved, so a subsequent deletion still uses the prune path
100
115
 
101
- This design allows:
102
- - Debugging reorg scenarios by keeping transaction data available
103
- - Potential resubmission of transactions that failed validation after a reorg
104
- - Clean eventual cleanup once we're certain the transaction won't be needed
116
+ Prune-soft-deleted transactions are **not** affected by slot cleanup - they survive across slot boundaries until finalized.
105
117
 
106
- **Example scenario:**
118
+ **Prune example:**
107
119
  1. Tx mined at block 10
108
120
  2. Chain prunes to block 5 (tx becomes un-mined, tracked as minedAtBlock=10)
109
- 3. Tx fails validation and is soft-deleted
121
+ 3. Tx fails validation and is prune-soft-deleted
110
122
  4. Block 9 finalized → tx still in DB (minedAtBlock=10 > finalized=9)
111
123
  5. Block 10 finalized → tx hard-deleted (minedAtBlock=10 ≤ finalized=10)
112
124
 
@@ -117,6 +129,10 @@ If the tx is re-mined at a higher block before being soft-deleted:
117
129
  4. Block 10 finalized → tx still in DB
118
130
  5. Block 15 finalized → tx hard-deleted
119
131
 
132
+ ### Hydration
133
+
134
+ On node restart, slot-soft-deleted transactions are immediately hard-deleted (they are stale by definition). Prune-soft-deleted transactions are loaded from the database and tracked normally.
135
+
120
136
  ## Architecture: Pre-add vs Post-event Rules
121
137
 
122
138
  **Pre-add rules** (run during `addPendingTxs`):
@@ -1,6 +1,6 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { Logger } from '@aztec/foundation/log';
3
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
3
+ import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSet } from '@aztec/kv-store';
4
4
 
5
5
  /**
6
6
  * State stored for each transaction from a pruned block.
@@ -39,15 +39,17 @@ function deserializeState(buffer: Buffer): DeletedTxState {
39
39
  * When a chain prune (reorg) happens, transactions from pruned blocks are tracked here.
40
40
  * This class is responsible for ALL deletion decisions:
41
41
  *
42
- * - Transactions from pruned blocks are "soft deleted" - removed from indices but kept
43
- * in the database for later re-execution
44
- * - Transactions NOT from pruned blocks are "hard deleted" - completely removed from DB
42
+ * - Transactions from pruned blocks are "prune-soft-deleted" - removed from indices but kept
43
+ * in the database for later re-execution until their mined block is finalized
44
+ * - Transactions NOT from pruned blocks are "slot-soft-deleted" - kept in the database
45
+ * until the next slot, so other nodes can still fetch them via reqresp
45
46
  *
46
- * When a block is finalized, soft-deleted transactions that were originally mined at or
47
- * before that block number are permanently (hard) deleted.
47
+ * When a block is finalized, prune-soft-deleted transactions that were originally mined at or
48
+ * before that block number are permanently (hard) deleted. Slot-soft-deleted transactions
49
+ * are hard-deleted when `prepareForSlot` advances to a new slot.
48
50
  */
49
51
  export class DeletedPool {
50
- /** Persisted map: txHash -> DeletedTxState (serialized) */
52
+ /** Persisted map: txHash -> DeletedTxState (serialized) - for prune-based soft deletions */
51
53
  #deletedTxsDB: AztecAsyncMap<string, Buffer>;
52
54
 
53
55
  /** Reference to the main txs database for hard deletion */
@@ -56,16 +58,27 @@ export class DeletedPool {
56
58
  /** In-memory state for transactions from pruned blocks */
57
59
  #state: Map<string, DeletedTxState> = new Map();
58
60
 
61
+ /** In-memory tracking: txHash -> slot at which the tx was deleted */
62
+ #slotDeletedTxs: Map<string, SlotNumber> = new Map();
63
+
64
+ /** Persisted set tracking which txs are slot-deleted, for hydration cleanup. */
65
+ #slotDeletedDB: AztecAsyncSet<string>;
66
+
67
+ /** Current slot number, updated by cleanupSlotDeleted */
68
+ #currentSlot: SlotNumber = SlotNumber(0);
69
+
59
70
  #log: Logger;
60
71
 
61
72
  constructor(store: AztecAsyncKVStore, txsDB: AztecAsyncMap<string, Buffer>, log: Logger) {
62
73
  this.#deletedTxsDB = store.openMap('deleted_txs');
74
+ this.#slotDeletedDB = store.openSet('slot_deleted_txs');
63
75
  this.#txsDB = txsDB;
64
76
  this.#log = log;
65
77
  }
66
78
 
67
79
  /**
68
80
  * Loads state from the database on startup.
81
+ * Slot-deleted txs are stale after restart and are immediately hard-deleted.
69
82
  */
70
83
  async hydrateFromDatabase(): Promise<void> {
71
84
  let prunedCount = 0;
@@ -83,6 +96,18 @@ export class DeletedPool {
83
96
  if (prunedCount > 0 || softDeletedCount > 0) {
84
97
  this.#log.info(`Loaded ${prunedCount} txs from pruned blocks, ${softDeletedCount} soft-deleted`);
85
98
  }
99
+
100
+ // Slot-deleted txs are stale after restart - hard-delete them all
101
+ let slotDeletedCount = 0;
102
+ for await (const txHash of this.#slotDeletedDB.entriesAsync()) {
103
+ await this.#txsDB.delete(txHash);
104
+ await this.#slotDeletedDB.delete(txHash);
105
+ slotDeletedCount++;
106
+ }
107
+
108
+ if (slotDeletedCount > 0) {
109
+ this.#log.info(`Hard-deleted ${slotDeletedCount} stale slot-deleted txs on startup`);
110
+ }
86
111
  }
87
112
 
88
113
  /**
@@ -117,33 +142,31 @@ export class DeletedPool {
117
142
  }
118
143
 
119
144
  if (count > 0) {
120
- this.#log.debug(`Marked ${count} transactions from pruned blocks`);
145
+ this.#log.info(`Marked ${count} transactions from pruned blocks`);
121
146
  }
122
147
  }
123
148
 
124
149
  /**
125
150
  * Deletes a transaction. This is the single entry point for ALL deletions.
151
+ * The tx is always soft-deleted (kept in DB):
126
152
  *
127
- * - If the tx is from a pruned block: soft-delete (keep in DB, mark as deleted)
128
- * - If the tx is NOT from a pruned block: hard-delete (remove from DB)
129
- *
130
- * @returns 'soft' if soft-deleted, 'hard' if hard-deleted
153
+ * - If the tx is from a pruned block: prune-soft-delete (kept until finalized)
154
+ * - If the tx is NOT from a pruned block: slot-soft-delete (kept until next slot)
131
155
  */
132
- async deleteTx(txHash: string): Promise<'soft' | 'hard'> {
156
+ async deleteTx(txHash: string): Promise<void> {
133
157
  const existing = this.#state.get(txHash);
134
158
  if (existing !== undefined) {
135
- // Soft delete - keep in DB
159
+ // Prune-soft-delete - keep in DB until finalized
136
160
  const state: DeletedTxState = {
137
161
  minedAtBlock: existing.minedAtBlock,
138
162
  softDeleted: true,
139
163
  };
140
164
  this.#state.set(txHash, state);
141
165
  await this.#deletedTxsDB.set(txHash, serializeState(state));
142
- return 'soft';
143
166
  } else {
144
- // Hard delete - remove from DB
145
- await this.#txsDB.delete(txHash);
146
- return 'hard';
167
+ // Slot-soft-delete - keep in DB until next slot
168
+ this.#slotDeletedTxs.set(txHash, this.#currentSlot);
169
+ await this.#slotDeletedDB.add(txHash);
147
170
  }
148
171
  }
149
172
 
@@ -176,10 +199,10 @@ export class DeletedPool {
176
199
  }
177
200
 
178
201
  /**
179
- * Checks if a transaction is soft-deleted.
202
+ * Checks if a transaction is soft-deleted (either prune-based or slot-based).
180
203
  */
181
204
  isSoftDeleted(txHash: string): boolean {
182
- return this.#state.get(txHash)?.softDeleted ?? false;
205
+ return (this.#state.get(txHash)?.softDeleted ?? false) || this.#slotDeletedTxs.has(txHash);
183
206
  }
184
207
 
185
208
  /**
@@ -214,10 +237,63 @@ export class DeletedPool {
214
237
  await this.#txsDB.delete(txHash);
215
238
  }
216
239
 
217
- this.#log.debug(`Finalized ${toHardDelete.length} txs from pruned blocks at block ${finalizedBlockNumber}`);
240
+ this.#log.debug(`Finalized ${toHardDelete.length} txs from pruned blocks at block ${finalizedBlockNumber}`, {
241
+ txHashes: toHardDelete,
242
+ });
218
243
  return toHardDelete;
219
244
  }
220
245
 
246
+ /**
247
+ * Cleans up slot-deleted transactions from previous slots.
248
+ * Called at the start of prepareForSlot. Updates #currentSlot and hard-deletes
249
+ * any txs that were deleted in an earlier slot.
250
+ */
251
+ async cleanupSlotDeleted(currentSlot: SlotNumber): Promise<void> {
252
+ const previousSlot = this.#currentSlot;
253
+ this.#currentSlot = currentSlot;
254
+
255
+ const toHardDelete: string[] = [];
256
+ for (const [txHash, deletedAtSlot] of this.#slotDeletedTxs) {
257
+ if (deletedAtSlot < currentSlot) {
258
+ toHardDelete.push(txHash);
259
+ }
260
+ }
261
+
262
+ if (toHardDelete.length === 0) {
263
+ return;
264
+ }
265
+
266
+ for (const txHash of toHardDelete) {
267
+ this.#slotDeletedTxs.delete(txHash);
268
+ await this.#slotDeletedDB.delete(txHash);
269
+ await this.#txsDB.delete(txHash);
270
+ }
271
+
272
+ this.#log.debug(
273
+ `Cleaned up ${toHardDelete.length} slot-deleted txs from slot ${previousSlot} (now slot ${currentSlot})`,
274
+ { txHashes: toHardDelete },
275
+ );
276
+ }
277
+
278
+ /**
279
+ * Clears soft-deletion status for a transaction being re-added to the pool.
280
+ * Removes slot-deleted tracking entirely, and resets the prune-soft-deleted flag
281
+ * while preserving the prune tracking itself (so a subsequent delete still uses
282
+ * the prune path).
283
+ */
284
+ async clearSoftDeleted(txHash: string): Promise<void> {
285
+ if (this.#slotDeletedTxs.has(txHash)) {
286
+ this.#slotDeletedTxs.delete(txHash);
287
+ await this.#slotDeletedDB.delete(txHash);
288
+ }
289
+ const existing = this.#state.get(txHash);
290
+ if (existing?.softDeleted) {
291
+ const state: DeletedTxState = { minedAtBlock: existing.minedAtBlock, softDeleted: false };
292
+ this.#state.set(txHash, state);
293
+ await this.#deletedTxsDB.set(txHash, serializeState(state));
294
+ }
295
+ }
296
+
221
297
  /**
222
298
  * Gets the count of transactions from pruned blocks.
223
299
  */
@@ -225,6 +301,17 @@ export class DeletedPool {
225
301
  return this.#state.size;
226
302
  }
227
303
 
304
+ /** Gets the count of soft-deleted transactions (both prune-based and slot-based). */
305
+ getSoftDeletedCount(): number {
306
+ let count = this.#slotDeletedTxs.size;
307
+ for (const state of this.#state.values()) {
308
+ if (state.softDeleted) {
309
+ count++;
310
+ }
311
+ }
312
+ return count;
313
+ }
314
+
228
315
  /**
229
316
  * Gets all transaction hashes from pruned blocks.
230
317
  */
@@ -9,9 +9,12 @@ import {
9
9
  EvictionEvent,
10
10
  type EvictionRule,
11
11
  type PoolOperations,
12
+ type PreAddContext,
12
13
  type PreAddPoolAccess,
13
14
  type PreAddResult,
14
15
  type PreAddRule,
16
+ type TaggedEviction,
17
+ TxPoolRejectionCode,
15
18
  } from './interfaces.js';
16
19
 
17
20
  /**
@@ -47,21 +50,27 @@ export class EvictionManager {
47
50
  * Runs all pre-add rules for an incoming transaction.
48
51
  * Returns combined result of all rules.
49
52
  */
50
- async runPreAddRules(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
51
- const allTxHashesToEvict: string[] = [];
53
+ async runPreAddRules(
54
+ incomingMeta: TxMetaData,
55
+ poolAccess: PreAddPoolAccess,
56
+ context?: PreAddContext,
57
+ ): Promise<PreAddResult> {
58
+ const evictions: TaggedEviction[] = [];
59
+ const seen = new Set<string>();
52
60
 
53
61
  for (const rule of this.preAddRules) {
54
62
  try {
55
- const result = await rule.check(incomingMeta, poolAccess);
63
+ const result = await rule.check(incomingMeta, poolAccess, context);
56
64
 
57
65
  if (result.shouldIgnore) {
58
66
  return result;
59
67
  }
60
68
 
61
- // Collect txs to evict from all rules
69
+ // Collect txs to evict from all rules, tagged with the rule name
62
70
  for (const txHash of result.txHashesToEvict) {
63
- if (!allTxHashesToEvict.includes(txHash)) {
64
- allTxHashesToEvict.push(txHash);
71
+ if (!seen.has(txHash)) {
72
+ seen.add(txHash);
73
+ evictions.push({ txHash, reason: rule.name });
65
74
  }
66
75
  }
67
76
  } catch (err) {
@@ -70,14 +79,18 @@ export class EvictionManager {
70
79
  return {
71
80
  shouldIgnore: true,
72
81
  txHashesToEvict: [],
73
- reason: `pre-add rule ${rule.name} error: ${err}`,
82
+ reason: {
83
+ code: TxPoolRejectionCode.INTERNAL_ERROR,
84
+ message: `Pre-add rule ${rule.name} error: ${err}`,
85
+ },
74
86
  };
75
87
  }
76
88
  }
77
89
 
78
90
  return {
79
91
  shouldIgnore: false,
80
- txHashesToEvict: allTxHashesToEvict,
92
+ txHashesToEvict: evictions.map(e => e.txHash),
93
+ evictions,
81
94
  };
82
95
  }
83
96
 
@@ -34,7 +34,7 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
34
34
  }
35
35
 
36
36
  if (context.event === EvictionEvent.CHAIN_PRUNED) {
37
- await this.worldState.syncImmediate(context.blockNumber);
37
+ await this.worldState.syncImmediate();
38
38
  const feePayers = pool.getPendingFeePayers();
39
39
  return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), pool);
40
40
  }
@@ -67,7 +67,10 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
67
67
  ).flat();
68
68
 
69
69
  if (txsToEvict.length > 0) {
70
- await pool.deleteTxs(txsToEvict);
70
+ await pool.deleteTxs(txsToEvict, this.name);
71
+ this.log.debug(`Evicted ${txsToEvict.length} txs due to insufficient fee payer balance`, {
72
+ txHashes: txsToEvict,
73
+ });
71
74
  }
72
75
 
73
76
  return {
@@ -1,7 +1,13 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import { type TxMetaData, comparePriority } from '../tx_metadata.js';
4
- import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
4
+ import {
5
+ type PreAddContext,
6
+ type PreAddPoolAccess,
7
+ type PreAddResult,
8
+ type PreAddRule,
9
+ TxPoolRejectionCode,
10
+ } from './interfaces.js';
5
11
 
6
12
  /**
7
13
  * Pre-add rule that checks if a fee payer has sufficient balance to cover the incoming transaction.
@@ -19,7 +25,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
19
25
 
20
26
  private log = createLogger('p2p:tx_pool_v2:fee_payer_balance_pre_add_rule');
21
27
 
22
- async check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
28
+ async check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, _context?: PreAddContext): Promise<PreAddResult> {
23
29
  // Get fee payer's on-chain balance
24
30
  const initialBalance = await poolAccess.getFeePayerBalance(incomingMeta.feePayer);
25
31
 
@@ -29,6 +35,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
29
35
  // Create combined list with incoming tx
30
36
  const allTxs: Array<{
31
37
  txHash: string;
38
+ txHashBigInt: bigint;
32
39
  priorityFee: bigint;
33
40
  feeLimit: bigint;
34
41
  claimAmount: bigint;
@@ -36,6 +43,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
36
43
  }> = [
37
44
  ...existingTxs.map(t => ({
38
45
  txHash: t.txHash,
46
+ txHashBigInt: t.txHashBigInt,
39
47
  priorityFee: t.priorityFee,
40
48
  feeLimit: t.feeLimit,
41
49
  claimAmount: t.claimAmount,
@@ -43,6 +51,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
43
51
  })),
44
52
  {
45
53
  txHash: incomingMeta.txHash,
54
+ txHashBigInt: incomingMeta.txHashBigInt,
46
55
  priorityFee: incomingMeta.priorityFee,
47
56
  feeLimit: incomingMeta.feeLimit,
48
57
  claimAmount: incomingMeta.claimAmount,
@@ -78,7 +87,13 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
78
87
  return {
79
88
  shouldIgnore: true,
80
89
  txHashesToEvict: [],
81
- reason: `fee payer ${incomingMeta.feePayer} has insufficient balance`,
90
+ reason: {
91
+ code: TxPoolRejectionCode.INSUFFICIENT_FEE_PAYER_BALANCE,
92
+ message: `Fee payer ${incomingMeta.feePayer} has insufficient balance. Balance at transaction: ${available}, required: ${incomingMeta.feeLimit}`,
93
+ currentBalance: initialBalance,
94
+ availableBalance: available,
95
+ feeLimit: incomingMeta.feeLimit,
96
+ },
82
97
  };
83
98
  } else {
84
99
  // Existing tx cannot be covered after adding incoming - mark for eviction
@@ -93,7 +108,6 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
93
108
  return {
94
109
  shouldIgnore: true,
95
110
  txHashesToEvict: [],
96
- reason: 'internal error: tx coverage not determined',
97
111
  };
98
112
  }
99
113
 
@@ -6,9 +6,13 @@ export {
6
6
  type EvictionResult,
7
7
  type EvictionRule,
8
8
  type PoolOperations,
9
+ type PreAddContext,
9
10
  type PreAddPoolAccess,
10
11
  type PreAddResult,
11
12
  type PreAddRule,
13
+ type TaggedEviction,
14
+ TxPoolRejectionCode,
15
+ type TxPoolRejectionError,
12
16
  } from './interfaces.js';
13
17
 
14
18
  // Pre-add rules