@aztec/p2p 0.0.1-commit.7ac86ea28 → 0.0.1-commit.7b86788
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.
- package/dest/client/factory.d.ts +4 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +15 -26
- package/dest/client/interface.d.ts +6 -13
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +5 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +3 -58
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -2
- package/dest/config.d.ts +2 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +0 -5
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +10 -6
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +26 -4
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +48 -7
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +9 -10
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +173 -146
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/services/dummy_service.d.ts +2 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +1 -4
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -7
- package/dest/services/libp2p/libp2p_service.d.ts +15 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +64 -80
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +14 -37
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -1
- package/dest/services/service.d.ts +2 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +2 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +2 -2
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +5 -5
- package/package.json +14 -14
- package/src/client/factory.ts +22 -46
- package/src/client/interface.ts +5 -19
- package/src/client/p2p_client.ts +4 -88
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -2
- package/src/config.ts +1 -9
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +1 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +2 -2
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +10 -6
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +65 -10
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +11 -11
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +1 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +179 -148
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- package/src/msg_validators/tx_validator/factory.ts +353 -77
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/services/dummy_service.ts +1 -5
- package/src/services/encoding.ts +5 -6
- package/src/services/libp2p/libp2p_service.ts +75 -90
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +14 -42
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/reqresp.ts +3 -1
- package/src/services/service.ts +1 -1
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +0 -2
- package/src/test-helpers/mock-pubsub.ts +3 -6
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +2 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{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EAAE,MAAM,CAAC;KAC5B,CAKA;CAsTF"}
|
|
@@ -128,6 +128,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
128
128
|
const rejected = [];
|
|
129
129
|
const errors = new Map();
|
|
130
130
|
const acceptedPending = new Set();
|
|
131
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
132
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
133
|
+
const precomputed = new Map();
|
|
134
|
+
const validator = await this.#createTxValidator();
|
|
135
|
+
for (const tx of txs){
|
|
136
|
+
const txHash = tx.getTxHash();
|
|
137
|
+
const txHashStr = txHash.toString();
|
|
138
|
+
const meta = await buildTxMetaData(tx);
|
|
139
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
140
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
141
|
+
let isValid = true;
|
|
142
|
+
if (!minedBlockId) {
|
|
143
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
144
|
+
}
|
|
145
|
+
precomputed.set(txHashStr, {
|
|
146
|
+
meta,
|
|
147
|
+
minedBlockId,
|
|
148
|
+
isValid
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
152
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
131
153
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
132
154
|
const preAddContext = opts.feeComparisonOnly !== undefined ? {
|
|
133
155
|
feeComparisonOnly: opts.feeComparisonOnly
|
|
@@ -141,33 +163,41 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
141
163
|
ignored.push(txHash);
|
|
142
164
|
continue;
|
|
143
165
|
}
|
|
144
|
-
|
|
145
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
166
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
|
|
146
167
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
147
168
|
if (minedBlockId) {
|
|
148
169
|
// Already mined - add directly (protection already set if pre-protected)
|
|
149
170
|
await this.#addTx(tx, {
|
|
150
171
|
mined: minedBlockId
|
|
151
|
-
}, opts);
|
|
172
|
+
}, opts, meta);
|
|
152
173
|
accepted.push(txHash);
|
|
153
174
|
} else if (preProtectedSlot !== undefined) {
|
|
154
175
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
155
176
|
await this.#addTx(tx, {
|
|
156
177
|
protected: preProtectedSlot
|
|
157
|
-
}, opts);
|
|
178
|
+
}, opts, meta);
|
|
158
179
|
accepted.push(txHash);
|
|
180
|
+
} else if (!isValid) {
|
|
181
|
+
// Failed pre-computed validation
|
|
182
|
+
rejected.push(txHash);
|
|
159
183
|
} else {
|
|
160
|
-
// Regular pending tx -
|
|
161
|
-
const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
|
|
184
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
185
|
+
const result = await this.#tryAddRegularPendingTx(tx, meta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
|
|
162
186
|
if (result.status === 'accepted') {
|
|
163
187
|
acceptedPending.add(txHashStr);
|
|
164
|
-
} else if (result.status === 'rejected') {
|
|
165
|
-
rejected.push(txHash);
|
|
166
188
|
} else {
|
|
167
189
|
ignored.push(txHash);
|
|
168
190
|
}
|
|
169
191
|
}
|
|
170
192
|
}
|
|
193
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
194
|
+
if (acceptedPending.size > 0) {
|
|
195
|
+
const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
|
|
196
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
197
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
|
|
198
|
+
...uniqueFeePayers
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
171
201
|
});
|
|
172
202
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
173
203
|
for (const txHashStr of acceptedPending){
|
|
@@ -180,14 +210,6 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
180
210
|
if (rejected.length > 0) {
|
|
181
211
|
this.#instrumentation.recordRejected(rejected.length);
|
|
182
212
|
}
|
|
183
|
-
// Run post-add eviction rules for pending txs
|
|
184
|
-
if (acceptedPending.size > 0) {
|
|
185
|
-
const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
|
|
186
|
-
const uniqueFeePayers = new Set(feePayers);
|
|
187
|
-
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
|
|
188
|
-
...uniqueFeePayers
|
|
189
|
-
]);
|
|
190
|
-
}
|
|
191
213
|
return {
|
|
192
214
|
accepted,
|
|
193
215
|
ignored,
|
|
@@ -197,18 +219,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
197
219
|
} : {}
|
|
198
220
|
};
|
|
199
221
|
}
|
|
200
|
-
/**
|
|
201
|
-
const
|
|
202
|
-
const txHashStr = txHash.toString();
|
|
203
|
-
// Build metadata and validate using metadata
|
|
204
|
-
const meta = await buildTxMetaData(tx);
|
|
205
|
-
if (!await this.#validateMeta(meta)) {
|
|
206
|
-
return {
|
|
207
|
-
status: 'rejected'
|
|
208
|
-
};
|
|
209
|
-
}
|
|
222
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */ async #tryAddRegularPendingTx(tx, precomputedMeta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
|
|
223
|
+
const txHashStr = tx.getTxHash().toString();
|
|
210
224
|
// Run pre-add rules
|
|
211
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(
|
|
225
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
212
226
|
if (preAddResult.shouldIgnore) {
|
|
213
227
|
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
214
228
|
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
@@ -246,8 +260,15 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
246
260
|
}
|
|
247
261
|
}
|
|
248
262
|
}
|
|
263
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
264
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
265
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
266
|
+
return {
|
|
267
|
+
status: 'accepted'
|
|
268
|
+
};
|
|
269
|
+
}
|
|
249
270
|
// Add the transaction
|
|
250
|
-
await this.#addTx(tx, 'pending', opts);
|
|
271
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
251
272
|
return {
|
|
252
273
|
status: 'accepted'
|
|
253
274
|
};
|
|
@@ -258,13 +279,8 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
258
279
|
if (this.#indices.has(txHashStr)) {
|
|
259
280
|
return 'ignored';
|
|
260
281
|
}
|
|
261
|
-
// Build metadata and
|
|
282
|
+
// Build metadata and check pre-add rules
|
|
262
283
|
const meta = await buildTxMetaData(tx);
|
|
263
|
-
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
264
|
-
if (validationResult !== true) {
|
|
265
|
-
return 'rejected';
|
|
266
|
-
}
|
|
267
|
-
// Use pre-add rules
|
|
268
284
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
269
285
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
270
286
|
return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
|
|
@@ -305,34 +321,36 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
305
321
|
const missing = [];
|
|
306
322
|
let softDeletedHits = 0;
|
|
307
323
|
let missingPreviouslyEvicted = 0;
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
await this.#store.transactionAsync(async ()=>{
|
|
325
|
+
for (const txHash of txHashes){
|
|
326
|
+
const txHashStr = txHash.toString();
|
|
327
|
+
if (this.#indices.has(txHashStr)) {
|
|
328
|
+
// Update protection for existing tx
|
|
329
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
330
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
331
|
+
// Resurrect soft-deleted tx as protected
|
|
332
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
333
|
+
if (buffer) {
|
|
334
|
+
const tx = Tx.fromBuffer(buffer);
|
|
335
|
+
await this.#addTx(tx, {
|
|
336
|
+
protected: slotNumber
|
|
337
|
+
});
|
|
338
|
+
softDeletedHits++;
|
|
339
|
+
} else {
|
|
340
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
341
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
342
|
+
missing.push(txHash);
|
|
343
|
+
}
|
|
322
344
|
} else {
|
|
323
|
-
//
|
|
345
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
324
346
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
325
347
|
missing.push(txHash);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.#indices.setProtection(txHashStr, slotNumber);
|
|
330
|
-
missing.push(txHash);
|
|
331
|
-
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
332
|
-
missingPreviouslyEvicted++;
|
|
348
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
349
|
+
missingPreviouslyEvicted++;
|
|
350
|
+
}
|
|
333
351
|
}
|
|
334
352
|
}
|
|
335
|
-
}
|
|
353
|
+
});
|
|
336
354
|
// Record metrics
|
|
337
355
|
if (softDeletedHits > 0) {
|
|
338
356
|
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
@@ -383,44 +401,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
383
401
|
found.push(meta);
|
|
384
402
|
}
|
|
385
403
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
404
|
+
await this.#store.transactionAsync(async ()=>{
|
|
405
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
406
|
+
for (const meta of found){
|
|
407
|
+
this.#indices.markAsMined(meta, blockId);
|
|
408
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
409
|
+
}
|
|
410
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
411
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
412
|
+
});
|
|
393
413
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
394
414
|
}
|
|
395
415
|
async prepareForSlot(slotNumber) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
416
|
+
await this.#store.transactionAsync(async ()=>{
|
|
417
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
418
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
419
|
+
// Step 1: Find expired protected txs
|
|
420
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
421
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
422
|
+
this.#indices.clearProtection(expiredProtected);
|
|
423
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
424
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
425
|
+
if (txsToRestore.length === 0) {
|
|
426
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
430
|
+
// Step 4: Validate for pending pool
|
|
431
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
432
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
433
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
434
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
435
|
+
await this.#deleteTxsBatch(invalid);
|
|
436
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
437
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
438
|
+
if (added.length > 0) {
|
|
439
|
+
const feePayers = added.map((meta)=>meta.feePayer);
|
|
440
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
441
|
+
await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
|
|
442
|
+
...uniqueFeePayers
|
|
443
|
+
]);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
424
446
|
}
|
|
425
447
|
async handlePrunedBlocks(latestBlock, options) {
|
|
426
448
|
// Step 1: Find transactions mined after the prune point
|
|
@@ -430,45 +452,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
430
452
|
return;
|
|
431
453
|
}
|
|
432
454
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
455
|
+
await this.#store.transactionAsync(async ()=>{
|
|
456
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
457
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
458
|
+
// when their original mined block is finalized
|
|
459
|
+
await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
|
|
460
|
+
txHash: m.txHash,
|
|
461
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId.number)
|
|
462
|
+
})));
|
|
463
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
464
|
+
for (const meta of txsToUnmine){
|
|
465
|
+
this.#indices.markAsUnmined(meta);
|
|
466
|
+
}
|
|
467
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
468
|
+
if (options?.deleteAllTxs) {
|
|
469
|
+
const allTxHashes = txsToUnmine.map((m)=>m.txHash);
|
|
470
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
471
|
+
this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
475
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
476
|
+
// Step 5: Validate for pending pool
|
|
477
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
478
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
479
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
480
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
481
|
+
await this.#deleteTxsBatch(invalid);
|
|
482
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
483
|
+
this.#log.info(`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`, {
|
|
484
|
+
txHashesRestored: valid.map((m)=>m.txHash),
|
|
485
|
+
txHashesInvalid: invalid,
|
|
486
|
+
txHashesEvicted: toEvict
|
|
487
|
+
});
|
|
488
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
489
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
490
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
464
491
|
});
|
|
465
|
-
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
466
|
-
// This handles cases like existing pending txs with invalid fee payer balances
|
|
467
|
-
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
468
492
|
}
|
|
469
493
|
async handleFailedExecution(txHashes) {
|
|
470
|
-
|
|
471
|
-
|
|
494
|
+
await this.#store.transactionAsync(async ()=>{
|
|
495
|
+
await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
|
|
496
|
+
});
|
|
472
497
|
this.#log.info(`Deleted ${txHashes.length} failed txs`, {
|
|
473
498
|
txHashes: txHashes.map((h)=>h.toString())
|
|
474
499
|
});
|
|
@@ -477,24 +502,26 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
477
502
|
const blockNumber = block.globalVariables.blockNumber;
|
|
478
503
|
// Step 1: Find mined txs at or before finalized block
|
|
479
504
|
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
505
|
+
await this.#store.transactionAsync(async ()=>{
|
|
506
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
507
|
+
const txsToArchive = [];
|
|
508
|
+
if (this.#archive.isEnabled()) {
|
|
509
|
+
for (const txHashStr of minedTxsToFinalize){
|
|
510
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
511
|
+
if (buffer) {
|
|
512
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
513
|
+
}
|
|
487
514
|
}
|
|
488
515
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
516
|
+
// Step 3: Delete mined txs from active pool
|
|
517
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
518
|
+
// Step 4: Finalize soft-deleted txs
|
|
519
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
520
|
+
// Step 5: Archive mined txs
|
|
521
|
+
if (txsToArchive.length > 0) {
|
|
522
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
498
525
|
if (minedTxsToFinalize.length > 0) {
|
|
499
526
|
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
500
527
|
txHashes: minedTxsToFinalize
|
|
@@ -610,9 +637,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
610
637
|
/**
|
|
611
638
|
* Adds a new transaction to the pool with the specified state.
|
|
612
639
|
* Emits onTxsAdded callback immediately after DB write.
|
|
613
|
-
*/ async #addTx(tx, state, opts = {}) {
|
|
640
|
+
*/ async #addTx(tx, state, opts = {}, precomputedMeta) {
|
|
614
641
|
const txHashStr = tx.getTxHash().toString();
|
|
615
|
-
const meta = await buildTxMetaData(tx);
|
|
642
|
+
const meta = precomputedMeta ?? await buildTxMetaData(tx);
|
|
616
643
|
meta.receivedAt = this.#dateProvider.now();
|
|
617
644
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
618
645
|
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TxValidationResult, TxValidator } from '@aztec/stdlib/tx';
|
|
2
2
|
export declare class AggregateTxValidator<T> implements TxValidator<T> {
|
|
3
|
-
|
|
3
|
+
readonly validators: TxValidator<T>[];
|
|
4
4
|
constructor(...validators: TxValidator<T>[]);
|
|
5
5
|
validateTx(tx: T): Promise<TxValidationResult>;
|
|
6
6
|
}
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdncmVnYXRlX3R4X3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL3R4X3ZhbGlkYXRvci9hZ2dyZWdhdGVfdHhfdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLFdBQVcsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXhFLHFCQUFhLG9CQUFvQixDQUFDLENBQUMsQ0FBRSxZQUFXLFdBQVcsQ0FBQyxDQUFDLENBQUM7SUFDNUQsUUFBUSxDQUFDLFVBQVUsRUFBRSxXQUFXLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQztJQUN0QyxZQUFZLEdBQUcsVUFBVSxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUMsRUFBRSxFQU0xQztJQUVLLFVBQVUsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQWtCbkQ7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate_tx_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/aggregate_tx_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,oBAAoB,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"aggregate_tx_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/aggregate_tx_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,oBAAoB,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,YAAY,GAAG,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAM1C;IAEK,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkBnD;CACF"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export class AggregateTxValidator {
|
|
2
|
-
|
|
2
|
+
validators;
|
|
3
3
|
constructor(...validators){
|
|
4
4
|
if (validators.length === 0) {
|
|
5
5
|
throw new Error('At least one validator must be provided');
|
|
6
6
|
}
|
|
7
|
-
this
|
|
7
|
+
this.validators = validators;
|
|
8
8
|
}
|
|
9
9
|
async validateTx(tx) {
|
|
10
10
|
const aggregate = {
|
|
11
11
|
result: 'valid',
|
|
12
12
|
reason: []
|
|
13
13
|
};
|
|
14
|
-
for (const validator of this
|
|
14
|
+
for (const validator of this.validators){
|
|
15
15
|
const result = await validator.validateTx(tx);
|
|
16
16
|
if (result.result === 'invalid') {
|
|
17
17
|
aggregate.result = 'invalid';
|