From 87d99d09d819433d5c3a999751f0bf2c6dfb9504 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Fri, 16 Oct 2015 04:48:29 +0200 Subject: [PATCH] 1 --- core/block_processor.go | 2 +- core/canary.go | 12 ++++++++---- core/chain_makers.go | 8 +++++--- core/genesis.go | 2 +- core/transaction_pool.go | 23 ++++++++++++++++++----- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/core/block_processor.go b/core/block_processor.go index 783e156876..71b2f1fb26 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -82,7 +82,7 @@ func NewBlockProcessor(db ethdb.Database, pow pow.PoW, blockchain *BlockChain, e } func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block *types.Block, transientProcess bool) (receipts types.Receipts, err error) { - gp := statedb.GetOrNewStateObject(block.Coinbase()) + gp, _ := statedb.GetOrNewStateObject(block.Coinbase()) gp.SetGasLimit(block.GasLimit()) // Process the transactions on to parent state diff --git a/core/canary.go b/core/canary.go index 69db18e582..11acc9e300 100644 --- a/core/canary.go +++ b/core/canary.go @@ -35,16 +35,20 @@ var ( // dies a horrible death. func Canary(statedb *state.StateDB) bool { var r int - if (statedb.GetState(jeff, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) { + state, err := statedb.GetState(jeff, common.Hash{}) + if err == nil && (state.Big().Cmp(big.NewInt(0)) > 0) { r++ } - if (statedb.GetState(gav, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) { + state, err = statedb.GetState(gav, common.Hash{}) + if err == nil && (state.Big().Cmp(big.NewInt(0)) > 0) { r++ } - if (statedb.GetState(christoph, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) { + state, err = statedb.GetState(christoph, common.Hash{}) + if err == nil && (state.Big().Cmp(big.NewInt(0)) > 0) { r++ } - if (statedb.GetState(vitalik, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) { + state, err = statedb.GetState(vitalik, common.Hash{}) + if err == nil && (state.Big().Cmp(big.NewInt(0)) > 0) { r++ } return r > 1 diff --git a/core/chain_makers.go b/core/chain_makers.go index ba09b30290..9f21de6cea 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -70,7 +70,7 @@ func (b *BlockGen) SetCoinbase(addr common.Address) { panic("coinbase can only be set once") } b.header.Coinbase = addr - b.coinbase = b.statedb.GetOrNewStateObject(addr) + b.coinbase, _ = b.statedb.GetOrNewStateObject(addr) b.coinbase.SetGasLimit(b.header.GasLimit) } @@ -108,10 +108,12 @@ func (b *BlockGen) AddTx(tx *types.Transaction) { // TxNonce returns the next valid transaction nonce for the // account at addr. It panics if the account does not exist. func (b *BlockGen) TxNonce(addr common.Address) uint64 { - if !b.statedb.HasAccount(addr) { + ha, _ := b.statedb.HasAccount(addr) + if !ha { panic("account does not exist") } - return b.statedb.GetNonce(addr) + nonce, _ := b.statedb.GetNonce(addr) + return nonce } // AddUncle adds an uncle header to the generated block. diff --git a/core/genesis.go b/core/genesis.go index 4c5c17f601..eb5e46637c 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -118,7 +118,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block, // The state trie of the block is written to db. func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block { statedb := state.New(common.Hash{}, db) - obj := statedb.GetOrNewStateObject(addr) + obj, _ := statedb.GetOrNewStateObject(addr) obj.SetBalance(balance) root, err := statedb.Commit() if err != nil { diff --git a/core/transaction_pool.go b/core/transaction_pool.go index a4e6ce3e2f..5169a589c2 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -180,12 +180,20 @@ func (pool *TxPool) validateTx(tx *types.Transaction) error { // Make sure the account exist. Non existent accounts // haven't got funds and well therefor never pass. - if !pool.currentState().HasAccount(from) { + ha, err := pool.currentState().HasAccount(from) + if err != nil { + return err + } + if !ha { return ErrNonExistentAccount } // Last but not least check for nonce errors - if pool.currentState().GetNonce(from) > tx.Nonce() { + nonce, err := pool.currentState().GetNonce(from) + if err != nil { + return err + } + if nonce > tx.Nonce() { return ErrNonce } @@ -204,7 +212,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction) error { // Transactor should have enough funds to cover the costs // cost == V + GP * GL - if pool.currentState().GetBalance(from).Cmp(tx.Cost()) < 0 { + balance, err := pool.currentState().GetBalance(from) + if err != nil { + return err + } + if balance.Cmp(tx.Cost()) < 0 { return ErrInsufficientFunds } @@ -389,7 +401,7 @@ func (pool *TxPool) checkQueue() { // guessed nonce is the nonce currently kept by the tx pool (pending state) guessedNonce := state.GetNonce(address) // true nonce is the nonce known by the last state - trueNonce := pool.currentState().GetNonce(address) + trueNonce, _ := pool.currentState().GetNonce(address) addq := addq[:0] for hash, tx := range txs { if tx.Nonce() < trueNonce { @@ -438,7 +450,8 @@ func (pool *TxPool) validatePool() { for hash, tx := range pool.pending { from, _ := tx.From() // err already checked // perform light nonce validation - if state.GetNonce(from) > tx.Nonce() { + nonce, _ := state.GetNonce(from) + if nonce > tx.Nonce() { if glog.V(logger.Core) { glog.Infof("removed tx (%x) from pool: low tx nonce\n", hash[:4]) }