From e79e43c2776161b3f872a130131ad4a7b4c16e3f Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 10 Aug 2021 15:51:34 -0700 Subject: [PATCH] fix(swingset): rename snapshot-related DB keys to be "local" We're defining the `local.*` namespace as the portion of the DB that is excluded from consensus (the #3442 kernel activity hash). Vat snapshots are a local concern: each member of a consensus machine can decide for itself if/when to make a snapshot. So both the vat->snapshot and the snapshot->vats tables must be moved to `local.`. --- packages/SwingSet/src/kernel/state/kernelKeeper.js | 8 ++++++-- packages/SwingSet/src/kernel/state/vatKeeper.js | 8 ++++---- .../SwingSet/test/vat-warehouse/test-reload-snapshot.js | 2 +- packages/SwingSet/test/vat-warehouse/test-warehouse.js | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/SwingSet/src/kernel/state/kernelKeeper.js b/packages/SwingSet/src/kernel/state/kernelKeeper.js index 3954f604909..8b6c1d5b131 100644 --- a/packages/SwingSet/src/kernel/state/kernelKeeper.js +++ b/packages/SwingSet/src/kernel/state/kernelKeeper.js @@ -31,6 +31,10 @@ const enableKernelGC = true; // "prefix." and "prefix/", which avoids including anything using an // extension of the prefix (e.g. [vat1.foo, vat1.bar, vat15.baz]). // +// The 'local.' namespace is excluded from the kernel activity hash, and is +// allowed to vary between instances in a consensus machine. Everything else +// is required to be deterministic. +// // The schema is: // // vat.names = JSON([names..]) @@ -59,13 +63,13 @@ const enableKernelGC = true; // v$NN.vs.$key = string // v$NN.meter = m$NN // exclude from consensus -// v$NN.lastSnapshot = JSON({ snapshotID, startPos }) +// local.v$NN.lastSnapshot = JSON({ snapshotID, startPos }) // m$NN.remaining = $NN // remaining capacity (in computrons) or 'unlimited' // m$NN.threshold = $NN // notify when .remaining first drops below this // exclude from consensus -// snapshot.$id = [vatID, ...] +// local.snapshot.$id = [vatID, ...] // d$NN.o.nextID = $NN // d$NN.c.$kernelSlot = $deviceSlot = o-$NN/d+$NN/d-$NN diff --git a/packages/SwingSet/src/kernel/state/vatKeeper.js b/packages/SwingSet/src/kernel/state/vatKeeper.js index 236b485c338..f043c9db5f9 100644 --- a/packages/SwingSet/src/kernel/state/vatKeeper.js +++ b/packages/SwingSet/src/kernel/state/vatKeeper.js @@ -445,7 +445,7 @@ export function makeVatKeeper( * @returns {{ snapshotID: string, startPos: StreamPosition } | undefined} */ function getLastSnapshot() { - const notation = kvStore.get(`${vatID}.lastSnapshot`); + const notation = kvStore.get(`local.${vatID}.lastSnapshot`); if (!notation) { return undefined; } @@ -470,7 +470,7 @@ export function makeVatKeeper( * @param {string} snapshotID */ function addToSnapshot(snapshotID) { - const key = `snapshot.${snapshotID}`; + const key = `local.snapshot.${snapshotID}`; const consumers = JSON.parse(kvStore.get(key) || '[]'); assert(Array.isArray(consumers)); @@ -493,7 +493,7 @@ export function makeVatKeeper( * @param {string} snapshotID */ function removeFromSnapshot(snapshotID) { - const key = `snapshot.${snapshotID}`; + const key = `local.snapshot.${snapshotID}`; const consumersJSON = kvStore.get(key); assert(consumersJSON, X`cannot remove ${vatID}: ${key} key not defined`); const consumers = JSON.parse(consumersJSON); @@ -526,7 +526,7 @@ export function makeVatKeeper( } const endPosition = getTranscriptEndPosition(); kvStore.set( - `${vatID}.lastSnapshot`, + `local.${vatID}.lastSnapshot`, JSON.stringify({ snapshotID, startPos: endPosition }), ); addToSnapshot(snapshotID); diff --git a/packages/SwingSet/test/vat-warehouse/test-reload-snapshot.js b/packages/SwingSet/test/vat-warehouse/test-reload-snapshot.js index 712f3f69827..422012c2509 100644 --- a/packages/SwingSet/test/vat-warehouse/test-reload-snapshot.js +++ b/packages/SwingSet/test/vat-warehouse/test-reload-snapshot.js @@ -33,7 +33,7 @@ test('vat reload from snapshot', async t => { const vatID = c1.vatNameToID('target'); function getPositions() { - const lastSnapshot = hostStorage.kvStore.get(`${vatID}.lastSnapshot`); + const lastSnapshot = hostStorage.kvStore.get(`local.${vatID}.lastSnapshot`); const start = lastSnapshot ? JSON.parse(lastSnapshot).startPos.itemCount : 0; diff --git a/packages/SwingSet/test/vat-warehouse/test-warehouse.js b/packages/SwingSet/test/vat-warehouse/test-warehouse.js index 18a77b7a2eb..78b3dc13db6 100644 --- a/packages/SwingSet/test/vat-warehouse/test-warehouse.js +++ b/packages/SwingSet/test/vat-warehouse/test-warehouse.js @@ -103,10 +103,10 @@ test('4 vats in warehouse with 2 online', async t => { function unusedSnapshotsOnDisk(kvStore, snapstorePath) { const inUse = []; - for (const k of kvStore.getKeys(`snapshot.`, `snapshot/`)) { + for (const k of kvStore.getKeys(`local.snapshot.`, `local.snapshot/`)) { const consumers = JSON.parse(kvStore.get(k)); if (consumers.length > 0) { - const id = k.slice(`snapshot.`.length); + const id = k.slice(`local.snapshot.`.length); inUse.push(id); } }