github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/core/vm/gas.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:35</date> 10 //</624342621602451456> 11 12 13 package vm 14 15 import ( 16 "math/big" 17 18 "github.com/ethereum/go-ethereum/params" 19 ) 20 21 //天然气成本 22 const ( 23 GasQuickStep uint64 = 2 24 GasFastestStep uint64 = 3 25 GasFastStep uint64 = 5 26 GasMidStep uint64 = 8 27 GasSlowStep uint64 = 10 28 GasExtStep uint64 = 20 29 30 GasReturn uint64 = 0 31 GasStop uint64 = 0 32 GasContractByte uint64 = 200 33 ) 34 35 //CalcGas返回呼叫的实际气体成本。 36 // 37 //天然气成本在宅基地价格变化期间发生了变化。考虑EIP150 38 //待实施。返回气体为气基*63/64。 39 func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big.Int) (uint64, error) { 40 if gasTable.CreateBySuicide > 0 { 41 availableGas = availableGas - base 42 gas := availableGas - availableGas/64 43 //如果位长度超过64位,我们知道新计算的EIP150“气体” 44 //小于请求的金额。因此,我们把新的天然气换回来。 45 //返回错误。 46 if callCost.BitLen() > 64 || gas < callCost.Uint64() { 47 return gas, nil 48 } 49 } 50 if callCost.BitLen() > 64 { 51 return 0, errGasUintOverflow 52 } 53 54 return callCost.Uint64(), nil 55 } 56