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

fix(orchestration): chainHub accepts zone #10129

Merged
merged 2 commits into from
Sep 24, 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
6 changes: 5 additions & 1 deletion packages/orchestration/src/examples/stake-bld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export const start = async (zcf, privateArgs, baggage) => {
);
const vowTools = prepareVowTools(zone.subZone('vows'));

const chainHub = makeChainHub(privateArgs.agoricNames, vowTools);
const chainHub = makeChainHub(
zone.subZone('chainHub'),
privateArgs.agoricNames,
vowTools,
);
const zoeTools = makeZoeTools(zcf, vowTools);

const { localchain, timerService } = privateArgs;
Expand Down
6 changes: 5 additions & 1 deletion packages/orchestration/src/examples/stake-ica.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export const start = async (zcf, privateArgs, baggage) => {

const vowTools = prepareVowTools(zone.subZone('vows'));

const chainHub = makeChainHub(agoricNames, vowTools);
const chainHub = makeChainHub(
zone.subZone('chainHub'),
agoricNames,
vowTools,
);

const makeCosmosOrchestrationAccount = prepareCosmosOrchestrationAccount(
zone,
Expand Down
8 changes: 4 additions & 4 deletions packages/orchestration/src/exos/chain-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { M } from '@endo/patterns';
import { BrandShape } from '@agoric/ertp/src/typeGuards.js';

import { VowShape } from '@agoric/vow';
import { makeHeapZone } from '@agoric/zone';
import { CosmosChainInfoShape, IBCConnectionInfoShape } from '../typeGuards.js';

/**
* @import {NameHub} from '@agoric/vats';
* @import {Vow, VowTools} from '@agoric/vow';
* @import {Zone} from '@agoric/zone';
* @import {CosmosAssetInfo, CosmosChainInfo, IBCConnectionInfo} from '../cosmos-api.js';
* @import {ChainInfo, KnownChains} from '../chain-info.js';
* @import {Denom} from '../orchestration-api.js';
Expand Down Expand Up @@ -171,18 +171,18 @@ const ChainHubI = M.interface('ChainHub', {
});

/**
* Make a new ChainHub in the zone (or in the heap if no zone is provided).
* Make a new ChainHub in the zone.
*
* The resulting object is an Exo singleton. It has no precious state. It's only
* state is a cache of queries to agoricNames and whatever info was provided in
* registration calls. When you need a newer version you can simply make a hub
* hub and repeat the registrations.
*
* @param {Zone} zone
* @param {Remote<NameHub>} agoricNames
* @param {VowTools} vowTools
*/
export const makeChainHub = (agoricNames, vowTools) => {
const zone = makeHeapZone();
export const makeChainHub = (zone, agoricNames, vowTools) => {
/** @type {MapStore<string, CosmosChainInfo>} */
const chainInfos = zone.mapStore('chainInfos', {
keyShape: M.string(),
Expand Down
9 changes: 7 additions & 2 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ export const startStakeAtom = async ({
const storageNode = await makeStorageNodeChild(chainStorage, VSTORAGE_PATH);
const marshaller = await E(board).getPublishingMarshaller();

const vt = prepareVowTools(makeHeapZone());
const chainHub = makeChainHub(await agoricNames, vt);
const zone = makeHeapZone();
const vt = prepareVowTools(zone.subZone('vows'));
const chainHub = makeChainHub(
zone.subZone('chainHub'),
await agoricNames,
vt,
);

const [_, cosmoshub, connectionInfo] = await vt.when(
chainHub.getChainsAndConnection('agoric', 'cosmoshub'),
Expand Down
9 changes: 7 additions & 2 deletions packages/orchestration/src/proposals/start-stakeOsmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ export const startStakeOsmo = async ({
const storageNode = await makeStorageNodeChild(chainStorage, VSTORAGE_PATH);
const marshaller = await E(board).getPublishingMarshaller();

const vt = prepareVowTools(makeHeapZone());
const chainHub = makeChainHub(await agoricNames, vt);
const zone = makeHeapZone();
const vt = prepareVowTools(zone.subZone('vows'));
const chainHub = makeChainHub(
zone.subZone('chainHub'),
await agoricNames,
vt,
);

const [_, osmosis, connectionInfo] = await vt.when(
chainHub.getChainsAndConnection('agoric', 'osmosis'),
Expand Down
4 changes: 3 additions & 1 deletion packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const provideOrchestration = (
asyncFlow: zone.subZone('asyncFlow'),
/** system names for orchestration implementation */
orchestration: zone.subZone('orchestration'),
/** system names for chainHub */
chainHub: zone.subZone('chainHub'),
/** system names for vows */
vows: zone.subZone('vows'),
/** contract-provided names, and subzones */
Expand All @@ -73,7 +75,7 @@ export const provideOrchestration = (

const vowTools = prepareVowTools(zones.vows);

const chainHub = makeChainHub(agoricNames, vowTools);
const chainHub = makeChainHub(zones.chainHub, agoricNames, vowTools);

const zoeTools = makeZoeTools(zcf, vowTools);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Generated by [AVA](https://avajs.dev).
flowForOutcomeVow: {},
unwrapMap: 'Alleged: weakMapStore',
},
chainHub: {
ChainHub_kindHandle: 'Alleged: kind',
ChainHub_singleton: 'Alleged: ChainHub',
brandDenom: {},
chainInfos: {},
connectionInfos: {},
denom: {},
},
contract: {
'ChainHub Admin_kindHandle': 'Alleged: kind',
'ChainHub Admin_singleton': 'Alleged: ChainHub Admin',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,79 @@ Generated by [AVA](https://avajs.dev).
flowForOutcomeVow: {},
unwrapMap: 'Alleged: weakMapStore',
},
chainHub: {
ChainHub_kindHandle: 'Alleged: kind',
ChainHub_singleton: 'Alleged: ChainHub',
brandDenom: {
'Alleged: BLD brand': 'ubld',
},
chainInfos: {
agoric: {
chainId: 'agoric-3',
icqEnabled: false,
stakingTokens: [
{
denom: 'ubld',
},
],
},
cosmoshub: {
chainId: 'cosmoshub-4',
icqEnabled: false,
stakingTokens: [
{
denom: 'uatom',
},
],
},
},
connectionInfos: {
'agoric-3_cosmoshub-4': {
client_id: '07-tendermint-6',
counterparty: {
client_id: '07-tendermint-927',
connection_id: 'connection-649',
},
id: 'connection-8',
state: 3,
transferChannel: {
channelId: 'channel-5',
counterPartyChannelId: 'channel-405',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
'cosmoshub-4_osmosis-1': {
client_id: '07-tendermint-259',
counterparty: {
client_id: '07-tendermint-1',
connection_id: 'connection-1',
},
id: 'connection-257',
state: 3,
transferChannel: {
channelId: 'channel-141',
counterPartyChannelId: 'channel-0',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
},
denom: {
ubld: {
baseDenom: 'ubld',
baseName: 'agoric',
brand: Object @Alleged: BLD brand {},
chainName: 'agoric',
},
},
},
contract: {
'ChainHub Admin_kindHandle': 'Alleged: kind',
'ChainHub Admin_singleton': 'Alleged: ChainHub Admin',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,97 @@ Generated by [AVA](https://avajs.dev).
flowForOutcomeVow: {},
unwrapMap: 'Alleged: weakMapStore',
},
chainHub: {
ChainHub_kindHandle: 'Alleged: kind',
ChainHub_singleton: 'Alleged: ChainHub',
brandDenom: {},
chainInfos: {
agoric: {
chainId: 'agoric-3',
icqEnabled: false,
stakingTokens: [
{
denom: 'ubld',
},
],
},
osmosis: {
chainId: 'osmosis-1',
icqEnabled: true,
stakingTokens: [
{
denom: 'uosmo',
},
],
},
stride: {
chainId: 'stride-1',
icqEnabled: false,
stakingTokens: [
{
denom: 'ustrd',
},
],
},
},
connectionInfos: {
'agoric-3_osmosis-1': {
client_id: '07-tendermint-1',
counterparty: {
client_id: '07-tendermint-2109',
connection_id: 'connection-1649',
},
id: 'connection-1',
state: 3,
transferChannel: {
channelId: 'channel-1',
counterPartyChannelId: 'channel-320',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
'agoric-3_stride-1': {
client_id: '07-tendermint-74',
counterparty: {
client_id: '07-tendermint-129',
connection_id: 'connection-118',
},
id: 'connection-68',
state: 3,
transferChannel: {
channelId: 'channel-59',
counterPartyChannelId: 'channel-148',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
'osmosis-1_stride-1': {
client_id: '07-tendermint-2119',
counterparty: {
client_id: '07-tendermint-1',
connection_id: 'connection-2',
},
id: 'connection-1657',
state: 3,
transferChannel: {
channelId: 'channel-326',
counterPartyChannelId: 'channel-5',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
},
denom: {},
},
contract: {
orchestration: {
unbondAndTransfer: {
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/orchestration/test/exos/chain-hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const connection = {
// fresh state for each test
const setup = () => {
const zone = provideDurableZone('root');
const vt = prepareSwingsetVowTools(zone);
const vt = prepareSwingsetVowTools(zone.subZone('vows'));
const { nameHub, nameAdmin } = makeNameHubKit();
const chainHub = makeChainHub(nameHub, vt);
const chainHub = makeChainHub(zone.subZone('chainHub'), nameHub, vt);

return { chainHub, nameAdmin, vt };
};
Expand Down
Loading
Loading