@aztec/kv-store 0.0.1-commit.e61ad554 → 0.0.1-commit.ee80a48
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/indexeddb/array.js +18 -6
- package/dest/indexeddb/index.d.ts +2 -2
- package/dest/indexeddb/index.d.ts.map +1 -1
- package/dest/indexeddb/index.js +3 -6
- package/dest/indexeddb/map.d.ts +2 -2
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +11 -11
- package/dest/indexeddb/multi_map.d.ts +2 -1
- package/dest/indexeddb/multi_map.d.ts.map +1 -1
- package/dest/indexeddb/multi_map.js +15 -0
- package/dest/indexeddb/singleton.js +3 -1
- package/dest/indexeddb/store.d.ts +3 -3
- package/dest/indexeddb/store.d.ts.map +1 -1
- 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 +48 -2
- package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.js +25 -0
- package/dest/interfaces/utils.d.ts +2 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +2 -1
- package/dest/lmdb/index.d.ts +2 -2
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +3 -3
- package/dest/lmdb-v2/factory.d.ts +6 -6
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +14 -10
- package/dest/lmdb-v2/store.d.ts +3 -3
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +2 -1
- package/dest/utils.d.ts +9 -6
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +51 -16
- package/package.json +10 -8
- package/src/indexeddb/array.ts +4 -4
- package/src/indexeddb/index.ts +8 -6
- package/src/indexeddb/map.ts +10 -9
- package/src/indexeddb/multi_map.ts +14 -0
- package/src/indexeddb/singleton.ts +1 -1
- package/src/indexeddb/store.ts +7 -2
- package/src/interfaces/map_test_suite.ts +30 -2
- package/src/interfaces/multi_map_test_suite.ts +32 -0
- package/src/interfaces/utils.ts +1 -0
- package/src/lmdb/index.ts +8 -3
- package/src/lmdb-v2/factory.ts +15 -11
- package/src/lmdb-v2/store.ts +3 -2
- package/src/utils.ts +79 -21
package/dest/lmdb-v2/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type LoggerBindings } from '@aztec/foundation/log';
|
|
2
2
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
3
3
|
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncCounter } from '../interfaces/counter.js';
|
|
@@ -23,7 +23,7 @@ export declare class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageC
|
|
|
23
23
|
private constructor();
|
|
24
24
|
get dataDirectory(): string;
|
|
25
25
|
private start;
|
|
26
|
-
static new(dataDir: string, dbMapSizeKb?: number, maxReaders?: number, cleanup?: () => Promise<void>,
|
|
26
|
+
static new(dataDir: string, dbMapSizeKb?: number, maxReaders?: number, cleanup?: () => Promise<void>, bindings?: LoggerBindings): Promise<AztecLMDBStoreV2>;
|
|
27
27
|
backupTo(dstPath: string, compact?: boolean): Promise<void>;
|
|
28
28
|
getReadTx(): ReadTransaction;
|
|
29
29
|
getCurrentWriteTx(): WriteTransaction | undefined;
|
|
@@ -40,4 +40,4 @@ export declare class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageC
|
|
|
40
40
|
sendMessage<T extends LMDBMessageType>(msgType: T, body: LMDBRequestBody[T]): Promise<LMDBResponseBody[T]>;
|
|
41
41
|
estimateSize(): Promise<StoreSize>;
|
|
42
42
|
}
|
|
43
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
43
|
+
//# sourceMappingURL=data:application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DLENBd0I5QjtJQUVZLFlBQVksSUFBSSxPQUFPLENBQUMsU0FBUyxDQUFDLENBUTlDO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/store.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAOvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,OAAO,EAEL,KAAK,kBAAkB,EACvB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE9D,qBAAa,gBAAiB,YAAW,iBAAiB,EAAE,kBAAkB;IAQ1E,OAAO,CAAC,OAAO;IAGf,OAAO,CAAC,GAAG;IACX,OAAO,CAA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K,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EACzD,QAAQ,EAAE,CAAC,EAAE,EAAE,gBAAgB,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7C,OAAO,CAAC,CAAC,CAAC,CA0BZ;IAED,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAErB;IAEK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAK5B;IAEK,KAAK,kBAQV;IAEY,WAAW,CAAC,CAAC,SAAS,eAAe,EAChD,OAAO,EAAE,CAAC,EACV,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAwB9B;IAEY,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC,CAQ9C;CACF"}
|
package/dest/lmdb-v2/store.js
CHANGED
|
@@ -48,7 +48,8 @@ export class AztecLMDBStoreV2 {
|
|
|
48
48
|
});
|
|
49
49
|
this.open = true;
|
|
50
50
|
}
|
|
51
|
-
static async new(dataDir, dbMapSizeKb = 10 * 1024 * 1024, maxReaders = 16, cleanup,
|
|
51
|
+
static async new(dataDir, dbMapSizeKb = 10 * 1024 * 1024, maxReaders = 16, cleanup, bindings) {
|
|
52
|
+
const log = createLogger('kv-store:lmdb-v2', bindings);
|
|
52
53
|
const db = new AztecLMDBStoreV2(dataDir, dbMapSizeKb, maxReaders, log, cleanup);
|
|
53
54
|
await db.start();
|
|
54
55
|
return db;
|
package/dest/utils.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore, AztecKVStore } from './interfaces/store.js';
|
|
4
4
|
/**
|
|
5
|
-
* Clears the store if the rollup address does not match the one stored in the database.
|
|
6
|
-
*
|
|
5
|
+
* Clears the store if the schema version or rollup address does not match the one stored in the database.
|
|
6
|
+
* Also clears if migrating from an older store format that didn't track schema version.
|
|
7
|
+
* This is to prevent data from being accidentally mixed up between different rollup instances or schema versions.
|
|
7
8
|
* @param store - The store to check
|
|
9
|
+
* @param targetSchemaVersion - The current schema version
|
|
8
10
|
* @param rollupAddress - The ETH address of the rollup contract
|
|
9
|
-
* @
|
|
11
|
+
* @param log - Optional logger
|
|
12
|
+
* @returns The store (cleared if necessary)
|
|
10
13
|
*/
|
|
11
|
-
export declare function
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
export declare function initStoreForRollupAndSchemaVersion<T extends AztecKVStore | AztecAsyncKVStore>(store: T, schemaVersion: number | undefined, rollupAddress: EthAddress | undefined, log?: Logger): Promise<T>;
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFJcEQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsWUFBWSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFHN0U7Ozs7Ozs7OztHQVNHO0FBQ0gsd0JBQXNCLGtDQUFrQyxDQUFDLENBQUMsU0FBUyxZQUFZLEdBQUcsaUJBQWlCLEVBQ2pHLEtBQUssRUFBRSxDQUFDLEVBQ1IsYUFBYSxFQUFFLE1BQU0sR0FBRyxTQUFTLEVBQ2pDLGFBQWEsRUFBRSxVQUFVLEdBQUcsU0FBUyxFQUNyQyxHQUFHLENBQUMsRUFBRSxNQUFNLEdBQ1gsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQXFDWiJ9
|
package/dest/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG7E;;;;;;;;;GASG;AACH,wBAAsB,kCAAkC,CAAC,CAAC,SAAS,YAAY,GAAG,iBAAiB,EACjG,KAAK,EAAE,CAAC,EACR,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,aAAa,EAAE,UAAU,GAAG,SAAS,EACrC,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,CAAC,CAqCZ"}
|
package/dest/utils.js
CHANGED
|
@@ -1,24 +1,59 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { DatabaseVersion } from '@aztec/stdlib/database-version/version';
|
|
1
3
|
import { isSyncStore } from './interfaces/utils.js';
|
|
2
4
|
/**
|
|
3
|
-
* Clears the store if the rollup address does not match the one stored in the database.
|
|
4
|
-
*
|
|
5
|
+
* Clears the store if the schema version or rollup address does not match the one stored in the database.
|
|
6
|
+
* Also clears if migrating from an older store format that didn't track schema version.
|
|
7
|
+
* This is to prevent data from being accidentally mixed up between different rollup instances or schema versions.
|
|
5
8
|
* @param store - The store to check
|
|
9
|
+
* @param targetSchemaVersion - The current schema version
|
|
6
10
|
* @param rollupAddress - The ETH address of the rollup contract
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
* @param log - Optional logger
|
|
12
|
+
* @returns The store (cleared if necessary)
|
|
13
|
+
*/ export async function initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, log) {
|
|
14
|
+
const targetSchemaVersion = schemaVersion ?? 0;
|
|
15
|
+
const targetRollupAddress = rollupAddress ?? EthAddress.ZERO;
|
|
16
|
+
const targetDatabaseVersion = new DatabaseVersion(targetSchemaVersion, targetRollupAddress);
|
|
17
|
+
// DB version: database schema version + rollup address combined)
|
|
18
|
+
const dbVersion = store.openSingleton('dbVersion');
|
|
19
|
+
const storedDatabaseVersion = isSyncStore(store) ? dbVersion.get() : await dbVersion.getAsync();
|
|
20
|
+
// Check if this is an old format store (has rollupAddress singleton but no dbVersion)
|
|
21
|
+
const oldRollupSingleton = store.openSingleton('rollupAddress');
|
|
22
|
+
const hasOldFormat = isSyncStore(store) ? !storedDatabaseVersion && !!oldRollupSingleton.get() : !storedDatabaseVersion && !!await oldRollupSingleton.getAsync();
|
|
23
|
+
if (hasOldFormat || doesStoreNeedToBeCleared(targetDatabaseVersion, storedDatabaseVersion, targetSchemaVersion, targetRollupAddress, log)) {
|
|
24
|
+
if (hasOldFormat) {
|
|
25
|
+
log?.warn('Detected old store format without dbVersion, clearing database');
|
|
26
|
+
}
|
|
20
27
|
await store.clear();
|
|
21
28
|
}
|
|
22
|
-
await
|
|
29
|
+
await dbVersion.set(targetDatabaseVersion.toBuffer().toString('utf-8'));
|
|
23
30
|
return store;
|
|
24
31
|
}
|
|
32
|
+
function doesStoreNeedToBeCleared(targetDatabaseVersion, storedDatabaseVersion, targetSchemaVersion, targetRollupAddress, log) {
|
|
33
|
+
if (storedDatabaseVersion) {
|
|
34
|
+
try {
|
|
35
|
+
const storedVersion = DatabaseVersion.fromBuffer(Buffer.from(storedDatabaseVersion, 'utf-8'));
|
|
36
|
+
const cmp = storedVersion.cmp(targetDatabaseVersion);
|
|
37
|
+
if (cmp === undefined) {
|
|
38
|
+
log?.warn('Rollup address changed, clearing database', {
|
|
39
|
+
stored: storedVersion.rollupAddress.toString(),
|
|
40
|
+
current: targetRollupAddress.toString()
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (cmp !== 0) {
|
|
45
|
+
log?.warn('Schema version changed, clearing database', {
|
|
46
|
+
stored: storedVersion.schemaVersion,
|
|
47
|
+
current: targetSchemaVersion
|
|
48
|
+
});
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
log?.warn('Failed to parse stored version, clearing database', {
|
|
53
|
+
err
|
|
54
|
+
});
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.ee80a48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
18
18
|
"test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
|
|
19
19
|
"test:browser": "wtr --config ./web-test-runner.config.mjs",
|
|
20
|
-
"test": "yarn test:node",
|
|
20
|
+
"test": "yarn test:node && yarn test:browser",
|
|
21
21
|
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
22
22
|
},
|
|
23
23
|
"inherits": [
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"./package.local.json"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aztec/constants": "0.0.1-commit.
|
|
29
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
30
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
31
|
-
"@aztec/native": "0.0.1-commit.
|
|
32
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
28
|
+
"@aztec/constants": "0.0.1-commit.ee80a48",
|
|
29
|
+
"@aztec/ethereum": "0.0.1-commit.ee80a48",
|
|
30
|
+
"@aztec/foundation": "0.0.1-commit.ee80a48",
|
|
31
|
+
"@aztec/native": "0.0.1-commit.ee80a48",
|
|
32
|
+
"@aztec/stdlib": "0.0.1-commit.ee80a48",
|
|
33
33
|
"idb": "^8.0.0",
|
|
34
34
|
"lmdb": "^3.2.0",
|
|
35
35
|
"msgpackr": "^1.11.2",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@types/sinon": "^17.0.3",
|
|
48
48
|
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
49
49
|
"@web/dev-server-esbuild": "^1.0.3",
|
|
50
|
+
"@web/dev-server-import-maps": "^0.2.1",
|
|
50
51
|
"@web/test-runner": "^0.19.0",
|
|
51
52
|
"@web/test-runner-playwright": "^0.11.0",
|
|
52
53
|
"chai": "^5.1.2",
|
|
@@ -56,7 +57,8 @@
|
|
|
56
57
|
"mocha-each": "^2.0.1",
|
|
57
58
|
"sinon": "^19.0.2",
|
|
58
59
|
"ts-node": "^10.9.1",
|
|
59
|
-
"typescript": "^5.3.3"
|
|
60
|
+
"typescript": "^5.3.3",
|
|
61
|
+
"util": "^0.12.5"
|
|
60
62
|
},
|
|
61
63
|
"files": [
|
|
62
64
|
"dest",
|
package/src/indexeddb/array.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T>
|
|
|
32
32
|
return (
|
|
33
33
|
(await this.db
|
|
34
34
|
.index('key')
|
|
35
|
-
.count(IDBKeyRange.bound([this.#container, this.#name], [this.#container, this.#name]))) ?? 0
|
|
35
|
+
.count(IDBKeyRange.bound([this.#container, [this.#name]], [this.#container, [this.#name]]))) ?? 0
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -43,7 +43,7 @@ export class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T>
|
|
|
43
43
|
value: val,
|
|
44
44
|
hash: hash(val),
|
|
45
45
|
container: this.#container,
|
|
46
|
-
key: this.#name,
|
|
46
|
+
key: [this.#name],
|
|
47
47
|
keyCount: length + 1,
|
|
48
48
|
slot: this.#slot(length),
|
|
49
49
|
});
|
|
@@ -91,7 +91,7 @@ export class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T>
|
|
|
91
91
|
value: val,
|
|
92
92
|
hash: hash(val),
|
|
93
93
|
container: this.#container,
|
|
94
|
-
key: this.#name,
|
|
94
|
+
key: [this.#name],
|
|
95
95
|
keyCount: index + 1,
|
|
96
96
|
slot: this.#slot(index),
|
|
97
97
|
});
|
|
@@ -100,7 +100,7 @@ export class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T>
|
|
|
100
100
|
|
|
101
101
|
async *entriesAsync(): AsyncIterableIterator<[number, T]> {
|
|
102
102
|
const index = this.db.index('key');
|
|
103
|
-
const rangeQuery = IDBKeyRange.bound([this.#container, this.#name], [this.#container, this.#name]);
|
|
103
|
+
const rangeQuery = IDBKeyRange.bound([this.#container, [this.#name]], [this.#container, [this.#name]]);
|
|
104
104
|
for await (const cursor of index.iterate(rangeQuery)) {
|
|
105
105
|
yield [cursor.value.keyCount - 1, cursor.value.value] as [number, T];
|
|
106
106
|
}
|
package/src/indexeddb/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
3
|
import type { DataStoreConfig } from '../config.js';
|
|
4
|
-
import {
|
|
4
|
+
import { initStoreForRollupAndSchemaVersion } from '../utils.js';
|
|
5
5
|
import { AztecIndexedDBStore } from './store.js';
|
|
6
6
|
|
|
7
7
|
export { AztecIndexedDBStore } from './store.js';
|
|
8
8
|
|
|
9
|
-
export async function createStore(
|
|
9
|
+
export async function createStore(
|
|
10
|
+
name: string,
|
|
11
|
+
config: DataStoreConfig,
|
|
12
|
+
schemaVersion: number | undefined = undefined,
|
|
13
|
+
log: Logger = createLogger('kv-store'),
|
|
14
|
+
) {
|
|
10
15
|
let { dataDirectory } = config;
|
|
11
16
|
if (typeof dataDirectory !== 'undefined') {
|
|
12
17
|
dataDirectory = `${dataDirectory}/${name}`;
|
|
@@ -18,10 +23,7 @@ export async function createStore(name: string, config: DataStoreConfig, log: Lo
|
|
|
18
23
|
: `Creating ${name} ephemeral data store with map size ${config.dataStoreMapSizeKb} KB`,
|
|
19
24
|
);
|
|
20
25
|
const store = await AztecIndexedDBStore.open(createLogger('kv-store:indexeddb'), dataDirectory ?? '', false);
|
|
21
|
-
|
|
22
|
-
return initStoreForRollup(store, config.l1Contracts.rollupAddress, log);
|
|
23
|
-
}
|
|
24
|
-
return store;
|
|
26
|
+
return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.l1Contracts?.rollupAddress, log);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export function openTmpStore(ephemeral: boolean = false): Promise<AztecIndexedDBStore> {
|
package/src/indexeddb/map.ts
CHANGED
|
@@ -41,7 +41,7 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
|
|
|
41
41
|
|
|
42
42
|
async sizeAsync(): Promise<number> {
|
|
43
43
|
const index = this.db.index('key');
|
|
44
|
-
const rangeQuery = IDBKeyRange.bound([this.container
|
|
44
|
+
const rangeQuery = IDBKeyRange.bound([this.container], [this.container + '\uffff'], true, true);
|
|
45
45
|
return await index.count(rangeQuery);
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -80,9 +80,12 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
|
|
|
80
80
|
|
|
81
81
|
async *entriesAsync(range: Range<K> = {}): AsyncIterableIterator<[K, V]> {
|
|
82
82
|
const index = this.db.index('key');
|
|
83
|
+
const startKey = range.start ? this.normalizeKey(range.start) : [];
|
|
84
|
+
const endKey = range.end ? this.normalizeKey(range.end) : ['\uffff'];
|
|
85
|
+
|
|
83
86
|
const rangeQuery = IDBKeyRange.bound(
|
|
84
|
-
[this.container,
|
|
85
|
-
[this.container,
|
|
87
|
+
[this.container, startKey],
|
|
88
|
+
[this.container, endKey],
|
|
86
89
|
!!range.reverse,
|
|
87
90
|
!range.reverse,
|
|
88
91
|
);
|
|
@@ -108,14 +111,12 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
|
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
#denormalizeKey(key: string): K {
|
|
112
|
-
|
|
113
|
-
return (denormalizedKey.length > 1 ? denormalizedKey : denormalizedKey[0]) as K;
|
|
114
|
+
#denormalizeKey(key: (string | number | Uint8Array)[]): K {
|
|
115
|
+
return (key.length > 1 ? key : key[0]) as K;
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
protected normalizeKey(key: K): string {
|
|
117
|
-
|
|
118
|
-
return (arrayKey as K[]).map((element: K) => (typeof element === 'number' ? `n_${element}` : element)).join(',');
|
|
118
|
+
protected normalizeKey(key: K): (string | number | Uint8Array)[] {
|
|
119
|
+
return Array.isArray(key) ? key : [key];
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
protected slot(key: K, index: number = 0): string {
|
|
@@ -88,4 +88,18 @@ export class IndexedDBAztecMultiMap<K extends Key, V extends Value>
|
|
|
88
88
|
await this.db.delete(fullKey);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
override async delete(key: K): Promise<void> {
|
|
93
|
+
const index = this.db.index('keyCount');
|
|
94
|
+
const rangeQuery = IDBKeyRange.bound(
|
|
95
|
+
[this.container, this.normalizeKey(key), 0],
|
|
96
|
+
[this.container, this.normalizeKey(key), Number.MAX_SAFE_INTEGER],
|
|
97
|
+
false,
|
|
98
|
+
false,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
for await (const cursor of index.iterate(rangeQuery)) {
|
|
102
|
+
await cursor.delete();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
91
105
|
}
|
|
@@ -37,7 +37,7 @@ export class IndexedDBAztecSingleton<T extends Value> implements AztecAsyncSingl
|
|
|
37
37
|
const result = await this.db.put({
|
|
38
38
|
container: this.#container,
|
|
39
39
|
slot: this.#slot,
|
|
40
|
-
key: this.#slot,
|
|
40
|
+
key: [this.#slot],
|
|
41
41
|
keyCount: 1,
|
|
42
42
|
value: val,
|
|
43
43
|
hash: hash(val),
|
package/src/indexeddb/store.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
|
|
|
20
20
|
export type StoredData<V extends Value> = {
|
|
21
21
|
value: V;
|
|
22
22
|
container: string;
|
|
23
|
-
key: string;
|
|
23
|
+
key: (string | number | Uint8Array)[];
|
|
24
24
|
keyCount: number;
|
|
25
25
|
slot: string;
|
|
26
26
|
hash: string;
|
|
@@ -30,7 +30,12 @@ export interface AztecIDBSchema extends DBSchema {
|
|
|
30
30
|
data: {
|
|
31
31
|
value: StoredData<any>;
|
|
32
32
|
key: string;
|
|
33
|
-
indexes: {
|
|
33
|
+
indexes: {
|
|
34
|
+
container: string;
|
|
35
|
+
key: any; // Runtime: (string | number | Uint8Array)[] - idb types don't support arrays
|
|
36
|
+
keyCount: number;
|
|
37
|
+
hash: string;
|
|
38
|
+
};
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
41
|
|
|
@@ -107,6 +107,33 @@ export function describeAztecMap(
|
|
|
107
107
|
expect(await size()).to.equal(1);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
+
it('returns 0 for empty map size', async () => {
|
|
111
|
+
expect(await size()).to.equal(0);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('calculates size correctly across multiple operations', async () => {
|
|
115
|
+
expect(await size()).to.equal(0);
|
|
116
|
+
|
|
117
|
+
// Add items
|
|
118
|
+
await map.set('a', 'value1');
|
|
119
|
+
await map.set('b', 'value2');
|
|
120
|
+
await map.set('c', 'value3');
|
|
121
|
+
expect(await size()).to.equal(3);
|
|
122
|
+
|
|
123
|
+
// Update existing (size should not change)
|
|
124
|
+
await map.set('b', 'updated');
|
|
125
|
+
expect(await size()).to.equal(3);
|
|
126
|
+
|
|
127
|
+
// Delete some
|
|
128
|
+
await map.delete('a');
|
|
129
|
+
expect(await size()).to.equal(2);
|
|
130
|
+
|
|
131
|
+
// Delete all
|
|
132
|
+
await map.delete('b');
|
|
133
|
+
await map.delete('c');
|
|
134
|
+
expect(await size()).to.equal(0);
|
|
135
|
+
});
|
|
136
|
+
|
|
110
137
|
it('should be able to iterate over entries when there are no keys', async () => {
|
|
111
138
|
expect(await entries()).to.deep.equal([]);
|
|
112
139
|
});
|
|
@@ -145,10 +172,11 @@ export function describeAztecMap(
|
|
|
145
172
|
for (const [name, data] of [
|
|
146
173
|
['chars', ['a', 'b', 'c', 'd']],
|
|
147
174
|
['numbers', [1, 2, 3, 4]],
|
|
148
|
-
|
|
149
|
-
// ['negative numbers', [-4, -3, -2, -1]],
|
|
175
|
+
['negative numbers', [-4, -3, -2, -1]],
|
|
150
176
|
['strings', ['aaa', 'bbb', 'ccc', 'ddd']],
|
|
151
177
|
['zero-based numbers', [0, 1, 2, 3]],
|
|
178
|
+
['large numbers', [100, 999, 1000, 1001]],
|
|
179
|
+
['mixed negative and positive', [-1000, -1, 1, 1000]],
|
|
152
180
|
]) {
|
|
153
181
|
it(`supports range queries over ${name} keys`, async () => {
|
|
154
182
|
const [a, b, c, d] = data;
|
|
@@ -104,6 +104,38 @@ export function describeAztecMultiMap(
|
|
|
104
104
|
expect(await size()).to.equal(1);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
it('returns 0 for empty multimap size', async () => {
|
|
108
|
+
expect(await size()).to.equal(0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('calculates size correctly with multiple values per key', async () => {
|
|
112
|
+
expect(await size()).to.equal(0);
|
|
113
|
+
|
|
114
|
+
// Add multiple values for same key
|
|
115
|
+
await multiMap.set('key1', 'value1');
|
|
116
|
+
expect(await size()).to.equal(1);
|
|
117
|
+
await multiMap.set('key1', 'value2');
|
|
118
|
+
expect(await size()).to.equal(2);
|
|
119
|
+
await multiMap.set('key1', 'value3');
|
|
120
|
+
expect(await size()).to.equal(3);
|
|
121
|
+
|
|
122
|
+
// Add values for different key
|
|
123
|
+
await multiMap.set('key2', 'value4');
|
|
124
|
+
expect(await size()).to.equal(4);
|
|
125
|
+
|
|
126
|
+
// Delete one value from key1
|
|
127
|
+
await multiMap.deleteValue('key1', 'value2');
|
|
128
|
+
expect(await size()).to.equal(3);
|
|
129
|
+
|
|
130
|
+
// Delete entire key
|
|
131
|
+
await multiMap.delete('key1');
|
|
132
|
+
expect(await size()).to.equal(1);
|
|
133
|
+
|
|
134
|
+
// Delete last key
|
|
135
|
+
await multiMap.delete('key2');
|
|
136
|
+
expect(await size()).to.equal(0);
|
|
137
|
+
});
|
|
138
|
+
|
|
107
139
|
it('should be able to iterate over entries when there are no keys', async () => {
|
|
108
140
|
expect(await entries()).to.deep.equal([]);
|
|
109
141
|
});
|
package/src/interfaces/utils.ts
CHANGED
package/src/lmdb/index.ts
CHANGED
|
@@ -3,12 +3,17 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
|
|
5
5
|
import type { DataStoreConfig } from '../config.js';
|
|
6
|
-
import {
|
|
6
|
+
import { initStoreForRollupAndSchemaVersion } from '../utils.js';
|
|
7
7
|
import { AztecLmdbStore } from './store.js';
|
|
8
8
|
|
|
9
9
|
export { AztecLmdbStore } from './store.js';
|
|
10
10
|
|
|
11
|
-
export function createStore(
|
|
11
|
+
export function createStore(
|
|
12
|
+
name: string,
|
|
13
|
+
config: DataStoreConfig,
|
|
14
|
+
schemaVersion: number | undefined = undefined,
|
|
15
|
+
log: Logger = createLogger('kv-store'),
|
|
16
|
+
) {
|
|
12
17
|
let { dataDirectory } = config;
|
|
13
18
|
if (typeof dataDirectory !== 'undefined') {
|
|
14
19
|
dataDirectory = join(dataDirectory, name);
|
|
@@ -22,7 +27,7 @@ export function createStore(name: string, config: DataStoreConfig, log: Logger =
|
|
|
22
27
|
|
|
23
28
|
const store = AztecLmdbStore.open(dataDirectory, config.dataStoreMapSizeKb, false);
|
|
24
29
|
if (config.l1Contracts?.rollupAddress) {
|
|
25
|
-
return
|
|
30
|
+
return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.l1Contracts.rollupAddress, log);
|
|
26
31
|
}
|
|
27
32
|
return store;
|
|
28
33
|
}
|
package/src/lmdb-v2/factory.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { type
|
|
3
|
-
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
2
|
+
import { type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
4
4
|
|
|
5
5
|
import { mkdir, mkdtemp, rm } from 'fs/promises';
|
|
6
6
|
import { tmpdir } from 'os';
|
|
@@ -15,8 +15,9 @@ export async function createStore(
|
|
|
15
15
|
name: string,
|
|
16
16
|
schemaVersion: number,
|
|
17
17
|
config: DataStoreConfig,
|
|
18
|
-
|
|
18
|
+
bindings?: LoggerBindings,
|
|
19
19
|
): Promise<AztecLMDBStoreV2> {
|
|
20
|
+
const log = createLogger('kv-store:lmdb-v2:' + name, bindings);
|
|
20
21
|
const { dataDirectory, l1Contracts } = config;
|
|
21
22
|
|
|
22
23
|
let store: AztecLMDBStoreV2;
|
|
@@ -33,7 +34,7 @@ export async function createStore(
|
|
|
33
34
|
rollupAddress,
|
|
34
35
|
dataDirectory: subDir,
|
|
35
36
|
onOpen: dbDirectory =>
|
|
36
|
-
AztecLMDBStoreV2.new(dbDirectory, config.dataStoreMapSizeKb, MAX_READERS, () => Promise.resolve(),
|
|
37
|
+
AztecLMDBStoreV2.new(dbDirectory, config.dataStoreMapSizeKb, MAX_READERS, () => Promise.resolve(), bindings),
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
log.info(
|
|
@@ -41,7 +42,7 @@ export async function createStore(
|
|
|
41
42
|
);
|
|
42
43
|
[store] = await versionManager.open();
|
|
43
44
|
} else {
|
|
44
|
-
store = await openTmpStore(name, true, config.dataStoreMapSizeKb, MAX_READERS,
|
|
45
|
+
store = await openTmpStore(name, true, config.dataStoreMapSizeKb, MAX_READERS, bindings);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
return store;
|
|
@@ -52,8 +53,9 @@ export async function openTmpStore(
|
|
|
52
53
|
ephemeral: boolean = true,
|
|
53
54
|
dbMapSizeKb = 10 * 1_024 * 1_024, // 10GB
|
|
54
55
|
maxReaders = MAX_READERS,
|
|
55
|
-
|
|
56
|
+
bindings?: LoggerBindings,
|
|
56
57
|
): Promise<AztecLMDBStoreV2> {
|
|
58
|
+
const log = createLogger('kv-store:lmdb-v2:' + name, bindings);
|
|
57
59
|
const dataDir = await mkdtemp(join(tmpdir(), name + '-'));
|
|
58
60
|
log.debug(`Created temporary data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
|
|
59
61
|
|
|
@@ -73,17 +75,18 @@ export async function openTmpStore(
|
|
|
73
75
|
|
|
74
76
|
// For temporary stores, we don't need to worry about versioning
|
|
75
77
|
// as they are ephemeral and get cleaned up after use
|
|
76
|
-
return AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, cleanup,
|
|
78
|
+
return AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, cleanup, bindings);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
export async function openStoreAt(
|
|
80
82
|
dataDir: string,
|
|
81
83
|
dbMapSizeKb = 10 * 1_024 * 1_024, // 10GB
|
|
82
84
|
maxReaders = MAX_READERS,
|
|
83
|
-
|
|
85
|
+
bindings?: LoggerBindings,
|
|
84
86
|
): Promise<AztecLMDBStoreV2> {
|
|
87
|
+
const log = createLogger('kv-store:lmdb-v2', bindings);
|
|
85
88
|
log.debug(`Opening data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
|
|
86
|
-
return await AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined,
|
|
89
|
+
return await AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, bindings);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
export async function openVersionedStoreAt(
|
|
@@ -92,14 +95,15 @@ export async function openVersionedStoreAt(
|
|
|
92
95
|
rollupAddress: EthAddress,
|
|
93
96
|
dbMapSizeKb = 10 * 1_024 * 1_024, // 10GB
|
|
94
97
|
maxReaders = MAX_READERS,
|
|
95
|
-
|
|
98
|
+
bindings?: LoggerBindings,
|
|
96
99
|
): Promise<AztecLMDBStoreV2> {
|
|
100
|
+
const log = createLogger('kv-store:lmdb-v2', bindings);
|
|
97
101
|
log.debug(`Opening data store at: ${dataDirectory} with size: ${dbMapSizeKb} KB (LMDB v2)`);
|
|
98
102
|
const [store] = await new DatabaseVersionManager({
|
|
99
103
|
schemaVersion,
|
|
100
104
|
rollupAddress,
|
|
101
105
|
dataDirectory,
|
|
102
|
-
onOpen: dataDir => AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined,
|
|
106
|
+
onOpen: dataDir => AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, bindings),
|
|
103
107
|
}).open();
|
|
104
108
|
return store;
|
|
105
109
|
}
|
package/src/lmdb-v2/store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { Semaphore, SerialQueue } from '@aztec/foundation/queue';
|
|
3
3
|
import { MsgpackChannel, NativeLMDBStore } from '@aztec/native';
|
|
4
4
|
|
|
@@ -75,8 +75,9 @@ export class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageChannel {
|
|
|
75
75
|
dbMapSizeKb: number = 10 * 1024 * 1024,
|
|
76
76
|
maxReaders: number = 16,
|
|
77
77
|
cleanup?: () => Promise<void>,
|
|
78
|
-
|
|
78
|
+
bindings?: LoggerBindings,
|
|
79
79
|
) {
|
|
80
|
+
const log = createLogger('kv-store:lmdb-v2', bindings);
|
|
80
81
|
const db = new AztecLMDBStoreV2(dataDir, dbMapSizeKb, maxReaders, log, cleanup);
|
|
81
82
|
await db.start();
|
|
82
83
|
return db;
|