Skip to content

Commit

Permalink
WIP: record xsnap proceedings
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jun 20, 2021
1 parent 574ea73 commit 6688127
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { assert, details as X } from '@agoric/assert';
import { isTamed, tameMetering } from '@agoric/tame-metering';
import { importBundle } from '@agoric/import-bundle';
import { makeMeteringTransformer } from '@agoric/transform-metering';
import { xsnap } from '@agoric/xsnap';
import { xsnap, recordXSnap } from '@agoric/xsnap';

import engineGC from './engine-gc.js';
import { WeakRef, FinalizationRegistry } from './weakref.js';
Expand Down Expand Up @@ -63,6 +63,7 @@ export function makeStartXSnap(bundles, { snapStore, env, spawn }) {
};

let supervisorHash = '';
let serial = 0;
/**
* @param {string} name
* @param {(request: Uint8Array) => Promise<Uint8Array>} handleCommand
Expand All @@ -75,17 +76,33 @@ export function makeStartXSnap(bundles, { snapStore, env, spawn }) {
metered,
snapshotHash = undefined,
) {
serial += 1;
const ensureDir = d => {
console.log('ensureDir', d);
fs.mkdirSync(d, { recursive: true });
return d;
};
if (snapStore && (snapshotHash || supervisorHash)) {
// console.log('startXSnap from', { supervisorHash, snapshotHash });
return snapStore.load(snapshotHash || supervisorHash, async snapshot => {
const xs = xsnap({ snapshot, name, handleCommand, ...xsnapOpts });
const opts = { snapshot, name, handleCommand, ...xsnapOpts };
const xs = env.XSNAP_TEST_RECORD
? recordXSnap(opts, ensureDir(`/tmp/xsnap-tests/${serial}/`), {
writeFileSync: fs.writeFileSync,
})
: xsnap(opts);
await xs.evaluate('null'); // ensure that spawn is done
return xs;
});
}
// console.log('fresh xsnap', { snapstore: snapStore });
const meterOpts = metered ? {} : { meteringLimit: 0 };
const worker = xsnap({ handleCommand, name, ...meterOpts, ...xsnapOpts });
const opts = { handleCommand, name, ...meterOpts, ...xsnapOpts };
const worker = env.XSNAP_TEST_RECORD
? recordXSnap(opts, ensureDir(`/tmp/xsnap-tests/${serial}/`), {
writeFileSync: fs.writeFileSync,
})
: xsnap({ handleCommand, name, ...meterOpts, ...xsnapOpts });

for (const bundle of bundles) {
assert(
Expand Down

0 comments on commit 6688127

Please sign in to comment.