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

chore: uprade 18 cherrypicks round 5 #10676

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
86 changes: 52 additions & 34 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const prepareVaultManagerKit = (
{ zcf, marshaller, makeRecorderKit, factoryPowers },
) => {
const { priceAuthority, timerService, reservePublicFacet } = zcf.getTerms();
const watchedBrands = new Set();

const makeVault = prepareVault(baggage, makeRecorderKit, zcf);

Expand Down Expand Up @@ -424,52 +425,69 @@ export const prepareVaultManagerKit = (
},
});

void facets.helper.observeQuoteNotifier();
void facets.helper.ensureQuoteNotifierWatched();

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

const { collateralBrand, collateralUnit, debtBrand, storageNode } =
state;
if (watchedBrands.has(collateralBrand)) {
return;
}
watchedBrands.add(collateralBrand);

const ephemera = collateralEphemera(collateralBrand);

const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
const quoteNotifierP = E(priceAuthority).makeQuoteNotifier(
collateralUnit,
debtBrand,
);
// @ts-expect-error XXX quotes
ephemera.storedQuotesNotifier = makeStoredNotifier(
// @ts-expect-error XXX quotes
quoteNotifier,
E(storageNode).makeChildNode('quotes'),
marshaller,
);
trace(
'helper.start() awaiting observe storedQuotesNotifier',
collateralBrand,
);
// NB: upon restart, there may not be a price for a while. If manager
// 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) {
trace('watcher updated price', value);
ephemera.storedCollateralQuote = value;
},
onRejected() {
// NOTE: drastic action, if the quoteNotifier fails, we don't know
// the value of the asset, nor do we know how long we'll be in
// ignorance. Best choice is to disable actions that require
// prices and restart when we have a new price. If we restart the
// notifier immediately, we'll trigger an infinite loop, so try
// to restart each time we get a request.

void E.when(
quoteNotifierP,
quoteNotifier => {
// @ts-expect-error XXX quotes
ephemera.storedQuotesNotifier = makeStoredNotifier(
// @ts-expect-error XXX quotes
quoteNotifier,
E(storageNode).makeChildNode('quotes'),
marshaller,
);
trace(
'helper.start() awaiting observe storedQuotesNotifier',
collateralBrand,
);
// NB: upon restart, there may not be a price for a while. If manager
// 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) {
trace('watcher updated price', value);
ephemera.storedCollateralQuote = value;
},
onRejected() {
// NOTE: drastic action, if the quoteNotifier fails, we don't know
// the value of the asset, nor do we know how long we'll be in
// ignorance. Best choice is to disable actions that require
// prices and restart when we have a new price. If we restart the
// notifier immediately, we'll trigger an infinite loop, so try
// to restart each time we get a request.

ephemera.storedCollateralQuote = null;
watchedBrands.delete(collateralBrand);
},
});
void watchQuoteNotifier(quoteNotifier, quoteWatcher);
},
e => {
trace('makeQuoteNotifier failed, resetting', e);
ephemera.storedCollateralQuote = null;
watchedBrands.delete(collateralBrand);
},
});
void watchQuoteNotifier(quoteNotifier, quoteWatcher);
);
},
/** @param {Timestamp} updateTime */
async chargeAllVaults(updateTime) {
Expand Down Expand Up @@ -841,7 +859,7 @@ export const prepareVaultManagerKit = (
const { collateralBrand } = state;
const { storedCollateralQuote } = collateralEphemera(collateralBrand);
if (!storedCollateralQuote) {
facets.helper.observeQuoteNotifier();
facets.helper.ensureQuoteNotifierWatched();

// it might take an arbitrary amount of time to get a new quote
throw Fail`maxDebtFor called before a collateral quote was available for ${collateralBrand}`;
Expand Down Expand Up @@ -1088,7 +1106,7 @@ export const prepareVaultManagerKit = (
state.collateralBrand,
);
if (!storedCollateralQuote) {
facets.helper.observeQuoteNotifier();
facets.helper.ensureQuoteNotifierWatched();

// it might take an arbitrary amount of time to get a new quote
throw Fail`getCollateralQuote called before a collateral quote was available`;
Expand All @@ -1107,7 +1125,7 @@ export const prepareVaultManagerKit = (
state.collateralBrand,
);
if (!storedCollateralQuote) {
facets.helper.observeQuoteNotifier();
facets.helper.ensureQuoteNotifierWatched();

// it might take an arbitrary amount of time to get a new quote
throw Fail`lockOraclePrices called before a collateral quote was available for ${state.collateralBrand}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/telemetry/src/context-aware-slog.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const makeContextualSlogProcessor = (

triggerContext = {
'run.num': undefined,
'run.id': `${triggerType}-${finalBody.inboundNum}`,
'run.id': `${triggerType}-${finalBody.blockHeight}`,
'run.trigger.type': triggerType,
'run.trigger.time': finalBody.blockTime,
'run.trigger.blockHeight': finalBody.blockHeight,
Expand Down
Loading