Skip to content

Commit

Permalink
Add channel close init and confirm CLIs (#556)
Browse files Browse the repository at this point in the history
* Add channel close init and confirm CLIs

* Update Changelog

* Fixed typos in operating instructions.

Co-authored-by: Adi Seredinschi <[email protected]>
  • Loading branch information
ancazamfir and adizere authored Jan 27, 2021
1 parent 93c0e6d commit 8c54128
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 91 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [relayer-cli]
- Implement command to query the channels associated with a connection ([#505])
- JSON output for queries and txs ([#500])
- Implement commands for channel close init and confirm ([#538])
- Implement command to perform the handshake for a new channel ([#557])

- [relayer]
Expand Down Expand Up @@ -60,6 +61,7 @@
[#535]: https://github.com/informalsystems/ibc-rs/issues/535
[#536]: https://github.com/informalsystems/ibc-rs/issues/536
[#537]: https://github.com/informalsystems/ibc-rs/issues/537
[#538]: https://github.com/informalsystems/ibc-rs/issues/538
[#540]: https://github.com/informalsystems/ibc-rs/issues/540
[#554]: https://github.com/informalsystems/ibc-rs/issues/554
[#557]: https://github.com/informalsystems/ibc-rs/issues/557
Expand Down
32 changes: 20 additions & 12 deletions modules/src/ics04_channel/msgs/chan_close_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
use std::convert::{TryFrom, TryInto};

use tendermint::account::Id as AccountId;
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm;

use crate::address::{account_to_string, string_to_account};
use crate::ics04_channel::error::{Error, Kind};
use crate::ics24_host::identifier::{ChannelId, PortId};
use crate::{proofs::Proofs, tx_msg::Msg};

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm;
use tendermint::account::Id as AccountId;
use tendermint_proto::Protobuf;

use std::convert::{TryFrom, TryInto};
pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseConfirm";

///
/// Message definition for the second step in the channel close handshake (the `ChanCloseConfirm`
/// datagram).
///
#[derive(Clone, Debug, PartialEq)]
pub struct MsgChannelCloseConfirm {
port_id: PortId,
channel_id: ChannelId,
proofs: Proofs,
signer: AccountId,
pub port_id: PortId,
pub channel_id: ChannelId,
pub proofs: Proofs,
pub signer: AccountId,
}

impl Msg for MsgChannelCloseConfirm {
Expand All @@ -28,6 +31,10 @@ impl Msg for MsgChannelCloseConfirm {
crate::keys::ROUTER_KEY.to_string()
}

fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
Expand Down Expand Up @@ -84,9 +91,9 @@ impl From<MsgChannelCloseConfirm> for RawMsgChannelCloseConfirm {
#[cfg(test)]
pub mod test_util {
use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm;
use ibc_proto::ibc::core::client::v1::Height;

use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof};
use ibc_proto::ibc::core::client::v1::Height;

/// Returns a dummy `RawMsgChannelCloseConfirm`, for testing only!
pub fn get_dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelCloseConfirm {
Expand All @@ -105,12 +112,13 @@ pub mod test_util {

#[cfg(test)]
mod tests {
use std::convert::TryFrom;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm;
use ibc_proto::ibc::core::client::v1::Height;

use crate::ics04_channel::msgs::chan_close_confirm::test_util::get_dummy_raw_msg_chan_close_confirm;
use crate::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm;
use ibc_proto::ibc::core::client::v1::Height;
use std::convert::TryFrom;

#[test]
fn parse_channel_close_confirm_msg() {
Expand Down
46 changes: 17 additions & 29 deletions modules/src/ics04_channel/msgs/chan_close_init.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
use std::convert::TryFrom;

use tendermint::account::Id as AccountId;
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit;

use crate::address::{account_to_string, string_to_account};
use crate::ics04_channel::error::{Error, Kind};
use crate::ics24_host::identifier::{ChannelId, PortId};
use crate::tx_msg::Msg;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit;
use tendermint::account::Id as AccountId;
use tendermint_proto::Protobuf;

use std::convert::TryFrom;
pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseInit";

///
/// Message definition for the first step in the channel close handshake (`ChanCloseInit` datagram).
///
#[derive(Clone, Debug, PartialEq)]
pub struct MsgChannelCloseInit {
port_id: PortId,
channel_id: ChannelId,
signer: AccountId,
}

impl MsgChannelCloseInit {
// todo: Constructor not used yet.
#[allow(dead_code)]
fn new(
port_id: String,
channel_id: String,
signer: AccountId,
) -> Result<MsgChannelCloseInit, Error> {
Ok(Self {
port_id: port_id
.parse()
.map_err(|e| Kind::IdentifierError.context(e))?,
channel_id: channel_id
.parse()
.map_err(|e| Kind::IdentifierError.context(e))?,
signer,
})
}
pub port_id: PortId,
pub channel_id: ChannelId,
pub signer: AccountId,
}

impl Msg for MsgChannelCloseInit {
Expand All @@ -46,6 +29,10 @@ impl Msg for MsgChannelCloseInit {
crate::keys::ROUTER_KEY.to_string()
}

fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
Expand Down Expand Up @@ -102,11 +89,12 @@ pub mod test_util {

#[cfg(test)]
mod tests {
use std::convert::TryFrom;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit;

use crate::ics04_channel::msgs::chan_close_init::test_util::get_dummy_raw_msg_chan_close_init;
use crate::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit;
use std::convert::TryFrom;

#[test]
fn parse_channel_close_init_msg() {
Expand Down
63 changes: 56 additions & 7 deletions relayer-cli/relayer_operation_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
1. Clone gaia:

```shell script
git clone https://github.com/cosmos/gaia.git ~/go/src/github.com/comsos/gaia
~/go/src/github.com/comsos/gaia ; git co v3.0.0 ; make install
git clone https://github.com/cosmos/gaia.git ~/go/src/github.com/cosmos/gaia
cd ~/go/src/github.com/cosmos/gaia ; git co v3.0.0 ; make install
```

2. Start the gaia instances by running the `dev-env` script from the `ibc-rs` repo:
Expand Down Expand Up @@ -96,28 +96,28 @@ alias rrly='cargo run --bin relayer --'
rrly -c loop_config.toml query connection end ibc-0 connection-0
```

#### Channel CLIs:
#### Channel Open CLIs:

- init-none

```shell script
rrly -c loop_config.toml tx raw chan-init ibc-0 ibc-1 connection-0 transfer transfer defaultChannel defaultChannel
rrly -c loop_config.toml tx raw chan-open-init ibc-0 ibc-1 connection-0 transfer transfer defaultChannel defaultChannel
```
- init-try

```shell script
rrly -c loop_config.toml tx raw chan-try ibc-1 ibc-0 connection-0 transfer transfer defaultChannel channel-0
rrly -c loop_config.toml tx raw chan-open-try ibc-1 ibc-0 connection-0 transfer transfer defaultChannel channel-0
```

- open-try

```shell script
rrly -c loop_config.toml tx raw chan-ack ibc-0 ibc-1 connection-0 transfer transfer channel-0 channel-0
rrly -c loop_config.toml tx raw chan-open-ack ibc-0 ibc-1 connection-0 transfer transfer channel-0 channel-0
```
- open-open

```shell script
rrly -c loop_config.toml tx raw chan-confirm ibc-1 ibc-0 connection-0 transfer transfer channel-0 channel-0
rrly -c loop_config.toml tx raw chan-open-confirm ibc-1 ibc-0 connection-0 transfer transfer channel-0 channel-0
```

- verify that the two ends are in Open state:
Expand Down Expand Up @@ -199,6 +199,55 @@ rrly -c loop_config.toml tx raw packet-ack ibc-1 ibc-0 transfer channel-0
The `ibc/27A6394C3F9FF9C9DCF5DFFADF9BB5FE9A37C7E92B006199894CF1824DF9AC7C` denominator above can be obtained by querying the balance at `ibc-1` after the transfer from `ibc-0` to `ibc-1` is concluded.
#### Channel Close CLIs:
__Note__: This command is currently rejected by cosmos-sdk transfer module. To
make it work:
- clone cosmos-sdk
```shell script
git clone https://github.com/cosmos/cosmos-sdk.git ~/go/src/github.com/cosmos/cosmos-sdk
cd ~/go/src/github.com/cosmos/cosmos-sdk
```
- apply these diffs:
```
--- a/x/ibc/applications/transfer/module.go
+++ b/x/ibc/applications/transfer/module.go
@@ -305,7 +305,7 @@ func (am AppModule) OnChanCloseInit(
channelID string,
) error {
// Disallow user-initiated channel closing for transfer channels
- return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel")
+ return nil
}
```
- append the line below (watch for the placeholder `<your>`) as the last line
in your `go.mod` in the gaia clone:
```replace github.com/cosmos/cosmos-sdk => /Users/<your>/go/src/github.com/cosmos/cosmos-sdk```
- now `make build` and `make install` your local copy of gaia
Starting with channel in open-open:
- close-open
```shell script
rrly -c loop_config.toml tx raw chan-close-init ibc-0 ibc-1 connection-0 transfer transfer channel-0 channel-0
```
- close-close
```shell script
rrly -c loop_config.toml tx raw chan-close-confirm ibc-1 ibc-0 connection-0 transfer transfer channel-0 channel-0
```
- verify that the two ends are in Close state:
```shell script
rrly -c loop_config.toml query channel end ibc-0 transfer channel-0
rrly -c loop_config.toml query channel end ibc-1 transfer channel-0
```
### Relayer loop:
Client, connection, channel handshake and packet relaying can pe done from
Expand Down
30 changes: 19 additions & 11 deletions relayer-cli/src/commands/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,29 @@ pub enum TxRawCommands {
#[options(help = "tx raw conn-confirm")]
ConnConfirm(connection::TxRawConnConfirmCmd),

/// The `tx raw chan-init` subcommand
#[options(help = "tx raw chan-init")]
ChanInit(channel::TxRawChanInitCmd),
/// The `tx raw chan-open-init` subcommand
#[options(help = "tx raw chan-open-init")]
ChanOpenInit(channel::TxRawChanOpenInitCmd),

/// The `tx raw chan-try` subcommand
#[options(help = "tx raw chan-try")]
ChanTry(channel::TxRawChanTryCmd),
#[options(help = "tx raw chan-open-try")]
ChanOpenTry(channel::TxRawChanOpenTryCmd),

/// The `tx raw chan-ack` subcommand
#[options(help = "tx raw chan-ack")]
ChanAck(channel::TxRawChanAckCmd),
/// The `tx raw chan-open-ack` subcommand
#[options(help = "tx raw chan-open-ack")]
ChanOpenAck(channel::TxRawChanOpenAckCmd),

/// The `tx raw chan-confirm` subcommand
#[options(help = "tx raw chan-confirm")]
ChanConfirm(channel::TxRawChanConfirmCmd),
/// The `tx raw chan-open-confirm` subcommand
#[options(help = "tx raw chan-open-confirm")]
ChanOpenConfirm(channel::TxRawChanOpenConfirmCmd),

/// The `tx raw chan-close-init` subcommand
#[options(help = "tx raw chan-close-init")]
ChanCloseInit(channel::TxRawChanCloseInitCmd),

/// The `tx raw chan-close-confirm` subcommand
#[options(help = "tx raw chan-close-confirm")]
ChanCloseConfirm(channel::TxRawChanCloseConfirmCmd),

/// The `tx raw packet-send` subcommand
#[options(help = "tx raw packet-send")]
Expand Down
46 changes: 35 additions & 11 deletions relayer-cli/src/commands/tx/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::conclude::Output;
use crate::error::{Error, Kind};
use crate::prelude::*;

macro_rules! chan_open_cmd {
($chan_open_cmd:ident, $dbg_string:literal, $func:ident) => {
macro_rules! tx_chan_cmd {
($tx_chan_cmd:ident, $dbg_string:literal, $func:ident) => {
#[derive(Clone, Command, Debug, Options)]
pub struct $chan_open_cmd {
pub struct $tx_chan_cmd {
#[options(free, required, help = "identifier of the destination chain")]
dst_chain_id: ChainId,

Expand Down Expand Up @@ -43,7 +43,7 @@ macro_rules! chan_open_cmd {
ordering: Order,
}

impl Runnable for $chan_open_cmd {
impl Runnable for $tx_chan_cmd {
fn run(&self) {
let config = app_config();

Expand Down Expand Up @@ -89,21 +89,45 @@ macro_rules! chan_open_cmd {

match res {
Ok(receipt) => Output::success(receipt).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(format!("{:?}", e)).exit(),
}
}
}
};
}

chan_open_cmd!(TxRawChanInitCmd, "ChanOpenInit", build_chan_init_and_send);
tx_chan_cmd!(
TxRawChanOpenInitCmd,
"ChanOpenInit",
build_chan_open_init_and_send
);

chan_open_cmd!(TxRawChanTryCmd, "ChanOpenTry", build_chan_try_and_send);
tx_chan_cmd!(
TxRawChanOpenTryCmd,
"ChanOpenTry",
build_chan_open_try_and_send
);

chan_open_cmd!(TxRawChanAckCmd, "ChanOpenAck", build_chan_ack_and_send);
tx_chan_cmd!(
TxRawChanOpenAckCmd,
"ChanOpenAck",
build_chan_open_ack_and_send
);

chan_open_cmd!(
TxRawChanConfirmCmd,
tx_chan_cmd!(
TxRawChanOpenConfirmCmd,
"ChanOpenConfirm",
build_chan_confirm_and_send
build_chan_open_confirm_and_send
);

tx_chan_cmd!(
TxRawChanCloseInitCmd,
"ChanCloseInit",
build_chan_close_init_and_send
);

tx_chan_cmd!(
TxRawChanCloseConfirmCmd,
"ChanCloseConfirm",
build_chan_close_confirm_and_send
);
Loading

0 comments on commit 8c54128

Please sign in to comment.