Skip to content

Commit

Permalink
refactor: use a non-durable set to reflect the observers' lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 4, 2024
1 parent 77f2260 commit ee6c0a1
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => {
export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
const makeScaledBidBook = prepareScaledBidBook(baggage);
const makePriceBook = preparePriceBook(baggage);
// Brands that have or are making active quoteNotifier Observers
const observedBrands = new Set();

const AuctionBookStateShape = harden({
collateralBrand: M.any(),
Expand All @@ -136,7 +138,6 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
capturedPriceForRound: M.any(),
curAuctionPrice: M.any(),
remainingProceedsGoal: M.any(),
isQuoteNotifierObserved: M.boolean(),
});

const makeAuctionBookKit = prepareExoClassKit(
Expand Down Expand Up @@ -229,13 +230,6 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
* @type {Amount<'nat'> | null}
*/
remainingProceedsGoal: null,

/**
* Is the observer for the quoteNotifier active?
*
* @type {boolean}
*/
isQuoteNotifierObserved: false,
};
},
{
Expand Down Expand Up @@ -468,12 +462,11 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
ensureQuoteNotifierObserved() {
const { state, facets } = this;
const { collateralBrand, bidBrand, priceAuthority } = state;
let { isQuoteNotifierObserved } = state;

if (isQuoteNotifierObserved) {
if (observedBrands.has(collateralBrand)) {
return;
}
isQuoteNotifierObserved = true;
observedBrands.add(collateralBrand);
trace('observing');

const quoteNotifierP = E(priceAuthority).makeQuoteNotifier(
Expand All @@ -499,21 +492,21 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
);
// lack of quote will trigger restart
state.updatingOracleQuote = null;
isQuoteNotifierObserved = false;
observedBrands.delete(collateralBrand);
},
finish: done => {
trace(
`quoteNotifier invoked finish(${done}). setting quote to null`,
);
// lack of quote will trigger restart
state.updatingOracleQuote = null;
isQuoteNotifierObserved = false;
observedBrands.delete(collateralBrand);
},
}),
e => {
trace('makeQuoteNotifier failed, resetting', e);
state.updatingOracleQuote = null;
isQuoteNotifierObserved = false;
observedBrands.delete(collateralBrand);
},
);

Expand Down

0 comments on commit ee6c0a1

Please sign in to comment.