@aztec/kv-store 0.0.0-test.1 → 0.0.1-commit.1142ef1
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 +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -3
- package/dest/indexeddb/array.d.ts +3 -2
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/array.js +6 -1
- package/dest/indexeddb/index.d.ts +1 -1
- package/dest/indexeddb/index.js +1 -1
- package/dest/indexeddb/map.d.ts +12 -6
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +38 -60
- package/dest/indexeddb/multi_map.d.ts +13 -0
- package/dest/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/indexeddb/multi_map.js +92 -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 +3 -1
- package/dest/indexeddb/store.d.ts +13 -14
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +45 -42
- 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 +135 -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 +339 -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 +2 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +2 -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 +1 -1
- package/dest/lmdb/index.js +2 -2
- 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 +9 -25
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +12 -32
- 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 +4 -7
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +16 -6
- 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 +11 -11
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +17 -28
- 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 +1 -1
- package/package.json +23 -16
- package/src/config.ts +6 -4
- package/src/indexeddb/array.ts +5 -1
- package/src/indexeddb/index.ts +2 -2
- package/src/indexeddb/map.ts +35 -53
- package/src/indexeddb/multi_map.ts +91 -0
- package/src/indexeddb/singleton.ts +4 -1
- package/src/indexeddb/store.ts +66 -56
- 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 +73 -44
- package/src/interfaces/multi_map.ts +45 -0
- package/src/interfaces/multi_map_test_suite.ts +342 -0
- package/src/interfaces/store.ts +18 -53
- package/src/interfaces/utils.ts +1 -0
- package/src/lmdb/array.ts +2 -1
- package/src/lmdb/index.ts +3 -3
- package/src/lmdb/map.ts +23 -94
- package/src/lmdb/multi_map.ts +51 -0
- package/src/lmdb/store.ts +24 -48
- package/src/lmdb-v2/array.ts +8 -3
- package/src/lmdb-v2/factory.ts +17 -10
- 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 +21 -40
- 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/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/interfaces/store_test_suite.ts +0 -56
package/src/lmdb-v2/utils.ts
CHANGED
|
@@ -2,124 +2,6 @@ import { MAXIMUM_KEY, fromBufferKey, toBufferKey } from 'ordered-binary';
|
|
|
2
2
|
|
|
3
3
|
import type { Key } from '../interfaces/common.js';
|
|
4
4
|
|
|
5
|
-
type Cmp<T> = (a: T, b: T) => -1 | 0 | 1;
|
|
6
|
-
|
|
7
|
-
export function dedupeSortedArray<T>(arr: T[], cmp: Cmp<T>): void {
|
|
8
|
-
for (let i = 0; i < arr.length; i++) {
|
|
9
|
-
let j = i + 1;
|
|
10
|
-
for (; j < arr.length; j++) {
|
|
11
|
-
const res = cmp(arr[i], arr[j]);
|
|
12
|
-
if (res === 0) {
|
|
13
|
-
continue;
|
|
14
|
-
} else if (res < 0) {
|
|
15
|
-
break;
|
|
16
|
-
} else {
|
|
17
|
-
throw new Error('Array not sorted');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (j - i > 1) {
|
|
22
|
-
arr.splice(i + 1, j - i - 1);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function insertIntoSortedArray<T>(arr: T[], item: T, cmp: (a: T, b: T) => number): void {
|
|
28
|
-
let left = 0;
|
|
29
|
-
let right = arr.length;
|
|
30
|
-
|
|
31
|
-
while (left < right) {
|
|
32
|
-
const mid = (left + right) >> 1;
|
|
33
|
-
const comparison = cmp(arr[mid], item);
|
|
34
|
-
|
|
35
|
-
if (comparison < 0) {
|
|
36
|
-
left = mid + 1;
|
|
37
|
-
} else {
|
|
38
|
-
right = mid;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
arr.splice(left, 0, item);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function findIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
|
|
46
|
-
let start = 0;
|
|
47
|
-
let end = values.length - 1;
|
|
48
|
-
|
|
49
|
-
while (start <= end) {
|
|
50
|
-
const mid = start + (((end - start) / 2) | 0);
|
|
51
|
-
const res = cmp(values[mid], needle);
|
|
52
|
-
if (res === 0) {
|
|
53
|
-
return mid;
|
|
54
|
-
} else if (res > 0) {
|
|
55
|
-
end = mid - 1;
|
|
56
|
-
} else {
|
|
57
|
-
start = mid + 1;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return -1;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function findInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): T | undefined {
|
|
65
|
-
const idx = findIndexInSortedArray(values, needle, cmp);
|
|
66
|
-
return idx > -1 ? values[idx] : undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function removeAnyOf<T, N>(arr: T[], vals: N[], cmp: (a: T, b: N) => -1 | 0 | 1): void {
|
|
70
|
-
let writeIdx = 0;
|
|
71
|
-
let readIdx = 0;
|
|
72
|
-
let valIdx = 0;
|
|
73
|
-
|
|
74
|
-
while (readIdx < arr.length && valIdx < vals.length) {
|
|
75
|
-
const comparison = cmp(arr[readIdx], vals[valIdx]);
|
|
76
|
-
|
|
77
|
-
if (comparison < 0) {
|
|
78
|
-
arr[writeIdx++] = arr[readIdx++];
|
|
79
|
-
} else if (comparison > 0) {
|
|
80
|
-
valIdx++;
|
|
81
|
-
} else {
|
|
82
|
-
readIdx++;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
while (readIdx < arr.length) {
|
|
87
|
-
arr[writeIdx++] = arr[readIdx++];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
arr.length = writeIdx;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function removeFromSortedArray<T, N>(arr: T[], val: N, cmp: (a: T, b: N) => -1 | 0 | 1) {
|
|
94
|
-
const idx = findIndexInSortedArray(arr, val, cmp);
|
|
95
|
-
if (idx > -1) {
|
|
96
|
-
arr.splice(idx, 1);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function merge<T>(arr: T[], toInsert: T[], cmp: (a: T, b: T) => -1 | 0 | 1): void {
|
|
101
|
-
const result = new Array<T>(arr.length + toInsert.length);
|
|
102
|
-
let i = 0,
|
|
103
|
-
j = 0,
|
|
104
|
-
k = 0;
|
|
105
|
-
|
|
106
|
-
while (i < arr.length && j < toInsert.length) {
|
|
107
|
-
result[k++] = cmp(arr[i], toInsert[j]) <= 0 ? arr[i++] : toInsert[j++];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
while (i < arr.length) {
|
|
111
|
-
result[k++] = arr[i++];
|
|
112
|
-
}
|
|
113
|
-
while (j < toInsert.length) {
|
|
114
|
-
result[k++] = toInsert[j++];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
for (i = 0; i < result.length; i++) {
|
|
118
|
-
arr[i] = result[i];
|
|
119
|
-
}
|
|
120
|
-
arr.length = result.length;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
5
|
export function keyCmp(a: [Uint8Array, Uint8Array[] | null], b: [Uint8Array, Uint8Array[] | null]): -1 | 0 | 1 {
|
|
124
6
|
return Buffer.compare(a[0], b[0]);
|
|
125
7
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { type Batch, Database, LMDBMessageType } from './message.js';
|
|
2
|
-
import { ReadTransaction } from './read_transaction.js';
|
|
3
1
|
import {
|
|
4
2
|
dedupeSortedArray,
|
|
5
3
|
findInSortedArray,
|
|
6
4
|
findIndexInSortedArray,
|
|
7
5
|
insertIntoSortedArray,
|
|
8
|
-
keyCmp,
|
|
9
6
|
merge,
|
|
10
7
|
removeAnyOf,
|
|
11
8
|
removeFromSortedArray,
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
} from '@aztec/foundation/array';
|
|
10
|
+
|
|
11
|
+
import { type Batch, Database, LMDBMessageType } from './message.js';
|
|
12
|
+
import { ReadTransaction } from './read_transaction.js';
|
|
13
|
+
import { keyCmp, singleKeyCmp } from './utils.js';
|
|
14
14
|
|
|
15
15
|
export class WriteTransaction extends ReadTransaction {
|
|
16
16
|
// exposed for tests
|
|
@@ -44,7 +44,7 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
44
44
|
remove(key: Uint8Array): Promise<void> {
|
|
45
45
|
const removeEntryIndex = findIndexInSortedArray(this.dataBatch.removeEntries, key, singleKeyCmp);
|
|
46
46
|
if (removeEntryIndex === -1) {
|
|
47
|
-
this.dataBatch.removeEntries
|
|
47
|
+
insertIntoSortedArray(this.dataBatch.removeEntries, [key, null], keyCmp);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const addEntryIndex = findIndexInSortedArray(this.dataBatch.addEntries, key, singleKeyCmp);
|
|
@@ -163,7 +163,7 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
163
163
|
|
|
164
164
|
public override async *iterate(
|
|
165
165
|
startKey: Uint8Array,
|
|
166
|
-
endKey?: Uint8Array
|
|
166
|
+
endKey?: Uint8Array,
|
|
167
167
|
reverse?: boolean,
|
|
168
168
|
limit?: number,
|
|
169
169
|
): AsyncIterable<[Uint8Array, Uint8Array]> {
|
|
@@ -181,7 +181,7 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
181
181
|
|
|
182
182
|
public override async *iterateIndex(
|
|
183
183
|
startKey: Uint8Array,
|
|
184
|
-
endKey?: Uint8Array
|
|
184
|
+
endKey?: Uint8Array,
|
|
185
185
|
reverse?: boolean,
|
|
186
186
|
limit?: number,
|
|
187
187
|
): AsyncIterable<[Uint8Array, Uint8Array[]]> {
|
|
@@ -218,8 +218,9 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
218
218
|
): AsyncIterable<[Uint8Array, T]> {
|
|
219
219
|
this.assertIsOpen();
|
|
220
220
|
|
|
221
|
-
//
|
|
221
|
+
// Snapshot both add and remove entries at the start of iteration to ensure consistency
|
|
222
222
|
const uncommittedEntries = [...batch.addEntries];
|
|
223
|
+
const removeEntries = [...batch.removeEntries];
|
|
223
224
|
// used to check we're in the right order when comparing between a key and uncommittedEntries
|
|
224
225
|
let cmpDirection = -1;
|
|
225
226
|
if (reverse) {
|
|
@@ -262,7 +263,7 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
262
263
|
break;
|
|
263
264
|
}
|
|
264
265
|
|
|
265
|
-
const toRemove = findInSortedArray(
|
|
266
|
+
const toRemove = findInSortedArray(removeEntries, key, singleKeyCmp);
|
|
266
267
|
|
|
267
268
|
// at this point we've either exhausted all uncommitted entries,
|
|
268
269
|
// we reached a key strictly greater/smaller than `key`
|
package/src/stores/index.ts
CHANGED
|
@@ -1,70 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
L2BlockStreamEventHandler,
|
|
5
|
-
L2BlockStreamLocalDataProvider,
|
|
6
|
-
L2BlockTag,
|
|
7
|
-
L2Tips,
|
|
8
|
-
} from '@aztec/stdlib/block';
|
|
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';
|
|
9
4
|
|
|
10
5
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
11
6
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
12
7
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
10
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
11
|
+
*/
|
|
12
|
+
export class L2TipsKVStore extends L2TipsStoreBase {
|
|
13
|
+
private readonly l2TipsStore: AztecAsyncMap<L2BlockTag, BlockNumber>;
|
|
14
|
+
private readonly l2BlockHashesStore: AztecAsyncMap<BlockNumber, string>;
|
|
15
|
+
private readonly l2BlockNumberToCheckpointNumberStore: AztecAsyncMap<BlockNumber, CheckpointNumber>;
|
|
16
|
+
private readonly l2CheckpointStore: AztecAsyncMap<CheckpointNumber, Buffer>;
|
|
17
17
|
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
private store: AztecAsyncKVStore,
|
|
20
|
+
namespace: string,
|
|
21
|
+
) {
|
|
22
|
+
super();
|
|
19
23
|
this.l2TipsStore = store.openMap([namespace, 'l2_tips'].join('_'));
|
|
20
24
|
this.l2BlockHashesStore = store.openMap([namespace, 'l2_block_hashes'].join('_'));
|
|
25
|
+
this.l2BlockNumberToCheckpointNumberStore = store.openMap(
|
|
26
|
+
[namespace, 'l2_block_number_to_checkpoint_number'].join('_'),
|
|
27
|
+
);
|
|
28
|
+
this.l2CheckpointStore = store.openMap([namespace, 'l2_checkpoint_store'].join('_'));
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
return this.
|
|
31
|
+
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined> {
|
|
32
|
+
return this.l2TipsStore.getAsync(tag);
|
|
25
33
|
}
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
latest: await this.getL2Tip('latest'),
|
|
30
|
-
finalized: await this.getL2Tip('finalized'),
|
|
31
|
-
proven: await this.getL2Tip('proven'),
|
|
32
|
-
};
|
|
35
|
+
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void> {
|
|
36
|
+
return this.l2TipsStore.set(tag, blockNumber);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined> {
|
|
40
|
+
return this.l2BlockHashesStore.getAsync(blockNumber);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void> {
|
|
44
|
+
return this.l2BlockHashesStore.set(blockNumber, hash);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected async deleteBlockHashesBefore(blockNumber: BlockNumber): Promise<void> {
|
|
48
|
+
for await (const key of this.l2BlockHashesStore.keysAsync({ end: blockNumber })) {
|
|
49
|
+
await this.l2BlockHashesStore.delete(key);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected getCheckpointNumberForBlock(blockNumber: BlockNumber): Promise<CheckpointNumber | undefined> {
|
|
54
|
+
return this.l2BlockNumberToCheckpointNumberStore.getAsync(blockNumber);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected setCheckpointNumberForBlock(blockNumber: BlockNumber, checkpointNumber: CheckpointNumber): Promise<void> {
|
|
58
|
+
return this.l2BlockNumberToCheckpointNumberStore.set(blockNumber, checkpointNumber);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected async deleteBlockToCheckpointBefore(blockNumber: BlockNumber): Promise<void> {
|
|
62
|
+
for await (const key of this.l2BlockNumberToCheckpointNumberStore.keysAsync({ end: blockNumber })) {
|
|
63
|
+
await this.l2BlockNumberToCheckpointNumberStore.delete(key);
|
|
39
64
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<PublishedCheckpoint | undefined> {
|
|
68
|
+
const buffer = await this.l2CheckpointStore.getAsync(checkpointNumber);
|
|
69
|
+
if (!buffer) {
|
|
70
|
+
return undefined;
|
|
43
71
|
}
|
|
72
|
+
return PublishedCheckpoint.fromBuffer(buffer);
|
|
73
|
+
}
|
|
44
74
|
|
|
45
|
-
|
|
75
|
+
protected saveCheckpointData(checkpoint: PublishedCheckpoint): Promise<void> {
|
|
76
|
+
return this.l2CheckpointStore.set(checkpoint.checkpoint.number, checkpoint.toBuffer());
|
|
46
77
|
}
|
|
47
78
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (const block of event.blocks) {
|
|
52
|
-
await this.l2BlockHashesStore.set(block.number, (await block.header.hash()).toString());
|
|
53
|
-
}
|
|
54
|
-
await this.l2TipsStore.set('latest', event.blocks.at(-1)!.number);
|
|
55
|
-
break;
|
|
56
|
-
case 'chain-pruned':
|
|
57
|
-
await this.l2TipsStore.set('latest', event.blockNumber);
|
|
58
|
-
break;
|
|
59
|
-
case 'chain-proven':
|
|
60
|
-
await this.l2TipsStore.set('proven', event.blockNumber);
|
|
61
|
-
break;
|
|
62
|
-
case 'chain-finalized':
|
|
63
|
-
await this.l2TipsStore.set('finalized', event.blockNumber);
|
|
64
|
-
for await (const key of this.l2BlockHashesStore.keysAsync({ end: event.blockNumber })) {
|
|
65
|
-
await this.l2BlockHashesStore.delete(key);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
79
|
+
protected async deleteCheckpointsBefore(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
80
|
+
for await (const key of this.l2CheckpointStore.keysAsync({ end: checkpointNumber })) {
|
|
81
|
+
await this.l2CheckpointStore.delete(key);
|
|
68
82
|
}
|
|
69
83
|
}
|
|
84
|
+
|
|
85
|
+
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T> {
|
|
86
|
+
return this.store.transactionAsync(fn);
|
|
87
|
+
}
|
|
70
88
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
2
|
-
export declare function describeAztecStore(testName: string, getPersistentStore: () => Promise<AztecKVStore | AztecAsyncKVStore>, getPersistentNoPathStore: () => Promise<AztecKVStore | AztecAsyncKVStore>, getEphemeralStore: () => Promise<AztecKVStore | AztecAsyncKVStore>): void;
|
|
3
|
-
//# sourceMappingURL=store_test_suite.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/store_test_suite.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,iBAAiB,CAAC,EACnE,wBAAwB,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,iBAAiB,CAAC,EACzE,iBAAiB,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,iBAAiB,CAAC,QA6CnE"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { isSyncStore } from './utils.js';
|
|
3
|
-
export function describeAztecStore(testName, getPersistentStore, getPersistentNoPathStore, getEphemeralStore) {
|
|
4
|
-
describe(testName, ()=>{
|
|
5
|
-
async function get(store, singleton) {
|
|
6
|
-
return isSyncStore(store) ? singleton.get() : await singleton.getAsync();
|
|
7
|
-
}
|
|
8
|
-
const itForks = async (store)=>{
|
|
9
|
-
const singleton = store.openSingleton('singleton');
|
|
10
|
-
await singleton.set('foo');
|
|
11
|
-
const forkedStore = await store.fork();
|
|
12
|
-
const forkedSingleton = forkedStore.openSingleton('singleton');
|
|
13
|
-
expect(await get(store, singleton)).to.equal('foo');
|
|
14
|
-
await forkedSingleton.set('bar');
|
|
15
|
-
expect(await get(store, singleton)).to.equal('foo');
|
|
16
|
-
expect(await get(forkedStore, forkedSingleton)).to.equal('bar');
|
|
17
|
-
await forkedSingleton.delete();
|
|
18
|
-
expect(await get(store, singleton)).to.equal('foo');
|
|
19
|
-
await forkedStore.delete();
|
|
20
|
-
};
|
|
21
|
-
it('forks a persistent store', async ()=>{
|
|
22
|
-
const store = await getPersistentStore();
|
|
23
|
-
await itForks(store);
|
|
24
|
-
await store.delete();
|
|
25
|
-
});
|
|
26
|
-
it('forks a persistent store with no path', async ()=>{
|
|
27
|
-
const store = await getPersistentNoPathStore();
|
|
28
|
-
await itForks(store);
|
|
29
|
-
await store.delete();
|
|
30
|
-
});
|
|
31
|
-
it('forks an ephemeral store', async ()=>{
|
|
32
|
-
const store = await getEphemeralStore();
|
|
33
|
-
await itForks(store);
|
|
34
|
-
await store.delete();
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import type { AztecAsyncSingleton, AztecSingleton } from './singleton.js';
|
|
4
|
-
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
5
|
-
import { isSyncStore } from './utils.js';
|
|
6
|
-
|
|
7
|
-
export function describeAztecStore(
|
|
8
|
-
testName: string,
|
|
9
|
-
getPersistentStore: () => Promise<AztecKVStore | AztecAsyncKVStore>,
|
|
10
|
-
getPersistentNoPathStore: () => Promise<AztecKVStore | AztecAsyncKVStore>,
|
|
11
|
-
getEphemeralStore: () => Promise<AztecKVStore | AztecAsyncKVStore>,
|
|
12
|
-
) {
|
|
13
|
-
describe(testName, () => {
|
|
14
|
-
async function get(
|
|
15
|
-
store: AztecKVStore | AztecAsyncKVStore,
|
|
16
|
-
singleton: AztecSingleton<string> | AztecAsyncSingleton<string>,
|
|
17
|
-
) {
|
|
18
|
-
return isSyncStore(store)
|
|
19
|
-
? (singleton as AztecSingleton<string>).get()
|
|
20
|
-
: await (singleton as AztecAsyncSingleton<string>).getAsync();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const itForks = async (store: AztecKVStore | AztecAsyncKVStore) => {
|
|
24
|
-
const singleton = store.openSingleton<string>('singleton');
|
|
25
|
-
await singleton.set('foo');
|
|
26
|
-
|
|
27
|
-
const forkedStore = await store.fork();
|
|
28
|
-
const forkedSingleton = forkedStore.openSingleton<string>('singleton');
|
|
29
|
-
expect(await get(store, singleton)).to.equal('foo');
|
|
30
|
-
await forkedSingleton.set('bar');
|
|
31
|
-
expect(await get(store, singleton)).to.equal('foo');
|
|
32
|
-
expect(await get(forkedStore, forkedSingleton)).to.equal('bar');
|
|
33
|
-
await forkedSingleton.delete();
|
|
34
|
-
expect(await get(store, singleton)).to.equal('foo');
|
|
35
|
-
await forkedStore.delete();
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
it('forks a persistent store', async () => {
|
|
39
|
-
const store = await getPersistentStore();
|
|
40
|
-
await itForks(store);
|
|
41
|
-
await store.delete();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('forks a persistent store with no path', async () => {
|
|
45
|
-
const store = await getPersistentNoPathStore();
|
|
46
|
-
await itForks(store);
|
|
47
|
-
await store.delete();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('forks an ephemeral store', async () => {
|
|
51
|
-
const store = await getEphemeralStore();
|
|
52
|
-
await itForks(store);
|
|
53
|
-
await store.delete();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|