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

more robust repairWalletForIncarnation2 #8966

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/deploy-script-support/src/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AmountMath } from '@agoric/ertp/src/amountMath.js';
* @param {ERef<any>} walletAdmin - an internal type of the
* wallet, not defined here
* @param {ERef<ZoeService>} zoe
* @param {ERef<Purse>} zoeInvitationPurse
* @param {ERef<Purse<'set'>>} zoeInvitationPurse
*/
export const makeOfferAndFindInvitationAmount = (
walletAdmin,
Expand All @@ -28,7 +28,7 @@ export const makeOfferAndFindInvitationAmount = (
) => {
/**
* @param {Record<string, any>} invitationDetailsCriteria
* @returns {Promise<Amount>} invitationAmount
* @returns {Promise<Amount<'set'>>} invitationAmount
*/
const findInvitationAmount = async invitationDetailsCriteria => {
const invitationAmount = await E(zoeInvitationPurse).getCurrentAmount();
Expand Down
16 changes: 14 additions & 2 deletions packages/smart-wallet/src/offerWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,29 @@ const offerWatcherGuard = harden({
}),
});

/**
* @param {import('@agoric/vat-data').Baggage} baggage
*/
export const prepareOfferWatcher = baggage => {
return prepareExoClassKit(
baggage,
'OfferWatcher',
offerWatcherGuard,
(walletHelper, deposit, offerSpec, address, iAmount, seatRef) => ({
/**
*
* @param {*} walletHelper
* @param {*} deposit
* @param {import('./offers.js').OfferSpec} offerSpec
* @param {string} address
* @param {Amount<'set'>} invitationAmount
* @param {UserSeat} seatRef
*/
(walletHelper, deposit, offerSpec, address, invitationAmount, seatRef) => ({
walletHelper,
deposit,
status: offerSpec,
address,
invitationAmount: iAmount,
invitationAmount,
seatRef,
}),
{
Expand Down
66 changes: 44 additions & 22 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const trace = makeTracer('SmrtWlt');
* paymentQueues: MapStore<Brand, Array<Payment>>,
* offerToInvitationMakers: MapStore<string, import('./types.js').InvitationMakers>,
* offerToPublicSubscriberPaths: MapStore<string, Record<string, string>>,
* offerToUsedInvitation: MapStore<string, Amount>,
* offerToUsedInvitation: MapStore<string, Amount<'set'>>,
* purseBalances: MapStore<Purse, Amount>,
* updateRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<UpdateRecord>,
* currentRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<CurrentWalletRecord>,
Expand Down Expand Up @@ -643,24 +643,42 @@ export const prepareSmartWallet = (baggage, shared) => {
const offerSpec = liveOffers.get(seatId);
const seat = liveOfferSeats.get(seatId);

const invitation = invitationFromSpec(offerSpec.invitationSpec);
watcherPromises.push(
E.when(
E(invitationIssuer).getAmountOf(invitation),
invitationAmount => {
const watcher = makeOfferWatcher(
facets.helper,
facets.deposit,
offerSpec,
address,
invitationAmount,
seat,
);
return watchOfferOutcomes(watcher, seat);
},
),
);
const watchOutcome = (async () => {
await null;
let invitationAmount = state.offerToUsedInvitation.get(
// @ts-expect-error older type allowed number
offerSpec.id,
);
if (invitationAmount) {
Comment on lines +648 to +652
Copy link
Member

Choose a reason for hiding this comment

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

This will throw if the key doesn't exist. It needs to be a .has check instead

facets.helper.logWalletInfo(
'recovered invitation amount for offer',
offerSpec.id,
);
} else {
facets.helper.logWalletInfo(
'inferring invitation amount for offer',
offerSpec.id,
);
const tempInvitation = invitationFromSpec(
offerSpec.invitationSpec,
);
invitationAmount =
await E(invitationIssuer).getAmountOf(tempInvitation);
void E(invitationIssuer).burn(tempInvitation);
}

const watcher = makeOfferWatcher(
facets.helper,
facets.deposit,
offerSpec,
address,
invitationAmount,
seat,
);
return watchOfferOutcomes(watcher, seat);
})();
trace(`Repaired seat ${seatId} for wallet ${address}`);
watcherPromises.push(watchOutcome);
}

await Promise.all(watcherPromises);
Expand Down Expand Up @@ -1102,9 +1120,9 @@ export const prepareSmartWallet = (baggage, shared) => {
},
});
},
// TODO remove this and repairUnwatchedSeats once the repair has taken place.
/**
* one-time use function. Remove this and repairUnwatchedSeats once the
* repair has taken place.
* To be called once ever per wallet.
*
* @param {object} key
*/
Expand All @@ -1115,8 +1133,12 @@ export const prepareSmartWallet = (baggage, shared) => {
return;
}

void facets.helper.repairUnwatchedSeats();
void facets.helper.repairUnwatchedPurses();
facets.helper.repairUnwatchedSeats().catch(e => {
console.error('repairUnwatchedSeats rejection', e);
});
facets.helper.repairUnwatchedPurses().catch(e => {
console.error('repairUnwatchedPurses rejection', e);
});
trace(`repaired wallet ${state.address}`);
},
},
Expand Down
Loading