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

7918 upgrade15 update zoe zcf #8793

Merged
merged 5 commits into from
Feb 8, 2024
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
10 changes: 8 additions & 2 deletions packages/vats/src/vat-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ const BUILD_PARAMS_KEY = 'buildZoeParams';
export function buildRootObject(vatPowers, _vatParams, zoeBaggage) {
const shutdownZoeVat = vatPowers.exitVatWithFailure;

let zoeConfigFacet;

if (zoeBaggage.has(BUILD_PARAMS_KEY)) {
const { feeIssuerConfig, zcfSpec } = zoeBaggage.get(BUILD_PARAMS_KEY);
makeDurableZoeKit({
// The return value is `{ zoeService, zoeConfigFacet, feeMintAccess }`. This
// call only needs zoeConfigFacet because the others have been returned.
// zoeConfigFacet was added after the first release of Zoe on-chain.
({ zoeConfigFacet } = makeDurableZoeKit({
// For now Zoe will rewire vatAdminSvc on its own
shutdownZoeVat,
feeIssuerConfig,
zcfSpec,
zoeBaggage,
});
}));
}

return Far('root', {
Expand Down Expand Up @@ -44,5 +49,6 @@ export function buildRootObject(vatPowers, _vatParams, zoeBaggage) {
feeMintAccess,
});
},
getZoeConfigFacet: () => zoeConfigFacet,
});
}
32 changes: 15 additions & 17 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const makeStartInstance = (
seatHandleToZoeSeatAdmin,
);

const getFreshZcfBundleCap = async () => {
const settledBundleCap = await getZcfBundleCapP();
settledBundleCap !== undefined || Fail`the ZCF bundle cap was broken`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When might settledBundleCap be undefined? What I'm wondering is if "broken" is the right diagnosis to report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a fresh ZcfBundleCap is gotten, what if anything updates state.zcfBundleCap? Does getZcfBundleCapP do that? Where is getZcfBundleCapP defined anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zcfBundleCap is defined in zoe.js. It starts out undefined, and is set when setVatAdminSvc() is called. Zoe ensures that it's set early, but I think the type system can't tell, and is happier when we check and throw. "unset" might be more apt, but if it happens, I want whoever sees it to realize it's a big deal.

When a fresh ZcfBundleCap is gotten, what if anything updates state.zcfBundleCap?

Ooh! good catch! There's no state.zcfBundleCap, it's held in baggage. (We can't change what's in state in a new incarnation.) A fresh one would be set in a call to updateZcfBundleId, which does not update zoeBaggage. Created an issue: #8805.

Where is getZcfBundleCapP defined anyway?

In the call to makeStartInstance it's set to () => zcfBundleCap. (i.e. just dynamically access the local version held by Zoe.)

return settledBundleCap;
};

