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

handle floating promises in /inter-protocol and /vats #7760

Merged
merged 9 commits into from
May 16, 2023
16 changes: 8 additions & 8 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
priceBook.add(seat, price, stillWant, exitAfterBuy);
}

helper.publishBookData();
void helper.publishBookData();
},

/**
Expand Down Expand Up @@ -437,7 +437,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
scaledBidBook.add(seat, bidScaling, stillWant, exitAfterBuy);
}

helper.publishBookData();
void helper.publishBookData();
},
publishBookData() {
const { state } = this;
Expand All @@ -457,7 +457,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
collateralAvailable,
currentPriceLevel: state.curAuctionPrice,
});
state.bookDataKit.recorder.write(bookData);
return state.bookDataKit.recorder.write(bookData);
},
},
self: {
Expand Down Expand Up @@ -534,7 +534,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
state.startCollateral = state.startCollateral
? AmountMath.add(state.startCollateral, assetAmount)
: assetAmount;
facets.helper.publishBookData();
void facets.helper.publishBookData();
},
/** @type {(reduction: Ratio) => void} */
settleAtNewRate(reduction) {
Expand Down Expand Up @@ -601,7 +601,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
}
}

facets.helper.publishBookData();
void facets.helper.publishBookData();
},
getCurrentPrice() {
return this.state.curAuctionPrice;
Expand All @@ -615,7 +615,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {

trace(`locking `, state.updatingOracleQuote);
state.lockedPriceForRound = state.updatingOracleQuote;
facets.helper.publishBookData();
void facets.helper.publishBookData();
},

setStartingRate(rate) {
Expand Down Expand Up @@ -689,7 +689,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
state.curAuctionPrice = null;
state.remainingProceedsGoal = null;
state.startProceedsGoal = null;
facets.helper.publishBookData();
void facets.helper.publishBookData();
},
getDataUpdates() {
return this.state.bookDataKit.subscriber;
Expand Down Expand Up @@ -738,7 +738,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
});
},
);
facets.helper.publishBookData();
void facets.helper.publishBookData();
},
stateShape: AuctionBookStateShape,
},
Expand Down
25 changes: 13 additions & 12 deletions packages/inter-protocol/src/auction/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ export const makeScheduler = async (
now,
),
});
scheduleRecorder.write(sched);
return scheduleRecorder.write(sched);
};

/**
* @param {Schedule | null} schedule
* @returns {Promise<void>}
*/
const clockTick = schedule => {
const clockTick = async schedule => {
trace('clockTick', schedule?.startTime, now);
if (!schedule) {
return;
Expand All @@ -161,7 +162,7 @@ export const makeScheduler = async (
return E(timer).cancel(stepCancelToken);
};

const advanceRound = () => {
const advanceRound = async () => {
if (auctionState === AuctionState.ACTIVE) {
auctionDriver.reducePriceAndTrade();
} else {
Expand All @@ -176,7 +177,7 @@ export const makeScheduler = async (
'Unable to start auction cleanly. skipping this auction round.',
),
);
finishAuctionRound();
await finishAuctionRound();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? finishAuctionRound() isn't async.


return false;
}
Expand All @@ -188,21 +189,21 @@ export const makeScheduler = async (
case 'before':
break;
case 'during':
advanceRound();
await advanceRound();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nor is advanceRound().

break;
case 'endExactly':
if (advanceRound()) {
finishAuctionRound();
if (await advanceRound()) {
await finishAuctionRound();
}
break;
case 'after':
finishAuctionRound();
await finishAuctionRound();
break;
default:
Fail`invalid case`;
}

publishSchedule();
void publishSchedule();
};

// schedule the wakeups for the steps of this round
Expand All @@ -226,7 +227,7 @@ export const makeScheduler = async (
wake(time) {
setTimeMonotonically(time);
trace('wake step', now);
clockTick(liveSchedule);
void clockTick(liveSchedule);
},
}),
stepCancelToken,
Expand All @@ -246,7 +247,7 @@ export const makeScheduler = async (
},
}),
);
publishSchedule();
void publishSchedule();
};

