@aztec/kv-store 0.77.0-testnet-ignition.29 → 0.77.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.
@@ -1,9 +1,12 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
1
2
  import { type Logger } from '@aztec/foundation/log';
2
3
  import type { DataStoreConfig } from '../config.js';
3
4
  import { AztecLMDBStoreV2 } from './store.js';
4
- export declare function createStore(name: string, config: DataStoreConfig, log?: Logger): Promise<AztecLMDBStoreV2>;
5
+ export declare function createStore(name: string, schemaVersion: number, config: DataStoreConfig, log?: Logger): Promise<AztecLMDBStoreV2>;
5
6
  export declare function openTmpStore(name: string, ephemeral?: boolean, dbMapSizeKb?: number, // 10GB
6
7
  maxReaders?: number, log?: Logger): Promise<AztecLMDBStoreV2>;
7
8
  export declare function openStoreAt(dataDir: string, dbMapSizeKb?: number, // 10GB
8
9
  maxReaders?: number, log?: Logger): Promise<AztecLMDBStoreV2>;
10
+ export declare function openVersionedStoreAt(dataDir: string, schemaVersion: number, rollupAddress: EthAddress, dbMapSizeKb?: number, // 10GB
11
+ maxReaders?: number, log?: Logger): Promise<AztecLMDBStoreV2>;
9
12
  //# sourceMappingURL=factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAMlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAK9C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EACvB,GAAG,GAAE,MAAiD,GACrD,OAAO,CAAC,gBAAgB,CAAC,CAsC3B;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,OAA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E,MAAyC,GAC7C,OAAO,CAAC,gBAAgB,CAAC,CAM3B"}
@@ -1,42 +1,25 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
- import { mkdir, mkdtemp, readFile, rm, writeFile } from 'fs/promises';
3
+ import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
4
+ import { mkdir, mkdtemp, rm } from 'fs/promises';
4
5
  import { tmpdir } from 'os';
5
6
  import { join } from 'path';
6
7
  import { AztecLMDBStoreV2 } from './store.js';
7
- const ROLLUP_ADDRESS_FILE = 'rollup_address';
8
8
  const MAX_READERS = 16;
9
- export async function createStore(name, config, log = createLogger('kv-store:lmdb-v2:' + name)) {
9
+ export async function createStore(name, schemaVersion, config, log = createLogger('kv-store:lmdb-v2:' + name)) {
10
10
  const { dataDirectory, l1Contracts } = config;
11
11
  let store;
12
12
  if (typeof dataDirectory !== 'undefined') {
13
+ // Get rollup address from contracts config, or use zero address
13
14
  const subDir = join(dataDirectory, name);
14
15
  await mkdir(subDir, {
15
16
  recursive: true
16
17
  });
17
- if (l1Contracts) {
18
- const { rollupAddress } = l1Contracts;
19
- const localRollupAddress = await readFile(join(subDir, ROLLUP_ADDRESS_FILE), 'utf-8').then(EthAddress.fromString).catch(()=>EthAddress.ZERO);
20
- if (!localRollupAddress.equals(rollupAddress)) {
21
- if (!localRollupAddress.isZero()) {
22
- log.warn(`Rollup address mismatch. Clearing entire database...`, {
23
- expected: rollupAddress,
24
- found: localRollupAddress
25
- });
26
- await rm(subDir, {
27
- recursive: true,
28
- force: true,
29
- maxRetries: 3
30
- });
31
- await mkdir(subDir, {
32
- recursive: true
33
- });
34
- }
35
- await writeFile(join(subDir, ROLLUP_ADDRESS_FILE), rollupAddress.toString());
36
- }
37
- }
18
+ const rollupAddress = l1Contracts ? l1Contracts.rollupAddress : EthAddress.ZERO;
19
+ // Create a version manager
20
+ const versionManager = new DatabaseVersionManager(schemaVersion, rollupAddress, subDir, (dbDirectory)=>AztecLMDBStoreV2.new(dbDirectory, config.dataStoreMapSizeKB, MAX_READERS, ()=>Promise.resolve(), log));
38
21
  log.info(`Creating ${name} data store at directory ${subDir} with map size ${config.dataStoreMapSizeKB} KB (LMDB v2)`);
39
- store = await AztecLMDBStoreV2.new(subDir, config.dataStoreMapSizeKB, MAX_READERS, ()=>Promise.resolve(), log);
22
+ [store] = await versionManager.open();
40
23
  } else {
41
24
  store = await openTmpStore(name, true, config.dataStoreMapSizeKB, MAX_READERS, log);
42
25
  }
@@ -62,9 +45,16 @@ export async function openTmpStore(name, ephemeral = true, dbMapSizeKb = 10 * 1_
62
45
  log.debug(`Leaving temporary data store: ${dataDir}`);
63
46
  }
64
47
  };
48
+ // For temporary stores, we don't need to worry about versioning
49
+ // as they are ephemeral and get cleaned up after use
65
50
  return AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, cleanup, log);
