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(orch): optional storage node #10718

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 1 addition & 5 deletions packages/boot/test/fast-usdc/fast-usdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,7 @@ test.serial('writes account addresses to vstorage', async t => {
showValue: JSON.parse,
pattern: /published\.fastUsdc\.(feeConfig|feedPolicy|poolMetrics)/,
replacement: '',
note: `Under "published", the "fastUsdc" node is delegated to FastUSDC contract.
Note: published.fastUsdc.[settleAcctAddr], published.fastUsdc.[poolAcctAddr],
and published.fastUsdc.[intermediateAcctAddr] are published by @agoric/orchestration
via 'withOrchestration' and (local|cosmos)-orch-account-kit.js.
`,
owner: 'FastUSDC contract',
};

await documentStorageSchema(t, storage, doc);
Expand Down
25 changes: 0 additions & 25 deletions packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ Generated by [AVA](https://avajs.dev).
## writes account addresses to vstorage

> Under "published", the "fastUsdc" node is delegated to FastUSDC contract.
> Note: published.fastUsdc.[settleAcctAddr], published.fastUsdc.[poolAcctAddr],
> and published.fastUsdc.[intermediateAcctAddr] are published by @agoric/orchestration
> via 'withOrchestration' and (local|cosmos)-orch-account-kit.js.
>
> The example below illustrates the schema of the data published there.
>
> See also board marshalling conventions (_to appear_).
Expand All @@ -136,27 +132,6 @@ Generated by [AVA](https://avajs.dev).
settlementAccount: 'agoric1fakeLCAAddress1',
},
],
[
'published.fastUsdc.agoric1fakeLCAAddress',
{
body: '#""',
slots: [],
},
],
[
'published.fastUsdc.agoric1fakeLCAAddress1',
{
body: '#""',
slots: [],
},
],
[
'published.fastUsdc.noble1test',
{
body: '#{"localAddress":"/ibc-port/icacontroller-1/ordered/{\\"version\\":\\"ics27-1\\",\\"controllerConnectionId\\":\\"connection-72\\",\\"hostConnectionId\\":\\"connection-40\\",\\"address\\":\\"noble1test\\",\\"encoding\\":\\"proto3\\",\\"txType\\":\\"sdk_multi_msg\\"}/ibc-channel/channel-1","remoteAddress":"/ibc-hop/connection-72/ibc-port/icahost/ordered/{\\"version\\":\\"ics27-1\\",\\"controllerConnectionId\\":\\"connection-72\\",\\"hostConnectionId\\":\\"connection-40\\",\\"address\\":\\"noble1test\\",\\"encoding\\":\\"proto3\\",\\"txType\\":\\"sdk_multi_msg\\"}/ibc-channel/channel-1"}',
slots: [],
},
],
]

## makes usdc advance
Expand Down
Binary file modified packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,6 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
};
harden(contract);

