From cbcc513e2ba1fec5fb503c7bdd97267ad8b62418 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Wed, 21 Aug 2024 15:24:11 -0700 Subject: [PATCH] refactor: remove outdated dependence of vault upgrade on priceFeeds --- .../src/proposals/add-auction.js | 8 +- .../src/proposals/upgrade-vaults.js | 116 ++---------------- 2 files changed, 15 insertions(+), 109 deletions(-) diff --git a/packages/inter-protocol/src/proposals/add-auction.js b/packages/inter-protocol/src/proposals/add-auction.js index 81411f6ebf8..378f7485028 100644 --- a/packages/inter-protocol/src/proposals/add-auction.js +++ b/packages/inter-protocol/src/proposals/add-auction.js @@ -28,7 +28,7 @@ export const addAuction = async ( economicCommitteeCreatorFacet: electorateCreatorFacet, auctioneerKit: legacyKitP, }, - produce: { newAuctioneerKit, auctionsUpgradeComplete }, + produce: { auctioneerKit: produceAuctioneerKit, auctionsUpgradeComplete }, instance: { consume: { reserve: reserveInstance }, }, @@ -151,7 +151,8 @@ export const addAuction = async ( ), ); - newAuctioneerKit.resolve( + produceAuctioneerKit.reset(); + produceAuctioneerKit.resolve( harden({ label: 'auctioneer', creatorFacet: governedCreatorFacet, @@ -182,7 +183,7 @@ export const ADD_AUCTION_MANIFEST = harden({ auctioneerKit: true, }, produce: { - newAuctioneerKit: true, + auctioneerKit: true, auctionsUpgradeComplete: true, }, instance: { @@ -190,7 +191,6 @@ export const ADD_AUCTION_MANIFEST = harden({ }, installation: { consume: { - auctioneer: true, contractGovernor: true, }, produce: { auctioneer: true }, diff --git a/packages/inter-protocol/src/proposals/upgrade-vaults.js b/packages/inter-protocol/src/proposals/upgrade-vaults.js index 4b6bc0e7349..08d2a82ae50 100644 --- a/packages/inter-protocol/src/proposals/upgrade-vaults.js +++ b/packages/inter-protocol/src/proposals/upgrade-vaults.js @@ -2,34 +2,9 @@ import { E } from '@endo/far'; import { makeNotifierFromAsyncIterable } from '@agoric/notifier'; import { AmountMath } from '@agoric/ertp/src/index.js'; import { makeTracer } from '@agoric/internal/src/index.js'; -import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js'; const trace = makeTracer('upgrade Vaults proposal'); -// stand-in for Promise.any() which isn't available at this point. -/** @param {Promise[]} promises */ -const any = promises => - new Promise((resolve, reject) => { - for (const promise of promises) { - void promise.then(resolve, () => {}); - } - void Promise.allSettled(promises).then(results => { - const rejects = /** @type {PromiseRejectedResult[]} */ ( - results.filter(({ status }) => status === 'rejected') - ); - if (rejects.length === results.length) { - const messages = rejects.map( - ({ reason: { message } }) => message || 'no error message', - ); - const aggregate = new Error(messages.join(';')); - /** @type {any} */ (aggregate).errors = rejects.map( - ({ reason }) => reason, - ); - reject(aggregate); - } - }); - }); - /** * @typedef {PromiseSpaceOf<{ * auctionsUpgradeComplete: boolean; @@ -44,35 +19,26 @@ const any = promises => export const upgradeVaults = async ( { consume: { - agoricNamesAdmin, - newAuctioneerKit: auctioneerKitP, - priceAuthority, vaultFactoryKit, zoe, economicCommitteeCreatorFacet: electorateCreatorFacet, reserveKit, auctionsUpgradeComplete, }, - produce: { - auctioneerKit: auctioneerKitProducer, - newAuctioneerKit: tempAuctioneerKit, - auctionsUpgradeComplete: auctionsUpgradeCompleteProducer, - }, installation: { produce: { VaultFactory: produceVaultInstallation }, }, instance: { - produce: { auctioneer: auctioneerProducer }, + consume: { auctioneer: auctioneerInstanceP }, }, }, { options }, ) => { const { vaultsRef } = options; const kit = await vaultFactoryKit; - const auctioneerKit = await auctioneerKitP; const { instance: directorInstance } = kit; const allBrands = await E(zoe).getBrands(directorInstance); - const { Minted: istBrand, ...vaultBrands } = allBrands; + const { Minted: _istBrand, ...vaultBrands } = allBrands; const bundleID = vaultsRef.bundleID; console.log(`upgradeVaults: bundleId`, bundleID); @@ -164,14 +130,15 @@ export const upgradeVaults = async ( E.get(reserveKit).creatorFacet, ).makeShortfallReportingInvitation(); - const poserInvitation = await E( - electorateCreatorFacet, - ).getPoserInvitation(); + const [poserInvitation, auctioneerInstance] = await Promise.all([ + E(electorateCreatorFacet).getPoserInvitation(), + auctioneerInstanceP, + ]); + /** @type {import('../../src/vaultFactory/vaultFactory').VaultFactoryContract['privateArgs']} */ const newPrivateArgs = harden({ ...privateArgs, - // @ts-expect-error It has a value until reset after the upgrade - auctioneerInstance: auctioneerKit.instance, + auctioneerInstance, initialPoserInvitation: poserInvitation, initialShortfallInvitation: shortfallInvitation, managerParams: managerParamValues, @@ -186,60 +153,7 @@ export const upgradeVaults = async ( trace('upgraded vaultFactory.', upgradeResult); }; - // Wait for at least one new price feed to be ready before upgrading Vaults - void E.when( - any( - Object.values(vaultBrands).map(async brand => { - const getQuote = async lastRejectionReason => { - await null; - try { - return await E(priceAuthority).quoteGiven( - AmountMath.make(brand, 10n), - istBrand, - ); - } catch (reason) { - if ( - isUpgradeDisconnection(reason) && - (!lastRejectionReason || - reason.incarnationNumber > - lastRejectionReason.incarnationNumber) - ) { - return getQuote(reason); - } - throw reason; - } - }; - return getQuote(null); - }), - ), - async price => { - trace(`upgrading after delay`, price); - await upgradeVaultFactory(); - auctioneerKitProducer.reset(); - // @ts-expect-error auctioneerKit is non-null except between auctioneerKitProducer.reset() and auctioneerKitProducer.resolve() - auctioneerKitProducer.resolve(auctioneerKit); - auctioneerProducer.reset(); - // @ts-expect-error auctioneerKit is non-null except between auctioneerKitProducer.reset() and auctioneerKitProducer.resolve() - auctioneerProducer.resolve(auctioneerKit.instance); - // We wanted it to be valid for only a short while. - tempAuctioneerKit.reset(); - await E(E(agoricNamesAdmin).lookupAdmin('instance')).update( - 'auctioneer', - // @ts-expect-error auctioneerKit is non-null except between auctioneerKitProducer.reset() and auctioneerKitProducer.resolve() - auctioneerKit.instance, - ); - trace(`upgrading complete`, price); - }, - error => { - console.error( - 'Failed to upgrade vaultFactory', - error.message, - ...(error.errors || []), - ); - }, - ); - - console.log(`upgradeVaults scheduled; waiting for priceFeeds`); + await upgradeVaultFactory(); }; const uV = 'upgradeVaults'; @@ -256,25 +170,17 @@ export const getManifestForUpgradeVaults = async ( manifest: { [upgradeVaults.name]: { consume: { - agoricNamesAdmin: uV, - newAuctioneerKit: uV, economicCommitteeCreatorFacet: uV, - priceAuthority: uV, reserveKit: uV, vaultFactoryKit: uV, - board: uV, zoe: uV, auctionsUpgradeComplete: uV, }, - produce: { - auctioneerKit: uV, - newAuctioneerKit: uV, - auctionsUpgradeComplete: uV, - }, + produce: { auctionsUpgradeComplete: uV }, installation: { produce: { VaultFactory: true }, }, - instance: { produce: { auctioneer: uV, newAuctioneerKit: uV } }, + instance: { consume: { auctioneer: uV } }, }, }, options: { ...vaultUpgradeOptions },