const InstanceAdminStateShape = harden({
instanceStorage: M.remotable('ZoeInstanceStorageManager'),
instanceAdmin: M.remotable('InstanceAdmin'),
Expand Down Expand Up @@ -225,12 +231,10 @@ export const makeStartInstance = (
/**
*
* @param {import('@agoric/swingset-vat').VatAdminFacet} adminNode
* @param {*} zcfBundleCap
* @param {*} contractBundleCap
*/
(adminNode, zcfBundleCap, contractBundleCap) => ({
(adminNode, contractBundleCap) => ({
adminNode,
zcfBundleCap,
contractBundleCap,
}),
{
Expand All @@ -247,22 +251,23 @@ export const makeStartInstance = (
privateArgs: newPrivateArgs,
};

return E(state.adminNode).upgrade(state.zcfBundleCap, {
vatParameters,
});
return E.when(getFreshZcfBundleCap(), bCap =>
E(state.adminNode).upgrade(bCap, { vatParameters }),
);
},
async upgradeContract(contractBundleId, newPrivateArgs = undefined) {
const { state } = this;

const newContractBundleCap = await getBundleCapByIdNow(
contractBundleId,
);
const vatParameters = {
contractBundleCap: newContractBundleCap,
privateArgs: newPrivateArgs,
};
return E(state.adminNode).upgrade(state.zcfBundleCap, {
vatParameters,
});
return E.when(getFreshZcfBundleCap(), bCap =>
E(state.adminNode).upgrade(bCap, { vatParameters }),
);
},
},
);
Expand Down Expand Up @@ -347,9 +352,6 @@ export const makeStartInstance = (

instanceAdmin.initDelayedState(handleOfferObj, publicFacet);

const settledBundleCap = await getZcfBundleCapP();
settledBundleCap !== undefined || Fail`the bundle cap was broken`;

// creatorInvitation can be undefined, but if it is defined,
// let's make sure it is an invitation.
return E.when(
Expand All @@ -365,11 +367,7 @@ export const makeStartInstance = (
isLiveResult ||
Fail`The contract did not correctly return a creatorInvitation`;

const adminFacet = makeAdminFacet(
adminNode,
harden(settledBundleCap),
contractBundleCap,
);
const adminFacet = makeAdminFacet(adminNode, contractBundleCap);

// Actually returned to the user.
return harden({
Expand Down
24 changes: 23 additions & 1 deletion packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../internal-types.js';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { makeScalarBigMapStore, prepareExo } from '@agoric/vat-data';
import { M } from '@agoric/store';

import { makeZoeStorageManager } from './zoeStorageManager.js';
import { makeStartInstance } from './startInstance.js';
Expand All @@ -32,7 +33,7 @@ import { ZoeServiceI } from '../typeGuards.js';
const { Fail } = assert;

/**
* Create an durable instance of Zoe.
* Create a durable instance of Zoe.
*
* @param {object} options
* @param {Baggage} options.zoeBaggage - the baggage for Zoe durability. Must be provided by caller
Expand All @@ -52,6 +53,7 @@ const makeDurableZoeKit = ({
feeIssuerConfig = defaultFeeIssuerConfig,
zcfSpec = { name: 'zcf' },
}) => {
/** @type {BundleCap} */
let zcfBundleCap;

const saveBundleCap = () => {
Expand Down Expand Up @@ -168,6 +170,25 @@ const makeDurableZoeKit = ({
});
};

const ZoeConfigI = M.interface('ZoeConfigFacet', {
updateZcfBundleId: M.call(M.string()).returns(),
});

const zoeConfigFacet = prepareExo(zoeBaggage, 'ZoeConfigFacet', ZoeConfigI, {
updateZcfBundleId(bundleId) {
E.when(
getZcfBundleCap({ id: bundleId }, vatAdminSvc),
bundleCap => {
zcfBundleCap = bundleCap;
},
e => {
console.error(`'🚨 unable to update ZCF Bundle: `, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

image

What's the weird character within the literal string after the open single quote? Why is there no close single quote?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's (unnecessarily) a backquoted string. The singlequote within (between the backquote and flashing light) is unintentional. Since it's withing a backquoted string, it doesn't need a close quote.

I don't want to fix it only here. If you think it's worth the trouble, I will fix it first on master and then here.

throw e;
},
);
},
});

/** @type {ZoeService} */
const zoeService = prepareExo(zoeBaggage, 'ZoeService', ZoeServiceI, {
install(bundleId, bundleLabel) {
Expand Down Expand Up @@ -223,6 +244,7 @@ const makeDurableZoeKit = ({

return harden({
zoeService,
zoeConfigFacet,
/** @type {FeeMintAccess} */
// @ts-expect-error cast
feeMintAccess: feeMintKit.feeMintAccess,
Expand Down
9 changes: 7 additions & 2 deletions packages/zoe/src/zoeService/zoeStorageManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { E } from '@endo/far';
import { AssetKind, makeDurableIssuerKit, AmountMath } from '@agoric/ertp';
import {
AssetKind,
makeDurableIssuerKit,
AmountMath,
prepareIssuerKit,
} from '@agoric/ertp';
import {
makeScalarBigMapStore,
provideDurableWeakMapStore,
Expand Down Expand Up @@ -117,7 +122,7 @@ export const makeZoeStorageManager = (
'zoeMintBaggageSet',
);
for (const issuerBaggage of zoeMintBaggageSet.values()) {
zoeMintBaggageSet(issuerBaggage);
prepareIssuerKit(issuerBaggage);
Copy link
Member

@erights erights Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised to see zoeMintBaggageSet become prepareIssuerKit. Digging, I see that zoeMintBaggageSet just calls provideDurableSetStore. Neither sounds like it is doing a job similar to prepareIssuerKit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zoeMintBaggageSet(issuerBaggage) was always a typo here. zoeMintBaggageSet is a collection. I don't know why lint didn't complain about it, but it's been fixed on master for a while.

As @warner noticed earlier today, it only didn't fail because zoeMintBaggageSet was empty till recently.

}

const makeZoeMint = prepareExoClass(
Expand Down
Loading