Skip to content

Commit

Permalink
Fix: calc l1 fee unconditionally but deduct only if tx is ok
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed Mar 22, 2024
1 parent 1b67ba9 commit eacbfcd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions module-system/module-implementations/sov-evm/src/evm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ impl<EXT: CitreaHandlerContext, DB: Database> CitreaHandler<EXT, DB> {
context: &mut Context<EXT, DB>,
result: FrameResult,
) -> Result<ResultAndState, EVMError<<DB as Database>::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: {}",
Expand Down

0 comments on commit eacbfcd

Please sign in to comment.