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

create new swingset-worker-xsnap-v1 package #7101

Closed
wants to merge 11 commits into from

Conversation

warner
Copy link
Member

@warner warner commented Mar 1, 2023

This moves the main startXSnap functionality out to a new package named @agoric/swingset-worker-xsnap-v1, and replacing the packages/SwingSet code with a stub that switches between available versions via a new workerVersion argument (the only currently accepted version is xsnap-v1).

refs #6596

@warner warner added the SwingSet package: SwingSet label Mar 1, 2023
@warner warner self-assigned this Mar 1, 2023
@warner warner force-pushed the 6596-worker-xsnap-v1 branch from e5251ef to 4063a31 Compare March 2, 2023 08:14
@warner warner force-pushed the 6596-supervisor branch from 7dd5b0c to dd88b57 Compare March 6, 2023 18:20
@warner warner force-pushed the 6596-worker-xsnap-v1 branch from 4063a31 to cdc0401 Compare March 6, 2023 18:20
@datadog-full-agoric
Copy link

datadog-full-agoric bot commented Mar 6, 2023

Datadog Report

Branch report: 6596-worker-xsnap-v1
Commit report: fb0daf6

agoric-sdk: 0 Failed, 0 New Flaky, 3669 Passed, 55 Skipped, 13m 52.98s Wall Time

@warner warner force-pushed the 6596-worker-xsnap-v1 branch from cdc0401 to 511f5d5 Compare March 7, 2023 05:49
@warner warner force-pushed the 6596-supervisor branch from 3bf3842 to 86df0c5 Compare March 7, 2023 05:52
@warner warner force-pushed the 6596-worker-xsnap-v1 branch 2 times, most recently from 470c569 to 48051e5 Compare March 8, 2023 02:00
@warner warner marked this pull request as ready for review March 8, 2023 02:00
@warner warner requested a review from mhofman March 8, 2023 02:01
@warner
Copy link
Member Author

warner commented Mar 8, 2023

This is finally ready for review. Best reviewed one commit at a time: the core function gets refactored and moved around in like half the commits.

@warner warner force-pushed the 6596-supervisor branch from 152913a to 97f0584 Compare March 8, 2023 07:22
@warner warner force-pushed the 6596-worker-xsnap-v1 branch from 48051e5 to 0731fbd Compare March 8, 2023 07:22
warner added 11 commits March 10, 2023 18:03
These types define the messages (deliveries and syscalls) that can
pass between a swingset kernel and one of its workers. By moving them
to swingset-liveslots, they can be imported by the upcoming
"swingset-xsnap-supervisor" package.

Strictly speaking, these are not defined by (or limited to) liveslots:
we can imagine alternate (non-liveslots) vat runtimes which still
speak the same language of deliveries and syscalls. For example we
might define a less object-capability -ish runtime whose userspace
code makes direct vatstore changes, in more of an ORM style, which
lacks internal confinement but might be faster/cheaper. Or we could
use a language other than JavaScript.

In the long run, we probably need to define a separate
"swingset-vat-api-v1" package, which defines the kinds of deliveries
and syscalls that can be exchanged between the kernel and a vat
worker. The kernel-side translators will emit these, the worker
management code will transport them, and they will be consumed by
liveslots/etc within the worker.

If we add a new kind of delivery in the future, we could define
"swingset-vat-api-v2" with the additions, the kernel could use both
-v1 and -v2, and the translator would refrain from sending the extra
-v2 messages to an older worker.
This extracts the XS supervisor bundle out of packages/SwingSet and
into a new package whose NPM name is
`@agoric/swingset-xsnap-supervisor`, and lives (for now) in
packages/swingset-xsnap-supervisor .

The bundle is created explicitly, by running `yarn build`. As with
`xsnap-lockdown`, the intention is that each published version has a
stable bundle, with specific (hashable) contents. Importing clients
can rely upon this stability to e.g. have deterministic xsnap heap
snapshot contents even if the versions of other parts of the system
have changed.

The new README.md describes the API, the stability goals, and how we
achieve them.

Fairly soon, we'll need manage the version number of this package more
explicitly, either by moving it to a different git repository, or
changing our use of `lerna publish` to avoid spurious changes. But for
now we can leave it in place.

