@aztec/kv-store 0.76.4 → 0.77.0-testnet-ignition.17
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/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -7
- package/dest/indexeddb/array.d.ts +3 -3
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/array.js +44 -36
- package/dest/indexeddb/index.d.ts +1 -1
- package/dest/indexeddb/index.d.ts.map +1 -1
- package/dest/indexeddb/index.js +1 -4
- package/dest/indexeddb/map.d.ts +4 -4
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +72 -43
- package/dest/indexeddb/set.d.ts +4 -4
- package/dest/indexeddb/set.d.ts.map +1 -1
- package/dest/indexeddb/set.js +3 -4
- package/dest/indexeddb/singleton.d.ts +3 -3
- package/dest/indexeddb/singleton.d.ts.map +1 -1
- package/dest/indexeddb/singleton.js +17 -22
- package/dest/indexeddb/store.d.ts +8 -8
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +97 -93
- package/dest/interfaces/array.js +3 -2
- package/dest/interfaces/array_test_suite.d.ts +1 -1
- package/dest/interfaces/array_test_suite.d.ts.map +1 -1
- package/dest/interfaces/array_test_suite.js +29 -25
- package/dest/interfaces/common.d.ts +1 -1
- package/dest/interfaces/common.d.ts.map +1 -1
- package/dest/interfaces/common.js +3 -2
- package/dest/interfaces/counter.d.ts +1 -1
- package/dest/interfaces/counter.d.ts.map +1 -1
- package/dest/interfaces/counter.js +1 -2
- package/dest/interfaces/index.d.ts +1 -1
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/index.js +0 -1
- package/dest/interfaces/map.d.ts +1 -1
- package/dest/interfaces/map.d.ts.map +1 -1
- package/dest/interfaces/map.js +3 -2
- package/dest/interfaces/map_test_suite.d.ts +1 -1
- package/dest/interfaces/map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/map_test_suite.js +87 -42
- package/dest/interfaces/set.d.ts +1 -1
- package/dest/interfaces/set.d.ts.map +1 -1
- package/dest/interfaces/set.js +1 -2
- package/dest/interfaces/set_test_suite.d.ts +1 -1
- package/dest/interfaces/set_test_suite.d.ts.map +1 -1
- package/dest/interfaces/set_test_suite.js +59 -22
- package/dest/interfaces/singleton.js +4 -2
- package/dest/interfaces/singleton_test_suite.d.ts +1 -1
- package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
- package/dest/interfaces/singleton_test_suite.js +7 -10
- package/dest/interfaces/store.d.ts +6 -6
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/interfaces/store.js +1 -2
- package/dest/interfaces/store_test_suite.d.ts +1 -1
- package/dest/interfaces/store_test_suite.d.ts.map +1 -1
- package/dest/interfaces/store_test_suite.js +6 -9
- package/dest/interfaces/utils.d.ts +1 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +12 -15
- package/dest/lmdb/array.d.ts +2 -2
- package/dest/lmdb/array.d.ts.map +1 -1
- package/dest/lmdb/array.js +46 -41
- package/dest/lmdb/counter.d.ts +3 -3
- package/dest/lmdb/counter.d.ts.map +1 -1
- package/dest/lmdb/counter.js +18 -24
- package/dest/lmdb/index.d.ts +1 -1
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +2 -6
- package/dest/lmdb/map.d.ts +3 -3
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/map.js +90 -68
- package/dest/lmdb/set.d.ts +3 -3
- package/dest/lmdb/set.d.ts.map +1 -1
- package/dest/lmdb/set.js +4 -5
- package/dest/lmdb/singleton.d.ts +2 -2
- package/dest/lmdb/singleton.d.ts.map +1 -1
- package/dest/lmdb/singleton.js +13 -14
- package/dest/lmdb/store.d.ts +7 -7
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +125 -134
- package/dest/lmdb-v2/array.d.ts +18 -0
- package/dest/lmdb-v2/array.d.ts.map +1 -0
- package/dest/lmdb-v2/array.js +101 -0
- package/dest/lmdb-v2/factory.d.ts +1 -1
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +30 -21
- package/dest/lmdb-v2/index.js +0 -1
- package/dest/lmdb-v2/map.js +82 -85
- package/dest/lmdb-v2/message.js +6 -7
- package/dest/lmdb-v2/read_transaction.js +65 -53
- package/dest/lmdb-v2/singleton.d.ts +1 -1
- package/dest/lmdb-v2/singleton.d.ts.map +1 -1
- package/dest/lmdb-v2/singleton.js +7 -5
- package/dest/lmdb-v2/store.d.ts +1 -1
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +31 -28
- package/dest/lmdb-v2/utils.d.ts +1 -1
- package/dest/lmdb-v2/utils.d.ts.map +1 -1
- package/dest/lmdb-v2/utils.js +30 -30
- package/dest/lmdb-v2/write_transaction.js +130 -110
- package/dest/stores/index.js +0 -1
- package/dest/stores/l2_tips_store.d.ts +2 -2
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +26 -12
- package/dest/utils.d.ts +3 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +3 -7
- package/package.json +8 -11
- package/src/config.ts +1 -1
- package/src/indexeddb/array.ts +3 -3
- package/src/indexeddb/index.ts +1 -1
- package/src/indexeddb/map.ts +4 -4
- package/src/indexeddb/set.ts +4 -4
- package/src/indexeddb/singleton.ts +3 -3
- package/src/indexeddb/store.ts +8 -8
- package/src/interfaces/array_test_suite.ts +2 -2
- package/src/interfaces/common.ts +1 -1
- package/src/interfaces/counter.ts +1 -1
- package/src/interfaces/index.ts +1 -1
- package/src/interfaces/map.ts +1 -1
- package/src/interfaces/map_test_suite.ts +3 -3
- package/src/interfaces/set.ts +1 -1
- package/src/interfaces/set_test_suite.ts +3 -3
- package/src/interfaces/singleton_test_suite.ts +2 -2
- package/src/interfaces/store.ts +12 -12
- package/src/interfaces/store_test_suite.ts +2 -2
- package/src/interfaces/utils.ts +1 -1
- package/src/lmdb/array.ts +2 -2
- package/src/lmdb/counter.ts +3 -3
- package/src/lmdb/index.ts +1 -1
- package/src/lmdb/map.ts +3 -3
- package/src/lmdb/set.ts +3 -3
- package/src/lmdb/singleton.ts +2 -2
- package/src/lmdb/store.ts +14 -14
- package/src/lmdb-v2/array.ts +115 -0
- package/src/lmdb-v2/factory.ts +9 -5
- package/src/lmdb-v2/map.ts +1 -1
- package/src/lmdb-v2/singleton.ts +1 -1
- package/src/lmdb-v2/store.ts +4 -3
- package/src/lmdb-v2/utils.ts +1 -1
- package/src/stores/l2_tips_store.ts +10 -10
- package/src/utils.ts +4 -4
|
@@ -2,8 +2,8 @@ import { toArray } from '@aztec/foundation/iterable';
|
|
|
2
2
|
|
|
3
3
|
import { expect } from 'chai';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import type { AztecArray, AztecAsyncArray } from './array.js';
|
|
6
|
+
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
7
7
|
import { isSyncStore } from './utils.js';
|
|
8
8
|
|
|
9
9
|
export function describeAztecArray(
|
package/src/interfaces/common.ts
CHANGED
package/src/interfaces/index.ts
CHANGED
package/src/interfaces/map.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { toArray } from '@aztec/foundation/iterable';
|
|
|
2
2
|
|
|
3
3
|
import { expect } from 'chai';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import type { Key, Range } from './common.js';
|
|
6
|
+
import type { AztecAsyncMap, AztecAsyncMultiMap, AztecMap, AztecMultiMap } from './map.js';
|
|
7
|
+
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
8
8
|
import { isSyncStore } from './utils.js';
|
|
9
9
|
|
|
10
10
|
export function describeAztecMap(
|
package/src/interfaces/set.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { toArray } from '@aztec/foundation/iterable';
|
|
|
2
2
|
|
|
3
3
|
import { expect } from 'chai';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import type { Range } from './common.js';
|
|
6
|
+
import type { AztecAsyncSet, AztecSet } from './set.js';
|
|
7
|
+
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
8
8
|
import { isSyncStore } from './utils.js';
|
|
9
9
|
|
|
10
10
|
export function describeAztecSet(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { AztecAsyncSingleton, AztecSingleton } from './singleton.js';
|
|
4
|
+
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
5
5
|
import { isSyncStore } from './utils.js';
|
|
6
6
|
|
|
7
7
|
export function describeAztecSingleton(
|
package/src/interfaces/store.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { AztecArray, AztecAsyncArray } from './array.js';
|
|
2
|
+
import type { Key, StoreSize } from './common.js';
|
|
3
|
+
import type { AztecAsyncCounter, AztecCounter } from './counter.js';
|
|
4
|
+
import type {
|
|
5
|
+
AztecAsyncMap,
|
|
6
|
+
AztecAsyncMultiMap,
|
|
7
|
+
AztecMap,
|
|
8
|
+
AztecMapWithSize,
|
|
9
|
+
AztecMultiMap,
|
|
10
|
+
AztecMultiMapWithSize,
|
|
11
11
|
} from './map.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import type { AztecAsyncSet, AztecSet } from './set.js';
|
|
13
|
+
import type { AztecAsyncSingleton, AztecSingleton } from './singleton.js';
|
|
14
14
|
|
|
15
15
|
/** A key-value store */
|
|
16
16
|
export interface AztecKVStore {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { AztecAsyncSingleton, AztecSingleton } from './singleton.js';
|
|
4
|
+
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
5
5
|
import { isSyncStore } from './utils.js';
|
|
6
6
|
|
|
7
7
|
export function describeAztecStore(
|
package/src/interfaces/utils.ts
CHANGED
package/src/lmdb/array.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Database, Key } from 'lmdb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { AztecArray, AztecAsyncArray } from '../interfaces/array.js';
|
|
4
4
|
import { LmdbAztecSingleton } from './singleton.js';
|
|
5
5
|
|
|
6
6
|
/** The shape of a key that stores a value in an array */
|
package/src/lmdb/counter.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Key as BaseKey, Database } from 'lmdb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { Key, Range } from '../interfaces/common.js';
|
|
4
|
+
import type { AztecAsyncCounter, AztecCounter } from '../interfaces/counter.js';
|
|
5
5
|
import { LmdbAztecMap } from './map.js';
|
|
6
6
|
|
|
7
7
|
/**
|
package/src/lmdb/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type { DataStoreConfig } from '../config.js';
|
|
6
6
|
import { initStoreForRollup } from '../utils.js';
|
|
7
7
|
import { AztecLmdbStore } from './store.js';
|
|
8
8
|
|
package/src/lmdb/map.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Database, RangeOptions } from 'lmdb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { Key, Range } from '../interfaces/common.js';
|
|
4
|
+
import type { AztecAsyncMultiMap, AztecMapWithSize, AztecMultiMap } from '../interfaces/map.js';
|
|
5
5
|
|
|
6
6
|
/** The slot where a key-value entry would be stored */
|
|
7
7
|
type MapValueSlot<K extends Key | Buffer> = ['map', string, 'slot', K];
|
package/src/lmdb/set.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Database } from 'lmdb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { Key, Range } from '../interfaces/common.js';
|
|
4
|
+
import type { AztecAsyncSet, AztecSet } from '../interfaces/set.js';
|
|
5
5
|
import { LmdbAztecMap } from './map.js';
|
|
6
6
|
|
|
7
7
|
/**
|
package/src/lmdb/singleton.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Database, Key } from 'lmdb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { AztecAsyncSingleton, AztecSingleton } from '../interfaces/singleton.js';
|
|
4
4
|
|
|
5
5
|
/** The slot where this singleton will store its value */
|
|
6
6
|
type ValueSlot = ['singleton', string, 'value'];
|
package/src/lmdb/store.ts
CHANGED
|
@@ -6,20 +6,20 @@ import { type Database, type RootDatabase, open } from 'lmdb';
|
|
|
6
6
|
import { tmpdir } from 'os';
|
|
7
7
|
import { join } from 'path';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
import type { AztecArray, AztecAsyncArray } from '../interfaces/array.js';
|
|
10
|
+
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
11
|
+
import type { AztecAsyncCounter, AztecCounter } from '../interfaces/counter.js';
|
|
12
|
+
import type {
|
|
13
|
+
AztecAsyncMap,
|
|
14
|
+
AztecAsyncMultiMap,
|
|
15
|
+
AztecMap,
|
|
16
|
+
AztecMapWithSize,
|
|
17
|
+
AztecMultiMap,
|
|
18
|
+
AztecMultiMapWithSize,
|
|
19
19
|
} from '../interfaces/map.js';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
20
|
+
import type { AztecAsyncSet, AztecSet } from '../interfaces/set.js';
|
|
21
|
+
import type { AztecAsyncSingleton, AztecSingleton } from '../interfaces/singleton.js';
|
|
22
|
+
import type { AztecAsyncKVStore, AztecKVStore } from '../interfaces/store.js';
|
|
23
23
|
import { LmdbAztecArray } from './array.js';
|
|
24
24
|
import { LmdbAztecCounter } from './counter.js';
|
|
25
25
|
import { LmdbAztecMap, LmdbAztecMapWithSize } from './map.js';
|
|
@@ -211,7 +211,7 @@ export class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
211
211
|
await this.drop();
|
|
212
212
|
await this.close();
|
|
213
213
|
if (this.path) {
|
|
214
|
-
await fs.rm(this.path, { recursive: true, force: true });
|
|
214
|
+
await fs.rm(this.path, { recursive: true, force: true, maxRetries: 3 });
|
|
215
215
|
this.#log.verbose(`Deleted database files at ${this.path}`);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Encoder } from 'msgpackr/pack';
|
|
2
|
+
|
|
3
|
+
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
4
|
+
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
5
|
+
import type { ReadTransaction } from './read_transaction.js';
|
|
6
|
+
import { AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
7
|
+
import { deserializeKey, serializeKey } from './utils.js';
|
|
8
|
+
|
|
9
|
+
export class LMDBArray<T> implements AztecAsyncArray<T> {
|
|
10
|
+
private length: AztecAsyncSingleton<number>;
|
|
11
|
+
private encoder = new Encoder();
|
|
12
|
+
private prefix: string;
|
|
13
|
+
|
|
14
|
+
constructor(private store: AztecLMDBStoreV2, name: string) {
|
|
15
|
+
this.length = store.openSingleton(name + ':length');
|
|
16
|
+
this.prefix = `array:${name}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pop(): Promise<T | undefined> {
|
|
20
|
+
return execInWriteTx(this.store, async tx => {
|
|
21
|
+
const length = await this.lengthAsync();
|
|
22
|
+
if (length === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const val = await tx.get(serializeKey(this.prefix, length - 1));
|
|
27
|
+
await tx.remove(serializeKey(this.prefix, length - 1));
|
|
28
|
+
|
|
29
|
+
await this.length.set(length - 1);
|
|
30
|
+
|
|
31
|
+
return val ? this.encoder.unpack(val) : undefined;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
push(...vals: T[]): Promise<number> {
|
|
36
|
+
return execInWriteTx(this.store, async tx => {
|
|
37
|
+
let length = await this.lengthAsync();
|
|
38
|
+
for (const val of vals) {
|
|
39
|
+
await tx.set(serializeKey(this.prefix, length++), this.encoder.pack(val));
|
|
40
|
+
}
|
|
41
|
+
await this.length.set(length);
|
|
42
|
+
return length;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setAt(index: number, val: T): Promise<boolean> {
|
|
47
|
+
return execInWriteTx(this.store, async tx => {
|
|
48
|
+
const length = await this.lengthAsync();
|
|
49
|
+
if (index < 0) {
|
|
50
|
+
index += length;
|
|
51
|
+
}
|
|
52
|
+
if (index < 0 || index >= length) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
await tx.set(serializeKey(this.prefix, index), this.encoder.pack(val));
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
atAsync(index: number): Promise<T | undefined> {
|
|
61
|
+
return execInReadTx(this.store, async tx => {
|
|
62
|
+
const length = await this.lengthAsync();
|
|
63
|
+
if (index < 0) {
|
|
64
|
+
index += length;
|
|
65
|
+
}
|
|
66
|
+
if (index < 0 || index >= length) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const val = await tx.get(serializeKey(this.prefix, index));
|
|
71
|
+
return val ? this.encoder.unpack(val) : undefined;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async lengthAsync(): Promise<number> {
|
|
76
|
+
return (await this.length.getAsync()) ?? 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async *entriesAsync(): AsyncIterableIterator<[number, T]> {
|
|
80
|
+
// pin array length so that pushes don't affect iteration
|
|
81
|
+
const length = await this.lengthAsync();
|
|
82
|
+
if (length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let tx: ReadTransaction | undefined = this.store.getCurrentWriteTx();
|
|
87
|
+
const shouldClose = !tx;
|
|
88
|
+
tx ??= this.store.getReadTx();
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
for await (const [key, val] of tx.iterate(serializeKey(this.prefix, 0), undefined, false, length)) {
|
|
92
|
+
const deserializedKey = deserializeKey<number>(this.prefix, key);
|
|
93
|
+
// if pops happened while iterating we may have read too much. Terminate early
|
|
94
|
+
if (deserializedKey === false) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
yield [deserializedKey, this.encoder.unpack(val)];
|
|
98
|
+
}
|
|
99
|
+
} finally {
|
|
100
|
+
if (shouldClose) {
|
|
101
|
+
tx.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async *valuesAsync(): AsyncIterableIterator<T> {
|
|
107
|
+
for await (const [_, value] of this.entriesAsync()) {
|
|
108
|
+
yield value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T> {
|
|
113
|
+
return this.valuesAsync();
|
|
114
|
+
}
|
|
115
|
+
}
|
package/src/lmdb-v2/factory.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
|
|
4
4
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'fs/promises';
|
|
5
5
|
import { tmpdir } from 'os';
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import type { DataStoreConfig } from '../config.js';
|
|
9
9
|
import { AztecLMDBStoreV2 } from './store.js';
|
|
10
10
|
|
|
11
11
|
const ROLLUP_ADDRESS_FILE = 'rollup_address';
|
|
@@ -36,7 +36,7 @@ export async function createStore(
|
|
|
36
36
|
found: localRollupAddress,
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
await rm(subDir, { recursive: true, force: true });
|
|
39
|
+
await rm(subDir, { recursive: true, force: true, maxRetries: 3 });
|
|
40
40
|
await mkdir(subDir, { recursive: true });
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -68,8 +68,12 @@ export async function openTmpStore(
|
|
|
68
68
|
// pass a cleanup callback because process.on('beforeExit', cleanup) does not work under Jest
|
|
69
69
|
const cleanup = async () => {
|
|
70
70
|
if (ephemeral) {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
try {
|
|
72
|
+
await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
|
|
73
|
+
log.debug(`Deleted temporary data store: ${dataDir}`);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
log.warn(`Failed to delete temporary data directory (LMDB v2) ${dataDir}: ${err}`);
|
|
76
|
+
}
|
|
73
77
|
} else {
|
|
74
78
|
log.debug(`Leaving temporary data store: ${dataDir}`);
|
|
75
79
|
}
|
package/src/lmdb-v2/map.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Encoder } from 'msgpackr';
|
|
|
2
2
|
|
|
3
3
|
import type { Key, Range } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncMap, AztecAsyncMultiMap } from '../interfaces/map.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { ReadTransaction } from './read_transaction.js';
|
|
6
6
|
import { type AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
7
7
|
import { deserializeKey, maxKey, minKey, serializeKey } from './utils.js';
|
|
8
8
|
|
package/src/lmdb-v2/singleton.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Encoder } from 'msgpackr';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
4
4
|
import { type AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
5
5
|
import { serializeKey } from './utils.js';
|
|
6
6
|
|
package/src/lmdb-v2/store.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { AztecAsyncMap, AztecAsyncMultiMap } from '../interfaces/map.js';
|
|
|
12
12
|
import type { AztecAsyncSet } from '../interfaces/set.js';
|
|
13
13
|
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
14
14
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
15
|
+
import { LMDBArray } from './array.js';
|
|
15
16
|
import { LMDBMap, LMDBMultiMap } from './map.js';
|
|
16
17
|
import {
|
|
17
18
|
Database,
|
|
@@ -103,8 +104,8 @@ export class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageChannel {
|
|
|
103
104
|
return new LMDBSingleValue(this, name);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
openArray<T>(
|
|
107
|
-
|
|
107
|
+
openArray<T>(name: string): AztecAsyncArray<T> {
|
|
108
|
+
return new LMDBArray(this, name);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
openSet<K extends Key>(_name: string): AztecAsyncSet<K> {
|
|
@@ -155,7 +156,7 @@ export class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageChannel {
|
|
|
155
156
|
|
|
156
157
|
async delete(): Promise<void> {
|
|
157
158
|
await this.close();
|
|
158
|
-
await rm(this.dataDir, { recursive: true, force: true });
|
|
159
|
+
await rm(this.dataDir, { recursive: true, force: true, maxRetries: 3 });
|
|
159
160
|
this.log.verbose(`Deleted database files at ${this.dataDir}`);
|
|
160
161
|
await this.cleanup?.();
|
|
161
162
|
}
|
package/src/lmdb-v2/utils.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@aztec/
|
|
1
|
+
import type {
|
|
2
|
+
L2BlockId,
|
|
3
|
+
L2BlockStreamEvent,
|
|
4
|
+
L2BlockStreamEventHandler,
|
|
5
|
+
L2BlockStreamLocalDataProvider,
|
|
6
|
+
L2BlockTag,
|
|
7
|
+
L2Tips,
|
|
8
|
+
} from '@aztec/stdlib/block';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
11
|
+
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
12
12
|
|
|
13
13
|
/** Stores currently synced L2 tips and unfinalized block hashes. */
|
|
14
14
|
export class L2TipsStore implements L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider {
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { AztecAsyncSingleton, AztecSingleton } from './interfaces/singleton.js';
|
|
5
|
+
import type { AztecAsyncKVStore, AztecKVStore } from './interfaces/store.js';
|
|
6
6
|
import { isSyncStore } from './interfaces/utils.js';
|
|
7
7
|
|
|
8
8
|
/**
|