66
51
  }
67
- export function openStoreAt(dataDir, dbMapSizeKb = 10 * 1_024 * 1_024, maxReaders = MAX_READERS, log = createLogger('kv-store:lmdb-v2')) {
52
+ export async function openStoreAt(dataDir, dbMapSizeKb = 10 * 1_024 * 1_024, maxReaders = MAX_READERS, log = createLogger('kv-store:lmdb-v2')) {
68
53
  log.debug(`Opening data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
69
- return AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log);
54
+ return await AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log);
55
+ }
56
+ export async function openVersionedStoreAt(dataDir, schemaVersion, rollupAddress, dbMapSizeKb = 10 * 1_024 * 1_024, maxReaders = MAX_READERS, log = createLogger('kv-store:lmdb-v2')) {
57
+ log.debug(`Opening data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
58
+ const [store] = await new DatabaseVersionManager(schemaVersion, rollupAddress, dataDir, (dataDir)=>AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log)).open();
59
+ return store;
70
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/kv-store",
3
- "version": "0.77.0-testnet-ignition.29",
3
+ "version": "0.77.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/interfaces/index.js",
@@ -25,10 +25,10 @@
25
25
  "./package.local.json"
26
26
  ],
27
27
  "dependencies": {
28
- "@aztec/ethereum": "0.77.0-testnet-ignition.29",
29
- "@aztec/foundation": "0.77.0-testnet-ignition.29",
30
- "@aztec/native": "0.77.0-testnet-ignition.29",
31
- "@aztec/stdlib": "0.77.0-testnet-ignition.29",
28
+ "@aztec/ethereum": "0.77.0",
29
+ "@aztec/foundation": "0.77.0",
30
+ "@aztec/native": "0.77.0",
31
+ "@aztec/stdlib": "0.77.0",
32
32
  "idb": "^8.0.0",
33
33
  "lmdb": "^3.2.0",
34
34
  "msgpackr": "^1.11.2",
@@ -1,18 +1,19 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
+ import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
3
4
 
4
- import { mkdir, mkdtemp, readFile, rm, writeFile } from 'fs/promises';
5
+ import { mkdir, mkdtemp, rm } from 'fs/promises';
5
6
  import { tmpdir } from 'os';
6
7
  import { join } from 'path';
7
8
 
8
9
  import type { DataStoreConfig } from '../config.js';
9
10
  import { AztecLMDBStoreV2 } from './store.js';
10
11
 
11
- const ROLLUP_ADDRESS_FILE = 'rollup_address';
12
12
  const MAX_READERS = 16;
13
13
 
14
14
  export async function createStore(
15
15
  name: string,
16
+ schemaVersion: number,
16
17
  config: DataStoreConfig,
17
18
  log: Logger = createLogger('kv-store:lmdb-v2:' + name),
18
19
  ): Promise<AztecLMDBStoreV2> {
@@ -20,34 +21,21 @@ export async function createStore(
20
21
 
21
22
  let store: AztecLMDBStoreV2;
22
23
  if (typeof dataDirectory !== 'undefined') {
24
+ // Get rollup address from contracts config, or use zero address
23
25
  const subDir = join(dataDirectory, name);
24
26
  await mkdir(subDir, { recursive: true });
25
27
 
26
- if (l1Contracts) {
27
- const { rollupAddress } = l1Contracts;
28
- const localRollupAddress = await readFile(join(subDir, ROLLUP_ADDRESS_FILE), 'utf-8')
29
- .then(EthAddress.fromString)
30
- .catch(() => EthAddress.ZERO);
28
+ const rollupAddress = l1Contracts ? l1Contracts.rollupAddress : EthAddress.ZERO;
31
29
 
32
- if (!localRollupAddress.equals(rollupAddress)) {
33
- if (!localRollupAddress.isZero()) {
34
- log.warn(`Rollup address mismatch. Clearing entire database...`, {
35
- expected: rollupAddress,
36
- found: localRollupAddress,
37
- });
38
-
39
- await rm(subDir, { recursive: true, force: true, maxRetries: 3 });
40
- await mkdir(subDir, { recursive: true });
41
- }
42
-
43
- await writeFile(join(subDir, ROLLUP_ADDRESS_FILE), rollupAddress.toString());
44
- }
45
- }
30
+ // Create a version manager
31
+ const versionManager = new DatabaseVersionManager(schemaVersion, rollupAddress, subDir, dbDirectory =>
32
+ AztecLMDBStoreV2.new(dbDirectory, config.dataStoreMapSizeKB, MAX_READERS, () => Promise.resolve(), log),
33
+ );
46
34
 
47
35
  log.info(
48
36
  `Creating ${name} data store at directory ${subDir} with map size ${config.dataStoreMapSizeKB} KB (LMDB v2)`,
49
37
  );
50
- store = await AztecLMDBStoreV2.new(subDir, config.dataStoreMapSizeKB, MAX_READERS, () => Promise.resolve(), log);
38
+ [store] = await versionManager.open();
51
39
  } else {
52
40
  store = await openTmpStore(name, true, config.dataStoreMapSizeKB, MAX_READERS, log);
53
41
  }
@@ -79,15 +67,32 @@ export async function openTmpStore(
79
67
  }
80
68
  };
81
69
 
70
+ // For temporary stores, we don't need to worry about versioning
71
+ // as they are ephemeral and get cleaned up after use
82
72
  return AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, cleanup, log);
83
73
  }
84
74
 
85
- export function openStoreAt(
75
+ export async function openStoreAt(
76
+ dataDir: string,
77
+ dbMapSizeKb = 10 * 1_024 * 1_024, // 10GB
78
+ maxReaders = MAX_READERS,
79
+ log: Logger = createLogger('kv-store:lmdb-v2'),
80
+ ): Promise<AztecLMDBStoreV2> {
81
+ log.debug(`Opening data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
82
+ return await AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log);
83
+ }
84
+
85
+ export async function openVersionedStoreAt(
86
86
  dataDir: string,
87
+ schemaVersion: number,
88
+ rollupAddress: EthAddress,
87
89
  dbMapSizeKb = 10 * 1_024 * 1_024, // 10GB
88
90
  maxReaders = MAX_READERS,
89
91
  log: Logger = createLogger('kv-store:lmdb-v2'),
90
92
  ): Promise<AztecLMDBStoreV2> {
91
93
  log.debug(`Opening data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
92
- return AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log);
94
+ const [store] = await new DatabaseVersionManager(schemaVersion, rollupAddress, dataDir, dataDir =>
95
+ AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log),
96
+ ).open();
97
+ return store;
93
98
  }