Skip to content

Commit

Permalink
feat(runUtils): add EV.whenVow() to unwrap a vow
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Connolly <[email protected]>
  • Loading branch information
0xpatrickdev and dckc committed Jun 24, 2024
1 parent 7e83a07 commit 7f5f1af
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
10 changes: 9 additions & 1 deletion packages/SwingSet/tools/run-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Fail, q } from '@agoric/assert';
import { kunser } from '@agoric/kmarshal';
import { makeQueue } from '@endo/stream';

/** @import { ERef } from '@endo/far' */
/**
* @import { ERef } from '@endo/far';
* @import {Vow} from '@agoric/vow';
*/

/**
* @param {import('../src/controller/controller.js').SwingsetController} controller
Expand Down Expand Up @@ -49,6 +52,7 @@ export const makeRunUtils = controller => {
* @typedef {import('@endo/eventual-send').EProxy & {
* sendOnly: (presence: unknown) => Record<string, (...args: any) => void>;
* vat: (name: string) => Record<string, (...args: any) => Promise<any>>;
* whenVow: (vow: Vow) => Promise<any>;
* }} EVProxy
*/

Expand Down Expand Up @@ -141,6 +145,10 @@ export const makeRunUtils = controller => {
]),
),
}),
whenVow: vow =>
queueAndRun(() =>
controller.queueToVatRoot('bootstrap', 'whenVow', [vow]),
),
},
);
return harden({ queueAndRun, EV });
Expand Down
14 changes: 6 additions & 8 deletions packages/boot/test/bootstrapTests/vat-orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,18 @@ test.skip('Query connection can be created', async t => {
});

// skipping until EV supports Vows, or this functionality is tested elsewhere #9572
test.skip('Query connection can send a query', async t => {
test('Query connection can send a query', async t => {
const {
runUtils: { EV },
} = t.context;

type Powers = { orchestration: OrchestrationService };
const contract = async ({ orchestration }: Powers) => {
const queryConnection: ICQConnection =
const queryConnection =
await EV(orchestration).provideICQConnection('connection-0');

const [result] = await EV(queryConnection).query([balanceQuery]);
const unwrappedQc: ICQConnection = await EV.whenVow(queryConnection);
const [result] = await EV(unwrappedQc).query([balanceQuery]);
t.is(result.code, 0);
t.is(result.height, '0'); // bigint
t.deepEqual(QueryBalanceResponse.decode(decodeBase64(result.key)), {
Expand All @@ -235,10 +236,7 @@ test.skip('Query connection can send a query', async t => {
},
});

const results = await EV(queryConnection).query([
balanceQuery,
balanceQuery,
]);
const results = await EV(unwrappedQc).query([balanceQuery, balanceQuery]);
t.is(results.length, 2);
for (const { key } of results) {
t.deepEqual(QueryBalanceResponse.decode(decodeBase64(key)), {
Expand All @@ -250,7 +248,7 @@ test.skip('Query connection can send a query', async t => {
}

await t.throwsAsync(
EV(queryConnection).query([
EV(unwrappedQc).query([
{ ...balanceQuery, path: '/cosmos.bank.v1beta1.QueryBalanceRequest' },
]),
{
Expand Down
23 changes: 11 additions & 12 deletions packages/orchestration/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ const prepareOrchestrationKit = (
M.remotable('ChainAccountKit'),
),
provideICQConnection: M.callWhen(M.string()).returns(
M.remotable('ICQConnection'),
// M.remotable('ICQConnection'),
M.any(),
),
}),
},
Expand Down Expand Up @@ -224,17 +225,15 @@ const prepareOrchestrationKit = (
}
const remoteConnAddr = makeICQChannelAddress(controllerConnectionId);
const portAllocator = getPower(this.state.powers, 'portAllocator');
return when(
watch(
// allocate a new Port for every Connection
// TODO #9317 optimize ICQ port allocation
E(portAllocator).allocateICQControllerPort(),
this.facets.requestICQChannelWatcher,
{
remoteConnAddr,
controllerConnectionId,
},
),
return watch(
// allocate a new Port for every Connection
// TODO #9317 optimize ICQ port allocation
E(portAllocator).allocateICQControllerPort(),
this.facets.requestICQChannelWatcher,
{
remoteConnAddr,
controllerConnectionId,
},
);
},
},
Expand Down
7 changes: 7 additions & 0 deletions packages/vats/src/core/lib-boot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { E, Far } from '@endo/far';
import { makeHeapZone } from '@agoric/zone';
import { prepareVowTools } from '@agoric/vow/vat.js';
import {
makeVatSpace,
makeWellKnownSpaces,
Expand Down Expand Up @@ -73,6 +74,9 @@ export const makeBootstrap = (
const { produce, consume } = makePromiseSpace({ log, store: powerStore });
produce.powerStore.resolve(powerStore);

const vowZone = zone.subZone('vow');
const vowTools = prepareVowTools(vowZone);

/**
* Bootstrap vats and devices.
*
Expand Down Expand Up @@ -209,6 +213,9 @@ export const makeBootstrap = (
}
return value;
},
whenVow: async vow => {
return vowTools.when(vow);
},
/**
* @template K, V
* @param {MapStore<K, V>} store
Expand Down

0 comments on commit 7f5f1af

Please sign in to comment.