export const start = withOrchestration(contract);
export const start = withOrchestration(contract, { disableStorageNode: true });
harden(start);
/** @typedef {typeof start} FastUsdcSF */
43 changes: 26 additions & 17 deletions packages/orchestration/src/exos/cosmos-orchestration-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const { Vow$ } = NetworkShape; // TODO #9611
/**
* @private
* @typedef {{
* topicKit: RecorderKit<ComosOrchestrationAccountNotification>;
* topicKit: RecorderKit<ComosOrchestrationAccountNotification> | undefined;
* account: IcaAccount;
* chainAddress: ChainAddress;
* localAddress: LocalIbcAddress;
Expand Down Expand Up @@ -291,26 +291,28 @@ export const prepareCosmosOrchestrationAccountKit = (
* @param {RemoteIbcAddress} info.remoteAddress
* @param {object} io
* @param {IcaAccount} io.account
* @param {Remote<StorageNode>} io.storageNode
* @param {Remote<StorageNode> | undefined} io.storageNode
* @param {ICQConnection | undefined} io.icqConnection
* @param {Remote<TimerService>} io.timer
* @returns {State}
*/
({ chainAddress, localAddress, remoteAddress }, io) => {
const { storageNode } = io;
// must be the fully synchronous maker because the kit is held in durable state
const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
// TODO determine what goes in vstorage https://github.com/Agoric/agoric-sdk/issues/9066
// XXX consider parsing local/remoteAddr to portId, channelId, counterpartyPortId, counterpartyChannelId, connectionId, counterpartyConnectionId
// FIXME these values will not update if IcaAccount gets new values after reopening.
// consider having IcaAccount responsible for the owning the writer. It might choose to share it with COA.
void E(topicKit.recorder).write(
/** @type {CosmosOrchestrationAccountStorageState} */ ({
localAddress,
remoteAddress,
}),
);

let topicKit;
if (storageNode) {
// must be the fully synchronous maker because the kit is held in durable state
topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
// TODO determine what goes in vstorage https://github.com/Agoric/agoric-sdk/issues/9066
// XXX consider parsing local/remoteAddr to portId, channelId, counterpartyPortId, counterpartyChannelId, connectionId, counterpartyConnectionId
// FIXME these values will not update if IcaAccount gets new values after reopening.
// consider having IcaAccount responsible for the owning the writer. It might choose to share it with COA.
void E(topicKit.recorder).write(
/** @type {CosmosOrchestrationAccountStorageState} */ ({
localAddress,
remoteAddress,
}),
);
}
const { account, icqConnection, timer } = io;
return {
account,
Expand All @@ -333,6 +335,8 @@ export const prepareCosmosOrchestrationAccountKit = (
return account;
},
getUpdater() {
if (!this.state.topicKit)
throw Fail`No topicKit; storageNode not provided`;
return this.state.topicKit.recorder;
},
/**
Expand Down Expand Up @@ -731,6 +735,7 @@ export const prepareCosmosOrchestrationAccountKit = (
return asVow(async () => {
await null;
const { topicKit } = this.state;
if (!topicKit) throw Fail`No topicKit; storageNode not provided`;
return harden({
account: {
description: PUBLIC_TOPICS.account[0],
Expand Down Expand Up @@ -1005,7 +1010,9 @@ export const prepareCosmosOrchestrationAccountKit = (
return watch(results, this.facets.delegationsQueryWatcher);
});
},
/** @type {HostOf<StakingAccountQueries['getUnbondingDelegation']>} */
/**
* @type {HostOf<StakingAccountQueries['getUnbondingDelegation']>}
*/
getUnbondingDelegation(validator) {
return asVow(() => {
trace('getUnbondingDelegation', validator);
Expand All @@ -1024,7 +1031,9 @@ export const prepareCosmosOrchestrationAccountKit = (
return watch(results, this.facets.unbondingDelegationQueryWatcher);
});
},
/** @type {HostOf<StakingAccountQueries['getUnbondingDelegations']>} */
/**
* @type {HostOf<StakingAccountQueries['getUnbondingDelegations']>}
*/
getUnbondingDelegations() {
return asVow(() => {
trace('getUnbondingDelegations');
Expand Down
16 changes: 9 additions & 7 deletions packages/orchestration/src/exos/local-chain-facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { chainFacadeMethods, TypedJsonShape } from '../typeGuards.js';
* @typedef {{
* makeLocalOrchestrationAccountKit: MakeLocalOrchestrationAccountKit;
* orchestration: Remote<CosmosInterchainService>;
* storageNode: Remote<StorageNode>;
* storageNode: Remote<StorageNode> | undefined;
* agoricNames: Remote<NameHub>;
* timer: Remote<TimerService>;
* localchain: Remote<LocalChain>;
Expand Down Expand Up @@ -79,7 +79,7 @@ const prepareLocalChainFacadeKit = (
.returns(VowShape),
}),
makeChildNodeWatcher: M.interface('makeChildNodeWatcher', {
onFulfilled: M.call(M.remotable())
onFulfilled: M.call(M.or(M.remotable(), M.undefined()))
.optional({ account: M.remotable(), address: M.string() }) // empty context
.returns(M.remotable()),
}),
Expand Down Expand Up @@ -145,11 +145,13 @@ const prepareLocalChainFacadeKit = (
* @param {[LocalChainAccount, ChainAddress['value']]} results
*/
onFulfilled([account, address]) {
return watch(
E(storageNode).makeChildNode(address),
this.facets.makeChildNodeWatcher,
{ account, address },
);
const optionalStorageNode = storageNode
? E(storageNode).makeChildNode(address)
: undefined;
return watch(optionalStorageNode, this.facets.makeChildNodeWatcher, {
account,
address,
});
},
},
makeChildNodeWatcher: {
Expand Down
17 changes: 11 additions & 6 deletions packages/orchestration/src/exos/local-orchestration-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const EVow$ = shape => M.or(Vow$(shape), M.promise(/* shape */));
/**
* @private
* @typedef {{
* topicKit: RecorderKit<LocalChainAccountNotification>;
* topicKit: RecorderKit<LocalChainAccountNotification> | undefined;
* packetTools: PacketTools;
* account: LocalChainAccount;
* address: ChainAddress;
Expand Down Expand Up @@ -181,14 +181,18 @@ export const prepareLocalOrchestrationAccountKit = (
* @param {object} initState
* @param {LocalChainAccount} initState.account
* @param {ChainAddress} initState.address
* @param {Remote<StorageNode>} initState.storageNode
* @param {Remote<StorageNode> | undefined} initState.storageNode
* @returns {State}
*/
({ account, address, storageNode }) => {
// must be the fully synchronous maker because the kit is held in durable state
const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
// TODO determine what goes in vstorage https://github.com/Agoric/agoric-sdk/issues/9066
void E(topicKit.recorder).write('');
let topicKit;
if (storageNode) {
// must be the fully synchronous maker because the kit is held in durable state
topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
// TODO determine what goes in vstorage https://github.com/Agoric/agoric-sdk/issues/9066
void E(topicKit.recorder).write('');
}

const packetTools = makePacketTools(account);

return { account, address, topicKit, packetTools };
Expand Down Expand Up @@ -548,6 +552,7 @@ export const prepareLocalOrchestrationAccountKit = (
return asVow(async () => {
await null;
const { topicKit } = this.state;
if (!topicKit) throw Fail`No topicKit; storageNode not provided`;
return harden({
account: {
description: PUBLIC_TOPICS.account[0],
Expand Down
20 changes: 12 additions & 8 deletions packages/orchestration/src/exos/remote-chain-facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const trace = makeTracer('RemoteChainFacade');
* typeof prepareCosmosOrchestrationAccount
* >;
* orchestration: Remote<CosmosInterchainService>;
* storageNode: Remote<StorageNode>;
* storageNode: Remote<StorageNode> | undefined;
* timer: Remote<TimerService>;
* vowTools: VowTools;
* }} RemoteChainFacadePowers
Expand Down Expand Up @@ -94,7 +94,7 @@ const prepareRemoteChainFacadeKit = (
).returns(VowShape),
}),
makeChildNodeWatcher: M.interface('makeChildNodeWatcher', {
onFulfilled: M.call(M.remotable(), {
onFulfilled: M.call(M.or(M.remotable(), M.undefined()), {
account: M.remotable(),
chainAddress: ChainAddressShape,
localAddress: M.string(),
Expand Down Expand Up @@ -210,16 +210,20 @@ const prepareRemoteChainFacadeKit = (
* @param {IcaAccount} account
*/
onFulfilled([chainAddress, localAddress, remoteAddress], account) {
return watch(
E(storageNode).makeChildNode(chainAddress.value),
this.facets.makeChildNodeWatcher,
{ account, chainAddress, localAddress, remoteAddress },
);
const optionalStorageNode = storageNode
? E(storageNode).makeChildNode(chainAddress.value)
: undefined;
return watch(optionalStorageNode, this.facets.makeChildNodeWatcher, {
account,
chainAddress,
localAddress,
remoteAddress,
});
},
},
makeChildNodeWatcher: {
/**
* @param {Remote<StorageNode>} childNode
* @param {Remote<StorageNode> | undefined} childNode
* @param {{
* account: IcaAccount;
* chainAddress: ChainAddress;
Expand Down
20 changes: 17 additions & 3 deletions packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import { makeZcfTools } from './zcf-tools.js';
* }} OrchestrationPowers
*/

/**
* @typedef {{
* disableStorageNode?: boolean;
* }} WithOrchestrationOpts
*/

/**
* Helper that a contract start function can use to set up the objects needed
* for orchestration.
Expand All @@ -42,13 +48,15 @@ import { makeZcfTools } from './zcf-tools.js';
* @param {Baggage} baggage
* @param {OrchestrationPowers} remotePowers
* @param {Marshaller} marshaller
* @param {WithOrchestrationOpts} [opts]
* @internal
*/
export const provideOrchestration = (
zcf,
baggage,
remotePowers,
marshaller,
opts,
) => {
// separate zones
const zones = (() => {
Expand Down Expand Up @@ -77,6 +85,10 @@ export const provideOrchestration = (

const zcfTools = makeZcfTools(zcf, vowTools);

const storageNode = opts?.disableStorageNode
? undefined
: remotePowers.storageNode;

const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller);
const makeLocalOrchestrationAccountKit = prepareLocalOrchestrationAccountKit(
zones.orchestration,
Expand Down Expand Up @@ -109,7 +121,7 @@ export const provideOrchestration = (
const makeRemoteChainFacade = prepareRemoteChainFacade(zones.orchestration, {
makeCosmosOrchestrationAccount,
orchestration: remotePowers.orchestrationService,
storageNode: remotePowers.storageNode,
storageNode,
timer: remotePowers.timerService,
vowTools,
});
Expand All @@ -118,7 +130,7 @@ export const provideOrchestration = (
makeLocalOrchestrationAccountKit,
localchain: remotePowers.localchain,
// FIXME what path?
storageNode: remotePowers.storageNode,
storageNode,
agoricNames,
orchestration: remotePowers.orchestrationService,
timer: remotePowers.timerService,
Expand Down Expand Up @@ -199,16 +211,18 @@ harden(provideOrchestration);
* zone: Zone,
* tools: OrchestrationTools,
* ) => Promise<R>} contractFn
* @param {WithOrchestrationOpts} [opts]
* @returns {(zcf: ZCF<CT>, privateArgs: PA, baggage: Baggage) => Promise<R>} a
* Zoe start function
*/
export const withOrchestration =
contractFn => async (zcf, privateArgs, baggage) => {
(contractFn, opts) => async (zcf, privateArgs, baggage) => {
const { zone, ...tools } = provideOrchestration(
zcf,
baggage,
privateArgs,
privateArgs.marshaller,
opts,
);
return contractFn(zcf, privateArgs, zone, tools);
};
Expand Down
Loading