Skip to content
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

Refactor registry module, add IBC path cache, paths API #63

Merged
merged 15 commits into from
Jul 11, 2022

Conversation

cbrit
Copy link
Member

@cbrit cbrit commented Jun 27, 2022

Closes #13 and #15

This PR does a number of things:

  1. Restructures the registry module such that it is no longer under chain, and moves the asset objects into into their own registry::assets submodule.
  2. Switches to using raw.githubusercontent.com file endpoints for single-file retrieval such as for get_chain() and get_assets(). The octocrab crate is still used for getting the list of IBC path and chain names.
  3. Adds a registry-cache feature which houses the RegistryCache type.
  4. Adds IBC path retrieval methods requested by the Hermes relayer team in Retrieve relayer paths info given a tag #13 and Retrieve relayer paths pairwise #15. Both the registry module itself and the cache have a get_path(chain_a, chain_b) method. The former will make a network call to the chain registry github repo, the latter will use the already-cached data. This allows a path to be queried pairwise even without the cache feature enabled. To retrieve all paths with a given tag, the cache must be used.

@cbrit cbrit marked this pull request as draft June 27, 2022 22:34
@cbrit cbrit marked this pull request as draft June 27, 2022 22:34
@cbrit cbrit requested review from EricBolten and removed request for EricBolten June 28, 2022 14:46
@cbrit cbrit requested a review from adizere June 28, 2022 16:07
@cbrit cbrit marked this pull request as ready for review July 6, 2022 21:57
@cbrit cbrit requested a review from tony-iqlusion July 6, 2022 22:14
@cbrit
Copy link
Member Author

cbrit commented Jul 7, 2022

Replaced the remaining uses of the octocrab crate with direct requests to the github repos API. Octocrab was not honoring the refs passed to it and was always pulling from the head of the main branch. We only need to list file/dir names anyway so it was kind of overkill to have a whole crate included for just that.

Copy link
Contributor

@philipjames44 philipjames44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of nits and one comment around testing.


async fn get_file_content(r#ref: &str, path: &str) -> Result<String, ChainRegistryError> {
let url = format!(
"https://raw.githubusercontent.com/cosmos/chain-registry/{}/{}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should probably be a constant

Comment on lines 41 to 67
pub struct Channel {
#[serde(rename = "chain-1")]
pub chain_1: Chain12,
#[serde(rename = "chain-2")]
pub chain_2: Chain22,
pub ordering: String,
pub version: String,
pub tags: Tags,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Chain12 {
#[serde(rename = "channel-id")]
pub channel_id: String,
#[serde(rename = "port-id")]
pub port_id: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Chain22 {
#[serde(rename = "channel-id")]
pub channel_id: String,
#[serde(rename = "port-id")]
pub port_id: String,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Potentially renaming these to chain a & b (or some other convention) might be more clear than 1 & 2 as Chain12 & Chain22 read more as chain twelve and chain twenty two imo

Copy link
Member Author

@cbrit cbrit Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunate schema design forced this; I generated the structs with a webtool and it derived those names haha. How about ChainA, ChainAA, ChainB, ChainBB?

EDIT: I'll go with Chain1, ChannelChain1, etc

Comment on lines +5 to +6
#[assay]
async fn registry_cache_happy_path() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it might be a good idea to get an unhappy path test here to verify things fail as expected.

for pn in path_names {
let cn: Vec<&str> = pn.split('-').collect();

// this unwrap is safe becauase we query the path directly from the list of path .json file names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I missed it but I don't see what line this is referring to

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.expect("path returned None")

I may should just make it return an error just in case

@cbrit
Copy link
Member Author

cbrit commented Jul 11, 2022

Going to merge this and can tweak as needed when we hear back from the Hermes relayer team

@cbrit cbrit merged commit 098a261 into main Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retrieve relayer paths info given a tag
2 participants