@@ -207,14 +207,14 @@ export class AztecKVTxPool implements TxPool {
207
207
/**
208
208
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
209
209
* @param txHashes - An array of tx hashes to be removed from the tx pool.
210
- * @returns The number of transactions that was deleted from the pool .
210
+ * @returns Empty promise .
211
211
*/
212
212
public deleteTxs ( txHashes : TxHash [ ] ) : Promise < void > {
213
213
let pendingDeleted = 0 ;
214
214
let minedDeleted = 0 ;
215
215
216
- const archiveTxs : Promise < void > [ ] = [ ] ;
217
- const poolTxs = this . #store. transaction ( ( ) => {
216
+ const deletedTxs : Tx [ ] = [ ] ;
217
+ const poolDbTx = this . #store. transaction ( ( ) => {
218
218
for ( const hash of txHashes ) {
219
219
const key = hash . toString ( ) ;
220
220
const tx = this . getTxByHash ( hash ) ;
@@ -231,7 +231,7 @@ export class AztecKVTxPool implements TxPool {
231
231
}
232
232
233
233
if ( this . #archivedTxLimit) {
234
- archiveTxs . push ( this . archiveTx ( tx ) ) ;
234
+ deletedTxs . push ( tx ) ;
235
235
}
236
236
237
237
void this . #txs. delete ( key ) ;
@@ -243,12 +243,7 @@ export class AztecKVTxPool implements TxPool {
243
243
this . #metrics. recordRemovedObjects ( minedDeleted , 'mined' ) ;
244
244
} ) ;
245
245
246
- return poolTxs . then ( ( ) =>
247
- archiveTxs . reduce (
248
- ( archiveTx , remainingArchiveTxs ) => archiveTx . then ( ( ) => remainingArchiveTxs ) ,
249
- Promise . resolve ( ) ,
250
- ) ,
251
- ) ;
246
+ return this . #archivedTxLimit ? poolDbTx . then ( ( ) => this . archiveTxs ( deletedTxs ) ) : poolDbTx ;
252
247
}
253
248
254
249
/**
@@ -272,35 +267,41 @@ export class AztecKVTxPool implements TxPool {
272
267
}
273
268
274
269
/**
275
- * Archives a tx for future reference. The number of archived txs is limited by the specified archivedTxLimit.
276
- * @param tx - The transaction to archive.
270
+ * Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
271
+ * @param txs - The list of transactions to archive.
272
+ * @returns Empty promise.
277
273
*/
278
- private archiveTx ( tx : Tx ) : Promise < void > {
274
+ private archiveTxs ( txs : Tx [ ] ) : Promise < void > {
279
275
return this . #archive. transaction ( ( ) => {
280
276
let headIdx = this . #archivedTxHead. get ( ) ?? 0 ;
281
277
let tailIdx = this . #archivedTxTail. get ( ) ?? 0 ;
282
278
283
- while ( headIdx - tailIdx >= this . #archivedTxLimit) {
284
- const txHash = this . #archivedTxIndices. get ( tailIdx ) ;
285
- if ( txHash ) {
286
- void this . #archivedTxs. delete ( txHash ) ;
287
- void this . #archivedTxIndices. delete ( tailIdx ) ;
279
+ for ( const tx of txs ) {
280
+ while ( headIdx - tailIdx >= this . #archivedTxLimit) {
281
+ const txHash = this . #archivedTxIndices. get ( tailIdx ) ;
282
+ if ( txHash ) {
283
+ void this . #archivedTxs. delete ( txHash ) ;
284
+ void this . #archivedTxIndices. delete ( tailIdx ) ;
285
+ }
286
+ tailIdx ++ ;
288
287
}
289
- void this . #archivedTxTail. set ( ++ tailIdx ) ;
288
+
289
+ const archivedTx : Tx = new Tx (
290
+ tx . data ,
291
+ ClientIvcProof . empty ( ) ,
292
+ tx . unencryptedLogs ,
293
+ tx . contractClassLogs ,
294
+ tx . enqueuedPublicFunctionCalls ,
295
+ tx . publicTeardownFunctionCall ,
296
+ ) ;
297
+ const txHash = tx . getTxHash ( ) . toString ( ) ;
298
+ void this . #archivedTxs. set ( txHash , archivedTx . toBuffer ( ) ) ;
299
+ void this . #archivedTxIndices. set ( headIdx , txHash ) ;
300
+ headIdx ++ ;
290
301
}
291
302
292
- const archivedTx : Tx = new Tx (
293
- tx . data ,
294
- ClientIvcProof . empty ( ) ,
295
- tx . unencryptedLogs ,
296
- tx . contractClassLogs ,
297
- tx . enqueuedPublicFunctionCalls ,
298
- tx . publicTeardownFunctionCall ,
299
- ) ;
300
- const txHash = tx . getTxHash ( ) . toString ( ) ;
301
- void this . #archivedTxs. set ( txHash , archivedTx . toBuffer ( ) ) ;
302
- void this . #archivedTxIndices. set ( headIdx , txHash ) ;
303
- void this . #archivedTxHead. set ( ++ headIdx ) ;
303
+ void this . #archivedTxHead. set ( headIdx ) ;
304
+ void this . #archivedTxTail. set ( tailIdx ) ;
304
305
} ) ;
305
306
}
306
307
}
0 commit comments