Skip to content

Commit

Permalink
fix(swingset): rename snapshot-related DB keys to be "local"
Browse files Browse the repository at this point in the history
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.`.
  • Loading branch information
warner committed Aug 12, 2021
1 parent 3b860fa commit e79e43c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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..])
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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));

Expand All @@ -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);
Expand Down Expand Up @@ -526,7 +526,7 @@ export function makeVatKeeper(
}
const endPosition = getTranscriptEndPosition();
kvStore.set(
`${vatID}.lastSnapshot`,
`local.${vatID}.lastSnapshot`,
JSON.stringify({ snapshotID, startPos: endPosition }),
);
addToSnapshot(snapshotID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/test/vat-warehouse/test-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit e79e43c

Please sign in to comment.