Skip to content

Commit

Permalink
9281 chainHub exo (#9538)
Browse files Browse the repository at this point in the history
refs: #9281 

## Description

AsyncFlow requires that everything passing the membrane is durable. This makes the ChainHub durable by making it an Exo.


### Security Considerations
none

### Scaling Considerations

It's a singleton, because there will only be one per vat.

### Documentation Considerations
none

### Testing Considerations
Existing coverage

### Upgrade Considerations
Not yet deployed.

Now that it's an Exo, we have to consider its state an upgradability. We expect to make a new one on each vat invocation. The only state it has is cache of AgoricNames and data supplied by the contract.
  • Loading branch information
mergify[bot] authored Jun 19, 2024
2 parents f3f87b1 + e382b66 commit 9274bc7
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/orchestration/src/chain-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { registerChain } from './utils/chainHub.js';
import { registerChain } from './exos/chain-hub.js';

// Refresh with scripts/refresh-chain-info.ts
import fetchedChainInfo from './fetched-chain-info.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/examples/stakeBld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { E } from '@endo/far';
import { deeplyFulfilled } from '@endo/marshal';
import { M } from '@endo/patterns';
import { prepareLocalOrchestrationAccountKit } from '../exos/local-orchestration-account.js';
import { makeChainHub } from '../utils/chainHub.js';
import { makeChainHub } from '../exos/chain-hub.js';

/**
* @import {NameHub} from '@agoric/vats';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,38 @@ export const connectionKey = (chainId1, chainId2) => {
return [chainId1, chainId2].sort().join(CHAIN_ID_SEPARATOR);
};

const ChainIdArgShape = M.or(
M.string(),
M.splitRecord(
{
chainId: M.string(),
},
undefined,
M.any(),
),
);

const ChainHubI = M.interface('ChainHub', {
registerChain: M.call(M.string(), CosmosChainInfoShape).returns(),
getChainInfo: M.callWhen(M.string()).returns(CosmosChainInfoShape),
registerConnection: M.callWhen(
M.string(),
M.string(),
IBCConnectionInfoShape,
).returns(),
getConnectionInfo: M.callWhen(ChainIdArgShape, ChainIdArgShape).returns(
IBCConnectionInfoShape,
),
});

/**
* Make a new ChainHub in the zone (or in the heap if no zone is provided).
*
* 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 {Remote<NameHub>} agoricNames
* @param {Zone} [zone]
*/
Expand All @@ -70,7 +101,7 @@ export const makeChainHub = (agoricNames, zone = makeHeapZone()) => {
valueShape: IBCConnectionInfoShape,
});

const chainHub = harden({
const chainHub = zone.exo('ChainHub', ChainHubI, {
/**
* Register a new chain. The name will override a name in well known chain
* names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { dateInSeconds, makeTimestampHelper } from '../utils/time.js';
* @import {TimerService, TimerBrand, TimestampRecord} from '@agoric/time';
* @import {PromiseVow, VowTools} from '@agoric/vow';
* @import {TypedJson} from '@agoric/cosmic-proto';
* @import {ChainHub} from '../utils/chainHub.js';
* @import {ChainHub} from './chain-hub.js';
*/

const trace = makeTracer('LOA');
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/exos/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

/**
* @import {Zone} from '@agoric/base-zone';
* @import {ChainHub} from '../utils/chainHub.js';
* @import {ChainHub} from './chain-hub.js';
* @import {AsyncFlowTools} from '@agoric/async-flow';
* @import {Vow} from '@agoric/vow';
* @import {TimerService} from '@agoric/time';
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { prepareOrchestrator } from './exos/orchestrator.js';
* storageNode: Remote<StorageNode>;
* orchestrationService: Remote<OrchestrationService>;
* localchain: Remote<LocalChain>;
* chainHub: import('./utils/chainHub.js').ChainHub;
* chainHub: import('./exos/chain-hub.js').ChainHub;
* makeLocalOrchestrationAccountKit: MakeLocalOrchestrationAccountKit;
* makeRecorderKit: MakeRecorderKit;
* makeCosmosOrchestrationAccount: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { E, Far } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
import { Fail } from '@agoric/assert';
import { registerChainNamespace } from '../chain-info.js';
import { CHAIN_KEY, CONNECTIONS_KEY } from '../utils/chainHub.js';
import { CHAIN_KEY, CONNECTIONS_KEY } from '../exos/chain-hub.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeTracer } from '@agoric/internal';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
import { E } from '@endo/far';
import { getChainsAndConnection, makeChainHub } from '../utils/chainHub.js';
import { getChainsAndConnection, makeChainHub } from '../exos/chain-hub.js';

/**
* @import {IBCConnectionID} from '@agoric/vats';
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/proposals/start-stakeOsmo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeTracer } from '@agoric/internal';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
import { E } from '@endo/far';
import { getChainsAndConnection, makeChainHub } from '../utils/chainHub.js';
import { getChainsAndConnection, makeChainHub } from '../exos/chain-hub.js';

/**
* @import {IBCConnectionID} from '@agoric/vats';
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/record
import { makeDurableZone } from '@agoric/zone/durable.js';
import { prepareLocalOrchestrationAccountKit } from '../exos/local-orchestration-account.js';
import { makeOrchestrationFacade } from '../facade.js';
import { makeChainHub } from './chainHub.js';
import { makeChainHub } from '../exos/chain-hub.js';
import { prepareRemoteChainFacade } from '../exos/remote-chain-facade.js';
import { prepareCosmosOrchestrationAccount } from '../exos/cosmos-orchestration-account.js';
import { prepareLocalChainFacade } from '../exos/local-chain-facade.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/test/examples/sendAnywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { makeIssuerKit } from '@agoric/ertp';
import { CosmosChainInfo, IBCConnectionInfo } from '../../src/cosmos-api.js';
import { commonSetup } from '../supports.js';
import { SingleAmountRecord } from '../../src/examples/sendAnywhere.contract.js';
import { registerChain } from '../../src/utils/chainHub.js';
import { registerChain } from '../../src/exos/chain-hub.js';

const dirname = path.dirname(new URL(import.meta.url).pathname);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import test from '@endo/ses-ava/prepare-endo.js';

import { makeNameHubKit } from '@agoric/vats';
import { makeChainHub } from '../../src/utils/chainHub.js';
import { makeChainHub } from '../../src/exos/chain-hub.js';

const connection = {
id: 'connection-1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/record
import { Far } from '@endo/far';
import { prepareLocalOrchestrationAccountKit } from '../../src/exos/local-orchestration-account.js';
import { ChainAddress } from '../../src/orchestration-api.js';
import { makeChainHub } from '../../src/utils/chainHub.js';
import { makeChainHub } from '../../src/exos/chain-hub.js';
import { NANOSECONDS_PER_SECOND } from '../../src/utils/time.js';
import { commonSetup } from '../supports.js';

Expand Down

0 comments on commit 9274bc7

Please sign in to comment.