@aztec/kv-store 3.0.0-devnet.5 → 3.0.0-devnet.6-patch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config.d.ts +1 -1
- package/dest/indexeddb/array.d.ts +1 -1
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/index.d.ts +1 -1
- package/dest/indexeddb/map.d.ts +1 -1
- package/dest/indexeddb/map.d.ts.map +1 -1
- 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 +14 -0
- package/dest/indexeddb/set.d.ts +1 -1
- package/dest/indexeddb/set.d.ts.map +1 -1
- package/dest/indexeddb/singleton.d.ts +1 -1
- package/dest/indexeddb/singleton.d.ts.map +1 -1
- package/dest/indexeddb/store.d.ts +1 -1
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/interfaces/array.d.ts +1 -1
- package/dest/interfaces/array_test_suite.d.ts +1 -1
- package/dest/interfaces/common.d.ts +1 -1
- package/dest/interfaces/counter.d.ts +1 -1
- package/dest/interfaces/index.d.ts +1 -1
- package/dest/interfaces/map.d.ts +1 -1
- package/dest/interfaces/map_test_suite.d.ts +1 -1
- package/dest/interfaces/multi_map.d.ts +7 -1
- package/dest/interfaces/multi_map.d.ts.map +1 -1
- 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 +94 -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 +1 -1
- package/dest/interfaces/utils.d.ts +1 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/lmdb/array.d.ts +1 -1
- package/dest/lmdb/array.d.ts.map +1 -1
- 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/map.d.ts +1 -1
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/multi_map.d.ts +2 -1
- package/dest/lmdb/multi_map.d.ts.map +1 -1
- package/dest/lmdb/multi_map.js +15 -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 +2 -3
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +1 -1
- package/dest/lmdb-v2/array.d.ts +1 -1
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.d.ts +4 -7
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/index.d.ts +1 -1
- package/dest/lmdb-v2/map.d.ts +1 -1
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/message.d.ts +1 -1
- package/dest/lmdb-v2/multi_map.d.ts +2 -1
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -1
- package/dest/lmdb-v2/multi_map.js +11 -0
- package/dest/lmdb-v2/read_transaction.d.ts +1 -1
- package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/set.d.ts +1 -1
- package/dest/lmdb-v2/set.d.ts.map +1 -1
- package/dest/lmdb-v2/singleton.d.ts +1 -1
- package/dest/lmdb-v2/singleton.d.ts.map +1 -1
- package/dest/lmdb-v2/store.d.ts +1 -1
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/utils.d.ts +1 -1
- package/dest/lmdb-v2/write_transaction.d.ts +1 -1
- package/dest/lmdb-v2/write_transaction.d.ts.map +1 -1
- package/dest/stores/index.d.ts +1 -1
- package/dest/stores/l2_tips_store.d.ts +3 -2
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +4 -2
- package/dest/utils.d.ts +1 -1
- package/package.json +10 -7
- package/src/indexeddb/multi_map.ts +12 -0
- package/src/interfaces/multi_map.ts +7 -0
- package/src/interfaces/multi_map_test_suite.ts +100 -0
- package/src/lmdb/multi_map.ts +16 -0
- package/src/lmdb/store.ts +1 -1
- package/src/lmdb-v2/multi_map.ts +9 -0
- package/src/stores/l2_tips_store.ts +6 -4
package/src/lmdb-v2/multi_map.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Encoder } from 'msgpackr/pack';
|
|
2
|
+
import { MAXIMUM_KEY, toBufferKey } from 'ordered-binary';
|
|
2
3
|
|
|
3
4
|
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
4
5
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
5
6
|
import type { ReadTransaction } from './read_transaction.js';
|
|
7
|
+
// eslint-disable-next-line import/no-cycle
|
|
6
8
|
import { type AztecLMDBStoreV2, execInReadTx, execInWriteTx } from './store.js';
|
|
7
9
|
import { deserializeKey, maxKey, minKey, serializeKey } from './utils.js';
|
|
8
10
|
|
|
@@ -138,4 +140,11 @@ export class LMDBMultiMap<K extends Key, V extends Value> implements AztecAsyncM
|
|
|
138
140
|
yield this.encoder.unpack(value);
|
|
139
141
|
}
|
|
140
142
|
}
|
|
143
|
+
|
|
144
|
+
getValueCountAsync(key: K): Promise<number> {
|
|
145
|
+
const startKey = serializeKey(this.prefix, key);
|
|
146
|
+
const endKey = toBufferKey([this.prefix, key, MAXIMUM_KEY]);
|
|
147
|
+
|
|
148
|
+
return execInReadTx(this.store, tx => tx.countEntriesIndex(startKey, endKey, false));
|
|
149
|
+
}
|
|
141
150
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
3
|
import type {
|
|
2
4
|
L2BlockId,
|
|
3
5
|
L2BlockStreamEvent,
|
|
@@ -12,15 +14,15 @@ import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
|
12
14
|
|
|
13
15
|
/** Stores currently synced L2 tips and unfinalized block hashes. */
|
|
14
16
|
export class L2TipsKVStore implements L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider {
|
|
15
|
-
private readonly l2TipsStore: AztecAsyncMap<L2BlockTag,
|
|
16
|
-
private readonly l2BlockHashesStore: AztecAsyncMap<
|
|
17
|
+
private readonly l2TipsStore: AztecAsyncMap<L2BlockTag, BlockNumber>;
|
|
18
|
+
private readonly l2BlockHashesStore: AztecAsyncMap<BlockNumber, string>;
|
|
17
19
|
|
|
18
20
|
constructor(store: AztecAsyncKVStore, namespace: string) {
|
|
19
21
|
this.l2TipsStore = store.openMap([namespace, 'l2_tips'].join('_'));
|
|
20
22
|
this.l2BlockHashesStore = store.openMap([namespace, 'l2_block_hashes'].join('_'));
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
public getL2BlockHash(number:
|
|
25
|
+
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
24
26
|
return this.l2BlockHashesStore.getAsync(number);
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -35,7 +37,7 @@ export class L2TipsKVStore implements L2BlockStreamEventHandler, L2BlockStreamLo
|
|
|
35
37
|
private async getL2Tip(tag: L2BlockTag): Promise<L2BlockId> {
|
|
36
38
|
const blockNumber = await this.l2TipsStore.getAsync(tag);
|
|
37
39
|
if (blockNumber === undefined || blockNumber === 0) {
|
|
38
|
-
return { number:
|
|
40
|
+
return { number: BlockNumber.ZERO, hash: GENESIS_BLOCK_HEADER_HASH.toString() };
|
|
39
41
|
}
|
|
40
42
|
const blockHash = await this.l2BlockHashesStore.getAsync(blockNumber);
|
|
41
43
|
if (!blockHash) {
|