Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Apr 21, 2023
1 parent 91e0527 commit 4659426
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop,@jessie.js/no-nested-await */
import { assert, Fail, quote as q } from '@agoric/assert';
import { isNat } from '@endo/nat';
import { makeVatTranslators } from './vatTranslator.js';
Expand Down Expand Up @@ -37,8 +36,8 @@ function recordSyscalls(origHandler) {
syscalls.push({ s: vso, r: vres });
return vres;
};
const getSyscalls = () => syscalls;
return { syscallHandler, getSyscalls };
const getTranscriptSyscalls = () => syscalls;
return { syscallHandler, getTranscriptSyscalls };
}

/**
Expand All @@ -62,8 +61,12 @@ export function makeSyscallSimulator(
deliveryNum,
transcriptEntry,
) {
const syscallsExpected = Array.from(transcriptEntry.sc); // copy
const syscallsExpected = [...transcriptEntry.sc]; // copy
const syscallsMade = [];
// syscallStatus's length will be max(syscallsExpected,
// syscallsMade). We push a new status onto it each time the
// replaying vat makes a syscall, then when the delivery ends,
// finishSimulation will pad it out with 'missing' entries.
const syscallStatus = []; // array of 'ok'/'wrong'/'extra'/'missing'
let replayError; // sticky

Expand Down Expand Up @@ -256,18 +259,16 @@ export function makeVatWarehouse({
kernelSlog.write({ type: 'start-replay', vatID, deliveries: total });
// TODO glean deliveryNum better, make sure we get the post-snapshot
// transcript starting point right. getTranscript() should probably
// return [deliveryNum, t] pairs. Think about how to provide an
// accurate crankNum, because I'm not sure I want that in transcript.
// return [deliveryNum, t] pairs.
let deliveryNum = startPos || 0;
for (const te of vatKeeper.getTranscript(startPos)) {
for await (const te of vatKeeper.getTranscript(startPos)) {
// if (deliveryNum % 100 === 0) {
// console.debug(`replay vatID:${vatID} deliveryNum:${deliveryNum} / ${total}`);
// }
//
// we slog the replay just like the original, but some fields are missing
const finishSlog = slogReplay(kernelSlog, vatID, deliveryNum, te);
const sim = makeSyscallSimulator(kernelSlog, vatID, deliveryNum, te);
// eslint-disable-next-line no-await-in-loop, @jessie.js/no-nested-await
const status = await manager.deliver(te.d, sim.syscallHandler);
finishSlog(status);
sim.finishSimulation(); // will throw if syscalls did not match
Expand Down Expand Up @@ -310,6 +311,7 @@ export function makeVatWarehouse({
const { enablePipelining = false } = options;

if (options.useTranscript) {
// eslint-disable-next-line @jessie.js/no-nested-await
await replayTranscript(vatID, vatKeeper, manager);
}

Expand Down Expand Up @@ -352,7 +354,7 @@ export function makeVatWarehouse({

// instantiate all static vats, in lexicographic order, up to the
// maxPreload limit
for (const [name, vatID] of kernelKeeper.getStaticVats()) {
for await (const [name, vatID] of kernelKeeper.getStaticVats()) {
if (numPreloaded >= maxPreload) {
break;
}
Expand All @@ -364,7 +366,7 @@ export function makeVatWarehouse({

// then instantiate all dynamic vats, in creation order, also
// subject to maxPreload
for (const vatID of kernelKeeper.getDynamicVats()) {
for await (const vatID of kernelKeeper.getDynamicVats()) {
if (numPreloaded >= maxPreload) {
break;
}
Expand Down Expand Up @@ -474,7 +476,8 @@ export function makeVatWarehouse({
const finishSlog = vs.delivery(crankNum, deliveryNum, kd, vd);

// wrap the syscallHandler with a syscall recorder
const { syscallHandler, getSyscalls } = recordSyscalls(origHandler);
const recorder = recordSyscalls(origHandler);
const { syscallHandler, getTranscriptSyscalls } = recorder;
assert(syscallHandler);

// make the delivery
Expand All @@ -488,7 +491,7 @@ export function makeVatWarehouse({
// record transcript entry
/** @type { import('../types-external.js').TranscriptDeliveryResults} */
const tdr = { status: deliveryResult[0] };
const transcriptEntry = { d: vd, sc: getSyscalls(), r: tdr };
const transcriptEntry = { d: vd, sc: getTranscriptSyscalls(), r: tdr };
vatKeeper.addToTranscript(transcriptEntry);
}

Expand Down Expand Up @@ -590,6 +593,7 @@ export function makeVatWarehouse({
// worker may or may not be online
if (ephemeral.vats.has(vatID)) {
try {
// eslint-disable-next-line @jessie.js/no-nested-await
await evict(vatID);
} catch (err) {
console.debug('vat termination was already reported; ignoring:', err);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/lib/recordVatOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const makeVatOptionRecorder = (kernelKeeper, bundleHandler) => {
} = options;
const unused = Object.keys(leftover);
if (unused.length) {
Fail`warning: ${vatID} unused options ${unused.join(',')}`;
Fail`OptionRecorder: ${vatID} unused options ${unused.join(',')}`;
}
const workerOptions = await makeWorkerOptions(managerType, bundleHandler);
/** @type { import('../types-internal.js').RecordedVatOptions } */
Expand Down

0 comments on commit 4659426

Please sign in to comment.