From 91f79cad0e69fd65544d6057d499bf4c833b6cda Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Thu, 29 Apr 2021 21:12:19 +0200 Subject: [PATCH] Return PortId information in query_channels (#861) --- CHANGELOG.md | 12 ++++++++---- guide/src/commands/queries/channel.md | 25 +++++++++++++++++-------- relayer/src/chain.rs | 6 ++++-- relayer/src/chain/cosmos.rs | 15 ++++++++++++--- relayer/src/chain/mock.rs | 6 ++++-- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d9e6e5a4..036dceee46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - [ibc] - Reinstated `ics23` dependency ([#854]) - - Use proper Timestamp type to track time ([#855]) + - Use proper Timestamp type to track time ([#758]) - [ibc-relayer] - Change the default for client creation to allow governance recovery in case of expiration or misbehaviour ([#785]) @@ -16,21 +16,25 @@ - [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]) + - Fix missing port information in `hermes query channels` ([#840]) - [ibc-relayer-cli] - Fix for `ft-transfer` mismatching arguments ([#869]) ### BREAKING CHANGES -> Nothing yet. +- [ibc-relayer] + - `hermes -j query channels` command now returns `result` array with the format `[{"channel_id":"channel-0","port_id":"transfer"}, ...]` instead of `["channel-0", ...]`. +[#758]: https://github.com/informalsystems/ibc-rs/issues/758 [#785]: https://github.com/informalsystems/ibc-rs/issues/785 [#811]: https://github.com/informalsystems/ibc-rs/issues/811 -[#854]: https://github.com/informalsystems/ibc-rs/issues/854 +[#840]: https://github.com/informalsystems/ibc-rs/issues/840 [#851]: https://github.com/informalsystems/ibc-rs/issues/851 +[#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 -[#855]: https://github.com/informalsystems/ibc-rs/issues/855 ## v0.2.0 diff --git a/guide/src/commands/queries/channel.md b/guide/src/commands/queries/channel.md index f9777ee67e..eda61b66b0 100644 --- a/guide/src/commands/queries/channel.md +++ b/guide/src/commands/queries/channel.md @@ -27,12 +27,22 @@ hermes query channels ibc-1 ```rust Success: [ - ChannelId( - "channel-0", - ), - ChannelId( - "channel-1", - ), + PortChannelId { + channel_id: ChannelId( + "channel-0", + ), + port_id: PortId( + "transfer", + ), + }, + PortChannelId { + channel_id: ChannelId( + "channel-1", + ), + port_id: PortId( + "transfer", + ), + }, ] ``` @@ -76,7 +86,7 @@ __Example__ Query the channel end of channel `channel-1` on port `transfer` on `ibc-1`: ```shell -hermes query channel end ibc-1 channel-1 +hermes query channel end ibc-1 transfer channel-1 ``` ```rust @@ -101,4 +111,3 @@ Success: ChannelEnd { version: "ics20-1", } ``` - diff --git a/relayer/src/chain.rs b/relayer/src/chain.rs index 4dab38938d..a121ef421f 100644 --- a/relayer/src/chain.rs +++ b/relayer/src/chain.rs @@ -15,7 +15,9 @@ use ibc::ics03_connection::version::{get_compatible_versions, Version}; use ibc::ics04_channel::channel::ChannelEnd; use ibc::ics04_channel::packet::{PacketMsgType, Sequence}; use ibc::ics23_commitment::commitment::{CommitmentPrefix, CommitmentProofBytes}; -use ibc::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; +use ibc::ics24_host::identifier::{ + ChainId, ChannelId, ClientId, ConnectionId, PortChannelId, PortId, +}; use ibc::proofs::{ConsensusProof, Proofs}; use ibc::query::QueryTxRequest; use ibc::signer::Signer; @@ -172,7 +174,7 @@ pub trait Chain: Sized { ) -> Result, Error>; /// Performs a query to retrieve the identifiers of all channels. - fn query_channels(&self, request: QueryChannelsRequest) -> Result, Error>; + fn query_channels(&self, request: QueryChannelsRequest) -> Result, Error>; fn query_channel( &self, diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index 4ed288942f..5634a4d893 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -36,7 +36,9 @@ use ibc::ics07_tendermint::consensus_state::ConsensusState as TMConsensusState; use ibc::ics07_tendermint::header::Header as TmHeader; use ibc::ics23_commitment::commitment::CommitmentPrefix; use ibc::ics23_commitment::merkle::convert_tm_to_ics_merkle_proof; -use ibc::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; +use ibc::ics24_host::identifier::{ + ChainId, ChannelId, ClientId, ConnectionId, PortChannelId, PortId, +}; use ibc::ics24_host::Path::ClientConsensusState as ClientConsensusPath; use ibc::ics24_host::Path::ClientState as ClientStatePath; use ibc::ics24_host::{ClientUpgradePath, Path, IBC_QUERY_PATH, SDK_UPGRADE_QUERY_PATH}; @@ -768,7 +770,7 @@ impl Chain for CosmosSdkChain { Ok(vec_ids) } - fn query_channels(&self, request: QueryChannelsRequest) -> Result, Error> { + fn query_channels(&self, request: QueryChannelsRequest) -> Result, Error> { crate::time!("query_connections"); let mut client = self @@ -792,7 +794,14 @@ impl Chain for CosmosSdkChain { let ids = response .channels .iter() - .filter_map(|ch| ChannelId::from_str(ch.channel_id.as_str()).ok()) + .filter_map(|ch| { + let port_id = PortId::from_str(ch.port_id.as_str()).ok()?; + let channel_id = ChannelId::from_str(ch.channel_id.as_str()).ok()?; + Some(PortChannelId { + port_id, + channel_id, + }) + }) .collect(); Ok(ids) diff --git a/relayer/src/chain/mock.rs b/relayer/src/chain/mock.rs index 9b9a1286b6..3c4e67410b 100644 --- a/relayer/src/chain/mock.rs +++ b/relayer/src/chain/mock.rs @@ -20,7 +20,9 @@ use ibc::ics07_tendermint::consensus_state::ConsensusState as TendermintConsensu use ibc::ics07_tendermint::header::Header as TendermintHeader; use ibc::ics18_relayer::context::Ics18Context; use ibc::ics23_commitment::commitment::CommitmentPrefix; -use ibc::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; +use ibc::ics24_host::identifier::{ + ChainId, ChannelId, ClientId, ConnectionId, PortChannelId, PortId, +}; use ibc::mock::context::MockContext; use ibc::mock::host::HostType; use ibc::query::QueryTxRequest; @@ -184,7 +186,7 @@ impl Chain for MockChain { unimplemented!() } - fn query_channels(&self, _request: QueryChannelsRequest) -> Result, Error> { + fn query_channels(&self, _request: QueryChannelsRequest) -> Result, Error> { unimplemented!() }