@ocap/statedb-sqlite 1.31.3 → 1.31.5
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/esm/db.d.mts +1 -1
- package/esm/db.mjs +69 -24
- package/esm/kysely.d.mts +5 -0
- package/esm/kysely.mjs +2 -2
- package/esm/reconcile.d.mts +3 -3
- package/esm/reconcile.mjs +40 -26
- package/esm/table/balance.mjs +6 -3
- package/esm/table/base.mjs +13 -12
- package/esm/tombstone-cleanup.mjs +4 -1
- package/lib/db.cjs +69 -24
- package/lib/db.d.cts +1 -1
- package/lib/kysely.cjs +2 -2
- package/lib/kysely.d.cts +5 -0
- package/lib/reconcile.cjs +40 -26
- package/lib/reconcile.d.cts +3 -3
- package/lib/table/balance.cjs +6 -3
- package/lib/table/base.cjs +13 -12
- package/lib/tombstone-cleanup.cjs +4 -1
- package/package.json +8 -8
package/esm/db.d.mts
CHANGED
|
@@ -81,7 +81,6 @@ declare class SqliteStateDB extends StateDB implements IStateDB {
|
|
|
81
81
|
/**
|
|
82
82
|
* Fail startup instead of failing every reserve-tracking rollup write later (#1548): a file whose migration
|
|
83
83
|
* bookkeeping says 004 ran but whose `rollup` table lacks the columns (copied/hand-built DB) must not open.
|
|
84
|
-
* Mirrors the Dolt backend's `rollup.reserves` startup guard.
|
|
85
84
|
*/
|
|
86
85
|
private assertRollupReserveColumns;
|
|
87
86
|
/**
|
|
@@ -95,6 +94,7 @@ declare class SqliteStateDB extends StateDB implements IStateDB {
|
|
|
95
94
|
}>;
|
|
96
95
|
private startWalCheckpointWorker;
|
|
97
96
|
private ensureStateCommitTable;
|
|
97
|
+
private hasPopulatedStateTables;
|
|
98
98
|
private ensureTrustedStorageInitialized;
|
|
99
99
|
/**
|
|
100
100
|
* Get the current and previous state commit hash tracked in SQLite StateDB.
|
package/esm/db.mjs
CHANGED
|
@@ -216,21 +216,23 @@ var SqliteStateDB = class extends StateDB {
|
|
|
216
216
|
*/
|
|
217
217
|
async initialize() {
|
|
218
218
|
this.closed = false;
|
|
219
|
+
const allowTrustedRecovery = !this.config.readonly;
|
|
219
220
|
if (this.initialized) {
|
|
220
|
-
if (this.trustedStorage && !this.trustedInitialized) await this.ensureTrustedStorageInitialized(
|
|
221
|
+
if (this.trustedStorage && !this.trustedInitialized) await this.ensureTrustedStorageInitialized(allowTrustedRecovery);
|
|
221
222
|
this.startWalCheckpointWorker();
|
|
222
223
|
return;
|
|
223
224
|
}
|
|
224
|
-
|
|
225
|
-
|
|
225
|
+
if (!this.config.readonly) {
|
|
226
|
+
await runMigrations(this.db);
|
|
227
|
+
await this.assertRollupReserveColumns();
|
|
228
|
+
}
|
|
226
229
|
this.initialized = true;
|
|
227
|
-
if (this.trustedStorage) await this.ensureTrustedStorageInitialized(
|
|
230
|
+
if (this.trustedStorage) await this.ensureTrustedStorageInitialized(allowTrustedRecovery);
|
|
228
231
|
this.startWalCheckpointWorker();
|
|
229
232
|
}
|
|
230
233
|
/**
|
|
231
234
|
* Fail startup instead of failing every reserve-tracking rollup write later (#1548): a file whose migration
|
|
232
235
|
* bookkeeping says 004 ran but whose `rollup` table lacks the columns (copied/hand-built DB) must not open.
|
|
233
|
-
* Mirrors the Dolt backend's `rollup.reserves` startup guard.
|
|
234
236
|
*/
|
|
235
237
|
async assertRollupReserveColumns() {
|
|
236
238
|
const { rows } = await sql`SELECT name FROM pragma_table_info('rollup')`.execute(this.db);
|
|
@@ -286,7 +288,7 @@ var SqliteStateDB = class extends StateDB {
|
|
|
286
288
|
if (typeof this.walCheckpointTimer.unref === "function") this.walCheckpointTimer.unref();
|
|
287
289
|
}
|
|
288
290
|
async ensureStateCommitTable() {
|
|
289
|
-
if (this.stateCommitTableReady) return;
|
|
291
|
+
if (this.stateCommitTableReady || this.config.readonly) return;
|
|
290
292
|
await sql`
|
|
291
293
|
CREATE TABLE IF NOT EXISTS "_state_commit" (
|
|
292
294
|
"id" INTEGER PRIMARY KEY CHECK ("id" = 1),
|
|
@@ -302,15 +304,42 @@ var SqliteStateDB = class extends StateDB {
|
|
|
302
304
|
`.execute(this.db);
|
|
303
305
|
this.stateCommitTableReady = true;
|
|
304
306
|
}
|
|
307
|
+
async hasPopulatedStateTables() {
|
|
308
|
+
for (const table of [
|
|
309
|
+
"chain",
|
|
310
|
+
"account",
|
|
311
|
+
"balance",
|
|
312
|
+
"token",
|
|
313
|
+
"tx",
|
|
314
|
+
"asset",
|
|
315
|
+
"stake",
|
|
316
|
+
"factory",
|
|
317
|
+
"delegation",
|
|
318
|
+
"rollup",
|
|
319
|
+
"rollupBlock",
|
|
320
|
+
"evidence",
|
|
321
|
+
"tokenFactory"
|
|
322
|
+
]) try {
|
|
323
|
+
if ((await sql`SELECT 1 AS present FROM ${sql.table(table)} LIMIT 1`.execute(this.db)).rows.length > 0) return true;
|
|
324
|
+
} catch {}
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
305
327
|
async ensureTrustedStorageInitialized(allowForwardRecovery = false) {
|
|
306
328
|
if (!this.trustedStorage || this.trustedInitialized) return;
|
|
307
329
|
await this.ensureStateCommitTable();
|
|
308
|
-
if (typeof this.trustedStorage.initStorage === "function") await this.trustedStorage.initStorage();
|
|
330
|
+
if (!this.config.readonly && typeof this.trustedStorage.initStorage === "function") await this.trustedStorage.initStorage();
|
|
309
331
|
if (!await this.trustedStorage.getHash()) {
|
|
310
|
-
const { currentHash } = await this.getCommitHash();
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
332
|
+
const { currentHash, prevHash, seq = 0 } = await this.getCommitHash();
|
|
333
|
+
if (!(seq === 0 && currentHash === "GENESIS" && !prevHash && !await this.hasPopulatedStateTables()) && !this.config.allowTrustedBootstrap) {
|
|
334
|
+
const err = /* @__PURE__ */ new Error("Trusted hash verification failed");
|
|
335
|
+
err.code = "INVALID_HASH";
|
|
336
|
+
throw err;
|
|
337
|
+
}
|
|
338
|
+
if (!this.config.readonly) {
|
|
339
|
+
const newTrustedHash = await this.trustedStorage.createHash(currentHash);
|
|
340
|
+
await this.trustedStorage.writeHash(newTrustedHash);
|
|
341
|
+
}
|
|
342
|
+
} else await this.verifyTrustedHashInternal(allowForwardRecovery && !this.config.readonly);
|
|
314
343
|
this.trustedInitialized = true;
|
|
315
344
|
}
|
|
316
345
|
/**
|
|
@@ -325,16 +354,29 @@ var SqliteStateDB = class extends StateDB {
|
|
|
325
354
|
* checkpoints and self-verifying segments.
|
|
326
355
|
*/
|
|
327
356
|
async getCommitHash(executor = this.db) {
|
|
328
|
-
if (!this.stateCommitTableReady) await this.ensureStateCommitTable();
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
357
|
+
if (!this.stateCommitTableReady && !this.config.readonly) await this.ensureStateCommitTable();
|
|
358
|
+
try {
|
|
359
|
+
const row = (await sql`
|
|
360
|
+
SELECT "current_hash", "prev_hash", "seq", "msg" FROM "_state_commit" WHERE "id" = 1
|
|
361
|
+
`.execute(executor)).rows[0];
|
|
362
|
+
return {
|
|
363
|
+
currentHash: row?.current_hash || "GENESIS",
|
|
364
|
+
prevHash: row?.prev_hash || "",
|
|
365
|
+
seq: Number(row?.seq || 0),
|
|
366
|
+
msg: row?.msg || ""
|
|
367
|
+
};
|
|
368
|
+
} catch (err) {
|
|
369
|
+
if (this.config.readonly) {
|
|
370
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
371
|
+
if (/no such table/i.test(msg)) return {
|
|
372
|
+
currentHash: "GENESIS",
|
|
373
|
+
prevHash: "",
|
|
374
|
+
seq: 0,
|
|
375
|
+
msg: ""
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
throw err;
|
|
379
|
+
}
|
|
338
380
|
}
|
|
339
381
|
async verifyTrustedHashInternal(allowForwardRecovery = false) {
|
|
340
382
|
if (!this.trustedStorage) return;
|
|
@@ -355,9 +397,10 @@ var SqliteStateDB = class extends StateDB {
|
|
|
355
397
|
*/
|
|
356
398
|
async verifyTrustedHash() {
|
|
357
399
|
if (!this.trustedStorage) return;
|
|
400
|
+
const allowRecovery = !this.config.readonly;
|
|
358
401
|
await this.enqueueCommit(async () => {
|
|
359
|
-
await this.ensureTrustedStorageInitialized(
|
|
360
|
-
await this.verifyTrustedHashInternal(
|
|
402
|
+
await this.ensureTrustedStorageInitialized(allowRecovery);
|
|
403
|
+
await this.verifyTrustedHashInternal(allowRecovery);
|
|
361
404
|
});
|
|
362
405
|
}
|
|
363
406
|
enqueueCommit(task) {
|
|
@@ -378,6 +421,7 @@ var SqliteStateDB = class extends StateDB {
|
|
|
378
421
|
return this.executeRunAsLambda(fn, options);
|
|
379
422
|
}
|
|
380
423
|
async executeRunAsLambda(fn, options = {}) {
|
|
424
|
+
if (this.config.readonly) throw new Error("Cannot execute runAsLambda on a SqliteStateDB opened in readonly mode");
|
|
381
425
|
const { retryLimit = 5, verifyHash = false, commitMessage } = options;
|
|
382
426
|
if (!this.stateCommitTableReady) await this.ensureStateCommitTable();
|
|
383
427
|
if (this.trustedStorage) {
|
|
@@ -454,6 +498,7 @@ var SqliteStateDB = class extends StateDB {
|
|
|
454
498
|
* Reset all tables (for testing)
|
|
455
499
|
*/
|
|
456
500
|
async reset() {
|
|
501
|
+
if (this.config.readonly) throw new Error("Cannot reset a SqliteStateDB opened in readonly mode");
|
|
457
502
|
const tables = Object.keys(this.readyMarks);
|
|
458
503
|
for (const table of tables) {
|
|
459
504
|
const tableInstance = this[table];
|
|
@@ -484,7 +529,7 @@ var SqliteStateDB = class extends StateDB {
|
|
|
484
529
|
if (this.walCheckpointPromise) await this.walCheckpointPromise.catch(() => void 0);
|
|
485
530
|
await this.commitQueue;
|
|
486
531
|
await this.db.destroy();
|
|
487
|
-
if (this.trustedStorage && typeof this.trustedStorage.destroy === "function") await this.trustedStorage.destroy();
|
|
532
|
+
if (this.trustedStorage && typeof this.trustedStorage.destroy === "function" && this.trustedStorage.filename !== ":memory:") await this.trustedStorage.destroy();
|
|
488
533
|
}
|
|
489
534
|
/**
|
|
490
535
|
* Get the canonical SHA-256 digest of the write-set from the most recently committed `runAsLambda` transaction.
|
package/esm/kysely.d.mts
CHANGED
|
@@ -59,6 +59,11 @@ interface SqliteConfig {
|
|
|
59
59
|
dialect?: Dialect;
|
|
60
60
|
/** Optional trusted storage instance for state commit hash verification */
|
|
61
61
|
trustedStorage?: ITrustedStorage;
|
|
62
|
+
/**
|
|
63
|
+
* Explicitly allow bootstrapping an empty `trustedStorage` onto an already-populated StateDB
|
|
64
|
+
* (only set by operator `--force` recovery tools; false by default so wiped `trusted.sqlite` fails closed).
|
|
65
|
+
*/
|
|
66
|
+
allowTrustedBootstrap?: boolean;
|
|
62
67
|
/** Open database in readonly mode */
|
|
63
68
|
readonly?: boolean;
|
|
64
69
|
/** Throw error if file doesn't exist (default: false, creates new file) */
|
package/esm/kysely.mjs
CHANGED
|
@@ -1545,7 +1545,7 @@ function createKysely(config) {
|
|
|
1545
1545
|
const { BunSqliteDialect } = bunReq("kysely-bun-sqlite");
|
|
1546
1546
|
const { Database: BunDatabase } = bunReq("bun:sqlite");
|
|
1547
1547
|
const sqlite$1 = new BunDatabase(filename, {
|
|
1548
|
-
create: config.create !== false,
|
|
1548
|
+
create: config.readonly && filename !== ":memory:" ? false : config.create !== false,
|
|
1549
1549
|
readonly: config.readonly === true
|
|
1550
1550
|
});
|
|
1551
1551
|
if (config.walMode !== false && !config.readonly && filename !== ":memory:") {
|
|
@@ -1560,7 +1560,7 @@ function createKysely(config) {
|
|
|
1560
1560
|
}
|
|
1561
1561
|
const sqlite = new (__require("better-sqlite3"))(filename, {
|
|
1562
1562
|
readonly: config.readonly === true,
|
|
1563
|
-
fileMustExist: config.create === false
|
|
1563
|
+
fileMustExist: config.readonly === true || config.create === false
|
|
1564
1564
|
});
|
|
1565
1565
|
if (config.walMode !== false && !config.readonly && filename !== ":memory:") {
|
|
1566
1566
|
sqlite.pragma("journal_mode = WAL");
|
package/esm/reconcile.d.mts
CHANGED
|
@@ -41,8 +41,8 @@ interface ReconcileOptions {
|
|
|
41
41
|
dryRun?: boolean;
|
|
42
42
|
/**
|
|
43
43
|
* Required when `dryRun: false`. Reconcile `--apply` writes SQLite rows directly and bypasses all protocol
|
|
44
|
-
* validation (no tx, no ledger entry), so it must be an explicit operator decision. Never
|
|
45
|
-
*
|
|
44
|
+
* validation (no tx, no ledger entry), so it must be an explicit operator decision. Never run it against a live
|
|
45
|
+
* node's files while the node is running.
|
|
46
46
|
*/
|
|
47
47
|
allowProtocolBypass?: boolean;
|
|
48
48
|
/** Reconcile token.totalSupply (and active tokenFactory.currentSupply) to match authoritative holder + revoked balances. */
|
|
@@ -65,7 +65,7 @@ interface ReconcileResult {
|
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Verification and reconcile are SQLite-only (they query SQLite tables through kysely). Fail loudly when given
|
|
68
|
-
* any other backend (e.g. statedb-
|
|
68
|
+
* any other backend (e.g. statedb-memory) instead of crashing midway or silently skipping.
|
|
69
69
|
*/
|
|
70
70
|
declare function assertSqliteStateDb(db: unknown): void;
|
|
71
71
|
/**
|
package/esm/reconcile.mjs
CHANGED
|
@@ -7,11 +7,11 @@ import { toStakeAddress, toTokenCharterAssetAddress } from "@arcblock/did-util";
|
|
|
7
7
|
//#region src/reconcile.ts
|
|
8
8
|
/**
|
|
9
9
|
* Verification and reconcile are SQLite-only (they query SQLite tables through kysely). Fail loudly when given
|
|
10
|
-
* any other backend (e.g. statedb-
|
|
10
|
+
* any other backend (e.g. statedb-memory) instead of crashing midway or silently skipping.
|
|
11
11
|
*/
|
|
12
12
|
function assertSqliteStateDb(db) {
|
|
13
13
|
const candidate = db;
|
|
14
|
-
if (!candidate || typeof candidate.getKysely !== "function") throw new Error("Chain state verify/reconcile only supports @ocap/statedb-sqlite.
|
|
14
|
+
if (!candidate || typeof candidate.getKysely !== "function") throw new Error("Chain state verify/reconcile only supports @ocap/statedb-sqlite. Other backends are not supported.");
|
|
15
15
|
}
|
|
16
16
|
const CANONICAL_UINT_REGEX = /^\d+$/;
|
|
17
17
|
function parseJsonColumn(raw, fallback) {
|
|
@@ -494,6 +494,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
494
494
|
assertSqliteStateDb(db);
|
|
495
495
|
const dryRun = options.dryRun !== false;
|
|
496
496
|
if (!dryRun && options.allowProtocolBypass !== true) throw new Error("reconcileChainState({ dryRun: false }) writes directly to SQLite and bypasses protocol validation; pass allowProtocolBypass: true to confirm");
|
|
497
|
+
if (!dryRun && db.trustedStorage) await db.verifyTrustedHash();
|
|
497
498
|
const beforeReport = await verifyChainStateInvariants(db, { ledger: options.ledger });
|
|
498
499
|
const actions = [];
|
|
499
500
|
if (beforeReport.valid) return {
|
|
@@ -503,7 +504,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
503
504
|
afterReport: beforeReport,
|
|
504
505
|
actions
|
|
505
506
|
};
|
|
506
|
-
const executeRepairs = async (executor) => {
|
|
507
|
+
const executeRepairs = async (executor, applyWrites, targetActions) => {
|
|
507
508
|
const allBalances = await executor.selectFrom("balance").selectAll().execute();
|
|
508
509
|
for (const row of allBalances) {
|
|
509
510
|
const addr = String(row.address || "");
|
|
@@ -511,7 +512,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
511
512
|
const balStr = String(row.balance ?? "0");
|
|
512
513
|
const checksumAddr = ensureChecksumAddress(addr);
|
|
513
514
|
if (CANONICAL_UINT_REGEX.test(balStr) && new BN(balStr, 10).isZero()) {
|
|
514
|
-
|
|
515
|
+
targetActions.push({
|
|
515
516
|
code: "I-BAL-3",
|
|
516
517
|
table: "balance",
|
|
517
518
|
key: `${addr}:${tokAddr}`,
|
|
@@ -523,13 +524,13 @@ async function reconcileChainState(db, options = {}) {
|
|
|
523
524
|
},
|
|
524
525
|
after: null
|
|
525
526
|
});
|
|
526
|
-
if (
|
|
527
|
+
if (applyWrites) await executor.deleteFrom("balance").where("address", "=", addr).where("tokenAddress", "=", tokAddr).execute();
|
|
527
528
|
continue;
|
|
528
529
|
}
|
|
529
530
|
if (checksumAddr !== addr && CANONICAL_UINT_REGEX.test(balStr)) {
|
|
530
531
|
const existingCanonical = await executor.selectFrom("balance").selectAll().where("address", "=", checksumAddr).where("tokenAddress", "=", tokAddr).executeTakeFirst();
|
|
531
532
|
const mergedBalance = existingCanonical && CANONICAL_UINT_REGEX.test(String(existingCanonical.balance)) ? new BN(String(existingCanonical.balance), 10).add(new BN(balStr, 10)).toString(10) : balStr;
|
|
532
|
-
|
|
533
|
+
targetActions.push({
|
|
533
534
|
code: "I-BAL-1",
|
|
534
535
|
table: "balance",
|
|
535
536
|
key: `${addr}:${tokAddr}`,
|
|
@@ -545,7 +546,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
545
546
|
balance: mergedBalance
|
|
546
547
|
}
|
|
547
548
|
});
|
|
548
|
-
if (
|
|
549
|
+
if (applyWrites) {
|
|
549
550
|
await executor.deleteFrom("balance").where("address", "=", addr).where("tokenAddress", "=", tokAddr).execute();
|
|
550
551
|
await executor.insertInto("balance").values({
|
|
551
552
|
address: checksumAddr,
|
|
@@ -600,7 +601,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
600
601
|
if (!nextMigratedFrom.includes(acc.address)) {
|
|
601
602
|
const updatedFrom = [...nextMigratedFrom, acc.address];
|
|
602
603
|
nextAcc.migratedFrom = JSON.stringify(updatedFrom);
|
|
603
|
-
|
|
604
|
+
targetActions.push({
|
|
604
605
|
code: "I-MIG-1",
|
|
605
606
|
table: "account",
|
|
606
607
|
key: nextHop,
|
|
@@ -608,7 +609,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
608
609
|
before: nextMigratedFrom,
|
|
609
610
|
after: updatedFrom
|
|
610
611
|
});
|
|
611
|
-
if (
|
|
612
|
+
if (applyWrites) await executor.updateTable("account").set({ migratedFrom: JSON.stringify(updatedFrom) }).where("address", "=", nextHop).execute();
|
|
612
613
|
}
|
|
613
614
|
}
|
|
614
615
|
const zombieRows = await executor.selectFrom("balance").selectAll().where("address", "=", acc.address).execute();
|
|
@@ -627,7 +628,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
627
628
|
const forwardPortion = zBal.sub(zombiePortion);
|
|
628
629
|
if (zombiePortion.gt(new BN(0))) runningAccountedSupply.set(tokAddr, accountedSupply.sub(zombiePortion));
|
|
629
630
|
if (forwardPortion.isZero()) {
|
|
630
|
-
|
|
631
|
+
targetActions.push({
|
|
631
632
|
code: "I-BAL-2",
|
|
632
633
|
table: "balance",
|
|
633
634
|
key: `${acc.address}:${tokAddr}`,
|
|
@@ -639,12 +640,12 @@ async function reconcileChainState(db, options = {}) {
|
|
|
639
640
|
},
|
|
640
641
|
after: null
|
|
641
642
|
});
|
|
642
|
-
if (
|
|
643
|
+
if (applyWrites) await executor.deleteFrom("balance").where("address", "=", acc.address).where("tokenAddress", "=", tokAddr).execute();
|
|
643
644
|
} else {
|
|
644
645
|
const nextTermBalBn = termBal.add(forwardPortion);
|
|
645
646
|
const nextTermBal = nextTermBalBn.toString(10);
|
|
646
647
|
liveBalanceMap.set(termBalKey, nextTermBalBn);
|
|
647
|
-
|
|
648
|
+
targetActions.push({
|
|
648
649
|
code: "I-BAL-2",
|
|
649
650
|
table: "balance",
|
|
650
651
|
key: `${acc.address}:${tokAddr}`,
|
|
@@ -668,7 +669,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
668
669
|
deletedDuplicateZombiePortion: zombiePortion.toString(10)
|
|
669
670
|
}
|
|
670
671
|
});
|
|
671
|
-
if (
|
|
672
|
+
if (applyWrites) {
|
|
672
673
|
await executor.deleteFrom("balance").where("address", "=", acc.address).where("tokenAddress", "=", tokAddr).execute();
|
|
673
674
|
await executor.insertInto("balance").values({
|
|
674
675
|
address: terminalAddr,
|
|
@@ -681,7 +682,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
681
682
|
}
|
|
682
683
|
const orphanAssets = await executor.selectFrom("asset").selectAll().where("owner", "=", acc.address).execute();
|
|
683
684
|
for (const ast of orphanAssets) {
|
|
684
|
-
|
|
685
|
+
targetActions.push({
|
|
685
686
|
code: "I-AST-1",
|
|
686
687
|
table: "asset",
|
|
687
688
|
key: ast.address,
|
|
@@ -689,7 +690,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
689
690
|
before: { owner: acc.address },
|
|
690
691
|
after: { owner: terminalAddr }
|
|
691
692
|
});
|
|
692
|
-
if (
|
|
693
|
+
if (applyWrites) await executor.updateTable("asset").set({ owner: terminalAddr }).where("address", "=", ast.address).execute();
|
|
693
694
|
}
|
|
694
695
|
}
|
|
695
696
|
const stakes = await executor.selectFrom("stake").selectAll().execute();
|
|
@@ -709,7 +710,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
709
710
|
return Boolean(a && a.owner === stk.address);
|
|
710
711
|
});
|
|
711
712
|
if (validActive.length !== activeAssets.length || validRevoked.length !== revokedAssets.length) {
|
|
712
|
-
|
|
713
|
+
targetActions.push({
|
|
713
714
|
code: "I-STK-1",
|
|
714
715
|
table: "stake",
|
|
715
716
|
key: stk.address,
|
|
@@ -723,7 +724,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
723
724
|
revokedAssets: validRevoked
|
|
724
725
|
}
|
|
725
726
|
});
|
|
726
|
-
if (
|
|
727
|
+
if (applyWrites) await executor.updateTable("stake").set({
|
|
727
728
|
assets: JSON.stringify(validActive),
|
|
728
729
|
revokedAssets: JSON.stringify(validRevoked)
|
|
729
730
|
}).where("address", "=", stk.address).execute();
|
|
@@ -746,7 +747,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
746
747
|
name: tok.name
|
|
747
748
|
}
|
|
748
749
|
};
|
|
749
|
-
|
|
750
|
+
targetActions.push({
|
|
750
751
|
code: "I-TOK-4",
|
|
751
752
|
table: "asset",
|
|
752
753
|
key: charterAddr,
|
|
@@ -754,7 +755,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
754
755
|
before: charterData,
|
|
755
756
|
after: repairedData
|
|
756
757
|
});
|
|
757
|
-
if (
|
|
758
|
+
if (applyWrites) await executor.updateTable("asset").set({ data: JSON.stringify(repairedData) }).where("address", "=", charterAddr).execute();
|
|
758
759
|
}
|
|
759
760
|
}
|
|
760
761
|
} catch {}
|
|
@@ -776,7 +777,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
776
777
|
for (const tok of tokens) {
|
|
777
778
|
const expected = (sums.get(tok.address) || new BN(0)).toString(10);
|
|
778
779
|
if (String(tok.totalSupply ?? "0") !== expected) {
|
|
779
|
-
|
|
780
|
+
targetActions.push({
|
|
780
781
|
code: "I-TOK-1",
|
|
781
782
|
table: "token",
|
|
782
783
|
key: tok.address,
|
|
@@ -784,7 +785,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
784
785
|
before: { totalSupply: tok.totalSupply },
|
|
785
786
|
after: { totalSupply: expected }
|
|
786
787
|
});
|
|
787
|
-
if (
|
|
788
|
+
if (applyWrites) await executor.updateTable("token").set({ totalSupply: expected }).where("address", "=", tok.address).execute();
|
|
788
789
|
}
|
|
789
790
|
}
|
|
790
791
|
const tokenFactories = await executor.selectFrom("tokenFactory").selectAll().execute();
|
|
@@ -792,7 +793,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
792
793
|
if (Number(tf.status || 0) !== 0) continue;
|
|
793
794
|
const expected = (sums.get(tf.tokenAddress) || new BN(0)).toString(10);
|
|
794
795
|
if (String(tf.currentSupply ?? "0") !== expected) {
|
|
795
|
-
|
|
796
|
+
targetActions.push({
|
|
796
797
|
code: "I-TOK-3",
|
|
797
798
|
table: "tokenFactory",
|
|
798
799
|
key: tf.address,
|
|
@@ -800,13 +801,13 @@ async function reconcileChainState(db, options = {}) {
|
|
|
800
801
|
before: { currentSupply: tf.currentSupply },
|
|
801
802
|
after: { currentSupply: expected }
|
|
802
803
|
});
|
|
803
|
-
if (
|
|
804
|
+
if (applyWrites) await executor.updateTable("tokenFactory").set({ currentSupply: expected }).where("address", "=", tf.address).execute();
|
|
804
805
|
}
|
|
805
806
|
}
|
|
806
807
|
}
|
|
807
808
|
};
|
|
808
809
|
if (dryRun) {
|
|
809
|
-
await executeRepairs(db.getKysely());
|
|
810
|
+
await executeRepairs(db.getKysely(), false, actions);
|
|
810
811
|
return {
|
|
811
812
|
dryRun: true,
|
|
812
813
|
reconciled: false,
|
|
@@ -815,9 +816,22 @@ async function reconcileChainState(db, options = {}) {
|
|
|
815
816
|
actions
|
|
816
817
|
};
|
|
817
818
|
}
|
|
819
|
+
const previewActions = [];
|
|
820
|
+
await executeRepairs(db.getKysely(), false, previewActions);
|
|
821
|
+
if (previewActions.length === 0) return {
|
|
822
|
+
dryRun: false,
|
|
823
|
+
reconciled: beforeReport.valid,
|
|
824
|
+
beforeReport,
|
|
825
|
+
afterReport: beforeReport,
|
|
826
|
+
actions: previewActions
|
|
827
|
+
};
|
|
818
828
|
await db.runAsLambda(async (txn) => {
|
|
819
|
-
|
|
820
|
-
|
|
829
|
+
actions.length = 0;
|
|
830
|
+
await executeRepairs(txn, true, actions);
|
|
831
|
+
}, {
|
|
832
|
+
commitMessage: "reconcile_chain_state",
|
|
833
|
+
verifyHash: true
|
|
834
|
+
});
|
|
821
835
|
await sql`PRAGMA wal_checkpoint(PASSIVE)`.execute(db.getKysely()).catch(() => {});
|
|
822
836
|
const afterReport = await verifyChainStateInvariants(db, { ledger: options.ledger });
|
|
823
837
|
return {
|
package/esm/table/balance.mjs
CHANGED
|
@@ -92,7 +92,7 @@ var BalanceTable = class extends base_default {
|
|
|
92
92
|
const tokenBalances = await this.getBalance(normalizedAddress, ctx);
|
|
93
93
|
const removedTokens = Object.keys(tokenBalances).filter((token) => !(token in tokens));
|
|
94
94
|
const updatedTokens = Object.keys(tokens).filter((token) => tokenBalances[token] && tokenBalances[token] !== "0" || tokens[token] && tokens[token] !== "0").filter((token) => tokenBalances[token] !== tokens[token]);
|
|
95
|
-
if (updatedTokens.length === 0 && removedTokens.length === 0) return { ...
|
|
95
|
+
if (updatedTokens.length === 0 && removedTokens.length === 0) return { ...tokenBalances };
|
|
96
96
|
const batchRows = [];
|
|
97
97
|
const pendingOps = [];
|
|
98
98
|
for (const tokenAddress of updatedTokens) {
|
|
@@ -124,7 +124,10 @@ var BalanceTable = class extends base_default {
|
|
|
124
124
|
}
|
|
125
125
|
const sqlContext = ctx;
|
|
126
126
|
const executor = this.getExecutor(sqlContext);
|
|
127
|
-
if (removedTokens.length > 0)
|
|
127
|
+
if (removedTokens.length > 0) {
|
|
128
|
+
await executor.deleteFrom("balance").where("address", "=", normalizedAddress).where("tokenAddress", "in", removedTokens).execute();
|
|
129
|
+
for (const removedToken of removedTokens) delete tokenBalances[removedToken];
|
|
130
|
+
}
|
|
128
131
|
if (batchRows.length > 0) for (let i = 0; i < batchRows.length; i += UPSERT_BATCH_SIZE) {
|
|
129
132
|
const batch = batchRows.slice(i, i + UPSERT_BATCH_SIZE);
|
|
130
133
|
await executor.insertInto("balance").values(batch).onConflict((oc) => oc.columns(["address", "tokenAddress"]).doUpdateSet((eb) => ({
|
|
@@ -160,7 +163,7 @@ var BalanceTable = class extends base_default {
|
|
|
160
163
|
else await this.create(op.key, op.payload, ctx);
|
|
161
164
|
tokenBalances[op.tokenAddress] = tokens[op.tokenAddress];
|
|
162
165
|
}
|
|
163
|
-
return { ...
|
|
166
|
+
return { ...tokenBalances };
|
|
164
167
|
}
|
|
165
168
|
};
|
|
166
169
|
var balance_default = BalanceTable;
|
package/esm/table/base.mjs
CHANGED
|
@@ -150,15 +150,19 @@ var SqliteTable = class SqliteTable extends StateDBTable {
|
|
|
150
150
|
const insertedRow = await executor.insertInto(this.name).values(serialized).returningAll().executeTakeFirst();
|
|
151
151
|
const deserializedInserted = this.deserializeFromDb(insertedRow ?? serialized) ?? insertAttrs;
|
|
152
152
|
this.recordCommittedRowPut(sqlContext, lookupKey, deserializedInserted);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
tokens
|
|
158
|
-
|
|
159
|
-
|
|
153
|
+
const created = { ...deserializedInserted };
|
|
154
|
+
if (this.syncBalance) {
|
|
155
|
+
const balanceAddr = created.address || insertAttrs.address || (typeof key === "string" ? key : "");
|
|
156
|
+
if (attrs.tokens !== void 0) {
|
|
157
|
+
const rawTokens = attrs.tokens || {};
|
|
158
|
+
created.tokens = Object.keys(rawTokens).length ? await this.balanceTable.updateBalance({
|
|
159
|
+
address: balanceAddr,
|
|
160
|
+
tokens: rawTokens,
|
|
161
|
+
context: attrs.context
|
|
162
|
+
}, context) : await this.balanceTable.getBalance(balanceAddr, context);
|
|
163
|
+
} else created.tokens = await this.balanceTable.getBalance(balanceAddr, context);
|
|
160
164
|
}
|
|
161
|
-
return
|
|
165
|
+
return created;
|
|
162
166
|
}
|
|
163
167
|
async _get(key, context) {
|
|
164
168
|
if (!key) return null;
|
|
@@ -225,10 +229,7 @@ var SqliteTable = class SqliteTable extends StateDBTable {
|
|
|
225
229
|
if (!updatedRow) throw new Error(`${this.name} does not exist: ${JSON.stringify(key)}`);
|
|
226
230
|
const deserialized = this.deserializeFromDb(updatedRow);
|
|
227
231
|
this.recordCommittedRowPut(sqlContext, lookupKey, deserialized);
|
|
228
|
-
merged = {
|
|
229
|
-
...deserialized,
|
|
230
|
-
...updateAttrs
|
|
231
|
-
};
|
|
232
|
+
merged = { ...deserialized };
|
|
232
233
|
} else {
|
|
233
234
|
let qb = executor.selectFrom(this.name).selectAll();
|
|
234
235
|
for (const [k, v] of queryEntries) qb = qb.where(k, "=", v);
|
|
@@ -197,7 +197,10 @@ async function applyTombstoneBalanceCleanup(dbOrKysely, options) {
|
|
|
197
197
|
planDigest: freshPlan.planDigest
|
|
198
198
|
};
|
|
199
199
|
};
|
|
200
|
-
if (isSqliteStateDB(dbOrKysely)) return dbOrKysely.runAsLambda((txn) => executeInTxn(txn)
|
|
200
|
+
if (isSqliteStateDB(dbOrKysely)) return dbOrKysely.runAsLambda((txn) => executeInTxn(txn), {
|
|
201
|
+
verifyHash: true,
|
|
202
|
+
commitMessage: "cleanup_tombstone_balances"
|
|
203
|
+
});
|
|
201
204
|
const kysely = resolveKyselyExecutor(dbOrKysely);
|
|
202
205
|
if ("transaction" in kysely && typeof kysely.transaction === "function") return kysely.transaction().execute((txn) => executeInTxn(txn));
|
|
203
206
|
return executeInTxn(kysely);
|
package/lib/db.cjs
CHANGED
|
@@ -218,21 +218,23 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
218
218
|
*/
|
|
219
219
|
async initialize() {
|
|
220
220
|
this.closed = false;
|
|
221
|
+
const allowTrustedRecovery = !this.config.readonly;
|
|
221
222
|
if (this.initialized) {
|
|
222
|
-
if (this.trustedStorage && !this.trustedInitialized) await this.ensureTrustedStorageInitialized(
|
|
223
|
+
if (this.trustedStorage && !this.trustedInitialized) await this.ensureTrustedStorageInitialized(allowTrustedRecovery);
|
|
223
224
|
this.startWalCheckpointWorker();
|
|
224
225
|
return;
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
if (!this.config.readonly) {
|
|
228
|
+
await require_migrations_index.runMigrations(this.db);
|
|
229
|
+
await this.assertRollupReserveColumns();
|
|
230
|
+
}
|
|
228
231
|
this.initialized = true;
|
|
229
|
-
if (this.trustedStorage) await this.ensureTrustedStorageInitialized(
|
|
232
|
+
if (this.trustedStorage) await this.ensureTrustedStorageInitialized(allowTrustedRecovery);
|
|
230
233
|
this.startWalCheckpointWorker();
|
|
231
234
|
}
|
|
232
235
|
/**
|
|
233
236
|
* Fail startup instead of failing every reserve-tracking rollup write later (#1548): a file whose migration
|
|
234
237
|
* bookkeeping says 004 ran but whose `rollup` table lacks the columns (copied/hand-built DB) must not open.
|
|
235
|
-
* Mirrors the Dolt backend's `rollup.reserves` startup guard.
|
|
236
238
|
*/
|
|
237
239
|
async assertRollupReserveColumns() {
|
|
238
240
|
const { rows } = await kysely.sql`SELECT name FROM pragma_table_info('rollup')`.execute(this.db);
|
|
@@ -288,7 +290,7 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
288
290
|
if (typeof this.walCheckpointTimer.unref === "function") this.walCheckpointTimer.unref();
|
|
289
291
|
}
|
|
290
292
|
async ensureStateCommitTable() {
|
|
291
|
-
if (this.stateCommitTableReady) return;
|
|
293
|
+
if (this.stateCommitTableReady || this.config.readonly) return;
|
|
292
294
|
await kysely.sql`
|
|
293
295
|
CREATE TABLE IF NOT EXISTS "_state_commit" (
|
|
294
296
|
"id" INTEGER PRIMARY KEY CHECK ("id" = 1),
|
|
@@ -304,15 +306,42 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
304
306
|
`.execute(this.db);
|
|
305
307
|
this.stateCommitTableReady = true;
|
|
306
308
|
}
|
|
309
|
+
async hasPopulatedStateTables() {
|
|
310
|
+
for (const table of [
|
|
311
|
+
"chain",
|
|
312
|
+
"account",
|
|
313
|
+
"balance",
|
|
314
|
+
"token",
|
|
315
|
+
"tx",
|
|
316
|
+
"asset",
|
|
317
|
+
"stake",
|
|
318
|
+
"factory",
|
|
319
|
+
"delegation",
|
|
320
|
+
"rollup",
|
|
321
|
+
"rollupBlock",
|
|
322
|
+
"evidence",
|
|
323
|
+
"tokenFactory"
|
|
324
|
+
]) try {
|
|
325
|
+
if ((await kysely.sql`SELECT 1 AS present FROM ${kysely.sql.table(table)} LIMIT 1`.execute(this.db)).rows.length > 0) return true;
|
|
326
|
+
} catch {}
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
307
329
|
async ensureTrustedStorageInitialized(allowForwardRecovery = false) {
|
|
308
330
|
if (!this.trustedStorage || this.trustedInitialized) return;
|
|
309
331
|
await this.ensureStateCommitTable();
|
|
310
|
-
if (typeof this.trustedStorage.initStorage === "function") await this.trustedStorage.initStorage();
|
|
332
|
+
if (!this.config.readonly && typeof this.trustedStorage.initStorage === "function") await this.trustedStorage.initStorage();
|
|
311
333
|
if (!await this.trustedStorage.getHash()) {
|
|
312
|
-
const { currentHash } = await this.getCommitHash();
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
334
|
+
const { currentHash, prevHash, seq = 0 } = await this.getCommitHash();
|
|
335
|
+
if (!(seq === 0 && currentHash === "GENESIS" && !prevHash && !await this.hasPopulatedStateTables()) && !this.config.allowTrustedBootstrap) {
|
|
336
|
+
const err = /* @__PURE__ */ new Error("Trusted hash verification failed");
|
|
337
|
+
err.code = "INVALID_HASH";
|
|
338
|
+
throw err;
|
|
339
|
+
}
|
|
340
|
+
if (!this.config.readonly) {
|
|
341
|
+
const newTrustedHash = await this.trustedStorage.createHash(currentHash);
|
|
342
|
+
await this.trustedStorage.writeHash(newTrustedHash);
|
|
343
|
+
}
|
|
344
|
+
} else await this.verifyTrustedHashInternal(allowForwardRecovery && !this.config.readonly);
|
|
316
345
|
this.trustedInitialized = true;
|
|
317
346
|
}
|
|
318
347
|
/**
|
|
@@ -327,16 +356,29 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
327
356
|
* checkpoints and self-verifying segments.
|
|
328
357
|
*/
|
|
329
358
|
async getCommitHash(executor = this.db) {
|
|
330
|
-
if (!this.stateCommitTableReady) await this.ensureStateCommitTable();
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
359
|
+
if (!this.stateCommitTableReady && !this.config.readonly) await this.ensureStateCommitTable();
|
|
360
|
+
try {
|
|
361
|
+
const row = (await kysely.sql`
|
|
362
|
+
SELECT "current_hash", "prev_hash", "seq", "msg" FROM "_state_commit" WHERE "id" = 1
|
|
363
|
+
`.execute(executor)).rows[0];
|
|
364
|
+
return {
|
|
365
|
+
currentHash: row?.current_hash || "GENESIS",
|
|
366
|
+
prevHash: row?.prev_hash || "",
|
|
367
|
+
seq: Number(row?.seq || 0),
|
|
368
|
+
msg: row?.msg || ""
|
|
369
|
+
};
|
|
370
|
+
} catch (err) {
|
|
371
|
+
if (this.config.readonly) {
|
|
372
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
373
|
+
if (/no such table/i.test(msg)) return {
|
|
374
|
+
currentHash: "GENESIS",
|
|
375
|
+
prevHash: "",
|
|
376
|
+
seq: 0,
|
|
377
|
+
msg: ""
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
throw err;
|
|
381
|
+
}
|
|
340
382
|
}
|
|
341
383
|
async verifyTrustedHashInternal(allowForwardRecovery = false) {
|
|
342
384
|
if (!this.trustedStorage) return;
|
|
@@ -357,9 +399,10 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
357
399
|
*/
|
|
358
400
|
async verifyTrustedHash() {
|
|
359
401
|
if (!this.trustedStorage) return;
|
|
402
|
+
const allowRecovery = !this.config.readonly;
|
|
360
403
|
await this.enqueueCommit(async () => {
|
|
361
|
-
await this.ensureTrustedStorageInitialized(
|
|
362
|
-
await this.verifyTrustedHashInternal(
|
|
404
|
+
await this.ensureTrustedStorageInitialized(allowRecovery);
|
|
405
|
+
await this.verifyTrustedHashInternal(allowRecovery);
|
|
363
406
|
});
|
|
364
407
|
}
|
|
365
408
|
enqueueCommit(task) {
|
|
@@ -380,6 +423,7 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
380
423
|
return this.executeRunAsLambda(fn, options);
|
|
381
424
|
}
|
|
382
425
|
async executeRunAsLambda(fn, options = {}) {
|
|
426
|
+
if (this.config.readonly) throw new Error("Cannot execute runAsLambda on a SqliteStateDB opened in readonly mode");
|
|
383
427
|
const { retryLimit = 5, verifyHash = false, commitMessage } = options;
|
|
384
428
|
if (!this.stateCommitTableReady) await this.ensureStateCommitTable();
|
|
385
429
|
if (this.trustedStorage) {
|
|
@@ -456,6 +500,7 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
456
500
|
* Reset all tables (for testing)
|
|
457
501
|
*/
|
|
458
502
|
async reset() {
|
|
503
|
+
if (this.config.readonly) throw new Error("Cannot reset a SqliteStateDB opened in readonly mode");
|
|
459
504
|
const tables = Object.keys(this.readyMarks);
|
|
460
505
|
for (const table of tables) {
|
|
461
506
|
const tableInstance = this[table];
|
|
@@ -486,7 +531,7 @@ var SqliteStateDB = class extends _ocap_statedb.StateDB {
|
|
|
486
531
|
if (this.walCheckpointPromise) await this.walCheckpointPromise.catch(() => void 0);
|
|
487
532
|
await this.commitQueue;
|
|
488
533
|
await this.db.destroy();
|
|
489
|
-
if (this.trustedStorage && typeof this.trustedStorage.destroy === "function") await this.trustedStorage.destroy();
|
|
534
|
+
if (this.trustedStorage && typeof this.trustedStorage.destroy === "function" && this.trustedStorage.filename !== ":memory:") await this.trustedStorage.destroy();
|
|
490
535
|
}
|
|
491
536
|
/**
|
|
492
537
|
* Get the canonical SHA-256 digest of the write-set from the most recently committed `runAsLambda` transaction.
|
package/lib/db.d.cts
CHANGED
|
@@ -81,7 +81,6 @@ declare class SqliteStateDB extends StateDB implements IStateDB {
|
|
|
81
81
|
/**
|
|
82
82
|
* Fail startup instead of failing every reserve-tracking rollup write later (#1548): a file whose migration
|
|
83
83
|
* bookkeeping says 004 ran but whose `rollup` table lacks the columns (copied/hand-built DB) must not open.
|
|
84
|
-
* Mirrors the Dolt backend's `rollup.reserves` startup guard.
|
|
85
84
|
*/
|
|
86
85
|
private assertRollupReserveColumns;
|
|
87
86
|
/**
|
|
@@ -95,6 +94,7 @@ declare class SqliteStateDB extends StateDB implements IStateDB {
|
|
|
95
94
|
}>;
|
|
96
95
|
private startWalCheckpointWorker;
|
|
97
96
|
private ensureStateCommitTable;
|
|
97
|
+
private hasPopulatedStateTables;
|
|
98
98
|
private ensureTrustedStorageInitialized;
|
|
99
99
|
/**
|
|
100
100
|
* Get the current and previous state commit hash tracked in SQLite StateDB.
|
package/lib/kysely.cjs
CHANGED
|
@@ -1545,7 +1545,7 @@ function createKysely(config) {
|
|
|
1545
1545
|
const { BunSqliteDialect } = bunReq("kysely-bun-sqlite");
|
|
1546
1546
|
const { Database: BunDatabase } = bunReq("bun:sqlite");
|
|
1547
1547
|
const sqlite$1 = new BunDatabase(filename, {
|
|
1548
|
-
create: config.create !== false,
|
|
1548
|
+
create: config.readonly && filename !== ":memory:" ? false : config.create !== false,
|
|
1549
1549
|
readonly: config.readonly === true
|
|
1550
1550
|
});
|
|
1551
1551
|
if (config.walMode !== false && !config.readonly && filename !== ":memory:") {
|
|
@@ -1560,7 +1560,7 @@ function createKysely(config) {
|
|
|
1560
1560
|
}
|
|
1561
1561
|
const sqlite = new (require("better-sqlite3"))(filename, {
|
|
1562
1562
|
readonly: config.readonly === true,
|
|
1563
|
-
fileMustExist: config.create === false
|
|
1563
|
+
fileMustExist: config.readonly === true || config.create === false
|
|
1564
1564
|
});
|
|
1565
1565
|
if (config.walMode !== false && !config.readonly && filename !== ":memory:") {
|
|
1566
1566
|
sqlite.pragma("journal_mode = WAL");
|
package/lib/kysely.d.cts
CHANGED
|
@@ -59,6 +59,11 @@ interface SqliteConfig {
|
|
|
59
59
|
dialect?: Dialect;
|
|
60
60
|
/** Optional trusted storage instance for state commit hash verification */
|
|
61
61
|
trustedStorage?: ITrustedStorage;
|
|
62
|
+
/**
|
|
63
|
+
* Explicitly allow bootstrapping an empty `trustedStorage` onto an already-populated StateDB
|
|
64
|
+
* (only set by operator `--force` recovery tools; false by default so wiped `trusted.sqlite` fails closed).
|
|
65
|
+
*/
|
|
66
|
+
allowTrustedBootstrap?: boolean;
|
|
62
67
|
/** Open database in readonly mode */
|
|
63
68
|
readonly?: boolean;
|
|
64
69
|
/** Throw error if file doesn't exist (default: false, creates new file) */
|
package/lib/reconcile.cjs
CHANGED
|
@@ -8,11 +8,11 @@ let _arcblock_did_util = require("@arcblock/did-util");
|
|
|
8
8
|
//#region src/reconcile.ts
|
|
9
9
|
/**
|
|
10
10
|
* Verification and reconcile are SQLite-only (they query SQLite tables through kysely). Fail loudly when given
|
|
11
|
-
* any other backend (e.g. statedb-
|
|
11
|
+
* any other backend (e.g. statedb-memory) instead of crashing midway or silently skipping.
|
|
12
12
|
*/
|
|
13
13
|
function assertSqliteStateDb(db) {
|
|
14
14
|
const candidate = db;
|
|
15
|
-
if (!candidate || typeof candidate.getKysely !== "function") throw new Error("Chain state verify/reconcile only supports @ocap/statedb-sqlite.
|
|
15
|
+
if (!candidate || typeof candidate.getKysely !== "function") throw new Error("Chain state verify/reconcile only supports @ocap/statedb-sqlite. Other backends are not supported.");
|
|
16
16
|
}
|
|
17
17
|
const CANONICAL_UINT_REGEX = /^\d+$/;
|
|
18
18
|
function parseJsonColumn(raw, fallback) {
|
|
@@ -495,6 +495,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
495
495
|
assertSqliteStateDb(db);
|
|
496
496
|
const dryRun = options.dryRun !== false;
|
|
497
497
|
if (!dryRun && options.allowProtocolBypass !== true) throw new Error("reconcileChainState({ dryRun: false }) writes directly to SQLite and bypasses protocol validation; pass allowProtocolBypass: true to confirm");
|
|
498
|
+
if (!dryRun && db.trustedStorage) await db.verifyTrustedHash();
|
|
498
499
|
const beforeReport = await verifyChainStateInvariants(db, { ledger: options.ledger });
|
|
499
500
|
const actions = [];
|
|
500
501
|
if (beforeReport.valid) return {
|
|
@@ -504,7 +505,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
504
505
|
afterReport: beforeReport,
|
|
505
506
|
actions
|
|
506
507
|
};
|
|
507
|
-
const executeRepairs = async (executor) => {
|
|
508
|
+
const executeRepairs = async (executor, applyWrites, targetActions) => {
|
|
508
509
|
const allBalances = await executor.selectFrom("balance").selectAll().execute();
|
|
509
510
|
for (const row of allBalances) {
|
|
510
511
|
const addr = String(row.address || "");
|
|
@@ -512,7 +513,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
512
513
|
const balStr = String(row.balance ?? "0");
|
|
513
514
|
const checksumAddr = (0, _ocap_state_lib_states_account.ensureChecksumAddress)(addr);
|
|
514
515
|
if (CANONICAL_UINT_REGEX.test(balStr) && new _ocap_util.BN(balStr, 10).isZero()) {
|
|
515
|
-
|
|
516
|
+
targetActions.push({
|
|
516
517
|
code: "I-BAL-3",
|
|
517
518
|
table: "balance",
|
|
518
519
|
key: `${addr}:${tokAddr}`,
|
|
@@ -524,13 +525,13 @@ async function reconcileChainState(db, options = {}) {
|
|
|
524
525
|
},
|
|
525
526
|
after: null
|
|
526
527
|
});
|
|
527
|
-
if (
|
|
528
|
+
if (applyWrites) await executor.deleteFrom("balance").where("address", "=", addr).where("tokenAddress", "=", tokAddr).execute();
|
|
528
529
|
continue;
|
|
529
530
|
}
|
|
530
531
|
if (checksumAddr !== addr && CANONICAL_UINT_REGEX.test(balStr)) {
|
|
531
532
|
const existingCanonical = await executor.selectFrom("balance").selectAll().where("address", "=", checksumAddr).where("tokenAddress", "=", tokAddr).executeTakeFirst();
|
|
532
533
|
const mergedBalance = existingCanonical && CANONICAL_UINT_REGEX.test(String(existingCanonical.balance)) ? new _ocap_util.BN(String(existingCanonical.balance), 10).add(new _ocap_util.BN(balStr, 10)).toString(10) : balStr;
|
|
533
|
-
|
|
534
|
+
targetActions.push({
|
|
534
535
|
code: "I-BAL-1",
|
|
535
536
|
table: "balance",
|
|
536
537
|
key: `${addr}:${tokAddr}`,
|
|
@@ -546,7 +547,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
546
547
|
balance: mergedBalance
|
|
547
548
|
}
|
|
548
549
|
});
|
|
549
|
-
if (
|
|
550
|
+
if (applyWrites) {
|
|
550
551
|
await executor.deleteFrom("balance").where("address", "=", addr).where("tokenAddress", "=", tokAddr).execute();
|
|
551
552
|
await executor.insertInto("balance").values({
|
|
552
553
|
address: checksumAddr,
|
|
@@ -601,7 +602,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
601
602
|
if (!nextMigratedFrom.includes(acc.address)) {
|
|
602
603
|
const updatedFrom = [...nextMigratedFrom, acc.address];
|
|
603
604
|
nextAcc.migratedFrom = JSON.stringify(updatedFrom);
|
|
604
|
-
|
|
605
|
+
targetActions.push({
|
|
605
606
|
code: "I-MIG-1",
|
|
606
607
|
table: "account",
|
|
607
608
|
key: nextHop,
|
|
@@ -609,7 +610,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
609
610
|
before: nextMigratedFrom,
|
|
610
611
|
after: updatedFrom
|
|
611
612
|
});
|
|
612
|
-
if (
|
|
613
|
+
if (applyWrites) await executor.updateTable("account").set({ migratedFrom: JSON.stringify(updatedFrom) }).where("address", "=", nextHop).execute();
|
|
613
614
|
}
|
|
614
615
|
}
|
|
615
616
|
const zombieRows = await executor.selectFrom("balance").selectAll().where("address", "=", acc.address).execute();
|
|
@@ -628,7 +629,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
628
629
|
const forwardPortion = zBal.sub(zombiePortion);
|
|
629
630
|
if (zombiePortion.gt(new _ocap_util.BN(0))) runningAccountedSupply.set(tokAddr, accountedSupply.sub(zombiePortion));
|
|
630
631
|
if (forwardPortion.isZero()) {
|
|
631
|
-
|
|
632
|
+
targetActions.push({
|
|
632
633
|
code: "I-BAL-2",
|
|
633
634
|
table: "balance",
|
|
634
635
|
key: `${acc.address}:${tokAddr}`,
|
|
@@ -640,12 +641,12 @@ async function reconcileChainState(db, options = {}) {
|
|
|
640
641
|
},
|
|
641
642
|
after: null
|
|
642
643
|
});
|
|
643
|
-
if (
|
|
644
|
+
if (applyWrites) await executor.deleteFrom("balance").where("address", "=", acc.address).where("tokenAddress", "=", tokAddr).execute();
|
|
644
645
|
} else {
|
|
645
646
|
const nextTermBalBn = termBal.add(forwardPortion);
|
|
646
647
|
const nextTermBal = nextTermBalBn.toString(10);
|
|
647
648
|
liveBalanceMap.set(termBalKey, nextTermBalBn);
|
|
648
|
-
|
|
649
|
+
targetActions.push({
|
|
649
650
|
code: "I-BAL-2",
|
|
650
651
|
table: "balance",
|
|
651
652
|
key: `${acc.address}:${tokAddr}`,
|
|
@@ -669,7 +670,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
669
670
|
deletedDuplicateZombiePortion: zombiePortion.toString(10)
|
|
670
671
|
}
|
|
671
672
|
});
|
|
672
|
-
if (
|
|
673
|
+
if (applyWrites) {
|
|
673
674
|
await executor.deleteFrom("balance").where("address", "=", acc.address).where("tokenAddress", "=", tokAddr).execute();
|
|
674
675
|
await executor.insertInto("balance").values({
|
|
675
676
|
address: terminalAddr,
|
|
@@ -682,7 +683,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
682
683
|
}
|
|
683
684
|
const orphanAssets = await executor.selectFrom("asset").selectAll().where("owner", "=", acc.address).execute();
|
|
684
685
|
for (const ast of orphanAssets) {
|
|
685
|
-
|
|
686
|
+
targetActions.push({
|
|
686
687
|
code: "I-AST-1",
|
|
687
688
|
table: "asset",
|
|
688
689
|
key: ast.address,
|
|
@@ -690,7 +691,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
690
691
|
before: { owner: acc.address },
|
|
691
692
|
after: { owner: terminalAddr }
|
|
692
693
|
});
|
|
693
|
-
if (
|
|
694
|
+
if (applyWrites) await executor.updateTable("asset").set({ owner: terminalAddr }).where("address", "=", ast.address).execute();
|
|
694
695
|
}
|
|
695
696
|
}
|
|
696
697
|
const stakes = await executor.selectFrom("stake").selectAll().execute();
|
|
@@ -710,7 +711,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
710
711
|
return Boolean(a && a.owner === stk.address);
|
|
711
712
|
});
|
|
712
713
|
if (validActive.length !== activeAssets.length || validRevoked.length !== revokedAssets.length) {
|
|
713
|
-
|
|
714
|
+
targetActions.push({
|
|
714
715
|
code: "I-STK-1",
|
|
715
716
|
table: "stake",
|
|
716
717
|
key: stk.address,
|
|
@@ -724,7 +725,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
724
725
|
revokedAssets: validRevoked
|
|
725
726
|
}
|
|
726
727
|
});
|
|
727
|
-
if (
|
|
728
|
+
if (applyWrites) await executor.updateTable("stake").set({
|
|
728
729
|
assets: JSON.stringify(validActive),
|
|
729
730
|
revokedAssets: JSON.stringify(validRevoked)
|
|
730
731
|
}).where("address", "=", stk.address).execute();
|
|
@@ -747,7 +748,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
747
748
|
name: tok.name
|
|
748
749
|
}
|
|
749
750
|
};
|
|
750
|
-
|
|
751
|
+
targetActions.push({
|
|
751
752
|
code: "I-TOK-4",
|
|
752
753
|
table: "asset",
|
|
753
754
|
key: charterAddr,
|
|
@@ -755,7 +756,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
755
756
|
before: charterData,
|
|
756
757
|
after: repairedData
|
|
757
758
|
});
|
|
758
|
-
if (
|
|
759
|
+
if (applyWrites) await executor.updateTable("asset").set({ data: JSON.stringify(repairedData) }).where("address", "=", charterAddr).execute();
|
|
759
760
|
}
|
|
760
761
|
}
|
|
761
762
|
} catch {}
|
|
@@ -777,7 +778,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
777
778
|
for (const tok of tokens) {
|
|
778
779
|
const expected = (sums.get(tok.address) || new _ocap_util.BN(0)).toString(10);
|
|
779
780
|
if (String(tok.totalSupply ?? "0") !== expected) {
|
|
780
|
-
|
|
781
|
+
targetActions.push({
|
|
781
782
|
code: "I-TOK-1",
|
|
782
783
|
table: "token",
|
|
783
784
|
key: tok.address,
|
|
@@ -785,7 +786,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
785
786
|
before: { totalSupply: tok.totalSupply },
|
|
786
787
|
after: { totalSupply: expected }
|
|
787
788
|
});
|
|
788
|
-
if (
|
|
789
|
+
if (applyWrites) await executor.updateTable("token").set({ totalSupply: expected }).where("address", "=", tok.address).execute();
|
|
789
790
|
}
|
|
790
791
|
}
|
|
791
792
|
const tokenFactories = await executor.selectFrom("tokenFactory").selectAll().execute();
|
|
@@ -793,7 +794,7 @@ async function reconcileChainState(db, options = {}) {
|
|
|
793
794
|
if (Number(tf.status || 0) !== 0) continue;
|
|
794
795
|
const expected = (sums.get(tf.tokenAddress) || new _ocap_util.BN(0)).toString(10);
|
|
795
796
|
if (String(tf.currentSupply ?? "0") !== expected) {
|
|
796
|
-
|
|
797
|
+
targetActions.push({
|
|
797
798
|
code: "I-TOK-3",
|
|
798
799
|
table: "tokenFactory",
|
|
799
800
|
key: tf.address,
|
|
@@ -801,13 +802,13 @@ async function reconcileChainState(db, options = {}) {
|
|
|
801
802
|
before: { currentSupply: tf.currentSupply },
|
|
802
803
|
after: { currentSupply: expected }
|
|
803
804
|
});
|
|
804
|
-
if (
|
|
805
|
+
if (applyWrites) await executor.updateTable("tokenFactory").set({ currentSupply: expected }).where("address", "=", tf.address).execute();
|
|
805
806
|
}
|
|
806
807
|
}
|
|
807
808
|
}
|
|
808
809
|
};
|
|
809
810
|
if (dryRun) {
|
|
810
|
-
await executeRepairs(db.getKysely());
|
|
811
|
+
await executeRepairs(db.getKysely(), false, actions);
|
|
811
812
|
return {
|
|
812
813
|
dryRun: true,
|
|
813
814
|
reconciled: false,
|
|
@@ -816,9 +817,22 @@ async function reconcileChainState(db, options = {}) {
|
|
|
816
817
|
actions
|
|
817
818
|
};
|
|
818
819
|
}
|
|
820
|
+
const previewActions = [];
|
|
821
|
+
await executeRepairs(db.getKysely(), false, previewActions);
|
|
822
|
+
if (previewActions.length === 0) return {
|
|
823
|
+
dryRun: false,
|
|
824
|
+
reconciled: beforeReport.valid,
|
|
825
|
+
beforeReport,
|
|
826
|
+
afterReport: beforeReport,
|
|
827
|
+
actions: previewActions
|
|
828
|
+
};
|
|
819
829
|
await db.runAsLambda(async (txn) => {
|
|
820
|
-
|
|
821
|
-
|
|
830
|
+
actions.length = 0;
|
|
831
|
+
await executeRepairs(txn, true, actions);
|
|
832
|
+
}, {
|
|
833
|
+
commitMessage: "reconcile_chain_state",
|
|
834
|
+
verifyHash: true
|
|
835
|
+
});
|
|
822
836
|
await kysely.sql`PRAGMA wal_checkpoint(PASSIVE)`.execute(db.getKysely()).catch(() => {});
|
|
823
837
|
const afterReport = await verifyChainStateInvariants(db, { ledger: options.ledger });
|
|
824
838
|
return {
|
package/lib/reconcile.d.cts
CHANGED
|
@@ -41,8 +41,8 @@ interface ReconcileOptions {
|
|
|
41
41
|
dryRun?: boolean;
|
|
42
42
|
/**
|
|
43
43
|
* Required when `dryRun: false`. Reconcile `--apply` writes SQLite rows directly and bypasses all protocol
|
|
44
|
-
* validation (no tx, no ledger entry), so it must be an explicit operator decision. Never
|
|
45
|
-
*
|
|
44
|
+
* validation (no tx, no ledger entry), so it must be an explicit operator decision. Never run it against a live
|
|
45
|
+
* node's files while the node is running.
|
|
46
46
|
*/
|
|
47
47
|
allowProtocolBypass?: boolean;
|
|
48
48
|
/** Reconcile token.totalSupply (and active tokenFactory.currentSupply) to match authoritative holder + revoked balances. */
|
|
@@ -65,7 +65,7 @@ interface ReconcileResult {
|
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Verification and reconcile are SQLite-only (they query SQLite tables through kysely). Fail loudly when given
|
|
68
|
-
* any other backend (e.g. statedb-
|
|
68
|
+
* any other backend (e.g. statedb-memory) instead of crashing midway or silently skipping.
|
|
69
69
|
*/
|
|
70
70
|
declare function assertSqliteStateDb(db: unknown): void;
|
|
71
71
|
/**
|
package/lib/table/balance.cjs
CHANGED
|
@@ -94,7 +94,7 @@ var BalanceTable = class extends require_table_base.default {
|
|
|
94
94
|
const tokenBalances = await this.getBalance(normalizedAddress, ctx);
|
|
95
95
|
const removedTokens = Object.keys(tokenBalances).filter((token) => !(token in tokens));
|
|
96
96
|
const updatedTokens = Object.keys(tokens).filter((token) => tokenBalances[token] && tokenBalances[token] !== "0" || tokens[token] && tokens[token] !== "0").filter((token) => tokenBalances[token] !== tokens[token]);
|
|
97
|
-
if (updatedTokens.length === 0 && removedTokens.length === 0) return { ...
|
|
97
|
+
if (updatedTokens.length === 0 && removedTokens.length === 0) return { ...tokenBalances };
|
|
98
98
|
const batchRows = [];
|
|
99
99
|
const pendingOps = [];
|
|
100
100
|
for (const tokenAddress of updatedTokens) {
|
|
@@ -126,7 +126,10 @@ var BalanceTable = class extends require_table_base.default {
|
|
|
126
126
|
}
|
|
127
127
|
const sqlContext = ctx;
|
|
128
128
|
const executor = this.getExecutor(sqlContext);
|
|
129
|
-
if (removedTokens.length > 0)
|
|
129
|
+
if (removedTokens.length > 0) {
|
|
130
|
+
await executor.deleteFrom("balance").where("address", "=", normalizedAddress).where("tokenAddress", "in", removedTokens).execute();
|
|
131
|
+
for (const removedToken of removedTokens) delete tokenBalances[removedToken];
|
|
132
|
+
}
|
|
130
133
|
if (batchRows.length > 0) for (let i = 0; i < batchRows.length; i += UPSERT_BATCH_SIZE) {
|
|
131
134
|
const batch = batchRows.slice(i, i + UPSERT_BATCH_SIZE);
|
|
132
135
|
await executor.insertInto("balance").values(batch).onConflict((oc) => oc.columns(["address", "tokenAddress"]).doUpdateSet((eb) => ({
|
|
@@ -162,7 +165,7 @@ var BalanceTable = class extends require_table_base.default {
|
|
|
162
165
|
else await this.create(op.key, op.payload, ctx);
|
|
163
166
|
tokenBalances[op.tokenAddress] = tokens[op.tokenAddress];
|
|
164
167
|
}
|
|
165
|
-
return { ...
|
|
168
|
+
return { ...tokenBalances };
|
|
166
169
|
}
|
|
167
170
|
};
|
|
168
171
|
var balance_default = BalanceTable;
|
package/lib/table/base.cjs
CHANGED
|
@@ -154,15 +154,19 @@ var SqliteTable = class SqliteTable extends _ocap_statedb.StateDBTable {
|
|
|
154
154
|
const insertedRow = await executor.insertInto(this.name).values(serialized).returningAll().executeTakeFirst();
|
|
155
155
|
const deserializedInserted = this.deserializeFromDb(insertedRow ?? serialized) ?? insertAttrs;
|
|
156
156
|
this.recordCommittedRowPut(sqlContext, lookupKey, deserializedInserted);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
tokens
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
const created = { ...deserializedInserted };
|
|
158
|
+
if (this.syncBalance) {
|
|
159
|
+
const balanceAddr = created.address || insertAttrs.address || (typeof key === "string" ? key : "");
|
|
160
|
+
if (attrs.tokens !== void 0) {
|
|
161
|
+
const rawTokens = attrs.tokens || {};
|
|
162
|
+
created.tokens = Object.keys(rawTokens).length ? await this.balanceTable.updateBalance({
|
|
163
|
+
address: balanceAddr,
|
|
164
|
+
tokens: rawTokens,
|
|
165
|
+
context: attrs.context
|
|
166
|
+
}, context) : await this.balanceTable.getBalance(balanceAddr, context);
|
|
167
|
+
} else created.tokens = await this.balanceTable.getBalance(balanceAddr, context);
|
|
164
168
|
}
|
|
165
|
-
return
|
|
169
|
+
return created;
|
|
166
170
|
}
|
|
167
171
|
async _get(key, context) {
|
|
168
172
|
if (!key) return null;
|
|
@@ -229,10 +233,7 @@ var SqliteTable = class SqliteTable extends _ocap_statedb.StateDBTable {
|
|
|
229
233
|
if (!updatedRow) throw new Error(`${this.name} does not exist: ${JSON.stringify(key)}`);
|
|
230
234
|
const deserialized = this.deserializeFromDb(updatedRow);
|
|
231
235
|
this.recordCommittedRowPut(sqlContext, lookupKey, deserialized);
|
|
232
|
-
merged = {
|
|
233
|
-
...deserialized,
|
|
234
|
-
...updateAttrs
|
|
235
|
-
};
|
|
236
|
+
merged = { ...deserialized };
|
|
236
237
|
} else {
|
|
237
238
|
let qb = executor.selectFrom(this.name).selectAll();
|
|
238
239
|
for (const [k, v] of queryEntries) qb = qb.where(k, "=", v);
|
|
@@ -198,7 +198,10 @@ async function applyTombstoneBalanceCleanup(dbOrKysely, options) {
|
|
|
198
198
|
planDigest: freshPlan.planDigest
|
|
199
199
|
};
|
|
200
200
|
};
|
|
201
|
-
if (isSqliteStateDB(dbOrKysely)) return dbOrKysely.runAsLambda((txn) => executeInTxn(txn)
|
|
201
|
+
if (isSqliteStateDB(dbOrKysely)) return dbOrKysely.runAsLambda((txn) => executeInTxn(txn), {
|
|
202
|
+
verifyHash: true,
|
|
203
|
+
commitMessage: "cleanup_tombstone_balances"
|
|
204
|
+
});
|
|
202
205
|
const kysely$1 = resolveKyselyExecutor(dbOrKysely);
|
|
203
206
|
if ("transaction" in kysely$1 && typeof kysely$1.transaction === "function") return kysely$1.transaction().execute((txn) => executeInTxn(txn));
|
|
204
207
|
return executeInTxn(kysely$1);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/statedb-sqlite",
|
|
3
3
|
"description": "OCAP statedb adapter that uses SQLite as backend",
|
|
4
|
-
"version": "1.31.
|
|
4
|
+
"version": "1.31.5",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@ocap/statedb-test": "1.31.
|
|
17
|
+
"@ocap/statedb-test": "1.31.5"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/statedb/sqlite",
|
|
20
20
|
"keywords": [
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"clean": "rm -rf lib esm"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@arcblock/did": "1.31.
|
|
67
|
-
"@arcblock/did-util": "1.31.
|
|
68
|
-
"@ocap/state": "1.31.
|
|
69
|
-
"@ocap/statedb": "1.31.
|
|
70
|
-
"@ocap/types": "1.31.
|
|
71
|
-
"@ocap/util": "1.31.
|
|
66
|
+
"@arcblock/did": "1.31.5",
|
|
67
|
+
"@arcblock/did-util": "1.31.5",
|
|
68
|
+
"@ocap/state": "1.31.5",
|
|
69
|
+
"@ocap/statedb": "1.31.5",
|
|
70
|
+
"@ocap/types": "1.31.5",
|
|
71
|
+
"@ocap/util": "1.31.5",
|
|
72
72
|
"better-sqlite3": "^11.8.1",
|
|
73
73
|
"kysely": "^0.28.14",
|
|
74
74
|
"kysely-bun-sqlite": "^0.4.0",
|