Skip to content

Commit

Permalink
feat(SwingSet): direct liveslots errors to a different console
Browse files Browse the repository at this point in the history
This allows the SwingSet application to use the console tag
in order to redirect errors in liveslots.  `SwingSet:ls:vXX` and
`SwingSet:vat:vXX` are now in use.
  • Loading branch information
michaelfig committed Mar 16, 2021
1 parent c93bb04 commit 9eec3e3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
10 changes: 8 additions & 2 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@ export default function buildKernel(
}
harden(testLog);

function makeVatConsole(vatID) {
const origConsole = makeConsole(`${debugPrefix}SwingSet:${vatID}`);
function makeVatConsole(kind, vatID) {
const origConsole = makeConsole(`${debugPrefix}SwingSet:${kind}:${vatID}`);
if (kind === 'ls') {
// LiveSlots is not recorded to kernelSlog.
// The slog captures 1: what a vat is told to do, and
// 2: what a vat says about its activities
return origConsole;
}
return kernelSlog.vatConsole(vatID, origConsole);
}

Expand Down
27 changes: 25 additions & 2 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DEFAULT_VIRTUAL_OBJECT_CACHE_SIZE = 3; // XXX ridiculously small value to
* @param {number} cacheSize Maximum number of entries in the virtual object state cache
* @param {*} vatPowers
* @param {*} vatParameters
* @param {Console} console
* @returns {*} { vatGlobals, dispatch, setBuildRootObject }
*
* setBuildRootObject should be called, once, with a function that will
Expand All @@ -36,7 +37,14 @@ const DEFAULT_VIRTUAL_OBJECT_CACHE_SIZE = 3; // XXX ridiculously small value to
*
* buildRootObject(vatPowers, vatParameters)
*/
function build(syscall, forVatID, cacheSize, vatPowers, vatParameters) {
function build(
syscall,
forVatID,
cacheSize,
vatPowers,
vatParameters,
console,
) {
const enableLSDebug = false;
function lsdebug(...args) {
if (enableLSDebug) {
Expand Down Expand Up @@ -214,6 +222,12 @@ function build(syscall, forVatID, cacheSize, vatPowers, vatParameters) {
// eslint-disable-next-line no-use-before-define
const m = makeMarshal(convertValToSlot, convertSlotToVal, {
marshalName: `liveSlots:${forVatID}`,
marshalSaveError: err =>
// By sending this to `console.log`, under cosmic-swingset this is
// controlled by the `console` option given to makeLiveSlots. For Agoric,
// this output is enabled by `agoric start -v` and not enabled without the
// `-v` flag.
console.log('Logging sent error stack', err),
});

const {
Expand Down Expand Up @@ -635,6 +649,7 @@ function build(syscall, forVatID, cacheSize, vatPowers, vatParameters) {
* @param {*} vatParameters
* @param {number} cacheSize Upper bound on virtual object cache size
* @param {*} _gcTools
* @param {Console} [liveSlotsConsole]
* @returns {*} { vatGlobals, dispatch, setBuildRootObject }
*
* setBuildRootObject should be called, once, with a function that will
Expand Down Expand Up @@ -666,12 +681,20 @@ export function makeLiveSlots(
vatParameters = harden({}),
cacheSize = DEFAULT_VIRTUAL_OBJECT_CACHE_SIZE,
_gcTools,
liveSlotsConsole = console,
) {
const allVatPowers = {
...vatPowers,
makeMarshal,
};
const r = build(syscall, forVatID, cacheSize, allVatPowers, vatParameters);
const r = build(
syscall,
forVatID,
cacheSize,
allVatPowers,
vatParameters,
liveSlotsConsole,
);
const { vatGlobals, dispatch, setBuildRootObject } = r; // omit 'm'
return harden({ vatGlobals, dispatch, setBuildRootObject });
}
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/src/kernel/loadVat.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ export function makeVatLoader(stuff) {
enablePipelining,
enableInternalMetering: !isDynamic,
notifyTermination,
vatConsole: makeVatConsole(vatID),
vatConsole: makeVatConsole('vat', vatID),
liveSlotsConsole: makeVatConsole('ls', vatID),
vatParameters,
virtualObjectCacheSize,
};
Expand Down
1 change: 1 addition & 0 deletions packages/SwingSet/src/kernel/vatManager/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function makeVatManagerFactory({
'metered',
'enableSetup',
'enableInternalMetering',
'liveSlotsConsole',
'notifyTermination',
'virtualObjectCacheSize',
'vatParameters',
Expand Down
2 changes: 2 additions & 0 deletions packages/SwingSet/src/kernel/vatManager/manager-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function makeLocalVatManagerFactory(tools) {
enableInternalMetering = false,
vatParameters = {},
vatConsole,
liveSlotsConsole,
virtualObjectCacheSize,
} = managerOptions;
assert(vatConsole, 'vats need managerOptions.vatConsole');
Expand All @@ -110,6 +111,7 @@ export function makeLocalVatManagerFactory(tools) {
vatParameters,
virtualObjectCacheSize,
gcTools,
liveSlotsConsole,
);

let meterRecord = null;
Expand Down

0 comments on commit 9eec3e3

Please sign in to comment.