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

expose enable/disable metering to xsnap start compartment and liveslots #3457

Closed
warner opened this issue Jul 9, 2021 · 2 comments · Fixed by #3480
Closed

expose enable/disable metering to xsnap start compartment and liveslots #3457

warner opened this issue Jul 9, 2021 · 2 comments · Fixed by #3480
Assignees
Labels
enhancement New feature or request SwingSet package: SwingSet xsnap the XS execution tool

Comments

@warner
Copy link
Member

warner commented Jul 9, 2021

What is the Problem Being Solved?

We kind of want validators to be able to perform GC at arbitrary times, partially because of #3428, in which the "organic" GC schedule changes when a heap snapshot is reloaded because the new XS engine does not pre-allocate all the extra space that was left over in the pre-snapshot heap.

To support variance in GC activity while still maintaining stable metering results, we want to exclude the GC-sensitive code paths from metering. So we're looking for a way to build an unmetered "box". We disable metering when we enter the box, and we re-enable it when we exit the box. The number of times we enter the box is part of consensus, but the liveslots activity while we're inside the box is not (specifically the amount of code executed is allowed to vary from one validator to another). Liveslots may invoke syscalls while inside the box, but it will not resolve promises.

It's an open question as to what should happen if a runaway infinite loop occurs while inside the box. It might be appropriate to terminate the xsnap worker process (which would kill the kernel, since #3237 says unexplained worker errors should bail). It might be ok to signal an error that consensus-terminates the vat, but I'm wary, because we don't actually know what happened and whether it might match what's happening on other validators (and of course we can't actually detect infinite loops, we can merely run out of patience at some arbitrary time).

This suggests that, at least for now, meter underflows while inside the box should be ignored.

A different ticket will track the SwingSet/LiveSlots uses of the box.

Description of the Design

The basic approach is going to be a pair of C "callbacks", defined in xsnap.c, and exposed as globals to the start compartment (so supervisor.js can share them with liveslots). The definition of this "enter"/"exit" pair depends upon how XS enables/disables metering,

One option is for the "enter" call to return the current meter value, and replace it with some very large number. The "exit" call would then accept the original value and replace the current value.

Another is for "enter" to disable metering but leave the current meter value alone. "Exit" then just reenables it.

Security Considerations

These globals must only be on the start compartment. SES will strip them (as it does for all unrecognized globals, like gc), so 1: userspace won't see them, and 2: the liveslots compartment won't either, so supervisor.js must deliberately pass them through. We'll need to augment the gcTools record to include something like enterGCBox or similar.

If userspace could reach these functions, it could bypass the metering limits.

Test Plan

xsnap unit tests should perform two runs, both with a box enter/exit pair in the middle. One run should do no work inside the box, the other should do a moderate amount of work inside the box. The test should assert that both runs result in the same compute meter consumption.

Unit tests should also create a Compartment and assert that these functions are not available on the compartment's global.

@warner warner added enhancement New feature or request SwingSet package: SwingSet xsnap the XS execution tool labels Jul 9, 2021
@warner warner added this to the Testnet: Metering Phase milestone Jul 9, 2021
@warner
Copy link
Member Author

warner commented Jul 15, 2021

@dckc I'd like to bump the priority of this one, I can't exercise any #3458 code until it's available.

@dckc
Copy link
Member

dckc commented Jul 15, 2021

roger wilco

dckc added a commit that referenced this issue Jul 15, 2021
API:

```js
    const noLimit = 0;

    const limit = currentMeterLimit();
    const before = resetMeter(noLimit, 0);
    try {
      // unmetered work...
    } finally {
      resetMeter(limit, before);
    }
```

fixes #3457
dckc added a commit that referenced this issue Jul 15, 2021
API:

```js
    const noLimit = 0;

    const limit = currentMeterLimit();
    const before = resetMeter(noLimit, 0);
    try {
      // unmetered work...
    } finally {
      resetMeter(limit, before);
    }
```

fixes #3457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SwingSet package: SwingSet xsnap the XS execution tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants