diff options
-rw-r--r-- | common/db.go | 2 | ||||
-rw-r--r-- | core/block_processor.go | 2 | ||||
-rw-r--r-- | core/chain_makers.go | 2 | ||||
-rw-r--r-- | core/chain_manager.go | 16 | ||||
-rw-r--r-- | core/state/state_object.go | 19 | ||||
-rw-r--r-- | core/state_transition.go | 15 | ||||
-rw-r--r-- | ethdb/database.go | 4 | ||||
-rw-r--r-- | ethdb/memory_database.go | 4 | ||||
-rw-r--r-- | miner/worker.go | 2 | ||||
-rw-r--r-- | tests/state_test_util.go | 2 | ||||
-rw-r--r-- | trie/cache.go | 8 | ||||
-rw-r--r-- | trie/trie_test.go | 2 | ||||
-rw-r--r-- | xeth/xeth.go | 4 |
13 files changed, 37 insertions, 45 deletions
diff --git a/common/db.go b/common/db.go index c12a2cfb0..7f3becd5a 100644 --- a/common/db.go +++ b/common/db.go @@ -2,7 +2,7 @@ package common // Database interface type Database interface { - Put(key []byte, value []byte) + Put(key []byte, value []byte) error Get(key []byte) ([]byte, error) Delete(key []byte) error Close() 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/chain_manager.go b/core/chain_manager.go index c3b7273c2..e3795f561 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -377,8 +377,14 @@ func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error // assumes that the `mu` mutex is held! func (bc *ChainManager) insert(block *types.Block) { key := append(blockNumPre, block.Number().Bytes()...) - bc.blockDb.Put(key, block.Hash().Bytes()) - bc.blockDb.Put([]byte("LastBlock"), block.Hash().Bytes()) + err := bc.blockDb.Put(key, block.Hash().Bytes()) + if err != nil { + glog.Fatal("db write fail:", err) + } + err = bc.blockDb.Put([]byte("LastBlock"), block.Hash().Bytes()) + if err != nil { + glog.Fatal("db write fail:", err) + } bc.currentBlock = block bc.lastBlockHash = block.Hash() @@ -387,7 +393,11 @@ func (bc *ChainManager) insert(block *types.Block) { func (bc *ChainManager) write(block *types.Block) { enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block)) key := append(blockHashPre, block.Hash().Bytes()...) - bc.blockDb.Put(key, enc) + err := bc.blockDb.Put(key, enc) + if err != nil { + glog.Fatal("db write fail:", err) + } + // Push block to cache bc.cache.Push(block) } 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/ethdb/database.go b/ethdb/database.go index 019645ced..5faf8c4e0 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -42,8 +42,8 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) { } // Put puts the given key / value to the queue -func (self *LDBDatabase) Put(key []byte, value []byte) { - self.db.Put(key, rle.Compress(value), nil) +func (self *LDBDatabase) Put(key []byte, value []byte) error { + return self.db.Put(key, rle.Compress(value), nil) } // Get returns the given key if it's present. diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index f5d5faee7..c15c56bfb 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -19,8 +19,10 @@ func NewMemDatabase() (*MemDatabase, error) { return db, nil } -func (db *MemDatabase) Put(key []byte, value []byte) { +func (db *MemDatabase) Put(key []byte, value []byte) error { db.db[string(key)] = value + + return nil } func (db *MemDatabase) Set(key []byte, value []byte) { 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/trie/cache.go b/trie/cache.go index 2143785fa..4c76c6cba 100644 --- a/trie/cache.go +++ b/trie/cache.go @@ -1,8 +1,10 @@ package trie +import "github.com/ethereum/go-ethereum/logger/glog" + type Backend interface { Get([]byte) ([]byte, error) - Put([]byte, []byte) + Put([]byte, []byte) error } type Cache struct { @@ -29,7 +31,9 @@ func (self *Cache) Put(key []byte, data []byte) { func (self *Cache) Flush() { for k, v := range self.store { - self.backend.Put([]byte(k), v) + if err := self.backend.Put([]byte(k), v); err != nil { + glog.Fatal("db write err:", err) + } } // This will eventually grow too large. We'd could diff --git a/trie/trie_test.go b/trie/trie_test.go index 16311aadf..9a58958d8 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -12,7 +12,7 @@ import ( type Db map[string][]byte func (self Db) Get(k []byte) ([]byte, error) { return self[string(k)], nil } -func (self Db) Put(k, v []byte) { self[string(k)] = v } +func (self Db) Put(k, v []byte) error { self[string(k)] = v; return nil } // Used for testing func NewEmpty() *Trie { 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), |