From 7c51fd4c6c917cd37df81245d58756ab4532d4ee Mon Sep 17 00:00:00 2001 From: allthatjazzleo Date: Wed, 13 Nov 2024 12:41:24 +0800 Subject: [PATCH 1/4] allow osmosis testnet to use dynamic_gas_price --- .../bug-fixes/ibc-relayer/4237-improve-tls-configuration.md | 4 +++- crates/relayer/src/chain/cosmos/eip_base_fee.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md b/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md index 1c246d6aef..559777e189 100644 --- a/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md +++ b/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md @@ -1,3 +1,5 @@ - Fix an issue where Hermes would fail to connect to gRPC servers with an IPv6 address. - ([\#4237](https://github.com/informalsystems/hermes/issues/4237)) \ No newline at end of file + ([\#4237](https://github.com/informalsystems/hermes/issues/4237)) +- Fix an issue where osmosis testnet cannot use `dynamic_gas_price` feature. + ([\#4247](https://github.com/informalsystems/hermes/issues/4247)) \ No newline at end of file diff --git a/crates/relayer/src/chain/cosmos/eip_base_fee.rs b/crates/relayer/src/chain/cosmos/eip_base_fee.rs index 5c91fc7ad6..595c755e44 100644 --- a/crates/relayer/src/chain/cosmos/eip_base_fee.rs +++ b/crates/relayer/src/chain/cosmos/eip_base_fee.rs @@ -21,7 +21,7 @@ pub async fn query_eip_base_fee( let chain_name = chain_id.name(); - let is_osmosis = chain_name.starts_with("osmosis") || chain_name.starts_with("osmo-test"); + let is_osmosis = chain_name.starts_with("osmosis") || chain_name.starts_with("osmo"); let url = if is_osmosis { format!( From 11ca926502fa74e36f293d0b5da2ab46009eeba6 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Thu, 14 Nov 2024 13:52:24 +0100 Subject: [PATCH 2/4] Fix method to retrieve a chain name --- .../src/core/ics24_host/identifier.rs | 37 ++++++++++++++++++- .../relayer/src/chain/cosmos/eip_base_fee.rs | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/relayer-types/src/core/ics24_host/identifier.rs b/crates/relayer-types/src/core/ics24_host/identifier.rs index 8c472d8947..c1f80058c0 100644 --- a/crates/relayer-types/src/core/ics24_host/identifier.rs +++ b/crates/relayer-types/src/core/ics24_host/identifier.rs @@ -68,8 +68,20 @@ impl ChainId { /// Extract the chain name from this chain identifier. The chain name /// consists of the first part of the identifier, before the dash. + /// If the value following the dash is not an integer, or if there are no + /// dashes, the entire chain ID will be returned. pub fn name(&self) -> String { - self.id.split('-').take(1).collect::>().join("") + self.id + .rsplit_once('-') + .and_then(|(chain_name, rev_number_str)| { + // Parses the revision number string into a `u64` and checks its validity. + if rev_number_str.parse::().is_ok() { + Some(chain_name.to_owned()) + } else { + None + } + }) + .unwrap_or_else(|| self.id.clone()) } /// Extract the version from the given chain identifier. @@ -442,3 +454,26 @@ impl Display for PortChannelId { write!(f, "{}/{}", self.port_id, self.channel_id) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_chain_id_name() { + let chain_id = ChainId::from_str("ibc-5").unwrap(); + assert_eq!(chain_id.name(), "ibc".to_owned()); + } + + #[test] + fn test_chain_id_name_with_test() { + let chain_id = ChainId::from_str("ibc-test-5").unwrap(); + assert_eq!(chain_id.name(), "ibc-test".to_owned()); + } + + #[test] + fn test_chain_id_name_no_dash() { + let chain_id = ChainId::from_str("ibc5").unwrap(); + assert_eq!(chain_id.name(), "ibc5".to_owned()); + } +} diff --git a/crates/relayer/src/chain/cosmos/eip_base_fee.rs b/crates/relayer/src/chain/cosmos/eip_base_fee.rs index 595c755e44..5c91fc7ad6 100644 --- a/crates/relayer/src/chain/cosmos/eip_base_fee.rs +++ b/crates/relayer/src/chain/cosmos/eip_base_fee.rs @@ -21,7 +21,7 @@ pub async fn query_eip_base_fee( let chain_name = chain_id.name(); - let is_osmosis = chain_name.starts_with("osmosis") || chain_name.starts_with("osmo"); + let is_osmosis = chain_name.starts_with("osmosis") || chain_name.starts_with("osmo-test"); let url = if is_osmosis { format!( From 21b5a10e61ec0b539324e59ef5a135bc3ade5b3b Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Fri, 15 Nov 2024 09:55:32 +0100 Subject: [PATCH 3/4] Split changelog entry --- .../bug-fixes/ibc-relayer/4237-improve-tls-configuration.md | 4 +--- .../bug-fixes/ibc-relayer/4247-fix-chain-name-extraction.md | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .changelog/unreleased/bug-fixes/ibc-relayer/4247-fix-chain-name-extraction.md diff --git a/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md b/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md index 559777e189..1c246d6aef 100644 --- a/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md +++ b/.changelog/unreleased/bug-fixes/ibc-relayer/4237-improve-tls-configuration.md @@ -1,5 +1,3 @@ - Fix an issue where Hermes would fail to connect to gRPC servers with an IPv6 address. - ([\#4237](https://github.com/informalsystems/hermes/issues/4237)) -- Fix an issue where osmosis testnet cannot use `dynamic_gas_price` feature. - ([\#4247](https://github.com/informalsystems/hermes/issues/4247)) \ No newline at end of file + ([\#4237](https://github.com/informalsystems/hermes/issues/4237)) \ No newline at end of file diff --git a/.changelog/unreleased/bug-fixes/ibc-relayer/4247-fix-chain-name-extraction.md b/.changelog/unreleased/bug-fixes/ibc-relayer/4247-fix-chain-name-extraction.md new file mode 100644 index 0000000000..6f538ac1d9 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/ibc-relayer/4247-fix-chain-name-extraction.md @@ -0,0 +1,3 @@ +- Fix the extraction of the chain name from the chain ID to ensure + accurate identification. + ([\#4247](https://github.com/informalsystems/hermes/issues/4247)) \ No newline at end of file From 33d2496a88e0b22cb7778883673d71bb1d595cb4 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Fri, 15 Nov 2024 14:48:33 +0100 Subject: [PATCH 4/4] Apply GitHub suggestions --- .../src/core/ics24_host/identifier.rs | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/crates/relayer-types/src/core/ics24_host/identifier.rs b/crates/relayer-types/src/core/ics24_host/identifier.rs index c1f80058c0..dbe60ea337 100644 --- a/crates/relayer-types/src/core/ics24_host/identifier.rs +++ b/crates/relayer-types/src/core/ics24_host/identifier.rs @@ -70,18 +70,18 @@ impl ChainId { /// consists of the first part of the identifier, before the dash. /// If the value following the dash is not an integer, or if there are no /// dashes, the entire chain ID will be returned. - pub fn name(&self) -> String { + pub fn name(&self) -> &str { self.id .rsplit_once('-') .and_then(|(chain_name, rev_number_str)| { // Parses the revision number string into a `u64` and checks its validity. if rev_number_str.parse::().is_ok() { - Some(chain_name.to_owned()) + Some(chain_name) } else { None } }) - .unwrap_or_else(|| self.id.clone()) + .unwrap_or_else(|| &self.id) } /// Extract the version from the given chain identifier. @@ -476,4 +476,60 @@ mod tests { let chain_id = ChainId::from_str("ibc5").unwrap(); assert_eq!(chain_id.name(), "ibc5".to_owned()); } + + #[test] + fn standard_chain_names() { + let test_cases = [ + ("ibc-0", "ibc"), + ("osmosis-1", "osmosis"), + ("cosmoshub-4", "cosmoshub"), + ("juno-mainnet-1", "juno-mainnet"), + ("akash-testnet-2", "akash-testnet"), + ("stargaze-123", "stargaze"), + ("crypto-org-chain-0", "crypto-org-chain"), + ("mars-hub-1", "mars-hub"), + ("evmos-9000-1", "evmos-9000"), + ]; + + for (input, expected) in test_cases { + let chain_id = ChainId::from_str(input).unwrap(); + assert_eq!(chain_id.name(), expected); + } + } + + #[test] + fn missing_or_invalid_revision_numbers() { + let test_cases = [ + ("osmosis", "osmosis"), + ("ibc-test", "ibc-test"), + ("cosmos-hub", "cosmos-hub"), + ("juno-", "juno-"), + ("akash-testnet-x", "akash-testnet-x"), + ("stargaze-abc", "stargaze-abc"), + ("chain-123-xyz", "chain-123-xyz"), + ]; + + for (input, expected) in test_cases { + let chain_id = ChainId::from_str(input).unwrap(); + assert_eq!(chain_id.name(), expected); + } + } + + #[test] + fn edge_cases() { + let test_cases = [ + ("", ""), + ("-", "-"), + ("chain-", "chain-"), + ( + "chain-9999999999999999999999", + "chain-9999999999999999999999", + ), // number too large for u64 + ]; + + for (input, expected) in test_cases { + let chain_id = ChainId::from_str(input).unwrap(); + assert_eq!(chain_id.name(), expected); + } + } }