Skip to content

Commit 672fda2

Browse files
committed
rename gasRemaining
1 parent 515303f commit 672fda2

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

core/state_transition.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ The state transitioning model does all the necessary work to work out a valid ne
9595

9696
// StateTransition is the state of current tx in vm
9797
type StateTransition struct {
98-
gp *GasPool
99-
qp *QuotaPool
100-
msg *Message
101-
gas uint64
102-
initialGas uint64
103-
state vm.StateDB
104-
cvm *vm.CVM
105-
modelGas map[common.Address]uint64
98+
gp *GasPool
99+
qp *QuotaPool
100+
msg *Message
101+
gasRemaining uint64
102+
initialGas uint64
103+
state vm.StateDB
104+
cvm *vm.CVM
105+
modelGas map[common.Address]uint64
106106
}
107107

108108
type Message struct {
@@ -203,10 +203,10 @@ func (st *StateTransition) to() common.Address {
203203
}
204204

205205
//func (st *StateTransition) useGas(amount uint64) error {
206-
// if st.gas < amount {
206+
// if st.gasRemaining < amount {
207207
// return vm.ErrOutOfGas
208208
// }
209-
// st.gas -= amount
209+
// st.gasRemaining -= amount
210210
//
211211
// return nil
212212
//}
@@ -219,7 +219,7 @@ func (st *StateTransition) buyGas() error {
219219
if err := st.gp.SubGas(st.msg.GasLimit); err != nil {
220220
return err
221221
}
222-
st.gas = st.msg.GasLimit
222+
st.gasRemaining = st.msg.GasLimit
223223

224224
st.initialGas = st.msg.GasLimit
225225
st.state.SubBalance(st.msg.From, mgval)
@@ -314,10 +314,10 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
314314
if err != nil {
315315
return nil, err
316316
}
317-
if st.gas < gas {
318-
return nil, fmt.Errorf("%w: have %d, want %d", vm.ErrOutOfGas, st.gas, gas)
317+
if st.gasRemaining < gas {
318+
return nil, fmt.Errorf("%w: have %d, want %d", vm.ErrOutOfGas, st.gasRemaining, gas)
319319
}
320-
st.gas -= gas
320+
st.gasRemaining -= gas
321321

322322
if msg.Value.Sign() > 0 && !st.cvm.Context.CanTransfer(st.state, msg.From, msg.Value) {
323323
return nil, fmt.Errorf("%w: address %v", ErrInsufficientFundsForTransfer, msg.From.Hex())
@@ -336,14 +336,14 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
336336
vmerr error
337337
)
338338
if contractCreation {
339-
ret, _, st.gas, st.modelGas, vmerr = st.cvm.Create(msg.From, msg.Data, st.gas, msg.Value)
339+
ret, _, st.gasRemaining, st.modelGas, vmerr = st.cvm.Create(msg.From, msg.Data, st.gasRemaining, msg.Value)
340340
} else {
341341
// Increment the nonce for the next transaction
342342
//if pool.config.NoInfers && asm.HasInferOp(tx.Data()) {
343343
// fmt.Println("Has INFER operation !!! continue ...")
344344
//}
345345
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1)
346-
ret, st.gas, st.modelGas, vmerr = st.cvm.Call(msg.From, st.to(), msg.Data, st.gas, msg.Value)
346+
ret, st.gasRemaining, st.modelGas, vmerr = st.cvm.Call(msg.From, st.to(), msg.Data, st.gasRemaining, msg.Value)
347347
}
348348

349349
if vmerr != nil {
@@ -417,7 +417,7 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
417417

418418
// vote to model
419419
func (st *StateTransition) uploading() bool {
420-
return st.msg != nil && st.msg.To != nil && st.msg.Value.Sign() == 0 && st.state.Uploading(st.to()) // && st.gas >= params.UploadGas
420+
return st.msg != nil && st.msg.To != nil && st.msg.Value.Sign() == 0 && st.state.Uploading(st.to()) // && st.gasRemaining >= params.UploadGas
421421
}
422422

423423
func (st *StateTransition) refundGas() uint64 {
@@ -426,20 +426,20 @@ func (st *StateTransition) refundGas() uint64 {
426426
if refund > st.state.GetRefund() {
427427
refund = st.state.GetRefund()
428428
}
429-
st.gas += refund
429+
st.gasRemaining += refund
430430

431431
// Return ETH for remaining gas, exchanged at the original rate.
432-
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gas), st.msg.GasPrice)
432+
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gasRemaining), st.msg.GasPrice)
433433
st.state.AddBalance(st.msg.From, remaining)
434434

435435
// Also return remaining gas to the block gas counter so it is
436436
// available for the next transaction.
437-
st.gp.AddGas(st.gas)
437+
st.gp.AddGas(st.gasRemaining)
438438

439439
return refund
440440
}
441441

442442
// gasUsed returns the amount of gas used up by the state transition.
443443
func (st *StateTransition) gasUsed() uint64 {
444-
return st.initialGas - st.gas
444+
return st.initialGas - st.gasRemaining
445445
}

0 commit comments

Comments
 (0)