Skip to content

Commit

Permalink
use max_block_gas for tx max_gas unless configured
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Sep 27, 2024
1 parent bee2448 commit 10572b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
5 changes: 5 additions & 0 deletions crates/relayer/src/chain/cosmos/types/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub fn max_gas_from_config(config: &CosmosSdkConfig) -> u64 {
config.max_gas.unwrap_or(DEFAULT_MAX_GAS)
}

/// The maximum amount of gas the relayer is willing to pay for a transaction
pub fn max_gas_from_config_opt(config: &CosmosSdkConfig) -> Option<u64> {
config.max_gas
}

/// The gas multiplier
pub fn gas_multiplier_from_config(config: &CosmosSdkConfig) -> f64 {
config.gas_multiplier.unwrap_or_default().to_f64()
Expand Down
25 changes: 9 additions & 16 deletions crates/relayer/src/chain/namada/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tendermint_rpc::endpoint::broadcast::tx_sync::Response;
use tracing::{debug, debug_span, trace, warn};

use crate::chain::cosmos::gas::{adjust_estimated_gas, AdjustGas};
use crate::chain::cosmos::types::gas::max_gas_from_config;
use crate::chain::cosmos::types::gas::max_gas_from_config_opt;
use crate::chain::cosmos::types::tx::{TxStatus, TxSyncResult};
use crate::chain::cosmos::wait::all_tx_results_found;
use crate::chain::endpoint::ChainEndpoint;
Expand Down Expand Up @@ -165,24 +165,17 @@ impl NamadaChain {
let fee_token_str = self.config.gas_price.denom.clone();
let fee_token = Address::from_str(&fee_token_str)
.map_err(|_| NamadaError::address_decode(fee_token_str.clone()))?;
let max_gas = max_gas_from_config(&self.config);
let gas_price = self.config.gas_price.price;

let max_block_gas_key = namada_sdk::parameters::storage::get_max_block_gas_key();
let max_block_gas: u64 = match self.rt.block_on(rpc::query_storage_value(
self.ctx.client(),
&max_block_gas_key,
)) {
Ok(max_block_gas) => max_block_gas,
Err(e) => {
warn!(
id = %chain_id,
"estimate_fee: error while querying max block gas, defaulting to config default. Error: {}",
e
);
max_gas
}
};
let max_block_gas: u64 = self
.rt
.block_on(rpc::query_storage_value(
self.ctx.client(),
&max_block_gas_key,
))
.map_err(NamadaError::namada)?;
let max_gas = max_gas_from_config_opt(&self.config).unwrap_or(max_block_gas);

let args = args.clone().dry_run_wrapper(true);
// Set the max gas to the gas limit for the simulation
Expand Down

0 comments on commit 10572b2

Please sign in to comment.