@aztec/kv-store 0.0.1-commit.c31f2472 → 0.0.1-commit.c52d6e7
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/README.md +10 -1
- package/dest/bench/shared_map_bench.d.ts +19 -0
- package/dest/bench/shared_map_bench.d.ts.map +1 -0
- package/dest/bench/shared_map_bench.js +91 -0
- package/dest/deprecated/indexeddb/array.d.ts +22 -0
- package/dest/deprecated/indexeddb/array.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/array.js +18 -6
- package/dest/deprecated/indexeddb/index.d.ts +7 -0
- package/dest/deprecated/indexeddb/index.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/index.js +8 -0
- package/dest/deprecated/indexeddb/map.d.ts +38 -0
- package/dest/deprecated/indexeddb/map.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/map.js +23 -13
- package/dest/deprecated/indexeddb/multi_map.d.ts +14 -0
- package/dest/deprecated/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/multi_map.js +16 -1
- package/dest/deprecated/indexeddb/set.d.ts +17 -0
- package/dest/deprecated/indexeddb/set.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/singleton.d.ts +17 -0
- package/dest/deprecated/indexeddb/singleton.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/singleton.js +3 -1
- package/dest/deprecated/indexeddb/store.d.ts +98 -0
- package/dest/deprecated/indexeddb/store.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/store.js +8 -4
- package/dest/interfaces/array_test_suite.d.ts +1 -1
- package/dest/interfaces/array_test_suite.d.ts.map +1 -1
- package/dest/interfaces/array_test_suite.js +33 -34
- package/dest/interfaces/index.d.ts +2 -2
- package/dest/interfaces/index.d.ts.map +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 +74 -29
- 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 +84 -60
- package/dest/interfaces/set_test_suite.d.ts +1 -1
- package/dest/interfaces/set_test_suite.d.ts.map +1 -1
- package/dest/interfaces/set_test_suite.js +13 -14
- package/dest/interfaces/singleton_test_suite.d.ts +1 -1
- package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
- package/dest/interfaces/singleton_test_suite.js +6 -7
- package/dest/lmdb/index.d.ts +3 -3
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +4 -4
- package/dest/lmdb/store.d.ts +3 -3
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +12 -8
- package/dest/lmdb-v2/factory.d.ts +30 -4
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +63 -11
- package/dest/lmdb-v2/read_transaction.js +21 -19
- package/dest/lmdb-v2/store.d.ts +2 -2
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +4 -4
- package/dest/sqlite-opfs/array.d.ts +21 -0
- package/dest/sqlite-opfs/array.d.ts.map +1 -0
- package/dest/sqlite-opfs/array.js +128 -0
- package/dest/sqlite-opfs/errors.d.ts +54 -0
- package/dest/sqlite-opfs/errors.d.ts.map +1 -0
- package/dest/sqlite-opfs/errors.js +77 -0
- package/dest/sqlite-opfs/index.d.ts +14 -0
- package/dest/sqlite-opfs/index.d.ts.map +1 -0
- package/dest/sqlite-opfs/index.js +16 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
- package/dest/sqlite-opfs/manage.d.ts +22 -0
- package/dest/sqlite-opfs/manage.d.ts.map +1 -0
- package/dest/sqlite-opfs/manage.js +38 -0
- package/dest/sqlite-opfs/map.d.ts +35 -0
- package/dest/sqlite-opfs/map.d.ts.map +1 -0
- package/dest/sqlite-opfs/map.js +163 -0
- package/dest/sqlite-opfs/messages.d.ts +66 -0
- package/dest/sqlite-opfs/messages.d.ts.map +1 -0
- package/dest/sqlite-opfs/messages.js +5 -0
- package/dest/sqlite-opfs/multi_map.d.ts +16 -0
- package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
- package/dest/sqlite-opfs/multi_map.js +67 -0
- package/dest/sqlite-opfs/pool_integrity.d.ts +20 -0
- package/dest/sqlite-opfs/pool_integrity.d.ts.map +1 -0
- package/dest/sqlite-opfs/pool_integrity.js +282 -0
- package/dest/sqlite-opfs/pool_lock.d.ts +8 -0
- package/dest/sqlite-opfs/pool_lock.d.ts.map +1 -0
- package/dest/sqlite-opfs/pool_lock.js +47 -0
- package/dest/sqlite-opfs/set.d.ts +13 -0
- package/dest/sqlite-opfs/set.d.ts.map +1 -0
- package/dest/sqlite-opfs/set.js +19 -0
- package/dest/sqlite-opfs/singleton.d.ts +13 -0
- package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
- package/dest/sqlite-opfs/singleton.js +48 -0
- package/dest/sqlite-opfs/store.d.ts +84 -0
- package/dest/sqlite-opfs/store.d.ts.map +1 -0
- package/dest/sqlite-opfs/store.js +317 -0
- package/dest/sqlite-opfs/worker.d.ts +2 -0
- package/dest/sqlite-opfs/worker.d.ts.map +1 -0
- package/dest/sqlite-opfs/worker.js +275 -0
- package/dest/stores/l2_tips_store.d.ts +7 -13
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +24 -43
- 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 -26
- package/src/bench/shared_map_bench.ts +111 -0
- package/src/{indexeddb → deprecated/indexeddb}/array.ts +6 -6
- package/src/deprecated/indexeddb/index.ts +12 -0
- package/src/{indexeddb → deprecated/indexeddb}/map.ts +26 -13
- package/src/{indexeddb → deprecated/indexeddb}/multi_map.ts +17 -3
- package/src/{indexeddb → deprecated/indexeddb}/set.ts +2 -2
- package/src/{indexeddb → deprecated/indexeddb}/singleton.ts +3 -3
- package/src/{indexeddb → deprecated/indexeddb}/store.ts +23 -15
- package/src/interfaces/array_test_suite.ts +33 -35
- package/src/interfaces/index.ts +1 -1
- package/src/interfaces/map_test_suite.ts +56 -30
- package/src/interfaces/multi_map_test_suite.ts +88 -58
- package/src/interfaces/set_test_suite.ts +13 -15
- package/src/interfaces/singleton_test_suite.ts +6 -8
- package/src/lmdb/index.ts +10 -5
- package/src/lmdb/store.ts +12 -8
- package/src/lmdb-v2/factory.ts +86 -10
- package/src/lmdb-v2/read_transaction.ts +23 -23
- package/src/lmdb-v2/store.ts +4 -2
- package/src/sqlite-opfs/array.ts +124 -0
- package/src/sqlite-opfs/errors.ts +94 -0
- package/src/sqlite-opfs/index.ts +27 -0
- package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
- package/src/sqlite-opfs/manage.ts +46 -0
- package/src/sqlite-opfs/map.ts +163 -0
- package/src/sqlite-opfs/messages.ts +39 -0
- package/src/sqlite-opfs/multi_map.ts +74 -0
- package/src/sqlite-opfs/pool_integrity.ts +327 -0
- package/src/sqlite-opfs/pool_lock.ts +62 -0
- package/src/sqlite-opfs/set.ts +29 -0
- package/src/sqlite-opfs/singleton.ts +48 -0
- package/src/sqlite-opfs/store.ts +330 -0
- package/src/sqlite-opfs/worker.ts +259 -0
- package/src/stores/l2_tips_store.ts +20 -41
- 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 -26
- package/dest/indexeddb/array.d.ts +0 -22
- package/dest/indexeddb/array.d.ts.map +0 -1
- package/dest/indexeddb/index.d.ts +0 -7
- package/dest/indexeddb/index.d.ts.map +0 -1
- package/dest/indexeddb/index.js +0 -19
- package/dest/indexeddb/map.d.ts +0 -32
- package/dest/indexeddb/map.d.ts.map +0 -1
- package/dest/indexeddb/multi_map.d.ts +0 -13
- package/dest/indexeddb/multi_map.d.ts.map +0 -1
- package/dest/indexeddb/set.d.ts +0 -17
- package/dest/indexeddb/set.d.ts.map +0 -1
- package/dest/indexeddb/singleton.d.ts +0 -17
- package/dest/indexeddb/singleton.d.ts.map +0 -1
- package/dest/indexeddb/store.d.ts +0 -96
- package/dest/indexeddb/store.d.ts.map +0 -1
- package/src/config.ts +0 -36
- package/src/indexeddb/index.ts +0 -29
- /package/dest/{indexeddb → deprecated/indexeddb}/set.js +0 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
import sqlite3InitModule from '@aztec/sqlite3mc-wasm';
|
|
3
|
+
import { SqliteEncryptionError, isDecryptFailureMessage } from './errors.js';
|
|
4
|
+
import { DEFAULT_SAH_POOL_DIRECTORY } from './pool_lock.js';
|
|
5
|
+
const SCHEMA_SQL = `
|
|
6
|
+
CREATE TABLE IF NOT EXISTS data (
|
|
7
|
+
slot TEXT NOT NULL PRIMARY KEY,
|
|
8
|
+
container TEXT NOT NULL,
|
|
9
|
+
key BLOB NOT NULL,
|
|
10
|
+
key_count INTEGER NOT NULL,
|
|
11
|
+
hash TEXT NOT NULL,
|
|
12
|
+
value BLOB
|
|
13
|
+
) WITHOUT ROWID;
|
|
14
|
+
|
|
15
|
+
CREATE INDEX IF NOT EXISTS idx_container_key ON data(container, key);
|
|
16
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_container_key_count ON data(container, key, key_count);
|
|
17
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_container_key_hash ON data(container, key, hash);
|
|
18
|
+
`;
|
|
19
|
+
const SAH_POOL_VFS_NAME = 'aztec-kv-opfs';
|
|
20
|
+
const MC_SAH_POOL_VFS_NAME = `multipleciphers-${SAH_POOL_VFS_NAME}`;
|
|
21
|
+
let sqlite3;
|
|
22
|
+
let pool;
|
|
23
|
+
let db;
|
|
24
|
+
let dbPath;
|
|
25
|
+
async function ensurePool(directory) {
|
|
26
|
+
const s = sqlite3 ??= await sqlite3InitModule();
|
|
27
|
+
if (!pool) {
|
|
28
|
+
pool = await s.installOpfsSAHPoolVfs({
|
|
29
|
+
name: SAH_POOL_VFS_NAME,
|
|
30
|
+
directory,
|
|
31
|
+
initialCapacity: 8
|
|
32
|
+
});
|
|
33
|
+
// Register a sqlite3mc-wrapped VFS pointing at our SAH Pool VFS.
|
|
34
|
+
// Encrypted DBs must be opened through this wrapper so sqlite3mc can
|
|
35
|
+
// intercept file I/O; plain DBs continue using the SAH Pool VFS directly.
|
|
36
|
+
// The wrapper name is `multipleciphers-<underlying>`.
|
|
37
|
+
s.capi.sqlite3mc_vfs_create(SAH_POOL_VFS_NAME, 0);
|
|
38
|
+
}
|
|
39
|
+
return pool;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Applies sqlite3mc's ChaCha20 page cipher using a pre-derived 32-byte key.
|
|
43
|
+
* The PRAGMAs must run before any schema DDL so sqlite3mc can decrypt existing
|
|
44
|
+
* pages and encrypt new ones. Zeroes the caller-held key array after the PRAGMA
|
|
45
|
+
* completes to minimize residency of the raw key bytes outside sqlite3mc's heap.
|
|
46
|
+
*/ function applyEncryptionKey(conn, key) {
|
|
47
|
+
const hex = Array.from(key, (b)=>b.toString(16).padStart(2, '0')).join('');
|
|
48
|
+
conn.exec(`PRAGMA cipher = 'chacha20'`);
|
|
49
|
+
conn.exec(`PRAGMA key = "x'${hex}'"`);
|
|
50
|
+
key.fill(0);
|
|
51
|
+
}
|
|
52
|
+
async function handleInit(dbName, ephemeral, directory, encryptionKey) {
|
|
53
|
+
const s = sqlite3 ??= await sqlite3InitModule();
|
|
54
|
+
if (encryptionKey !== undefined && ephemeral) {
|
|
55
|
+
throw new SqliteEncryptionError('encryption_not_supported_for_ephemeral', 'encryptionKey is not supported for ephemeral (:memory:) stores');
|
|
56
|
+
}
|
|
57
|
+
if (ephemeral) {
|
|
58
|
+
db = new s.oo1.DB(':memory:', 'c');
|
|
59
|
+
} else {
|
|
60
|
+
const activePool = await ensurePool(directory ?? DEFAULT_SAH_POOL_DIRECTORY);
|
|
61
|
+
dbPath = normalizeDbPath(dbName);
|
|
62
|
+
if (encryptionKey !== undefined) {
|
|
63
|
+
const conn = new s.oo1.DB({
|
|
64
|
+
filename: dbPath,
|
|
65
|
+
flags: 'c',
|
|
66
|
+
vfs: MC_SAH_POOL_VFS_NAME
|
|
67
|
+
});
|
|
68
|
+
db = conn;
|
|
69
|
+
applyEncryptionKey(conn, encryptionKey);
|
|
70
|
+
} else {
|
|
71
|
+
db = new activePool.OpfsSAHPoolDb(dbPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
runSql(SCHEMA_SQL);
|
|
75
|
+
}
|
|
76
|
+
function handleClose() {
|
|
77
|
+
try {
|
|
78
|
+
db?.close();
|
|
79
|
+
} finally{
|
|
80
|
+
db = undefined;
|
|
81
|
+
dbPath = undefined;
|
|
82
|
+
releasePool();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Releases the SAH pool's OPFS sync access handles before the terminal RPC is acked. Worker
|
|
87
|
+
* termination releases them only asynchronously, so without this a caller that deletes or reopens
|
|
88
|
+
* the store directory right after close()/delete() resolves races Chromium's cleanup
|
|
89
|
+
* (NoModificationAllowedError from removeEntry, or a hang installing a new pool on the directory).
|
|
90
|
+
* pauseVfs releases the handles without touching file contents; the worker is terminated right
|
|
91
|
+
* after, so the pool is never resumed.
|
|
92
|
+
*/ function releasePool() {
|
|
93
|
+
pool?.pauseVfs();
|
|
94
|
+
pool = undefined;
|
|
95
|
+
}
|
|
96
|
+
async function handleExport() {
|
|
97
|
+
if (!db || !dbPath) {
|
|
98
|
+
throw new Error('SQLite worker: no database open to export');
|
|
99
|
+
}
|
|
100
|
+
if (!pool) {
|
|
101
|
+
throw new Error('SQLite worker: no SAH Pool available (ephemeral DBs cannot be exported)');
|
|
102
|
+
}
|
|
103
|
+
return await pool.exportFile(dbPath);
|
|
104
|
+
}
|
|
105
|
+
function handleDeleteDb(dbName) {
|
|
106
|
+
const path = normalizeDbPath(dbName);
|
|
107
|
+
if (db && dbPath === path) {
|
|
108
|
+
db.close();
|
|
109
|
+
db = undefined;
|
|
110
|
+
dbPath = undefined;
|
|
111
|
+
}
|
|
112
|
+
// Ephemeral :memory: DBs never back a file — skip installing a pool just to unlink
|
|
113
|
+
// nothing. installOpfsSAHPoolVfs acquires an exclusive lock on the OPFS SAH
|
|
114
|
+
// directory, and under heavy test churn that can contend with workers from
|
|
115
|
+
// previous tests whose OPFS handles Chromium hasn't yet released, hanging the RPC
|
|
116
|
+
// and then the whole test run.
|
|
117
|
+
if (!pool) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
pool.unlink(path);
|
|
122
|
+
} catch {
|
|
123
|
+
// File may not exist; ignore.
|
|
124
|
+
}
|
|
125
|
+
// Guarded because pauseVfs refuses (SQLITE_MISUSE) while any file is open through the VFS.
|
|
126
|
+
if (!db) {
|
|
127
|
+
releasePool();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function requireDb() {
|
|
131
|
+
if (!db) {
|
|
132
|
+
throw new Error('SQLite worker: no database open');
|
|
133
|
+
}
|
|
134
|
+
return db;
|
|
135
|
+
}
|
|
136
|
+
function runSql(sql, bind) {
|
|
137
|
+
const conn = requireDb();
|
|
138
|
+
conn.exec({
|
|
139
|
+
sql,
|
|
140
|
+
bind
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
changes: conn.changes()
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function selectAll(sql, bind) {
|
|
147
|
+
const conn = requireDb();
|
|
148
|
+
const rows = [];
|
|
149
|
+
conn.exec({
|
|
150
|
+
sql,
|
|
151
|
+
bind,
|
|
152
|
+
rowMode: 'array',
|
|
153
|
+
resultRows: rows
|
|
154
|
+
});
|
|
155
|
+
return rows;
|
|
156
|
+
}
|
|
157
|
+
function normalizeDbPath(dbName) {
|
|
158
|
+
return dbName.startsWith('/') ? dbName : `/${dbName}`;
|
|
159
|
+
}
|
|
160
|
+
function respond(msg) {
|
|
161
|
+
self.postMessage(msg);
|
|
162
|
+
}
|
|
163
|
+
self.onmessage = async (ev)=>{
|
|
164
|
+
const req = ev.data;
|
|
165
|
+
try {
|
|
166
|
+
switch(req.type){
|
|
167
|
+
case 'init':
|
|
168
|
+
await handleInit(req.dbName, req.ephemeral, req.poolDirectory, req.encryptionKey);
|
|
169
|
+
return respond({
|
|
170
|
+
type: 'ok',
|
|
171
|
+
id: req.id
|
|
172
|
+
});
|
|
173
|
+
case 'close':
|
|
174
|
+
handleClose();
|
|
175
|
+
return respond({
|
|
176
|
+
type: 'ok',
|
|
177
|
+
id: req.id
|
|
178
|
+
});
|
|
179
|
+
case 'deleteDb':
|
|
180
|
+
handleDeleteDb(req.dbName);
|
|
181
|
+
return respond({
|
|
182
|
+
type: 'ok',
|
|
183
|
+
id: req.id
|
|
184
|
+
});
|
|
185
|
+
case 'run':
|
|
186
|
+
{
|
|
187
|
+
const { changes } = runSql(req.sql, req.bind);
|
|
188
|
+
return respond({
|
|
189
|
+
type: 'ok',
|
|
190
|
+
id: req.id,
|
|
191
|
+
changes
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
case 'all':
|
|
195
|
+
{
|
|
196
|
+
const rows = selectAll(req.sql, req.bind);
|
|
197
|
+
return respond({
|
|
198
|
+
type: 'ok',
|
|
199
|
+
id: req.id,
|
|
200
|
+
rows
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
case 'export':
|
|
204
|
+
{
|
|
205
|
+
const bytes = await handleExport();
|
|
206
|
+
return respond({
|
|
207
|
+
type: 'ok',
|
|
208
|
+
id: req.id,
|
|
209
|
+
bytes
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
case 'begin':
|
|
213
|
+
runSql('BEGIN');
|
|
214
|
+
return respond({
|
|
215
|
+
type: 'ok',
|
|
216
|
+
id: req.id
|
|
217
|
+
});
|
|
218
|
+
case 'commit':
|
|
219
|
+
runSql('COMMIT');
|
|
220
|
+
return respond({
|
|
221
|
+
type: 'ok',
|
|
222
|
+
id: req.id
|
|
223
|
+
});
|
|
224
|
+
case 'rollback':
|
|
225
|
+
runSql('ROLLBACK');
|
|
226
|
+
return respond({
|
|
227
|
+
type: 'ok',
|
|
228
|
+
id: req.id
|
|
229
|
+
});
|
|
230
|
+
default:
|
|
231
|
+
{
|
|
232
|
+
const _exhaustive = req;
|
|
233
|
+
throw new Error(`Unknown request: ${JSON.stringify(_exhaustive)}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} catch (err) {
|
|
237
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
238
|
+
const encryptionCode = detectEncryptionCode(req, err, message);
|
|
239
|
+
if (req.type === 'init') {
|
|
240
|
+
try {
|
|
241
|
+
handleClose();
|
|
242
|
+
} catch {
|
|
243
|
+
// The main thread terminates this worker after a failed init, which releases any remaining OPFS handles.
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
respond({
|
|
247
|
+
type: 'err',
|
|
248
|
+
id: req.id,
|
|
249
|
+
message,
|
|
250
|
+
encryptionCode
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Maps a thrown error during request handling to a typed encryption code, so the
|
|
256
|
+
* main thread can re-hydrate it as a {@link SqliteEncryptionError}. Returns
|
|
257
|
+
* `undefined` for non-encryption errors (preserves the existing untyped path).
|
|
258
|
+
*
|
|
259
|
+
* Two sources:
|
|
260
|
+
* - The error was already a `SqliteEncryptionError` (pre-flight throws inside
|
|
261
|
+
* this worker — e.g. ephemeral + encryptionKey). Forward its code as-is.
|
|
262
|
+
* - The error came from SQLite/sqlite3mc with a known decrypt-failure message
|
|
263
|
+
* during an `init` request. Both "wrong key supplied" and "no key supplied
|
|
264
|
+
* to an encrypted DB" surface as SQLITE_NOTADB ("file is not a database") —
|
|
265
|
+
* we don't constrain on `req.encryptionKey` because the no-key-on-encrypted-DB
|
|
266
|
+
* case is exactly when the caller most needs the typed signal.
|
|
267
|
+
*/ function detectEncryptionCode(req, err, message) {
|
|
268
|
+
if (err instanceof SqliteEncryptionError) {
|
|
269
|
+
return err.code;
|
|
270
|
+
}
|
|
271
|
+
if (req.type === 'init' && isDecryptFailureMessage(message)) {
|
|
272
|
+
return 'decrypt_failed';
|
|
273
|
+
}
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BlockNumber
|
|
2
|
-
import { type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
3
|
-
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type BlockHash, type CheckpointId, type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
4
3
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
5
4
|
/**
|
|
6
5
|
* Persistent implementation of L2 tips store backed by a KV store.
|
|
@@ -9,21 +8,16 @@ import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
|
9
8
|
export declare class L2TipsKVStore extends L2TipsStoreBase {
|
|
10
9
|
private store;
|
|
11
10
|
private readonly l2TipsStore;
|
|
11
|
+
private readonly l2TipCheckpointsStore;
|
|
12
12
|
private readonly l2BlockHashesStore;
|
|
13
|
-
|
|
14
|
-
private readonly l2CheckpointStore;
|
|
15
|
-
constructor(store: AztecAsyncKVStore, namespace: string);
|
|
13
|
+
constructor(store: AztecAsyncKVStore, namespace: string, initialBlockHash: BlockHash);
|
|
16
14
|
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined>;
|
|
17
15
|
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void>;
|
|
16
|
+
protected getTipCheckpoint(tag: L2BlockTag): Promise<CheckpointId | undefined>;
|
|
17
|
+
protected setTipCheckpoint(tag: L2BlockTag, checkpoint: CheckpointId): Promise<void>;
|
|
18
18
|
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined>;
|
|
19
19
|
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void>;
|
|
20
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
21
|
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
28
22
|
}
|
|
29
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
23
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3Jlcy9sMl90aXBzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQW9CLE1BQU0saUNBQWlDLENBQUM7QUFDaEYsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUFFLEtBQUssWUFBWSxFQUFFLEtBQUssVUFBVSxFQUFFLGVBQWUsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRzFHLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFLaEU7OztHQUdHO0FBQ0gscUJBQWEsYUFBYyxTQUFRLGVBQWU7SUFNOUMsT0FBTyxDQUFDLEtBQUs7SUFMZixPQUFPLENBQUMsUUFBUSxDQUFDLFdBQVcsQ0FBeUM7SUFDckUsT0FBTyxDQUFDLFFBQVEsQ0FBQyxxQkFBcUIsQ0FBZ0Q7SUFDdEYsT0FBTyxDQUFDLFFBQVEsQ0FBQyxrQkFBa0IsQ0FBcUM7SUFFeEUsWUFDVSxLQUFLLEVBQUUsaUJBQWlCLEVBQ2hDLFNBQVMsRUFBRSxNQUFNLEVBQ2pCLGdCQUFnQixFQUFFLFNBQVMsRUFNNUI7SUFFRCxTQUFTLENBQUMsTUFBTSxDQUFDLEdBQUcsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsR0FBRyxTQUFTLENBQUMsQ0FFbEU7SUFFRCxTQUFTLENBQUMsTUFBTSxDQUFDLEdBQUcsRUFBRSxVQUFVLEVBQUUsV0FBVyxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRXpFO0lBRUQsVUFBZ0IsZ0JBQWdCLENBQUMsR0FBRyxFQUFFLFVBQVUsR0FBRyxPQUFPLENBQUMsWUFBWSxHQUFHLFNBQVMsQ0FBQyxDQU1uRjtJQUVELFNBQVMsQ0FBQyxnQkFBZ0IsQ0FBQyxHQUFHLEVBQUUsVUFBVSxFQUFFLFVBQVUsRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUVuRjtJQUVELFNBQVMsQ0FBQyxrQkFBa0IsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBRWxGO0lBRUQsU0FBUyxDQUFDLFlBQVksQ0FBQyxXQUFXLEVBQUUsV0FBVyxFQUFFLElBQUksRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUU1RTtJQUVELFVBQWdCLHVCQUF1QixDQUFDLFdBQVcsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUkvRTtJQUVELFNBQVMsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLEVBQUUsRUFBRSxFQUFFLE1BQU0sT0FBTyxDQUFDLENBQUMsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FFOUQ7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG1G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAKhE;;;GAGG;AACH,qBAAa,aAAc,SAAQ,eAAe;IAM9C,OAAO,CAAC,KAAK;IALf,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyC;IACrE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAgD;IACtF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqC;IAExE,YACU,KAAK,EAAE,iBAAiB,EAChC,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,SAAS,EAM5B;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,UAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAMnF;IAED,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnF;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,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE9D;CACF"}
|
|
@@ -1,31 +1,26 @@
|
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
2
|
-
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
3
3
|
/**
|
|
4
4
|
* Persistent implementation of L2 tips store backed by a KV store.
|
|
5
5
|
* Used by nodes that need to persist chain state across restarts.
|
|
6
6
|
*/ export class L2TipsKVStore extends L2TipsStoreBase {
|
|
7
7
|
store;
|
|
8
8
|
l2TipsStore;
|
|
9
|
+
l2TipCheckpointsStore;
|
|
9
10
|
l2BlockHashesStore;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(store, namespace){
|
|
13
|
-
super(), this.store = store;
|
|
11
|
+
constructor(store, namespace, initialBlockHash){
|
|
12
|
+
super(initialBlockHash), this.store = store;
|
|
14
13
|
this.l2TipsStore = store.openMap([
|
|
15
14
|
namespace,
|
|
16
15
|
'l2_tips'
|
|
17
16
|
].join('_'));
|
|
18
|
-
this.
|
|
19
|
-
namespace,
|
|
20
|
-
'l2_block_hashes'
|
|
21
|
-
].join('_'));
|
|
22
|
-
this.l2BlockNumberToCheckpointNumberStore = store.openMap([
|
|
17
|
+
this.l2TipCheckpointsStore = store.openMap([
|
|
23
18
|
namespace,
|
|
24
|
-
'
|
|
19
|
+
'l2_tip_checkpoints'
|
|
25
20
|
].join('_'));
|
|
26
|
-
this.
|
|
21
|
+
this.l2BlockHashesStore = store.openMap([
|
|
27
22
|
namespace,
|
|
28
|
-
'
|
|
23
|
+
'l2_block_hashes'
|
|
29
24
|
].join('_'));
|
|
30
25
|
}
|
|
31
26
|
getTip(tag) {
|
|
@@ -34,6 +29,22 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
|
34
29
|
setTip(tag, blockNumber) {
|
|
35
30
|
return this.l2TipsStore.set(tag, blockNumber);
|
|
36
31
|
}
|
|
32
|
+
async getTipCheckpoint(tag) {
|
|
33
|
+
const stored = await this.l2TipCheckpointsStore.getAsync(tag);
|
|
34
|
+
if (stored === undefined) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
number: CheckpointNumber(stored.number),
|
|
39
|
+
hash: stored.hash
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
setTipCheckpoint(tag, checkpoint) {
|
|
43
|
+
return this.l2TipCheckpointsStore.set(tag, {
|
|
44
|
+
number: checkpoint.number,
|
|
45
|
+
hash: checkpoint.hash
|
|
46
|
+
});
|
|
47
|
+
}
|
|
37
48
|
getStoredBlockHash(blockNumber) {
|
|
38
49
|
return this.l2BlockHashesStore.getAsync(blockNumber);
|
|
39
50
|
}
|
|
@@ -47,36 +58,6 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
|
47
58
|
await this.l2BlockHashesStore.delete(key);
|
|
48
59
|
}
|
|
49
60
|
}
|
|
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;
|
|
67
|
-
}
|
|
68
|
-
return PublishedCheckpoint.fromBuffer(buffer);
|
|
69
|
-
}
|
|
70
|
-
saveCheckpointData(checkpoint) {
|
|
71
|
-
return this.l2CheckpointStore.set(checkpoint.checkpoint.number, checkpoint.toBuffer());
|
|
72
|
-
}
|
|
73
|
-
async deleteCheckpointsBefore(checkpointNumber) {
|
|
74
|
-
for await (const key of this.l2CheckpointStore.keysAsync({
|
|
75
|
-
end: checkpointNumber
|
|
76
|
-
})){
|
|
77
|
-
await this.l2CheckpointStore.delete(key);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
61
|
runInTransaction(fn) {
|
|
81
62
|
return this.store.transactionAsync(fn);
|
|
82
63
|
}
|
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=data:application/json;base64,
|
|
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,23 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.c52d6e7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
7
7
|
"./interfaces": "./dest/interfaces/index.js",
|
|
8
8
|
"./lmdb": "./dest/lmdb/index.js",
|
|
9
9
|
"./lmdb-v2": "./dest/lmdb-v2/index.js",
|
|
10
|
-
"./indexeddb": "./dest/indexeddb/index.js",
|
|
11
|
-
"./
|
|
12
|
-
"./
|
|
10
|
+
"./deprecated/indexeddb": "./dest/deprecated/indexeddb/index.js",
|
|
11
|
+
"./sqlite-opfs": "./dest/sqlite-opfs/index.js",
|
|
12
|
+
"./stores": "./dest/stores/index.js"
|
|
13
|
+
},
|
|
14
|
+
"imports": {
|
|
15
|
+
"#msgpackr": {
|
|
16
|
+
"browser": "msgpackr/index-no-eval",
|
|
17
|
+
"default": "msgpackr"
|
|
18
|
+
},
|
|
19
|
+
"#ordered-binary": {
|
|
20
|
+
"browser": "./dest/sqlite-opfs/internal/ordered-binary-browser.js",
|
|
21
|
+
"default": "ordered-binary"
|
|
22
|
+
}
|
|
13
23
|
},
|
|
14
24
|
"scripts": {
|
|
15
25
|
"build": "yarn clean && ../scripts/tsc.sh",
|
|
16
26
|
"build:dev": "../scripts/tsc.sh --watch",
|
|
17
27
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
18
|
-
"test:node": "
|
|
19
|
-
"test:browser": "
|
|
20
|
-
"
|
|
28
|
+
"test:node": "vitest run --project node",
|
|
29
|
+
"test:browser": "bash scripts/run-browser-tests.sh",
|
|
30
|
+
"bench:browser": "VITE_BENCH=1 vitest run --project browser src/bench",
|
|
31
|
+
"test": "vitest run",
|
|
21
32
|
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
22
33
|
},
|
|
23
34
|
"inherits": [
|
|
@@ -25,11 +36,12 @@
|
|
|
25
36
|
"./package.local.json"
|
|
26
37
|
],
|
|
27
38
|
"dependencies": {
|
|
28
|
-
"@aztec/constants": "0.0.1-commit.
|
|
29
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
30
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
31
|
-
"@aztec/native": "0.0.1-commit.
|
|
32
|
-
"@aztec/
|
|
39
|
+
"@aztec/constants": "0.0.1-commit.c52d6e7",
|
|
40
|
+
"@aztec/ethereum": "0.0.1-commit.c52d6e7",
|
|
41
|
+
"@aztec/foundation": "0.0.1-commit.c52d6e7",
|
|
42
|
+
"@aztec/native": "0.0.1-commit.c52d6e7",
|
|
43
|
+
"@aztec/sqlite3mc-wasm": "0.0.1-commit.c52d6e7",
|
|
44
|
+
"@aztec/stdlib": "0.0.1-commit.c52d6e7",
|
|
33
45
|
"idb": "^8.0.0",
|
|
34
46
|
"lmdb": "^3.2.0",
|
|
35
47
|
"msgpackr": "^1.11.2",
|
|
@@ -38,25 +50,17 @@
|
|
|
38
50
|
},
|
|
39
51
|
"devDependencies": {
|
|
40
52
|
"@jest/globals": "^30.0.0",
|
|
41
|
-
"@types/chai": "^5.0.1",
|
|
42
|
-
"@types/chai-as-promised": "^8.0.1",
|
|
43
53
|
"@types/jest": "^30.0.0",
|
|
44
|
-
"@types/mocha": "^10.0.10",
|
|
45
|
-
"@types/mocha-each": "^2.0.4",
|
|
46
54
|
"@types/node": "^22.15.17",
|
|
47
|
-
"@types/sinon": "^17.0.3",
|
|
48
55
|
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"@web/test-runner-playwright": "^0.11.0",
|
|
52
|
-
"chai": "^5.1.2",
|
|
53
|
-
"chai-as-promised": "^8.0.1",
|
|
56
|
+
"@vitest/browser-playwright": "^4.0.0",
|
|
57
|
+
"buffer": "^6.0.3",
|
|
54
58
|
"jest": "^30.0.0",
|
|
55
|
-
"
|
|
56
|
-
"mocha-each": "^2.0.1",
|
|
57
|
-
"sinon": "^19.0.2",
|
|
59
|
+
"playwright": "1.49.0",
|
|
58
60
|
"ts-node": "^10.9.1",
|
|
59
|
-
"typescript": "^5.3.3"
|
|
61
|
+
"typescript": "^5.3.3",
|
|
62
|
+
"util": "^0.12.5",
|
|
63
|
+
"vitest": "^4.0.0"
|
|
60
64
|
},
|
|
61
65
|
"files": [
|
|
62
66
|
"dest",
|