Skip to content

Commit

Permalink
mod usedSGTBalance outside
Browse files Browse the repository at this point in the history
  • Loading branch information
blockchaindevsh committed Oct 29, 2024
1 parent 3d5c5a9 commit d5c1a66
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ func (st *StateTransition) subSoulBalance(account common.Address, amount *uint25
st.state.SubBalance(types.SoulGasTokenAddr, amount, reason)
}

// subSoulBalance is only called by buyGas once
st.usedSGTBalance = amount
return
}

Expand All @@ -422,7 +420,6 @@ func (st *StateTransition) addSoulBalance(account common.Address, amount *uint25
if st.evm.ChainConfig().IsOptimism() && st.evm.ChainConfig().Optimism.IsSoulBackedByNative {
st.state.AddBalance(types.SoulGasTokenAddr, amount, reason)
}
st.usedSGTBalance.Sub(st.usedSGTBalance, amount)
}

func (st *StateTransition) buyGas() error {
Expand Down Expand Up @@ -497,12 +494,17 @@ func (st *StateTransition) buyGas() error {
st.state.SubBalance(st.msg.From, mgvalU256, tracing.BalanceDecreaseGasBuy)
} else {
if mgvalU256.Cmp(soulBalance) <= 0 {
return st.subSoulBalance(st.msg.From, mgvalU256, tracing.BalanceDecreaseGasBuy)
err := st.subSoulBalance(st.msg.From, mgvalU256, tracing.BalanceDecreaseGasBuy)
if err != nil {
return err
}
st.usedSGTBalance = mgvalU256
} else {
err := st.subSoulBalance(st.msg.From, soulBalance, tracing.BalanceDecreaseGasBuy)
if err != nil {
return err
}
st.usedSGTBalance = soulBalance
// when both SGT and native balance are used, we record both amounts for refund.
// the priority for refund is: first native, then SGT
usedNativeBalance := new(uint256.Int).Sub(mgvalU256, soulBalance)
Expand Down Expand Up @@ -884,6 +886,7 @@ func (st *StateTransition) refundGas(refundQuotient uint64) uint64 {
}
if sgt.Sign() > 0 {
st.addSoulBalance(st.msg.From, sgt, tracing.BalanceIncreaseGasReturn)
st.usedSGTBalance.Sub(st.usedSGTBalance, sgt)
}
}

Expand Down

0 comments on commit d5c1a66

Please sign in to comment.