Merge pull request #1304 from obscuren/state-renames

core, miner, xeth: renamed gas methods
This commit is contained in:
Jeffrey Wilcke 2015-06-21 16:49:47 -07:00
commit 9cf7913c61
7 changed files with 11 additions and 35 deletions

View File

@ -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) { 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 := statedb.GetOrNewStateObject(block.Header().Coinbase)
coinbase.SetGasPool(block.Header().GasLimit) coinbase.SetGasLimit(block.Header().GasLimit)
// Process the transactions on to parent state // Process the transactions on to parent state
receipts, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess) receipts, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess)

View File

@ -79,7 +79,7 @@ func makeBlock(bman *BlockProcessor, parent *types.Block, i int, db common.Datab
block := newBlockFromParent(addr, parent) block := newBlockFromParent(addr, parent)
state := state.New(block.Root(), db) state := state.New(block.Root(), db)
cbase := state.GetOrNewStateObject(addr) cbase := state.GetOrNewStateObject(addr)
cbase.SetGasPool(CalcGasLimit(parent)) cbase.SetGasLimit(CalcGasLimit(parent))
cbase.AddBalance(BlockReward) cbase.AddBalance(BlockReward)
state.Update() state.Update()
block.SetRoot(state.Root()) block.SetRoot(state.Root())

View File

@ -104,7 +104,6 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data
} }
object := &StateObject{address: address, db: db} object := &StateObject{address: address, db: db}
//object.RlpDecode(data)
object.nonce = extobject.Nonce object.nonce = extobject.Nonce
object.balance = extobject.Balance object.balance = extobject.Balance
object.codeHash = extobject.CodeHash 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 // 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) 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) func (self *StateObject) SetGasLimit(gasLimit *big.Int) {
c.dirty = true
return nil
}
func (self *StateObject) SetGasPool(gasLimit *big.Int) {
self.gasPool = new(big.Int).Set(gasLimit) self.gasPool = new(big.Int).Set(gasLimit)
if glog.V(logger.Core) { 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 { if self.gasPool.Cmp(gas) < 0 {
return GasLimitError(self.gasPool, gas) return GasLimitError(self.gasPool, gas)
} }
@ -251,7 +238,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
return nil return nil
} }
func (self *StateObject) RefundGas(gas, price *big.Int) { func (self *StateObject) AddGas(gas, price *big.Int) {
self.gasPool.Add(self.gasPool, gas) self.gasPool.Add(self.gasPool, gas)
} }

View File

@ -151,7 +151,7 @@ func (self *StateTransition) BuyGas() error {
} }
coinbase := self.Coinbase() coinbase := self.Coinbase()
err = coinbase.BuyGas(self.msg.Gas(), self.msg.GasPrice()) err = coinbase.SubGas(self.msg.Gas(), self.msg.GasPrice())
if err != nil { if err != nil {
return err return err
} }
@ -245,20 +245,9 @@ func (self *StateTransition) refundGas() {
self.gas.Add(self.gas, refund) self.gas.Add(self.gas, refund)
self.state.AddBalance(sender.Address(), refund.Mul(refund, self.msg.GasPrice())) 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 { func (self *StateTransition) gasUsed() *big.Int {
return new(big.Int).Sub(self.initialGas, self.gas) 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
}

View File

@ -319,7 +319,7 @@ func (self *worker) makeCurrent() {
current.localMinedBlocks = self.current.localMinedBlocks current.localMinedBlocks = self.current.localMinedBlocks
} }
current.coinbase.SetGasPool(core.CalcGasLimit(parent)) current.coinbase.SetGasLimit(core.CalcGasLimit(parent))
self.current = current self.current = current
} }

View File

@ -166,7 +166,7 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
snapshot := statedb.Copy() snapshot := statedb.Copy()
coinbase := statedb.GetOrNewStateObject(caddr) 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) message := NewMessage(common.BytesToAddress(keyPair.Address()), to, data, value, gas, price, nonce)
vmenv := NewEnvFromMap(statedb, env, tx) vmenv := NewEnvFromMap(statedb, env, tx)

View File

@ -212,7 +212,7 @@ func (self *XEth) ApplyTestTxs(statedb *state.StateDB, address common.Address, t
block := self.backend.ChainManager().NewBlock(address) block := self.backend.ChainManager().NewBlock(address)
coinbase := statedb.GetStateObject(address) coinbase := statedb.GetStateObject(address)
coinbase.SetGasPool(big.NewInt(10000000)) coinbase.SetGasLimit(big.NewInt(10000000))
txs := self.backend.TxPool().GetQueuedTransactions() txs := self.backend.TxPool().GetQueuedTransactions()
for i := 0; i < len(txs); i++ { 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.SetBalance(common.MaxBig)
from.SetGasPool(self.backend.ChainManager().GasLimit()) from.SetGasLimit(self.backend.ChainManager().GasLimit())
msg := callmsg{ msg := callmsg{
from: from, from: from,
to: common.HexToAddress(toStr), to: common.HexToAddress(toStr),