Skip to content

Commit

Permalink
feat(swingset-vat): add xs-worker managerType
Browse files Browse the repository at this point in the history
If any vats are configured to use it, but xs-vat-worker does not have
an executable to offer, swingset will throw an error. (IOU a test?)

 - Swingset package depends on xs-vat-worker
   - ISSUE: cycle. factor out liveslots?
 - add startXsWorker kernel endowment,
   which is undefined unless binary is built
 - parameterize execPath, args in startSubprocessWorker()
   (mantain previous defaults)
 - xs-vat-worker: adopt array style protocol from SwingSet (WIP)
   - based on subprocessSupervisor.js
     copied SwingSet/src/kernel/vatManager/subprocessSupervisor.js
     wholesale; applied ocap discipline to module-level mutable state;
     adapted IO interface. Compare:

Initially it would hang after the first 2 syscalls of the first
deliver:

 - [ 'subscribe', 'p-60' ]
 - [ 'subscribe', 'p-61' ]

Then I fixed handle() to return a promise in all cases to be sure to
finish delivery before next blocking read.
  • Loading branch information
dckc committed Aug 25, 2020
1 parent 5313fdf commit 2db022d
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 99 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@agoric/tame-metering": "^1.2.3",
"@agoric/transform-eventual-send": "^1.3.1",
"@agoric/transform-metering": "^1.3.0",
"@agoric/xs-vat-worker": "^0.1.0",
"@babel/core": "^7.5.0",
"@babel/generator": "^7.6.4",
"anylogger": "^0.21.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { importBundle } from '@agoric/import-bundle';
import { initSwingStore } from '@agoric/swing-store-simple';
import { makeMeteringTransformer } from '@agoric/transform-metering';
import { makeTransform } from '@agoric/transform-eventual-send';
import { xsWorkerBin } from '@agoric/xs-vat-worker';

import { startSubprocessWorker } from './spawnSubprocessWorker';
import { assertKnownOptions } from './assertOptions';
Expand Down Expand Up @@ -321,6 +322,10 @@ export async function buildVatController(
// console.log(`--slog ${JSON.stringify(obj)}`);
}

const startXsWorker = xsWorkerBin
? () => startSubprocessWorker(xsWorkerBin, [])
: undefined;

const kernelEndowments = {
waitUntilQuiescent,
hostStorage,
Expand All @@ -333,6 +338,7 @@ export async function buildVatController(
makeNodeWorker,
startSubprocessWorker,
writeSlogObject,
startXsWorker,
};

const kernelOptions = { verbose };
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 @@ -52,6 +52,7 @@ export default function buildKernel(kernelEndowments, kernelOptions = {}) {
makeNodeWorker,
startSubprocessWorker,
writeSlogObject,
startXsWorker,
} = kernelEndowments;
const { verbose } = kernelOptions;
const logStartup = verbose ? console.debug : () => 0;
Expand Down Expand Up @@ -613,6 +614,7 @@ export default function buildKernel(kernelEndowments, kernelOptions = {}) {
waitUntilQuiescent,
makeNodeWorker,
startSubprocessWorker,
startXsWorker,
});

function buildVatSyscallHandler(vatID, translators) {
Expand Down
13 changes: 13 additions & 0 deletions packages/SwingSet/src/kernel/vatManager/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function makeVatManagerFactory({
waitUntilQuiescent,
makeNodeWorker,
startSubprocessWorker,
startXsWorker,
}) {
const localFactory = makeLocalVatManagerFactory({
allVatPowers,
Expand All @@ -34,6 +35,11 @@ export function makeVatManagerFactory({
kernelKeeper,
});

const xsWorkerFactory = makeNodeSubprocessFactory({
startSubprocessWorker: startXsWorker,
kernelKeeper,
});

function validateManagerOptions(managerOptions) {
assertKnownOptions(managerOptions, [
'enablePipelining',
Expand Down Expand Up @@ -93,6 +99,13 @@ export function makeVatManagerFactory({
);
}

if (managerType === 'xs-worker') {
if (!xsWorkerFactory) {
throw new Error('manager type xs-worker not available');
}
return xsWorkerFactory.createFromBundle(vatID, bundle, managerOptions);
}

throw Error(
`unknown type ${managerType}, not local/nodeWorker/node-subprocess`,
);
Expand Down
6 changes: 4 additions & 2 deletions packages/SwingSet/src/spawnSubprocessWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ const supercode = require.resolve(
// always be Node.
const stdio = harden(['inherit', 'inherit', 'inherit', 'pipe', 'pipe']);

export function startSubprocessWorker() {
const proc = spawn(process.execPath, ['-r', 'esm', supercode], { stdio });
export function startSubprocessWorker(execPath, args) {
execPath = execPath || process.execPath;
args = args || ['-r', 'esm', supercode];
const proc = spawn(execPath, args, { stdio });

const toChild = Netstring.writeStream();
toChild.pipe(proc.stdio[3]);
Expand Down
18 changes: 18 additions & 0 deletions packages/SwingSet/test/workers/test-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import '@agoric/install-ses';
import test from 'ava';
import { xsWorkerBin } from '@agoric/xs-vat-worker/src/locate';
import { loadBasedir, buildVatController } from '../../src/index';

test('xs vat manager', async t => {
if (!xsWorkerBin) {
console.warn('XS vat worker not built; skipping');
t.falsy.skip(false);
return;
}

const config = await loadBasedir(__dirname);
config.vats.target.creationOptions = { managerType: 'xs-worker' };
const c = await buildVatController(config, []);

await c.run();
t.is(c.bootstrapResult.status(), 'fulfilled');

await c.shutdown();
});

test('nodeWorker vat manager', async t => {
const config = await loadBasedir(__dirname);
config.vats.target.creationOptions = { managerType: 'nodeWorker' };
Expand Down
1 change: 1 addition & 0 deletions packages/xs-vat-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@agoric/eventual-send": "^0.9.3",
"@agoric/import-bundle": "^0.0.8",
"@agoric/install-ses": "^0.2.0",
"@agoric/marshal": "^0.2.3",
"@agoric/promise-kit": "^0.1.3",
"@agoric/swingset-vat": "^0.6.0",
"anylogger": "^1.0.4",
Expand Down
Loading

0 comments on commit 2db022d

Please sign in to comment.