-
Notifications
You must be signed in to change notification settings - Fork 39
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
docs: initial docs for chainhub #1142
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# ChainHub | ||
|
||
The [ChainHub API](https://github.com/Agoric/agoric-sdk/blob/859d8c0d151ff6f686583db1eaf72efb89cc7648/packages/orchestration/src/exos/chain-hub.js#L99) is responsible for managing chain and IBC connection information. It facilitates the registration and retrieval of chain and connection information. | ||
|
||
```js | ||
const zone = makeDurableZone(baggage); | ||
const { agoricNames } = remotePowers; | ||
const chainHub = makeChainHub(agoricNames, zone); | ||
``` | ||
|
||
The `makeChainHub` function accepts a `Remote<NameHub>` reference (`agoricNames`) and an optional `Zone` to manage data durability. The `makeChainHub` function creates a new `ChainHub` instance either in the specified zone or in the heap if no zone is provided. The resulting object is an Exo singleton, meaning it has no previous state. Its state consists solely of a cache of queries to `agoricNames` and the information provided during registration calls. | ||
|
||
The `ChainHub` object maintains two `MapStores`: | ||
|
||
- `chainInfos`: For storing `CosmosChainInfo` objects. | ||
- `connectionInfos`: For storing `IBCConnectionInfo` objects. | ||
|
||
These `MapStores` are not exposed directly. They are abstracted and used internally by the methods provided by the ChainHub. | ||
|
||
# ChainHub APIs | ||
|
||
The core functionality is encapsulated within the `makeChainHub` function, which sets up a new `ChainHub` in the specified zone. The `ChainHub` provides the following APIs: | ||
|
||
## **chainHub.registerChain(name, chainInfo)** | ||
|
||
- name: **string** | ||
- chainInfo: **CosmosChainInfo** | ||
|
||
Stores information about a chain in the `chainInfos` MapStore, enabling quick lookup of details without querying a remote source. | ||
|
||
```js | ||
const chainInfo = harden({ | ||
chainId: 'agoric-3', | ||
icaEnabled: false, | ||
icqEnabled: false, | ||
pfmEnabled: false, | ||
ibcHooksEnabled: false, | ||
stakingTokens: [{ denom: 'uist' }], | ||
}); | ||
let nonce = 0n; | ||
|
||
const chainKey = `${chainInfo.chainId}-${(nonce += 1n)}`; | ||
|
||
chainHub.registerChain(chainKey, chainInfo); | ||
``` | ||
|
||
## **chainHub.getChainInfo(chainName)** | ||
|
||
- chainName: **string** | ||
- Returns: **Vow\<ActualChainInfo\<K\>\>** | ||
|
||
Retrieves stored chain information from the `chainInfos` MapStore or fetches it from a remote source if not available locally. | ||
|
||
```js | ||
chainHub.getChainInfo('agoric-3'); | ||
``` | ||
|
||
## **chainHub.registerConnection(chainId1, chainId2)** | ||
|
||
- chainId1: **string** | ||
- chainId2: **string** | ||
- Returns: **IBCConnectionInfo** | ||
|
||
Stores information about a connection between two chains in `connectionInfos` Mapstore, such as IBC connection details. | ||
|
||
```js | ||
const chainConnection = { | ||
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-1', | ||
counterPartyChannelId: 'channel-1', | ||
counterPartyPortId: 'transfer', | ||
ordering: 1 /* Order.ORDER_UNORDERED */, | ||
state: 3 /* IBCConnectionState.STATE_OPEN */, | ||
version: 'ics20-1', | ||
}, | ||
}; | ||
|
||
chainHub.registerConnection('agoric-3', 'cosmoshub', chainConnection); | ||
``` | ||
|
||
## **chainHub.getConnectionInfo(chain1, chain2)** | ||
|
||
- chain1: **string** | { chainId: **string** } | ||
- chain2: **string** | { chainId: **string** } | ||
- Returns: **Vow\<IBCConnectionInfo\<K\>\>** | ||
|
||
Retrieves stored connection information from `connectionInfos` Mapstore or fetches it from a remote source if not available locally. | ||
|
||
```js | ||
const chainConnection = await E.when( | ||
chainHub.getConnectionInfo('agoric-3', 'cosmoshub'), | ||
); | ||
``` | ||
|
||
## **chainHub.getChainsAndConnection(chainName1, chainName2)** | ||
|
||
- chainName1: **C1** extends **string** | ||
- chainName2: **C2** extends **string** | ||
- Returns: **Vow\<[ActualChainInfo\<C1\>, ActualChainInfo\<C2\>, IBCConnectionInfo]\>** | ||
|
||
This method fetches information about two chains and their connection simultaneously. | ||
|
||
```js | ||
const [agoric3, cosmoshub, connectionInfo] = await E.when( | ||
chainHub.getChainsAndConnection('agoric-3', 'cosmoshub'), | ||
); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either remove
chainHub
in all APIs or add to all of them.I think for cleaner presentation you may just delete
chainHub
in all.Also, because this is a heading, you may also delete the parameters. But I haven't seen at other pages to confirm what is the convention here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
chainHub
with all APIs. Followed conventions from here