Skip to content
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

feat(orchestrator): return unwrapped vows #9537

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 74 additions & 27 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,16 +10,18 @@ import {
BrandInfoShape,
DenomAmountShape,
} from '../typeGuards.js';
import { getChainsAndConnection } from './chain-hub.js';

/**
* @import {Zone} from '@agoric/base-zone';
* @import {ChainHub} from './chain-hub.js';
* @import {AsyncFlowTools} from '@agoric/async-flow';
* @import {Vow} from '@agoric/vow';
* @import {Vow, VowTools} from '@agoric/vow';
* @import {TimerService} from '@agoric/time';
* @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 @@ -50,44 +52,89 @@ export const OrchestratorI = M.interface('Orchestrator', {
* orchestrationService: Remote<OrchestrationService>;
* storageNode: Remote<StorageNode>;
* timerService: Remote<TimerService>;
* vowTools: VowTools;
* zcf: ZCF;
* }} powers
*/
export const prepareOrchestrator = (
export const prepareOrchestratorKit = (
zone,
{ chainHub, localchain, makeLocalChainFacade, makeRemoteChainFacade },
{
chainHub,
localchain,
makeLocalChainFacade,
makeRemoteChainFacade,
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);
10 changes: 7 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 @@ -34,6 +34,7 @@ import { prepareOrchestrator } from './exos/orchestrator.js';
* makeCosmosOrchestrationAccount: any;
* makeLocalChainFacade: MakeLocalChainFacade;
* makeRemoteChainFacade: MakeRemoteChainFacade;
* vowTools: VowTools;
* asyncFlowTools: AsyncFlowTools;
* }} powers
*/
Expand All @@ -49,6 +50,7 @@ export const makeOrchestrationFacade = ({
makeRecorderKit,
makeLocalChainFacade,
makeRemoteChainFacade,
vowTools,
asyncFlowTools,
}) => {
(zone &&
Expand All @@ -65,7 +67,7 @@ export const makeOrchestrationFacade = ({
asyncFlowTools) ||
Fail`params missing`;

const makeOrchestrator = prepareOrchestrator(zone, {
const makeOrchestratorKit = prepareOrchestratorKit(zone, {
asyncFlowTools,
chainHub,
localchain,
Expand All @@ -75,8 +77,10 @@ export const makeOrchestrationFacade = ({
orchestrationService,
storageNode,
timerService,
vowTools,
zcf,
});
const makeOrchestrator = pickFacet(makeOrchestratorKit, 'orchestrator');

return {
/**
Expand Down
1 change: 1 addition & 0 deletions packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const provideOrchestration = (
makeLocalChainFacade,
makeRemoteChainFacade,
asyncFlowTools,
vowTools,
...remotePowers,
});
return { ...facade, chainHub, zone };
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
Loading