This commit is contained in:
zsfelfoldi 2015-10-16 04:48:29 +02:00
parent b87e55e722
commit 87d99d09d8
5 changed files with 33 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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 {

View file

@ -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])
}