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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dest/client/factory.d.ts +3 -3
  2. package/dest/client/factory.d.ts.map +1 -1
  3. package/dest/client/factory.js +5 -3
  4. package/dest/client/interface.d.ts +9 -2
  5. package/dest/client/interface.d.ts.map +1 -1
  6. package/dest/client/p2p_client.d.ts +7 -4
  7. package/dest/client/p2p_client.d.ts.map +1 -1
  8. package/dest/client/p2p_client.js +22 -7
  9. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -1
  10. package/dest/config.d.ts +9 -3
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +3 -1
  13. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
  14. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  15. package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
  16. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
  17. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  18. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +351 -85
  19. package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
  20. package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
  21. package/dest/mem_pools/attestation_pool/index.js +1 -2
  22. package/dest/mem_pools/index.d.ts +2 -2
  23. package/dest/mem_pools/index.d.ts.map +1 -1
  24. package/dest/mem_pools/index.js +1 -1
  25. package/dest/mem_pools/interface.d.ts +3 -3
  26. package/dest/mem_pools/interface.d.ts.map +1 -1
  27. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
  28. package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
  29. package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
  30. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
  31. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
  32. package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
  33. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
  34. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
  35. package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
  36. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
  37. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  38. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
  39. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
  40. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
  41. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
  42. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
  43. package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
  44. package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
  45. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
  46. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
  47. package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
  48. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
  49. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  50. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
  51. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
  52. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  53. package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
  54. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
  55. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  56. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
  57. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
  58. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
  59. package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
  60. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
  61. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
  62. package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
  63. package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
  64. package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
  65. package/dest/mem_pools/tx_pool_v2/index.js +4 -0
  66. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
  67. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
  68. package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
  69. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
  70. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
  71. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
  72. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
  73. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
  74. package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
  75. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
  76. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
  77. package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
  78. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
  79. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
  80. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
  81. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
  82. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
  83. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
  84. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  85. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  86. package/dest/services/dummy_service.d.ts +6 -2
  87. package/dest/services/dummy_service.d.ts.map +1 -1
  88. package/dest/services/dummy_service.js +3 -0
  89. package/dest/services/index.d.ts +2 -1
  90. package/dest/services/index.d.ts.map +1 -1
  91. package/dest/services/index.js +1 -0
  92. package/dest/services/libp2p/libp2p_service.d.ts +74 -33
  93. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  94. package/dest/services/libp2p/libp2p_service.js +299 -228
  95. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -4
  96. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  97. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +8 -8
  98. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
  99. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
  100. package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
  101. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -10
  102. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
  103. package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +12 -11
  104. package/dest/services/service.d.ts +18 -1
  105. package/dest/services/service.d.ts.map +1 -1
  106. package/dest/services/tx_collection/config.d.ts +3 -3
  107. package/dest/services/tx_collection/config.js +3 -3
  108. package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -5
  109. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  110. package/dest/services/tx_collection/fast_tx_collection.js +10 -14
  111. package/dest/services/tx_collection/index.d.ts +1 -1
  112. package/dest/services/tx_collection/proposal_tx_collector.d.ts +12 -12
  113. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  114. package/dest/services/tx_collection/proposal_tx_collector.js +4 -5
  115. package/dest/services/tx_file_store/config.d.ts +18 -0
  116. package/dest/services/tx_file_store/config.d.ts.map +1 -0
  117. package/dest/services/tx_file_store/config.js +26 -0
  118. package/dest/services/tx_file_store/index.d.ts +4 -0
  119. package/dest/services/tx_file_store/index.d.ts.map +1 -0
  120. package/dest/services/tx_file_store/index.js +3 -0
  121. package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
  122. package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
  123. package/dest/services/tx_file_store/instrumentation.js +29 -0
  124. package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
  125. package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
  126. package/dest/services/tx_file_store/tx_file_store.js +149 -0
  127. package/dest/test-helpers/testbench-utils.d.ts +10 -16
  128. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  129. package/dest/test-helpers/testbench-utils.js +32 -30
  130. package/dest/testbench/p2p_client_testbench_worker.js +1 -1
  131. package/package.json +14 -14
  132. package/src/client/factory.ts +7 -4
  133. package/src/client/interface.ts +13 -1
  134. package/src/client/p2p_client.ts +30 -8
  135. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -1
  136. package/src/config.ts +8 -1
  137. package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
  138. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
  139. package/src/mem_pools/attestation_pool/index.ts +9 -2
  140. package/src/mem_pools/index.ts +1 -1
  141. package/src/mem_pools/interface.ts +2 -2
  142. package/src/mem_pools/tx_pool_v2/README.md +209 -0
  143. package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
  144. package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
  145. package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
  146. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
  147. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
  148. package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
  149. package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
  150. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
  151. package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
  152. package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
  153. package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
  154. package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
  155. package/src/mem_pools/tx_pool_v2/index.ts +11 -0
  156. package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
  157. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
  158. package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
  159. package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
  160. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
  161. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
  162. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
  163. package/src/services/dummy_service.ts +6 -0
  164. package/src/services/index.ts +1 -0
  165. package/src/services/libp2p/libp2p_service.ts +304 -230
  166. package/src/services/reqresp/batch-tx-requester/README.md +7 -7
  167. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +11 -11
  168. package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +22 -13
  169. package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +21 -15
  170. package/src/services/service.ts +20 -0
  171. package/src/services/tx_collection/config.ts +6 -6
  172. package/src/services/tx_collection/fast_tx_collection.ts +14 -24
  173. package/src/services/tx_collection/index.ts +1 -1
  174. package/src/services/tx_collection/proposal_tx_collector.ts +12 -14
  175. package/src/services/tx_file_store/config.ts +43 -0
  176. package/src/services/tx_file_store/index.ts +3 -0
  177. package/src/services/tx_file_store/instrumentation.ts +36 -0
  178. package/src/services/tx_file_store/tx_file_store.ts +173 -0
  179. package/src/test-helpers/testbench-utils.ts +18 -39
  180. package/src/testbench/p2p_client_testbench_worker.ts +1 -1
  181. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
  182. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
  183. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
  184. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
  185. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
  186. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
  187. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
  188. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/mem_pools/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC"}
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/mem_pools/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,kBAAkB,CAAC;CACrC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { TxArchive } from './tx_archive.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvdHhfcG9vbF92Mi9hcmNoaXZlL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool_v2/archive/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export { TxArchive } from './tx_archive.js';
@@ -0,0 +1,43 @@
1
+ import { type Logger } from '@aztec/foundation/log';
2
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
3
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
4
+ /**
5
+ * Manages archived transactions with FIFO eviction.
6
+ * Archived transactions have their proofs stripped to save space.
7
+ */
8
+ export declare class TxArchive {
9
+ #private;
10
+ constructor(store: AztecAsyncKVStore, limit: number, log?: Logger);
11
+ /**
12
+ * Updates the maximum number of archived transactions.
13
+ */
14
+ updateLimit(limit: number): void;
15
+ /**
16
+ * Gets the current archive limit.
17
+ */
18
+ getLimit(): number;
19
+ /**
20
+ * Checks if archiving is enabled.
21
+ */
22
+ isEnabled(): boolean;
23
+ /**
24
+ * Archives transactions, stripping their proofs.
25
+ * Evicts oldest transactions if the limit is exceeded.
26
+ */
27
+ archiveTxs(txs: Tx[]): Promise<void>;
28
+ /**
29
+ * Retrieves an archived transaction by its hash.
30
+ */
31
+ getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
32
+ /**
33
+ * Gets the current count of archived transactions.
34
+ */
35
+ getCount(): Promise<number>;
36
+ /**
37
+ * Strips the proof from a transaction for archival.
38
+ */
39
+ private stripProof;
40
+ private getHeadIndex;
41
+ private getTailIndex;
42
+ }
43
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfYXJjaGl2ZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21lbV9wb29scy90eF9wb29sX3YyL2FyY2hpdmUvdHhfYXJjaGl2ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDbEUsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFFeEUsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUU5Qzs7O0dBR0c7QUFDSCxxQkFBYSxTQUFTOztJQU9wQixZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUFFLEdBQUcsQ0FBQyxFQUFFLE1BQU0sRUFNaEU7SUFFRDs7T0FFRztJQUNILFdBQVcsQ0FBQ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AAO,CAAC,IAAI,CAAC,CAmCzC;IAED;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAGzD;IAED;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAIhC;IAED;;OAEG;IACH,OAAO,CAAC,UAAU;YAIJ,YAAY;YAKZ,YAAY;CAI3B"}
@@ -0,0 +1,103 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { ChonkProof } from '@aztec/stdlib/proofs';
3
+ import { Tx } from '@aztec/stdlib/tx';
4
+ /**
5
+ * Manages archived transactions with FIFO eviction.
6
+ * Archived transactions have their proofs stripped to save space.
7
+ */ export class TxArchive {
8
+ #store;
9
+ #txs;
10
+ #indices;
11
+ #limit;
12
+ #log;
13
+ constructor(store, limit, log){
14
+ this.#store = store;
15
+ this.#txs = store.openMap('archivedTxs');
16
+ this.#indices = store.openMap('archivedTxIndices');
17
+ this.#limit = limit;
18
+ this.#log = log ?? createLogger('p2p:tx_pool_v2:archive');
19
+ }
20
+ /**
21
+ * Updates the maximum number of archived transactions.
22
+ */ updateLimit(limit) {
23
+ this.#limit = limit;
24
+ }
25
+ /**
26
+ * Gets the current archive limit.
27
+ */ getLimit() {
28
+ return this.#limit;
29
+ }
30
+ /**
31
+ * Checks if archiving is enabled.
32
+ */ isEnabled() {
33
+ return this.#limit > 0;
34
+ }
35
+ /**
36
+ * Archives transactions, stripping their proofs.
37
+ * Evicts oldest transactions if the limit is exceeded.
38
+ */ async archiveTxs(txs) {
39
+ if (!this.isEnabled() || txs.length === 0) {
40
+ return;
41
+ }
42
+ try {
43
+ await this.#store.transactionAsync(async ()=>{
44
+ // Get current head and tail indices
45
+ let headIdx = await this.getHeadIndex();
46
+ let tailIdx = await this.getTailIndex();
47
+ for (const tx of txs){
48
+ // Evict oldest entries if at capacity
49
+ while(headIdx - tailIdx >= this.#limit){
50
+ const txHashToEvict = await this.#indices.getAsync(tailIdx);
51
+ if (txHashToEvict) {
52
+ await this.#txs.delete(txHashToEvict);
53
+ await this.#indices.delete(tailIdx);
54
+ }
55
+ tailIdx++;
56
+ }
57
+ // Archive the transaction with stripped proof
58
+ const archivedTx = this.stripProof(tx);
59
+ const txHash = tx.getTxHash().toString();
60
+ await this.#txs.set(txHash, archivedTx.toBuffer());
61
+ await this.#indices.set(headIdx, txHash);
62
+ headIdx++;
63
+ }
64
+ this.#log.debug(`Archived ${txs.length} txs, total: ${headIdx - tailIdx}`);
65
+ });
66
+ } catch (error) {
67
+ this.#log.error('Error archiving transactions', {
68
+ error
69
+ });
70
+ }
71
+ }
72
+ /**
73
+ * Retrieves an archived transaction by its hash.
74
+ */ async getTxByHash(txHash) {
75
+ const buffer = await this.#txs.getAsync(txHash.toString());
76
+ return buffer ? Tx.fromBuffer(buffer) : undefined;
77
+ }
78
+ /**
79
+ * Gets the current count of archived transactions.
80
+ */ async getCount() {
81
+ const head = await this.getHeadIndex();
82
+ const tail = await this.getTailIndex();
83
+ return head - tail;
84
+ }
85
+ /**
86
+ * Strips the proof from a transaction for archival.
87
+ */ stripProof(tx) {
88
+ return new Tx(tx.txHash, tx.data, ChonkProof.empty(), tx.contractClassLogFields, tx.publicFunctionCalldata);
89
+ }
90
+ async getHeadIndex() {
91
+ const entry = await this.#indices.entriesAsync({
92
+ limit: 1,
93
+ reverse: true
94
+ }).next();
95
+ return (entry.value?.[0] ?? -1) + 1;
96
+ }
97
+ async getTailIndex() {
98
+ const entry = await this.#indices.entriesAsync({
99
+ limit: 1
100
+ }).next();
101
+ return entry.value?.[0] ?? 0;
102
+ }
103
+ }
@@ -0,0 +1,47 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+ import type { BlockHeader } from '@aztec/stdlib/tx';
4
+ import type { TxMetaData } from '../tx_metadata.js';
5
+ import { type EvictionConfig, type EvictionRule, type PoolOperations, type PreAddPoolAccess, type PreAddResult, type PreAddRule } from './interfaces.js';
6
+ /**
7
+ * Manages eviction rules for the transaction pool.
8
+ * Coordinates pre-add rules (run during addPendingTxs) and post-event rules (run after events).
9
+ */
10
+ export declare class EvictionManager {
11
+ private pool;
12
+ private log;
13
+ private preAddRules;
14
+ private postEventRules;
15
+ constructor(pool: PoolOperations, log: Logger);
16
+ /**
17
+ * Registers a pre-add rule that runs during transaction addition.
18
+ */
19
+ registerPreAddRule(rule: PreAddRule): void;
20
+ /**
21
+ * Registers a post-event eviction rule that runs after events.
22
+ */
23
+ registerRule(rule: EvictionRule): void;
24
+ /**
25
+ * Runs all pre-add rules for an incoming transaction.
26
+ * Returns combined result of all rules.
27
+ */
28
+ runPreAddRules(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult>;
29
+ /**
30
+ * Runs post-event eviction after new transactions are added.
31
+ */
32
+ evictAfterNewTxs(newTxHashes: string[], feePayers: string[]): Promise<void>;
33
+ /**
34
+ * Runs post-event eviction after a block is mined.
35
+ */
36
+ evictAfterNewBlock(block: BlockHeader, newNullifiers: string[], feePayers: string[]): Promise<void>;
37
+ /**
38
+ * Runs post-event eviction after a chain prune (reorg).
39
+ */
40
+ evictAfterChainPrune(blockNumber: BlockNumber): Promise<void>;
41
+ /**
42
+ * Updates configuration for all rules.
43
+ */
44
+ updateConfig(config: EvictionConfig): void;
45
+ private runPostEventRules;
46
+ }
47
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZpY3Rpb25fbWFuYWdlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21lbV9wb29scy90eF9wb29sX3YyL2V2aWN0aW9uL2V2aWN0aW9uX21hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDbkUsT0FBTyxLQUFL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xFQUFFLFdBQVcsRUFBRSxhQUFhLEVBQUUsTUFBTSxFQUFFLEVBQUUsU0FBUyxFQUFFLE1BQU0sRUFBRSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FTeEc7SUFFRDs7T0FFRztJQUNHLG9CQUFvQixDQUFDLFdBQVcsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQU9sRTtJQUVEOztPQUVHO0lBQ0gsWUFBWSxDQUFDLE1BQU0sRUFBRSxjQUFjLEdBQUcsSUFBSSxDQU96QztZQUVhLGlCQUFpQjtDQVloQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eviction_manager.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,qBAAa,eAAe;IAKxB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,GAAG;IALb,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,cAAc,CAAsB;IAE5C,YACU,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,MAAM,EACjB;IAEJ;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAGzC;IAED;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAGrC;IAED;;;OAGG;IACG,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAgClG;IAED;;OAEG;IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAQhF;IAED;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CASxG;IAED;;OAEG;IACG,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAOlE;IAED;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAOzC;YAEa,iBAAiB;CAYhC"}
@@ -0,0 +1,119 @@
1
+ import { EvictionEvent } from './interfaces.js';
2
+ /**
3
+ * Manages eviction rules for the transaction pool.
4
+ * Coordinates pre-add rules (run during addPendingTxs) and post-event rules (run after events).
5
+ */ export class EvictionManager {
6
+ pool;
7
+ log;
8
+ preAddRules;
9
+ postEventRules;
10
+ constructor(pool, log){
11
+ this.pool = pool;
12
+ this.log = log;
13
+ this.preAddRules = [];
14
+ this.postEventRules = [];
15
+ }
16
+ /**
17
+ * Registers a pre-add rule that runs during transaction addition.
18
+ */ registerPreAddRule(rule) {
19
+ this.preAddRules.push(rule);
20
+ this.log.debug(`Registered pre-add rule: ${rule.name}`);
21
+ }
22
+ /**
23
+ * Registers a post-event eviction rule that runs after events.
24
+ */ registerRule(rule) {
25
+ this.postEventRules.push(rule);
26
+ this.log.debug(`Registered eviction rule: ${rule.name}`);
27
+ }
28
+ /**
29
+ * Runs all pre-add rules for an incoming transaction.
30
+ * Returns combined result of all rules.
31
+ */ async runPreAddRules(incomingMeta, poolAccess) {
32
+ const allTxHashesToEvict = [];
33
+ for (const rule of this.preAddRules){
34
+ try {
35
+ const result = await rule.check(incomingMeta, poolAccess);
36
+ if (result.shouldIgnore) {
37
+ return result;
38
+ }
39
+ // Collect txs to evict from all rules
40
+ for (const txHash of result.txHashesToEvict){
41
+ if (!allTxHashesToEvict.includes(txHash)) {
42
+ allTxHashesToEvict.push(txHash);
43
+ }
44
+ }
45
+ } catch (err) {
46
+ this.log.error(`Error running pre-add rule ${rule.name}`, {
47
+ err,
48
+ txHash: incomingMeta.txHash
49
+ });
50
+ // On error, ignore the transaction to be safe
51
+ return {
52
+ shouldIgnore: true,
53
+ txHashesToEvict: [],
54
+ reason: `pre-add rule ${rule.name} error: ${err}`
55
+ };
56
+ }
57
+ }
58
+ return {
59
+ shouldIgnore: false,
60
+ txHashesToEvict: allTxHashesToEvict
61
+ };
62
+ }
63
+ /**
64
+ * Runs post-event eviction after new transactions are added.
65
+ */ async evictAfterNewTxs(newTxHashes, feePayers) {
66
+ const context = {
67
+ event: EvictionEvent.TXS_ADDED,
68
+ newTxHashes,
69
+ feePayers
70
+ };
71
+ await this.runPostEventRules(context);
72
+ }
73
+ /**
74
+ * Runs post-event eviction after a block is mined.
75
+ */ async evictAfterNewBlock(block, newNullifiers, feePayers) {
76
+ const context = {
77
+ event: EvictionEvent.BLOCK_MINED,
78
+ block,
79
+ newNullifiers,
80
+ feePayers
81
+ };
82
+ await this.runPostEventRules(context);
83
+ }
84
+ /**
85
+ * Runs post-event eviction after a chain prune (reorg).
86
+ */ async evictAfterChainPrune(blockNumber) {
87
+ const context = {
88
+ event: EvictionEvent.CHAIN_PRUNED,
89
+ blockNumber
90
+ };
91
+ await this.runPostEventRules(context);
92
+ }
93
+ /**
94
+ * Updates configuration for all rules.
95
+ */ updateConfig(config) {
96
+ for (const rule of this.preAddRules){
97
+ rule.updateConfig?.(config);
98
+ }
99
+ for (const rule of this.postEventRules){
100
+ rule.updateConfig?.(config);
101
+ }
102
+ }
103
+ async runPostEventRules(context) {
104
+ for (const rule of this.postEventRules){
105
+ try {
106
+ const result = await rule.evict(context, this.pool);
107
+ if (!result.success) {
108
+ this.log.warn(`Eviction rule ${rule.name} failed`, {
109
+ error: result.error
110
+ });
111
+ }
112
+ } catch (err) {
113
+ this.log.error(`Error running eviction rule ${rule.name}`, {
114
+ err
115
+ });
116
+ }
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,17 @@
1
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
2
+ import type { EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
3
+ /**
4
+ * Eviction rule that removes transactions when fee payers have insufficient balance.
5
+ * Triggers on TXS_ADDED, BLOCK_MINED, and CHAIN_PRUNED events.
6
+ */
7
+ export declare class FeePayerBalanceEvictionRule implements EvictionRule {
8
+ private worldState;
9
+ readonly name = "FeePayerBalanceEviction";
10
+ readonly reason = "fee_payer_balance";
11
+ private log;
12
+ constructor(worldState: WorldStateSynchronizer);
13
+ evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult>;
14
+ private evictForFeePayers;
15
+ private getEvictionsForFeePayer;
16
+ }
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmVlX3BheWVyX2JhbGFuY2VfZXZpY3Rpb25fcnVsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21lbV9wb29scy90eF9wb29sX3YyL2V2aWN0aW9uL2ZlZV9wYXllcl9iYWxhbmNlX2V2aWN0aW9uX3J1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxLQUFLLEVBQUUsc0JBQXNCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUk5RSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsY0FBYyxFQUFFLFlBQVksRUFBRSxjQUFjLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUdyRzs7O0dBR0c7QUFDSCxxQkFBYSwyQkFBNEIsWUFBVyxZQUFZO0lBTWxELE9BQU8sQ0FBQyxVQUFVO0lBTDlCLFNBQWdCLElBQUksNkJBQTZCO0lBQ2pELFNBQWdCLE1BQU0sdUJBQXVCO0lBRTdDLE9BQU8sQ0FBQyxHQUFHLENBQWtFO0lBRTdFLFlBQW9CLFVBQVUsRUFBRSxzQkFBc0IsRUFBSTtJQUVwRCxLQUFLLENBQUMsT0FBTyxFQUFFLGVBQWUsRUFBRSxJQUFJLEVBQUUsY0FBYyxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FnQ25GO1lBRWEsaUJBQWlCO1lBc0JqQix1QkFBdUI7Q0FzQ3RDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fee_payer_balance_eviction_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAI9E,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGrG;;;GAGG;AACH,qBAAa,2BAA4B,YAAW,YAAY;IAMlD,OAAO,CAAC,UAAU;IAL9B,SAAgB,IAAI,6BAA6B;IACjD,SAAgB,MAAM,uBAAuB;IAE7C,OAAO,CAAC,GAAG,CAAkE;IAE7E,YAAoB,UAAU,EAAE,sBAAsB,EAAI;IAEpD,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAgCnF;YAEa,iBAAiB;YAsBjB,uBAAuB;CAsCtC"}
@@ -0,0 +1,90 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
+ import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
6
+ import { comparePriority } from '../tx_metadata.js';
7
+ import { EvictionEvent } from './interfaces.js';
8
+ /**
9
+ * Eviction rule that removes transactions when fee payers have insufficient balance.
10
+ * Triggers on TXS_ADDED, BLOCK_MINED, and CHAIN_PRUNED events.
11
+ */ export class FeePayerBalanceEvictionRule {
12
+ worldState;
13
+ name;
14
+ reason;
15
+ log;
16
+ constructor(worldState){
17
+ this.worldState = worldState;
18
+ this.name = 'FeePayerBalanceEviction';
19
+ this.reason = 'fee_payer_balance';
20
+ this.log = createLogger('p2p:tx_pool_v2:fee_payer_balance_eviction_rule');
21
+ }
22
+ async evict(context, pool) {
23
+ try {
24
+ if (context.event === EvictionEvent.TXS_ADDED) {
25
+ return await this.evictForFeePayers(context.feePayers, this.worldState.getCommitted(), pool);
26
+ }
27
+ if (context.event === EvictionEvent.BLOCK_MINED) {
28
+ const blockNumber = context.block.getBlockNumber();
29
+ await this.worldState.syncImmediate(blockNumber);
30
+ return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), pool);
31
+ }
32
+ if (context.event === EvictionEvent.CHAIN_PRUNED) {
33
+ await this.worldState.syncImmediate(context.blockNumber);
34
+ const feePayers = pool.getPendingFeePayers();
35
+ return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), pool);
36
+ }
37
+ return {
38
+ reason: this.reason,
39
+ success: true,
40
+ txsEvicted: []
41
+ };
42
+ } catch (err) {
43
+ this.log.error('Failed to evict txs due to fee payer balance', {
44
+ err
45
+ });
46
+ return {
47
+ reason: this.reason,
48
+ success: false,
49
+ txsEvicted: [],
50
+ error: new Error('Failed to evict txs due to fee payer balance', {
51
+ cause: err
52
+ })
53
+ };
54
+ }
55
+ }
56
+ async evictForFeePayers(feePayers, db, pool) {
57
+ const publicStateSource = new DatabasePublicStateSource(db);
58
+ const txsToEvict = (await Promise.all(feePayers.map((feePayer)=>this.getEvictionsForFeePayer(feePayer, publicStateSource, pool)))).flat();
59
+ if (txsToEvict.length > 0) {
60
+ await pool.deleteTxs(txsToEvict);
61
+ }
62
+ return {
63
+ reason: this.reason,
64
+ success: true,
65
+ txsEvicted: txsToEvict
66
+ };
67
+ }
68
+ async getEvictionsForFeePayer(feePayerStr, publicStateSource, pool) {
69
+ const feePayer = AztecAddress.fromString(feePayerStr);
70
+ const initialBalance = (await publicStateSource.storageRead(ProtocolContractAddress.FeeJuice, await computeFeePayerBalanceStorageSlot(feePayer))).toBigInt();
71
+ const txs = pool.getFeePayerPendingTxs(feePayerStr);
72
+ if (txs.length === 0) {
73
+ return [];
74
+ }
75
+ const txsToEvict = [];
76
+ let balance = initialBalance;
77
+ // Sort by priority descending (highest first), with hash as tiebreaker
78
+ txs.sort((a, b)=>comparePriority(b, a));
79
+ for (const tx of txs){
80
+ const available = balance + tx.claimAmount;
81
+ if (available >= tx.feeLimit) {
82
+ balance = available - tx.feeLimit;
83
+ continue;
84
+ }
85
+ // This tx cannot be covered - mark for eviction
86
+ txsToEvict.push(tx.txHash);
87
+ }
88
+ return txsToEvict;
89
+ }
90
+ }
@@ -0,0 +1,19 @@
1
+ import { type TxMetaData } from '../tx_metadata.js';
2
+ import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
3
+ /**
4
+ * Pre-add rule that checks if a fee payer has sufficient balance to cover the incoming transaction.
5
+ *
6
+ * When an incoming tx is added:
7
+ * - Get the fee payer's on-chain balance
8
+ * - Get all existing pending txs for this fee payer
9
+ * - Insert incoming tx in priority order
10
+ * - Walk through in priority order, tracking running balance
11
+ * - If incoming tx can be covered: accept, mark lower-priority txs for eviction if needed
12
+ * - If incoming tx cannot be covered: ignore it
13
+ */
14
+ export declare class FeePayerBalancePreAddRule implements PreAddRule {
15
+ readonly name = "FeePayerBalancePreAdd";
16
+ private log;
17
+ check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult>;
18
+ }
19
+ //# sourceMappingURL=data:application/json;base64,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AU,EAAE,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAwFzF;CACF"}
@@ -0,0 +1,89 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { comparePriority } from '../tx_metadata.js';
3
+ /**
4
+ * Pre-add rule that checks if a fee payer has sufficient balance to cover the incoming transaction.
5
+ *
6
+ * When an incoming tx is added:
7
+ * - Get the fee payer's on-chain balance
8
+ * - Get all existing pending txs for this fee payer
9
+ * - Insert incoming tx in priority order
10
+ * - Walk through in priority order, tracking running balance
11
+ * - If incoming tx can be covered: accept, mark lower-priority txs for eviction if needed
12
+ * - If incoming tx cannot be covered: ignore it
13
+ */ export class FeePayerBalancePreAddRule {
14
+ name = 'FeePayerBalancePreAdd';
15
+ log = createLogger('p2p:tx_pool_v2:fee_payer_balance_pre_add_rule');
16
+ async check(incomingMeta, poolAccess) {
17
+ // Get fee payer's on-chain balance
18
+ const initialBalance = await poolAccess.getFeePayerBalance(incomingMeta.feePayer);
19
+ // Get existing pending txs for this fee payer
20
+ const existingTxs = poolAccess.getFeePayerPendingTxs(incomingMeta.feePayer);
21
+ // Create combined list with incoming tx
22
+ const allTxs = [
23
+ ...existingTxs.map((t)=>({
24
+ txHash: t.txHash,
25
+ priorityFee: t.priorityFee,
26
+ feeLimit: t.feeLimit,
27
+ claimAmount: t.claimAmount,
28
+ isIncoming: false
29
+ })),
30
+ {
31
+ txHash: incomingMeta.txHash,
32
+ priorityFee: incomingMeta.priorityFee,
33
+ feeLimit: incomingMeta.feeLimit,
34
+ claimAmount: incomingMeta.claimAmount,
35
+ isIncoming: true
36
+ }
37
+ ];
38
+ // Sort by priority descending (highest first), with hash as tiebreaker
39
+ allTxs.sort((a, b)=>comparePriority(b, a));
40
+ // Walk through in priority order, tracking balance
41
+ let balance = initialBalance;
42
+ let incomingTxCovered = false;
43
+ const txsToEvict = [];
44
+ for (const txInfo of allTxs){
45
+ const available = balance + txInfo.claimAmount;
46
+ if (available >= txInfo.feeLimit) {
47
+ // This tx can be covered
48
+ balance = available - txInfo.feeLimit;
49
+ if (txInfo.isIncoming) {
50
+ incomingTxCovered = true;
51
+ }
52
+ } else {
53
+ // This tx cannot be covered
54
+ if (txInfo.isIncoming) {
55
+ // Incoming tx cannot be covered - ignore it
56
+ this.log.debug(`Ignoring tx ${incomingMeta.txHash}: fee payer ${incomingMeta.feePayer} has insufficient balance`, {
57
+ balance: initialBalance,
58
+ feeLimit: incomingMeta.feeLimit,
59
+ claimAmount: incomingMeta.claimAmount
60
+ });
61
+ return {
62
+ shouldIgnore: true,
63
+ txHashesToEvict: [],
64
+ reason: `fee payer ${incomingMeta.feePayer} has insufficient balance`
65
+ };
66
+ } else {
67
+ // Existing tx cannot be covered after adding incoming - mark for eviction
68
+ txsToEvict.push(txInfo.txHash);
69
+ }
70
+ }
71
+ }
72
+ if (!incomingTxCovered) {
73
+ // This shouldn't happen if the logic above is correct, but just in case
74
+ this.log.warn(`Incoming tx ${incomingMeta.txHash} was not covered but also not ignored - this is a bug`);
75
+ return {
76
+ shouldIgnore: true,
77
+ txHashesToEvict: [],
78
+ reason: 'internal error: tx coverage not determined'
79
+ };
80
+ }
81
+ if (txsToEvict.length > 0) {
82
+ this.log.debug(`Accepting tx ${incomingMeta.txHash}, evicting ${txsToEvict.length} lower-priority txs due to fee payer balance`);
83
+ }
84
+ return {
85
+ shouldIgnore: false,
86
+ txHashesToEvict: txsToEvict
87
+ };
88
+ }
89
+ }
@@ -0,0 +1,10 @@
1
+ export { EvictionManager } from './eviction_manager.js';
2
+ export { type EvictionConfig, type EvictionContext, EvictionEvent, type EvictionResult, type EvictionRule, type PoolOperations, type PreAddPoolAccess, type PreAddResult, type PreAddRule, } from './interfaces.js';
3
+ export { NullifierConflictRule } from './nullifier_conflict_rule.js';
4
+ export { FeePayerBalancePreAddRule } from './fee_payer_balance_pre_add_rule.js';
5
+ export { LowPriorityPreAddRule } from './low_priority_pre_add_rule.js';
6
+ export { InvalidTxsAfterMiningRule } from './invalid_txs_after_mining_rule.js';
7
+ export { InvalidTxsAfterReorgRule } from './invalid_txs_after_reorg_rule.js';
8
+ export { FeePayerBalanceEvictionRule } from './fee_payer_balance_eviction_rule.js';
9
+ export { LowPriorityEvictionRule } from './low_priority_eviction_rule.js';
10
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvdHhfcG9vbF92Mi9ldmljdGlvbi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDeEQsT0FBTyxFQUNMLEtBQUssY0FBYyxFQUNuQixLQUFLLGVBQWUsRUFDcEIsYUFBYSxFQUNiLEtBQUssY0FBYyxFQUNuQixLQUFLLFlBQVksRUFDakIsS0FBSyxjQUFjLEVBQ25CLEtBQUssZ0JBQWdCLEVBQ3JCLEtBQUssWUFBWSxFQUNqQixLQUFLLFVBQVUsR0FDaEIsTUFBTSxpQkFBaUIsQ0FBQztBQUd6QixPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUNyRSxPQUFPLEVBQUUseUJBQXlCLEVBQUUsTUFBTSxxQ0FBcUMsQ0FBQztBQUNoRixPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUd2RSxPQUFPLEVBQUUseUJBQXlCLEVBQUUsTUFBTSxvQ0FBb0MsQ0FBQztBQUMvRSxPQUFPLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxtQ0FBbUMsQ0FBQztBQUM3RSxPQUFPLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSxzQ0FBc0MsQ0FBQztBQUNuRixPQUFPLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool_v2/eviction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAGvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,11 @@
1
+ export { EvictionManager } from './eviction_manager.js';
2
+ export { EvictionEvent } from './interfaces.js';
3
+ // Pre-add rules
4
+ export { NullifierConflictRule } from './nullifier_conflict_rule.js';
5
+ export { FeePayerBalancePreAddRule } from './fee_payer_balance_pre_add_rule.js';
6
+ export { LowPriorityPreAddRule } from './low_priority_pre_add_rule.js';
7
+ // Post-event eviction rules
8
+ export { InvalidTxsAfterMiningRule } from './invalid_txs_after_mining_rule.js';
9
+ export { InvalidTxsAfterReorgRule } from './invalid_txs_after_reorg_rule.js';
10
+ export { FeePayerBalanceEvictionRule } from './fee_payer_balance_eviction_rule.js';
11
+ export { LowPriorityEvictionRule } from './low_priority_eviction_rule.js';