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

Fix for chain_version parsing when chain identifier has multiple dashes #884

Merged
merged 3 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

Special thanks to external contributors:
Jongwhan Lee (@leejw51crypto) ([#878]).

> [TODO: high level summary]

### IMPROVEMENTS
Expand All @@ -13,6 +16,9 @@

### BUG FIXES

- [ibc]
- Fix parsing in `chain_version` when chain identifier has multiple dashes ([#878])

- [ibc-relayer]
- Fix pagination in gRPC query for clients ([#811])
- Fix relayer crash when hermes starts in the same time as packets are being sent ([#851])
Expand All @@ -35,6 +41,7 @@
[#854]: https://github.com/informalsystems/ibc-rs/issues/854
[#861]: https://github.com/informalsystems/ibc-rs/issues/861
[#869]: https://github.com/informalsystems/ibc-rs/issues/869
[#878]: https://github.com/informalsystems/ibc-rs/issues/878


## v0.2.0
Expand Down
14 changes: 13 additions & 1 deletion modules/src/ics24_host/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,25 @@ impl ChainId {
}

/// Extract the version from the given chain identifier.
/// ```
/// use ibc::ics24_host::identifier::ChainId;
///
/// assert_eq!(ChainId::chain_version("chain--a-0"), 0);
/// assert_eq!(ChainId::chain_version("ibc-10"), 10);
/// assert_eq!(ChainId::chain_version("cosmos-hub-97"), 97);
/// assert_eq!(ChainId::chain_version("testnet-helloworld-2"), 2);
/// ```
pub fn chain_version(chain_id: &str) -> u64 {
if !ChainId::is_epoch_format(chain_id) {
return 0;
}

let split: Vec<_> = chain_id.split('-').collect();
split[1].parse().unwrap_or(0)
split
.last()
.expect("get revision number from chain_id")
.parse()
.unwrap_or(0)
}

/// is_epoch_format() checks if a chain_id is in the format required for parsing epochs
Expand Down