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

9063 chain lookup #9459

Merged
merged 4 commits into from
Jun 6, 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
8 changes: 0 additions & 8 deletions packages/orchestration/src/chain-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const wellKnownChainInfo =
icqEnabled: true,
pfmEnabled: true,
ibcHooksEnabled: true,
allowedMessages: [],
allowedQueries: [],
stakingTokens: [{ denom: 'ustride' }],
},
cosmos: {
Expand All @@ -30,8 +28,6 @@ export const wellKnownChainInfo =
icqEnabled: true,
pfmEnabled: true,
ibcHooksEnabled: true,
allowedMessages: [],
allowedQueries: [],
stakingTokens: [{ denom: 'uatom' }],
},
celestia: {
Expand All @@ -41,8 +37,6 @@ export const wellKnownChainInfo =
icqEnabled: true,
pfmEnabled: true,
ibcHooksEnabled: true,
allowedMessages: [],
allowedQueries: [],
stakingTokens: [{ denom: 'utia' }],
},
osmosis: {
Expand All @@ -52,8 +46,6 @@ export const wellKnownChainInfo =
icqEnabled: true,
pfmEnabled: true,
ibcHooksEnabled: true,
allowedMessages: [],
allowedQueries: [],
stakingTokens: [{ denom: 'uosmo' }],
},
})
Expand Down
5 changes: 0 additions & 5 deletions packages/orchestration/src/cosmos-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ export type CosmosChainInfo = {
icqEnabled: boolean;
pfmEnabled: boolean;
ibcHooksEnabled: boolean;
/**
*
*/
allowedMessages: TypeUrl[];
allowedQueries: TypeUrl[];

/**
* cf https://github.com/cosmos/chain-registry/blob/master/chain.schema.json#L117
Expand Down
22 changes: 15 additions & 7 deletions packages/orchestration/src/examples/swapExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import { orcUtils } from '../utils/orc.js';
* @import {Remote} from '@agoric/internal';
* @import {OrchestrationService} from '../service.js';
* @import {Baggage} from '@agoric/vat-data'
* @import {Zone} from '@agoric/zone';
* @import {NameHub} from '@agoric/vats';
*/

/** @type {ContractMeta} */
export const meta = {
privateArgsShape: {
agoricNames: M.remotable('agoricNames'),
localchain: M.remotable('localchain'),
orchestrationService: M.or(M.remotable('orchestration'), null),
storageNode: StorageNodeShape,
Expand All @@ -42,6 +43,7 @@ export const makeNatAmountShape = (brand, min) =>
/**
* @param {ZCF} zcf
* @param {{
* agoricNames: Remote<NameHub>;
* localchain: Remote<LocalChain>;
* orchestrationService: Remote<OrchestrationService>;
* storageNode: Remote<StorageNode>;
Expand All @@ -54,16 +56,22 @@ export const start = async (zcf, privateArgs, baggage) => {

const zone = makeDurableZone(baggage);

const { localchain, orchestrationService, storageNode, timerService } =
privateArgs;
const {
agoricNames,
localchain,
orchestrationService,
storageNode,
timerService,
} = privateArgs;

const { orchestrate } = makeOrchestrationFacade({
zone,
timerService,
zcf,
agoricNames,
localchain,
storageNode,
orchestrationService,
storageNode,
timerService,
zcf,
zone,
});

/** deprecated historical example */
Expand Down
18 changes: 13 additions & 5 deletions packages/orchestration/src/examples/unbondExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { makeOrchestrationFacade } from '../facade.js';
* @import {TimerService} from '@agoric/time';
* @import {Baggage} from '@agoric/vat-data';
* @import {LocalChain} from '@agoric/vats/src/localchain.js';
* @import {NameHub} from '@agoric/vats';
* @import {Remote} from '@agoric/internal';
* @import {OrchestrationService} from '../service.js';
*/

/**
* @param {ZCF} zcf
* @param {{
* agoricNames: Remote<NameHub>;
* localchain: Remote<LocalChain>;
* orchestrationService: Remote<OrchestrationService>;
* storageNode: Remote<StorageNode>;
Expand All @@ -23,17 +25,23 @@ import { makeOrchestrationFacade } from '../facade.js';
* @param {Baggage} baggage
*/
export const start = async (zcf, privateArgs, baggage) => {
const { localchain, orchestrationService, storageNode, timerService } =
privateArgs;
const {
agoricNames,
localchain,
orchestrationService,
storageNode,
timerService,
} = privateArgs;
const zone = makeDurableZone(baggage);

const { orchestrate } = makeOrchestrationFacade({
agoricNames,
localchain,
zone,
orchestrationService,
storageNode,
timerService,
zcf,
storageNode,
orchestrationService,
zone,
});

/** @type {OfferHandler} */
Expand Down
33 changes: 24 additions & 9 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import { makeScalarBigMapStore } from '@agoric/vat-data';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { wellKnownChainInfo } from './chain-info.js';
import { prepareCosmosOrchestrationAccount } from './exos/cosmosOrchestrationAccount.js';
import { CosmosChainInfoShape } from './typeGuards.js';

/**
* @import {NameHub} from '@agoric/vats';
* @import {Zone} from '@agoric/zone';
* @import {TimerService} from '@agoric/time';
* @import {LocalChain} from '@agoric/vats/src/localchain.js';
Expand All @@ -19,12 +19,14 @@ import { CosmosChainInfoShape } from './typeGuards.js';
/** @type {any} */
const anyVal = null;

// TODO define key hierarchy in shared constants
/** agoricNames key for ChainInfo hub */
export const CHAIN_KEY = 'chain';

// FIXME look up real values
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9063
const mockLocalChainInfo = {
allegedName: 'agoric',
allowedMessages: [],
allowedQueries: [],
chainId: 'agoriclocal',
connections: anyVal,
ibcHooksEnabled: true,
Expand Down Expand Up @@ -155,6 +157,7 @@ const makeRemoteChainFacade = (
* storageNode: Remote<StorageNode>;
* orchestrationService: Remote<OrchestrationService>;
* localchain: Remote<LocalChain>;
* agoricNames: Remote<NameHub>;
* }} powers
*/
export const makeOrchestrationFacade = ({
Expand All @@ -164,6 +167,7 @@ export const makeOrchestrationFacade = ({
storageNode,
orchestrationService,
localchain,
agoricNames,
}) => {
console.log('makeOrchestrationFacade got', {
zone,
Expand All @@ -178,6 +182,22 @@ export const makeOrchestrationFacade = ({
valueShape: CosmosChainInfoShape,
});

/**
* @param {string} name
* @returns {Promise<CosmosChainInfo>}
*/
const getChainInfo = async name => {
// Either from registerChain or memoized remote lookup()
if (chainInfos.has(name)) {
return chainInfos.get(name);
}

const chainInfo = await E(agoricNames).lookup(CHAIN_KEY, name);
assert(chainInfo, `unknown chain ${name}`);
chainInfos.init(name, chainInfo);
return chainInfo;
};

return {
/**
* Register a new chain in a heap store. The name will override a name in
Expand Down Expand Up @@ -211,12 +231,7 @@ export const makeOrchestrationFacade = ({
return makeLocalChainFacade(localchain);
}

// TODO look up well known realistically https://github.com/Agoric/agoric-sdk/issues/9063
const chainInfo = chainInfos.has(name)
? chainInfos.get(name)
: // @ts-expect-error may be undefined
wellKnownChainInfo[name];
assert(chainInfo, `unknown chain ${name}`);
const chainInfo = await getChainInfo(name);

return makeRemoteChainFacade(chainInfo, {
orchestration: orchestrationService,
Expand Down
2 changes: 0 additions & 2 deletions packages/orchestration/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,5 @@ export const CosmosChainInfoShape = M.splitRecord(
icqEnabled: M.boolean(),
pfmEnabled: M.boolean(),
ibcHooksEnabled: M.boolean(),
allowedMessages: M.arrayOf(M.string()),
allowedQueries: M.arrayOf(M.string()),
},
);
11 changes: 7 additions & 4 deletions packages/orchestration/src/utils/mockChainInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* @file Mocked Chain Info object until #8879
* @file Mocked Chain Info object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this out of src/ yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a try but will save it for a next PR because it affects the a3p test too.

*
* Until https://github.com/Agoric/agoric-sdk/issues/8879
*
* Generated using
* https://github.com/Agoric/agoric-sdk/compare/pc/ibc-chain-info
*/
import {
Order,
Expand Down Expand Up @@ -67,9 +72,7 @@ const connectionEntries = harden({
},
});

/**
* @returns {Pick<CosmosChainInfo, 'connections' | 'chainId'>}
*/
/** @returns {Pick<CosmosChainInfo, 'connections' | 'chainId'>} */
export const prepareMockChainInfo = () => {
return harden({
chainId: 'agoriclocal',
Expand Down
8 changes: 2 additions & 6 deletions packages/orchestration/test/examples/swapExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('start', async t => {
const {
bootstrap,
brands: { ist },
commonPrivateArgs,
utils,
} = await commonSetup(t);

Expand All @@ -27,12 +28,7 @@ test('start', async t => {
installation,
{ Stable: ist.issuer },
{},
{
localchain: bootstrap.localchain,
orchestrationService: bootstrap.orchestration,
storageNode: bootstrap.storage.rootNode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we been passing the whole storage root to the contract? that seems weird.

(not a request for change)

timerService: bootstrap.timer,
},
commonPrivateArgs,
);

const inv = E(publicFacet).makeSwapAndStakeInvitation();
Expand Down
9 changes: 2 additions & 7 deletions packages/orchestration/test/examples/unbondExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type StartFn =

test('start', async t => {
const {
bootstrap,
brands: { ist },
commonPrivateArgs,
} = await commonSetup(t);

const { zoe, bundleAndInstall } = await setUpZoeForTest();
Expand All @@ -25,12 +25,7 @@ test('start', async t => {
installation,
{ Stable: ist.issuer },
{},
{
localchain: bootstrap.localchain,
orchestrationService: bootstrap.orchestration,
storageNode: bootstrap.storage.rootNode,
timerService: bootstrap.timer,
},
commonPrivateArgs,
);

const inv = E(publicFacet).makeUnbondAndLiquidStakeInvitation();
Expand Down
18 changes: 5 additions & 13 deletions packages/orchestration/test/facade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ export const mockChainInfo: CosmosChainInfo = harden({
icqEnabled: false,
pfmEnabled: false,
ibcHooksEnabled: false,
allowedMessages: [],
allowedQueries: [],
stakingTokens: [{ denom: 'umock' }],
});

test('chain info', async t => {
const { bootstrap } = await commonSetup(t);
const { bootstrap, facadeServices } = await commonSetup(t);

const zone = bootstrap.rootZone;

const { zcf } = await setupZCFTest();

const { registerChain, orchestrate } = makeOrchestrationFacade({
localchain: bootstrap.localchain,
orchestrationService: bootstrap.orchestration,
...facadeServices,
storageNode: bootstrap.storage.rootNode,
timerService: bootstrap.timer,
zcf,
zone,
});
Expand All @@ -47,7 +43,7 @@ test('chain info', async t => {
});

test('contract upgrade', async t => {
const { bootstrap } = await commonSetup(t);
const { bootstrap, facadeServices } = await commonSetup(t);

const zone = bootstrap.rootZone;

Expand All @@ -56,10 +52,8 @@ test('contract upgrade', async t => {
// Register once
{
const { registerChain } = makeOrchestrationFacade({
localchain: bootstrap.localchain,
orchestrationService: bootstrap.orchestration,
...facadeServices,
storageNode: bootstrap.storage.rootNode,
timerService: bootstrap.timer,
zcf,
zone,
});
Expand All @@ -74,10 +68,8 @@ test('contract upgrade', async t => {
// Simulate running again in a new incarnation with the same zone
{
const { registerChain } = makeOrchestrationFacade({
localchain: bootstrap.localchain,
orchestrationService: bootstrap.orchestration,
...facadeServices,
storageNode: bootstrap.storage.rootNode,
timerService: bootstrap.timer,
zcf,
zone,
});
Expand Down
Loading
Loading