Explorar el Código

core, miner: removed vm errors from consensus err checking

Removed VM errors from the consensus errors. They now used for output
only.
Jeffrey Wilcke hace 10 años
padre
commit
e6bb9c1cad
Se han modificado 5 ficheros con 20 adiciones y 12 borrados
  1. 2 3
      core/block_processor.go
  2. 7 0
      core/state_transition.go
  3. 3 1
      core/types/transaction.go
  4. 1 1
      core/vm/errors.go
  5. 7 7
      miner/worker.go

+ 2 - 3
core/block_processor.go

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

+ 7 - 0
core/state_transition.go

@@ -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("VM create err:", err)
 	} else {
 		// Increment the nonce for the next transaction
 		self.state.SetNonce(sender.Address(), sender.Nonce()+1)
 		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) {
 		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 {
 		vm.StdErrFormat(vmenv.StructLogs())
 	}

+ 3 - 1
core/types/transaction.go

@@ -15,6 +15,8 @@ import (
 	"github.com/ethereum/go-ethereum/rlp"
 )
 
+var ErrInvalidSig = errors.New("invalid v, r, s values")
+
 func IsContractAddr(addr []byte) bool {
 	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) {
 	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

+ 1 - 1
core/vm/errors.go

@@ -22,7 +22,7 @@ func (self StackError) Error() string {
 	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)
 	return ok
 }

+ 7 - 7
miner/worker.go

@@ -524,18 +524,18 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP
 
 		err := env.commitTransaction(tx, proc)
 		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):
 			// 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.
 			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])
+		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:
 			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 {
 	snap := env.state.Copy()
 	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)
 		return err
 	}