Skip to content

Commit 07c3de3

Browse files
committed
core, miner, xeth: renamed gas methods
* BuyGas => SubGas * RefundGas => AddGas * SetGasPool => SetGasLimit
1 parent 3deded2 commit 07c3de3

File tree

6 files changed

+10
-34
lines changed

6 files changed

+10
-34
lines changed

core/block_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewBlockProcessor(db, extra common.Database, pow pow.PoW, chainManager *Cha
5858

5959
func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block *types.Block, transientProcess bool) (receipts types.Receipts, err error) {
6060
coinbase := statedb.GetOrNewStateObject(block.Header().Coinbase)
61-
coinbase.SetGasPool(block.Header().GasLimit)
61+
coinbase.SetGasLimit(block.Header().GasLimit)
6262

6363
// Process the transactions on to parent state
6464
receipts, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess)

core/chain_makers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func makeBlock(bman *BlockProcessor, parent *types.Block, i int, db common.Datab
7979
block := newBlockFromParent(addr, parent)
8080
state := state.New(block.Root(), db)
8181
cbase := state.GetOrNewStateObject(addr)
82-
cbase.SetGasPool(CalcGasLimit(parent))
82+
cbase.SetGasLimit(CalcGasLimit(parent))
8383
cbase.AddBalance(BlockReward)
8484
state.Update()
8585
block.SetRoot(state.Root())

core/state/state_object.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data
104104
}
105105

106106
object := &StateObject{address: address, db: db}
107-
//object.RlpDecode(data)
108107
object.nonce = extobject.Nonce
109108
object.balance = extobject.Balance
110109
object.codeHash = extobject.CodeHash
@@ -215,28 +214,16 @@ func (c *StateObject) St() Storage {
215214

216215
// Return the gas back to the origin. Used by the Virtual machine or Closures
217216
func (c *StateObject) ReturnGas(gas, price *big.Int) {}
218-
func (c *StateObject) ConvertGas(gas, price *big.Int) error {
219-
total := new(big.Int).Mul(gas, price)
220-
if total.Cmp(c.balance) > 0 {
221-
return fmt.Errorf("insufficient amount: %v, %v", c.balance, total)
222-
}
223-
224-
c.SubBalance(total)
225-
226-
c.dirty = true
227-
228-
return nil
229-
}
230217

231-
func (self *StateObject) SetGasPool(gasLimit *big.Int) {
218+
func (self *StateObject) SetGasLimit(gasLimit *big.Int) {
232219
self.gasPool = new(big.Int).Set(gasLimit)
233220

234221
if glog.V(logger.Core) {
235222
glog.Infof("%x: gas (+ %v)", self.Address(), self.gasPool)
236223
}
237224
}
238225

239-
func (self *StateObject) BuyGas(gas, price *big.Int) error {
226+
func (self *StateObject) SubGas(gas, price *big.Int) error {
240227
if self.gasPool.Cmp(gas) < 0 {
241228
return GasLimitError(self.gasPool, gas)
242229
}
@@ -251,7 +238,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
251238
return nil
252239
}
253240

254-
func (self *StateObject) RefundGas(gas, price *big.Int) {
241+
func (self *StateObject) AddGas(gas, price *big.Int) {
255242
self.gasPool.Add(self.gasPool, gas)
256243
}
257244

core/state_transition.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (self *StateTransition) BuyGas() error {
151151
}
152152

153153
coinbase := self.Coinbase()
154-
err = coinbase.BuyGas(self.msg.Gas(), self.msg.GasPrice())
154+
err = coinbase.SubGas(self.msg.Gas(), self.msg.GasPrice())
155155
if err != nil {
156156
return err
157157
}
@@ -245,20 +245,9 @@ func (self *StateTransition) refundGas() {
245245
self.gas.Add(self.gas, refund)
246246
self.state.AddBalance(sender.Address(), refund.Mul(refund, self.msg.GasPrice()))
247247

248-
coinbase.RefundGas(self.gas, self.msg.GasPrice())
248+
coinbase.AddGas(self.gas, self.msg.GasPrice())
249249
}
250250

251251
func (self *StateTransition) gasUsed() *big.Int {
252252
return new(big.Int).Sub(self.initialGas, self.gas)
253253
}
254-
255-
// Converts an message in to a state object
256-
func makeContract(msg Message, state *state.StateDB) *state.StateObject {
257-
faddr, _ := msg.From()
258-
addr := crypto.CreateAddress(faddr, msg.Nonce())
259-
260-
contract := state.GetOrNewStateObject(addr)
261-
contract.SetInitCode(msg.Data())
262-
263-
return contract
264-
}

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func (self *worker) makeCurrent() {
319319
current.localMinedBlocks = self.current.localMinedBlocks
320320
}
321321

322-
current.coinbase.SetGasPool(core.CalcGasLimit(parent))
322+
current.coinbase.SetGasLimit(core.CalcGasLimit(parent))
323323

324324
self.current = current
325325
}

xeth/xeth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (self *XEth) ApplyTestTxs(statedb *state.StateDB, address common.Address, t
212212

213213
block := self.backend.ChainManager().NewBlock(address)
214214
coinbase := statedb.GetStateObject(address)
215-
coinbase.SetGasPool(big.NewInt(10000000))
215+
coinbase.SetGasLimit(big.NewInt(10000000))
216216
txs := self.backend.TxPool().GetQueuedTransactions()
217217

218218
for i := 0; i < len(txs); i++ {
@@ -827,7 +827,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
827827
}
828828

829829
from.SetBalance(common.MaxBig)
830-
from.SetGasPool(self.backend.ChainManager().GasLimit())
830+
from.SetGasLimit(self.backend.ChainManager().GasLimit())
831831
msg := callmsg{
832832
from: from,
833833
to: common.HexToAddress(toStr),

0 commit comments

Comments
 (0)