Skip to content

Commit

Permalink
feat: add config flag to control fakeDurable
Browse files Browse the repository at this point in the history
Closes #5489
  • Loading branch information
FUDCo committed Jun 7, 2022
1 parent c6db041 commit 4690822
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/src/controller/initializeKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function initializeKernel(config, hostStorage, verbose = false) {
kernelKeeper.createStartingKernelState(
config.defaultManagerType || 'local',
config.defaultReapInterval || 1,
!!config.enableFakeDurable,
);

for (const id of Object.keys(config.idToBundle || {})) {
Expand Down
19 changes: 18 additions & 1 deletion packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const enableKernelGC = true;
//
// kernel.defaultManagerType = managerType
// kernel.defaultReapInterval = $NN
// kernel.enableFakeDurable = missing | 'true'

// v$NN.source = JSON({ bundle }) or JSON({ bundleName })
// v$NN.options = JSON
Expand Down Expand Up @@ -259,8 +260,13 @@ export default function makeKernelKeeper(
/**
* @param { ManagerType } defaultManagerType
* @param { number } defaultReapInterval
* @param { boolean } enableFakeDurable
*/
function createStartingKernelState(defaultManagerType, defaultReapInterval) {
function createStartingKernelState(
defaultManagerType,
defaultReapInterval,
enableFakeDurable,
) {
kvStore.set('vat.names', '[]');
kvStore.set('vat.dynamicIDs', '[]');
kvStore.set('vat.nextID', `${FIRST_VAT_ID}`);
Expand All @@ -278,6 +284,9 @@ export default function makeKernelKeeper(
kvStore.set('crankNumber', `${FIRST_CRANK_NUMBER}`);
kvStore.set('kernel.defaultManagerType', defaultManagerType);
kvStore.set('kernel.defaultReapInterval', `${defaultReapInterval}`);
if (enableFakeDurable) {
kvStore.set('kernel.enableFakeDurable', 'true');
}
// Will be saved in the bootstrap commit
initializeStats();
}
Expand Down Expand Up @@ -317,6 +326,13 @@ export default function makeKernelKeeper(
return ri;
}

/**
* @returns { boolean }
*/
function getEnableFakeDurable() {
return !!kvStore.get('kernel.enableFakeDurable');
}

const bundleIDRE = new RegExp('^b1-[0-9a-f]{128}$');

/**
Expand Down Expand Up @@ -1474,6 +1490,7 @@ export default function makeKernelKeeper(
createStartingKernelState,
getDefaultManagerType,
getDefaultReapInterval,
getEnableFakeDurable,

addNamedBundleID,
getNamedBundleID,
Expand Down
15 changes: 14 additions & 1 deletion packages/SwingSet/src/kernel/vat-loader/manager-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { makeTranscriptManager } from './transcript.js';
* makeSnapshot?: (ss: SnapStore) => Promise<string>) => VatManager,
* syscallFromWorker: (vso: VatSyscallObject) => VatSyscallResult,
* setDeliverToWorker: (dtw: unknown) => void,
* getEnableFakeDurable: () => boolean,
* } } ManagerKit
*
*/
Expand Down Expand Up @@ -264,6 +265,13 @@ function makeManagerKit(
return vres;
}

/**
* @returns { boolean }
*/
function getEnableFakeDurable() {
return kernelKeeper.getEnableFakeDurable();
}

/**
*
* @param { () => Promise<void>} shutdown
Expand All @@ -280,7 +288,12 @@ function makeManagerKit(
});
}

return harden({ getManager, syscallFromWorker, setDeliverToWorker });
return harden({
getManager,
syscallFromWorker,
setDeliverToWorker,
getEnableFakeDurable,
});
}
harden(makeManagerKit);
export { makeManagerKit };
1 change: 1 addition & 0 deletions packages/SwingSet/src/kernel/vat-loader/manager-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function makeLocalVatManagerFactory(tools) {
gcTools,
makeVatConsole(makeLogMaker('ls')),
buildVatNamespace,
kernelKeeper.getEnableFakeDurable(),
);
assert(ls.dispatch);
return finish(ls.dispatch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ export function makeNodeWorkerVatManagerFactory(tools) {
gotWorker(worker);

parentLog(`instructing worker to load bundle..`);
sendToWorker(['setBundle', bundle, virtualObjectCacheSize, enableDisavow]);
sendToWorker([
'setBundle',
bundle,
virtualObjectCacheSize,
enableDisavow,
mk.getEnableFakeDurable(),
]);

function deliverToWorker(delivery) {
parentLog(`sending delivery`, delivery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ export function makeNodeSubprocessFactory(tools) {
fromChild.on('data', handleUpstream);

parentLog(`instructing worker to load bundle..`);
sendToWorker(['setBundle', bundle, virtualObjectCacheSize, enableDisavow]);
sendToWorker([
'setBundle',
bundle,
virtualObjectCacheSize,
enableDisavow,
mk.getEnableFakeDurable(),
]);

function shutdown() {
terminate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function makeXsSubprocessFactory({
bundle,
virtualObjectCacheSize,
enableDisavow,
mk.getEnableFakeDurable(),
gcEveryCrank,
]);
if (bundleReply[0] === 'dispatchReady') {
Expand Down
32 changes: 16 additions & 16 deletions packages/SwingSet/src/liveslots/collectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function makeCollectionManager(
registerValue,
serialize,
unserialize,
enableFakeDurable,
) {
// TODO(#5058): we hold a list of all collections (both virtual and
// durable) in RAM, so we can delete the virtual ones during
Expand Down Expand Up @@ -781,6 +782,17 @@ export function makeCollectionManager(
return Far('weakSetStore', weakSetStore);
}

function assertCorrectDurabilityFlags(durable, fakeDurable) {
assert(
enableFakeDurable || !fakeDurable,
'fakeDurable may only be used if enableFakeDurable is true',
);
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
}

/**
* Produce a *scalar* big map: keys can only be atomic values, primitives, or
* remotables.
Expand All @@ -799,10 +811,7 @@ export function makeCollectionManager(
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
assertCorrectDurabilityFlags(durable, fakeDurable);
const kindName = durable ? 'scalarDurableMapStore' : 'scalarMapStore';
const [vobjID, collection] = makeCollection(
label,
Expand Down Expand Up @@ -853,10 +862,7 @@ export function makeCollectionManager(
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
assertCorrectDurabilityFlags(durable, fakeDurable);
const kindName = durable
? 'scalarDurableWeakMapStore'
: 'scalarWeakMapStore';
Expand Down Expand Up @@ -892,10 +898,7 @@ export function makeCollectionManager(
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
assertCorrectDurabilityFlags(durable, fakeDurable);
const kindName = durable ? 'scalarDurableSetStore' : 'scalarSetStore';
const [vobjID, collection] = makeCollection(
label,
Expand Down Expand Up @@ -929,10 +932,7 @@ export function makeCollectionManager(
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
assertCorrectDurabilityFlags(durable, fakeDurable);
const kindName = durable
? 'scalarDurableWeakSetStore'
: 'scalarWeakSetStore';
Expand Down
7 changes: 7 additions & 0 deletions packages/SwingSet/src/liveslots/liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const DEFAULT_VIRTUAL_OBJECT_CACHE_SIZE = 3; // XXX ridiculously small value to
* meterControl }
* @param {Console} console
* @param {*} buildVatNamespace
* @param {boolean} enableFakeDurable
*
* @returns {*} { dispatch }
*/
Expand All @@ -52,6 +53,7 @@ function build(
gcTools,
console,
buildVatNamespace,
enableFakeDurable,
) {
const { WeakRef, FinalizationRegistry, meterControl } = gcTools;
const enableLSDebug = false;
Expand Down Expand Up @@ -591,6 +593,7 @@ function build(
m.serialize,
unmeteredUnserialize,
cacheSize,
enableFakeDurable,
);

const collectionManager = makeCollectionManager(
Expand All @@ -605,6 +608,7 @@ function build(
registerValue,
m.serialize,
unmeteredUnserialize,
enableFakeDurable,
);

const watchedPromiseManager = makeWatchedPromiseManager(
Expand Down Expand Up @@ -1452,6 +1456,7 @@ function build(
* @param {*} gcTools { WeakRef, FinalizationRegistry, waitUntilQuiescent }
* @param {Pick<Console, 'debug' | 'log' | 'info' | 'warn' | 'error'>} [liveSlotsConsole]
* @param {*} buildVatNamespace
* @param {boolean} enableFakeDurable
*
* @returns {*} { vatGlobals, inescapableGlobalProperties, dispatch }
*
Expand Down Expand Up @@ -1486,6 +1491,7 @@ export function makeLiveSlots(
gcTools,
liveSlotsConsole = console,
buildVatNamespace,
enableFakeDurable,
) {
const allVatPowers = {
...vatPowers,
Expand All @@ -1500,6 +1506,7 @@ export function makeLiveSlots(
gcTools,
liveSlotsConsole,
buildVatNamespace,
enableFakeDurable,
);
const { dispatch, startVat, possiblyDeadSet, testHooks } = r; // omit 'm'
return harden({
Expand Down
6 changes: 6 additions & 0 deletions packages/SwingSet/src/liveslots/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export function makeCache(size, fetch, store) {
* @param {*} unserialize Unserializer for this vat
* @param {number} cacheSize How many virtual objects this manager should cache
* in memory.
* @param {boolean} enableFakeDurable True iff the associated kernel is running in dev mode.
*
* @returns a new virtual object manager.
*
Expand Down Expand Up @@ -189,6 +190,7 @@ export function makeVirtualObjectManager(
serialize,
unserialize,
cacheSize,
enableFakeDurable,
) {
const cache = makeCache(cacheSize, fetch, store);

Expand Down Expand Up @@ -578,6 +580,10 @@ export function makeVirtualObjectManager(
({ finish, fakeDurable } = options);
}
if (fakeDurable) {
assert(
enableFakeDurable,
`fakeDurable may only be used if enableFakeDurable is true`,
);
assert(
durable,
`the fakeDurable option may only be applied to durable objects`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ parentPort.on('message', ([type, ...margs]) => {
workerLog(`got start`);
sendUplink(['gotStart']);
} else if (type === 'setBundle') {
const [bundle, virtualObjectCacheSize, enableDisavow] = margs;
const [bundle, virtualObjectCacheSize, enableDisavow, enableFakeDurable] =
margs;

function testLog(...args) {
sendUplink(['testLog', ...args]);
Expand Down Expand Up @@ -111,6 +112,7 @@ parentPort.on('message', ([type, ...margs]) => {
gcTools,
makeVatConsole(makeLogMaker(`SwingSet:ls:${vatID}`)),
buildVatNamespace,
enableFakeDurable,
);

sendUplink(['gotBundle']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ fromParent.on('data', ([type, ...margs]) => {
workerLog(`got start`);
sendUplink(['gotStart']);
} else if (type === 'setBundle') {
const [bundle, virtualObjectCacheSize, enableDisavow] = margs;
const [bundle, virtualObjectCacheSize, enableDisavow, enableFakeDurable] =
margs;

function testLog(...args) {
sendUplink(['testLog', ...args]);
Expand Down Expand Up @@ -131,6 +132,7 @@ fromParent.on('data', ([type, ...margs]) => {
gcTools,
makeVatConsole(makeLogMaker(`SwingSet:ls:${vatID}`)),
buildVatNamespace,
enableFakeDurable,
);

sendUplink(['gotBundle']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function makeWorker(port) {
* @param {unknown} bundle
* @param {unknown} virtualObjectCacheSize
* @param {boolean} enableDisavow
* @param {boolean} enableFakeDurable
* @param {boolean} [gcEveryCrank]
* @returns { Promise<Tagged> }
*/
Expand All @@ -193,6 +194,7 @@ function makeWorker(port) {
bundle,
virtualObjectCacheSize,
enableDisavow,
enableFakeDurable,
gcEveryCrank,
) {
/** @type { (vso: VatSyscallObject) => VatSyscallResult } */
Expand Down Expand Up @@ -293,6 +295,7 @@ function makeWorker(port) {
gcTools,
makeVatConsole(makeLogMaker('ls')),
buildVatNamespace,
enableFakeDurable,
);

assert(ls.dispatch);
Expand All @@ -308,12 +311,14 @@ function makeWorker(port) {
case 'setBundle': {
assert(!dispatch, 'cannot setBundle again');
const enableDisavow = !!args[3];
const gcEveryCrank = args[4] === undefined ? true : !!args[4];
const enableFakeDurable = !!args[4];
const gcEveryCrank = args[5] === undefined ? true : !!args[5];
return setBundle(
args[0],
args[1],
args[2],
enableDisavow,
enableFakeDurable,
gcEveryCrank,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Far } from '@endo/marshal';
import {
makeKindHandle,
defineDurableKind,
makeScalarBigMapStore,
} from '@agoric/vat-data';

export function buildRootObject() {
return Far('root', {
bootstrap() {},

testStore() {
makeScalarBigMapStore('dfstore', { fakeDurable: true });
},

testObj() {
const kh = makeKindHandle('kh');
defineDurableKind(kh, () => ({}), {}, { fakeDurable: true });
},
});
}
Loading

0 comments on commit 4690822

Please sign in to comment.