diff --git a/core/state_transition.go b/core/state_transition.go index f285fdb11..ff46ffcb4 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -252,7 +252,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo return nil, 0, false, vmerr } } - st.refundGas() + st.refundGas(vmerr) st.chargeFee(st.gasUsed()) if vmerr == vm.ErrPoSWSenderNotAllowed { return nil, st.gasUsed(), true, nil @@ -260,13 +260,15 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo return ret, st.gasUsed(), vmerr != nil, err } -func (st *StateTransition) refundGas() { +func (st *StateTransition) refundGas(vmerr error) { // Apply refund counter, capped to half of the used gas. - refund := st.gasUsed() / 2 - if refund > st.state.GetRefund() { - refund = st.state.GetRefund() + if vmerr == nil { + refund := st.gasUsed() / 2 + if refund > st.state.GetRefund() { + refund = st.state.GetRefund() + } + st.gas += refund } - st.gas += refund // Return ETH for remaining gas, exchanged at the original rate. remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gas), st.gasPrice)