Skip to content

Commit

Permalink
【mainnet-fix】:hanle err when cal gasUsed (#401)
Browse files Browse the repository at this point in the history
【mainnet-fix】:hanle err when cal gasUsed (#401)
  • Loading branch information
scf0220 authored Oct 21, 2019
1 parent 3fcfe52 commit 852f21b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,23 @@ 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
}
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)
Expand Down

0 comments on commit 852f21b

Please sign in to comment.