forked from cerc-io/plugeth
Merge pull request #1304 from obscuren/state-renames
core, miner, xeth: renamed gas methods
This commit is contained in:
commit
9cf7913c61
@ -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)
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user