@aztec/kv-store 0.82.3 → 0.83.1-alpha-testnet.0
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 +2 -1
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/array.js +3 -0
- package/dest/indexeddb/map.d.ts +2 -2
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +2 -0
- package/dest/indexeddb/multi_map.d.ts +2 -2
- package/dest/indexeddb/multi_map.d.ts.map +1 -1
- package/dest/indexeddb/multi_map.js +20 -10
- package/dest/indexeddb/singleton.d.ts +2 -1
- package/dest/indexeddb/singleton.d.ts.map +1 -1
- package/dest/indexeddb/singleton.js +3 -1
- package/dest/indexeddb/store.d.ts +8 -6
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +7 -0
- package/dest/interfaces/array.d.ts +4 -3
- package/dest/interfaces/array.d.ts.map +1 -1
- package/dest/interfaces/array.js +1 -3
- package/dest/interfaces/common.d.ts +1 -0
- package/dest/interfaces/common.d.ts.map +1 -1
- package/dest/interfaces/map.d.ts +4 -4
- package/dest/interfaces/map.d.ts.map +1 -1
- package/dest/interfaces/multi_map.d.ts +3 -3
- package/dest/interfaces/multi_map.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.js +7 -0
- package/dest/interfaces/store.d.ts +9 -9
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/lmdb/array.d.ts +2 -1
- package/dest/lmdb/array.d.ts.map +1 -1
- package/dest/lmdb/map.d.ts +2 -2
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/multi_map.d.ts +2 -2
- package/dest/lmdb/multi_map.d.ts.map +1 -1
- package/dest/lmdb/store.d.ts +4 -4
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb-v2/array.d.ts +2 -1
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/map.d.ts +2 -2
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/multi_map.d.ts +2 -2
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -1
- package/dest/lmdb-v2/store.d.ts +5 -5
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/stores/l2_tips_memory_store.d.ts +1 -0
- package/dest/stores/l2_tips_memory_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_memory_store.js +10 -4
- package/dest/stores/l2_tips_store.d.ts +1 -0
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +10 -4
- package/package.json +6 -5
- package/src/indexeddb/array.ts +5 -1
- package/src/indexeddb/map.ts +4 -2
- package/src/indexeddb/multi_map.ts +26 -14
- package/src/indexeddb/singleton.ts +4 -1
- package/src/indexeddb/store.ts +15 -7
- package/src/interfaces/array.ts +5 -3
- package/src/interfaces/common.ts +2 -0
- package/src/interfaces/map.ts +4 -4
- package/src/interfaces/multi_map.ts +3 -3
- package/src/interfaces/multi_map_test_suite.ts +7 -0
- package/src/interfaces/store.ts +9 -9
- package/src/lmdb/array.ts +2 -1
- package/src/lmdb/map.ts +2 -2
- package/src/lmdb/multi_map.ts +2 -2
- package/src/lmdb/store.ts +4 -4
- package/src/lmdb-v2/array.ts +2 -1
- package/src/lmdb-v2/map.ts +2 -2
- package/src/lmdb-v2/multi_map.ts +2 -2
- package/src/lmdb-v2/store.ts +5 -5
- package/src/stores/l2_tips_memory_store.ts +11 -4
- package/src/stores/l2_tips_store.ts +11 -4
package/src/interfaces/store.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AztecArray, AztecAsyncArray } from './array.js';
|
|
2
|
-
import type { Key, StoreSize } from './common.js';
|
|
2
|
+
import type { Key, StoreSize, Value } from './common.js';
|
|
3
3
|
import type { AztecAsyncCounter, AztecCounter } from './counter.js';
|
|
4
4
|
import type { AztecAsyncMap, AztecMap } from './map.js';
|
|
5
5
|
import type { AztecAsyncMultiMap, AztecMultiMap } from './multi_map.js';
|
|
@@ -14,7 +14,7 @@ export interface AztecKVStore {
|
|
|
14
14
|
* @param name - The name of the map
|
|
15
15
|
* @returns The map
|
|
16
16
|
*/
|
|
17
|
-
openMap<K extends Key, V>(name: string): AztecMap<K, V>;
|
|
17
|
+
openMap<K extends Key, V extends Value>(name: string): AztecMap<K, V>;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Creates a new set.
|
|
@@ -28,21 +28,21 @@ export interface AztecKVStore {
|
|
|
28
28
|
* @param name - The name of the multi-map
|
|
29
29
|
* @returns The multi-map
|
|
30
30
|
*/
|
|
31
|
-
openMultiMap<K extends Key, V>(name: string): AztecMultiMap<K, V>;
|
|
31
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecMultiMap<K, V>;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Creates a new array.
|
|
35
35
|
* @param name - The name of the array
|
|
36
36
|
* @returns The array
|
|
37
37
|
*/
|
|
38
|
-
openArray<T>(name: string): AztecArray<T>;
|
|
38
|
+
openArray<T extends Value>(name: string): AztecArray<T>;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Creates a new singleton.
|
|
42
42
|
* @param name - The name of the singleton
|
|
43
43
|
* @returns The singleton
|
|
44
44
|
*/
|
|
45
|
-
openSingleton<T>(name: string): AztecSingleton<T>;
|
|
45
|
+
openSingleton<T extends Value>(name: string): AztecSingleton<T>;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Creates a new count map.
|
|
@@ -83,7 +83,7 @@ export interface AztecAsyncKVStore {
|
|
|
83
83
|
* @param name - The name of the map
|
|
84
84
|
* @returns The map
|
|
85
85
|
*/
|
|
86
|
-
openMap<K extends Key, V>(name: string): AztecAsyncMap<K, V>;
|
|
86
|
+
openMap<K extends Key, V extends Value>(name: string): AztecAsyncMap<K, V>;
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* Creates a new set.
|
|
@@ -97,21 +97,21 @@ export interface AztecAsyncKVStore {
|
|
|
97
97
|
* @param name - The name of the multi-map
|
|
98
98
|
* @returns The multi-map
|
|
99
99
|
*/
|
|
100
|
-
openMultiMap<K extends Key, V>(name: string): AztecAsyncMultiMap<K, V>;
|
|
100
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecAsyncMultiMap<K, V>;
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Creates a new array.
|
|
104
104
|
* @param name - The name of the array
|
|
105
105
|
* @returns The array
|
|
106
106
|
*/
|
|
107
|
-
openArray<T>(name: string): AztecAsyncArray<T>;
|
|
107
|
+
openArray<T extends Value>(name: string): AztecAsyncArray<T>;
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Creates a new singleton.
|
|
111
111
|
* @param name - The name of the singleton
|
|
112
112
|
* @returns The singleton
|
|
113
113
|
*/
|
|
114
|
-
openSingleton<T>(name: string): AztecAsyncSingleton<T>;
|
|
114
|
+
openSingleton<T extends Value>(name: string): AztecAsyncSingleton<T>;
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* Creates a new count map.
|
package/src/lmdb/array.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Database, Key } from 'lmdb';
|
|
2
2
|
|
|
3
3
|
import type { AztecArray, AztecAsyncArray } from '../interfaces/array.js';
|
|
4
|
+
import type { Value } from '../interfaces/common.js';
|
|
4
5
|
import { LmdbAztecSingleton } from './singleton.js';
|
|
5
6
|
|
|
6
7
|
/** The shape of a key that stores a value in an array */
|
|
@@ -9,7 +10,7 @@ type ArrayIndexSlot = ['array', string, 'slot', number];
|
|
|
9
10
|
/**
|
|
10
11
|
* An persistent array backed by LMDB.
|
|
11
12
|
*/
|
|
12
|
-
export class LmdbAztecArray<T> implements AztecArray<T>, AztecAsyncArray<T> {
|
|
13
|
+
export class LmdbAztecArray<T extends Value> implements AztecArray<T>, AztecAsyncArray<T> {
|
|
13
14
|
#db: Database<T, ArrayIndexSlot>;
|
|
14
15
|
#name: string;
|
|
15
16
|
#length: LmdbAztecSingleton<number>;
|
package/src/lmdb/map.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Database, RangeOptions } from 'lmdb';
|
|
2
2
|
|
|
3
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
3
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncMap, AztecMap } from '../interfaces/map.js';
|
|
5
5
|
|
|
6
6
|
/** The slot where a key-value entry would be stored */
|
|
@@ -9,7 +9,7 @@ type MapValueSlot<K extends Key | Buffer> = ['map', string, 'slot', K];
|
|
|
9
9
|
/**
|
|
10
10
|
* A map backed by LMDB.
|
|
11
11
|
*/
|
|
12
|
-
export class LmdbAztecMap<K extends Key, V> implements AztecMap<K, V>, AztecAsyncMap<K, V> {
|
|
12
|
+
export class LmdbAztecMap<K extends Key, V extends Value> implements AztecMap<K, V>, AztecAsyncMap<K, V> {
|
|
13
13
|
protected db: Database<[K, V], MapValueSlot<K>>;
|
|
14
14
|
protected name: string;
|
|
15
15
|
|
package/src/lmdb/multi_map.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Key } from '../interfaces/common.js';
|
|
1
|
+
import type { Key, Value } from '../interfaces/common.js';
|
|
2
2
|
import type { AztecAsyncMultiMap, AztecMultiMap } from '../interfaces/multi_map.js';
|
|
3
3
|
import { LmdbAztecMap } from './map.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A map backed by LMDB.
|
|
7
7
|
*/
|
|
8
|
-
export class LmdbAztecMultiMap<K extends Key, V>
|
|
8
|
+
export class LmdbAztecMultiMap<K extends Key, V extends Value>
|
|
9
9
|
extends LmdbAztecMap<K, V>
|
|
10
10
|
implements AztecMultiMap<K, V>, AztecAsyncMultiMap<K, V>
|
|
11
11
|
{
|
package/src/lmdb/store.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { tmpdir } from 'os';
|
|
|
7
7
|
import { join } from 'path';
|
|
8
8
|
|
|
9
9
|
import type { AztecArray, AztecAsyncArray } from '../interfaces/array.js';
|
|
10
|
-
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
10
|
+
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
11
11
|
import type { AztecAsyncCounter, AztecCounter } from '../interfaces/counter.js';
|
|
12
12
|
import type { AztecAsyncMap, AztecMap } from '../interfaces/map.js';
|
|
13
13
|
import type { AztecAsyncMultiMap, AztecMultiMap } from '../interfaces/multi_map.js';
|
|
@@ -80,7 +80,7 @@ export class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
80
80
|
* @param name - Name of the map
|
|
81
81
|
* @returns A new AztecMap
|
|
82
82
|
*/
|
|
83
|
-
openMap<K extends Key, V>(name: string): AztecMap<K, V> & AztecAsyncMap<K, V> {
|
|
83
|
+
openMap<K extends Key, V extends Value>(name: string): AztecMap<K, V> & AztecAsyncMap<K, V> {
|
|
84
84
|
return new LmdbAztecMap(this.#data, name);
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -98,7 +98,7 @@ export class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
98
98
|
* @param name - Name of the map
|
|
99
99
|
* @returns A new AztecMultiMap
|
|
100
100
|
*/
|
|
101
|
-
openMultiMap<K extends Key, V>(name: string): AztecMultiMap<K, V> & AztecAsyncMultiMap<K, V> {
|
|
101
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecMultiMap<K, V> & AztecAsyncMultiMap<K, V> {
|
|
102
102
|
return new LmdbAztecMultiMap(this.#multiMapData, name);
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -111,7 +111,7 @@ export class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
111
111
|
* @param name - Name of the array
|
|
112
112
|
* @returns A new AztecArray
|
|
113
113
|
*/
|
|
114
|
-
openArray<T>(name: string): AztecArray<T> & AztecAsyncArray<T> {
|
|
114
|
+
openArray<T extends Value>(name: string): AztecArray<T> & AztecAsyncArray<T> {
|
|
115
115
|
return new LmdbAztecArray(this.#data, name);
|
|
116
116
|
}
|
|
117
117
|
|
package/src/lmdb-v2/array.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Encoder } from 'msgpackr/pack';
|
|
2
2
|
|
|
3
3
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
4
|
+
import type { Value } from '../interfaces/common.js';
|
|
4
5
|
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
5
6
|
import type { ReadTransaction } from './read_transaction.js';
|
|
6
7
|
// eslint-disable-next-line import/no-cycle
|
|
7
8
|
import { AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
8
9
|
import { deserializeKey, serializeKey } from './utils.js';
|
|
9
10
|
|
|
10
|
-
export class LMDBArray<T> implements AztecAsyncArray<T> {
|
|
11
|
+
export class LMDBArray<T extends Value> implements AztecAsyncArray<T> {
|
|
11
12
|
private length: AztecAsyncSingleton<number>;
|
|
12
13
|
private encoder = new Encoder();
|
|
13
14
|
private prefix: string;
|
package/src/lmdb-v2/map.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Encoder } from 'msgpackr';
|
|
2
2
|
|
|
3
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
3
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
5
5
|
import type { ReadTransaction } from './read_transaction.js';
|
|
6
6
|
// eslint-disable-next-line import/no-cycle
|
|
7
7
|
import { type AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
8
8
|
import { deserializeKey, maxKey, minKey, serializeKey } from './utils.js';
|
|
9
9
|
|
|
10
|
-
export class LMDBMap<K extends Key, V> implements AztecAsyncMap<K, V> {
|
|
10
|
+
export class LMDBMap<K extends Key, V extends Value> implements AztecAsyncMap<K, V> {
|
|
11
11
|
private prefix: string;
|
|
12
12
|
private encoder = new Encoder();
|
|
13
13
|
|
package/src/lmdb-v2/multi_map.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Encoder } from 'msgpackr/pack';
|
|
2
2
|
|
|
3
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
3
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
5
5
|
import type { ReadTransaction } from './read_transaction.js';
|
|
6
6
|
import { type AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
7
7
|
import { deserializeKey, maxKey, minKey, serializeKey } from './utils.js';
|
|
8
8
|
|
|
9
|
-
export class LMDBMultiMap<K extends Key, V> implements AztecAsyncMultiMap<K, V> {
|
|
9
|
+
export class LMDBMultiMap<K extends Key, V extends Value> implements AztecAsyncMultiMap<K, V> {
|
|
10
10
|
private prefix: string;
|
|
11
11
|
private encoder = new Encoder();
|
|
12
12
|
constructor(private store: AztecLMDBStoreV2, name: string) {
|
package/src/lmdb-v2/store.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { AsyncLocalStorage } from 'async_hooks';
|
|
|
6
6
|
import { mkdir, rm } from 'fs/promises';
|
|
7
7
|
|
|
8
8
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
9
|
-
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
9
|
+
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
10
10
|
import type { AztecAsyncCounter } from '../interfaces/counter.js';
|
|
11
11
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
12
12
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
@@ -102,19 +102,19 @@ export class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageChannel {
|
|
|
102
102
|
return currentWrite;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
openMap<K extends Key, V>(name: string): AztecAsyncMap<K, V> {
|
|
105
|
+
openMap<K extends Key, V extends Value>(name: string): AztecAsyncMap<K, V> {
|
|
106
106
|
return new LMDBMap(this, name);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
openMultiMap<K extends Key, V>(name: string): AztecAsyncMultiMap<K, V> {
|
|
109
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecAsyncMultiMap<K, V> {
|
|
110
110
|
return new LMDBMultiMap(this, name);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
openSingleton<T>(name: string): AztecAsyncSingleton<T> {
|
|
113
|
+
openSingleton<T extends Value>(name: string): AztecAsyncSingleton<T> {
|
|
114
114
|
return new LMDBSingleValue(this, name);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
openArray<T>(name: string): AztecAsyncArray<T> {
|
|
117
|
+
openArray<T extends Value>(name: string): AztecAsyncArray<T> {
|
|
118
118
|
return new LMDBArray(this, name);
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -48,19 +48,26 @@ export class L2TipsMemoryStore implements L2BlockStreamEventHandler, L2BlockStre
|
|
|
48
48
|
break;
|
|
49
49
|
}
|
|
50
50
|
case 'chain-pruned':
|
|
51
|
-
this.
|
|
51
|
+
this.saveTag('latest', event.block);
|
|
52
52
|
break;
|
|
53
53
|
case 'chain-proven':
|
|
54
|
-
this.
|
|
54
|
+
this.saveTag('proven', event.block);
|
|
55
55
|
break;
|
|
56
56
|
case 'chain-finalized':
|
|
57
|
-
this.
|
|
57
|
+
this.saveTag('finalized', event.block);
|
|
58
58
|
for (const key of this.l2BlockHashesStore.keys()) {
|
|
59
|
-
if (key < event.
|
|
59
|
+
if (key < event.block.number) {
|
|
60
60
|
this.l2BlockHashesStore.delete(key);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
private saveTag(name: L2BlockTag, block: L2BlockId) {
|
|
68
|
+
this.l2TipsStore.set(name, block.number);
|
|
69
|
+
if (block.hash) {
|
|
70
|
+
this.l2BlockHashesStore.set(block.number, block.hash);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
66
73
|
}
|
|
@@ -56,17 +56,24 @@ export class L2TipsKVStore implements L2BlockStreamEventHandler, L2BlockStreamLo
|
|
|
56
56
|
break;
|
|
57
57
|
}
|
|
58
58
|
case 'chain-pruned':
|
|
59
|
-
await this.
|
|
59
|
+
await this.saveTag('latest', event.block);
|
|
60
60
|
break;
|
|
61
61
|
case 'chain-proven':
|
|
62
|
-
await this.
|
|
62
|
+
await this.saveTag('proven', event.block);
|
|
63
63
|
break;
|
|
64
64
|
case 'chain-finalized':
|
|
65
|
-
await this.
|
|
66
|
-
for await (const key of this.l2BlockHashesStore.keysAsync({ end: event.
|
|
65
|
+
await this.saveTag('finalized', event.block);
|
|
66
|
+
for await (const key of this.l2BlockHashesStore.keysAsync({ end: event.block.number })) {
|
|
67
67
|
await this.l2BlockHashesStore.delete(key);
|
|
68
68
|
}
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
private async saveTag(name: L2BlockTag, block: L2BlockId) {
|
|
74
|
+
await this.l2TipsStore.set(name, block.number);
|
|
75
|
+
if (block.hash) {
|
|
76
|
+
await this.l2BlockHashesStore.set(block.number, block.hash);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
72
79
|
}
|