Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify vat-worker filenames #2202

Closed
warner opened this issue Jan 15, 2021 · 2 comments · Fixed by #2225
Closed

unify vat-worker filenames #2202

warner opened this issue Jan 15, 2021 · 2 comments · Fixed by #2225
Assignees
Labels
SwingSet package: SwingSet

Comments

@warner
Copy link
Member

warner commented Jan 15, 2021

The packages/SwingSet/src/kernel/vatManager/ directory currently contains the following files:

deliver.js
factory.js
localVatManager.js
nodeWorker.js
nodeWorkerSupervisor.js
nodeWorkerSupervisorCJS.js
subprocessSupervisor.js
syscall.js
transcript.js
worker-subprocess-node.js

and they could do with a renaming/cleanup pass. @dckc is likely to be working here in the next week, which might be a good time to do the cleanup.

factory.js is the entry point: it exposes a function (to the kernel) to create a new vat-manager of a particular type, with some set of options. Vat-managers of all types present a common API to the kernel for delivering messages to the vats they manage.

transcript.js, deliver.js, and syscall.js are libraries used by multiple manager types.

We currently have three types of vat-managers (and XS will be a fourth):

  • The oldest is the "local" type, which runs the vat in the same process (and thread) as the kernel: it is the default.
  • The "Node.js Worker" type runs the vat in the same process as the kernel, but in its own thread. In the Node.js world, Worker is the facility by which new threads are created, similar to how web browsers provide ServiceWorker and WebWorker. The kernel thread uses postMessage to send deliveries to the worker thread.
  • The "Node.js Subprocess" type runs the vat in a child subprocess, communicating with it via Netstring-wrapped JSON-encoded messages sent over pipes. The child subprocess runs Node.js
  • The (old) "XS Subprocess" type was just like a Node.js Subprocess, except that the child ran an XS binary instead of the Node.js binary. Our new XS type does the same, but uses a different control protocol, and uses the xsnap library to spawn and communicate with the child.

Each type of vat-manager is defined in a separate file: localVatManager.js, nodeWorker.js, and worker-subprocess-node.js.

The manager types which run the worker in a child process or thread all need some code for the child to first execute, known as a "supervisor". The Node.js Subprocess type puts this in subprocessSupervisor.js. The Node.js Worker type puts it in nodeWorkerSupervisor.js, and requires an additional file named nodeWorkerSupervisorCJS.js because you cannot start a worker from an ES6 Module -format file (so nodeWorkerSupervisorCJS.js is CJS-format and loads first, and it then can import the module-format code from nodeWorkerSupervisor.js).

The new XS-via-xsnap will require several pieces of code to be eval()ed in the child process. The first will set up the SES environment (portions of the SES-shim, and code to invoke lockdown()). The second will establish the supervisor, and install a command handler that accepts requests to create new Compartments and load vat code into them. Both must be delivered as single strings (actually byte arrays). These will be created by calling rollup() on files that live in the vatManager/ directory, and sending the resulting single string in an xsnap evaluate command.

So our current files are:

type manager/parent worker/child extra worker/child
local localVatManager.js N/A N/A
Node.js Worker nodeWorker.js nodeWorkerSupervisor.js nodeWorkerSupervisorCJS.js
Node.js Subprocess worker-subprocess-node.js subprocessSupervisor.js N/A

I think the new filenames should be:

type manager/parent worker/child extra worker/child
local manager-local.js N/A N/A
Node.js Worker manager-nodeworker.js supervisor-nodeworker.js supervisor-nodeworker-cjs.js
Node.js Subprocess manager-subprocess-node.js supervisor-subprocess-node.js N/A
xsnap subprocess manager-subprocess-xsnap.js supervisor-subprocess-xsnap.js lockdown-subprocess-xsnap.js

Also note that rollup takes a non-trivial amount of time, and is especially noticeable when running unit tests that create dozens of vats or kernel instances in a single program. We can improve this by building the two supervisor bundles ahead of time, and stashing them in memory until needed. Look at buildKernelBundles in src/initializeSwingset.js and examples of its use in e.g. test/test-promises.js and follow the pattern there.

