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

Thread stack traces to console, add entangled assert #1884

Merged
merged 4 commits into from
Nov 4, 2020
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
1 change: 1 addition & 0 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function makeSwingsetController(
filePrefix: 'kernel',
endowments: {
console: makeConsole(`${debugPrefix}SwingSet:kernel`),
assert,
require: kernelRequire,
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ export default function buildKernel(
// eslint-disable-next-line no-await-in-loop
const NS = await importBundle(source.bundle, {
filePrefix: `dev-${name}`,
endowments: harden({ ...vatEndowments, console: devConsole }),
endowments: harden({ ...vatEndowments, console: devConsole, assert }),
});
assert(
typeof NS.buildRootDeviceNode === 'function',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export function makeLocalVatManagerFactory(tools) {
...vatEndowments,
...ls.vatGlobals,
console: vatConsole,
assert,
});
const inescapableTransforms = [];
const inescapableGlobalLexicals = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ parentPort.on('message', ([type, ...margs]) => {
const endowments = {
...ls.vatGlobals,
console: makeConsole(`SwingSet:vatWorker`),
assert,
};

importBundle(bundle, { endowments }).then(vatNS => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fromParent.on('data', ([type, ...margs]) => {
const endowments = {
...ls.vatGlobals,
console: makeConsole(`SwingSet:vatWorker`),
assert,
};

importBundle(bundle, { endowments }).then(vatNS => {
Expand Down
41 changes: 15 additions & 26 deletions packages/SwingSet/src/kernel/virtualObjectManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, details, q } from '@agoric/assert';
import { assert, details as d, quote as q } from '@agoric/assert';
import { parseVatSlot } from '../parseVatSlots';

const initializationInProgress = Symbol('initializing');
Expand Down Expand Up @@ -106,17 +106,16 @@ export function makeCache(size, fetch, store) {
/**
* Create a new virtual object manager. There is one of these for each vat.
*
* @param {*} syscall Vat's syscall object, used to access the `vatstoreGet` and
* `vatstoreSet` operations.
* @param {*} syscall Vat's syscall object, used to access the `vatstoreGet`
* and `vatstoreSet` operations.
* @param {() => number} allocateExportID Function to allocate the next object
* export ID for the enclosing vat.
* @param valToSlotTable {*} The vat's table that maps object identities to their
* corresponding export IDs
* @param m {*} The vat's marshaler.
* @param cacheSize {number} How many virtual objects this manager should cache
* export ID for the enclosing vat.
* @param {*} valToSlotTable The vat's table that maps object identities to
* their corresponding export IDs
* @param {*} m The vat's marshaler.
* @param {number} cacheSize How many virtual objects this manager should cache
* in memory.
*
* @returns a new virtual object manager.
* @returns {*} a new virtual object manager.
Comment on lines +109 to +118
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FUDCo I adjusted this to appease the linter. It appears to have become more picky.

*
* The virtual object manager allows the creation of persistent objects that do
* not need to occupy memory when they are not in use. It provides four
Expand Down Expand Up @@ -155,7 +154,6 @@ export function makeVirtualObjectManager(
*
* @param {string} vobjID The virtual object ID of the object whose state is
* being fetched.
*
* @returns {*} an object representing the object's stored state.
*/
function fetch(vobjID) {
Expand Down Expand Up @@ -229,14 +227,11 @@ export function makeVirtualObjectManager(
nextWeakStoreID += 1;

function assertKeyDoesNotExist(key) {
assert(
!backingMap.has(key),
details`${q(keyName)} already registered: ${key}`,
);
assert(!backingMap.has(key), d`${q(keyName)} already registered: ${key}`);
}

function assertKeyExists(key) {
assert(backingMap.has(key), details`${q(keyName)} not found: ${key}`);
assert(backingMap.has(key), d`${q(keyName)} not found: ${key}`);
}

function virtualObjectKey(key) {
Expand Down Expand Up @@ -267,7 +262,7 @@ export function makeVirtualObjectManager(
if (vkey) {
assert(
!syscall.vatstoreGet(vkey),
details`${q(keyName)} already registered: ${key}`,
d`${q(keyName)} already registered: ${key}`,
);
syscall.vatstoreSet(vkey, JSON.stringify(m.serialize(value)));
} else {
Expand All @@ -279,7 +274,7 @@ export function makeVirtualObjectManager(
const vkey = virtualObjectKey(key);
if (vkey) {
const rawValue = syscall.vatstoreGet(vkey);
assert(rawValue, details`${q(keyName)} not found: ${key}`);
assert(rawValue, d`${q(keyName)} not found: ${key}`);
return m.unserialize(JSON.parse(rawValue));
} else {
assertKeyExists(key);
Expand All @@ -289,10 +284,7 @@ export function makeVirtualObjectManager(
set(key, value) {
const vkey = virtualObjectKey(key);
if (vkey) {
assert(
syscall.vatstoreGet(vkey),
details`${q(keyName)} not found: ${key}`,
);
assert(syscall.vatstoreGet(vkey), d`${q(keyName)} not found: ${key}`);
syscall.vatstoreSet(vkey, JSON.stringify(m.serialize(harden(value))));
} else {
assertKeyExists(key);
Expand All @@ -302,10 +294,7 @@ export function makeVirtualObjectManager(
delete(key) {
const vkey = virtualObjectKey(key);
if (vkey) {
assert(
syscall.vatstoreGet(vkey),
details`${q(keyName)} not found: ${key}`,
);
assert(syscall.vatstoreGet(vkey), d`${q(keyName)} not found: ${key}`);
syscall.vatstoreSet(vkey, undefined);
} else {
assertKeyExists(key);
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/metering/metered-dynamic-vat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { makePromiseKit } from '@agoric/promise-kit';
import { meterMe } from './metered-code';
Expand All @@ -23,7 +24,7 @@ export function buildRootObject(_dynamicVatPowers) {
async load(bundle) {
const require = harden(() => 0);
grandchildNS = await importBundle(bundle, {
endowments: { console, require },
endowments: { console, assert, require },
});
},

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/metering/test-metering.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function meteredImportBundle(bundle, endowments) {
test('metering a single bundle', async function testSingleBundle(t) {
const bundle = await bundleSource(require.resolve('./metered-code.js'));
harden(Object.getPrototypeOf(console));
const endowments = { console };
const endowments = { console, assert };
const {
ns,
runBundleThunkUnderMeter,
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/metering/vat-within.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';

export function buildRootObject(vatPowers) {
Expand All @@ -24,7 +25,7 @@ export function buildRootObject(vatPowers) {
async start(bundle) {
// console.log(`vatPowers`, vatPowers);
// console.log('bundle', bundle);
const endowments = { console, getMeter };
const endowments = { console, assert, getMeter };
// console.log('doing importBundle');
log('importing');
const ns = await importBundle(bundle, {
Expand Down
3 changes: 3 additions & 0 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,8 @@
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"ses": "^0.11.0"
}
}
Loading