@@ -95,14 +95,14 @@ The state transitioning model does all the necessary work to work out a valid ne
95
95
96
96
// StateTransition is the state of current tx in vm
97
97
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
106
106
}
107
107
108
108
type Message struct {
@@ -203,10 +203,10 @@ func (st *StateTransition) to() common.Address {
203
203
}
204
204
205
205
//func (st *StateTransition) useGas(amount uint64) error {
206
- // if st.gas < amount {
206
+ // if st.gasRemaining < amount {
207
207
// return vm.ErrOutOfGas
208
208
// }
209
- // st.gas -= amount
209
+ // st.gasRemaining -= amount
210
210
//
211
211
// return nil
212
212
//}
@@ -219,7 +219,7 @@ func (st *StateTransition) buyGas() error {
219
219
if err := st .gp .SubGas (st .msg .GasLimit ); err != nil {
220
220
return err
221
221
}
222
- st .gas = st .msg .GasLimit
222
+ st .gasRemaining = st .msg .GasLimit
223
223
224
224
st .initialGas = st .msg .GasLimit
225
225
st .state .SubBalance (st .msg .From , mgval )
@@ -314,10 +314,10 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
314
314
if err != nil {
315
315
return nil , err
316
316
}
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 )
319
319
}
320
- st .gas -= gas
320
+ st .gasRemaining -= gas
321
321
322
322
if msg .Value .Sign () > 0 && ! st .cvm .Context .CanTransfer (st .state , msg .From , msg .Value ) {
323
323
return nil , fmt .Errorf ("%w: address %v" , ErrInsufficientFundsForTransfer , msg .From .Hex ())
@@ -336,14 +336,14 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
336
336
vmerr error
337
337
)
338
338
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 )
340
340
} else {
341
341
// Increment the nonce for the next transaction
342
342
//if pool.config.NoInfers && asm.HasInferOp(tx.Data()) {
343
343
// fmt.Println("Has INFER operation !!! continue ...")
344
344
//}
345
345
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 )
347
347
}
348
348
349
349
if vmerr != nil {
@@ -417,7 +417,7 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
417
417
418
418
// vote to model
419
419
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
421
421
}
422
422
423
423
func (st * StateTransition ) refundGas () uint64 {
@@ -426,20 +426,20 @@ func (st *StateTransition) refundGas() uint64 {
426
426
if refund > st .state .GetRefund () {
427
427
refund = st .state .GetRefund ()
428
428
}
429
- st .gas += refund
429
+ st .gasRemaining += refund
430
430
431
431
// 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 )
433
433
st .state .AddBalance (st .msg .From , remaining )
434
434
435
435
// Also return remaining gas to the block gas counter so it is
436
436
// available for the next transaction.
437
- st .gp .AddGas (st .gas )
437
+ st .gp .AddGas (st .gasRemaining )
438
438
439
439
return refund
440
440
}
441
441
442
442
// gasUsed returns the amount of gas used up by the state transition.
443
443
func (st * StateTransition ) gasUsed () uint64 {
444
- return st .initialGas - st .gas
444
+ return st .initialGas - st .gasRemaining
445
445
}
0 commit comments