// schedule a wakeup to lock prices
Expand Down Expand Up @@ -333,7 +334,7 @@ export const makeScheduler = async (

// when auction parameters change, schedule a next auction if one isn't
// already scheduled
observeIteration(
void observeIteration(
subscribeEach(paramUpdateSubscription),
harden({
async updateState(_newState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ export const createPriceFeed = async (
installation: priceAggregator,
});

E(E(agoricNamesAdmin).lookupAdmin('instance')).update(
AGORIC_INSTANCE_NAME,
faKit.instance,
);
E(E(agoricNamesAdmin).lookupAdmin('instance'))
.update(AGORIC_INSTANCE_NAME, faKit.instance)
.catch(err =>
console.error(`🚨 failed to update ${AGORIC_INSTANCE_NAME}`, err),
);

E(E.get(econCharterKit).creatorFacet).addInstance(
faKit.instance,
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/reserve/assetReserveKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const prepareAssetReserveKit = async (
totalFeeMinted: state.totalFeeMinted,
totalFeeBurned: state.totalFeeBurned,
});
state.metricsKit.recorder.write(metrics);
void state.metricsKit.recorder.write(metrics);
},
},
governedApis: {
Expand Down
6 changes: 3 additions & 3 deletions packages/inter-protocol/src/vaultFactory/liquidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const scheduleLiquidationWakeups = async (
]);

// make one observer that will usually ignore the update.
observeIteration(
void observeIteration(
subscribeEach(E(auctioneerPublicFacet).getSubscription()),
harden({
async updateState(_newState) {
Expand All @@ -63,7 +63,7 @@ const scheduleLiquidationWakeups = async (

const waitForNewAuctionParams = () => {
if (cancelToken) {
E(timer).cancel(cancelToken);
void E(timer).cancel(cancelToken);
}
cancelToken = undefined;
};
Expand Down Expand Up @@ -96,7 +96,7 @@ const scheduleLiquidationWakeups = async (
if (TimeMath.compareAbs(now, nominalStart) > 0) {
if (TimeMath.compareAbs(now, endTime) < 0) {
if (cancelToken) {
E(timer).cancel(cancelToken);
void E(timer).cancel(cancelToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't wait, I think we should assign a new token so the old one doesn't get used to soon.

cancelToken = makeCancelToken();

}

void E(timer).setWakeup(afterStart, reschedulerWaker);
Expand Down
21 changes: 11 additions & 10 deletions packages/inter-protocol/src/vaultFactory/vaultDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,13 @@ export const prepareVaultDirector = (
*/
async start() {
const { helper } = this.facets;
helper.rescheduleLiquidationWakeups();
await updateShortfallReporter();
await helper.rescheduleLiquidationWakeups();
updateShortfallReporter().catch(err =>
console.error(
'🛠️ updateShortfallReporter failed during start(); repair by updating governance',
err,
),
);
},
},
},
Expand All @@ -550,19 +555,15 @@ export const prepareVaultDirector = (
harden(prepareVaultDirector);

/**
* Prepare the VaultDirector kind, get or make the singleton, and call .start() to kick off processes.
* Prepare the VaultDirector kind, get or make the singleton
*
* @type {(...pvdArgs: Parameters<typeof prepareVaultDirector>) => ReturnType<ReturnType<typeof prepareVaultDirector>>}
*/
export const provideAndStartDirector = (...args) => {
export const provideDirector = (...args) => {
const makeVaultDirector = prepareVaultDirector(...args);

const [baggage] = args;

const director = provide(baggage, 'director', makeVaultDirector);
director.helper
.start()
.catch(err => console.error('🚨 vaultDirector failed to start:', err));
return director;
return provide(baggage, 'director', makeVaultDirector);
};
harden(provideAndStartDirector);
harden(provideDirector);
10 changes: 8 additions & 2 deletions packages/inter-protocol/src/vaultFactory/vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { E } from '@endo/eventual-send';
import { FeeMintAccessShape } from '@agoric/zoe/src/typeGuards.js';
import { InvitationShape } from '../auction/params.js';
import { SHORTFALL_INVITATION_KEY, vaultDirectorParamTypes } from './params.js';
import { provideAndStartDirector } from './vaultDirector.js';
import { provideDirector } from './vaultDirector.js';

const trace = makeTracer('VF', false);

Expand Down Expand Up @@ -116,7 +116,7 @@ export const prepare = async (zcf, privateArgs, baggage) => {
vaultDirectorParamTypes,
);

const director = provideAndStartDirector(
const director = provideDirector(
baggage,
zcf,
vaultDirectorParamManager,
Expand All @@ -130,6 +130,12 @@ export const prepare = async (zcf, privateArgs, baggage) => {
makeERecorderKit,
);

// cannot await because it would make remote calls during vat restart
director.helper.start().catch(err => {
console.error('💀 vaultDirector failed to start:', err);
zcf.shutdownWithFailure(err);
});

// validate async to wait for params to be finished
// UNTIL https://github.com/Agoric/agoric-sdk/issues/4343
void validateElectorate(zcf, vaultDirectorParamManager);
Expand Down
23 changes: 16 additions & 7 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,17 @@ export const prepareVaultManagerKit = (
);
state.totalDebt = AmountMath.subtract(state.totalDebt, shortfall);

void E.when(factoryPowers.getShortfallReporter(), reporter =>
E(reporter).increaseLiquidationShortfall(shortfall),
);
E.when(
factoryPowers.getShortfallReporter(),
reporter => E(reporter).increaseLiquidationShortfall(shortfall),
err =>
console.error(
'🛠️ getShortfallReporter() failed during liquidation; repair by updating governance',
err,
),
).catch(err => {
console.error('🚨 failed to report liquidation shortfall', err);
});
},
/**
* If interest was charged between liquidating and liquidated, erase it.
Expand Down Expand Up @@ -990,6 +998,7 @@ export const prepareVaultManagerKit = (
* @param {VaultId} vaultId
* @param {import('./vault.js').VaultPhase} vaultPhase at the end of whatever change updated balances
* @param {Vault} vault
* @returns {void}
*/
handleBalanceChange(
oldDebtNormalized,
Expand Down Expand Up @@ -1061,7 +1070,7 @@ export const prepareVaultManagerKit = (
oldCollateral,
);
// debt accounting managed through minting and burning
facets.helper.updateMetrics();
void facets.helper.updateMetrics();
}
},
},
Expand Down Expand Up @@ -1228,7 +1237,7 @@ export const prepareVaultManagerKit = (
);

helper.markLiquidating(totalDebt, totalCollateral);
helper.updateMetrics();
void helper.updateMetrics();

const { userSeatPromise, deposited } = await E.when(
E(auctionPF).makeDepositInvitation(),
Expand All @@ -1254,7 +1263,7 @@ export const prepareVaultManagerKit = (
);

trace(`LiqV after long wait`, proceeds);
helper.distributeProceeds(
return helper.distributeProceeds(
proceeds,
totalDebt,
storedCollateralQuote,
Expand All @@ -1280,7 +1289,7 @@ export const prepareVaultManagerKit = (
);

// push initial state of metrics
helper.updateMetrics();
void helper.updateMetrics();
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const makeAuctionDriver = async (t, params = defaultParams) => {
initialPrice: makeRatio(100n, bid.brand, 100n, collateralBrand),
});
priceAuthorities.init(collateralBrand, pa);
registry.registerPriceAuthority(pa, collateralBrand, bid.brand, true);
await registry.registerPriceAuthority(pa, collateralBrand, bid.brand, true);

await E(creatorFacet).addBrand(
issuerKit.issuer,
Expand Down Expand Up @@ -1015,8 +1015,8 @@ test.serial('onDeadline exit, with chainStorage RPC snapshot', async t => {
await assertPayouts(t, liqSeat, bid, collateral, 116n, 0n);

await driver.advanceTo(186n, 'wait');
scheduleTracker.assertNoUpdate();
bookTracker.assertNoUpdate();
await scheduleTracker.assertNoUpdate();
await bookTracker.assertNoUpdate();

await driver.advanceTo(210n, 'wait');
await scheduleTracker.assertChange({
Expand Down
Loading