diff --git a/evm_loader/program/src/account/state.rs b/evm_loader/program/src/account/state.rs index 4f00f8df1..50ca97073 100644 --- a/evm_loader/program/src/account/state.rs +++ b/evm_loader/program/src/account/state.rs @@ -327,7 +327,7 @@ impl<'a> StateAccount<'a> { } #[must_use] - fn gas_available(&self) -> U256 { + pub fn gas_available(&self) -> U256 { self.trx().gas_limit().saturating_sub(self.gas_used()) } diff --git a/evm_loader/program/src/instruction/transaction_cancel.rs b/evm_loader/program/src/instruction/transaction_cancel.rs index 86e30e046..1f3af0d6b 100644 --- a/evm_loader/program/src/instruction/transaction_cancel.rs +++ b/evm_loader/program/src/instruction/transaction_cancel.rs @@ -1,3 +1,5 @@ +use std::cmp::min; + use crate::account::{AccountsDB, BalanceAccount, Operator, OperatorBalanceAccount, StateAccount}; use crate::config::DEFAULT_CHAIN_ID; use crate::debug::log_data; @@ -53,17 +55,20 @@ fn execute<'a>( ) -> Result<()> { let trx_chain_id = storage.trx().chain_id().unwrap_or(DEFAULT_CHAIN_ID); - let used_gas = U256::ZERO; - let total_used_gas = storage.gas_used(); + let used_gas = min( + storage.gas_available(), + U256::from(CANCEL_TRX_COST + LAST_ITERATION_COST), + ); + let total_used_gas = storage.gas_used() + used_gas; + log_data(&[ b"GAS", &used_gas.to_le_bytes(), &total_used_gas.to_le_bytes(), ]); - let gas = U256::from(CANCEL_TRX_COST + LAST_ITERATION_COST); - let priority_fee = priority_fee_txn_calculator::handle_priority_fee(storage.trx(), gas)?; - let _ = storage.consume_gas(gas, priority_fee, accounts.try_operator_balance()); // ignore error + let priority_fee = priority_fee_txn_calculator::handle_priority_fee(storage.trx(), used_gas)?; + let _ = storage.consume_gas(used_gas, priority_fee, accounts.try_operator_balance()); // ignore error let origin = storage.trx_origin(); let (origin_pubkey, _) = origin.find_balance_address(program_id, trx_chain_id);