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(SwingSet): Restore LRU cache flushing when stopping a vat #6627

Merged
merged 3 commits into from
Dec 16, 2022
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
9 changes: 7 additions & 2 deletions packages/SwingSet/src/liveslots/stop-vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ export async function releaseOldState(tools) {
identifyExportedFacets(abandonedVrefSet, tools);
abandonExports(abandonedVrefSet, tools);

/* Disabling the rest of this in the interest of stop-vat performance. We
* expect that in the fullness of time the following will be superseded by a
// bringOutYourDead remains to ensure that the LRU cache is flushed,
// but the rest of this function has been disabled to improve stop-vat
// performance.
// eslint-disable-next-line no-use-before-define
await tools.bringOutYourDead();

/* We expect that in the fullness of time the following will be superseded by a
* post-upgrade scavenger process that cleans up dead database debris
* incrementally, rather than taking the hit of a potentially large delay at
* shutdown time. If that change happens, the below code can simply be
Expand Down
98 changes: 98 additions & 0 deletions packages/SwingSet/test/bootstrap-relay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { E } from '@endo/eventual-send';
import { Far, makeMarshal } from '@endo/marshal';
import { assert } from '@agoric/assert';

const { Fail, quote: q } = assert;

export const buildRootObject = () => {
let vatAdmin;
const vatData = new Map();

// Represent all data as passable by replacing non-passable values
// with special-prefix registered symbols.
const replaced = new Map();
// This is testing code, so we don't enforce absence of this prefix
// from manually created symbols.
const replacementPrefix = 'replaced:';
const makeReplacement = value => {
const replacement = Symbol.for(`${replacementPrefix}${replaced.size}`);
replaced.set(replacement, value);
return replacement;
};
const { serialize: encodeReplacements } = makeMarshal(
makeReplacement,
undefined,
{
marshalSaveError: () => {},
serializeBodyFormat: 'capdata',
},
);
const { unserialize: decodeReplacements } = makeMarshal(
undefined,
undefined,
{
serializeBodyFormat: 'capdata',
},
);
const encodePassable = value => decodeReplacements(encodeReplacements(value));
const decodePassable = arg => {
// This is testing code, so we look for replacements only at top level.
if (typeof arg !== 'symbol' || !Symbol.keyFor(arg)) {
return arg;
}
const { description } = arg;
if (!description.startsWith(replacementPrefix)) {
return arg;
}
const value =
replaced.get(arg) || Fail`no value for replacement: ${q(arg)}`;
return value;
};

return Far('root', {
bootstrap: async (vats, devices) => {
vatAdmin = await E(vats.vatAdmin).createVatAdminService(devices.vatAdmin);
},

createVat: async ({ name, bundleCapName, vatParameters = {} }) => {
const bcap = await E(vatAdmin).getNamedBundleCap(bundleCapName);
const options = { vatParameters };
const { adminNode, root } = await E(vatAdmin).createVat(bcap, options);
vatData.set(name, { adminNode, root });
return root;
},

upgradeVat: async ({ name, bundleCapName, vatParameters = {} }) => {
const vat = vatData.get(name) || Fail`unknown vat name: ${q(name)}`;
const bcap = await E(vatAdmin).getNamedBundleCap(bundleCapName);
const options = { vatParameters };
const incarnationNumber = await E(vat.adminNode).upgrade(bcap, options);
vat.incarnationNumber = incarnationNumber;
return incarnationNumber;
},

messageVat: async ({ name, methodName, args = [] }) => {
const vat = vatData.get(name) || Fail`unknown vat name: ${q(name)}`;
const { root } = vat;
const decodedArgs = args.map(decodePassable);
const result = await E(root)[methodName](...decodedArgs);
return encodePassable(result);
},

messageVatObject: async ({ presence, methodName, args = [] }) => {
const object = decodePassable(presence);
const decodedArgs = args.map(decodePassable);
const result = await E(object)[methodName](...decodedArgs);
return encodePassable(result);
},

awaitVatObject: async ({ presence, path = [] }) => {
let value = await decodePassable(presence);
for (const key of path) {
// eslint-disable-next-line no-await-in-loop
value = await value[key];
}
return encodePassable(value);
},
});
};
Loading