Skip to content

Commit

Permalink
chore: getPublicTopics and asContinuingOffer return vows
Browse files Browse the repository at this point in the history
- update PublicTopic.storagePath on async-flow endowments to return a string instead of a promise. Uses asVow with async function since it's reasonable to assume the remote call will resolve promptly (in the same run)
- update asContinuingOffer to return a vow and unwrap the result of getPublicTopic since this is also a vow. same promptness considerations mentioned above apply
- closes: #9673
  • Loading branch information
0xpatrickdev committed Jul 10, 2024
1 parent 26741d2 commit 9edce07
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 46 deletions.
31 changes: 25 additions & 6 deletions packages/boot/test/bootstrapTests/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ test('kitchen-sink', async t => {
const wd =
await t.context.walletFactoryDriver.provideSmartWallet('agoric1test');

// create a cosmos orchestration account
await wd.executeOffer({
id: 'request-coa',
invitationSpec: {
Expand All @@ -258,17 +259,35 @@ test('kitchen-sink', async t => {
[
'request-coa',
{
// FIXME in this PR
account: { payload: { vowV0: { vowV0: undefined } } },
// account: 'published.kitchenSink.cosmos1test',
account: 'published.kitchenSink.cosmos1test',
},
],
],
});
t.like(wd.getLatestUpdateRecord(), {
status: { id: 'request-coa', numWantsSatisfied: 1 },
});
t.is(readLatest('published.kitchenSink'), '');
// FIXME in this PR
t.not(readLatest('published.kitchenSink.cosmos1test'), '');
t.is(readLatest('published.kitchenSink.cosmos1test'), '');

// create a local orchestration account
await wd.executeOffer({
id: 'request-loa',
invitationSpec: {
source: 'agoricContract',
instancePath: ['kitchenSink'],
callPipe: [['makeLocalOrchAcctInvitation']],
},
proposal: {},
});

const publicSubscriberPaths = Object.fromEntries(
wd.getCurrentWalletRecord().offerToPublicSubscriberPaths,
);
t.deepEqual(publicSubscriberPaths['request-loa'], {
account: 'published.kitchenSink.agoric1mockVlocalchainAddress',
});
t.like(wd.getLatestUpdateRecord(), {
status: { id: 'request-loa', numWantsSatisfied: 1 },
});
t.is(readLatest('published.kitchenSink.agoric1mockVlocalchainAddress'), '');
});
38 changes: 23 additions & 15 deletions packages/orchestration/src/exos/cosmos-orchestration-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { makeTracer } from '@agoric/internal';
import { Shape as NetworkShape } from '@agoric/network';
import { M } from '@agoric/vat-data';
import { VowShape } from '@agoric/vow';
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js';
import {
AmountArgShape,
ChainAddressShape,
Expand Down Expand Up @@ -69,7 +68,6 @@ const { Vow$ } = NetworkShape; // TODO #9611
/** @see {OrchestrationAccountI} */
export const IcaAccountHolderI = M.interface('IcaAccountHolder', {
...orchestrationAccountMethods,
getPublicTopics: M.call().returns(TopicsRecordShape),
delegate: M.call(ChainAddressShape, AmountArgShape).returns(VowShape),
redelegate: M.call(
ChainAddressShape,
Expand Down Expand Up @@ -100,7 +98,7 @@ const toDenomAmount = c => ({ denom: c.denom, value: BigInt(c.amount) });
export const prepareCosmosOrchestrationAccountKit = (
zone,
makeRecorderKit,
{ watch, asVow },
{ watch, asVow, when },
zcf,
) => {
const makeCosmosOrchestrationAccountKit = zone.exoClassKit(
Expand Down Expand Up @@ -313,21 +311,31 @@ export const prepareCosmosOrchestrationAccountKit = (
},
holder: {
asContinuingOffer() {
const { holder, invitationMakers } = this.facets;
return harden({
publicSubscribers: holder.getPublicTopics(),
invitationMakers,
holder,
// getStoragePath resolves promptly (same run), so we don't need a watcher
// eslint-disable-next-line no-restricted-syntax
return asVow(async () => {
const { holder, invitationMakers } = this.facets;
return harden({
// eslint-disable-next-line @jessie.js/safe-await-separator
publicSubscribers: await when(holder.getPublicTopics()),
invitationMakers,
holder,
});
});
},
getPublicTopics() {
const { topicKit } = this.state;
return harden({
account: {
description: PUBLIC_TOPICS.account[0],
subscriber: topicKit.subscriber,
storagePath: topicKit.recorder.getStoragePath(),
},
// getStoragePath resolves promptly (same run), so we don't need a watcher
// eslint-disable-next-line no-restricted-syntax
return asVow(async () => {
const { topicKit } = this.state;
return harden({
account: {
description: PUBLIC_TOPICS.account[0],
subscriber: topicKit.subscriber,
// eslint-disable-next-line @jessie.js/safe-await-separator
storagePath: await topicKit.recorder.getStoragePath(),
},
});
});
},

Expand Down
38 changes: 23 additions & 15 deletions packages/orchestration/src/exos/local-orchestration-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { makeTracer } from '@agoric/internal';
import { Shape as NetworkShape } from '@agoric/network';
import { M } from '@agoric/vat-data';
import { VowShape } from '@agoric/vow';
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/far';
import {
ChainAddressShape,
Expand Down Expand Up @@ -51,7 +50,6 @@ const { Vow$ } = NetworkShape; // TODO #9611

const HolderI = M.interface('holder', {
...orchestrationAccountMethods,
getPublicTopics: M.call().returns(TopicsRecordShape),
delegate: M.call(M.string(), AmountShape).returns(VowShape),
undelegate: M.call(M.string(), AmountShape).returns(VowShape),
deposit: M.call(PaymentShape).returns(VowShape),
Expand All @@ -77,7 +75,7 @@ export const prepareLocalOrchestrationAccountKit = (
makeRecorderKit,
zcf,
timerService,
{ watch, allVows, asVow },
{ watch, allVows, asVow, when },
chainHub,
) => {
const timestampHelper = makeTimestampHelper(timerService);
Expand Down Expand Up @@ -291,11 +289,16 @@ export const prepareLocalOrchestrationAccountKit = (
},
holder: {
asContinuingOffer() {
const { holder, invitationMakers } = this.facets;
return harden({
publicSubscribers: holder.getPublicTopics(),
invitationMakers,
holder,
// getStoragePath resolves promptly (same run), so we don't need a watcher
// eslint-disable-next-line no-restricted-syntax
return asVow(async () => {
const { holder, invitationMakers } = this.facets;
return harden({
// eslint-disable-next-line @jessie.js/safe-await-separator
publicSubscribers: await when(holder.getPublicTopics()),
invitationMakers,
holder,
});
});
},
/**
Expand All @@ -322,13 +325,18 @@ export const prepareLocalOrchestrationAccountKit = (
return asVow(() => Fail`not yet implemented`);
},
getPublicTopics() {
const { topicKit } = this.state;
return harden({
account: {
description: PUBLIC_TOPICS.account[0],
subscriber: topicKit.subscriber,
storagePath: topicKit.recorder.getStoragePath(),
},
// getStoragePath resolves promptly (same run), so we don't need a watcher
// eslint-disable-next-line no-restricted-syntax
return asVow(async () => {
const { topicKit } = this.state;
return harden({
account: {
description: PUBLIC_TOPICS.account[0],
subscriber: topicKit.subscriber,
// eslint-disable-next-line @jessie.js/safe-await-separator
storagePath: await topicKit.recorder.getStoragePath(),
},
});
});
},
/**
Expand Down
13 changes: 8 additions & 5 deletions packages/orchestration/src/utils/orchestrationAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export const orchestrationAccountMethods = {
.optional(M.record())
.returns(VowShape),
transferSteps: M.call(AmountArgShape, M.any()).returns(VowShape),
asContinuingOffer: M.call().returns({
publicSubscribers: TopicsRecordShape,
invitationMakers: M.any(),
holder: M.remotable(),
}),
asContinuingOffer: M.call().returns(
Vow$({
publicSubscribers: TopicsRecordShape,
invitationMakers: M.any(),
holder: M.remotable(),
}),
),
getPublicTopics: M.call().returns(Vow$(TopicsRecordShape)),
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ test('orchestrate - LocalOrchAccount returns a ContinuingOfferResult', async t =
getInterfaceOf(invitationMakers)!,
/Local Orchestration (.*) invitationMakers/,
);
t.log('publicSubscribers', publicSubscribers);
const { description, storagePath, subscriber } = publicSubscribers.account;
t.regex(description, /Account holder/);
// FIXME in this PR, currently a vow
t.is(getInterfaceOf(storagePath), undefined);
t.is(storagePath, 'mockChainStorageRoot.kitchen-sink.agoric1fakeLCAAddress');
t.regex(getInterfaceOf(subscriber)!, /Durable Publish Kit subscriber/);
});

Expand Down Expand Up @@ -88,7 +88,6 @@ test('orchestrate - CosmosOrchAccount returns a ContinuingOfferResult', async t
);
const { description, storagePath, subscriber } = publicSubscribers.account;
t.regex(description, /Account holder/);
// FIXME in this PR, currently a vow
t.is(getInterfaceOf(storagePath), undefined);
t.is(storagePath, 'mockChainStorageRoot.kitchen-sink.cosmos1test');
t.regex(getInterfaceOf(subscriber)!, /Durable Publish Kit subscriber/);
});
2 changes: 1 addition & 1 deletion packages/orchestration/test/staking-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ test('makeAccount() writes to storage', async t => {
icqConnection,
timer,
});
const { publicSubscribers } = holder.asContinuingOffer();
const { publicSubscribers } = await E.when(holder.asContinuingOffer());
const accountNotifier = makeNotifierFromSubscriber(
publicSubscribers.account.subscriber,
);
Expand Down

0 comments on commit 9edce07

Please sign in to comment.