From c905c650927739e8775825b6ce78796f81d042b5 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Thu, 28 Mar 2024 15:02:47 -0700 Subject: [PATCH] refactor: workaround bad initial update for vault params --- .../src/proposals/upgrade-vaults.js | 19 ++++++++++++++----- .../inter-protocol/src/vaultFactory/params.js | 14 +++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/inter-protocol/src/proposals/upgrade-vaults.js b/packages/inter-protocol/src/proposals/upgrade-vaults.js index 60b8b732da5d..4c76c1f67fd6 100644 --- a/packages/inter-protocol/src/proposals/upgrade-vaults.js +++ b/packages/inter-protocol/src/proposals/upgrade-vaults.js @@ -1,7 +1,9 @@ import { E } from '@endo/far'; import { makeNotifierFromAsyncIterable } from '@agoric/notifier'; import { AmountMath } from '@agoric/ertp/src/index.js'; -import { makeScalarMapStore } from '@agoric/store/src/index.js'; +import { makeTracer } from '@agoric/internal/src/index.js'; + +const trace = makeTracer('upgrade Vaults proposal'); // stand-in for Promise.any() which isn't available at this point. const any = promises => @@ -76,14 +78,20 @@ export const upgradeVaults = async (powers, { options }) => { const params = {}; for (const kwd of Object.keys(vaultBrands)) { - const b = vaultBrands[kwd]; + const collateralBrand = vaultBrands[kwd]; const subscription = E(directorPF).getSubscription({ - collateralBrand: b, + collateralBrand, }); const notifier = makeNotifierFromAsyncIterable(subscription); - const { value } = await notifier.getUpdateSince(); + let { value, updateCount } = await notifier.getUpdateSince(0n); + // @ts-expect-error It's an amount. + while (AmountMath.isEmpty(value.current.DebtLimit.value)) { + ({ value, updateCount } = await notifier.getUpdateSince(updateCount)); + trace(`debtLimit was empty, retried`, value.current.DebtLimit.value); + } + trace(kwd, 'params at', updateCount, 'are', value.current); params[kwd] = harden({ - brand: b, + brand: collateralBrand, debtLimit: value.current.DebtLimit.value, interestRate: value.current.InterestRate.value, liquidationMargin: value.current.LiquidationMargin.value, @@ -133,6 +141,7 @@ export const upgradeVaults = async (powers, { options }) => { ), ), async () => { + trace(`upgrading after delay`); await upgradeVaultFactory(); auctioneerKitProducer.reset(); auctioneerKitProducer.resolve(auctioneerKit); diff --git a/packages/inter-protocol/src/vaultFactory/params.js b/packages/inter-protocol/src/vaultFactory/params.js index 8fd360ee7e9d..046579088480 100644 --- a/packages/inter-protocol/src/vaultFactory/params.js +++ b/packages/inter-protocol/src/vaultFactory/params.js @@ -1,5 +1,3 @@ -// @jessie-check - /// import { @@ -12,6 +10,7 @@ import { M, makeScalarMapStore } from '@agoric/store'; import { TimeMath } from '@agoric/time'; import { provideDurableMapStore } from '@agoric/vat-data'; import { subtractRatios } from '@agoric/zoe/src/contractSupport/ratio.js'; +import { makeTracer } from '@agoric/internal/src/index.js'; import { amountPattern, ratioPattern } from '../contractSupport.js'; export const CHARGING_PERIOD_KEY = 'ChargingPeriod'; @@ -35,6 +34,8 @@ export const vaultDirectorParamTypes = { }; harden(vaultDirectorParamTypes); +const trace = makeTracer('Vault Params'); + /** * @param {Amount<'set'>} electorateInvitationAmount * @param {Amount<'nat'>} minInitialDebt @@ -220,18 +221,17 @@ export const provideVaultParamManagers = ( for (const [brand, args] of managerArgs.entries()) { let values; for (const key of Object.keys(managerParamValues)) { - // For a couple of runs, changing to managerParamValues[+key] worked, - // but then that stopped working. Dunno why - // eslint-disable-next-line no-restricted-syntax - if (managerParamValues[key].brand === brand) { - values = managerParamValues[+key]; + if (managerParamValues[key]?.brand === brand) { + values = managerParamValues[key]; break; } } if (values) { + trace(`reviving params, override`, brand, values); makeManager(brand, { ...args, initialParamValues: values }); } else { + trace(`reviving params, keeping`, brand, args.initialParamValues); makeManager(brand, args); } }