Skip to content

Commit

Permalink
for Namada 3428 - Improve gas interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Jul 9, 2024
1 parent 5550adf commit c2fce62
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 61 deletions.
88 changes: 44 additions & 44 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ tendermint-rpc = { version = "=0.36.0" }
tendermint-testgen = { version = "=0.36.0" }

# Namada dependencies
namada_ibc = { git = "https://github.com/anoma/namada", rev = "59332a22943e47c74cfcec4a2d08281822ba75f9" }
namada_parameters = { git = "https://github.com/anoma/namada", rev = "59332a22943e47c74cfcec4a2d08281822ba75f9" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "59332a22943e47c74cfcec4a2d08281822ba75f9" }
namada_token = { git = "https://github.com/anoma/namada", rev = "59332a22943e47c74cfcec4a2d08281822ba75f9" }
namada_ibc = { git = "https://github.com/anoma/namada", rev = "4f0b027da53c10e600e61c54a6900b4fba485726" }
namada_parameters = { git = "https://github.com/anoma/namada", rev = "4f0b027da53c10e600e61c54a6900b4fba485726" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "4f0b027da53c10e600e61c54a6900b4fba485726" }
namada_token = { git = "https://github.com/anoma/namada", rev = "4f0b027da53c10e600e61c54a6900b4fba485726" }

# Other dependencies
abscissa_core = "=0.6.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/src/chain/namada/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ define_error! {
|_| { "borsh decoding failed" },

DryRun
{ tx_results: namada_sdk::tx::data::BatchResults<String> }
|e| { format!("Dry run to simulate a transaction failed: {:?}", e.tx_results) },
{ tx_result: namada_sdk::tx::data::TxResult<String> }
|e| { format!("Dry run to simulate a transaction failed: {:?}", e.tx_result) },
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/namada/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl NamadaChain {
height,
)]);
}
let events = tx_result.batch_results.iter().filter_map(|(_, r)| {
let events = tx_result.iter().filter_map(|(_, r)| {
r.as_ref().map(|batched_tx_result| {
// Get IBC events when the transaction was accepted
if batched_tx_result.is_accepted() {
Expand Down
13 changes: 3 additions & 10 deletions crates/relayer/src/chain/namada/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use std::time::Instant;

use ibc_proto::google::protobuf::Any;
use itertools::Itertools;
use namada_parameters::storage as param_storage;
use namada_sdk::address::{Address, ImplicitAddress};
use namada_sdk::args::TxBuilder;
use namada_sdk::args::{Tx as TxArgs, TxCustom};
use namada_sdk::borsh::BorshDeserialize;
use namada_sdk::chain::ChainId;
use namada_sdk::tx::{prepare_tx, ProcessTxResponse};
use namada_sdk::{signing, tx, Namada};
Expand All @@ -22,7 +20,6 @@ use crate::chain::cosmos::types::gas::max_gas_from_config;
use crate::chain::cosmos::types::tx::{TxStatus, TxSyncResult};
use crate::chain::cosmos::wait::all_tx_results_found;
use crate::chain::endpoint::ChainEndpoint;
use crate::chain::requests::{IncludeProof, QueryHeight};
use crate::error::{Error, ErrorDetail};

use super::error::{Error as NamadaError, ErrorDetail as NamadaErrorDetail};
Expand Down Expand Up @@ -170,10 +167,6 @@ impl NamadaChain {
let max_gas = max_gas_from_config(self.config());
let gas_price = self.config().gas_price.price;

let gas_scale_key = param_storage::get_gas_scale_key();
let (value, _) = self.query(gas_scale_key, QueryHeight::Latest, IncludeProof::No)?;
let gas_scale = u64::try_from_slice(&value[..]).map_err(NamadaError::borsh_decode)?;

let args = args.clone().dry_run_wrapper(true);
// Set the max gas to the gas limit for the simulation
self.prepare_tx_with_gas(&mut tx, &args, &fee_token, max_gas, gas_price)?;
Expand Down Expand Up @@ -201,14 +194,14 @@ impl NamadaChain {
let estimated_gas = match response {
ProcessTxResponse::DryRun(result) => {
if result
.batch_results
.0
.iter()
.all(|(_, r)| matches!(&r, Ok(result) if result.is_accepted()))
{
result.gas_used.get_whole_gas_units(gas_scale)
result.1.into()
} else {
// All or some of requests will fail
return Err(NamadaError::dry_run(result.batch_results).into());
return Err(NamadaError::dry_run(result.0).into());
}
}
_ => unreachable!("Unexpected response"),
Expand Down
3 changes: 3 additions & 0 deletions e2e/namada-gaia-simple-transfers
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ ${NAMADAC} --base-dir ${base_dir} ibc-transfer \
--amount 50 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${NAMADA_LEDGER_ADDR}

# packet-recv
Expand Down Expand Up @@ -207,6 +208,7 @@ ${NAMADAC} --base-dir ${base_dir} ibc-transfer \
--amount 200 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${NAMADA_LEDGER_ADDR}

# wait for relaying
Expand Down Expand Up @@ -324,6 +326,7 @@ ${NAMADAC} --base-dir ${base_dir} ibc-transfer \
--amount 5 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${NAMADA_LEDGER_ADDR}

# wait for relaying
Expand Down
6 changes: 6 additions & 0 deletions e2e/namada-simple-transfers
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ ${NAMADAC} --base-dir ${base_dir_a} ibc-transfer \
--amount 100 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${LEDGER_ADDR_A}

# packet-recv
Expand Down Expand Up @@ -198,6 +199,7 @@ ${NAMADAC} --base-dir ${base_dir_b} ibc-transfer \
--amount 50000000 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${LEDGER_ADDR_B}

# packet-recv
Expand Down Expand Up @@ -250,6 +252,7 @@ ${NAMADAC} --base-dir ${base_dir_a} ibc-transfer \
--amount 200 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${LEDGER_ADDR_A}

echo "~~ Transfer 300 apfel from chain B to chain A ~~"
Expand All @@ -260,6 +263,7 @@ ${NAMADAC} --base-dir ${base_dir_b} ibc-transfer \
--amount 300 \
--signing-keys relayer \
--channel-id channel-0 \
--gas-limit 150000 \
--node ${LEDGER_ADDR_B}

wait_for_relaying ${chain_a}
Expand Down Expand Up @@ -329,6 +333,7 @@ ${NAMADAC} --base-dir ${base_dir_a} ibc-transfer \
--channel-id channel-0 \
--memo-path ${memo_path} \
--gas-payer relayer \
--gas-limit 150000 \
--node ${LEDGER_ADDR_A}

wait_for_relaying ${chain_a}
Expand Down Expand Up @@ -419,6 +424,7 @@ ${NAMADAC} --base-dir ${base_dir_b} ibc-transfer \
--signing-keys relayer \
--channel-id channel-0 \
--memo-path ${memo_path} \
--gas-limit 150000 \
--node ${LEDGER_ADDR_B}

wait_for_relaying ${chain_a}
Expand Down
Loading

0 comments on commit c2fce62

Please sign in to comment.