From 1801eec61b5077809cce46437b8bedd80fad6a43 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Fri, 22 Jan 2021 22:01:15 -0600 Subject: [PATCH] refactor(xsnap): fold in what's left of xs-vat-worker - prune obsolete locate.js --- packages/SwingSet/package.json | 1 - .../vatManager/lockdown-subprocess-xsnap.js | 2 +- packages/xs-vat-worker/.gitignore | 1 - packages/xs-vat-worker/.npmignore | 11 - packages/xs-vat-worker/CHANGELOG.md | 101 --------- packages/xs-vat-worker/package.json | 81 ------- packages/xs-vat-worker/src/locate.js | 16 -- packages/xs-vat-worker/src/vatWorker.js | 210 ------------------ packages/xsnap/package.json | 6 +- .../{xs-vat-worker => xsnap}/rollup.config.js | 0 .../{xs-vat-worker => xsnap}/src/bootstrap.js | 0 .../src/console-shim.js | 0 .../src/lockdown-shim.js | 1 + .../{xs-vat-worker => xsnap}/src/text-shim.js | 0 .../test/escapeCompartment.js | 0 .../test/test-boot-lockdown.js | 2 +- 16 files changed, 8 insertions(+), 424 deletions(-) delete mode 100644 packages/xs-vat-worker/.gitignore delete mode 100644 packages/xs-vat-worker/.npmignore delete mode 100644 packages/xs-vat-worker/CHANGELOG.md delete mode 100644 packages/xs-vat-worker/package.json delete mode 100644 packages/xs-vat-worker/src/locate.js delete mode 100644 packages/xs-vat-worker/src/vatWorker.js rename packages/{xs-vat-worker => xsnap}/rollup.config.js (100%) rename packages/{xs-vat-worker => xsnap}/src/bootstrap.js (100%) rename packages/{xs-vat-worker => xsnap}/src/console-shim.js (100%) rename packages/{xs-vat-worker => xsnap}/src/lockdown-shim.js (72%) rename packages/{xs-vat-worker => xsnap}/src/text-shim.js (100%) rename packages/{xs-vat-worker => xsnap}/test/escapeCompartment.js (100%) rename packages/{xs-vat-worker => xsnap}/test/test-boot-lockdown.js (97%) diff --git a/packages/SwingSet/package.json b/packages/SwingSet/package.json index 0ed59d1a1cf..6614b9d97ff 100644 --- a/packages/SwingSet/package.json +++ b/packages/SwingSet/package.json @@ -48,7 +48,6 @@ "@agoric/tame-metering": "^1.3.0", "@agoric/transform-eventual-send": "^1.4.0", "@agoric/transform-metering": "^1.4.0", - "@agoric/xs-vat-worker": "^0.4.0", "@agoric/xsnap": "^0.1.0", "@babel/core": "^7.5.0", "@babel/generator": "^7.6.4", diff --git a/packages/SwingSet/src/kernel/vatManager/lockdown-subprocess-xsnap.js b/packages/SwingSet/src/kernel/vatManager/lockdown-subprocess-xsnap.js index c058d91da4e..ed9300404b5 100644 --- a/packages/SwingSet/src/kernel/vatManager/lockdown-subprocess-xsnap.js +++ b/packages/SwingSet/src/kernel/vatManager/lockdown-subprocess-xsnap.js @@ -1 +1 @@ -import '@agoric/xs-vat-worker/src/bootstrap'; +import '@agoric/xsnap/src/bootstrap'; diff --git a/packages/xs-vat-worker/.gitignore b/packages/xs-vat-worker/.gitignore deleted file mode 100644 index 1521c8b7652..00000000000 --- a/packages/xs-vat-worker/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist diff --git a/packages/xs-vat-worker/.npmignore b/packages/xs-vat-worker/.npmignore deleted file mode 100644 index cd75c6170bf..00000000000 --- a/packages/xs-vat-worker/.npmignore +++ /dev/null @@ -1,11 +0,0 @@ -# Demo -demo - -# scripts -scripts - -# test -test - -# Travis CI -.travis.yml diff --git a/packages/xs-vat-worker/CHANGELOG.md b/packages/xs-vat-worker/CHANGELOG.md deleted file mode 100644 index 55deff9e20d..00000000000 --- a/packages/xs-vat-worker/CHANGELOG.md +++ /dev/null @@ -1,101 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -# [0.4.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.3.0...@agoric/xs-vat-worker@0.4.0) (2020-12-10) - - -### Features - -* **import-bundle:** Preliminary support Endo zip hex bundle format ([#1983](https://github.com/Agoric/agoric-sdk/issues/1983)) ([983681b](https://github.com/Agoric/agoric-sdk/commit/983681bfc4bf512b6bd90806ed9220cd4fefc13c)) - - - - - -# [0.3.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.4-dev.0...@agoric/xs-vat-worker@0.3.0) (2020-11-07) - - -### Bug Fixes - -* further cleanup based on reviews ([2e74cc7](https://github.com/Agoric/agoric-sdk/commit/2e74cc72ce1c898b24c1a2613d7864d97fe383c2)) - - -### Features - -* **assert:** Thread stack traces to console, add entangled assert ([#1884](https://github.com/Agoric/agoric-sdk/issues/1884)) ([5d4f35f](https://github.com/Agoric/agoric-sdk/commit/5d4f35f901f2ca40a2a4d66dab980a5fe8e575f4)) - - - - - -## [0.2.4-dev.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.3...@agoric/xs-vat-worker@0.2.4-dev.0) (2020-10-19) - -**Note:** Version bump only for package @agoric/xs-vat-worker - - - - - -## [0.2.3](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.3-dev.2...@agoric/xs-vat-worker@0.2.3) (2020-10-11) - - -### Bug Fixes - -* handle syscallResult and deliveryResult consistently among workers ([9e6e31a](https://github.com/Agoric/agoric-sdk/commit/9e6e31ac55521893b6fdf31785bb901345ed46af)), closes [#1775](https://github.com/Agoric/agoric-sdk/issues/1775) -* pass testLog to all vatWorkers ([29bc81a](https://github.com/Agoric/agoric-sdk/commit/29bc81a46d057532f51c37bed081d850cf7f31db)), closes [#1776](https://github.com/Agoric/agoric-sdk/issues/1776) -* xs-vat-worker: add makeMarshal to vatPowers ([1edd620](https://github.com/Agoric/agoric-sdk/commit/1edd62015e955d99fef8f75d32d2a5f1032aca38)), closes [#1776](https://github.com/Agoric/agoric-sdk/issues/1776) - - - - - -## [0.2.3-dev.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.3-dev.1...@agoric/xs-vat-worker@0.2.3-dev.2) (2020-09-18) - -**Note:** Version bump only for package @agoric/xs-vat-worker - - - - - -## [0.2.3-dev.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.3-dev.0...@agoric/xs-vat-worker@0.2.3-dev.1) (2020-09-18) - -**Note:** Version bump only for package @agoric/xs-vat-worker - - - - - -## [0.2.3-dev.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.2...@agoric/xs-vat-worker@0.2.3-dev.0) (2020-09-18) - -**Note:** Version bump only for package @agoric/xs-vat-worker - - - - - -## [0.2.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.1...@agoric/xs-vat-worker@0.2.2) (2020-09-16) - -**Note:** Version bump only for package @agoric/xs-vat-worker - - - - - -## [0.2.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/xs-vat-worker@0.2.0...@agoric/xs-vat-worker@0.2.1) (2020-08-31) - -**Note:** Version bump only for package @agoric/xs-vat-worker - - - - - -# 0.2.0 (2020-08-31) - - -### Features - -* **swingset-vat:** add xs-worker managerType ([2db022d](https://github.com/Agoric/agoric-sdk/commit/2db022d966a416c9b765c18ed543dd5adb31cc6d)) -* **xs-vat-worker:** locateWorkerBin finds built executable ([aecaeb1](https://github.com/Agoric/agoric-sdk/commit/aecaeb143668825183c5aa1b9a5c76d954b51501)) -* use npm style imports with XS build tools via compartmap ([903027a](https://github.com/Agoric/agoric-sdk/commit/903027a30299e9d9b03246bb0476bc4b94fddcf9)) diff --git a/packages/xs-vat-worker/package.json b/packages/xs-vat-worker/package.json deleted file mode 100644 index d00293ea5a9..00000000000 --- a/packages/xs-vat-worker/package.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "name": "@agoric/xs-vat-worker", - "version": "0.4.0", - "description": "swingset-vat worker for XS js runtime", - "parsers": { - "js": "mjs" - }, - "main": "src/locate.js", - "module": "src/locate.js", - "scripts": { - "test": "ava", - "build": "rollup --config rollup.config.js", - "lint-fix": "eslint --fix '**/*.{js,jsx}'", - "lint-check": "eslint '**/*.{js,jsx}'", - "lint-fix-jessie": "eslint -c '.eslintrc-jessie.js' --fix '**/*.{js,jsx}'", - "lint-check-jessie": "eslint -c '.eslintrc-jessie.js' '**/*.{js,jsx}'" - }, - "ava": { - "files": [ - "test/**/test-*.js" - ], - "require": [ - "esm" - ], - "timeout": "2m" - }, - "devDependencies": { - "@rollup/plugin-commonjs": "^11.0.2", - "@rollup/plugin-node-resolve": "^7.1.1", - "ava": "^3.12.1", - "eslint": "^6.8.0", - "eslint-config-airbnb-base": "^14.0.0", - "eslint-config-jessie": "^0.0.4", - "eslint-config-prettier": "^6.9.0", - "eslint-plugin-import": "^2.20.0", - "eslint-plugin-jsx-a11y": "^6.2.3", - "eslint-plugin-prettier": "^3.1.2", - "nyc": "^15.1.0", - "prettier": "^1.18.2", - "rollup": "^1.23.1" - }, - "dependencies": { - "@agoric/assert": "^0.2.0", - "@agoric/bundle-source": "^1.2.0", - "@agoric/eventual-send": "^0.13.0", - "@agoric/import-bundle": "^0.2.0", - "@agoric/marshal": "^0.3.0", - "@agoric/promise-kit": "^0.2.0", - "@agoric/swingset-vat": "^0.11.0", - "@agoric/xsnap": "^0.1.0", - "anylogger": "^0.21.0", - "esm": "^3.2.5", - "ses": "^0.11.0" - }, - "keywords": [], - "files": [ - "dist" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/Agoric/agoric-sdk.git" - }, - "author": "Agoric", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/Agoric/agoric-sdk/issues" - }, - "homepage": "https://github.com/Agoric/agoric-sdk#readme", - "publishConfig": { - "access": "public" - }, - "eslintConfig": { - "extends": [ - "@agoric" - ] - }, - "prettier": { - "trailingComma": "all", - "singleQuote": true - } -} diff --git a/packages/xs-vat-worker/src/locate.js b/packages/xs-vat-worker/src/locate.js deleted file mode 100644 index 41cd6a0549b..00000000000 --- a/packages/xs-vat-worker/src/locate.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Locate the XS vat worker executable. - * - * Note: executable is not built by default. - * - * @see the `build:xs-lin` script in package.json - * - * @param {{ resolve: (...string) => string }} filesystem path access - * @returns { string } full path where linux debug executable is built; - * not guaranteed to exist. - */ -export function locateWorkerBin({ resolve }) { - const goal = 'debug'; // ISSUE: support, test release too? - const os = 'lin'; // ISSUE: support, test mac too? - return resolve(__dirname, '../build/bin', os, goal, 'xs-vat-worker'); -} diff --git a/packages/xs-vat-worker/src/vatWorker.js b/packages/xs-vat-worker/src/vatWorker.js deleted file mode 100644 index 0e14053bab6..00000000000 --- a/packages/xs-vat-worker/src/vatWorker.js +++ /dev/null @@ -1,210 +0,0 @@ -/* global HandledPromise */ -import { importBundle } from '@agoric/import-bundle'; -import { Remotable, getInterfaceOf, makeMarshal } from '@agoric/marshal'; -// TODO? import anylogger from 'anylogger'; -import { makeLiveSlots } from '@agoric/swingset-vat/src/kernel/liveSlots'; - -function workerLog(first, ...args) { - console.log(`---worker: ${first}`, ...args); -} - -function assert(ok, whynot) { - if (!ok) { - throw new Error(whynot); - } -} - -function makeConsole(_tag) { - const log = console; // TODO? anylogger(tag); - const cons = {}; - for (const level of ['debug', 'log', 'info', 'warn', 'error']) { - cons[level] = log[level]; - } - return harden(cons); -} - -// see also: detecting an empty vat promise queue (end of "crank") -// https://github.com/Agoric/agoric-sdk/issues/45 -function waitUntilQuiescent(setImmediate) { - return new Promise((resolve, _reject) => { - setImmediate(() => { - // console.log('hello from setImmediate callback. The promise queue is presumably empty.'); - resolve(); - }); - }); -} - -function runAndWait(f, errmsg, setImmediate) { - Promise.resolve() - .then(f) - .then(undefined, err => workerLog(`doProcess: ${errmsg}:`, err)); - return waitUntilQuiescent(setImmediate); -} - -function makeWorker(io, setImmediate) { - let dispatch; - - async function doProcess(dispatchRecord, errmsg) { - const dispatchOp = dispatchRecord[0]; - const dispatchArgs = dispatchRecord.slice(1); - workerLog(`runAndWait`); - await runAndWait( - () => dispatch[dispatchOp](...dispatchArgs), - errmsg, - setImmediate, - ); - workerLog(`doProcess done`); - const vatDeliveryResults = harden(['ok']); - return vatDeliveryResults; - } - - function doMessage(targetSlot, msg) { - const errmsg = `vat[${targetSlot}].${msg.method} dispatch failed`; - return doProcess( - ['deliver', targetSlot, msg.method, msg.args, msg.result], - errmsg, - ); - } - - function doNotify(vpid, vp) { - const errmsg = `vat.promise[${vpid}] ${vp.state} failed`; - switch (vp.state) { - case 'fulfilledToPresence': - return doProcess(['notifyFulfillToPresence', vpid, vp.slot], errmsg); - case 'redirected': - throw new Error('not implemented yet'); - case 'fulfilledToData': - return doProcess(['notifyFulfillToData', vpid, vp.data], errmsg); - case 'rejected': - return doProcess(['notifyReject', vpid, vp.data], errmsg); - default: - throw Error(`unknown promise state '${vp.state}'`); - } - } - - function sendUplink(msg) { - assert(msg instanceof Array, `msg must be an Array`); - io.writeMessage(JSON.stringify(msg)); - } - - // fromParent.on('data', data => { - // workerLog('data from parent', data); - // toParent.write('child ack'); - // }); - - const handle = harden(async ([type, ...margs]) => { - workerLog(`received`, type); - if (type === 'start') { - // TODO: parent should send ['start', vatID] - workerLog(`got start`); - sendUplink(['gotStart']); - } else if (type === 'setBundle') { - const [bundle, vatParameters, virtualObjectCacheSize] = margs; - const endowments = { - console: makeConsole(`SwingSet:vatWorker`), - assert, - HandledPromise, - }; - // ISSUE: this draft code is contorted because it started - // as code that didn't return anything but now it - // has to return a promise to be resolved before - // reading the next input. - return importBundle(bundle, { endowments }).then(vatNS => { - workerLog(`got vatNS:`, Object.keys(vatNS).join(',')); - sendUplink(['gotBundle']); - - function doSyscall(vatSyscallObject) { - sendUplink(['syscall', ...vatSyscallObject]); - } - const syscall = harden({ - send: (...args) => doSyscall(['send', ...args]), - callNow: (..._args) => { - throw Error(`nodeWorker cannot syscall.callNow`); - }, - subscribe: (...args) => doSyscall(['subscribe', ...args]), - fulfillToData: (...args) => doSyscall(['fulfillToData', ...args]), - fulfillToPresence: (...args) => - doSyscall(['fulfillToPresence', ...args]), - reject: (...args) => doSyscall(['reject', ...args]), - }); - - function testLog(...args) { - sendUplink(['testLog', ...args]); - } - const state = null; - const vatID = 'demo-vatID'; - // todo: maybe add transformTildot, makeGetMeter/transformMetering to - // vatPowers, but only if options tell us they're wanted. Maybe - // transformTildot should be async and outsourced to the kernel - // process/thread. - const vatPowers = { - Remotable, - getInterfaceOf, - makeMarshal, - testLog, - }; - dispatch = makeLiveSlots( - syscall, - state, - vatNS.buildRootObject, - vatID, - vatPowers, - vatParameters, - virtualObjectCacheSize, - ); - workerLog(`got dispatch:`, Object.keys(dispatch).join(',')); - sendUplink(['dispatchReady']); - return type; - }); - } else if (type === 'deliver') { - if (!dispatch) { - workerLog(`error: deliver before dispatchReady`); - return undefined; - } - const [dtype, ...dargs] = margs; - if (dtype === 'message') { - await doMessage(...dargs).then(res => - sendUplink(['deliverDone', ...res]), - ); - } else if (dtype === 'notify') { - await doNotify(...dargs).then(res => - sendUplink(['deliverDone', ...res]), - ); - } else { - throw Error(`bad delivery type ${dtype}`); - } - } else { - workerLog(`unrecognized downlink message ${type}`); - } - return type; - }); - - return harden({ handle }); -} - -export async function main({ readMessage, writeMessage, setImmediate }) { - workerLog(`supervisor started`); - - const worker = makeWorker({ readMessage, writeMessage }, setImmediate); - const EOF = new Error('EOF'); - - for (;;) { - let message; - try { - // eslint-disable-next-line no-await-in-loop - message = JSON.parse(readMessage(EOF)); - } catch (noMessage) { - if (noMessage === EOF) { - return; - } - console.warn('problem getting message:', noMessage); - // eslint-disable-next-line no-continue - continue; - } - // eslint-disable-next-line no-await-in-loop - const msgtype = await worker.handle(message); - if (msgtype === 'finish') { - break; - } - } -} diff --git a/packages/xsnap/package.json b/packages/xsnap/package.json index fa36230967c..2088c60d04d 100644 --- a/packages/xsnap/package.json +++ b/packages/xsnap/package.json @@ -13,7 +13,9 @@ }, "scripts": { "repl": "node -r esm src/xsrepl.js", - "build": "git submodule update --init && node -r esm src/build.js", + "build:bundle": "rollup --config rollup.config.js", + "build:bin": "git submodule update --init && node -r esm src/build.js", + "build": "yarn build:bin && yarn build:bundle", "clean": "rm -rf build", "lint": "yarn lint:js && yarn lint:types", "lint:js": "eslint 'src/**/*.js'", @@ -24,6 +26,8 @@ "postinstall": "yarn build" }, "dependencies": { + "@agoric/eventual-send": "^0.13.0", + "ses": "^0.11.0", "esm": "^3.2.5" }, "devDependencies": { diff --git a/packages/xs-vat-worker/rollup.config.js b/packages/xsnap/rollup.config.js similarity index 100% rename from packages/xs-vat-worker/rollup.config.js rename to packages/xsnap/rollup.config.js diff --git a/packages/xs-vat-worker/src/bootstrap.js b/packages/xsnap/src/bootstrap.js similarity index 100% rename from packages/xs-vat-worker/src/bootstrap.js rename to packages/xsnap/src/bootstrap.js diff --git a/packages/xs-vat-worker/src/console-shim.js b/packages/xsnap/src/console-shim.js similarity index 100% rename from packages/xs-vat-worker/src/console-shim.js rename to packages/xsnap/src/console-shim.js diff --git a/packages/xs-vat-worker/src/lockdown-shim.js b/packages/xsnap/src/lockdown-shim.js similarity index 72% rename from packages/xs-vat-worker/src/lockdown-shim.js rename to packages/xsnap/src/lockdown-shim.js index a67d383cbeb..25d481feac8 100644 --- a/packages/xs-vat-worker/src/lockdown-shim.js +++ b/packages/xsnap/src/lockdown-shim.js @@ -1,3 +1,4 @@ +// @ts-ignore import 'ses/lockdown'; lockdown(); diff --git a/packages/xs-vat-worker/src/text-shim.js b/packages/xsnap/src/text-shim.js similarity index 100% rename from packages/xs-vat-worker/src/text-shim.js rename to packages/xsnap/src/text-shim.js diff --git a/packages/xs-vat-worker/test/escapeCompartment.js b/packages/xsnap/test/escapeCompartment.js similarity index 100% rename from packages/xs-vat-worker/test/escapeCompartment.js rename to packages/xsnap/test/escapeCompartment.js diff --git a/packages/xs-vat-worker/test/test-boot-lockdown.js b/packages/xsnap/test/test-boot-lockdown.js similarity index 97% rename from packages/xs-vat-worker/test/test-boot-lockdown.js rename to packages/xsnap/test/test-boot-lockdown.js index 9e9b1ac5393..d649487a7b2 100644 --- a/packages/xs-vat-worker/test/test-boot-lockdown.js +++ b/packages/xsnap/test/test-boot-lockdown.js @@ -3,7 +3,7 @@ import * as childProcess from 'child_process'; import * as os from 'os'; import * as fs from 'fs'; import * as path from 'path'; -import { xsnap } from '@agoric/xsnap'; +import { xsnap } from '../src/xsnap'; const importModuleUrl = `file://${__filename}`;