From abaf1296b75819500a614c06f64ed1c980d79b40 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 12:49:51 -0700 Subject: [PATCH 1/4] chore: remove allowed{Messages,Queries} from chain info no value in runtime --- packages/orchestration/src/chain-info.js | 8 -------- packages/orchestration/src/cosmos-api.ts | 5 ----- packages/orchestration/src/facade.js | 2 -- packages/orchestration/src/typeGuards.js | 2 -- packages/orchestration/test/facade.test.ts | 2 -- 5 files changed, 19 deletions(-) diff --git a/packages/orchestration/src/chain-info.js b/packages/orchestration/src/chain-info.js index fe7352ca004..5629e52633a 100644 --- a/packages/orchestration/src/chain-info.js +++ b/packages/orchestration/src/chain-info.js @@ -19,8 +19,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'ustride' }], }, cosmos: { @@ -30,8 +28,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'uatom' }], }, celestia: { @@ -41,8 +37,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'utia' }], }, osmosis: { @@ -52,8 +46,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'uosmo' }], }, }) diff --git a/packages/orchestration/src/cosmos-api.ts b/packages/orchestration/src/cosmos-api.ts index 04cebb79777..5306de19b60 100644 --- a/packages/orchestration/src/cosmos-api.ts +++ b/packages/orchestration/src/cosmos-api.ts @@ -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 diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index b9ea70bfeea..703639ebf86 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -23,8 +23,6 @@ const anyVal = null; // UNTIL https://github.com/Agoric/agoric-sdk/issues/9063 const mockLocalChainInfo = { allegedName: 'agoric', - allowedMessages: [], - allowedQueries: [], chainId: 'agoriclocal', connections: anyVal, ibcHooksEnabled: true, diff --git a/packages/orchestration/src/typeGuards.js b/packages/orchestration/src/typeGuards.js index 9ba142f57ec..c67b08fba39 100644 --- a/packages/orchestration/src/typeGuards.js +++ b/packages/orchestration/src/typeGuards.js @@ -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()), }, ); diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 10fdfa1c162..4f2f8c5392a 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -15,8 +15,6 @@ export const mockChainInfo: CosmosChainInfo = harden({ icqEnabled: false, pfmEnabled: false, ibcHooksEnabled: false, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'umock' }], }); From 75bb7dfbe2adabff3ee64713d9d6558788bbb8bf Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 15:18:39 -0700 Subject: [PATCH 2/4] feat: chainInfo from agoricNames --- .../src/examples/swapExample.contract.js | 22 ++++++++----- .../src/examples/unbondExample.contract.js | 18 ++++++++--- packages/orchestration/src/facade.js | 31 ++++++++++++++----- .../orchestration/src/utils/mockChainInfo.js | 11 ++++--- .../test/examples/swapExample.test.ts | 1 + .../test/examples/unbondExample.test.ts | 1 + packages/orchestration/test/facade.test.ts | 3 ++ packages/orchestration/test/supports.ts | 18 +++++++++++ 8 files changed, 82 insertions(+), 23 deletions(-) diff --git a/packages/orchestration/src/examples/swapExample.contract.js b/packages/orchestration/src/examples/swapExample.contract.js index 8fdb4ac49de..448663f7eb1 100644 --- a/packages/orchestration/src/examples/swapExample.contract.js +++ b/packages/orchestration/src/examples/swapExample.contract.js @@ -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, @@ -42,6 +43,7 @@ export const makeNatAmountShape = (brand, min) => /** * @param {ZCF} zcf * @param {{ + * agoricNames: Remote; * localchain: Remote; * orchestrationService: Remote; * storageNode: Remote; @@ -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 */ diff --git a/packages/orchestration/src/examples/unbondExample.contract.js b/packages/orchestration/src/examples/unbondExample.contract.js index 48a2a1979d5..70ae1696114 100644 --- a/packages/orchestration/src/examples/unbondExample.contract.js +++ b/packages/orchestration/src/examples/unbondExample.contract.js @@ -8,6 +8,7 @@ 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'; */ @@ -15,6 +16,7 @@ import { makeOrchestrationFacade } from '../facade.js'; /** * @param {ZCF} zcf * @param {{ + * agoricNames: Remote; * localchain: Remote; * orchestrationService: Remote; * storageNode: Remote; @@ -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} */ diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 703639ebf86..1f73ae93120 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -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'; @@ -19,6 +19,10 @@ 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 = { @@ -153,6 +157,7 @@ const makeRemoteChainFacade = ( * storageNode: Remote; * orchestrationService: Remote; * localchain: Remote; + * agoricNames: Remote; * }} powers */ export const makeOrchestrationFacade = ({ @@ -162,6 +167,7 @@ export const makeOrchestrationFacade = ({ storageNode, orchestrationService, localchain, + agoricNames, }) => { console.log('makeOrchestrationFacade got', { zone, @@ -176,6 +182,22 @@ export const makeOrchestrationFacade = ({ valueShape: CosmosChainInfoShape, }); + /** + * @param {string} name + * @returns {Promise} + */ + 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 @@ -209,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, diff --git a/packages/orchestration/src/utils/mockChainInfo.js b/packages/orchestration/src/utils/mockChainInfo.js index d7fb12cea0e..42cfcca688f 100644 --- a/packages/orchestration/src/utils/mockChainInfo.js +++ b/packages/orchestration/src/utils/mockChainInfo.js @@ -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, @@ -67,9 +72,7 @@ const connectionEntries = harden({ }, }); -/** - * @returns {Pick} - */ +/** @returns {Pick} */ export const prepareMockChainInfo = () => { return harden({ chainId: 'agoriclocal', diff --git a/packages/orchestration/test/examples/swapExample.test.ts b/packages/orchestration/test/examples/swapExample.test.ts index ca1a8852fe5..e288dc9a982 100644 --- a/packages/orchestration/test/examples/swapExample.test.ts +++ b/packages/orchestration/test/examples/swapExample.test.ts @@ -28,6 +28,7 @@ test('start', async t => { { Stable: ist.issuer }, {}, { + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, diff --git a/packages/orchestration/test/examples/unbondExample.test.ts b/packages/orchestration/test/examples/unbondExample.test.ts index b78e606fdf0..7540faf10d3 100644 --- a/packages/orchestration/test/examples/unbondExample.test.ts +++ b/packages/orchestration/test/examples/unbondExample.test.ts @@ -26,6 +26,7 @@ test('start', async t => { { Stable: ist.issuer }, {}, { + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 4f2f8c5392a..8c2514d052e 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -26,6 +26,7 @@ test('chain info', async t => { const { zcf } = await setupZCFTest(); const { registerChain, orchestrate } = makeOrchestrationFacade({ + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, @@ -54,6 +55,7 @@ test('contract upgrade', async t => { // Register once { const { registerChain } = makeOrchestrationFacade({ + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, @@ -72,6 +74,7 @@ test('contract upgrade', async t => { // Simulate running again in a new incarnation with the same zone { const { registerChain } = makeOrchestrationFacade({ + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index d13338b260b..c0079ef920f 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -9,8 +9,13 @@ import { buildZoeManualTimer } from '@agoric/zoe/tools/manualTimer.js'; import { withAmountUtils } from '@agoric/zoe/tools/test-utils.js'; import { makeHeapZone } from '@agoric/zone'; import { E } from '@endo/far'; +import { makeNameHubKit } from '@agoric/vats'; +import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js'; import { fakeNetworkEchoStuff } from './network-fakes.js'; import { prepareOrchestrationTools } from '../src/service.js'; +import { CHAIN_KEY } from '../src/facade.js'; +import type { CosmosChainInfo } from '../src/cosmos-api.js'; +import { wellKnownChainInfo } from '../src/chain-info.js'; export { makeFakeLocalchainBridge } from '@agoric/vats/tools/fake-bridge.js'; @@ -53,8 +58,21 @@ export const commonSetup = async t => { const { portAllocator } = fakeNetworkEchoStuff(rootZone.subZone('network')); const { public: orchestration } = makeOrchestrationKit({ portAllocator }); + const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } = + makeNameHubKit(); + const spaces = await makeWellKnownSpaces(agoricNamesAdmin, t.log, [ + CHAIN_KEY, + ]); + + // Simulate what BLD stakers would have configured + for (const [name, info] of Object.entries(wellKnownChainInfo)) { + // @ts-expect-error FIXME types + spaces.chain.produce[name].resolve(info); + } + return { bootstrap: { + agoricNames, bankManager, timer, localchain, From 72bf1bfea6e3f1b45a479235b2672cf26d7f3a6b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 15:51:48 -0700 Subject: [PATCH 3/4] test: extract commonPrivateArgs --- .../orchestration/test/examples/swapExample.test.ts | 9 ++------- .../orchestration/test/examples/unbondExample.test.ts | 10 ++-------- packages/orchestration/test/supports.ts | 7 +++++++ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/orchestration/test/examples/swapExample.test.ts b/packages/orchestration/test/examples/swapExample.test.ts index e288dc9a982..c10c4b2a994 100644 --- a/packages/orchestration/test/examples/swapExample.test.ts +++ b/packages/orchestration/test/examples/swapExample.test.ts @@ -16,6 +16,7 @@ test('start', async t => { const { bootstrap, brands: { ist }, + commonPrivateArgs, utils, } = await commonSetup(t); @@ -27,13 +28,7 @@ test('start', async t => { installation, { Stable: ist.issuer }, {}, - { - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, - storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, - }, + commonPrivateArgs, ); const inv = E(publicFacet).makeSwapAndStakeInvitation(); diff --git a/packages/orchestration/test/examples/unbondExample.test.ts b/packages/orchestration/test/examples/unbondExample.test.ts index 7540faf10d3..7b23042977a 100644 --- a/packages/orchestration/test/examples/unbondExample.test.ts +++ b/packages/orchestration/test/examples/unbondExample.test.ts @@ -13,8 +13,8 @@ type StartFn = test('start', async t => { const { - bootstrap, brands: { ist }, + commonPrivateArgs, } = await commonSetup(t); const { zoe, bundleAndInstall } = await setUpZoeForTest(); @@ -25,13 +25,7 @@ test('start', async t => { installation, { Stable: ist.issuer }, {}, - { - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, - storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, - }, + commonPrivateArgs, ); const inv = E(publicFacet).makeUnbondAndLiquidStakeInvitation(); diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index c0079ef920f..fea78fb9123 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -86,6 +86,13 @@ export const commonSetup = async t => { bld, ist, }, + commonPrivateArgs: { + agoricNames, + localchain, + orchestrationService: orchestration, + storageNode: storage.rootNode, + timerService: timer, + }, utils: { pourPayment, }, From 9fdd77faebb661bc4e055d7f22c79a20f2a1d9be Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 15:55:49 -0700 Subject: [PATCH 4/4] test: extract facadeServices --- packages/orchestration/test/facade.test.ts | 19 +++++-------------- packages/orchestration/test/supports.ts | 6 ++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 8c2514d052e..0057a932502 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -19,18 +19,15 @@ export const mockChainInfo: CosmosChainInfo = harden({ }); 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({ - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); @@ -46,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; @@ -55,11 +52,8 @@ test('contract upgrade', async t => { // Register once { const { registerChain } = makeOrchestrationFacade({ - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); @@ -74,11 +68,8 @@ test('contract upgrade', async t => { // Simulate running again in a new incarnation with the same zone { const { registerChain } = makeOrchestrationFacade({ - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index fea78fb9123..b87f4678bb7 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -93,6 +93,12 @@ export const commonSetup = async t => { storageNode: storage.rootNode, timerService: timer, }, + facadeServices: { + agoricNames, + localchain, + orchestrationService: orchestration, + timerService: timer, + }, utils: { pourPayment, },