Skip to content

Commit 457a3c8

Browse files
committed
Merge pull request #1410 from obscuren/newerrors-fix
core, miner: adopted new style errors
2 parents aa45020 + e6bb9c1 commit 457a3c8

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

core/block_processor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/ethereum/go-ethereum/common"
1010
"github.com/ethereum/go-ethereum/core/state"
1111
"github.com/ethereum/go-ethereum/core/types"
12-
"github.com/ethereum/go-ethereum/core/vm"
1312
"github.com/ethereum/go-ethereum/crypto"
1413
"github.com/ethereum/go-ethereum/event"
1514
"github.com/ethereum/go-ethereum/logger"
@@ -73,7 +72,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
7372

7473
cb := statedb.GetStateObject(coinbase.Address())
7574
_, gas, err := ApplyMessage(NewEnv(statedb, self.bc, tx, header), tx, cb)
76-
if err != nil && err != vm.OutOfGasError {
75+
if err != nil {
7776
return nil, nil, err
7877
}
7978

@@ -119,7 +118,7 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
119118
statedb.StartRecord(tx.Hash(), block.Hash(), i)
120119

121120
receipt, txGas, err := self.ApplyTransaction(coinbase, statedb, header, tx, totalUsedGas, transientProcess)
122-
if err != nil && err != vm.OutOfGasError {
121+
if err != nil {
123122
return nil, err
124123
}
125124

core/state_transition.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,23 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
203203
glog.V(logger.Core).Infoln("Insufficient gas for creating code. Require", dataGas, "and have", self.gas)
204204
}
205205
}
206+
glog.V(logger.Core).Infoln("VM create err:", err)
206207
} else {
207208
// Increment the nonce for the next transaction
208209
self.state.SetNonce(sender.Address(), sender.Nonce()+1)
209210
ret, err = vmenv.Call(sender, self.To().Address(), self.data, self.gas, self.gasPrice, self.value)
211+
glog.V(logger.Core).Infoln("VM call err:", err)
210212
}
211213

212214
if err != nil && IsValueTransferErr(err) {
213215
return nil, nil, InvalidTxError(err)
214216
}
215217

218+
// We aren't interested in errors here. Errors returned by the VM are non-consensus errors and therefor shouldn't bubble up
219+
if err != nil {
220+
err = nil
221+
}
222+
216223
if vm.Debug {
217224
vm.StdErrFormat(vmenv.StructLogs())
218225
}

core/types/transaction.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/ethereum/go-ethereum/rlp"
1616
)
1717

18+
var ErrInvalidSig = errors.New("invalid v, r, s values")
19+
1820
func IsContractAddr(addr []byte) bool {
1921
return len(addr) == 0
2022
}
@@ -177,7 +179,7 @@ func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int) {
177179

178180
func (tx *Transaction) publicKey() ([]byte, error) {
179181
if !crypto.ValidateSignatureValues(tx.data.V, tx.data.R, tx.data.S) {
180-
return nil, errors.New("invalid v, r, s values")
182+
return nil, ErrInvalidSig
181183
}
182184

183185
// encode the signature in uncompressed format

core/vm/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (self StackError) Error() string {
2222
return fmt.Sprintf("stack error! require %v, have %v", self.req, self.has)
2323
}
2424

25-
func IsStack(err error) bool {
25+
func IsStackErr(err error) bool {
2626
_, ok := err.(StackError)
2727
return ok
2828
}

miner/worker.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,18 +524,18 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP
524524

525525
err := env.commitTransaction(tx, proc)
526526
switch {
527-
case core.IsNonceErr(err) || core.IsInvalidTxErr(err):
528-
env.remove.Add(tx.Hash())
529-
530-
if glog.V(logger.Detail) {
531-
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
532-
}
533527
case state.IsGasLimitErr(err):
534528
// ignore the transactor so no nonce errors will be thrown for this account
535529
// next time the worker is run, they'll be picked up again.
536530
env.ignoredTransactors.Add(from)
537531

538532
glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])
533+
case err != nil:
534+
env.remove.Add(tx.Hash())
535+
536+
if glog.V(logger.Detail) {
537+
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
538+
}
539539
default:
540540
env.tcount++
541541
}
@@ -545,7 +545,7 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP
545545
func (env *environment) commitTransaction(tx *types.Transaction, proc *core.BlockProcessor) error {
546546
snap := env.state.Copy()
547547
receipt, _, err := proc.ApplyTransaction(env.coinbase, env.state, env.header, tx, env.header.GasUsed, true)
548-
if err != nil && (core.IsNonceErr(err) || state.IsGasLimitErr(err) || core.IsInvalidTxErr(err)) {
548+
if err != nil {
549549
env.state.Set(snap)
550550
return err
551551
}

0 commit comments

Comments
 (0)