refs #6596
Our replay-transcript.js tool has some affordances for forcing a
rebuild of the lockdown and supervisor bundles. Now that the bundles
are coming from separate packages, the affordances have changed. I'm
not sure if the new code is as useful as the original.
Running tsc in the new swingset-xsnap-supervisor package caused this
unrelated line in packages/store to start complaining. Removing the
ts-expect-error caused it to fail tsc when run in
packages/store. Thanks to @mfig for a fix that appeased both cases.
Minor refactoring of `makeStartXSnap` to inline as much as possible
This moves the "which bundles should we use?" responsibility into
startXSnap, described by a new 'workerVersion' argument. The only
version supported for now is 'xsnap-v1'.

The bundles themselves are loaded from their source
packages ('@agoric/xsnap-lockdown' and
'@agoric/swingset-xsnap-supervisor'), rather than being pulled from
the kvStore. We rely upon those packages supplying stable bundles
despite kernel-package changes.

Unit tests and replay tools can use `options.overrideBundles=[..]` to
replace the usual bundles with alternates: either no bundles, or
custom lockdown/supervisor bundles.
This moves the xsnap-worker-creation code out of SwingSet and into a
new package, whose NPM name is `@agoric/swingset-worker-xsnap-v1`, and
lives (for now) in packages/swingset-worker-xsnap-v1 .

This new package encapsulates:
* the choice of `xsnap` executable, hence the XS engine version inside
* the choice of `@agoric/xsnap-lockdown`, hence the Endo/SES version
* the choice of `@agoric/swingset-xsnap-supervisor`, hence liveslots

We roughly expect there will be exactly one version of
`@agoric/swingset-worker-xsnap-v1` published. Any major changes to
XS/xsnap/SES/liveslots will be published to a new
`@agoric/swingset-worker-xsnap-v2` package, and a single kernel can
depend upon both -v1 and -v2 at the same time, to support older
vats (started with -v1) as well as newer vats (started with, or
upgraded to, -v2).

Minor (and sufficiently backwards-compatible) changes of the
components may be possible. If so, we can publish new versions of -v1,
and deployed systems can perform orchestrated (within-consensus)
upgrades from e.g. -v1@1.0 to -v1@1.1 . We still need to think
carefully about potential differences in behavior between the
first-run deliveries (using 1.0) and the post-upgrade replayed
deliveries (using 1.1).

SwingSet now has a primary dependency on the new
`@agoric/swingset-worker-xsnap-v1` package, and only `devDependencies`
on the individual components (`@agoric/swingset-xsnap-supervisor` and
`@agoric/xsnap-lockdown`). Hopefully these dev-dependencies will go
away once the dust settles.

refs #6596
Previously, the SwingSet-side `manager-subprocess-xsnap.js` asked the
`xsnap` package for the integers corresponding to the three
meter-based error exits: E_TOO_MUCH_COMPUTATION, E_STACK_OVERFLOW, and
E_NOT_ENOUGH_MEMORY. It needs these to distinguish an in-consensus vat
termination from a random I-don't-know-why-so-panic-the-kernel worker
exit.

However, that required SwingSet to have a direct dependency on
`@agoric/xsnap`, whereas we really want the xsnap version to be
entirely encapsulated by the new swingset-worker-xsnap-v1
package. Imagine how this would work when we introduce a -v2 package,
which e.g. uses a new xsnap that has changed the exit code values.

This commit adds a new `trapMeteringFailure()` method to the workers
created by `swingset-worker-xsnap-v1`. This method inspects the error
object (including the exit code), and either converts it into a
termination-reason string (for the three recognized meter-based
exits), or throws an error (for anything else). The manager can call
this worker method instead of needing to know the exact exit codes,
delegating knowledge of the details to the specific worker version.

This allows SwingSet to lose the direct dependency upon @agoric/xsnap,
relegating it to `devDependencies`.
@warner warner force-pushed the 6596-worker-xsnap-v1 branch from 0731fbd to 2a7780a Compare March 11, 2023 02:04
@warner warner force-pushed the 6596-supervisor branch 2 times, most recently from 9fbfb20 to 8139f14 Compare March 21, 2023 06:36
@warner
Copy link
Member Author

warner commented Mar 21, 2023

In our meeting today, our new approach for #6596 does not use a separate worker package, so I'm abandoning this PR in favor of the plan described in #6596 (comment)

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
Development

Successfully merging this pull request may close these issues.

1 participant