Skip to content

Commit

Permalink
chore: refactor crank commit/abort logic
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Dec 13, 2022
1 parent f685383 commit c63246f
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 182 deletions.
9 changes: 7 additions & 2 deletions packages/SwingSet/src/controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export async function makeSwingsetController(
const vatID = kernel.vatNameToID(vatName);
const kref = kernel.getRootObject(vatID);
kernel.pinObject(kref);
kernelStorage.emitCrankHashes();
return kref;
},

Expand All @@ -440,7 +441,9 @@ export async function makeSwingsetController(
},

kpResolution(kpid) {
return kernel.kpResolution(kpid);
const result = kernel.kpResolution(kpid);
kernelStorage.emitCrankHashes();
return result;
},
vatNameToID(vatName) {
return kernel.vatNameToID(vatName);
Expand All @@ -463,6 +466,7 @@ export async function makeSwingsetController(
if (kpid) {
kernel.kpRegisterInterest(kpid);
}
kernelStorage.emitCrankHashes();
return kpid;
},

Expand All @@ -475,12 +479,13 @@ export async function makeSwingsetController(
if (!options.upgradeMessage) {
options.upgradeMessage = `vat ${vatName} upgraded`;
}
return controller.queueToVatRoot(
const result = controller.queueToVatRoot(
'vatAdmin',
'upgradeStaticVat',
[vatID, pauseTarget, bundleID, options],
'ignore',
);
return result;
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/initializeKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function initializeKernel(config, kernelStorage, verbose = false) {
}
}
kernelKeeper.setInitialized();
kernelKeeper.commitCrank(); // commit initialized kernel state as crank #0
kernelKeeper.emitCrankHashes();
return bootstrapResultKpid;

// ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export async function initializeSwingset(

kvStore.set('lockdownBundle', JSON.stringify(kernelBundles.lockdown));
kvStore.set('supervisorBundle', JSON.stringify(kernelBundles.supervisor));
kernelStorage.resetCrankhash();
kernelStorage.emitCrankHashes();

if (config.bootstrap && argv) {
const bootConfig = config.vats[config.bootstrap];
Expand Down
20 changes: 14 additions & 6 deletions packages/SwingSet/src/kernel/gc-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ function parseAction(s) {
return { vatID, type, kref };
}

export function processNextGCAction(kernelKeeper) {
export function processGCActionSet(kernelKeeper) {
const allActionsSet = kernelKeeper.getGCActions();
let actionSetUpdated = false;

// GC actions are each one of 'dropExport', 'retireExport', or
// 'retireImport', aimed at a specific vat and affecting a specific kref.
// They are added to the durable "GC Actions" set (stored in kernelDB) when
// `processRefcounts` notices a refcount sitting at zero, which means some
// vat needs to be told that an object can be freed. Before each crank, the
// kernel calls processNextGCAction to see if there are any GC actions that
// kernel calls processGCActionSet to see if there are any GC actions that
// should be taken. All such GC actions are executed before any regular vat
// delivery gets to run.

Expand Down Expand Up @@ -90,6 +91,7 @@ export function processNextGCAction(kernelKeeper) {
krefs.push(kref);
}
allActionsSet.delete(action);
actionSetUpdated = true;
}
return krefs;
}
Expand Down Expand Up @@ -126,8 +128,14 @@ export function processNextGCAction(kernelKeeper) {
}
}
}
// remove negated items from the durable set
kernelKeeper.setGCActions(allActionsSet);
return undefined; // no GC work to do
if (actionSetUpdated) {
// remove negated items from the durable set
kernelKeeper.setGCActions(allActionsSet);
// return a special gc-nop event to tell kernel to record our
// DB changes in their own crank
return harden({ type: 'negated-gc-action', vatID: undefined });
} else {
return undefined; // no GC work to do and no DB changes
}
}
harden(processNextGCAction);
harden(processGCActionSet);
Loading

0 comments on commit c63246f

Please sign in to comment.