@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
@@ -0,0 +1,748 @@
1
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
+ import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
3
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
5
+ import { Tx, TxHash } from '@aztec/stdlib/tx';
6
+ import { TxArchive } from './archive/index.js';
7
+ import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule } from './eviction/index.js';
8
+ import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
9
+ import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
10
+ import { TxPoolIndices } from './tx_pool_indices.js';
11
+ /**
12
+ * Implementation of TxPoolV2 logic.
13
+ *
14
+ * This class contains all the actual transaction pool logic.
15
+ */ export class TxPoolV2Impl {
16
+ // === Persistence ===
17
+ #store;
18
+ #txsDB;
19
+ // === Dependencies ===
20
+ #l2BlockSource;
21
+ #worldStateSynchronizer;
22
+ #pendingTxValidator;
23
+ // === In-Memory Indices ===
24
+ #indices = new TxPoolIndices();
25
+ // === Config & Services ===
26
+ #config;
27
+ #archive;
28
+ #evictionManager;
29
+ #log;
30
+ #callbacks;
31
+ constructor(store, archiveStore, deps, callbacks, config = {}, log){
32
+ this.#store = store;
33
+ this.#txsDB = store.openMap('txs');
34
+ this.#l2BlockSource = deps.l2BlockSource;
35
+ this.#worldStateSynchronizer = deps.worldStateSynchronizer;
36
+ this.#pendingTxValidator = deps.pendingTxValidator;
37
+ this.#config = {
38
+ ...DEFAULT_TX_POOL_V2_CONFIG,
39
+ ...config
40
+ };
41
+ this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
42
+ this.#log = log;
43
+ this.#callbacks = callbacks;
44
+ // Setup eviction manager with rules
45
+ this.#evictionManager = new EvictionManager(this.#createPoolOperations(), log);
46
+ // Pre-add rules (run during addPendingTxs) - work with TxMetaData
47
+ this.#evictionManager.registerPreAddRule(new NullifierConflictRule());
48
+ this.#evictionManager.registerPreAddRule(new FeePayerBalancePreAddRule());
49
+ this.#evictionManager.registerPreAddRule(new LowPriorityPreAddRule({
50
+ maxPoolSize: this.#config.maxPendingTxCount
51
+ }));
52
+ // Post-event eviction rules (run after events to check ALL pending txs)
53
+ this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
54
+ this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(deps.worldStateSynchronizer));
55
+ this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(deps.worldStateSynchronizer));
56
+ // LowPriorityEvictionRule handles cases where txs become pending via prepareForSlot (unprotect)
57
+ // The pre-add rule handles the addPendingTxs case, but post-event is needed for unprotect
58
+ this.#evictionManager.registerRule(new LowPriorityEvictionRule({
59
+ maxPoolSize: this.#config.maxPendingTxCount
60
+ }));
61
+ }
62
+ // ============================================================================
63
+ // PUBLIC IMPLEMENTATION METHODS
64
+ // ============================================================================
65
+ /**
66
+ * Hydrates the in-memory state from the database on startup.
67
+ * Pipeline: Load → Check Mined Status → Partition → Validate Non-Mined → Rebuild Pending Pool → Delete Invalid
68
+ *
69
+ * Note: Protected status is lost on restart. All non-mined txs are rebuilt as pending
70
+ * by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
71
+ */ async hydrateFromDatabase() {
72
+ // Step 1: Load all transactions from DB
73
+ const { loaded, errors: deserializationErrors } = await this.#loadAllTxsFromDb();
74
+ // Step 2: Check mined status for each tx
75
+ await this.#markMinedStatusBatch(loaded.map((l)=>l.meta));
76
+ // Step 3: Partition by mined status
77
+ const mined = [];
78
+ const nonMined = [];
79
+ for (const entry of loaded){
80
+ if (entry.meta.minedL2BlockId !== undefined) {
81
+ mined.push(entry.meta);
82
+ } else {
83
+ nonMined.push(entry);
84
+ }
85
+ }
86
+ // Step 4: Validate non-mined transactions
87
+ const { valid, invalid } = await this.#validateTxBatch(nonMined, 'on startup');
88
+ // Step 5: Populate mined indices (these don't need conflict resolution)
89
+ for (const meta of mined){
90
+ this.#indices.addMined(meta);
91
+ }
92
+ // Step 6: Rebuild pending pool by running pre-add rules for each tx
93
+ // This resolves nullifier conflicts, fee payer balance issues, and pool size limits
94
+ const { rejected } = await this.#rebuildPendingPool(valid);
95
+ // Step 7: Delete invalid and rejected txs from DB only (indices were never populated for these)
96
+ const toDelete = [
97
+ ...deserializationErrors,
98
+ ...invalid,
99
+ ...rejected
100
+ ];
101
+ if (toDelete.length === 0) {
102
+ return;
103
+ }
104
+ await this.#store.transactionAsync(async ()=>{
105
+ for (const txHashStr of toDelete){
106
+ await this.#txsDB.delete(txHashStr);
107
+ }
108
+ });
109
+ this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`);
110
+ }
111
+ async addPendingTxs(txs, opts) {
112
+ const accepted = [];
113
+ const ignored = [];
114
+ const rejected = [];
115
+ const acceptedPending = new Set();
116
+ const poolAccess = this.#createPreAddPoolAccess();
117
+ await this.#store.transactionAsync(async ()=>{
118
+ for (const tx of txs){
119
+ const txHash = tx.getTxHash();
120
+ const txHashStr = txHash.toString();
121
+ // Skip duplicates
122
+ if (this.#indices.has(txHashStr)) {
123
+ ignored.push(txHash);
124
+ continue;
125
+ }
126
+ // Check mined status first (applies to all paths)
127
+ const minedBlockId = await this.#getMinedBlockId(txHash);
128
+ const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
129
+ if (minedBlockId) {
130
+ // Already mined - add directly (protection already set if pre-protected)
131
+ await this.#addTx(tx, {
132
+ mined: minedBlockId
133
+ }, opts);
134
+ accepted.push(txHash);
135
+ } else if (preProtectedSlot !== undefined) {
136
+ // Pre-protected and not mined - add as protected (bypass validation)
137
+ await this.#addTx(tx, {
138
+ protected: preProtectedSlot
139
+ }, opts);
140
+ accepted.push(txHash);
141
+ } else {
142
+ // Regular pending tx - validate and run pre-add rules
143
+ const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
144
+ if (result.status === 'accepted') {
145
+ acceptedPending.add(txHashStr);
146
+ } else if (result.status === 'rejected') {
147
+ rejected.push(txHash);
148
+ } else {
149
+ ignored.push(txHash);
150
+ }
151
+ }
152
+ }
153
+ });
154
+ // Build final accepted list for pending txs (excludes intra-batch evictions)
155
+ for (const txHashStr of acceptedPending){
156
+ accepted.push(TxHash.fromString(txHashStr));
157
+ }
158
+ // Run post-add eviction rules for pending txs
159
+ if (acceptedPending.size > 0) {
160
+ const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
161
+ const uniqueFeePayers = new Set(feePayers);
162
+ await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
163
+ ...uniqueFeePayers
164
+ ]);
165
+ }
166
+ return {
167
+ accepted,
168
+ ignored,
169
+ rejected
170
+ };
171
+ }
172
+ /** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored) {
173
+ const txHash = tx.getTxHash();
174
+ const txHashStr = txHash.toString();
175
+ // Validate transaction
176
+ if (!await this.#validateTx(tx)) {
177
+ return {
178
+ status: 'rejected'
179
+ };
180
+ }
181
+ // Build metadata and run pre-add rules
182
+ const meta = await buildTxMetaData(tx);
183
+ const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
184
+ if (preAddResult.shouldIgnore) {
185
+ this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
186
+ return {
187
+ status: 'ignored'
188
+ };
189
+ }
190
+ // Evict conflicts
191
+ for (const evictHashStr of preAddResult.txHashesToEvict){
192
+ await this.#deleteTx(evictHashStr);
193
+ this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`);
194
+ if (acceptedPending.has(evictHashStr)) {
195
+ // Evicted tx was from this batch - mark as ignored in result
196
+ acceptedPending.delete(evictHashStr);
197
+ ignored.push(TxHash.fromString(evictHashStr));
198
+ }
199
+ }
200
+ // Add the transaction
201
+ await this.#addTx(tx, 'pending', opts);
202
+ return {
203
+ status: 'accepted'
204
+ };
205
+ }
206
+ async canAddPendingTx(tx) {
207
+ const txHashStr = tx.getTxHash().toString();
208
+ // Check if already in pool
209
+ if (this.#indices.has(txHashStr)) {
210
+ return 'ignored';
211
+ }
212
+ // Validate transaction (no logging for dry-run check)
213
+ const validationResult = await this.#pendingTxValidator.validateTx(tx);
214
+ if (validationResult.result !== 'valid') {
215
+ return 'rejected';
216
+ }
217
+ // Build metadata and use pre-add rules
218
+ const meta = await buildTxMetaData(tx);
219
+ const poolAccess = this.#createPreAddPoolAccess();
220
+ const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
221
+ return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
222
+ }
223
+ async addProtectedTxs(txs, block, opts) {
224
+ const slotNumber = block.globalVariables.slotNumber;
225
+ await this.#store.transactionAsync(async ()=>{
226
+ for (const tx of txs){
227
+ const txHash = tx.getTxHash();
228
+ const txHashStr = txHash.toString();
229
+ const isNew = !this.#indices.has(txHashStr);
230
+ const minedBlockId = await this.#getMinedBlockId(txHash);
231
+ if (isNew) {
232
+ // New tx - add as mined or protected (callback emitted by #addTx)
233
+ if (minedBlockId) {
234
+ await this.#addTx(tx, {
235
+ mined: minedBlockId
236
+ }, opts);
237
+ this.#indices.setProtection(txHashStr, slotNumber);
238
+ } else {
239
+ await this.#addTx(tx, {
240
+ protected: slotNumber
241
+ }, opts);
242
+ }
243
+ } else {
244
+ // Existing tx - update protection and mined status
245
+ this.#indices.updateProtection(txHashStr, slotNumber);
246
+ if (minedBlockId) {
247
+ const meta = this.#indices.getMetadata(txHashStr);
248
+ this.#indices.markAsMined(meta, minedBlockId);
249
+ }
250
+ }
251
+ }
252
+ });
253
+ }
254
+ protectTxs(txHashes, block) {
255
+ const slotNumber = block.globalVariables.slotNumber;
256
+ const missing = [];
257
+ for (const txHash of txHashes){
258
+ const txHashStr = txHash.toString();
259
+ if (this.#indices.has(txHashStr)) {
260
+ // Update protection for existing tx
261
+ this.#indices.updateProtection(txHashStr, slotNumber);
262
+ } else {
263
+ // Pre-record protection for tx we don't have yet
264
+ this.#indices.setProtection(txHashStr, slotNumber);
265
+ missing.push(txHash);
266
+ }
267
+ }
268
+ return missing;
269
+ }
270
+ async addMinedTxs(txs, block, opts) {
271
+ // Step 1: Build block ID
272
+ const blockId = await this.#buildBlockId(block);
273
+ await this.#store.transactionAsync(async ()=>{
274
+ for (const tx of txs){
275
+ const txHashStr = tx.getTxHash().toString();
276
+ const existingMeta = this.#indices.getMetadata(txHashStr);
277
+ if (existingMeta) {
278
+ // Mark existing tx as mined
279
+ this.#indices.markAsMined(existingMeta, blockId);
280
+ } else {
281
+ // Add new mined tx (callback emitted by #addTx)
282
+ await this.#addTx(tx, {
283
+ mined: blockId
284
+ }, opts);
285
+ }
286
+ }
287
+ });
288
+ }
289
+ async handleMinedBlock(block) {
290
+ // Step 1: Build block ID
291
+ const blockId = await this.#buildBlockId(block.header);
292
+ // Step 2: Extract tx hashes and nullifiers directly from the block
293
+ const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
294
+ const nullifiers = block.body.txEffects.flatMap((tx)=>tx.nullifiers.map((n)=>n.toString()));
295
+ // Step 3: Collect fee payers from txs we have in the pool (for balance-based eviction)
296
+ const feePayers = [];
297
+ const found = [];
298
+ for (const txHash of txHashes){
299
+ const meta = this.#indices.getMetadata(txHash.toString());
300
+ if (meta) {
301
+ feePayers.push(meta.feePayer);
302
+ found.push(meta);
303
+ }
304
+ }
305
+ // Step 4: Mark txs as mined (only those we have in the pool)
306
+ for (const meta of found){
307
+ this.#indices.markAsMined(meta, blockId);
308
+ }
309
+ // Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
310
+ await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
311
+ this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
312
+ }
313
+ async prepareForSlot(slotNumber) {
314
+ // Step 1: Find expired protected txs
315
+ const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
316
+ // Step 2: Clear protection for all expired entries (including those without metadata)
317
+ this.#indices.clearProtection(expiredProtected);
318
+ // Step 3: Filter to only txs that have metadata and are not mined
319
+ const txsToRestore = this.#indices.filterRestorable(expiredProtected);
320
+ if (txsToRestore.length === 0) {
321
+ return;
322
+ }
323
+ this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
324
+ // Step 4: Validate for pending pool
325
+ const { valid, invalid } = await this.#loadAndValidateTxs(txsToRestore, 'during prepareForSlot');
326
+ // Step 5: Resolve nullifier conflicts and add winners to pending indices
327
+ const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
328
+ // Step 6: Delete invalid and evicted txs
329
+ await this.#deleteTxsBatch([
330
+ ...invalid,
331
+ ...toEvict
332
+ ]);
333
+ // Step 7: Run eviction rules (enforce pool size limit)
334
+ if (added.length > 0) {
335
+ const feePayers = added.map((meta)=>meta.feePayer);
336
+ const uniqueFeePayers = new Set(feePayers);
337
+ await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
338
+ ...uniqueFeePayers
339
+ ]);
340
+ }
341
+ }
342
+ async handlePrunedBlocks(latestBlock) {
343
+ // Step 1: Find transactions mined after the prune point
344
+ const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
345
+ if (txsToUnmine.length === 0) {
346
+ this.#log.debug(`No transactions to un-mine for prune to block ${latestBlock.number}`);
347
+ return;
348
+ }
349
+ this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
350
+ // Step 2: Unmine - clear mined status from metadata
351
+ for (const meta of txsToUnmine){
352
+ this.#indices.markAsUnmined(meta);
353
+ }
354
+ // Step 3: Filter out protected txs (they'll be handled by prepareForSlot)
355
+ const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
356
+ // Step 4: Validate for pending pool
357
+ const { valid, invalid } = await this.#loadAndValidateTxs(unprotectedTxs, 'during handlePrunedBlocks');
358
+ // Step 5: Resolve nullifier conflicts and add winners to pending indices
359
+ const { toEvict } = this.#applyNullifierConflictResolution(valid);
360
+ // Step 6: Delete invalid and evicted txs
361
+ await this.#deleteTxsBatch([
362
+ ...invalid,
363
+ ...toEvict
364
+ ]);
365
+ // Step 7: Run eviction rules for ALL pending txs (not just restored ones)
366
+ // This handles cases like existing pending txs with invalid fee payer balances
367
+ await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
368
+ }
369
+ async handleFailedExecution(txHashes) {
370
+ // Delete failed txs
371
+ await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
372
+ this.#log.info(`Deleted ${txHashes.length} failed txs`);
373
+ }
374
+ async handleFinalizedBlock(block) {
375
+ const blockNumber = block.globalVariables.blockNumber;
376
+ // Step 1: Find txs mined at or before finalized block
377
+ const txsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
378
+ if (txsToFinalize.length === 0) {
379
+ return;
380
+ }
381
+ // Step 2: Collect txs for archiving (before deletion)
382
+ const txsToArchive = [];
383
+ if (this.#archive.isEnabled()) {
384
+ for (const txHashStr of txsToFinalize){
385
+ const buffer = await this.#txsDB.getAsync(txHashStr);
386
+ if (buffer) {
387
+ txsToArchive.push(Tx.fromBuffer(buffer));
388
+ }
389
+ }
390
+ }
391
+ // Step 3: Delete from active pool
392
+ await this.#deleteTxsBatch(txsToFinalize);
393
+ // Step 4: Archive
394
+ if (txsToArchive.length > 0) {
395
+ await this.#archive.archiveTxs(txsToArchive);
396
+ }
397
+ this.#log.info(`Finalized ${txsToFinalize.length} txs from blocks up to ${blockNumber}`);
398
+ }
399
+ // === Query Methods ===
400
+ async getTxByHash(txHash) {
401
+ const buffer = await this.#txsDB.getAsync(txHash.toString());
402
+ return buffer ? Tx.fromBuffer(buffer) : undefined;
403
+ }
404
+ async getTxsByHash(txHashes) {
405
+ const results = [];
406
+ for (const h of txHashes){
407
+ const buffer = await this.#txsDB.getAsync(h.toString());
408
+ results.push(buffer ? Tx.fromBuffer(buffer) : undefined);
409
+ }
410
+ return results;
411
+ }
412
+ hasTxs(txHashes) {
413
+ return txHashes.map((h)=>this.#indices.has(h.toString()));
414
+ }
415
+ getTxStatus(txHash) {
416
+ const meta = this.#indices.getMetadata(txHash.toString());
417
+ if (!meta) {
418
+ return undefined;
419
+ }
420
+ return this.#indices.getTxState(meta);
421
+ }
422
+ getPendingTxHashes() {
423
+ return [
424
+ ...this.#indices.iteratePendingByPriority('desc')
425
+ ].map((hash)=>TxHash.fromString(hash));
426
+ }
427
+ getPendingTxCount() {
428
+ return this.#indices.getPendingTxCount();
429
+ }
430
+ getMinedTxHashes() {
431
+ return this.#indices.getMinedTxs().map(([hash, blockId])=>[
432
+ TxHash.fromString(hash),
433
+ blockId
434
+ ]);
435
+ }
436
+ getMinedTxCount() {
437
+ let count = 0;
438
+ for (const [, meta] of this.#indices.iterateMetadata()){
439
+ if (meta.minedL2BlockId !== undefined) {
440
+ count++;
441
+ }
442
+ }
443
+ return count;
444
+ }
445
+ isEmpty() {
446
+ return this.#indices.isEmpty();
447
+ }
448
+ getTxCount() {
449
+ return this.#indices.getTxCount();
450
+ }
451
+ getArchivedTxByHash(txHash) {
452
+ return this.#archive.getTxByHash(txHash);
453
+ }
454
+ getLowestPriorityPending(limit) {
455
+ return this.#indices.getLowestPriorityPending(limit).map((h)=>TxHash.fromString(h));
456
+ }
457
+ // === Configuration ===
458
+ updateConfig(config) {
459
+ if (config.maxPendingTxCount !== undefined) {
460
+ this.#config.maxPendingTxCount = config.maxPendingTxCount;
461
+ }
462
+ if (config.archivedTxLimit !== undefined) {
463
+ this.#config.archivedTxLimit = config.archivedTxLimit;
464
+ this.#archive.updateLimit(config.archivedTxLimit);
465
+ }
466
+ // Update eviction rules with new config
467
+ this.#evictionManager.updateConfig(config);
468
+ }
469
+ // === Pool Read Access ===
470
+ getPoolReadAccess() {
471
+ return {
472
+ getMetadata: (txHash)=>this.#indices.getMetadata(txHash),
473
+ getTxHashByNullifier: (nullifier)=>this.#indices.getTxHashByNullifier(nullifier),
474
+ getTxHashesByFeePayer: (feePayer)=>this.#indices.getTxHashesByFeePayer(feePayer),
475
+ getPendingTxCount: ()=>this.#indices.getPendingTxCount()
476
+ };
477
+ }
478
+ // === Metrics ===
479
+ countTxs() {
480
+ return this.#indices.countTxs();
481
+ }
482
+ // ============================================================================
483
+ // PRIVATE HELPERS - Transaction Management
484
+ // ============================================================================
485
+ /**
486
+ * Adds a new transaction to the pool with the specified state.
487
+ * Emits onTxsAdded callback immediately after DB write.
488
+ */ async #addTx(tx, state, opts = {}) {
489
+ const txHashStr = tx.getTxHash().toString();
490
+ const meta = await buildTxMetaData(tx);
491
+ await this.#txsDB.set(txHashStr, tx.toBuffer());
492
+ this.#callbacks.onTxsAdded([
493
+ tx
494
+ ], opts);
495
+ if (state === 'pending') {
496
+ this.#indices.addPending(meta);
497
+ } else if ('protected' in state) {
498
+ this.#indices.addProtected(meta, state.protected);
499
+ } else {
500
+ meta.minedL2BlockId = state.mined;
501
+ this.#indices.addMined(meta);
502
+ }
503
+ const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
504
+ this.#log.verbose(`Added ${stateStr} tx ${txHashStr}`, {
505
+ eventName: 'tx-added-to-pool',
506
+ state: stateStr
507
+ });
508
+ return meta;
509
+ }
510
+ /**
511
+ * Deletes a transaction from both indices and DB.
512
+ * Emits onTxsRemoved callback immediately after DB delete.
513
+ */ async #deleteTx(txHashStr) {
514
+ this.#indices.remove(txHashStr);
515
+ await this.#txsDB.delete(txHashStr);
516
+ this.#callbacks.onTxsRemoved([
517
+ txHashStr
518
+ ]);
519
+ }
520
+ /** Deletes a batch of transactions, emitting callbacks individually for each. */ async #deleteTxsBatch(txHashes) {
521
+ for (const txHashStr of txHashes){
522
+ await this.#deleteTx(txHashStr);
523
+ }
524
+ }
525
+ // ============================================================================
526
+ // PRIVATE HELPERS - Validation & Conflict Resolution
527
+ // ============================================================================
528
+ /** Validates a single transaction, returning true if valid */ async #validateTx(tx, context) {
529
+ const result = await this.#pendingTxValidator.validateTx(tx);
530
+ if (result.result !== 'valid') {
531
+ const contextStr = context ? ` ${context}` : '';
532
+ this.#log.info(`Tx ${tx.getTxHash()}${contextStr} failed validation: ${result.reason?.join(', ')}`);
533
+ return false;
534
+ }
535
+ return true;
536
+ }
537
+ /** Loads transactions from DB, returning loaded txs and missing hashes */ async #loadTxsFromDb(metas) {
538
+ const loaded = [];
539
+ const missing = [];
540
+ for (const meta of metas){
541
+ const buffer = await this.#txsDB.getAsync(meta.txHash);
542
+ if (!buffer) {
543
+ this.#log.warn(`Tx ${meta.txHash} not found in DB`);
544
+ missing.push(meta.txHash);
545
+ continue;
546
+ }
547
+ loaded.push({
548
+ tx: Tx.fromBuffer(buffer),
549
+ meta
550
+ });
551
+ }
552
+ return {
553
+ loaded,
554
+ missing
555
+ };
556
+ }
557
+ /** Validates a batch of transactions, returning valid and invalid groups */ async #validateTxBatch(txs, context) {
558
+ const valid = [];
559
+ const invalid = [];
560
+ for (const { tx, meta } of txs){
561
+ if (await this.#validateTx(tx, context)) {
562
+ valid.push(meta);
563
+ } else {
564
+ invalid.push(meta.txHash);
565
+ }
566
+ }
567
+ return {
568
+ valid,
569
+ invalid
570
+ };
571
+ }
572
+ /** Loads transactions from DB and validates them */ async #loadAndValidateTxs(metas, context) {
573
+ const { loaded, missing } = await this.#loadTxsFromDb(metas);
574
+ const { valid, invalid } = await this.#validateTxBatch(loaded, context);
575
+ return {
576
+ valid,
577
+ invalid: [
578
+ ...missing,
579
+ ...invalid
580
+ ]
581
+ };
582
+ }
583
+ /**
584
+ * Resolves nullifier conflicts between incoming txs and existing pending txs.
585
+ * Modifies the pending indices during iteration to maintain consistent state
586
+ * for subsequent conflict checks within the same batch.
587
+ */ #applyNullifierConflictResolution(txs) {
588
+ const added = [];
589
+ const toEvict = [];
590
+ for (const meta of txs){
591
+ const conflict = checkNullifierConflict(meta, (nullifier)=>this.#indices.getTxHashByNullifier(nullifier), (txHash)=>this.#indices.getMetadata(txHash));
592
+ if (conflict.shouldIgnore) {
593
+ // Lower priority than existing - don't add, mark for deletion
594
+ toEvict.push(meta.txHash);
595
+ } else {
596
+ // Higher priority - evict existing conflicts
597
+ toEvict.push(...conflict.txHashesToEvict);
598
+ // Remove evicted from indices immediately for subsequent checks
599
+ for (const evictHash of conflict.txHashesToEvict){
600
+ const evictMeta = this.#indices.getMetadata(evictHash);
601
+ if (evictMeta) {
602
+ this.#indices.removeFromPendingIndices(evictMeta);
603
+ }
604
+ }
605
+ // Add to pending indices immediately so subsequent txs in the batch see this tx
606
+ this.#indices.addToPendingIndices(meta);
607
+ added.push(meta);
608
+ }
609
+ }
610
+ return {
611
+ added,
612
+ toEvict
613
+ };
614
+ }
615
+ // ============================================================================
616
+ // PRIVATE HELPERS - Block & Hydration
617
+ // ============================================================================
618
+ async #buildBlockId(block) {
619
+ return {
620
+ number: block.globalVariables.blockNumber,
621
+ hash: (await block.hash()).toString()
622
+ };
623
+ }
624
+ /** Checks if a tx is already mined and returns its block ID if so */ async #getMinedBlockId(txHash) {
625
+ const txEffect = await this.#l2BlockSource.getTxEffect(txHash);
626
+ if (!txEffect) {
627
+ return undefined;
628
+ }
629
+ return {
630
+ number: txEffect.l2BlockNumber,
631
+ hash: txEffect.l2BlockHash.toString()
632
+ };
633
+ }
634
+ /** Loads all transactions from the database, returning loaded txs and deserialization errors */ async #loadAllTxsFromDb() {
635
+ const loaded = [];
636
+ const errors = [];
637
+ for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()){
638
+ try {
639
+ const tx = Tx.fromBuffer(buffer);
640
+ const meta = await buildTxMetaData(tx);
641
+ loaded.push({
642
+ tx,
643
+ meta
644
+ });
645
+ } catch (err) {
646
+ this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, {
647
+ err
648
+ });
649
+ errors.push(txHashStr);
650
+ }
651
+ }
652
+ return {
653
+ loaded,
654
+ errors
655
+ };
656
+ }
657
+ /** Queries block source and marks mined status on transaction metadata */ async #markMinedStatusBatch(metas) {
658
+ for (const meta of metas){
659
+ try {
660
+ const txEffect = await this.#l2BlockSource.getTxEffect(TxHash.fromString(meta.txHash));
661
+ if (txEffect) {
662
+ meta.minedL2BlockId = {
663
+ number: txEffect.l2BlockNumber,
664
+ hash: txEffect.l2BlockHash.toString()
665
+ };
666
+ }
667
+ } catch (err) {
668
+ this.#log.warn(`Failed to check mined status for tx ${meta.txHash}`, {
669
+ err
670
+ });
671
+ }
672
+ }
673
+ }
674
+ /**
675
+ * Rebuilds the pending pool by processing each tx through pre-add rules.
676
+ * Starts with an empty pending pool and adds txs one by one, resolving conflicts.
677
+ * Returns the list of accepted and rejected tx hashes.
678
+ */ async #rebuildPendingPool(metas) {
679
+ const accepted = new Set();
680
+ const rejected = [];
681
+ const poolAccess = this.#createPreAddPoolAccess();
682
+ for (const meta of metas){
683
+ // Run pre-add rules against current pending pool state (metadata not yet in pool)
684
+ const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
685
+ if (preAddResult.shouldIgnore) {
686
+ // Transaction rejected - mark for deletion from DB
687
+ rejected.push(meta.txHash);
688
+ this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
689
+ continue;
690
+ }
691
+ // Evict any conflicting txs identified by pre-add rules
692
+ for (const evictHashStr of preAddResult.txHashesToEvict){
693
+ const evictMeta = this.#indices.getMetadata(evictHashStr);
694
+ if (evictMeta) {
695
+ this.#indices.removeFromPendingIndices(evictMeta);
696
+ this.#indices.remove(evictHashStr);
697
+ rejected.push(evictHashStr);
698
+ accepted.delete(evictHashStr);
699
+ this.#log.debug(`Evicted tx ${evictHashStr} during rebuild due to conflict with ${meta.txHash}`);
700
+ }
701
+ }
702
+ // Add to indices
703
+ this.#indices.addPending(meta);
704
+ accepted.add(meta.txHash);
705
+ }
706
+ this.#log.info(`Rebuilt pending pool: ${accepted.size} accepted, ${rejected.length} rejected`);
707
+ return {
708
+ accepted: [
709
+ ...accepted
710
+ ],
711
+ rejected
712
+ };
713
+ }
714
+ // ============================================================================
715
+ // PRIVATE HELPERS - Pool Access Adapters
716
+ // ============================================================================
717
+ #createPoolOperations() {
718
+ return {
719
+ getPendingTxs: ()=>this.#indices.getPendingTxs(),
720
+ getPendingFeePayers: ()=>this.#indices.getPendingFeePayers(),
721
+ getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
722
+ getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
723
+ getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
724
+ deleteTxs: (txHashes)=>this.#deleteTxsBatch(txHashes)
725
+ };
726
+ }
727
+ #createPreAddPoolAccess() {
728
+ return {
729
+ getMetadata: (txHashStr)=>{
730
+ const meta = this.#indices.getMetadata(txHashStr);
731
+ if (!meta || this.#indices.getTxState(meta) !== 'pending') {
732
+ return undefined;
733
+ }
734
+ return meta;
735
+ },
736
+ getTxHashByNullifier: (nullifier)=>this.#indices.getTxHashByNullifier(nullifier),
737
+ getFeePayerBalance: async (feePayer)=>{
738
+ const db = this.#worldStateSynchronizer.getCommitted();
739
+ const publicStateSource = new DatabasePublicStateSource(db);
740
+ const balance = await publicStateSource.storageRead(ProtocolContractAddress.FeeJuice, await computeFeePayerBalanceStorageSlot(AztecAddress.fromString(feePayer)));
741
+ return balance.toBigInt();
742
+ },
743
+ getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
744
+ getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
745
+ getLowestPriorityPendingTx: ()=>this.#indices.getLowestPriorityPendingTx()
746
+ };
747
+ }
748
+ }