Skip to content

Commit

Permalink
feat: vaults detects failing priceAuthority and requests new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 27, 2023
1 parent d940a99 commit 830d52a
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 22 deletions.
41 changes: 24 additions & 17 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {
RatioShape,
} from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { makeStoredNotifier, observeNotifier } from '@agoric/notifier';
import {
makeStoredNotifier,
observeNotifier,
watchPerpetualNotifier,
} from '@agoric/notifier';
import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js';
import {
M,
Expand Down Expand Up @@ -355,13 +359,7 @@ export const prepareVaultManagerKit = (
start() {
const { state, facets } = this;
trace(state.collateralBrand, 'helper.start()', state.vaultCounter);
const {
collateralBrand,
collateralUnit,
debtBrand,
storageNode,
unsettledVaults,
} = state;
const { collateralBrand, unsettledVaults } = state;

const ephemera = collateralEphemera(collateralBrand);
ephemera.prioritizedVaults = makePrioritizedVaults(unsettledVaults);
Expand Down Expand Up @@ -394,7 +392,17 @@ export const prepareVaultManagerKit = (
},
});

trace('helper.start() making quoteNotifier from', priceAuthority);
facets.helper.observeQuoteNotifier();

trace('helper.start() done');
},
observeQuoteNotifier() {
const { state, facets } = this;

const { collateralBrand, collateralUnit, debtBrand, storageNode } =
state;
const ephemera = collateralEphemera(collateralBrand);

const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
collateralUnit,
debtBrand,
Expand All @@ -406,18 +414,17 @@ export const prepareVaultManagerKit = (
);
trace('helper.start() awaiting observe storedQuotesNotifier');
// NB: upon restart, there may not be a price for a while. If manager
// operations are permitted, ones the depend on price information will
// throw. See https://github.com/Agoric/agoric-sdk/issues/4317
void observeNotifier(quoteNotifier, {
updateState(value) {
trace('storing new quote', value.quoteAmount.value);
// operations are permitted, ones that depend on price information
// will throw. See https://github.com/Agoric/agoric-sdk/issues/4317
const quoteWatcher = harden({
onFulfilled(value) {
ephemera.storedCollateralQuote = value;
},
fail(reason) {
console.error('quoteNotifier failed to iterate', reason);
onRejected() {
facets.helper.observeQuoteNotifier();
},
});
trace('helper.start() done');
void watchPerpetualNotifier(quoteNotifier, quoteWatcher);
},
/** @param {Timestamp} updateTime */
async chargeAllVaults(updateTime) {
Expand Down
Loading

0 comments on commit 830d52a

Please sign in to comment.