Skip to content

Commit

Permalink
feat(orchestrator): return unwrapped vows
Browse files Browse the repository at this point in the history
- returning unwrapped vows to ensure tests are passing and functionality is preserved
  • Loading branch information
0xpatrickdev authored and turadg committed Jun 19, 2024
1 parent 95188cd commit 5b3d56e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 30 deletions.
92 changes: 66 additions & 26 deletions packages/orchestration/src/exos/orchestrator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file ChainAccount exo */
import { AmountShape } from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { V } from '@agoric/vow/vat.js';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import {
ChainInfoShape,
Expand All @@ -10,6 +10,7 @@ import {
BrandInfoShape,
DenomAmountShape,
} from '../typeGuards.js';
import { getChainsAndConnection } from '../utils/chainHub.js';

/**
* @import {Zone} from '@agoric/base-zone';
Expand All @@ -20,6 +21,7 @@ import {
* @import {LocalChain} from '@agoric/vats/src/localchain.js';
* @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'.
* @import {Remote} from '@agoric/internal';
* @import {PickFacet} from '@agoric/swingset-liveslots';
* @import {OrchestrationService} from '../service.js';
* @import {MakeLocalOrchestrationAccountKit} from './local-orchestration-account.js';
* @import {MakeLocalChainFacade} from './local-chain-facade.js';
Expand Down Expand Up @@ -54,47 +56,85 @@ export const OrchestratorI = M.interface('Orchestrator', {
* zcf: ZCF;
* }} powers
*/
export const prepareOrchestrator = (
export const prepareOrchestratorKit = (
zone,
{
chainHub,
localchain,
makeLocalChainFacade,
makeRemoteChainFacade,
vowTools: _vowTools,
vowTools: { watch, when },
},
) =>
zone.exoClass(
zone.exoClassKit(
'Orchestrator',
OrchestratorI,
{
orchestrator: OrchestratorI,
makeLocalChainFacadeWatcher: M.interface('makeLocalChainFacadeWatcher', {
onFulfilled: M.call(M.record())
.optional(M.arrayOf(M.undefined()))
.returns(M.any()), // FIXME narrow
}),
makeRemoteChainFacadeWatcher: M.interface(
'makeRemoteChainFacadeWatcher',
{
onFulfilled: M.call(M.arrayOf(M.record()))
.optional(M.arrayOf(M.undefined()))
.returns(M.any()), // FIXME narrow
},
),
},
() => {
trace('making an Orchestrator');
return {};
},
{
/** @type {Orchestrator['getChain']} */
getChain: async name => {
const agoricChainInfo = await chainHub.getChainInfo('agoric');

if (name === 'agoric') {
// @ts-expect-error XXX chainInfo generic
/** Waits for `chainInfo` and returns a LocalChainFacade */
makeLocalChainFacadeWatcher: {
/** @param {ChainInfo} agoricChainInfo */
onFulfilled(agoricChainInfo) {
return makeLocalChainFacade(agoricChainInfo);
}

const remoteChainInfo = await chainHub.getChainInfo(name);
const connectionInfo = await chainHub.getConnectionInfo(
agoricChainInfo.chainId,
remoteChainInfo.chainId,
);

// @ts-expect-error XXX chainInfo generic
return makeRemoteChainFacade(remoteChainInfo, connectionInfo);
},
},
/**
* Waits for `chainInfo` for `agoric` and a remote chain and returns a
* RemoteChainFacade
*/
makeRemoteChainFacadeWatcher: {
/**
* Waits for `chainInfo` for `agoric` and a remote chain and returns a
* RemoteChainFacade
*
* @param {[ChainInfo, ChainInfo, IBCConnectionInfo]} chainsAndConnection
*/
onFulfilled([_agoricChainInfo, remoteChainInfo, connectionInfo]) {
return makeRemoteChainFacade(remoteChainInfo, connectionInfo);
},
},
makeLocalAccount() {
return V(localchain).makeAccount();
orchestrator: {
/** @type {Orchestrator['getChain']} */
getChain(name) {
if (name === 'agoric') {
return when(
watch(
chainHub.getChainInfo('agoric'),
this.facets.makeLocalChainFacadeWatcher,
),
);
}
return when(
watch(
getChainsAndConnection(chainHub, 'agoric', name),
this.facets.makeRemoteChainFacadeWatcher,
),
);
},
makeLocalAccount() {
return when(watch(E(localchain).makeAccount()));
},
getBrandInfo: () => Fail`not yet implemented`,
asAmount: () => Fail`not yet implemented`,
},
getBrandInfo: () => Fail`not yet implemented`,
asAmount: () => Fail`not yet implemented`,
},
);
harden(prepareOrchestrator);
harden(prepareOrchestratorKit);
7 changes: 4 additions & 3 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @file Orchestration service */

import { Fail } from '@agoric/assert';

import { prepareOrchestrator } from './exos/orchestrator.js';
import { pickFacet } from '@agoric/vat-data';
import { prepareOrchestratorKit } from './exos/orchestrator.js';

/**
* @import {AsyncFlowTools} from '@agoric/async-flow';
Expand Down Expand Up @@ -67,7 +67,7 @@ export const makeOrchestrationFacade = ({
asyncFlowTools) ||
Fail`params missing`;

const makeOrchestrator = prepareOrchestrator(zone, {
const makeOrchestratorKit = prepareOrchestratorKit(zone, {
asyncFlowTools,
chainHub,
localchain,
Expand All @@ -80,6 +80,7 @@ export const makeOrchestrationFacade = ({
vowTools,
zcf,
});
const makeOrchestrator = pickFacet(makeOrchestratorKit, 'orchestrator');

return {
/**
Expand Down
6 changes: 5 additions & 1 deletion packages/orchestration/src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { TimeMath } from '@agoric/time';
export const SECONDS_PER_MINUTE = 60n;
export const NANOSECONDS_PER_SECOND = 1_000_000_000n;

/** @param {Remote<TimerService>} timer */
/**
* XXX should this be durable? resumable?
*
* @param {Remote<TimerService>} timer
*/
export function makeTimestampHelper(timer) {
/** @type {TimerBrand | undefined} */
let brandCache;
Expand Down

0 comments on commit 5b3d56e

Please sign in to comment.