Skip to content

Commit

Permalink
Merge pull request #6898 from Agoric/6826-other-install-bundle-id
Browse files Browse the repository at this point in the history
fix: replace other zoe.install with zoe.installBundleID
  • Loading branch information
mergify[bot] authored Feb 13, 2023
2 parents 690b2b4 + 7f1cd48 commit af4d93b
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 114 deletions.
1 change: 1 addition & 0 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ VOTE_OPTION = yes
GOSRC = ../../golang/cosmos
# For deep (cross-vat) stacks, try...
# DEBUG ?= SwingSet:ls,SwingSet:vat,track-turns
# or to get kernel messages: SwingSet:ls,SwingSet:vat,SwingSet
DEBUG ?= SwingSet:ls,SwingSet:vat
AG_SOLO = DEBUG=$(DEBUG) $(shell cd ../solo/bin && pwd)/ag-solo
AGC = DEBUG=$(DEBUG) PATH="$$PWD/bin:$$PATH" $(GOSRC)/build/agd
Expand Down
3 changes: 3 additions & 0 deletions packages/cosmic-swingset/test/test-make.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test.before(async t => {
});

test.serial('make and exec', async t => {
// Note: the test harness discards the (voluminous) log messages
// emitted by the kernel and vats. You can run `make scenario2-setup
// scenario2-run-chain-to-halt` manually, to see them all.
const { pspawnAgd, scenario2 } = t.context;
t.log('exec agd');
t.is(await pspawnAgd([]).exit, 0, 'exec agd exits successfully');
Expand Down
64 changes: 34 additions & 30 deletions packages/deploy-script-support/src/coreProposalBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const t = 'makeCoreProposalBehavior';

export const permits = {
consume: { board: t, agoricNamesAdmin: t },
evaluateInstallation: t,
evaluateBundleCap: t,
installation: { produce: t },
modules: { utils: { runModuleBehaviors: t } },
};
Expand All @@ -22,7 +22,7 @@ export const permits = {
* definitions.
*
* @param {object} opts
* @param {string} opts.manifestInstallRef
* @param {{ bundleName: string } | { bundleID: string }} opts.manifestBundleRef
* @param {[string, ...unknown[]]} opts.getManifestCall
* @param {Record<string, Record<string, unknown>>} [opts.overrideManifest]
* @param {typeof import('@endo/far').E} opts.E
Expand All @@ -31,7 +31,7 @@ export const permits = {
* @returns {(vatPowers: unknown) => Promise<unknown>}
*/
export const makeCoreProposalBehavior = ({
manifestInstallRef,
manifestBundleRef,
getManifestCall,
overrideManifest,
E,
Expand All @@ -54,37 +54,55 @@ export const makeCoreProposalBehavior = ({
return fromEntries(ents);
};

/** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateInstallation: any }} allPowers */
/** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} allPowers */
const behavior = async allPowers => {
const {
consume: { board, agoricNamesAdmin },
evaluateInstallation,
consume: { vatAdminSvc, zoe, agoricNamesAdmin },
evaluateBundleCap,
installation: { produce: produceInstallations },
modules: {
utils: { runModuleBehaviors },
},
} = allPowers;
const [exportedGetManifest, ...manifestArgs] = getManifestCall;

const restoreRef = overrideRestoreRef || (x => E(board).getValue(x));
const defaultRestoreRef = async ref => {
// extract-proposal.js creates these records, and bundleName is
// the name under which the bundle was installed into
// config.bundles
const p = ref.bundleName
? E(vatAdminSvc).getBundleIDByName(ref.bundleName)
: ref.bundleID;
const bundleID = await p;
return E(zoe).installBundleID(bundleID);
};
const restoreRef = overrideRestoreRef || defaultRestoreRef;

// Get the on-chain installation containing the manifest and behaviors.
console.info('restoreRef, evaluateInstallation', {
manifestInstallRef,
console.info('evaluateBundleCap', {
manifestBundleRef,
exportedGetManifest,
vatAdminSvc,
});
const manifestInstallation = await restoreRef(manifestInstallRef);
const behaviors = await evaluateInstallation(manifestInstallation);
let bcapP;
if ('bundleName' in manifestBundleRef) {
bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName);
} else {
bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID);
}
const bundleCap = await bcapP;

const manifestNS = await evaluateBundleCap(bundleCap);

console.error('execute', {
exportedGetManifest,
behaviors: Object.keys(behaviors),
behaviors: Object.keys(manifestNS),
});
const {
manifest,
options: rawOptions,
installations: rawInstallations,
} = await behaviors[exportedGetManifest](
} = await manifestNS[exportedGetManifest](
harden({ restoreRef }),
...manifestArgs,
);
Expand All @@ -106,7 +124,7 @@ export const makeCoreProposalBehavior = ({
// Evaluate the manifest for our behaviors.
return runModuleBehaviors({
allPowers,
behaviors,
behaviors: manifestNS,
manifest: overrideManifest || manifest,
makeConfig: (name, _permit) => {
log('coreProposal:', name);
Expand All @@ -119,30 +137,16 @@ export const makeCoreProposalBehavior = ({
return behavior;
};

export const makeEnactCoreProposalsFromBundleCap =
export const makeEnactCoreProposalsFromBundleRef =
({ makeCoreProposalArgs, E }) =>
async allPowers => {
const {
vatPowers: { D },
devices: { vatAdmin },
consume: { zoe },
} = allPowers;
const restoreRef = async ref => {
const { bundleID } = ref;
const bundleCap = D(vatAdmin).getNamedBundleCap(bundleID);
const bundle = D(bundleCap).getBundle();
const install = await E(zoe).install(bundle);
return install;
};

await Promise.all(
makeCoreProposalArgs.map(async ({ ref, call, overrideManifest }) => {
const subBehavior = makeCoreProposalBehavior({
manifestInstallRef: ref,
manifestBundleRef: ref,
getManifestCall: call,
overrideManifest,
E,
restoreRef,
});
return subBehavior(allPowers);
}),
Expand Down
24 changes: 12 additions & 12 deletions packages/deploy-script-support/src/extract-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
import { deeplyFulfilled, defangAndTrim, stringify } from './code-gen.js';
import {
makeCoreProposalBehavior,
makeEnactCoreProposalsFromBundleCap,
makeEnactCoreProposalsFromBundleRef,
} from './coreProposalBehavior.js';

const { details: X, Fail } = assert;
Expand Down Expand Up @@ -43,13 +43,13 @@ const pathResolve = (...paths) => {
* @param {(ModuleSpecifier | FilePath)[]} coreProposals - governance
* proposals to run at chain bootstrap for scenarios such as sim-chain.
* @param {FilePath} [dirname]
* @param {typeof makeEnactCoreProposalsFromBundleCap} [makeEnactCoreProposals]
* @param {typeof makeEnactCoreProposalsFromBundleRef} [makeEnactCoreProposals]
* @param {(i: number) => number} [getSequenceForProposal]
*/
export const extractCoreProposalBundles = async (
coreProposals,
dirname = '.',
makeEnactCoreProposals = makeEnactCoreProposalsFromBundleCap,
makeEnactCoreProposals = makeEnactCoreProposalsFromBundleRef,
getSequenceForProposal,
) => {
if (!getSequenceForProposal) {
Expand All @@ -62,7 +62,7 @@ export const extractCoreProposalBundles = async (
.stat(dirname)
.then(stbuf => (stbuf.isDirectory() ? dirname : path.dirname(dirname)));

/** @type {Map<{ bundleID?: string }, { source: string, bundle?: string }>} */
/** @type {Map<{ bundleName?: string }, { source: string, bundle?: string }>} */
const bundleHandleToAbsolutePaths = new Map();

const bundleToSource = new Map();
Expand Down Expand Up @@ -114,7 +114,7 @@ export const extractCoreProposalBundles = async (
bundleToSource.set(absoluteBundle, absoluteSrc);
}
}
// Don't harden the bundleHandle since we need to set the bundleID on
// Don't harden the bundleHandle since we need to set the bundleName on
// its unique identity later.
thisProposalBundleHandles.add(bundleHandle);
bundleHandleToAbsolutePaths.set(bundleHandle, harden(absolutePaths));
Expand All @@ -141,20 +141,20 @@ export const extractCoreProposalBundles = async (
return 0;
})
.map(([handle, absolutePaths], j) => {
// Transform the bundle handle identity into a bundleID reference.
handle.bundleID = `coreProposal${thisProposalSequence}_${j}`;
// Transform the bundle handle identity into a bundleName reference.
handle.bundleName = `coreProposal${thisProposalSequence}_${j}`;
harden(handle);

/** @type {[string, { sourceSpec: string }]} */
const specEntry = [
handle.bundleID,
handle.bundleName,
{ sourceSpec: absolutePaths.source },
];
return specEntry;
});

// Now that we've assigned all the bundleIDs and hardened the handles, we
// can extract the behavior bundle.
// Now that we've assigned all the bundleNames and hardened the
// handles, we can extract the behavior bundle.
const { sourceSpec, getManifestCall } = await deeplyFulfilled(
harden(proposal),
);
Expand All @@ -167,7 +167,7 @@ export const extractCoreProposalBundles = async (
](harden({ restoreRef: () => null }), ...manifestArgs);

const behaviorBundleHandle = harden({
bundleID: `coreProposal${thisProposalSequence}_behaviors`,
bundleName: `coreProposal${thisProposalSequence}_behaviors`,
});
const behaviorAbsolutePaths = harden({
source: behaviorSource,
Expand All @@ -178,7 +178,7 @@ export const extractCoreProposalBundles = async (
);

bundleSpecEntries.unshift([
behaviorBundleHandle.bundleID,
behaviorBundleHandle.bundleName,
{ sourceSpec: behaviorAbsolutePaths.source },
]);

Expand Down
13 changes: 9 additions & 4 deletions packages/deploy-script-support/src/writeCoreProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const makeWriteCoreProposal = (

// Await a reference then publish to the board.
const publishRef = async refP => {
throw Error('writeCoreProposal publishRef not implemented yet');
// TODO: rewrite to get a BundleID, and then:
// return harden({ bundleID });
// eslint-disable-next-line no-unreachable
const ref = await refP;
console.log('published', { filePrefix, ref });
return E(board).getId(ref);
Expand All @@ -97,18 +101,19 @@ export const makeWriteCoreProposal = (
await mergeProposalPermit(proposal, permits);

// Get an install
const manifestInstallRef = await publishRef(install(sourceSpec));
console.log('writing', { filePrefix, manifestInstallRef, sourceSpec });
// TODO: this won't use install(), because it won't go through zoe
const manifestBundleRef = await publishRef(install(sourceSpec));
console.log('writing', { filePrefix, manifestBundleRef, sourceSpec });
const code = `\
// This is generated by writeCoreProposal; please edit!
/* eslint-disable */
const manifestInstallRef = ${stringify(manifestInstallRef)};
const manifestBundleRef = ${stringify(manifestBundleRef)};
const getManifestCall = harden(${stringify(getManifestCall, true)});
const overrideManifest = ${stringify(overrideManifest, true)};
// Make the behavior the completion value.
(${makeCoreProposalBehavior})({ manifestInstallRef, getManifestCall, overrideManifest, E });
(${makeCoreProposalBehavior})({ manifestBundleRef, getManifestCall, overrideManifest, E });
`;

const trimmed = defangAndTrim(code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,51 @@ import {
} from '@agoric/vats/src/core/utils.js';
import { makeCoreProposalBehavior } from '../../src/coreProposalBehavior.js';

// TODO: we need to rewrite writeCoreProposal.js to produce BundleIDs,
// although this test doesn't exercise that.

test('coreProposalBehavior', async t => {
const manifestInstallRef = 'manifestInstallRef';
const manifestBundleRef = { bundleName: 'manifestBundleRef' };
/** @type {[string, ...unknown[]]} */
const getManifestCall = ['getManifestForTest', 'arg1', 'arg2'];
const behavior = makeCoreProposalBehavior({
E,
manifestInstallRef,
manifestBundleRef,
getManifestCall,
log: t.log,
});
const { agoricNamesAdmin } = makeAgoricNamesAccess(t.log);
const bundleID = 'the-bundleID';
const bundleCap = {};
const vatAdminSvc = {
getNamedBundleID: bundleName => {
t.is(bundleName, manifestBundleRef.bundleName);
return bundleID;
},
getNamedBundleCap: bundleName => {
t.is(bundleName, manifestBundleRef.bundleName);
return bundleCap;
},
};
const fromInstallation = {};
const result = await behavior({
consume: {
board: {
getValue: id => `boardValue:${id}`,
vatAdminSvc,
zoe: {
installBundleID: id => {
t.is(id, bundleID);
return `installation:${id}`;
},
},
agoricNamesAdmin,
},
aParams: 'aparms',
bParams: 'bparms',
cParams: 'cparms',
evaluateInstallation: inst => {
t.is(inst, 'boardValue:manifestInstallRef');
evaluateBundleCap: bcap => {
t.is(bcap, bundleCap);
return {
fromInstallation: inst,
fromInstallation,
getManifestForTest: (powers, ...args) => {
t.deepEqual(args, ['arg1', 'arg2']);
return {
Expand Down Expand Up @@ -92,7 +112,7 @@ test('coreProposalBehavior', async t => {
},
installation: {
produce: {
foo: { resolve: x => t.is(x.fromInstallation, 'boardValue:xxx') },
foo: { resolve: x => t.is(x.fromInstallation, fromInstallation) },
},
},
modules: {
Expand Down
15 changes: 5 additions & 10 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,9 @@ harden(makeAnchorAsset);

/** @typedef {import('./econ-behaviors.js').EconomyBootstrapSpace} EconomyBootstrapSpace */

/** @param {BootstrapSpace & EconomyBootstrapSpace & { devices: { vatAdmin: any }, vatPowers: { D: DProxy }, }} powers */
/** @param {BootstrapSpace & EconomyBootstrapSpace} powers */
export const installGovAndPSMContracts = async ({
vatPowers: { D },
devices: { vatAdmin },
consume: { zoe },
consume: { vatAdminSvc, zoe },
produce: { psmKit },
installation: {
produce: {
Expand All @@ -303,9 +301,8 @@ export const installGovAndPSMContracts = async ({
psm,
econCommitteeCharter,
}).map(async ([name, producer]) => {
const bundleCap = D(vatAdmin).getNamedBundleCap(name);
const bundle = D(bundleCap).getBundle();
const installation = E(zoe).install(bundle);
const bundleID = await E(vatAdminSvc).getBundleIDByName(name);
const installation = await E(zoe).installBundleID(bundleID);

producer.resolve(installation);
}),
Expand All @@ -321,9 +318,7 @@ export const installGovAndPSMContracts = async ({
*/
export const PSM_GOV_MANIFEST = {
[installGovAndPSMContracts.name]: {
vatPowers: { D: true },
devices: { vatAdmin: true },
consume: { zoe: 'zoe' },
consume: { vatAdminSvc: 'true', zoe: 'zoe' },
produce: { psmKit: 'true' },
installation: {
produce: {
Expand Down
5 changes: 4 additions & 1 deletion packages/inter-protocol/test/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ harden(provideBundle);
export const setUpZoeForTest = async (setJig = () => {}) => {
const { makeFar } = makeLoopback('zoeTest');

const { admin, vatAdminState } = makeFakeVatAdmin(setJig);
const { zoeService, feeMintAccess } = await makeFar(
makeZoeKit(makeFakeVatAdmin(setJig).admin, undefined, {
makeZoeKit(admin, undefined, {
name: Stable.symbol,
assetKind: Stable.assetKind,
displayInfo: Stable.displayInfo,
Expand All @@ -59,6 +60,8 @@ export const setUpZoeForTest = async (setJig = () => {}) => {
return {
zoe: zoeService,
feeMintAccessP: feeMintAccess,
vatAdminSvc: admin,
vatAdminState,
};
};
harden(setUpZoeForTest);
Expand Down
Loading

0 comments on commit af4d93b

Please sign in to comment.