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

fix(swing-store): replace getAllState/etc with a debug facet #6796

Merged
merged 2 commits into from
Jan 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@ import { test } from '../../tools/prepare-test-env-ava.js';

// eslint-disable-next-line import/order
import { assert } from '@agoric/assert';
import { initSwingStore, getAllState } from '@agoric/swing-store';
import { initSwingStore } from '@agoric/swing-store';
import { initializeSwingset, makeSwingsetController } from '../../src/index.js';
import { kunser } from '../../src/lib/kmarshal.js';

function bfile(name) {
return new URL(name, import.meta.url).pathname;
}

// eslint-disable-next-line no-unused-vars
function dumpState(kernelStorage, vatID) {
const s = getAllState(kernelStorage).kvStuff;
const keys = Array.from(Object.keys(s)).sort();
for (const k of keys) {
if (k.startsWith(`${vatID}.vs.`)) {
console.log(k, s[k]);
}
}
}

async function testChangeParameters(t) {
const config = {
bootstrap: 'bootstrap',
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/test/devices/test-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { test } from '../../tools/prepare-test-env-ava.js';

import bundleSource from '@endo/bundle-source';
import { initSwingStore, getAllState } from '@agoric/swing-store';
import { initSwingStore } from '@agoric/swing-store';
import { parse } from '@endo/marshal';

import {
Expand Down Expand Up @@ -211,7 +211,7 @@ test.serial('d2.5', async t => {
});

test.serial('device state', async t => {
const kernelStorage = initSwingStore().kernelStorage;
const { kernelStorage, debug } = initSwingStore();
const config = {
bootstrap: 'bootstrap',
vats: {
Expand All @@ -236,7 +236,7 @@ test.serial('device state', async t => {
const d3 = c1.deviceNameToID('d3');
await c1.run();
t.deepEqual(c1.dump().log, ['undefined', 'w+r', 'called', 'got {"s":"new"}']);
const s = getAllState(kernelStorage).kvStuff;
const s = debug.dump().kvEntries;
t.deepEqual(JSON.parse(s[`${d3}.deviceState`]), kser({ s: 'new' }));
t.deepEqual(JSON.parse(s[`${d3}.o.nextID`]), 10);
});
Expand Down
13 changes: 1 addition & 12 deletions packages/SwingSet/test/promise-watcher/test-promise-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@ import { test } from '../../tools/prepare-test-env-ava.js';
// eslint-disable-next-line import/order
import { assert } from '@agoric/assert';
// eslint-disable-next-line import/order
import { initSwingStore, getAllState } from '@agoric/swing-store';
import { initSwingStore } from '@agoric/swing-store';
import { initializeSwingset, makeSwingsetController } from '../../src/index.js';

function bfile(name) {
return new URL(name, import.meta.url).pathname;
}

// eslint-disable-next-line no-unused-vars
function dumpState(kernelStorage, vatID) {
const s = getAllState(kernelStorage).kvStuff;
const keys = Array.from(Object.keys(s)).sort();
for (const k of keys) {
if (k.startsWith(`${vatID}.vs.`)) {
console.log(k, s[k]);
}
}
}

async function testPromiseWatcher(t) {
const config = {
includeDevDependencies: true, // for vat-data
Expand Down
34 changes: 17 additions & 17 deletions packages/SwingSet/test/test-activityhash-vs-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { test } from '../tools/prepare-test-env-ava.js';

// eslint-disable-next-line import/order
import { initSwingStore, getAllState, setAllState } from '@agoric/swing-store';
import { initSwingStore } from '@agoric/swing-store';
import { initializeSwingset, makeSwingsetController } from '../src/index.js';
import { buildTimer } from '../src/devices/timer/timer.js';

Expand All @@ -11,14 +11,16 @@ const TimerSrc = new URL(
import.meta.url,
).pathname;

// all tests that are sensitive to GC timing (which means anything that
// exercises transcript replay or looks at activityHash) need to use
// test.serial or config.defaultManagerType='xsnap', until we figure out why
// gcAndFinalize sometimes doesn't work (details in #3240 and #4617)
// all tests that are sensitive to GC timing (which means anything
// that exercises transcript replay or looks at activityHash) need to
// use test.serial or config.defaultManagerType='xs-worker', until we
// figure out why gcAndFinalize sometimes doesn't work (details in
// #3240 and #4617). And even test.serial doesn't seem to be enough.

test.serial('restarting kernel does not change activityhash', async t => {
test('restarting kernel does not change activityhash', async t => {
const sourceSpec = new URL('vat-empty-setup.js', import.meta.url).pathname;
const config = {
defaultManagerType: 'xs-worker',
bootstrap: 'bootstrap',
vats: {
bootstrap: {
Expand All @@ -38,7 +40,7 @@ test.serial('restarting kernel does not change activityhash', async t => {
const deviceEndowments1 = {
timer: { ...timer1.endowments },
};
const ks1 = initSwingStore().kernelStorage;
const { kernelStorage: ks1, debug: debug1 } = initSwingStore();
// console.log(`--c1 build`);
await initializeSwingset(config, [], ks1);
const c1 = await makeSwingsetController(ks1, deviceEndowments1);
Expand All @@ -48,8 +50,8 @@ test.serial('restarting kernel does not change activityhash', async t => {
// console.log(`--c1 run1`);
await c1.run();

// console.log(`--c1 getAllState`);
const state = getAllState(ks1);
// console.log(`--c1 serialize`);
const serialized = debug1.serialize();
// console.log(`ah: ${c1.getActivityhash()}`);

// console.log(`--c1 poll1`);
Expand All @@ -70,8 +72,7 @@ test.serial('restarting kernel does not change activityhash', async t => {
const deviceEndowments2 = {
timer: { ...timer2.endowments },
};
const ks2 = initSwingStore().kernelStorage;
setAllState(ks2, state);
const { kernelStorage: ks2 } = initSwingStore(null, { serialized });
// console.log(`--c2 build`);
const c2 = await makeSwingsetController(ks2, deviceEndowments2);
// console.log(`ah: ${c2.getActivityhash()}`);
Expand All @@ -92,24 +93,24 @@ test.serial('restarting kernel does not change activityhash', async t => {
t.is(c1ah, c2ah);
});

test.serial('comms initialize is deterministic', async t => {
test('comms initialize is deterministic', async t => {
// bug #3726: comms was calling vatstoreGet('initialize') and
// vatstoreSet('meta.o+0') during the first message after process restart,
// which makes it a nondeterministic function of the input events.

const sourceSpec = new URL('vat-activityhash-comms.js', import.meta.url)
.pathname;
const config = {};
const config = { defaultManagerType: 'xs-worker' };
config.bootstrap = 'bootstrap';
config.vats = { bootstrap: { sourceSpec } };
const ks1 = initSwingStore().kernelStorage;
const { kernelStorage: ks1, debug: debug1 } = initSwingStore();
await initializeSwingset(config, [], ks1);
const c1 = await makeSwingsetController(ks1, {});
c1.pinVatRoot('bootstrap');
// the bootstrap message will cause comms to initialize itself
await c1.run();

const state = getAllState(ks1);
const serialized = debug1.serialize();

// but the second message should not
c1.queueToVatRoot('bootstrap', 'addRemote', ['remote2']);
Expand All @@ -118,8 +119,7 @@ test.serial('comms initialize is deterministic', async t => {
await c1.shutdown();

// a kernel restart is loading a new kernel from the same state
const ks2 = initSwingStore().kernelStorage;
setAllState(ks2, state);
const { kernelStorage: ks2 } = initSwingStore(null, { serialized });
const c2 = await makeSwingsetController(ks2, {});

// the "am I already initialized?" check must be identical to the
Expand Down
Loading