Skip to content

Commit

Permalink
Charge gas for failed transaction (#3659)
Browse files Browse the repository at this point in the history
Co-authored-by: bzawisto <bartosz@zilliqa.com>
  • Loading branch information
bzawisto and bzawisto committed Jun 13, 2023
1 parent aa38673 commit 8e8d37e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/libCps/CpsExecutor.cpp
Expand Up @@ -170,6 +170,18 @@ CpsExecuteResult CpsExecutor::RunFromScilla(

// Increase nonce regardless of processing result
mAccountStore.IncreaseNonceForAccount(cpsCtx.origSender);
// Deduct from account balance gas used for failed transaction
if (isFailure) {
const auto usedGasCore = clientContext.gasLimit - gasRemainedCore;
uint128_t gasCost;
// Convert here because we deducted in eth units.
if (!SafeMath<uint128_t>::mul(usedGasCore, clientContext.gasPrice,
gasCost)) {
return {TxnStatus::ERROR, false, {}};
}
const auto amount = Amount::fromQa(gasCost);
mAccountStore.DecreaseBalance(cpsCtx.origSender, amount);
}
return execResult;
}

Expand Down

0 comments on commit 8e8d37e

Please sign in to comment.