Skip to content

Commit

Permalink
refactor: only use snapstore if snapstorePath given
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Feb 16, 2021
1 parent cf7dd37 commit 906d5b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
43 changes: 24 additions & 19 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import {
swingsetIsInitialized,
initializeSwingset,
} from './initializeSwingset';
import {
makeSnapstore,
defaultSnapstorePath,
} from './kernel/vatManager/snapStore';
import { makeSnapstore } from './kernel/vatManager/snapStore';

function makeConsole(tag) {
const log = anylogger(tag);
Expand All @@ -43,7 +40,7 @@ function makeConsole(tag) {
return harden(cons);
}

function makeStartXSnap(bundles, { env }) {
function makeStartXSnap(bundles, { snapstorePath, env }) {
const xsnapOpts = {
os: osType(),
spawn,
Expand All @@ -52,18 +49,21 @@ function makeStartXSnap(bundles, { env }) {
debug: !!env.XSNAP_DEBUG,
};

const pool = defaultSnapstorePath({ env });
fs.mkdirSync(pool, { recursive: true });

const snapStore = makeSnapstore(pool, {
tmpName,
existsSync: fs.existsSync,
createReadStream: fs.createReadStream,
createWriteStream: fs.createWriteStream,
rename: fs.promises.rename,
unlink: fs.promises.unlink,
resolve: path.resolve,
});
let snapStore;

if (snapstorePath) {
fs.mkdirSync(snapstorePath, { recursive: true });

snapStore = makeSnapstore(snapstorePath, {
tmpName,
existsSync: fs.existsSync,
createReadStream: fs.createReadStream,
createWriteStream: fs.createWriteStream,
rename: fs.promises.rename,
unlink: fs.promises.unlink,
resolve: path.resolve,
});
}

let supervisorHash = '';
return async function startXSnap(name, handleCommand) {
Expand All @@ -83,7 +83,9 @@ function makeStartXSnap(bundles, { env }) {
);
await worker.evaluate(`(${bundle.source}\n)()`.trim());
}
supervisorHash = await snapStore.save(async fn => worker.snapshot(fn));
if (snapStore) {
supervisorHash = await snapStore.save(async fn => worker.snapshot(fn));
}
return worker;
};
}
Expand All @@ -105,6 +107,7 @@ export async function makeSwingsetController(
slogFile,
testTrackDecref,
defaultManagerType = env.WORKER_TYPE || 'local',
snapstorePath,
} = runtimeOptions;
if (typeof Compartment === 'undefined') {
throw Error('SES must be installed before calling makeSwingsetController');
Expand Down Expand Up @@ -217,7 +220,7 @@ export async function makeSwingsetController(
JSON.parse(hostStorage.get('lockdownBundle')),
JSON.parse(hostStorage.get('supervisorBundle')),
];
const startXSnap = makeStartXSnap(bundles, { env });
const startXSnap = makeStartXSnap(bundles, { snapstorePath, env });

const slogF =
slogFile && (await fs.createWriteStream(slogFile, { flags: 'a' })); // append
Expand Down Expand Up @@ -342,12 +345,14 @@ export async function buildVatController(
debugPrefix,
testTrackDecref,
defaultManagerType,
snapstorePath,
} = runtimeOptions;
const actualRuntimeOptions = {
verbose,
debugPrefix,
testTrackDecref,
defaultManagerType,
snapstorePath,
};
const initializationOptions = { verbose, kernelBundles };
let bootstrapResult;
Expand Down
6 changes: 0 additions & 6 deletions packages/SwingSet/src/kernel/vatManager/snapStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,3 @@ export function makeSnapstore(

return freeze({ load, save });
}

export function defaultSnapstorePath({ env = process.env }) {
// ISSUE: Windows paths?
const cache = env.XDG_CACHE_HOME || `${env.HOME}/.cache`;
return `${cache}/agoric-xs-snapshots/`;
}

0 comments on commit 906d5b8

Please sign in to comment.