Skip to content

Commit

Permalink
chore: use a fresh zcfBundleCap from inside startInstance
Browse files Browse the repository at this point in the history
makeStartInstance was being passed an accessor to retrieve
zcfBundleCap from zoe's state. The accessor was being called once and
the result re-used rather than calling the accessor every time in case
there was a new value.
  • Loading branch information
Chris-Hibbert committed Jun 23, 2023
1 parent 454ba9e commit a32d8e2
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export const makeStartInstance = (
seatHandleToZoeSeatAdmin,
);

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

const InstanceAdminStateShape = harden({
instanceStorage: M.remotable('ZoeInstanceStorageManager'),
instanceAdmin: M.remotable('InstanceAdmin'),
Expand Down Expand Up @@ -178,12 +184,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 @@ -200,22 +204,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 @@ -306,9 +311,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 @@ -324,11 +326,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

0 comments on commit a32d8e2

Please sign in to comment.