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

feat: look up last value of vault parameters when upgrading #10035

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 26 additions & 16 deletions packages/inter-protocol/src/proposals/upgrade-vaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ export const upgradeVaults = async (

const subscription = E(directorPF).getElectorateSubscription();
const notifier = makeNotifierFromAsyncIterable(subscription);
let { value, updateCount } = await notifier.getUpdateSince(0n);
// @ts-expect-error It's an amount.
while (AmountMath.isEmpty(value.current.MinInitialDebt.value)) {
({ value, updateCount } = await notifier.getUpdateSince(updateCount));
trace(
`minInitialDebt was empty, retried`,
value.current.MinInitialDebt.value,
);
}
const { value, updateCount } = await notifier.getUpdateSince();
trace(
`minInitialDebt retrieved`,
updateCount,
value.current.MinInitialDebt.value,
value,
);

return harden({
MinInitialDebt: value.current.MinInitialDebt.value,
Expand All @@ -108,19 +106,31 @@ export const upgradeVaults = async (
collateralBrand,
});
const notifier = makeNotifierFromAsyncIterable(subscription);
let { value, updateCount } = await notifier.getUpdateSince(0n);
let { value, updateCount } = await notifier.getUpdateSince();
trace(
`debtLimit first request`,
kwd,
updateCount,
value.current.DebtLimit.value,
);
// @ts-expect-error It's an amount.
if (AmountMath.isEmpty(value.current.DebtLimit.value)) {
// The parameters might have been empty at start, and the notifier might
// give the first state before the current state.
trace(`debtLimit was empty, retrying`, value.current.DebtLimit.value);
trace(
`debtLimit was empty, retrying`,
kwd,
updateCount,
value.current.DebtLimit.value,
value,
);

// unroll a loop
({ value, updateCount } = await notifier.getUpdateSince(updateCount));
trace(` retrying`, updateCount, value.current.DebtLimit.value);

// @ts-expect-error It's an amount.
if (AmountMath.isEmpty(value.current.DebtLimit.value)) {
trace('debtLimit was empty after retrying');
throw Error('🚨Governed parameters empty after retry, Giving up');
}
({ value, updateCount } = await notifier.getUpdateSince());
trace(` retrying`, updateCount, value.current.DebtLimit.value);
}
trace(kwd, 'params at', updateCount, 'are', value.current);
params[kwd] = harden({
Expand Down
Loading