Skip to content

Commit

Permalink
9063 chain lookup (#9459)
Browse files Browse the repository at this point in the history
refs: #9063

## Description

Progress on #9063, looking up primary chain info by chainID. Modeled
after https://github.com/Agoric/agoric-sdk/tree/dc-unk-chain-misc

Doesn't yet handle IBC connection info (`hostConnectionId`,
`controllerConnectionId`). I propose this is worth landing without that
but invite reviewers to weigh in with requests.

### Security Considerations

<!-- Does this change introduce new assumptions or dependencies that, if
violated, could introduce security vulnerabilities? How does this PR
change the boundaries between mutually-suspicious components? What new
authorities are introduced by this change, perhaps by new API calls?
-->

### Scaling Considerations

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations

<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations

<!-- What aspects of this PR are relevant to upgrading live production
systems, and how should they be addressed? -->
  • Loading branch information
mergify[bot] authored Jun 6, 2024
2 parents 95c7239 + 9fdd77f commit f6d77a3
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 66 deletions.
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
*
* 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,
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

0 comments on commit f6d77a3

Please sign in to comment.