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/tests/state_test_util.go b/tests/state_test_util.go index e9abad788..2f3d497be 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -166,7 +166,7 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state. snapshot := statedb.Copy() coinbase := statedb.GetOrNewStateObject(caddr) - coinbase.SetGasPool(common.Big(env["currentGasLimit"])) + coinbase.SetGasLimit(common.Big(env["currentGasLimit"])) message := NewMessage(common.BytesToAddress(keyPair.Address()), to, data, value, gas, price, nonce) vmenv := NewEnvFromMap(statedb, env, tx) 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),