Skip to content

Commit

Permalink
feat(SwingSet): new overrideVatManagerOptions kernel option
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 14, 2021
1 parent ea3280e commit 1ec045b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
9 changes: 6 additions & 3 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export function makeStartXSnap(bundles, { snapStore, env, spawn }) {
* slogCallbacks?: unknown,
* slogFile?: string,
* testTrackDecref?: unknown,
* warehousePolicy?: { maxVatsOnline?: number, consensusMode?: boolean },
* warehousePolicy?: { maxVatsOnline?: number },
* overrideVatManagerOptions?: { consensusMode?: boolean },
* spawn?: typeof import('child_process').spawn,
* env?: Record<string, string | undefined>
* }} runtimeOptions
Expand All @@ -147,6 +148,7 @@ export async function makeSwingsetController(
slogFile,
spawn = ambientSpawn,
warehousePolicy = {},
overrideVatManagerOptions = {},
} = runtimeOptions;
if (typeof Compartment === 'undefined') {
throw Error('SES must be installed before calling makeSwingsetController');
Expand Down Expand Up @@ -306,7 +308,7 @@ export async function makeSwingsetController(
gcAndFinalize: makeGcAndFinalize(engineGC),
};

const kernelOptions = { verbose, warehousePolicy };
const kernelOptions = { verbose, warehousePolicy, overrideVatManagerOptions };
/** @type { ReturnType<typeof import('./kernel').default> } */
const kernel = buildKernel(kernelEndowments, deviceEndowments, kernelOptions);

Expand Down Expand Up @@ -420,7 +422,8 @@ export async function makeSwingsetController(
* debugPrefix?: string,
* slogCallbacks?: unknown,
* testTrackDecref?: unknown,
* warehousePolicy?: { maxVatsOnline?: number, consensusMode?: boolean },
* warehousePolicy?: { maxVatsOnline?: number },
* overrideVatManagerOptions?: { consensusMode?: boolean },
* slogFile?: string,
* }} runtimeOptions
* @typedef { import('@agoric/swing-store-simple').KVStore } KVStore
Expand Down
2 changes: 2 additions & 0 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default function buildKernel(
verbose,
defaultManagerType = 'local',
warehousePolicy,
overrideVatManagerOptions = {},
} = kernelOptions;
const logStartup = verbose ? console.debug : () => 0;

Expand Down Expand Up @@ -800,6 +801,7 @@ export default function buildKernel(
panic,
buildVatSyscallHandler,
vatAdminRootKref,
overrideVatManagerOptions,
});

const vatWarehouse = makeVatWarehouse(
Expand Down
10 changes: 3 additions & 7 deletions packages/SwingSet/src/kernel/loadVat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function makeVatRootObjectSlot() {

export function makeVatLoader(stuff) {
const {
overrideVatManagerOptions = {},
vatManagerFactory,
kernelSlog,
makeVatConsole,
Expand Down Expand Up @@ -85,7 +86,6 @@ export function makeVatLoader(stuff) {
}

const allowedDynamicOptions = [
'consensusMode',
'description',
'metered',
'managerType', // TODO: not sure we want vats to be able to control this
Expand All @@ -98,7 +98,6 @@ export function makeVatLoader(stuff) {
];

const allowedStaticOptions = [
'consensusMode',
'description',
'name',
'vatParameters',
Expand Down Expand Up @@ -132,9 +131,6 @@ export function makeVatLoader(stuff) {
*
* @param {ManagerType} options.managerType
*
* @param {boolean} options.consensusMode if true,
* turn off debugging features provided to a vat that may cause nondeterminism
*
* @param {number} options.virtualObjectCacheSize
*
* @param {boolean} [options.metered] if true,
Expand Down Expand Up @@ -203,7 +199,6 @@ export function makeVatLoader(stuff) {
isDynamic ? allowedDynamicOptions : allowedStaticOptions,
);
const {
consensusMode,
metered = isDynamic,
vatParameters = {},
managerType,
Expand Down Expand Up @@ -234,7 +229,6 @@ export function makeVatLoader(stuff) {
);

const managerOptions = {
consensusMode,
managerType,
bundle: vatSourceBundle,
metered,
Expand All @@ -248,6 +242,7 @@ export function makeVatLoader(stuff) {
virtualObjectCacheSize,
useTranscript,
name,
...overrideVatManagerOptions,
};

const vatSyscallHandler = buildVatSyscallHandler(vatID, translators);
Expand All @@ -269,6 +264,7 @@ export function makeVatLoader(stuff) {
enableSetup: true,
managerType: 'local',
useTranscript: true,
...overrideVatManagerOptions,
};
const translators = makeVatTranslators(vatID, kernelKeeper);
const vatSyscallHandler = buildVatSyscallHandler(vatID, translators);
Expand Down
7 changes: 2 additions & 5 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,10 @@ export function makeVatKeeper(
kvStore.set(`${vatID}.options`, JSON.stringify(options));
}

/**
* @param {boolean} consensusMode
*/
function getSourceAndOptions(consensusMode) {
function getSourceAndOptions() {
const source = JSON.parse(kvStore.get(`${vatID}.source`));
const options = JSON.parse(kvStore.get(`${vatID}.options`));
return harden({ source, options: { ...options, consensusMode } });
return harden({ source, options });
}

function getOptions() {
Expand Down
4 changes: 1 addition & 3 deletions packages/SwingSet/src/kernel/vatManager/supervisor-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ function makeVatConsole(logger, wrapper = true) {
const cons = Object.fromEntries(
['debug', 'log', 'info', 'warn', 'error'].map(level => {
if (wrapper === false) {
// Static wrapper that never enables. We create unique no-op functions
// so that the different log methods cannot be compared to detect this
// mode.
// Static wrapper that never enables.
return [level, () => {}];
}

Expand Down
5 changes: 1 addition & 4 deletions packages/SwingSet/src/kernel/vatManager/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const makeLRU = max => {
* @param { KernelKeeper } kernelKeeper
* @param { ReturnType<typeof import('../loadVat.js').makeVatLoader> } vatLoader
* @param {{
* consensusMode: boolean,
* maxVatsOnline?: number,
* snapshotInitial?: number,
* snapshotInterval?: number,
Expand All @@ -59,8 +58,6 @@ export const makeLRU = max => {
*/
export function makeVatWarehouse(kernelKeeper, vatLoader, policyOptions) {
const {
// Whether to eliminate all vat nodeterminism.
consensusMode = false,
maxVatsOnline = 50,
// Often a large contract evaluation is among the first few deliveries,
// so let's do a snapshot after just a few deliveries.
Expand Down Expand Up @@ -111,7 +108,7 @@ export function makeVatWarehouse(kernelKeeper, vatLoader, policyOptions) {

assert(kernelKeeper.vatIsAlive(vatID), X`${q(vatID)}: not alive`);
const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
const { source, options } = vatKeeper.getSourceAndOptions(consensusMode);
const { source, options } = vatKeeper.getSourceAndOptions();

const translators = provideTranslators(vatID);

Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function buildSwingset(
const controller = await makeSwingsetController(
hostStorage,
deviceEndowments,
{ warehousePolicy: { consensusMode }, slogCallbacks, slogFile },
{ overrideVatManagerOptions: { consensusMode }, slogCallbacks, slogFile },
);

// We DON'T want to run the kernel yet, only when the application decides
Expand Down

0 comments on commit 1ec045b

Please sign in to comment.