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

Implement relaying of ConnOpenAck and ConnOpenConfirm #397

Merged
merged 17 commits into from
Nov 12, 2020
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ Special thanks to external contributors for this release: @CharlyCst ([#347]).
- [modules]
- Implement flexible connection id selection ([#332])
- ICS 4 Domain Types for channel handshakes ([#315])
- [relayer] Implement `query_header_at_height` via plain RPC queries (no light client verification) ([#336])
- [relayer]
- Implement `query_header_at_height` via plain RPC queries (no light client verification) ([#336])
- Implement the relayer logic for connection handshake message ([#358], [#359], [#360])
- [relayer-cli]
- Merge light clients config in relayer config and add commands to add/remove light clients ([#348])
- CLI for client update message ([#277])
- Implement the relayer CLI for connection handshake message ([#358], [#359], [#360])
- [proto-compiler]
- Refactor and allow specifying a commit at which the Cosmos SDK should be checked out ([#366])
- Add a `--tag` option to the `clone-sdk` command to check out a tag instead of a commit ([#369])
Expand All @@ -26,6 +29,9 @@ Special thanks to external contributors for this release: @CharlyCst ([#347]).
[#335]: https://github.com/informalsystems/ibc-rs/pulls/335
[#336]: https://github.com/informalsystems/ibc-rs/issues/336
[#348]: https://github.com/informalsystems/ibc-rs/pulls/348
[#358]: https://github.com/informalsystems/ibc-rs/issues/358
[#358]: https://github.com/informalsystems/ibc-rs/issues/359
[#358]: https://github.com/informalsystems/ibc-rs/issues/360
[#366]: https://github.com/informalsystems/ibc-rs/issues/366
[#369]: https://github.com/informalsystems/ibc-rs/pulls/369

Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Counterparty {
}
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum State {
Init = 1,
TryOpen = 2,
Expand Down
9 changes: 0 additions & 9 deletions modules/src/ics03_connection/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ pub mod conn_open_confirm;
pub mod conn_open_init;
pub mod conn_open_try;

/// Enumeration of all possible message types that the ICS3 protocol processes.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConnectionMsgType {
OpenInit,
OpenTry,
OpenAck,
OpenConfirm,
}

/// Enumeration of all possible messages that the ICS3 protocol processes.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConnectionMsg {
Expand Down
16 changes: 10 additions & 6 deletions modules/src/ics03_connection/msgs/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub const TYPE_MSG_CONNECTION_OPEN_ACK: &str = "connection_open_ack";
/// Message definition `MsgConnectionOpenAck` (i.e., `ConnOpenAck` datagram).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MsgConnectionOpenAck {
connection_id: ConnectionId,
counterparty_connection_id: Option<ConnectionId>,
client_state: Option<AnyClientState>,
proofs: Proofs,
version: String,
signer: AccountId,
pub connection_id: ConnectionId,
pub counterparty_connection_id: Option<ConnectionId>,
pub client_state: Option<AnyClientState>,
pub proofs: Proofs,
pub version: String,
pub signer: AccountId,
}

impl MsgConnectionOpenAck {
Expand Down Expand Up @@ -84,6 +84,10 @@ impl Msg for MsgConnectionOpenAck {
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}

fn type_url(&self) -> String {
"/ibc.core.connection.v1.MsgConnectionOpenAck".to_string()
}
}

impl DomainType<RawMsgConnectionOpenAck> for MsgConnectionOpenAck {}
Expand Down
10 changes: 7 additions & 3 deletions modules/src/ics03_connection/msgs/conn_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub const TYPE_MSG_CONNECTION_OPEN_CONFIRM: &str = "connection_open_confirm";
///
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MsgConnectionOpenConfirm {
connection_id: ConnectionId,
proofs: Proofs,
signer: AccountId,
pub connection_id: ConnectionId,
pub proofs: Proofs,
pub signer: AccountId,
}

impl MsgConnectionOpenConfirm {
Expand Down Expand Up @@ -53,6 +53,10 @@ impl Msg for MsgConnectionOpenConfirm {
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}

fn type_url(&self) -> String {
"/ibc.core.connection.v1.MsgConnectionOpenConfirm".to_string()
}
}

impl DomainType<RawMsgConnectionOpenConfirm> for MsgConnectionOpenConfirm {}
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ As shown above the tx commands currently require specifying a seed file:
#### Steps to testing the transactions:

* Start two chains using the `dev-env` script from the [ovrclk/relayer](https://github.com/ovrclk/relayer) (make sure to checkout stargate-4 version)
* After you run the script, the Go relayer will create a `data` folder for the chains. Open the key seed file `./data/ibc1/key_seed.json` for chain `ibc-1` and look for the account value
* After you run the script, the Go relayer will create a `data` folder for the chains. Copy the key seed file `./data/ibc1/key_seed.json` for chain `ibc-1` to a convenient location.


{
Expand Down
8 changes: 8 additions & 0 deletions relayer-cli/src/commands/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ pub enum TxRawCommands {
/// The `tx raw conn-try` subcommand
#[options(help = "tx raw conn-try")]
ConnTry(connection::TxRawConnTryCmd),

/// The `tx raw conn-ack` subcommand
#[options(help = "tx raw conn-ack")]
ConnAck(connection::TxRawConnAckCmd),

/// The `tx raw conn-confirm` subcommand
#[options(help = "tx raw conn-confirm")]
ConnConfirm(connection::TxRawConnConfirmCmd),
}
172 changes: 168 additions & 4 deletions relayer-cli/src/commands/tx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ibc::ics24_host::identifier::{ClientId, ConnectionId};

use relayer::config::Config;
use relayer::tx::connection::{
build_conn_init_and_send, build_conn_try_and_send, ConnectionOpenInitOptions,
ConnectionOpenTryOptions,
build_conn_ack_and_send, build_conn_confirm_and_send, build_conn_init_and_send,
build_conn_try_and_send, ConnectionOpenInitOptions, ConnectionOpenOptions,
adizere marked this conversation as resolved.
Show resolved Hide resolved
};

use crate::error::{Error, Kind};
Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct TxRawConnTryCmd {
}

impl TxRawConnTryCmd {
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenTryOptions, String> {
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenOptions, String> {
let dest_chain_config = config
.chains
.iter()
Expand All @@ -139,7 +139,7 @@ impl TxRawConnTryCmd {
anomaly::Context::new("invalid signer seed file", Some(e.into())).to_string()
})?;

let opts = ConnectionOpenTryOptions {
let opts = ConnectionOpenOptions {
src_chain_config: src_chain_config.clone(),
dest_chain_config: dest_chain_config.clone(),
src_client_id: self.src_client_id.clone(),
Expand Down Expand Up @@ -175,3 +175,167 @@ impl Runnable for TxRawConnTryCmd {
}
}
}

#[derive(Clone, Command, Debug, Options)]
pub struct TxRawConnAckCmd {
adizere marked this conversation as resolved.
Show resolved Hide resolved
#[options(free, help = "identifier of the destination chain")]
dest_chain_id: String,

#[options(free, help = "identifier of the source chain")]
src_chain_id: String,

#[options(free, help = "identifier of the destination client")]
dest_client_id: ClientId,

#[options(free, help = "identifier of the source client")]
src_client_id: ClientId,

#[options(free, help = "identifier of the destination connection")]
dest_connection_id: ConnectionId,

#[options(free, help = "identifier of the source connection")]
src_connection_id: ConnectionId,

#[options(
help = "json key file for the signer, must include mnemonic",
short = "k"
)]
seed_file: String,
}

impl TxRawConnAckCmd {
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenOptions, String> {
let dest_chain_config = config
.chains
.iter()
.find(|c| c.id == self.dest_chain_id.parse().unwrap())
.ok_or_else(|| "missing destination chain configuration".to_string())?;

let src_chain_config = config
.chains
.iter()
.find(|c| c.id == self.src_chain_id.parse().unwrap())
.ok_or_else(|| "missing src chain configuration".to_string())?;

let signer_seed = std::fs::read_to_string(&self.seed_file).map_err(|e| {
anomaly::Context::new("invalid signer seed file", Some(e.into())).to_string()
})?;

let opts = ConnectionOpenOptions {
src_chain_config: src_chain_config.clone(),
dest_chain_config: dest_chain_config.clone(),
src_client_id: self.src_client_id.clone(),
dest_client_id: self.dest_client_id.clone(),
src_connection_id: self.src_connection_id.clone(),
dest_connection_id: self.dest_connection_id.clone(),
signer_seed,
};

Ok(opts)
}
}

impl Runnable for TxRawConnAckCmd {
fn run(&self) {
let config = app_config();

let opts = match self.validate_options(&config) {
Err(err) => {
status_err!("invalid options: {}", err);
return;
}
Ok(result) => result,
};
status_info!("Message", "{:?}", opts);

let res: Result<String, Error> =
build_conn_ack_and_send(opts).map_err(|e| Kind::Tx.context(e).into());

match res {
Ok(receipt) => status_info!("conn ack, result: ", "{:?}", receipt),
Err(e) => status_info!("conn ack failed, error: ", "{}", e),
}
}
}

#[derive(Clone, Command, Debug, Options)]
pub struct TxRawConnConfirmCmd {
#[options(free, help = "identifier of the destination chain")]
dest_chain_id: String,

#[options(free, help = "identifier of the source chain")]
src_chain_id: String,

#[options(free, help = "identifier of the destination client")]
dest_client_id: ClientId,

#[options(free, help = "identifier of the source client")]
src_client_id: ClientId,

#[options(free, help = "identifier of the destination connection")]
dest_connection_id: ConnectionId,

#[options(free, help = "identifier of the source connection")]
src_connection_id: ConnectionId,

#[options(
help = "json key file for the signer, must include mnemonic",
short = "k"
)]
seed_file: String,
}

impl TxRawConnConfirmCmd {
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenOptions, String> {
let dest_chain_config = config
.chains
.iter()
.find(|c| c.id == self.dest_chain_id.parse().unwrap())
.ok_or_else(|| "missing destination chain configuration".to_string())?;

let src_chain_config = config
.chains
.iter()
.find(|c| c.id == self.src_chain_id.parse().unwrap())
.ok_or_else(|| "missing src chain configuration".to_string())?;

let signer_seed = std::fs::read_to_string(&self.seed_file).map_err(|e| {
anomaly::Context::new("invalid signer seed file", Some(e.into())).to_string()
})?;

let opts = ConnectionOpenOptions {
src_chain_config: src_chain_config.clone(),
dest_chain_config: dest_chain_config.clone(),
src_client_id: self.src_client_id.clone(),
dest_client_id: self.dest_client_id.clone(),
src_connection_id: self.src_connection_id.clone(),
dest_connection_id: self.dest_connection_id.clone(),
signer_seed,
};

Ok(opts)
}
}

impl Runnable for TxRawConnConfirmCmd {
fn run(&self) {
let config = app_config();

let opts = match self.validate_options(&config) {
Err(err) => {
status_err!("invalid options: {}", err);
return;
}
Ok(result) => result,
};
status_info!("Message", "{:?}", opts);

let res: Result<String, Error> =
build_conn_confirm_and_send(opts).map_err(|e| Kind::Tx.context(e).into());

match res {
Ok(receipt) => status_info!("conn confirm, result: ", "{:?}", receipt),
Err(e) => status_info!("conn confirm failed, error: ", "{}", e),
}
}
}
Loading