Merge pull request #1410 from obscuren/newerrors-fix

core, miner: adopted new style errors
This commit is contained in:
Jeffrey Wilcke 2015-07-06 04:00:37 -07:00
commit 457a3c8f76
5 changed files with 20 additions and 12 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
@ -73,7 +72,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
cb := statedb.GetStateObject(coinbase.Address()) cb := statedb.GetStateObject(coinbase.Address())
_, gas, err := ApplyMessage(NewEnv(statedb, self.bc, tx, header), tx, cb) _, gas, err := ApplyMessage(NewEnv(statedb, self.bc, tx, header), tx, cb)
if err != nil && err != vm.OutOfGasError { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -119,7 +118,7 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
statedb.StartRecord(tx.Hash(), block.Hash(), i) statedb.StartRecord(tx.Hash(), block.Hash(), i)
receipt, txGas, err := self.ApplyTransaction(coinbase, statedb, header, tx, totalUsedGas, transientProcess) receipt, txGas, err := self.ApplyTransaction(coinbase, statedb, header, tx, totalUsedGas, transientProcess)
if err != nil && err != vm.OutOfGasError { if err != nil {
return nil, err return nil, err
} }

View File

@ -203,16 +203,23 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
glog.V(logger.Core).Infoln("Insufficient gas for creating code. Require", dataGas, "and have", self.gas) glog.V(logger.Core).Infoln("Insufficient gas for creating code. Require", dataGas, "and have", self.gas)
} }
} }
glog.V(logger.Core).Infoln("VM create err:", err)
} else { } else {
// Increment the nonce for the next transaction // Increment the nonce for the next transaction
self.state.SetNonce(sender.Address(), sender.Nonce()+1) self.state.SetNonce(sender.Address(), sender.Nonce()+1)
ret, err = vmenv.Call(sender, self.To().Address(), self.data, self.gas, self.gasPrice, self.value) ret, err = vmenv.Call(sender, self.To().Address(), self.data, self.gas, self.gasPrice, self.value)
glog.V(logger.Core).Infoln("VM call err:", err)
} }
if err != nil && IsValueTransferErr(err) { if err != nil && IsValueTransferErr(err) {
return nil, nil, InvalidTxError(err) return nil, nil, InvalidTxError(err)
} }
// We aren't interested in errors here. Errors returned by the VM are non-consensus errors and therefor shouldn't bubble up
if err != nil {
err = nil
}
if vm.Debug { if vm.Debug {
vm.StdErrFormat(vmenv.StructLogs()) vm.StdErrFormat(vmenv.StructLogs())
} }

View File

@ -15,6 +15,8 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
var ErrInvalidSig = errors.New("invalid v, r, s values")
func IsContractAddr(addr []byte) bool { func IsContractAddr(addr []byte) bool {
return len(addr) == 0 return len(addr) == 0
} }
@ -177,7 +179,7 @@ func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int) {
func (tx *Transaction) publicKey() ([]byte, error) { func (tx *Transaction) publicKey() ([]byte, error) {
if !crypto.ValidateSignatureValues(tx.data.V, tx.data.R, tx.data.S) { if !crypto.ValidateSignatureValues(tx.data.V, tx.data.R, tx.data.S) {
return nil, errors.New("invalid v, r, s values") return nil, ErrInvalidSig
} }
// encode the signature in uncompressed format // encode the signature in uncompressed format

View File

@ -22,7 +22,7 @@ func (self StackError) Error() string {
return fmt.Sprintf("stack error! require %v, have %v", self.req, self.has) return fmt.Sprintf("stack error! require %v, have %v", self.req, self.has)
} }
func IsStack(err error) bool { func IsStackErr(err error) bool {
_, ok := err.(StackError) _, ok := err.(StackError)
return ok return ok
} }

View File

@ -524,18 +524,18 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP
err := env.commitTransaction(tx, proc) err := env.commitTransaction(tx, proc)
switch { switch {
case core.IsNonceErr(err) || core.IsInvalidTxErr(err):
env.remove.Add(tx.Hash())
if glog.V(logger.Detail) {
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
}
case state.IsGasLimitErr(err): case state.IsGasLimitErr(err):
// ignore the transactor so no nonce errors will be thrown for this account // ignore the transactor so no nonce errors will be thrown for this account
// next time the worker is run, they'll be picked up again. // next time the worker is run, they'll be picked up again.
env.ignoredTransactors.Add(from) env.ignoredTransactors.Add(from)
glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4]) glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])
case err != nil:
env.remove.Add(tx.Hash())
if glog.V(logger.Detail) {
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
}
default: default:
env.tcount++ env.tcount++
} }
@ -545,7 +545,7 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP
func (env *environment) commitTransaction(tx *types.Transaction, proc *core.BlockProcessor) error { func (env *environment) commitTransaction(tx *types.Transaction, proc *core.BlockProcessor) error {
snap := env.state.Copy() snap := env.state.Copy()
receipt, _, err := proc.ApplyTransaction(env.coinbase, env.state, env.header, tx, env.header.GasUsed, true) receipt, _, err := proc.ApplyTransaction(env.coinbase, env.state, env.header, tx, env.header.GasUsed, true)
if err != nil && (core.IsNonceErr(err) || state.IsGasLimitErr(err) || core.IsInvalidTxErr(err)) { if err != nil {
env.state.Set(snap) env.state.Set(snap)
return err return err
} }