Skip to content

Commit

Permalink
fix(swingset): merge bundle/vat-admin devices, add waitForBundlecap()
Browse files Browse the repository at this point in the history
Simplify the user experience by removing `devices.bundle` and merging its
functionality into vat-admin.

* bootstrap() can go back to doing `vatAdminService =
E(vats.vatAdmin).createVatAdminService(devices.vatAdmin)` ,
instead of `createVatAdminService(devices.vatAdmin, devices.bundle)`
* you can get bundlecaps from `E(vatAdminService).getBundlecap` or
`.getNamedBundlecap`, you no longer need `D(devices.bundle)` for those
* `E(vatAdminService).waitForBundlecap(bundleID)` gives you a Promise that
fires when (and if) the bundle has been installed, so you can e.g. begin a
`zoe.install()` before the bundle is installed (closes #4521)

closes #4566
  • Loading branch information
warner committed Feb 18, 2022
1 parent 9910309 commit df14366
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 197 deletions.
58 changes: 32 additions & 26 deletions packages/SwingSet/docs/bundles.md

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions packages/SwingSet/src/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export async function buildKernelBundles(options = {}) {
kernel: src('./kernel/kernel.js'),
adminDevice: src('./kernel/vatAdmin/vatAdmin-src'),
adminVat: src('./kernel/vatAdmin/vatAdminWrapper'),
bundleDevice: src('./devices/bundle'),
comms: src('./vats/comms'),
vattp: src('./vats/vat-tp'),
timer: src('./vats/vat-timerWrapper'),
Expand Down Expand Up @@ -327,9 +326,6 @@ export async function initializeSwingset(
config.devices.vatAdmin = {
bundle: kernelBundles.adminDevice,
};
config.devices.bundle = {
bundle: kernelBundles.bundleDevice,
};

// comms vat is added automatically, but TODO: bootstraps must still
// connect it to vat-tp. TODO: test-message-patterns builds two comms and
Expand Down Expand Up @@ -365,7 +361,7 @@ export async function initializeSwingset(
// The 'bundleName' option points into
// config.bundles.BUNDLENAME.[bundle|bundleSpec|sourceSpec] , which can
// also include arbitrary named bundles that will be made available to
// D(devices.bundle).getNamedBundlecap(bundleName) ,and temporarily as
// E(vatAdminService).getNamedBundlecap(bundleName) ,and temporarily as
// E(vatAdminService).createVatByName(bundleName)

// The 'kconfig' we pass through to initializeKernel has
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/src/kernel/initializeKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export function initializeKernel(config, hostStorage, verbose = false) {
vatKeeper.initializeReapCountdown(creationOptions.reapInterval);
if (name === 'vatAdmin') {
// Create a kref for the vatAdmin root, so the kernel can tell it
// about creation/termination of dynamic vats.
// about creation/termination of dynamic vats, and the installation
// of bundles
const kref = exportRootObject(kernelKeeper, vatID);
// Pin, to prevent it being GC'd when only the kvStore points to it
kernelKeeper.pinObject(kref);
Expand Down
23 changes: 12 additions & 11 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,9 @@ export default function buildKernel(

// the admin device is endowed directly by the kernel
deviceEndowments.vatAdmin = {
hasBundle: kernelKeeper.hasBundle,
getBundle: kernelKeeper.getBundle,
getNamedBundleID: kernelKeeper.getNamedBundleID,
pushCreateVatBundleEvent(bundle, dynamicOptions) {
const source = { bundle };
const vatID = kernelKeeper.allocateUnusedVatID();
Expand All @@ -1050,10 +1053,6 @@ export default function buildKernel(
// later when it is created and a root object is available
return vatID;
},
getBundleIDByName(bundleName) {
// this throws if the name is unknown
return kernelKeeper.getNamedBundleID(bundleName);
},
terminate: (vatID, reason) => terminateVat(vatID, true, reason),
meterCreate: (remaining, threshold) =>
kernelKeeper.allocateMeter(remaining, threshold),
Expand All @@ -1064,13 +1063,6 @@ export default function buildKernel(
meterGet: meterID => kernelKeeper.getMeter(meterID),
};

// same for bundle device
deviceEndowments.bundle = {
hasBundle: kernelKeeper.hasBundle,
getBundle: kernelKeeper.getBundle,
getNamedBundleID: kernelKeeper.getNamedBundleID,
};

// instantiate all devices
for (const [name, deviceID] of kernelKeeper.getDevices()) {
logStartup(`starting device ${name} as ${deviceID}`);
Expand Down Expand Up @@ -1239,6 +1231,15 @@ export default function buildKernel(
// bundleID is b1-HASH
if (!kernelKeeper.hasBundle(bundleID)) {
kernelKeeper.addBundle(bundleID, bundle);
const args = harden({ body: JSON.stringify([bundleID]), slots: [] });
if (vatAdminRootKref) {
// TODO: consider 'panic' instead of 'logFailure'
queueToKref(vatAdminRootKref, 'bundleInstalled', args, 'logFailure');
} else {
// this should only happen during unit tests that are too lazy to
// build a complete kernel: test/bundles/test-bundles-kernel.js
console.log(`installBundle cannot notify, missing vatAdminRootKref`);
}
kernelKeeper.commitCrank();
}
}
Expand Down
Loading

0 comments on commit df14366

Please sign in to comment.