From eacbfcddff7808cd31b693effbb5159456228adf Mon Sep 17 00:00:00 2001 From: Roman Proskuryakoff Date: Fri, 22 Mar 2024 20:04:56 +0800 Subject: [PATCH] Fix: calc l1 fee unconditionally but deduct only if tx is ok --- .../module-implementations/sov-evm/src/evm/handler.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/module-system/module-implementations/sov-evm/src/evm/handler.rs b/module-system/module-implementations/sov-evm/src/evm/handler.rs index 6c9e6d3f8..7cd063c47 100644 --- a/module-system/module-implementations/sov-evm/src/evm/handler.rs +++ b/module-system/module-implementations/sov-evm/src/evm/handler.rs @@ -103,11 +103,12 @@ impl CitreaHandler { context: &mut Context, result: FrameResult, ) -> Result::Error>> { - if !result.interpreter_result().is_error() { - let diff_size = calc_diff_size(context).map_err(EVMError::Database)? as u64; - let l1_fee_rate = U256::from(context.external.l1_fee_rate()); - let l1_fee = U256::from(diff_size) * l1_fee_rate; - context.external.set_tx_info(TxInfo { diff_size }); + let diff_size = calc_diff_size(context).map_err(EVMError::Database)? as u64; + let l1_fee_rate = U256::from(context.external.l1_fee_rate()); + let l1_fee = U256::from(diff_size) * l1_fee_rate; + context.external.set_tx_info(TxInfo { diff_size }); + if result.interpreter_result().is_ok() { + // Deduct L1 fee only if tx is successful. if let Some(_out_of_funds) = decrease_caller_balance(context, l1_fee)? { return Err(EVMError::Custom(format!( "Not enought funds for L1 fee: {}",