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

Silence validator vats #2658

Merged
merged 4 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ERTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
],
"require": [
"esm"
]
],
"timeout": "2m"
},
"eslintConfig": {
"extends": [
Expand Down
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
8 changes: 4 additions & 4 deletions packages/cosmic-swingset/lib/ag-solo/fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeWithQueue } from './vats/queue';
import { makeBatchedDeliver } from './batched-deliver';
import { getMeterProvider } from '../kernel-stats';

const log = anylogger('fake-chain');
const console = anylogger('fake-chain');

const PRETEND_BLOCK_DELAY = 5;
const scaleBlockTime = ms => Math.floor(ms / 1000);
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
assert(!replay, X`Replay not implemented`);
}

const meterProvider = getMeterProvider(log, process.env);
const meterProvider = getMeterProvider(console, process.env);
const s = await launch(
stateDBdir,
mailboxStorage,
Expand Down Expand Up @@ -133,7 +133,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
thisBlock = [];
blockTime += scaleBlockTime(Date.now() - actualStart);
} catch (e) {
log.error(`error fake processing`, e);
console.error(`error fake processing`, e);
}

clearTimeout(nextBlockTimeout);
Expand All @@ -148,7 +148,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
let totalDeliveries = 0;
async function deliver(newMessages, acknum) {
totalDeliveries += 1;
console.log(`delivering to ${GCI} (trips=${totalDeliveries})`);
console.info(`delivering to ${GCI} (trips=${totalDeliveries})`);

intoChain.push([newMessages, acknum]);
if (!delay) {
Expand Down
22 changes: 16 additions & 6 deletions packages/cosmic-swingset/lib/anylogger-agoric.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import anylogger from 'anylogger';
// Turn on debugging output with DEBUG=agoric

let debugging;
const filterOutPrefixes = [];
if (process.env.DEBUG === undefined) {
// DEBUG not set, default to log level.
debugging = 'log';
} else if (process.env.DEBUG.includes('agoric')) {
// DEBUG set and we're enabled; verbose.
debugging = 'debug';
} else {
// DEBUG set but we're not enabled; quieter than normal.
debugging = 'info';
if (!process.env.DEBUG.includes('SwingSet:vat')) {
filterOutPrefixes.push('SwingSet:vat:');
}
if (!process.env.DEBUG.includes('SwingSet:ls')) {
filterOutPrefixes.push('SwingSet:ls:');
}
if (process.env.DEBUG.includes('agoric')) {
// DEBUG set and we're enabled; verbose.
debugging = 'debug';
} else {
// DEBUG set but we're not enabled; quieter than normal.
debugging = 'info';
}
}
const defaultLevel = anylogger.levels[debugging];

Expand All @@ -22,8 +31,9 @@ anylogger.ext = (l, o) => {
l.enabledFor = lvl => defaultLevel >= anylogger.levels[lvl];

const prefix = l.name.replace(/:/g, ': ');
const filteredOut = filterOutPrefixes.find(pfx => l.name.startsWith(pfx));
for (const [level, code] of Object.entries(anylogger.levels)) {
if (code > defaultLevel) {
if (filteredOut || code > defaultLevel) {
// Disable printing.
l[level] = () => {};
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/cosmic-swingset/lib/chain-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const agcc = require('@agoric/cosmos');
// (dep chain: temp->glob->minimatch->brace-expansion)
esmRequire('@agoric/install-metering-and-ses');

if (!process.env.DEBUG) {
// By default, disable debugging.
process.env.DEBUG = '';
}

const path = require('path');
const os = require('os');

Expand Down
16 changes: 9 additions & 7 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,14 @@ const defaultSlotToValFn = (x, _) => x;
export function makeMarshal(
convertValToSlot = defaultValToSlotFn,
convertSlotToVal = defaultSlotToValFn,
{ marshalName = 'anon-marshal', errorTagging = 'on' } = {},
{
marshalName = 'anon-marshal',
errorTagging = 'on',
// We prefer that the caller instead log to somewhere hidden
// to be revealed when correlating with the received error.
marshalSaveError = err =>
console.log('Temporary logging of sent error', err),
} = {},
) {
assert.typeof(marshalName, 'string');
assert(
Expand Down Expand Up @@ -743,12 +750,7 @@ export function makeMarshal(
if (errorTagging === 'on') {
const errorId = nextErrorId();
assert.note(val, X`Sent as ${errorId}`);
// TODO we need to instead log to somewhere hidden
// to be revealed when correlating with the received error.
// By sending this to `console.log`, under swingset this is
// enabled by `agoric start --reset -v` and not enabled without
// the `-v` flag.
console.log('Temporary logging of sent error', val);
marshalSaveError(val);
return harden({
[QCLASS]: 'error',
errorId,
Expand Down
3 changes: 2 additions & 1 deletion packages/marshal/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
/**
* @typedef MakeMarshalOptions
* @property {string=} marshalName
* @property {('on'|'off')=} errorTagging
* @property {'on'|'off'=} errorTagging
* @property {(err: Error) => void=} marshalSaveError
michaelfig marked this conversation as resolved.
Show resolved Hide resolved
*/

// /////////////////////////////////////////////////////////////////////////////
Expand Down