@aztec/kv-store 0.0.0-test.1 → 0.0.1-commit.001888fc
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.d.ts +3 -2
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/array.js +24 -7
- package/dest/indexeddb/index.d.ts +3 -3
- package/dest/indexeddb/index.d.ts.map +1 -1
- package/dest/indexeddb/index.js +4 -7
- package/dest/indexeddb/map.d.ts +18 -6
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +51 -63
- package/dest/indexeddb/multi_map.d.ts +14 -0
- package/dest/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/indexeddb/multi_map.js +107 -0
- package/dest/indexeddb/set.d.ts +1 -1
- package/dest/indexeddb/set.d.ts.map +1 -1
- package/dest/indexeddb/singleton.d.ts +3 -2
- package/dest/indexeddb/singleton.d.ts.map +1 -1
- package/dest/indexeddb/singleton.js +6 -2
- package/dest/indexeddb/store.d.ts +15 -16
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +51 -46
- package/dest/interfaces/array.d.ts +5 -4
- package/dest/interfaces/array.d.ts.map +1 -1
- package/dest/interfaces/array.js +1 -3
- package/dest/interfaces/array_test_suite.d.ts +1 -1
- package/dest/interfaces/common.d.ts +11 -9
- package/dest/interfaces/common.d.ts.map +1 -1
- package/dest/interfaces/common.js +8 -3
- package/dest/interfaces/counter.d.ts +1 -1
- package/dest/interfaces/index.d.ts +4 -2
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/index.js +2 -0
- package/dest/interfaces/map.d.ts +21 -49
- package/dest/interfaces/map.d.ts.map +1 -1
- package/dest/interfaces/map.js +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 +181 -70
- package/dest/interfaces/multi_map.d.ts +41 -0
- package/dest/interfaces/multi_map.d.ts.map +1 -0
- package/dest/interfaces/multi_map.js +3 -0
- package/dest/interfaces/multi_map_test_suite.d.ts +3 -0
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -0
- package/dest/interfaces/multi_map_test_suite.js +364 -0
- package/dest/interfaces/set.d.ts +1 -1
- package/dest/interfaces/set_test_suite.d.ts +1 -1
- package/dest/interfaces/singleton.d.ts +1 -1
- package/dest/interfaces/singleton_test_suite.d.ts +1 -1
- package/dest/interfaces/store.d.ts +18 -43
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/interfaces/utils.d.ts +3 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +3 -1
- package/dest/lmdb/array.d.ts +3 -2
- package/dest/lmdb/array.d.ts.map +1 -1
- package/dest/lmdb/array.js +4 -2
- package/dest/lmdb/counter.d.ts +1 -1
- package/dest/lmdb/counter.d.ts.map +1 -1
- package/dest/lmdb/index.d.ts +3 -3
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +5 -5
- package/dest/lmdb/map.d.ts +11 -23
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/map.js +15 -81
- package/dest/lmdb/multi_map.d.ts +13 -0
- package/dest/lmdb/multi_map.d.ts.map +1 -0
- package/dest/lmdb/multi_map.js +44 -0
- package/dest/lmdb/set.d.ts +1 -1
- package/dest/lmdb/set.d.ts.map +1 -1
- package/dest/lmdb/singleton.d.ts +1 -1
- package/dest/lmdb/singleton.d.ts.map +1 -1
- package/dest/lmdb/store.d.ts +11 -27
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +24 -40
- package/dest/lmdb-v2/array.d.ts +4 -3
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/array.js +4 -2
- package/dest/lmdb-v2/factory.d.ts +7 -10
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +26 -12
- package/dest/lmdb-v2/index.d.ts +1 -1
- package/dest/lmdb-v2/map.d.ts +12 -45
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/map.js +17 -104
- package/dest/lmdb-v2/message.d.ts +24 -5
- package/dest/lmdb-v2/message.d.ts.map +1 -1
- package/dest/lmdb-v2/message.js +6 -4
- package/dest/lmdb-v2/multi_map.d.ts +52 -0
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -0
- package/dest/lmdb-v2/multi_map.js +123 -0
- package/dest/lmdb-v2/read_transaction.d.ts +3 -1
- package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/read_transaction.js +34 -0
- package/dest/lmdb-v2/set.d.ts +15 -0
- package/dest/lmdb-v2/set.d.ts.map +1 -0
- package/dest/lmdb-v2/set.js +23 -0
- package/dest/lmdb-v2/singleton.d.ts +2 -2
- package/dest/lmdb-v2/singleton.d.ts.map +1 -1
- package/dest/lmdb-v2/singleton.js +1 -1
- package/dest/lmdb-v2/store.d.ts +13 -13
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +19 -29
- package/dest/lmdb-v2/tx-helpers.d.ts +6 -0
- package/dest/lmdb-v2/tx-helpers.d.ts.map +1 -0
- package/dest/lmdb-v2/tx-helpers.js +21 -0
- package/dest/lmdb-v2/utils.d.ts +3 -14
- package/dest/lmdb-v2/utils.d.ts.map +1 -1
- package/dest/lmdb-v2/utils.js +0 -94
- package/dest/lmdb-v2/write_transaction.d.ts +3 -5
- package/dest/lmdb-v2/write_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/write_transaction.js +9 -5
- package/dest/stores/index.d.ts +2 -1
- package/dest/stores/index.d.ts.map +1 -1
- package/dest/stores/index.js +1 -0
- package/dest/stores/l2_tips_store.d.ts +24 -8
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +63 -45
- package/dest/utils.d.ts +9 -6
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +51 -16
- package/package.json +30 -22
- package/src/indexeddb/array.ts +9 -5
- package/src/indexeddb/index.ts +11 -9
- package/src/indexeddb/map.ts +51 -56
- package/src/indexeddb/multi_map.ts +105 -0
- package/src/indexeddb/singleton.ts +5 -2
- package/src/indexeddb/store.ts +77 -60
- package/src/interfaces/array.ts +5 -3
- package/src/interfaces/common.ts +20 -9
- package/src/interfaces/index.ts +3 -1
- package/src/interfaces/map.ts +19 -53
- package/src/interfaces/map_test_suite.ts +101 -44
- package/src/interfaces/multi_map.ts +45 -0
- package/src/interfaces/multi_map_test_suite.ts +374 -0
- package/src/interfaces/store.ts +18 -53
- package/src/interfaces/utils.ts +2 -0
- package/src/lmdb/array.ts +2 -1
- package/src/lmdb/index.ts +12 -7
- package/src/lmdb/map.ts +23 -94
- package/src/lmdb/multi_map.ts +51 -0
- package/src/lmdb/store.ts +36 -56
- package/src/lmdb-v2/array.ts +8 -3
- package/src/lmdb-v2/factory.ts +30 -19
- package/src/lmdb-v2/map.ts +30 -127
- package/src/lmdb-v2/message.ts +23 -0
- package/src/lmdb-v2/multi_map.ts +150 -0
- package/src/lmdb-v2/read_transaction.ts +40 -0
- package/src/lmdb-v2/set.ts +33 -0
- package/src/lmdb-v2/singleton.ts +6 -2
- package/src/lmdb-v2/store.ts +24 -42
- package/src/lmdb-v2/tx-helpers.ts +29 -0
- package/src/lmdb-v2/utils.ts +0 -118
- package/src/lmdb-v2/write_transaction.ts +11 -10
- package/src/stores/index.ts +2 -0
- package/src/stores/l2_tips_store.ts +67 -49
- package/src/utils.ts +79 -21
- package/dest/config.d.ts +0 -17
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -24
- package/dest/interfaces/store_test_suite.d.ts +0 -3
- package/dest/interfaces/store_test_suite.d.ts.map +0 -1
- package/dest/interfaces/store_test_suite.js +0 -37
- package/src/config.ts +0 -34
- package/src/interfaces/store_test_suite.ts +0 -56
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { dedupeSortedArray, findInSortedArray, findIndexInSortedArray, insertIntoSortedArray, merge, removeAnyOf, removeFromSortedArray } from '@aztec/foundation/array';
|
|
1
2
|
import { Database, LMDBMessageType } from './message.js';
|
|
2
3
|
import { ReadTransaction } from './read_transaction.js';
|
|
3
|
-
import {
|
|
4
|
+
import { keyCmp, singleKeyCmp } from './utils.js';
|
|
4
5
|
export class WriteTransaction extends ReadTransaction {
|
|
5
6
|
// exposed for tests
|
|
6
7
|
dataBatch = {
|
|
@@ -35,10 +36,10 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
35
36
|
remove(key) {
|
|
36
37
|
const removeEntryIndex = findIndexInSortedArray(this.dataBatch.removeEntries, key, singleKeyCmp);
|
|
37
38
|
if (removeEntryIndex === -1) {
|
|
38
|
-
this.dataBatch.removeEntries
|
|
39
|
+
insertIntoSortedArray(this.dataBatch.removeEntries, [
|
|
39
40
|
key,
|
|
40
41
|
null
|
|
41
|
-
]);
|
|
42
|
+
], keyCmp);
|
|
42
43
|
}
|
|
43
44
|
const addEntryIndex = findIndexInSortedArray(this.dataBatch.addEntries, key, singleKeyCmp);
|
|
44
45
|
if (addEntryIndex > -1) {
|
|
@@ -155,10 +156,13 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
155
156
|
}
|
|
156
157
|
async *#iterate(iterator, batch, startKey, endKey, reverse = false, limit, merge, map) {
|
|
157
158
|
this.assertIsOpen();
|
|
158
|
-
//
|
|
159
|
+
// Snapshot both add and remove entries at the start of iteration to ensure consistency
|
|
159
160
|
const uncommittedEntries = [
|
|
160
161
|
...batch.addEntries
|
|
161
162
|
];
|
|
163
|
+
const removeEntries = [
|
|
164
|
+
...batch.removeEntries
|
|
165
|
+
];
|
|
162
166
|
// used to check we're in the right order when comparing between a key and uncommittedEntries
|
|
163
167
|
let cmpDirection = -1;
|
|
164
168
|
if (reverse) {
|
|
@@ -198,7 +202,7 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
198
202
|
if (!checkLimit()) {
|
|
199
203
|
break;
|
|
200
204
|
}
|
|
201
|
-
const toRemove = findInSortedArray(
|
|
205
|
+
const toRemove = findInSortedArray(removeEntries, key, singleKeyCmp);
|
|
202
206
|
// at this point we've either exhausted all uncommitted entries,
|
|
203
207
|
// we reached a key strictly greater/smaller than `key`
|
|
204
208
|
// or we found the key itself
|
package/dest/stores/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from './l2_tips_store.js';
|
|
2
|
-
|
|
2
|
+
export { L2TipsMemoryStore, type L2TipsStore } from '@aztec/stdlib/block';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxvQkFBb0IsQ0FBQztBQUVuQyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsS0FBSyxXQUFXLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dest/stores/index.js
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
3
|
+
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
2
4
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
7
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
8
|
+
*/
|
|
9
|
+
export declare class L2TipsKVStore extends L2TipsStoreBase {
|
|
10
|
+
private store;
|
|
5
11
|
private readonly l2TipsStore;
|
|
6
12
|
private readonly l2BlockHashesStore;
|
|
13
|
+
private readonly l2BlockNumberToCheckpointNumberStore;
|
|
14
|
+
private readonly l2CheckpointStore;
|
|
7
15
|
constructor(store: AztecAsyncKVStore, namespace: string);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined>;
|
|
17
|
+
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void>;
|
|
18
|
+
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined>;
|
|
19
|
+
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void>;
|
|
20
|
+
protected deleteBlockHashesBefore(blockNumber: BlockNumber): Promise<void>;
|
|
21
|
+
protected getCheckpointNumberForBlock(blockNumber: BlockNumber): Promise<CheckpointNumber | undefined>;
|
|
22
|
+
protected setCheckpointNumberForBlock(blockNumber: BlockNumber, checkpointNumber: CheckpointNumber): Promise<void>;
|
|
23
|
+
protected deleteBlockToCheckpointBefore(blockNumber: BlockNumber): Promise<void>;
|
|
24
|
+
protected getCheckpoint(checkpointNumber: CheckpointNumber): Promise<PublishedCheckpoint | undefined>;
|
|
25
|
+
protected saveCheckpointData(checkpoint: PublishedCheckpoint): Promise<void>;
|
|
26
|
+
protected deleteCheckpointsBefore(checkpointNumber: CheckpointNumber): Promise<void>;
|
|
27
|
+
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
12
28
|
}
|
|
13
|
-
//# sourceMappingURL=
|
|
29
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3Jlcy9sMl90aXBzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNoRixPQUFPLEVBQUUsS0FBSyxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDdkUsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFHL0QsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUVoRTs7O0dBR0c7QUFDSCxxQkFBYSxhQUFjLFNBQVEsZUFBZTtJQU85QyxPQUFPLENBQUMsS0FBSztJQU5mLE9BQU8sQ0FBQyxRQUFRLENBQUMsV0FBVyxDQUF5QztJQUNyRSxPQUFPLENBQUMsUUFBUSxDQUFDLGtCQUFrQixDQUFxQztJQUN4RSxPQUFPLENBQUMsUUFBUSxDQUFDLG9DQUFvQyxDQUErQztJQUNwRyxPQUFPLENBQUMsUUFBUSxDQUFDLGlCQUFpQixDQUEwQztJQUU1RSxZQUNVLEtBQUssRUFBRSxpQkFBaUIsRUFDaEMsU0FBUyxFQUFFLE1BQU0sRUFTbEI7SUFFRCxTQUFTLENBQUMsTUFBTSxDQUFDLEdBQUcsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsR0FBRyxTQUFTLENBQUMsQ0FFbEU7SUFFRCxTQUFTLENBQUMsTUFBTSxDQUFDLEdBQUcsRUFBRSxVQUFVLEVBQUUsV0FBVyxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRXpFO0lBRUQsU0FBUyxDQUFDLGtCQUFrQixDQUFDLFdBQVcsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUMsQ0FFbEY7SUFFRCxTQUFTLENBQUMsWUFBWSxDQUFDLFdBQVcsRUFBRSxXQUFXLEVBQUUsSUFBSSxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRTVFO0lBRUQsVUFBZ0IsdUJBQXVCLENBQUMsV0FBVyxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBSS9FO0lBRUQsU0FBUyxDQUFDLDJCQUEyQixDQUFDLFdBQVcsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixHQUFHLFNBQVMsQ0FBQyxDQUVyRztJQUVELFNBQVMsQ0FBQywyQkFBMkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxFQUFFLGdCQUFnQixFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFakg7SUFFRCxVQUFnQiw2QkFBNkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FJckY7SUFFRCxVQUFnQixhQUFhLENBQUMsZ0JBQWdCLEVBQUUsZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLG1CQUFtQixHQUFHLFNBQVMsQ0FBQyxDQU0xRztJQUVELFNBQVMsQ0FBQyxrQkFBa0IsQ0FBQyxVQUFVLEVBQUUsbUJBQW1CLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUUzRTtJQUVELFVBQWdCLHVCQUF1QixDQUFDLGdCQUFnQixFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FJekY7SUFFRCxTQUFTLENBQUMsZ0JBQWdCLENBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBRSxNQUFNLE9BQU8sQ0FBQyxDQUFDLENBQUMsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBRTlEO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;GAGG;AACH,qBAAa,aAAc,SAAQ,eAAe;IAO9C,OAAO,CAAC,KAAK;IANf,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyC;IACrE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqC;IACxE,OAAO,CAAC,QAAQ,CAAC,oCAAoC,CAA+C;IACpG,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0C;IAE5E,YACU,KAAK,EAAE,iBAAiB,EAChC,SAAS,EAAE,MAAM,EASlB;IAED,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAElE;IAED,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE;IAED,SAAS,CAAC,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAElF;IAED,SAAS,CAAC,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5E;IAED,UAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/E;IAED,SAAS,CAAC,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAErG;IAED,SAAS,CAAC,2BAA2B,CAAC,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjH;IAED,UAAgB,6BAA6B,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;IAED,UAAgB,aAAa,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAM1G;IAED,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3E;IAED,UAAgB,uBAAuB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAIzF;IAED,SAAS,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE9D;CACF"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
2
|
+
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
3
|
+
/**
|
|
4
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
5
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
6
|
+
*/ export class L2TipsKVStore extends L2TipsStoreBase {
|
|
7
|
+
store;
|
|
2
8
|
l2TipsStore;
|
|
3
9
|
l2BlockHashesStore;
|
|
10
|
+
l2BlockNumberToCheckpointNumberStore;
|
|
11
|
+
l2CheckpointStore;
|
|
4
12
|
constructor(store, namespace){
|
|
13
|
+
super(), this.store = store;
|
|
5
14
|
this.l2TipsStore = store.openMap([
|
|
6
15
|
namespace,
|
|
7
16
|
'l2_tips'
|
|
@@ -10,56 +19,65 @@
|
|
|
10
19
|
namespace,
|
|
11
20
|
'l2_block_hashes'
|
|
12
21
|
].join('_'));
|
|
22
|
+
this.l2BlockNumberToCheckpointNumberStore = store.openMap([
|
|
23
|
+
namespace,
|
|
24
|
+
'l2_block_number_to_checkpoint_number'
|
|
25
|
+
].join('_'));
|
|
26
|
+
this.l2CheckpointStore = store.openMap([
|
|
27
|
+
namespace,
|
|
28
|
+
'l2_checkpoint_store'
|
|
29
|
+
].join('_'));
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
return this.
|
|
31
|
+
getTip(tag) {
|
|
32
|
+
return this.l2TipsStore.getAsync(tag);
|
|
16
33
|
}
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
latest: await this.getL2Tip('latest'),
|
|
20
|
-
finalized: await this.getL2Tip('finalized'),
|
|
21
|
-
proven: await this.getL2Tip('proven')
|
|
22
|
-
};
|
|
34
|
+
setTip(tag, blockNumber) {
|
|
35
|
+
return this.l2TipsStore.set(tag, blockNumber);
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
getStoredBlockHash(blockNumber) {
|
|
38
|
+
return this.l2BlockHashesStore.getAsync(blockNumber);
|
|
39
|
+
}
|
|
40
|
+
setBlockHash(blockNumber, hash) {
|
|
41
|
+
return this.l2BlockHashesStore.set(blockNumber, hash);
|
|
42
|
+
}
|
|
43
|
+
async deleteBlockHashesBefore(blockNumber) {
|
|
44
|
+
for await (const key of this.l2BlockHashesStore.keysAsync({
|
|
45
|
+
end: blockNumber
|
|
46
|
+
})){
|
|
47
|
+
await this.l2BlockHashesStore.delete(key);
|
|
31
48
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
}
|
|
50
|
+
getCheckpointNumberForBlock(blockNumber) {
|
|
51
|
+
return this.l2BlockNumberToCheckpointNumberStore.getAsync(blockNumber);
|
|
52
|
+
}
|
|
53
|
+
setCheckpointNumberForBlock(blockNumber, checkpointNumber) {
|
|
54
|
+
return this.l2BlockNumberToCheckpointNumberStore.set(blockNumber, checkpointNumber);
|
|
55
|
+
}
|
|
56
|
+
async deleteBlockToCheckpointBefore(blockNumber) {
|
|
57
|
+
for await (const key of this.l2BlockNumberToCheckpointNumberStore.keysAsync({
|
|
58
|
+
end: blockNumber
|
|
59
|
+
})){
|
|
60
|
+
await this.l2BlockNumberToCheckpointNumberStore.delete(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async getCheckpoint(checkpointNumber) {
|
|
64
|
+
const buffer = await this.l2CheckpointStore.getAsync(checkpointNumber);
|
|
65
|
+
if (!buffer) {
|
|
66
|
+
return undefined;
|
|
35
67
|
}
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
68
|
+
return PublishedCheckpoint.fromBuffer(buffer);
|
|
69
|
+
}
|
|
70
|
+
saveCheckpointData(checkpoint) {
|
|
71
|
+
return this.l2CheckpointStore.set(checkpoint.checkpoint.number, checkpoint.toBuffer());
|
|
40
72
|
}
|
|
41
|
-
async
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
await this.l2TipsStore.set('latest', event.blocks.at(-1).number);
|
|
48
|
-
break;
|
|
49
|
-
case 'chain-pruned':
|
|
50
|
-
await this.l2TipsStore.set('latest', event.blockNumber);
|
|
51
|
-
break;
|
|
52
|
-
case 'chain-proven':
|
|
53
|
-
await this.l2TipsStore.set('proven', event.blockNumber);
|
|
54
|
-
break;
|
|
55
|
-
case 'chain-finalized':
|
|
56
|
-
await this.l2TipsStore.set('finalized', event.blockNumber);
|
|
57
|
-
for await (const key of this.l2BlockHashesStore.keysAsync({
|
|
58
|
-
end: event.blockNumber
|
|
59
|
-
})){
|
|
60
|
-
await this.l2BlockHashesStore.delete(key);
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
73
|
+
async deleteCheckpointsBefore(checkpointNumber) {
|
|
74
|
+
for await (const key of this.l2CheckpointStore.keysAsync({
|
|
75
|
+
end: checkpointNumber
|
|
76
|
+
})){
|
|
77
|
+
await this.l2CheckpointStore.delete(key);
|
|
63
78
|
}
|
|
64
79
|
}
|
|
80
|
+
runInTransaction(fn) {
|
|
81
|
+
return this.store.transactionAsync(fn);
|
|
82
|
+
}
|
|
65
83
|
}
|
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=
|
|
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,59 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.001888fc",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
7
|
+
"./interfaces": "./dest/interfaces/index.js",
|
|
7
8
|
"./lmdb": "./dest/lmdb/index.js",
|
|
8
9
|
"./lmdb-v2": "./dest/lmdb-v2/index.js",
|
|
9
10
|
"./indexeddb": "./dest/indexeddb/index.js",
|
|
10
|
-
"./stores": "./dest/stores/index.js"
|
|
11
|
-
"./config": "./dest/config.js"
|
|
11
|
+
"./stores": "./dest/stores/index.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "yarn clean && tsc
|
|
15
|
-
"build:dev": "tsc
|
|
14
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
15
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
16
16
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
17
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
18
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
19
17
|
"test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
|
|
20
|
-
"test:browser": "
|
|
21
|
-
"test": "yarn test:node && yarn test:browser
|
|
18
|
+
"test:browser": "vitest run --config ./vitest.config.ts",
|
|
19
|
+
"test": "yarn test:node && yarn test:browser",
|
|
20
|
+
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
22
21
|
},
|
|
23
22
|
"inherits": [
|
|
24
23
|
"../package.common.json",
|
|
25
24
|
"./package.local.json"
|
|
26
25
|
],
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@aztec/
|
|
29
|
-
"@aztec/
|
|
30
|
-
"@aztec/
|
|
31
|
-
"@aztec/
|
|
27
|
+
"@aztec/constants": "0.0.1-commit.001888fc",
|
|
28
|
+
"@aztec/ethereum": "0.0.1-commit.001888fc",
|
|
29
|
+
"@aztec/foundation": "0.0.1-commit.001888fc",
|
|
30
|
+
"@aztec/native": "0.0.1-commit.001888fc",
|
|
31
|
+
"@aztec/stdlib": "0.0.1-commit.001888fc",
|
|
32
32
|
"idb": "^8.0.0",
|
|
33
33
|
"lmdb": "^3.2.0",
|
|
34
34
|
"msgpackr": "^1.11.2",
|
|
35
|
+
"ohash": "^2.0.11",
|
|
35
36
|
"ordered-binary": "^1.5.3"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@jest/globals": "^
|
|
39
|
+
"@jest/globals": "^30.0.0",
|
|
39
40
|
"@types/chai": "^5.0.1",
|
|
40
41
|
"@types/chai-as-promised": "^8.0.1",
|
|
41
|
-
"@types/jest": "^
|
|
42
|
+
"@types/jest": "^30.0.0",
|
|
42
43
|
"@types/mocha": "^10.0.10",
|
|
43
44
|
"@types/mocha-each": "^2.0.4",
|
|
44
|
-
"@types/node": "^
|
|
45
|
+
"@types/node": "^22.15.17",
|
|
45
46
|
"@types/sinon": "^17.0.3",
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
47
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
48
|
+
"@vitest/browser-playwright": "^4.0.0",
|
|
49
|
+
"buffer": "^6.0.3",
|
|
49
50
|
"chai": "^5.1.2",
|
|
50
51
|
"chai-as-promised": "^8.0.1",
|
|
51
|
-
"jest": "^
|
|
52
|
+
"jest": "^30.0.0",
|
|
52
53
|
"mocha": "^10.8.2",
|
|
53
54
|
"mocha-each": "^2.0.1",
|
|
55
|
+
"playwright": "1.49.0",
|
|
54
56
|
"sinon": "^19.0.2",
|
|
55
57
|
"ts-node": "^10.9.1",
|
|
56
|
-
"typescript": "^5.
|
|
58
|
+
"typescript": "^5.3.3",
|
|
59
|
+
"util": "^0.12.5",
|
|
60
|
+
"vitest": "^4.0.0"
|
|
57
61
|
},
|
|
58
62
|
"files": [
|
|
59
63
|
"dest",
|
|
@@ -61,7 +65,7 @@
|
|
|
61
65
|
"!*.test.*"
|
|
62
66
|
],
|
|
63
67
|
"engines": {
|
|
64
|
-
"node": ">=
|
|
68
|
+
"node": ">=20.10"
|
|
65
69
|
},
|
|
66
70
|
"jest": {
|
|
67
71
|
"extensionsToTreatAsEsm": [
|
|
@@ -94,6 +98,10 @@
|
|
|
94
98
|
"testTimeout": 120000,
|
|
95
99
|
"setupFiles": [
|
|
96
100
|
"../../foundation/src/jest/setup.mjs"
|
|
101
|
+
],
|
|
102
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
103
|
+
"setupFilesAfterEnv": [
|
|
104
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
97
105
|
]
|
|
98
106
|
}
|
|
99
107
|
}
|
package/src/indexeddb/array.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import { hash } from 'ohash';
|
|
2
3
|
|
|
3
4
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
5
|
+
import type { Value } from '../interfaces/common.js';
|
|
4
6
|
import type { AztecIDBSchema } from './store.js';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* A persistent array backed by IndexedDB.
|
|
8
10
|
*/
|
|
9
|
-
export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
11
|
+
export class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T> {
|
|
10
12
|
#_db?: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
11
13
|
#rootDB: IDBPDatabase<AztecIDBSchema>;
|
|
12
14
|
#container: string;
|
|
@@ -30,7 +32,7 @@ export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
|
30
32
|
return (
|
|
31
33
|
(await this.db
|
|
32
34
|
.index('key')
|
|
33
|
-
.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
|
|
34
36
|
);
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -39,8 +41,9 @@ export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
|
39
41
|
for (const val of vals) {
|
|
40
42
|
await this.db.put({
|
|
41
43
|
value: val,
|
|
44
|
+
hash: hash(val),
|
|
42
45
|
container: this.#container,
|
|
43
|
-
key: this.#name,
|
|
46
|
+
key: [this.#name],
|
|
44
47
|
keyCount: length + 1,
|
|
45
48
|
slot: this.#slot(length),
|
|
46
49
|
});
|
|
@@ -86,8 +89,9 @@ export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
|
86
89
|
|
|
87
90
|
await this.db.put({
|
|
88
91
|
value: val,
|
|
92
|
+
hash: hash(val),
|
|
89
93
|
container: this.#container,
|
|
90
|
-
key: this.#name,
|
|
94
|
+
key: [this.#name],
|
|
91
95
|
keyCount: index + 1,
|
|
92
96
|
slot: this.#slot(index),
|
|
93
97
|
});
|
|
@@ -96,7 +100,7 @@ export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
|
96
100
|
|
|
97
101
|
async *entriesAsync(): AsyncIterableIterator<[number, T]> {
|
|
98
102
|
const index = this.db.index('key');
|
|
99
|
-
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]]);
|
|
100
104
|
for await (const cursor of index.iterate(rangeQuery)) {
|
|
101
105
|
yield [cursor.value.keyCount - 1, cursor.value.value] as [number, T];
|
|
102
106
|
}
|
package/src/indexeddb/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
import { initStoreForRollup } from '../utils.js';
|
|
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}`;
|
|
@@ -14,14 +19,11 @@ export async function createStore(name: string, config: DataStoreConfig, log: Lo
|
|
|
14
19
|
|
|
15
20
|
log.info(
|
|
16
21
|
dataDirectory
|
|
17
|
-
? `Creating ${name} data store at directory ${dataDirectory} with map size ${config.
|
|
18
|
-
: `Creating ${name} ephemeral data store with map size ${config.
|
|
22
|
+
? `Creating ${name} data store at directory ${dataDirectory} with map size ${config.dataStoreMapSizeKb} KB`
|
|
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> {
|