Skip to content

Commit

Permalink
chore(types): VatAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Aug 31, 2024
1 parent 9a9e4fb commit d94b404
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/SwingSet/src/devices/vat-admin/device-vat-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ bundleID before submitting to the kernel), or (temporarily) a full bundle.
* @typedef { string } VatID
* @typedef { string } UpgradeID
* @typedef {{
* changeOptions: (vatID: string, options: {}) => void;
* createMeter: (remaining: bigint, threshold: bigint) => MeterID
* createUnlimitedMeter: () => MeterID
* addMeterRemaining: (meterID: MeterID, delta: bigint) => void
* setMeterThreshold: (meterID: MeterID, threshold: bigint) => void
* getMeter: (meterID: MeterID) => { remaining: bigint, threshold: bigint }
* createByBundle: (bundle: Bundle, options: {}) => VatID
* createByBundleID: (bundleID: BundleID, options: {}) => VatID
* upgradeVat: (bundleID: BundleID, vatParameters: {}) => UpgradeID
* getBundleIDByName: (name: string) => string;
* upgradeVat: (vatID: string, bundleID: BundleID, _vatParameters: unknown, upgradeMessage: string) => UpgradeID;
* terminateWithFailure: (vatID: VatID, reason: {}) => void
* getBundleCap: (bundleID: BundleID) => BundleCap
* getNamedBundleCap: (name: string) => BundleCap
Expand Down
24 changes: 21 additions & 3 deletions packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,38 @@ import {
prepareSingleton,
} from '@agoric/vat-data';

/**
* @import {VatAdminRootDeviceNode} from '../../devices/vat-admin/device-vat-admin.js';
* @import {DProxy} from'../plugin-manager.js';
* @import {Baggage} from '@agoric/vat-data';
*/

const managerTypes = ['local', 'node-subprocess', 'xsnap', 'xs-worker']; // xs-worker is alias

function producePRR() {
const { promise, resolve, reject } = makePromiseKit();
return /** @type {const} */ ([promise, { resolve, reject }]);
}

/**
* Build root object of the bootstrap vat.
*
* @param {VatPowers & {
* D: DProxy;
* }} vatPowers
* @param {never} _vatParameters
* @param {Baggage} baggage
*/
export function buildRootObject(vatPowers, _vatParameters, baggage) {
const criticalVatKey = prepareSingleton(baggage, 'criticalVatKey', {});

const { D } = vatPowers;
const pendingVatCreations = new Map(); // vatID -> { resolve, reject } for promise
const pendingBundles = new Map(); // bundleID -> Promise<BundleCap>
/** @type {Map<BundleID, PromiseKit<BundleCap>>} */
const pendingBundles = new Map();
const pendingUpgrades = new Map(); // upgradeID -> Promise<UpgradeResults>

/** @type {import('../plugin-manager.js').Device<VatAdminRootDeviceNode>} */
let vatAdminDev;

const runningVats = new Map(); // vatID -> [doneP, { resolve, reject }]
Expand Down Expand Up @@ -200,7 +217,7 @@ export function buildRootObject(vatPowers, _vatParameters, baggage) {
console.log(`bundle ${bundleID} missing, hoping for reinstall`);
return;
}
pendingBundles.get(bundleID).resolve(bundlecap);
pendingBundles.get(bundleID)?.resolve(bundlecap);
pendingBundles.delete(bundleID);
checkForQuiescence();
}
Expand Down Expand Up @@ -418,8 +435,9 @@ export function buildRootObject(vatPowers, _vatParameters, baggage) {
if (!pendingBundles.has(bundleID)) {
pendingBundles.set(bundleID, makePromiseKit());
}
return pendingBundles.get(bundleID).promise;
return pendingBundles.get(bundleID)?.promise;
},
/** @type {(bundleID: BundleID) => BundleCap} */
getBundleCap(bundleID) {
const bundlecap = D(vatAdminDev).getBundleCap(bundleID);
if (bundlecap) {
Expand Down

0 comments on commit d94b404

Please sign in to comment.