@warner warner added the SwingSet package: SwingSet label Jan 15, 2021
dckc added a commit that referenced this issue Jan 15, 2021
dckc added a commit that referenced this issue Jan 16, 2021
dckc added a commit that referenced this issue Jan 16, 2021
@dckc
Copy link
Member

dckc commented Jan 16, 2021

re lockdown-subprocess-xsnap.js... that sounds a lot like xs-vat-worker/src/bootstrap.js.

Is the xs-vat-worker package supposed to go away?

dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 21, 2021
dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 21, 2021
dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 21, 2021
dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 23, 2021
dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 23, 2021
dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 23, 2021
@warner
Copy link
Member Author

warner commented Jan 23, 2021

Yeah, packages/xs-vat-worker can go away. I originally thought it would export a library that was imported by a very short packages/SwingSet/src/kernel/vatManager/manager-subprocess-xsnap.js. But (as we discussed elsewhere) I think you're right, that we've sucked all the juice out of packages/xs-vat-worker and it can now be discarded.

dckc added a commit to dckc/agoric-sdk that referenced this issue Jan 24, 2021
dckc added a commit that referenced this issue Jan 24, 2021
* feat(xsnap): setImmediate and print

In addition to detecting XS Machine quiescense so we can safely take
snapshots, the supervisor has to detect vat queiscense so it can tell
when a delivery is done.

I have resorted to ad-hoc `fprintf()` at the C level for debugging
enough to justify restoring print. Here we test that it's only
available in the start compartment.

note print() includes fflush()

* build(xsnap): don't set mxDebug in release builds

fixes #2216

only tested on lin, not mac nor win

* build(xsnap): build GOAL=debug too

* fix(xsnap): don't swallow error message

* feat(xsnap): return data from xsnap.evaluate()

Using the .result property of a mutable object rather than
the resolution of a promise is a little awkward, but it seems to work.

* chore(xs-vat-worker): prune obsolete dependencies

* build(xs-vat-worker): moddable submodule is obsolete

* style(xs-vat-worker): use canonical @Agoric style

* feat(xs-vat-worker): TextDecoder, HandledPromise before lockdown

* refactor(SwingSet): unify vat-worker filenames

fixes #2202

* feat(swingset): xsnap vat manager

 - build xsnap bootstrap bundles
 - bytes to tagged array and back
 - setBundle,  importBundle
 - syscall
 - delivery success symbol is ok, not deliverDone
 - Use Tagged type consistently;
   don't constrain tag to be string.
 - clean up logging: use parentLog(), trace(), ...
 - static typing for doProcess: capture dispatch while
   it's known to be not null
 - silence parentLog, workerLog for xsnap
 - no, handleSyscall doesn't return Tagged
 - inherit stdout, stderr in xsnap
 - vatid arg on doNotify is no more

* fix: crank 1 comment in vat-target.js

* fix: supply groupCollapsed etc. in console-shim for SES

* fix(xsnap): handle edge cases in sending replies to e, ?

* refactor: avoid 2nd round trip to xsnap

  - manager: prune commandResult
  - supervisor: factor out "transport" logic as `ManagerPort`,
    separate from vat-worker `makeWorker()`
    - ManagerPort.handler provides `{ result?: ArrayBuffer }` idiom
      based on Promise<Tagged>
    - testLog uses ManagerPort.send
  - clean up redundant 'ok' tag in doMessage, doNotify
  - refactor: tagged -> item for consistency

* feat(xsnap worker): pass console log messages to manager

 - prune 'starting xsnap' log msg (per code review)
 - handle rejection in ManagerPort.handler

* fix(xsnap): build args

* refactor(xsnap): fold in what's left of xs-vat-worker

  - prune obsolete locate.js

* chore(xsnap): move lockdown-shim out of src/ to avoid tsc errors

move lockdown-shim.js and the rest of the SES bootstrap files from
src/ to lib/ to avoid many tsc errors of the form...

```
Error: ../../node_modules/ses/src/error/assert.js(24,20): error TS2304: Cannot find name 'StringablePayload'.
```

* docs(xsnap): document XS handleCommand async idiom

* refactor: build XS bundles with Kernel bundles

* fix(xsnap worker): update syscall API to use .resolve()

* chore(xsnap): provide non-trivial console in start compartment

add TODO re other console methods with pointer to
#2146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwingSet package: SwingSet
Projects
None yet
2 participants