@@ -2,7 +2,7 @@ import { Tx, TxHash } from '@aztec/circuit-types';
2
2
import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats' ;
3
3
import { ClientIvcProof } from '@aztec/circuits.js' ;
4
4
import { type Logger , createLogger } from '@aztec/foundation/log' ;
5
- import { type AztecKVStore , type AztecMap , type AztecMultiMap , type AztecSingleton } from '@aztec/kv-store' ;
5
+ import { type AztecKVStore , type AztecMap , type AztecMultiMap } from '@aztec/kv-store' ;
6
6
import { type TelemetryClient , getTelemetryClient } from '@aztec/telemetry-client' ;
7
7
8
8
import { PoolInstrumentation , PoolName } from '../instrumentation.js' ;
@@ -33,12 +33,6 @@ export class AztecKVTxPool implements TxPool {
33
33
/** Indexes of the archived txs by insertion order. */
34
34
#archivedTxIndices: AztecMap < number , string > ;
35
35
36
- /** Index of the most recently inserted archived tx. */
37
- #archivedTxHead: AztecSingleton < number > ;
38
-
39
- /** Index of the oldest archived tx. */
40
- #archivedTxTail: AztecSingleton < number > ;
41
-
42
36
/** Number of txs to archive. */
43
37
#archivedTxLimit: number ;
44
38
@@ -51,6 +45,7 @@ export class AztecKVTxPool implements TxPool {
51
45
* @param store - A KV store for live txs in the pool.
52
46
* @param archive - A KV store for archived txs.
53
47
* @param telemetry - A telemetry client.
48
+ * @param archivedTxLimit - The number of txs to archive.
54
49
* @param log - A logger.
55
50
*/
56
51
constructor (
@@ -66,8 +61,6 @@ export class AztecKVTxPool implements TxPool {
66
61
67
62
this . #archivedTxs = archive . openMap ( 'archivedTxs' ) ;
68
63
this . #archivedTxIndices = archive . openMap ( 'archivedTxIndices' ) ;
69
- this . #archivedTxHead = archive . openSingleton ( 'archivedTxHead' ) ;
70
- this . #archivedTxTail = archive . openSingleton ( 'archivedTxTail' ) ;
71
64
this . #archivedTxLimit = archivedTxLimit ;
72
65
73
66
this . #store = store ;
@@ -273,8 +266,9 @@ export class AztecKVTxPool implements TxPool {
273
266
*/
274
267
private archiveTxs ( txs : Tx [ ] ) : Promise < void > {
275
268
return this . #archive. transaction ( ( ) => {
276
- let headIdx = this . #archivedTxHead. get ( ) ?? 0 ;
277
- let tailIdx = this . #archivedTxTail. get ( ) ?? 0 ;
269
+ // calcualte the head and tail indices of the archived txs by insertion order.
270
+ let headIdx = ( this . #archivedTxIndices. entries ( { limit : 1 , reverse : true } ) . next ( ) . value ?. [ 0 ] ?? - 1 ) + 1 ;
271
+ let tailIdx = this . #archivedTxIndices. entries ( { limit : 1 } ) . next ( ) . value ?. [ 0 ] ?? 0 ;
278
272
279
273
for ( const tx of txs ) {
280
274
while ( headIdx - tailIdx >= this . #archivedTxLimit) {
@@ -299,9 +293,6 @@ export class AztecKVTxPool implements TxPool {
299
293
void this . #archivedTxIndices. set ( headIdx , txHash ) ;
300
294
headIdx ++ ;
301
295
}
302
-
303
- void this . #archivedTxHead. set ( headIdx ) ;
304
- void this . #archivedTxTail. set ( tailIdx ) ;
305
296
} ) ;
306
297
}
307
298
}
0 commit comments