Skip to content

Commit

Permalink
MsgConnOpenTry builder and CLI (informalsystems#388)
Browse files Browse the repository at this point in the history
* Initial commit for open try, updates to merkle and version, etc

* add grpc for unbonding period

* Added more version code and tests

* cleanup

* cargo fmt

* Correct checks for destination connection.

Move temporarily to broadcast_tx_commit() to help with testing.

* Remove the tendermint generated files

* review comments

* Just use RawMerkleProof for now and remove the conversion shortcuts

* moved CommitementProof deser/ser

* fix status info and match in build proofs

* forgotten changes after merge
  • Loading branch information
ancazamfir authored Nov 11, 2020
1 parent fd5575e commit 9a4aef5
Show file tree
Hide file tree
Showing 14 changed files with 647 additions and 136 deletions.
3 changes: 3 additions & 0 deletions relayer-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ relayer-cli -c config.toml tx raw create-client dest_chain_id src_chain_id dest_

relayer-cli -c config.toml tx raw conn-init dest_chain_id src_chain_id dest_client_id src_client_id dest_connection_id -d src_connection_id
-k seed_file.json

relayer-cli -c config.toml tx raw conn-try dest_chain_id src_chain_id dest_client_id src_client_id dest_connection_id src_connection_id
-k seed_file.json
```

Note: This is work in progress, more commands will be implemented and tested with gaia stargate-4 chains.
Expand Down
4 changes: 3 additions & 1 deletion relayer-cli/src/commands/query/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ impl Runnable for QueryChannelEndCmd {
opts.proof,
)
.map_err(|e| Kind::Query.context(e).into())
.and_then(|v| ChannelEnd::decode_vec(&v).map_err(|e| Kind::Query.context(e).into()));
.and_then(|v| {
ChannelEnd::decode_vec(&v.value).map_err(|e| Kind::Query.context(e).into())
});

match res {
Ok(cs) => status_info!("Result for channel end query: ", "{:?}", cs),
Expand Down
8 changes: 5 additions & 3 deletions relayer-cli/src/commands/query/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Runnable for QueryClientStateCmd {
)
.map_err(|e| Kind::Query.context(e).into())
.and_then(|v| {
AnyClientState::decode_vec(&v).map_err(|e| Kind::Query.context(e).into())
AnyClientState::decode_vec(&v.value).map_err(|e| Kind::Query.context(e).into())
});
match res {
Ok(cs) => status_info!("client state query result: ", "{:?}", cs),
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Runnable for QueryClientConsensusCmd {
)
.map_err(|e| Kind::Query.context(e).into())
.and_then(|v| {
AnyConsensusState::decode_vec(&v).map_err(|e| Kind::Query.context(e).into())
AnyConsensusState::decode_vec(&v.value).map_err(|e| Kind::Query.context(e).into())
});

match res {
Expand Down Expand Up @@ -289,7 +289,9 @@ impl Runnable for QueryClientConnectionsCmd {
false,
)
.map_err(|e| Kind::Query.context(e).into())
.and_then(|v| ConnectionIDs::decode_vec(&v).map_err(|e| Kind::Query.context(e).into()));
.and_then(|v| {
ConnectionIDs::decode_vec(&v.value).map_err(|e| Kind::Query.context(e).into())
});
match res {
Ok(cs) => status_info!("client connections query result: ", "{:?}", cs),
Err(e) => status_info!("client connections query error", "{}", e),
Expand Down
19 changes: 9 additions & 10 deletions relayer-cli/src/commands/query/connection.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::convert::TryInto;

use abscissa_core::{Command, Options, Runnable};
use ibc::ics03_connection::connection::ConnectionEnd;
use ibc::ics24_host::error::ValidationError;
use ibc::ics24_host::identifier::ConnectionId;
use ibc::ics24_host::identifier::{ChainId as ICSChainId, ConnectionId};
use relayer::chain::{Chain, CosmosSDKChain};
use relayer::config::{ChainConfig, Config};
use tendermint::chain::Id as ChainId;
Expand Down Expand Up @@ -64,6 +62,7 @@ impl QueryConnectionEndCmd {
}
}

// cargo run --bin relayer -- -c relayer/tests/config/fixtures/simple_config.toml query connection end ibc-test connectionidone --height 3
impl Runnable for QueryConnectionEndCmd {
fn run(&self) {
let config = app_config();
Expand All @@ -78,14 +77,14 @@ impl Runnable for QueryConnectionEndCmd {
status_info!("Options", "{:?}", opts);

let chain = CosmosSDKChain::from_config(chain_config).unwrap();
// run without proof:
// cargo run --bin relayer -- -c relayer/tests/config/fixtures/simple_config.toml query connection end ibc-test connectionidone --height 3 -p false
let height = ibc::Height::new(
ICSChainId::chain_version(chain.id().to_string()),
opts.height,
);

// TODO - any value in querying with proof from the CLI?
let res: Result<ConnectionEnd, Error> = chain
.query_connection(
&opts.connection_id,
opts.height.try_into().unwrap(),
opts.proof,
)
.query_connection(&opts.connection_id, height)
.map_err(|e| Kind::Query.context(e).into());

match res {
Expand Down
12 changes: 8 additions & 4 deletions relayer-cli/src/commands/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ pub enum TxRawCommands {
#[options(help = "get usage information")]
Help(Help<Self>),

/// The `tx raw conn-init` subcommand
#[options(help = "tx raw conn-init")]
ConnInit(connection::TxRawConnInitCmd),

/// The `tx raw client-create` subcommand submits a MsgCreateClient in a transaction to a chain
#[options(help = "tx raw create-client")]
CreateClient(TxCreateClientCmd),

/// The `tx raw client-update` subcommand submits a MsgUpdateClient in a transaction to a chain
#[options(help = "tx raw update-client")]
UpdateClient(TxUpdateClientCmd),

/// The `tx raw conn-init` subcommand
#[options(help = "tx raw conn-init")]
ConnInit(connection::TxRawConnInitCmd),

/// The `tx raw conn-try` subcommand
#[options(help = "tx raw conn-try")]
ConnTry(connection::TxRawConnTryCmd),
}
22 changes: 7 additions & 15 deletions relayer-cli/src/commands/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use abscissa_core::{Command, Options, Runnable};

use ibc::ics24_host::identifier::ClientId;

use relayer::tx::client::{create_client, update_client, ClientOptions};
use relayer::tx::client::{
build_create_client_and_send, build_update_client_and_send, ClientOptions,
};

use crate::application::app_config;
use crate::error::{Error, Kind};
Expand All @@ -22,9 +24,6 @@ pub struct TxCreateClientCmd {
)]
dest_client_id: ClientId,

#[options(help = "account sequence of the signer", short = "s")]
account_sequence: u64,

#[options(
help = "json key file for the signer, must include mnemonic",
short = "k"
Expand All @@ -38,7 +37,6 @@ impl Runnable for TxCreateClientCmd {
&self.dest_chain_id,
&self.src_chain_id,
&self.dest_client_id,
self.account_sequence,
&self.seed_file,
) {
Err(err) => {
Expand All @@ -49,8 +47,8 @@ impl Runnable for TxCreateClientCmd {
};
status_info!("Message", "{:?}", opts);

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

match res {
Ok(receipt) => status_ok!("Success", "client created: {:?}", receipt),
Expand All @@ -73,9 +71,6 @@ pub struct TxUpdateClientCmd {
)]
dest_client_id: ClientId,

#[options(help = "account sequence of the signer", short = "s")]
account_sequence: u64,

#[options(
help = "json key file for the signer, must include mnemonic",
short = "k"
Expand All @@ -89,7 +84,6 @@ impl Runnable for TxUpdateClientCmd {
&self.dest_chain_id,
&self.src_chain_id,
&self.dest_client_id,
self.account_sequence,
&self.seed_file,
) {
Err(err) => {
Expand All @@ -100,8 +94,8 @@ impl Runnable for TxUpdateClientCmd {
};
status_info!("Message", "{:?}", opts);

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

match res {
Ok(receipt) => status_ok!("Success", "client updated: {:?}", receipt),
Expand All @@ -114,7 +108,6 @@ fn validate_common_options(
dest_chain_id: &str,
src_chain_id: &str,
dest_client_id: &ClientId,
account_sequence: u64,
seed_file: &str,
) -> Result<ClientOptions, String> {
let config = app_config();
Expand Down Expand Up @@ -150,6 +143,5 @@ fn validate_common_options(
dest_chain_config: dest_chain_config.clone(),
src_chain_config: src_chain_config.clone(),
signer_seed,
account_sequence,
})
}
95 changes: 91 additions & 4 deletions relayer-cli/src/commands/tx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use abscissa_core::{Command, Options, Runnable};
use ibc::ics24_host::identifier::{ClientId, ConnectionId};

use relayer::config::Config;
use relayer::tx::connection::{conn_init, ConnectionOpenInitOptions};
use relayer::tx::connection::{
build_conn_init_and_send, build_conn_try_and_send, ConnectionOpenInitOptions,
ConnectionOpenTryOptions,
};

use crate::error::{Error, Kind};

Expand Down Expand Up @@ -43,6 +46,7 @@ impl TxRawConnInitCmd {
.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()
Expand All @@ -54,12 +58,12 @@ impl TxRawConnInitCmd {
})?;

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

Expand All @@ -80,11 +84,94 @@ impl Runnable for TxRawConnInitCmd {
};
status_info!("Message", "{:?}", opts);

let res: Result<Vec<u8>, Error> = conn_init(&opts).map_err(|e| Kind::Tx.context(e).into());
let res: Result<String, Error> =
build_conn_init_and_send(&opts).map_err(|e| Kind::Tx.context(e).into());

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

#[derive(Clone, Command, Debug, Options)]
pub struct TxRawConnTryCmd {
#[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 TxRawConnTryCmd {
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenTryOptions, 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 = ConnectionOpenTryOptions {
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 TxRawConnTryCmd {
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_try_and_send(opts).map_err(|e| Kind::Tx.context(e).into());

match res {
Ok(receipt) => status_info!("conn try, result: ", "{:?}", receipt),
Err(e) => status_info!("conn try failed, error: ", "{}", e),
}
}
}
6 changes: 4 additions & 2 deletions relayer-cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ fn query_channel_id() {
Height::from(0_u32),
false,
)
.unwrap(),
.unwrap()
.value,
)
.unwrap();

Expand All @@ -117,7 +118,8 @@ fn query_client_id() {
Height::from(0_u32),
false,
)
.unwrap(),
.unwrap()
.value,
)
.unwrap();

Expand Down
Loading

0 comments on commit 9a4aef5

Please sign in to comment.