Skip to content

Commit

Permalink
Use send_tx directly in ChainDriver for integration test (informa…
Browse files Browse the repository at this point in the history
…lsystems#2205)

* Add simple_send_tx

Introduce TxConfig

Add test constructor for TxConfig

Add send_tx method on ChainDriver

Accept Wallet instead of WalletAddress for transferring tokens

Implement ibc_token_transfer

Simplify ibc_token_transfer

Token transfer using ibc_token_transfer is now working

* Move AddressType into TxConfig, as it is configured per chain

* Disable GRPC Web and not rely on chain version

* Clean up ibc_transfer_token interface on ChainDriver

* Use longer IBC transfer timeout

* Further increase IBC transfer timeout

* Fix client expiration test in gaia7

* Move tx_raw_ft_transfer to simulation test

* Modularize ibc_token_transfer
  • Loading branch information
soareschen authored May 11, 2022
1 parent a110e09 commit 8d6ffa9
Show file tree
Hide file tree
Showing 44 changed files with 611 additions and 376 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ use crate::chain::cosmos::query::status::query_status;
use crate::chain::cosmos::query::tx::query_txs;
use crate::chain::cosmos::query::{abci_query, fetch_version_specs, packet_query};
use crate::chain::cosmos::types::account::Account;
use crate::chain::cosmos::types::config::TxConfig;
use crate::chain::cosmos::types::gas::{default_gas_from_config, max_gas_from_config};
use crate::chain::tx::TrackedMsgs;
use crate::chain::{ChainEndpoint, HealthCheck};
Expand Down Expand Up @@ -103,6 +104,7 @@ pub const GENESIS_MAX_BYTES_MAX_FRACTION: f64 = 0.9;

pub struct CosmosSdkChain {
config: ChainConfig,
tx_config: TxConfig,
rpc_client: HttpClient,
grpc_addr: Uri,
rt: Arc<TokioRuntime>,
Expand Down Expand Up @@ -402,10 +404,9 @@ impl CosmosSdkChain {
get_or_fetch_account(&self.grpc_addr, &key_entry.account, &mut self.account).await?;

send_batched_messages_and_wait_commit(
&self.config,
&self.rpc_client,
&self.config.rpc_addr,
&self.grpc_addr,
&self.tx_config,
self.config.max_msg_num,
self.config.max_tx_size,
&key_entry,
account,
&self.config.memo_prefix,
Expand All @@ -431,9 +432,9 @@ impl CosmosSdkChain {
get_or_fetch_account(&self.grpc_addr, &key_entry.account, &mut self.account).await?;

send_batched_messages_and_wait_check_tx(
&self.config,
&self.rpc_client,
&self.grpc_addr,
&self.tx_config,
self.config.max_msg_num,
self.config.max_tx_size,
&key_entry,
account,
&self.config.memo_prefix,
Expand Down Expand Up @@ -461,6 +462,8 @@ impl ChainEndpoint for CosmosSdkChain {
let grpc_addr = Uri::from_str(&config.grpc_addr.to_string())
.map_err(|e| Error::invalid_uri(config.grpc_addr.to_string(), e))?;

let tx_config = TxConfig::try_from(&config)?;

// Retrieve the version specification of this chain

let chain = Self {
Expand All @@ -470,6 +473,7 @@ impl ChainEndpoint for CosmosSdkChain {
rt,
keybase,
account: None,
tx_config,
};

Ok(chain)
Expand Down
77 changes: 31 additions & 46 deletions relayer/src/chain/cosmos/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ use ibc::events::IbcEvent;
use ibc_proto::google::protobuf::Any;
use prost::Message;
use tendermint_rpc::endpoint::broadcast::tx_sync::Response;
use tendermint_rpc::{HttpClient, Url};
use tonic::codegen::http::Uri;

use crate::chain::cosmos::retry::send_tx_with_account_sequence_retry;
use crate::chain::cosmos::types::account::Account;
use crate::chain::cosmos::types::config::TxConfig;
use crate::chain::cosmos::types::tx::TxSyncResult;
use crate::chain::cosmos::wait::wait_for_block_commits;
use crate::config::types::Memo;
use crate::config::ChainConfig;
use crate::config::types::{MaxMsgNum, MaxTxSize, Memo};
use crate::error::Error;
use crate::keyring::KeyEntry;

pub async fn send_batched_messages_and_wait_commit(
config: &ChainConfig,
rpc_client: &HttpClient,
rpc_address: &Url,
grpc_address: &Uri,
config: &TxConfig,
max_msg_num: MaxMsgNum,
max_tx_size: MaxTxSize,
key_entry: &KeyEntry,
account: &mut Account,
tx_memo: &Memo,
Expand All @@ -30,8 +27,8 @@ pub async fn send_batched_messages_and_wait_commit(

let mut tx_sync_results = send_messages_as_batches(
config,
rpc_client,
grpc_address,
max_msg_num,
max_tx_size,
key_entry,
account,
tx_memo,
Expand All @@ -40,9 +37,9 @@ pub async fn send_batched_messages_and_wait_commit(
.await?;

wait_for_block_commits(
&config.id,
rpc_client,
rpc_address,
&config.chain_id,
&config.rpc_client,
&config.rpc_address,
&config.rpc_timeout,
&mut tx_sync_results,
)
Expand All @@ -57,9 +54,9 @@ pub async fn send_batched_messages_and_wait_commit(
}

pub async fn send_batched_messages_and_wait_check_tx(
config: &ChainConfig,
rpc_client: &HttpClient,
grpc_address: &Uri,
config: &TxConfig,
max_msg_num: MaxMsgNum,
max_tx_size: MaxTxSize,
key_entry: &KeyEntry,
account: &mut Account,
tx_memo: &Memo,
Expand All @@ -69,22 +66,14 @@ pub async fn send_batched_messages_and_wait_check_tx(
return Ok(Vec::new());
}

let batches = batch_messages(config, messages)?;
let batches = batch_messages(max_msg_num, max_tx_size, messages)?;

let mut responses = Vec::new();

for batch in batches {
let response = send_tx_with_account_sequence_retry(
config,
rpc_client,
grpc_address,
key_entry,
account,
tx_memo,
batch,
0,
)
.await?;
let response =
send_tx_with_account_sequence_retry(config, key_entry, account, tx_memo, batch, 0)
.await?;

responses.push(response);
}
Expand All @@ -93,9 +82,9 @@ pub async fn send_batched_messages_and_wait_check_tx(
}

async fn send_messages_as_batches(
config: &ChainConfig,
rpc_client: &HttpClient,
grpc_address: &Uri,
config: &TxConfig,
max_msg_num: MaxMsgNum,
max_tx_size: MaxTxSize,
key_entry: &KeyEntry,
account: &mut Account,
tx_memo: &Memo,
Expand All @@ -105,24 +94,16 @@ async fn send_messages_as_batches(
return Ok(Vec::new());
}

let batches = batch_messages(config, messages)?;
let batches = batch_messages(max_msg_num, max_tx_size, messages)?;

let mut tx_sync_results = Vec::new();

for batch in batches {
let events_per_tx = vec![IbcEvent::default(); batch.len()];

let response = send_tx_with_account_sequence_retry(
config,
rpc_client,
grpc_address,
key_entry,
account,
tx_memo,
batch,
0,
)
.await?;
let response =
send_tx_with_account_sequence_retry(config, key_entry, account, tx_memo, batch, 0)
.await?;

let tx_sync_result = TxSyncResult {
response,
Expand All @@ -135,9 +116,13 @@ async fn send_messages_as_batches(
Ok(tx_sync_results)
}

fn batch_messages(config: &ChainConfig, messages: Vec<Any>) -> Result<Vec<Vec<Any>>, Error> {
let max_message_count = config.max_msg_num.to_usize();
let max_tx_size = config.max_tx_size.into();
fn batch_messages(
max_msg_num: MaxMsgNum,
max_tx_size: MaxTxSize,
messages: Vec<Any>,
) -> Result<Vec<Vec<Any>>, Error> {
let max_message_count = max_msg_num.to_usize();
let max_tx_size = max_tx_size.into();

let mut batches = vec![];

Expand Down
8 changes: 4 additions & 4 deletions relayer/src/chain/cosmos/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use ibc_proto::google::protobuf::Any;
use tendermint::account::Id as AccountId;

use crate::chain::cosmos::types::account::{Account, AccountNumber, AccountSequence};
use crate::chain::cosmos::types::config::TxConfig;
use crate::chain::cosmos::types::tx::SignedTx;
use crate::config::types::Memo;
use crate::config::AddressType;
use crate::config::ChainConfig;
use crate::error::Error;
use crate::keyring::{sign_message, KeyEntry};

pub fn sign_and_encode_tx(
config: &ChainConfig,
config: &TxConfig,
key_entry: &KeyEntry,
account: &Account,
tx_memo: &Memo,
Expand All @@ -34,7 +34,7 @@ pub fn sign_and_encode_tx(
}

pub fn sign_tx(
config: &ChainConfig,
config: &TxConfig,
key_entry: &KeyEntry,
account: &Account,
tx_memo: &Memo,
Expand All @@ -50,7 +50,7 @@ pub fn sign_tx(
let (auth_info, auth_info_bytes) = auth_info_and_bytes(signer, fee.clone())?;

let signed_doc = encode_sign_doc(
&config.id,
&config.chain_id,
key_entry,
&config.address_type,
account.number,
Expand Down
10 changes: 5 additions & 5 deletions relayer/src/chain/cosmos/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ use crate::chain::cosmos::encode::sign_tx;
use crate::chain::cosmos::gas::{gas_amount_to_fees, PrettyFee};
use crate::chain::cosmos::simulate::send_tx_simulate;
use crate::chain::cosmos::types::account::Account;
use crate::chain::cosmos::types::config::TxConfig;
use crate::chain::cosmos::types::gas::GasConfig;
use crate::config::types::Memo;
use crate::config::ChainConfig;
use crate::error::Error;
use crate::keyring::KeyEntry;

pub async fn estimate_tx_fees(
config: &ChainConfig,
grpc_address: &Uri,
config: &TxConfig,
key_entry: &KeyEntry,
account: &Account,
tx_memo: &Memo,
messages: Vec<Any>,
) -> Result<Fee, Error> {
let gas_config = GasConfig::from_chain_config(config);
let gas_config = &config.gas_config;

debug!(
"max fee, for use in tx simulation: {}",
Expand All @@ -44,7 +43,8 @@ pub async fn estimate_tx_fees(
signatures: signed_tx.signatures,
};

let estimated_fee = estimate_fee_with_tx(&gas_config, grpc_address, &config.id, tx).await?;
let estimated_fee =
estimate_fee_with_tx(gas_config, &config.grpc_address, &config.chain_id, tx).await?;

Ok(estimated_fee)
}
Expand Down
5 changes: 4 additions & 1 deletion relayer/src/chain/cosmos/query/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub async fn refresh_account<'a>(
}

/// Uses the GRPC client to retrieve the account sequence
async fn query_account(grpc_address: &Uri, account_address: &str) -> Result<BaseAccount, Error> {
pub async fn query_account(
grpc_address: &Uri,
account_address: &str,
) -> Result<BaseAccount, Error> {
let mut client = QueryClient::connect(grpc_address.clone())
.await
.map_err(Error::grpc_transport)?;
Expand Down
Loading

0 comments on commit 8d6ffa9

Please sign in to comment.