Skip to content

Commit

Permalink
feat: don't load unendowed devices
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed May 11, 2021
1 parent 79ce78b commit d6c1de6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
26 changes: 16 additions & 10 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ export default function buildKernel(
logStartup(`starting device ${name} as ${deviceID}`);
const deviceKeeper = kernelKeeper.allocateDeviceKeeperIfNeeded(deviceID);
const { source, options } = deviceKeeper.getSourceAndOptions();
assertKnownOptions(options, ['deviceParameters']);
const { deviceParameters = {} } = options;
assertKnownOptions(options, ['deviceParameters', 'unendowed']);
const { deviceParameters = {}, unendowed } = options;
const devConsole = makeConsole(`${debugPrefix}SwingSet:dev-${name}`);
// eslint-disable-next-line no-await-in-loop
const NS = await importBundle(source.bundle, {
Expand All @@ -887,14 +887,20 @@ export default function buildKernel(
typeof NS.buildRootDeviceNode === 'function',
`device ${name} lacks buildRootDeviceNode`,
);
const manager = buildDeviceManager(
deviceID,
name,
NS.buildRootDeviceNode,
deviceEndowments[name],
deviceParameters,
);
addDeviceManager(deviceID, name, manager);
if (deviceEndowments[name] || unendowed) {
const manager = buildDeviceManager(
deviceID,
name,
NS.buildRootDeviceNode,
deviceEndowments[name],
deviceParameters,
);
addDeviceManager(deviceID, name, manager);
} else {
console.log(
`WARNING: skipping device ${deviceID} (${name}) because it has no endowments`,
);
}
}

// replay any transcripts
Expand Down
8 changes: 6 additions & 2 deletions packages/SwingSet/test/test-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async function test2(t, mode) {
devices: {
d2: {
sourceSpec: require.resolve('./files-devices/device-2'),
creationOptions: { unendowed: true },
},
},
};
Expand Down Expand Up @@ -223,6 +224,7 @@ test.serial('device state', async t => {
devices: {
d3: {
sourceSpec: require.resolve('./files-devices/device-3'),
creationOptions: { unendowed: true },
},
},
};
Expand Down Expand Up @@ -492,12 +494,13 @@ test.serial('liveslots throws when D() gets promise', async t => {
devices: {
d0: {
sourceSpec: require.resolve('./files-devices/device-0'),
creationOptions: { unendowed: true },
},
},
};
const storage = initSwingStore().storage;
await initializeSwingset(config, ['promise1'], storage, t.context.data);
const c = await makeSwingsetController(storage, { d0: {} });
const c = await makeSwingsetController(storage, {});
await c.step();
// When liveslots catches an attempt to send a promise into D(), it throws
// a regular error, which the vat can catch.
Expand Down Expand Up @@ -527,12 +530,13 @@ test.serial('syscall.callNow(promise) is vat-fatal', async t => {
devices: {
d0: {
sourceSpec: require.resolve('./files-devices/device-0'),
creationOptions: { unendowed: true },
},
},
};
const storage = initSwingStore().storage;
await initializeSwingset(config, [], storage, t.context.data);
const c = await makeSwingsetController(storage, { d0: {} });
const c = await makeSwingsetController(storage, {});
await c.step();
// if the kernel paniced, that c.step() will reject, and the await will throw
t.deepEqual(c.dump().log, ['sending Promise', 'good: callNow failed']);
Expand Down
3 changes: 3 additions & 0 deletions packages/SwingSet/test/workers/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ async function makeController(managerType) {
config.devices = {
add: {
sourceSpec: require.resolve('./device-add.js'),
creationOptions: {
unendowed: true,
},
},
};
const c = await buildVatController(config, []);
Expand Down

0 comments on commit d6c1de6

Please sign in to comment.