diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-20 22:28:11 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-21 23:09:19 +0800 |
commit | 07c3de3f75a579cf573fae7bf7c0ec11427dda9f (patch) | |
tree | 2007b80da898cb96c9a00f1565bebb64271d712b | |
parent | 3deded28a50398b8ce108c72f27ea861c1bce178 (diff) | |
download | dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.tar dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.tar.gz dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.tar.bz2 dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.tar.lz dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.tar.xz dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.tar.zst dexon-07c3de3f75a579cf573fae7bf7c0ec11427dda9f.zip |
core, miner, xeth: renamed gas methods
* BuyGas => SubGas
* RefundGas => AddGas
* SetGasPool => SetGasLimit
-rw-r--r-- | core/block_processor.go | 2 | ||||
-rw-r--r-- | core/chain_makers.go | 2 | ||||
-rw-r--r-- | core/state/state_object.go | 19 | ||||
-rw-r--r-- | core/state_transition.go | 15 | ||||
-rw-r--r-- | miner/worker.go | 2 | ||||
-rw-r--r-- | xeth/xeth.go | 4 |
6 files changed, 10 insertions, 34 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index c78d419ce..e30ced312 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -58,7 +58,7 @@ func NewBlockProcessor(db, extra common.Database, pow pow.PoW, chainManager *Cha func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block *types.Block, transientProcess bool) (receipts types.Receipts, err error) { coinbase := statedb.GetOrNewStateObject(block.Header().Coinbase) - coinbase.SetGasPool(block.Header().GasLimit) + coinbase.SetGasLimit(block.Header().GasLimit) // Process the transactions on to parent state receipts, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess) diff --git a/core/chain_makers.go b/core/chain_makers.go index 4e685f599..76acfd6ca 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -79,7 +79,7 @@ func makeBlock(bman *BlockProcessor, parent *types.Block, i int, db common.Datab block := newBlockFromParent(addr, parent) state := state.New(block.Root(), db) cbase := state.GetOrNewStateObject(addr) - cbase.SetGasPool(CalcGasLimit(parent)) + cbase.SetGasLimit(CalcGasLimit(parent)) cbase.AddBalance(BlockReward) state.Update() block.SetRoot(state.Root()) diff --git a/core/state/state_object.go b/core/state/state_object.go index 2e4fe3269..a31c182d2 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -104,7 +104,6 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data } object := &StateObject{address: address, db: db} - //object.RlpDecode(data) object.nonce = extobject.Nonce object.balance = extobject.Balance object.codeHash = extobject.CodeHash @@ -215,20 +214,8 @@ func (c *StateObject) St() Storage { // Return the gas back to the origin. Used by the Virtual machine or Closures func (c *StateObject) ReturnGas(gas, price *big.Int) {} -func (c *StateObject) ConvertGas(gas, price *big.Int) error { - total := new(big.Int).Mul(gas, price) - if total.Cmp(c.balance) > 0 { - return fmt.Errorf("insufficient amount: %v, %v", c.balance, total) - } - - c.SubBalance(total) - - c.dirty = true - - return nil -} -func (self *StateObject) SetGasPool(gasLimit *big.Int) { +func (self *StateObject) SetGasLimit(gasLimit *big.Int) { self.gasPool = new(big.Int).Set(gasLimit) if glog.V(logger.Core) { @@ -236,7 +223,7 @@ func (self *StateObject) SetGasPool(gasLimit *big.Int) { } } -func (self *StateObject) BuyGas(gas, price *big.Int) error { +func (self *StateObject) SubGas(gas, price *big.Int) error { if self.gasPool.Cmp(gas) < 0 { return GasLimitError(self.gasPool, gas) } @@ -251,7 +238,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error { return nil } -func (self *StateObject) RefundGas(gas, price *big.Int) { +func (self *StateObject) AddGas(gas, price *big.Int) { self.gasPool.Add(self.gasPool, gas) } diff --git a/core/state_transition.go b/core/state_transition.go index 4a8d92375..915dd466b 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -151,7 +151,7 @@ func (self *StateTransition) BuyGas() error { } coinbase := self.Coinbase() - err = coinbase.BuyGas(self.msg.Gas(), self.msg.GasPrice()) + err = coinbase.SubGas(self.msg.Gas(), self.msg.GasPrice()) if err != nil { return err } @@ -245,20 +245,9 @@ func (self *StateTransition) refundGas() { self.gas.Add(self.gas, refund) self.state.AddBalance(sender.Address(), refund.Mul(refund, self.msg.GasPrice())) - coinbase.RefundGas(self.gas, self.msg.GasPrice()) + coinbase.AddGas(self.gas, self.msg.GasPrice()) } func (self *StateTransition) gasUsed() *big.Int { return new(big.Int).Sub(self.initialGas, self.gas) } - -// Converts an message in to a state object -func makeContract(msg Message, state *state.StateDB) *state.StateObject { - faddr, _ := msg.From() - addr := crypto.CreateAddress(faddr, msg.Nonce()) - - contract := state.GetOrNewStateObject(addr) - contract.SetInitCode(msg.Data()) - - return contract -} diff --git a/miner/worker.go b/miner/worker.go index d339507ca..55c23376c 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -319,7 +319,7 @@ func (self *worker) makeCurrent() { current.localMinedBlocks = self.current.localMinedBlocks } - current.coinbase.SetGasPool(core.CalcGasLimit(parent)) + current.coinbase.SetGasLimit(core.CalcGasLimit(parent)) self.current = current } diff --git a/xeth/xeth.go b/xeth/xeth.go index 7342be4a9..99e17423a 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -212,7 +212,7 @@ func (self *XEth) ApplyTestTxs(statedb *state.StateDB, address common.Address, t block := self.backend.ChainManager().NewBlock(address) coinbase := statedb.GetStateObject(address) - coinbase.SetGasPool(big.NewInt(10000000)) + coinbase.SetGasLimit(big.NewInt(10000000)) txs := self.backend.TxPool().GetQueuedTransactions() for i := 0; i < len(txs); i++ { @@ -827,7 +827,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st } from.SetBalance(common.MaxBig) - from.SetGasPool(self.backend.ChainManager().GasLimit()) + from.SetGasLimit(self.backend.ChainManager().GasLimit()) msg := callmsg{ from: from, to: common.HexToAddress(toStr), |