From 40407e9be77c4fd3b97a54683556a5e14b71a4e6 Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Wed, 31 Jan 2024 01:46:23 +0000 Subject: [PATCH] feat: replace zoe and zcf --- .../proposals/a:upgrade-14/post.test.js | 6 +++ .../proposals/a:upgrade-14/sanity.test.js | 14 ------ golang/cosmos/app/app.go | 2 + packages/vats/scripts/replace-zoe.js | 19 +++++++ packages/vats/src/proposals/zcf-proposal.js | 49 +++++++++++++++++++ 5 files changed, 76 insertions(+), 14 deletions(-) delete mode 100644 a3p-integration/proposals/a:upgrade-14/sanity.test.js create mode 100644 packages/vats/scripts/replace-zoe.js create mode 100644 packages/vats/src/proposals/zcf-proposal.js diff --git a/a3p-integration/proposals/a:upgrade-14/post.test.js b/a3p-integration/proposals/a:upgrade-14/post.test.js index e26fb1e280b..acb82d0ac4f 100644 --- a/a3p-integration/proposals/a:upgrade-14/post.test.js +++ b/a3p-integration/proposals/a:upgrade-14/post.test.js @@ -6,3 +6,9 @@ test(`Smart Wallet vat was upgraded`, async t => { t.is(incarnation, 2); }); + +test(`Zoe vat was upgraded`, async t => { + const incarnation = await getIncarnation('zoe'); + + t.is(incarnation, 1); +}); diff --git a/a3p-integration/proposals/a:upgrade-14/sanity.test.js b/a3p-integration/proposals/a:upgrade-14/sanity.test.js deleted file mode 100644 index 96f0b86f8b5..00000000000 --- a/a3p-integration/proposals/a:upgrade-14/sanity.test.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @file Sanity checks of upgrade-14 - * - * This "upgrade-14" test is a dummy since there is no upgrade behavior to be tested. - * This file serves as a starting point for tests of upgrade-14. - */ -import test from 'ava'; - -import { getIncarnation } from '@agoric/synthetic-chain/src/lib/vat-status.js'; - -test(`Ensure Zoe Vat is at 0`, async t => { - const incarnation = await getIncarnation('zoe'); - t.is(incarnation, 0); -}); diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index 2c391de5f61..98268fc03fd 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -834,6 +834,8 @@ func upgrade14Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgr CoreProposalSteps := []vm.CoreProposalStep{ // First, upgrade wallet factory vm.CoreProposalStepForModules("@agoric/vats/scripts/build-wallet-factory2-upgrade.js"), + // Then, upgrade Zoe and ZCF + vm.CoreProposalStepForModules("@agoric/vats/scripts/replace-zoe.js"), } app.upgradeDetails = &upgradeDetails{ diff --git a/packages/vats/scripts/replace-zoe.js b/packages/vats/scripts/replace-zoe.js new file mode 100644 index 00000000000..8f559a6ee62 --- /dev/null +++ b/packages/vats/scripts/replace-zoe.js @@ -0,0 +1,19 @@ +import { makeHelpers } from '@agoric/deploy-script-support'; + +/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ +export const defaultProposalBuilder = async ({ publishRef, install }) => + harden({ + sourceSpec: '@agoric/vats/src/proposals/zcf-proposal.js', + getManifestCall: [ + 'getManifestForZoe', + { + zoeRef: publishRef(install('@agoric/vats/src/vat-zoe.js')), + zcfRef: publishRef(install('@agoric/zoe/src/contractFacet/vatRoot.js')), + }, + ], + }); + +export default async (homeP, endowments) => { + const { writeCoreProposal } = await makeHelpers(homeP, endowments); + await writeCoreProposal('replace-zcf', defaultProposalBuilder); +}; diff --git a/packages/vats/src/proposals/zcf-proposal.js b/packages/vats/src/proposals/zcf-proposal.js new file mode 100644 index 00000000000..7d974e02460 --- /dev/null +++ b/packages/vats/src/proposals/zcf-proposal.js @@ -0,0 +1,49 @@ +import { E } from '@endo/far'; + +/** + * @param {BootstrapPowers & { + * consume: { + * vatAdminSvc: VatAdminSvc; + * vatStore: MapStore< + * string, + * import('@agoric/swingset-vat').CreateVatResults + * >; + * }; + * }} powers + * @param {object} options + * @param {{ zoeRef: VatSourceRef; zcfRef: VatSourceRef }} options.options + */ +export const upgradeZcf = async ( + { consume: { vatAdminSvc, vatStore } }, + options, +) => { + const { zoeRef, zcfRef } = options.options; + + assert(zoeRef.bundleID); + const zoeBundleCap = await E(vatAdminSvc).getBundleCap(zoeRef.bundleID); + console.log(`ZOE BUNDLE ID: `, zoeRef.bundleID); + + const { adminNode, root: zoeRoot } = await E(vatStore).get('zoe'); + + await E(adminNode).upgrade(zoeBundleCap, {}); + + const zoeConfigFacet = await E(zoeRoot).getZoeConfigFacet(); + await E(zoeConfigFacet).updateZcfBundleId(zcfRef.bundleID); + console.log(`ZCF BUNDLE ID: `, zcfRef.bundleID); +}; + +export const getManifestForZoe = (_powers, { zoeRef, zcfRef }) => ({ + manifest: { + [upgradeZcf.name]: { + consume: { + vatAdminSvc: 'vatAdminSvc', + vatStore: 'vatStore', + }, + produce: {}, + }, + }, + options: { + zoeRef, + zcfRef, + }, +});