From 110d9d88770115c16aa34500261e28e3aa177cc3 Mon Sep 17 00:00:00 2001 From: Danil Nemirovsky Date: Tue, 15 Oct 2024 16:37:53 +0100 Subject: [PATCH] feat: Record transaction with non-native fees (#4683) ### Description Record transaction with non-native fees. Fees will be recorded as a huge number: max value of unsigned 256-bit long integer. ### Backward compatibility Yes ### Testing Manual testing of Scraper Co-authored-by: Danil Nemirovsky <4614623+ameten@users.noreply.github.com> --- .../src/providers/cosmos/provider.rs | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/rust/main/chains/hyperlane-cosmos/src/providers/cosmos/provider.rs b/rust/main/chains/hyperlane-cosmos/src/providers/cosmos/provider.rs index c3e6cb114..491f19776 100644 --- a/rust/main/chains/hyperlane-cosmos/src/providers/cosmos/provider.rs +++ b/rust/main/chains/hyperlane-cosmos/src/providers/cosmos/provider.rs @@ -330,6 +330,29 @@ impl CosmosProvider { amount_in_native_denom * coefficient } + + fn calculate_gas_price(&self, hash: &H256, tx: &Tx) -> U256 { + // TODO support multiple denominations for amount + let supported = self.report_unsupported_denominations(tx, hash); + if supported.is_err() { + return U256::max_value(); + } + + let gas_limit = U256::from(tx.auth_info.fee.gas_limit); + let fee = tx + .auth_info + .fee + .amount + .iter() + .map(|c| self.convert_fee(c)) + .fold(U256::zero(), |acc, v| acc + v); + + if fee < gas_limit { + warn!(tx_hash = ?hash, ?fee, ?gas_limit, "calculated fee is less than gas limit. it will result in zero gas price"); + } + + fee / gas_limit + } } impl HyperlaneChain for CosmosProvider { @@ -395,26 +418,7 @@ impl HyperlaneProvider for CosmosProvider { let contract = Self::contract(&tx, hash)?; let (sender, nonce) = self.sender_and_nonce(&tx)?; - - // TODO support multiple denominations for amount - self.report_unsupported_denominations(&tx, hash)?; - - let gas_limit = U256::from(tx.auth_info.fee.gas_limit); - let fee = tx - .auth_info - .fee - .amount - .iter() - .map(|c| self.convert_fee(c)) - .fold(U256::zero(), |acc, v| acc + v); - - let gas_price = fee / gas_limit; - let gas_price = if gas_price == U256::zero() { - warn!(?fee, ?gas_limit, "calculated zero gas price"); - U256::one() - } else { - gas_price - }; + let gas_price = self.calculate_gas_price(hash, &tx); let tx_info = TxnInfo { hash: hash.to_owned(),