-
Notifications
You must be signed in to change notification settings - Fork 208
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
WalletFactory survive upgrades and repair outstanding purses and offers #8773
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
24527bb
feat: smartWallet verstion 2 with watchedPromises
turadg 41287a6
fix(smartWallet): handle upgrade disconnects from purse notifiers
dckc be1b237
feat: repairUnwatchedPurses
Chris-Hibbert 9ef5861
chore: ignore ts error for type of watchPromise
Chris-Hibbert d262617
chore: move test-wallet-upgrade from boot back to vats
dckc ce2bf57
chore: update imports in test-wallet-upgrade
dckc 5d0194e
chore: punt other another wallet test file
dckc 03ef418
chore: repair changed dropped from smartWallet
Chris-Hibbert dfe4d21
chore: drop duplicate file
Chris-Hibbert d58948e
ci: test wallet-factory core proposal
mhofman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import test from 'ava'; | ||
import { getIncarnation } from '@agoric/synthetic-chain/src/lib/vat-status.js'; | ||
|
||
test(`Smart Wallet vat was upgraded`, async t => { | ||
const incarnation = await getIncarnation('walletFactory'); | ||
|
||
t.is(incarnation, 2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
}, | ||
"devDependencies": { | ||
"@agoric/cosmic-proto": "^0.3.0", | ||
"@agoric/vats": "^0.15.2-u13.0", | ||
"@endo/bundle-source": "2.5.2-upstream-rollup", | ||
"@endo/captp": "3.1.1", | ||
"@endo/init": "0.5.56", | ||
|
@@ -26,6 +27,7 @@ | |
"dependencies": { | ||
"@agoric/assert": "^0.6.1-u11wf.0", | ||
"@agoric/casting": "^0.4.3-u13.0", | ||
"@agoric/deploy-script-support": "^0.10.4-u13.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if that could be moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, which we can punt on for now. |
||
"@agoric/ertp": "^0.16.3-u13.0", | ||
"@agoric/internal": "^0.4.0-u13.0", | ||
"@agoric/notifier": "^0.6.3-u13.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
import { E, passStyleOf } from '@endo/far'; | ||
|
||
import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js'; | ||
import { prepareExoClassKit, watchPromise } from '@agoric/vat-data'; | ||
import { M } from '@agoric/store'; | ||
import { | ||
PaymentPKeywordRecordShape, | ||
SeatShape, | ||
} from '@agoric/zoe/src/typeGuards.js'; | ||
import { AmountShape } from '@agoric/ertp/src/typeGuards.js'; | ||
import { deeplyFulfilledObject, objectMap } from '@agoric/internal'; | ||
|
||
import { UNPUBLISHED_RESULT } from './offers.js'; | ||
|
||
/** | ||
* @typedef {import('./offers.js').OfferSpec & { | ||
* error?: string, | ||
* numWantsSatisfied?: number | ||
* result?: unknown | typeof import('./offers.js').UNPUBLISHED_RESULT, | ||
* payouts?: AmountKeywordRecord, | ||
* }} OfferStatus | ||
*/ | ||
|
||
/** | ||
* @template {any} T | ||
* @typedef {{ onFulfilled: (any) => any, onRejected: (err: Error, seat: any) => void }} OfferPromiseWatcher<T, [UserSeat] | ||
*/ | ||
|
||
/** | ||
* @typedef {{ | ||
* resultWatcher: OfferPromiseWatcher<unknown>, | ||
* numWantsWatcher: OfferPromiseWatcher<number>, | ||
* paymentWatcher: OfferPromiseWatcher<PaymentPKeywordRecord>, | ||
* }} OutcomeWatchers | ||
*/ | ||
|
||
/** | ||
* @param {OutcomeWatchers} watchers | ||
* @param {UserSeat} seat | ||
*/ | ||
const watchForOfferResult = ({ resultWatcher }, seat) => { | ||
const p = E(seat).getOfferResult(); | ||
// @ts-expect-error missing declarations? | ||
watchPromise(p, resultWatcher, seat); | ||
return p; | ||
}; | ||
|
||
/** | ||
* @param {OutcomeWatchers} watchers | ||
* @param {UserSeat} seat | ||
*/ | ||
const watchForNumWants = ({ numWantsWatcher }, seat) => { | ||
const p = E(seat).numWantsSatisfied(); | ||
// @ts-expect-error missing declarations? | ||
watchPromise(p, numWantsWatcher, seat); | ||
return p; | ||
}; | ||
|
||
/** | ||
* @param {OutcomeWatchers} watchers | ||
* @param {UserSeat} seat | ||
*/ | ||
const watchForPayout = ({ paymentWatcher }, seat) => { | ||
const p = E(seat).getPayouts(); | ||
// @ts-expect-error missing declarations? | ||
watchPromise(p, paymentWatcher, seat); | ||
return p; | ||
}; | ||
|
||
/** | ||
* @param {OutcomeWatchers} watchers | ||
* @param {UserSeat} seat | ||
*/ | ||
export const watchOfferOutcomes = (watchers, seat) => { | ||
return Promise.all([ | ||
watchForOfferResult(watchers, seat), | ||
watchForNumWants(watchers, seat), | ||
watchForPayout(watchers, seat), | ||
]); | ||
}; | ||
|
||
const offerWatcherGuard = harden({ | ||
helper: M.interface('InstanceAdminStorage', { | ||
updateStatus: M.call(M.any()).returns(), | ||
onNewContinuingOffer: M.call( | ||
M.or(M.number(), M.string()), | ||
AmountShape, | ||
M.any(), | ||
) | ||
.optional(M.record()) | ||
.returns(), | ||
publishResult: M.call(M.any()).returns(), | ||
}), | ||
paymentWatcher: M.interface('paymentWatcher', { | ||
onFulfilled: M.call(PaymentPKeywordRecordShape, SeatShape).returns( | ||
M.promise(), | ||
), | ||
onRejected: M.call(M.any(), SeatShape).returns(), | ||
}), | ||
resultWatcher: M.interface('resultWatcher', { | ||
onFulfilled: M.call(M.any(), SeatShape).returns(), | ||
onRejected: M.call(M.any(), SeatShape).returns(), | ||
}), | ||
numWantsWatcher: M.interface('numWantsWatcher', { | ||
onFulfilled: M.call(M.number(), SeatShape).returns(), | ||
onRejected: M.call(M.any(), SeatShape).returns(), | ||
}), | ||
}); | ||
|
||
export const prepareOfferWatcher = baggage => { | ||
return prepareExoClassKit( | ||
baggage, | ||
'OfferWatcher', | ||
offerWatcherGuard, | ||
(walletHelper, deposit, offerSpec, address, iAmount, seatRef) => ({ | ||
walletHelper, | ||
deposit, | ||
status: offerSpec, | ||
address, | ||
invitationAmount: iAmount, | ||
seatRef, | ||
}), | ||
{ | ||
helper: { | ||
updateStatus(offerStatusUpdates) { | ||
const { state } = this; | ||
state.status = harden({ ...state.status, ...offerStatusUpdates }); | ||
|
||
state.walletHelper.updateStatus(state.status); | ||
}, | ||
onNewContinuingOffer( | ||
offerId, | ||
invitationAmount, | ||
invitationMakers, | ||
publicSubscribers, | ||
) { | ||
const { state } = this; | ||
|
||
void state.walletHelper.addContinuingOffer( | ||
offerId, | ||
invitationAmount, | ||
invitationMakers, | ||
publicSubscribers, | ||
); | ||
}, | ||
|
||
publishResult(result) { | ||
const { state, facets } = this; | ||
|
||
const passStyle = passStyleOf(result); | ||
// someday can we get TS to type narrow based on the passStyleOf result match? | ||
switch (passStyle) { | ||
case 'bigint': | ||
case 'boolean': | ||
case 'null': | ||
case 'number': | ||
case 'string': | ||
case 'symbol': | ||
case 'undefined': | ||
facets.helper.updateStatus({ result }); | ||
break; | ||
case 'copyRecord': | ||
if ('invitationMakers' in result) { | ||
// save for continuing invitation offer | ||
|
||
void facets.helper.onNewContinuingOffer( | ||
String(state.status.id), | ||
state.invitationAmount, | ||
result.invitationMakers, | ||
result.publicSubscribers, | ||
); | ||
} | ||
facets.helper.updateStatus({ result: UNPUBLISHED_RESULT }); | ||
break; | ||
default: | ||
// drop the result | ||
facets.helper.updateStatus({ result: UNPUBLISHED_RESULT }); | ||
} | ||
}, | ||
}, | ||
|
||
/** @type {OutcomeWatchers['paymentWatcher']} */ | ||
paymentWatcher: { | ||
async onFulfilled(payouts) { | ||
const { state, facets } = this; | ||
|
||
// This will block until all payouts succeed, but user will be updated | ||
// since each payout will trigger its corresponding purse notifier. | ||
const amountPKeywordRecord = objectMap(payouts, paymentRef => | ||
E.when(paymentRef, payment => state.deposit.receive(payment)), | ||
); | ||
const amounts = await deeplyFulfilledObject(amountPKeywordRecord); | ||
facets.helper.updateStatus({ payouts: amounts }); | ||
}, | ||
/** | ||
* @param {Error} err | ||
* @param {UserSeat} seat | ||
*/ | ||
onRejected(err, seat) { | ||
const { facets } = this; | ||
if (isUpgradeDisconnection(err)) { | ||
void watchForPayout(facets, seat); | ||
} | ||
}, | ||
}, | ||
|
||
/** @type {OutcomeWatchers['resultWatcher']} */ | ||
resultWatcher: { | ||
onFulfilled(result) { | ||
const { facets } = this; | ||
facets.helper.publishResult(result); | ||
}, | ||
/** | ||
* @param {Error} err | ||
* @param {UserSeat} seat | ||
*/ | ||
onRejected(err, seat) { | ||
const { facets } = this; | ||
if (isUpgradeDisconnection(err)) { | ||
void watchForOfferResult(facets, seat); | ||
} | ||
}, | ||
}, | ||
|
||
/** @type {OutcomeWatchers['numWantsWatcher']} */ | ||
numWantsWatcher: { | ||
onFulfilled(numSatisfied) { | ||
const { facets } = this; | ||
|
||
facets.helper.updateStatus({ numWantsSatisfied: numSatisfied }); | ||
}, | ||
/** | ||
* @param {Error} err | ||
* @param {UserSeat} seat | ||
*/ | ||
onRejected(err, seat) { | ||
const { facets } = this; | ||
if (isUpgradeDisconnection(err)) { | ||
void watchForNumWants(facets, seat); | ||
} | ||
}, | ||
}, | ||
}, | ||
); | ||
}; | ||
harden(prepareOfferWatcher); | ||
|
||
/** @typedef {ReturnType<typeof prepareOfferWatcher>} MakeOfferWatcher */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MH usually avoids changes that have no runtime impact on the release branch. I'm not sure whether that matters here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a problem in test files