From 2cad888dbdd5bd468435608191a037f7cb06bc94 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Thu, 19 Sep 2024 14:59:11 -0400 Subject: [PATCH] feat: `zoeTools` uses `asVow` - `retriable` does not seem to be a good fit for these functions as they are not idempotent --- .../orchestration/src/utils/start-helper.js | 4 +- packages/orchestration/src/utils/zoe-tools.js | 53 ++++++++++-------- .../snapshots/send-anywhere.test.ts.md | 1 - .../snapshots/send-anywhere.test.ts.snap | Bin 1118 -> 1102 bytes .../snapshots/staking-combinations.test.ts.md | 1 - .../staking-combinations.test.ts.snap | Bin 1672 -> 1664 bytes .../snapshots/unbond.contract.test.ts.md | 1 - .../snapshots/unbond.contract.test.ts.snap | Bin 987 -> 981 bytes 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/orchestration/src/utils/start-helper.js b/packages/orchestration/src/utils/start-helper.js index f11da8db32cc..e86cb6e6b0a8 100644 --- a/packages/orchestration/src/utils/start-helper.js +++ b/packages/orchestration/src/utils/start-helper.js @@ -63,8 +63,6 @@ export const provideOrchestration = ( orchestration: zone.subZone('orchestration'), /** system names for vows */ vows: zone.subZone('vows'), - /** system names for zoe */ - zoe: zone.subZone('zoe'), /** contract-provided names, and subzones */ contract: zone.subZone('contract'), }; @@ -76,7 +74,7 @@ export const provideOrchestration = ( const chainHub = makeChainHub(agoricNames, vowTools); - const zoeTools = makeZoeTools(zones.zoe, { zcf, vowTools }); + const zoeTools = makeZoeTools(zcf, vowTools); const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller); const makeLocalOrchestrationAccountKit = prepareLocalOrchestrationAccountKit( diff --git a/packages/orchestration/src/utils/zoe-tools.js b/packages/orchestration/src/utils/zoe-tools.js index 59306435247f..97dbd6e8124c 100644 --- a/packages/orchestration/src/utils/zoe-tools.js +++ b/packages/orchestration/src/utils/zoe-tools.js @@ -5,10 +5,10 @@ import { E } from '@endo/far'; const { assign, keys, values } = Object; /** + * @import {HostOf, GuestInterface} from '@agoric/async-flow'; * @import {InvitationMakers} from '@agoric/smart-wallet/src/types.js'; * @import {ResolvedPublicTopic} from '@agoric/zoe/src/contractSupport/topics.js'; * @import {VowTools} from '@agoric/vow'; - * @import {Zone} from '@agoric/zone'; * @import {LocalAccountMethods} from '../types.js'; */ @@ -38,25 +38,26 @@ const { assign, keys, values } = Object; */ /** - * @param {Zone} zone - * @param {{ zcf: ZCF; vowTools: VowTools }} io + * @param {ZCF} zcf + * @param {VowTools} vowTools */ -export const makeZoeTools = ( - zone, - { zcf, vowTools: { retriable, when, allVows, allSettled } }, -) => { +export const makeZoeTools = (zcf, vowTools) => { + const { when, allVows, allSettled, asVow } = vowTools; /** * Transfer the `amounts` from `srcSeat` to `localAccount`. If any of the * deposits fail, everything will be rolled back to the `srcSeat`. Supports * multiple items in the `amounts` {@link AmountKeywordRecord}. + * + * @type {HostOf} */ - const localTransfer = retriable( - zone, - 'localTransfer', + const localTransfer = (srcSeat, localAccount, amounts) => /** - * @type {LocalTransfer} + * There are no interchain actions - everything happens on the local chain - + * so we can expect this to settle promptly. As such, it's safe to use + * `asVow` instead of `watch`. In the future, when async-flow supports E and + * promises, we might consider making this an async-flow function. */ - async (srcSeat, localAccount, amounts) => { + asVow(async () => { !srcSeat.hasExited() || Fail`The seat cannot have exited.`; const { zcfSeat: tempSeat, userSeat: userSeatP } = zcf.makeEmptySeatKit(); const userSeat = await userSeatP; @@ -114,21 +115,24 @@ export const makeZoeTools = ( throw makeError(`One or more deposits failed ${q(errors)}`); } // TODO #9541 remove userSeat from baggage - }, - ); + }); /** * Transfer the `amounts` from a `localAccount` to the `recipientSeat`. If any * of the withdrawals fail, everything will be rolled back to the * `srcLocalAccount`. Supports multiple items in the `amounts` - * {@link PaymentKeywordRecord}. + * {@link PaymentKeywordRecord} + * + * @type {HostOf} */ - const withdrawToSeat = retriable( - zone, - 'withdrawToSeat', - /** @type {WithdrawToSeat} */ - async (localAccount, destSeat, amounts) => { - await null; + const withdrawToSeat = (localAccount, destSeat, amounts) => + /* + * There are no interchain actions - everything happens on the local chain - + * so we can expect this to settle promptly. As such, it's safe to use + * `asVow` instead of `watch`. In the future, when async-flow supports E and + * promises, we might consider making this an async-flow function. + */ + asVow(async () => { !destSeat.hasExited() || Fail`The seat cannot have exited.`; const settledWithdrawals = await when( @@ -167,12 +171,13 @@ export const makeZoeTools = ( paymentKwr, ); console.debug(depositResponse); - }, - ); + }); return harden({ localTransfer, withdrawToSeat, }); }; -/** @typedef {ReturnType} ZoeTools */ + +/** @typedef {ReturnType} ZoeToolsHost */ +/** @typedef {GuestInterface} ZoeTools */ diff --git a/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md b/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md index a835e96a709d..11710ddf60d7 100644 --- a/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md +++ b/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md @@ -68,5 +68,4 @@ Generated by [AVA](https://avajs.dev). VowInternalsKit_kindHandle: 'Alleged: kind', WatchUtils_kindHandle: 'Alleged: kind', }, - zoe: {}, } diff --git a/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.snap b/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.snap index fc84d7f6361077398b9303cada551421deac665c..bbf9e53542d64bc4c6152de2241123e5fe71373e 100644 GIT binary patch literal 1102 zcmV-U1hM-;RzVSI=)7MHqc!ukH1(*d_^0S_=$^f)JESa6(8`l42#$k|;?N zaR4;lo!E=VGuG@F6AqPnrVu(P_TsnRK-VxKD=B(SH-7f7i&lhy)_oVjk9l0*m^u6khEDD(Xh)oKs z0M-HA2k;Ys-vB%TuuOn?l5ddwX6Ga3XhLR>^?Dto3X%t@VV-0bNERg5AkW+!Dca$z zwKeK+&+oO~@$`p%Pq^z;xSWNs>I&zq%iK3wlbE3~zs($}T&B)JoFn8_0)*ir^$&&9 z=5ic_?nXkkBZXGf(Lv;gNTe#2(__9?RC`hc;m47%^|2iLlR8yi$N;Zo0GTo8-T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;i60HS$dS6*=G5?wmZ<$*Wy zz;}6IbP%9}z@sV1E*;~a9`(ZLO*g#!&@5O((smsw>13!YM2?c%#4%8)^WL1rj-hQx? diff --git a/packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.md b/packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.md index 82a7b2f488ec..1a7163c59949 100644 --- a/packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.md +++ b/packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.md @@ -57,5 +57,4 @@ Generated by [AVA](https://avajs.dev). VowInternalsKit_kindHandle: 'Alleged: kind', WatchUtils_kindHandle: 'Alleged: kind', }, - zoe: {}, } diff --git a/packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.snap b/packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.snap index 90478398c1d52da9fe00bc1335147e5e5807a195..fbf713b176456c4563af10a276dffac5d86a43b3 100644 GIT binary patch literal 981 zcmV;`11kJMRzVRy~g!MHqf&yH*Qub_tMLwr)( z1+Wj`V*oz@_zl2+0JaFQLA-V19dzI0%n&kvU0YiNX@YnltJok;i&Q|W>*Sf&5=FZ) z53VNNIMRdQjmW$+j6}FkMHusp)@;Wy@AL3tFvTp5jYH0)3b|Us@H8PW5Fmr=RNoP- z6U#{oeVBuMCWTRynH2dphcu;P1FnstCXynBALd~9ww&l`oKEdHz;g}|I>0v$@P`AO zuK>3zz;_kk?+VazftOw2mTSe%S&W@e+)rKLGZ%Q^0{_@_&!*R3tO6ISz$aDUmnyL1 z0dIT2=N|CA2mIt&67|B04?W;t4|u5tBsGiPEF^cuO3YR}97Up?g}7{9pSH|(B>FKo zQe=cPbL&N>rPJDtrd~!;l=Wb{lZe#tx|k?B9xqj53kv6o3WaT)oeLDmcBNmI{Uak4 zFYCtEk)ei{*~Mu>?$?fsx;1N*M6lOspR1d6$dyi6Kjv8Lb5@5&aiaK)@@JmXi{+#v z)j?vI9Pt~4Y}J$0%PVx8{n?zmHsN%5g^tq@q!m|5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