Fixes gas limit for simulated transaction (#130)

* Fixes call gas limit for stdTxs

* reword comment
This commit is contained in:
Austin Abell
2019-10-29 11:52:26 -04:00
committed by GitHub
parent 2b4d2bea82
commit 51ff5d48a9
3 changed files with 20 additions and 9 deletions
+16 -5
View File
@@ -29,15 +29,26 @@ type StateTransition struct {
}
// TransitionCSDB performs an evm state transition from a transaction
func (st StateTransition) TransitionCSDB(ctx sdk.Context) (sdk.Result, *big.Int) {
func (st StateTransition) TransitionCSDB(ctx sdk.Context) (*big.Int, sdk.Result) {
contractCreation := st.Recipient == nil
if res := st.checkNonce(); !res.IsOK() {
return res, nil
return nil, res
}
cost, err := core.IntrinsicGas(st.Payload, st.Recipient == nil, true)
if err != nil {
return nil, sdk.ErrOutOfGas("invalid intrinsic gas for transaction").Result()
}
// This gas limit the the transaction gas limit with intrinsic gas subtracted
gasLimit := ctx.GasMeter().Limit()
gasLimit := st.GasLimit - ctx.GasMeter().GasConsumed()
if st.Simulate {
// gasLimit is set here because stdTxs incur gaskv charges in the ante handler, but for eth_call
// the cost needs to be the same as an Ethereum transaction sent through the web3 API
gasLimit = st.GasLimit - cost
}
// Create context for evm
context := vm.Context{
@@ -92,7 +103,7 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (sdk.Result, *big.Int)
if vmerr != nil {
res := emint.ErrVMExecution(vmerr.Error()).Result()
res.Data = returnData
return res, nil
return nil, res
}
// TODO: Refund unused gas here, if intended in future
@@ -103,7 +114,7 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (sdk.Result, *big.Int)
// Out of gas check does not need to be done here since it is done within the EVM execution
ctx.GasMeter().ConsumeGas(gasLimit-leftOverGas, "EVM execution consumption")
return sdk.Result{Data: returnData, GasUsed: st.GasLimit - leftOverGas}, bloomInt
return bloomInt, sdk.Result{Data: returnData, GasUsed: st.GasLimit - leftOverGas}
}
func (st *StateTransition) checkNonce() sdk.Result {