Skip to content

Commit

Permalink
9063 localChain metadata by agoricNames (#9464)
Browse files Browse the repository at this point in the history
refs: #9063

## Description

More progress on #9063

Following up on #9459

Next I think I'll set up a tool to grab the chain-registry info for the
chains in the checklist and bring them into agoricNames

In parallel, @dckc is populating agoricNames with the chain _connection_
info which can be appended to even after the chain (graph node) is
defined.


### Security Considerations

no changes

### Scaling Considerations

no changes

### Documentation Considerations

no need

### Testing Considerations

CI, including A3P proposal update

### Upgrade Considerations

no yet deployed
  • Loading branch information
mergify[bot] committed Jun 6, 2024
2 parents f6d77a3 + 3cab037 commit 4491bd1
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 109 deletions.
80 changes: 79 additions & 1 deletion packages/orchestration/src/chain-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,76 @@

/** @file temporary static lookup of chain info */

/** @import {CosmosChainInfo, EthChainInfo} from './types.js'; */
import { E } from '@endo/far';

/**
* @import {CosmosChainInfo, EthChainInfo} from './types.js';
*/

/** @typedef {CosmosChainInfo | EthChainInfo} ChainInfo */

// TODO generate this automatically with a build script drawing on data sources such as https://github.com/cosmos/chain-registry

// XXX inlines the enum values to save the import (entraining cosmic-proto which is megabytes)

export const wellKnownChainInfo =
/** @satisfies {Record<string, ChainInfo>} */ (
harden({
agoric: {
chainId: 'agoriclocal',
connections: {
cosmoslocal: {
id: 'connection-1',
client_id: '07-tendermint-3',
counterparty: {
client_id: '07-tendermint-2',
connection_id: 'connection-1',
prefix: {
key_prefix: '',
},
},
state: 3 /* IBCConnectionState.STATE_OPEN */,
transferChannel: {
portId: 'transfer',
channelId: 'channel-1',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 1 /* Order.ORDER_UNORDERED */,
state: 3 /* IBCConnectionState.STATE_OPEN */,
version: 'ics20-1',
},
versions: [{ identifier: '', features: ['', ''] }],
delay_period: 0n,
},
osmosislocal: {
id: 'connection-0',
client_id: '07-tendermint-2',
counterparty: {
client_id: '07-tendermint-2',
connection_id: 'connection-1',
prefix: {
key_prefix: '',
},
},
state: 3 /* IBCConnectionState.STATE_OPEN */,
transferChannel: {
portId: 'transfer',
channelId: 'channel-0',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 1 /* Order.ORDER_UNORDERED */,
state: 3 /* IBCConnectionState.STATE_OPEN */,
version: 'ics20-1',
},
versions: [{ identifier: '', features: ['', ''] }],
delay_period: 0n,
},
},
ibcHooksEnabled: true,
icaEnabled: true,
icqEnabled: true,
pfmEnabled: true,
},
// https://github.com/cosmos/chain-registry/blob/master/stride/chain.json
stride: {
chainId: 'stride-1',
Expand Down Expand Up @@ -50,3 +111,20 @@ export const wellKnownChainInfo =
},
})
);

/**
* @param {ERef<import('@agoric/vats').NameHubKit['nameAdmin']>} agoricNamesAdmin
* @param {(...messages: string[]) => void} log
*/
export const registerChainNamespace = async (agoricNamesAdmin, log) => {
const { nameAdmin } = await E(agoricNamesAdmin).provideChild('chain');

const registrationPromises = Object.entries(wellKnownChainInfo).map(
async ([name, info]) => {
log(`registering chain ${name}`);
return E(nameAdmin).update(name, info);
},
);

await Promise.all(registrationPromises);
};
16 changes: 11 additions & 5 deletions packages/orchestration/src/examples/stakeBld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ import { E } from '@endo/far';
import { deeplyFulfilled } from '@endo/marshal';
import { M } from '@endo/patterns';
import { prepareLocalChainAccountKit } from '../exos/local-chain-account-kit.js';
import { prepareMockChainInfo } from '../utils/mockChainInfo.js';

/**
* @import {NameHub} from '@agoric/vats';
* @import {Remote} from '@agoric/internal';
* @import {TimerBrand, TimerService} from '@agoric/time';
* @import {LocalChain} from '@agoric/vats/src/localchain.js';
*/

const trace = makeTracer('StakeBld');

/**
* @param {ZCF} zcf
* @param {{
* localchain: import('@agoric/vats/src/localchain.js').LocalChain;
* agoricNames: Remote<NameHub>;
* localchain: Remote<LocalChain>;
* marshaller: Marshaller;
* storageNode: StorageNode;
* timerService: TimerService;
Expand All @@ -42,9 +45,12 @@ export const start = async (zcf, privateArgs, baggage) => {
privateArgs.marshaller,
);

// Mocked until #8879
// Would expect this to be instantiated elsewhere, and passed in as a reference
const agoricChainInfo = prepareMockChainInfo();
// FIXME in a second incarnation we can't make a remote call before defining all kinds
// UNTIL https://github.com/Agoric/agoric-sdk/issues/8879
const agoricChainInfo = await E(privateArgs.agoricNames).lookup(
'chain',
'agoric',
);

const makeLocalChainAccountKit = prepareLocalChainAccountKit(
zone,
Expand Down
5 changes: 1 addition & 4 deletions packages/orchestration/src/exos/local-chain-account-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import { dateInSeconds, makeTimestampHelper } from '../utils/time.js';
* @import {TimerService, TimerBrand} from '@agoric/time';
*/

// partial until #8879
/** @typedef {Pick<CosmosChainInfo, 'connections'>} AgoricChainInfo */

const trace = makeTracer('LCAH');

const { Fail } = assert;
Expand Down Expand Up @@ -66,7 +63,7 @@ const PUBLIC_TOPICS = {
* @param {ZCF} zcf
* @param {TimerService} timerService
* @param {TimerBrand} timerBrand
* @param {AgoricChainInfo} agoricChainInfo
* @param {CosmosChainInfo} agoricChainInfo
*/
export const prepareLocalChainAccountKit = (
zone,
Expand Down
13 changes: 12 additions & 1 deletion packages/orchestration/src/proposals/start-stakeBld.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { makeTracer } from '@agoric/internal';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
import { Stake } from '@agoric/internal/src/tokens.js';
import { E } from '@endo/far';
import { registerChainNamespace } from '../chain-info.js';

const trace = makeTracer('StartStakeBld', true);

Expand All @@ -18,6 +19,8 @@ const trace = makeTracer('StartStakeBld', true);
*/
export const startStakeBld = async ({
consume: {
agoricNames: agoricNamesP,
agoricNamesAdmin,
board,
chainStorage,
chainTimerService: chainTimerServiceP,
Expand All @@ -37,12 +40,16 @@ export const startStakeBld = async ({
const VSTORAGE_PATH = 'stakeBld';
trace('startStakeBld');

// Assumes this is the first proposal to need/provide `chain` namespace
await registerChainNamespace(agoricNamesAdmin, trace);

const storageNode = await makeStorageNodeChild(chainStorage, VSTORAGE_PATH);

// NB: committee must only publish what it intended to be public
const marshaller = await E(board).getPublishingMarshaller();

const [timerService, timerBrand] = await Promise.all([
const [agoricNames, timerService, timerBrand] = await Promise.all([
agoricNamesP,
chainTimerServiceP,
chainTimerServiceP.then(ts => E(ts).getTimerBrand()),
]);
Expand All @@ -58,6 +65,8 @@ export const startStakeBld = async ({
issuerKeywordRecord: harden({ In: await stakeIssuer }),
terms: {},
privateArgs: {
// BEFOREPUSh populate agoricNames with 'agoric' info and test in a3p
agoricNames,
localchain: await localchain,
timerService,
timerBrand,
Expand All @@ -76,6 +85,8 @@ export const getManifestForStakeBld = ({ restoreRef }, { installKeys }) => {
manifest: {
[startStakeBld.name]: {
consume: {
agoricNames: true,
agoricNamesAdmin: true,
board: true,
chainStorage: true,
chainTimerService: true,
Expand Down
81 changes: 0 additions & 81 deletions packages/orchestration/src/utils/mockChainInfo.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type StartFn =
typeof import('@agoric/orchestration/src/examples/stakeBld.contract.js').start;

const startContract = async ({
agoricNames,
timer,
localchain,
marshaller,
Expand All @@ -28,6 +29,7 @@ const startContract = async ({
{ In: bld.issuer },
{},
{
agoricNames,
localchain,
marshaller,
storageNode: storage.rootNode,
Expand Down
11 changes: 3 additions & 8 deletions packages/orchestration/test/exos/local-chain-account-kit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/record
import { E, Far } from '@endo/far';
import { prepareLocalChainAccountKit } from '../../src/exos/local-chain-account-kit.js';
import { ChainAddress } from '../../src/orchestration-api.js';
import { prepareMockChainInfo } from '../../src/utils/mockChainInfo.js';
import { NANOSECONDS_PER_SECOND } from '../../src/utils/time.js';
import { commonSetup } from '../supports.js';
import { wellKnownChainInfo } from '../../src/chain-info.js';

const agoricChainInfo = wellKnownChainInfo.agoric;

test('deposit, withdraw', async t => {
const { bootstrap, brands, utils } = await commonSetup(t);
Expand All @@ -17,7 +19,6 @@ test('deposit, withdraw', async t => {
const { timer, localchain, marshaller, rootZone, storage } = bootstrap;

t.log('chainInfo mocked via `prepareMockChainInfo` until #8879');
const agoricChainInfo = prepareMockChainInfo();

t.log('exo setup - prepareLocalChainAccountKit');
const { makeRecorderKit } = prepareRecorderKitMakers(
Expand Down Expand Up @@ -84,9 +85,6 @@ test('delegate, undelegate', async t => {

const { timer, localchain, marshaller, rootZone, storage } = bootstrap;

t.log('chainInfo mocked via `prepareMockChainInfo` until #8879');
const agoricChainInfo = prepareMockChainInfo();

t.log('exo setup - prepareLocalChainAccountKit');
const { makeRecorderKit } = prepareRecorderKitMakers(
rootZone.mapStore('recorder'),
Expand Down Expand Up @@ -135,9 +133,6 @@ test('transfer', async t => {

const { timer, localchain, marshaller, rootZone, storage } = bootstrap;

t.log('chainInfo mocked via `prepareMockChainInfo` until #8879');
const agoricChainInfo = prepareMockChainInfo();

t.log('exo setup - prepareLocalChainAccountKit');
const { makeRecorderKit } = prepareRecorderKitMakers(
rootZone.mapStore('recorder'),
Expand Down
14 changes: 5 additions & 9 deletions packages/orchestration/test/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ 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';
import {
registerChainNamespace,
wellKnownChainInfo,
} from '../src/chain-info.js';

export { makeFakeLocalchainBridge } from '@agoric/vats/tools/fake-bridge.js';

Expand Down Expand Up @@ -60,15 +63,8 @@ export const commonSetup = async t => {

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);
}
await registerChainNamespace(agoricNamesAdmin, t.log);

return {
bootstrap: {
Expand Down

0 comments on commit 4491bd1

Please sign in to comment.