Skip to content

Commit

Permalink
move ExitCode processing into worker
Browse files Browse the repository at this point in the history
This allows SwingSet to lose the direct dependency upon @agoric/xsnap,
allowing swingset-worker-xsnap-v1 to encapsulate it.
  • Loading branch information
warner committed Mar 1, 2023
1 parent 7628ae1 commit 4063a31
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/misc-tools/measure-metering/measure.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
// run as `node tools/measure-metering/measure.js`

// eslint-disable-next-line import/order
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"devDependencies": {
"@agoric/swingset-xsnap-supervisor": "^0.9.0",
"@agoric/xsnap": "^0.13.2",
"@agoric/xsnap-lockdown": "^0.13.2",
"@types/microtime": "^2.1.0",
"better-sqlite3": "^7.5.0",
Expand All @@ -40,7 +41,6 @@
"@agoric/swingset-worker-xsnap-v1": "^0.9.0",
"@agoric/time": "^0.2.1",
"@agoric/vat-data": "^0.4.3",
"@agoric/xsnap": "^0.13.2",
"@endo/base64": "^0.2.28",
"@endo/bundle-source": "^2.4.2",
"@endo/captp": "^2.0.18",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assert, Fail, q } from '@agoric/assert';
import { ExitCode } from '@agoric/xsnap/api.js';
import { makeManagerKit } from './manager-helper.js';

import {
Expand Down Expand Up @@ -185,21 +184,8 @@ export function makeXsSubprocessFactory({
result = await issueTagged(['deliver', delivery]);
} catch (err) {
parentLog('issueTagged error:', err.code, err.message);
let message;
switch (err.code) {
case ExitCode.E_TOO_MUCH_COMPUTATION:
message = 'Compute meter exceeded';
break;
case ExitCode.E_STACK_OVERFLOW:
message = 'Stack meter exceeded';
break;
case ExitCode.E_NOT_ENOUGH_MEMORY:
message = 'Allocate meter exceeded';
break;
default:
// non-metering failure. crash.
throw err;
}
// get an error message for metering failures, else throw
const message = worker.trapMeteringFailure(err);
return harden(['error', message, null]);
}

Expand Down
18 changes: 17 additions & 1 deletion packages/swingset-worker-xsnap-v1/src/make-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import { Fail } from '@agoric/assert';
import { type as osType } from 'os';
import { xsnap, recordXSnap } from '@agoric/xsnap';
import { ExitCode } from '@agoric/xsnap/api.js';
import { getLockdownBundle } from '@agoric/xsnap-lockdown';
import { getSupervisorBundle } from '@agoric/swingset-xsnap-supervisor';

Expand Down Expand Up @@ -95,7 +96,22 @@ export function makeStartXSnapV1(options) {
// eslint-disable-next-line no-await-in-loop, @jessie.js/no-nested-await
await worker.evaluate(`(${bundle.source}\n)()`.trim());
}
return worker;

const trapMeteringFailure = err => {
switch (err.code) {
case ExitCode.E_TOO_MUCH_COMPUTATION:
return 'Compute meter exceeded';
case ExitCode.E_STACK_OVERFLOW:
return 'Stack meter exceeded';
case ExitCode.E_NOT_ENOUGH_MEMORY:
return 'Allocate meter exceeded';
default:
// non-metering failure. crash.
throw err;
}
};

return harden({ ...worker, trapMeteringFailure });
}
return startXSnapV1;
}

0 comments on commit 4063a31

Please sign in to comment.