Skip to content

Commit 46e7c85

Browse files
committed
Merge pull request bnb-chain#1395 from Gustav-Simonsson/fix_core_errors_in_apply_txs
Fix core errors in apply txs
2 parents 9c3db1b + 0f04af5 commit 46e7c85

7 files changed

Lines changed: 10 additions & 54 deletions

File tree

‎core/block_processor.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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"
1213
"github.com/ethereum/go-ethereum/crypto"
1314
"github.com/ethereum/go-ethereum/event"
1415
"github.com/ethereum/go-ethereum/logger"
@@ -72,7 +73,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
7273

7374
cb := statedb.GetStateObject(coinbase.Address())
7475
_, gas, err := ApplyMessage(NewEnv(statedb, self.bc, tx, header), tx, cb)
75-
if err != nil && (IsNonceErr(err) || state.IsGasLimitErr(err) || IsInvalidTxErr(err)) {
76+
if err != nil && err != vm.OutOfGasError {
7677
return nil, nil, err
7778
}
7879

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

120121
receipt, txGas, err := self.ApplyTransaction(coinbase, statedb, header, tx, totalUsedGas, transientProcess)
121-
if err != nil && (IsNonceErr(err) || state.IsGasLimitErr(err) || IsInvalidTxErr(err)) {
122+
if err != nil && err != vm.OutOfGasError {
122123
return nil, err
123124
}
124125

‎core/error.go‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func ParentError(hash common.Hash) error {
3030

3131
func IsParentErr(err error) bool {
3232
_, ok := err.(*ParentErr)
33-
3433
return ok
3534
}
3635

@@ -48,7 +47,6 @@ func UncleError(format string, v ...interface{}) error {
4847

4948
func IsUncleErr(err error) bool {
5049
_, ok := err.(*UncleErr)
51-
5250
return ok
5351
}
5452

@@ -67,7 +65,6 @@ func ValidationError(format string, v ...interface{}) *ValidationErr {
6765

6866
func IsValidationErr(err error) bool {
6967
_, ok := err.(*ValidationErr)
70-
7168
return ok
7269
}
7370

@@ -86,7 +83,6 @@ func NonceError(is, exp uint64) *NonceErr {
8683

8784
func IsNonceErr(err error) bool {
8885
_, ok := err.(*NonceErr)
89-
9086
return ok
9187
}
9288

@@ -121,24 +117,6 @@ func InvalidTxError(err error) *InvalidTxErr {
121117

122118
func IsInvalidTxErr(err error) bool {
123119
_, ok := err.(*InvalidTxErr)
124-
125-
return ok
126-
}
127-
128-
type OutOfGasErr struct {
129-
Message string
130-
}
131-
132-
func OutOfGasError() *OutOfGasErr {
133-
return &OutOfGasErr{Message: "Out of gas"}
134-
}
135-
func (self *OutOfGasErr) Error() string {
136-
return self.Message
137-
}
138-
139-
func IsOutOfGasErr(err error) bool {
140-
_, ok := err.(*OutOfGasErr)
141-
142120
return ok
143121
}
144122

‎core/execution.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (self *Execution) exec(contextAddr *common.Address, code []byte, caller vm.
5353
if env.Depth() > int(params.CallCreateDepth.Int64()) {
5454
caller.ReturnGas(self.Gas, self.price)
5555

56-
return nil, vm.DepthError{}
56+
return nil, vm.DepthError
5757
}
5858

5959
vsnapshot := env.State().Copy()

‎core/state_transition.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (self *StateTransition) To() *state.StateObject {
122122

123123
func (self *StateTransition) UseGas(amount *big.Int) error {
124124
if self.gas.Cmp(amount) < 0 {
125-
return OutOfGasError()
125+
return vm.OutOfGasError
126126
}
127127
self.gas.Sub(self.gas, amount)
128128

‎core/vm/errors.go‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
package vm
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/ethereum/go-ethereum/params"
78
)
89

9-
type OutOfGasError struct{}
10-
11-
func (self OutOfGasError) Error() string {
12-
return "Out Of Gas"
13-
}
14-
15-
func IsOOGErr(err error) bool {
16-
_, ok := err.(OutOfGasError)
17-
return ok
18-
}
10+
var OutOfGasError = errors.New("Out of gas")
11+
var DepthError = fmt.Errorf("Max call depth exceeded (%d)", params.CallCreateDepth)
1912

2013
type StackError struct {
2114
req, has int
@@ -33,14 +26,3 @@ func IsStack(err error) bool {
3326
_, ok := err.(StackError)
3427
return ok
3528
}
36-
37-
type DepthError struct{}
38-
39-
func (self DepthError) Error() string {
40-
return fmt.Sprintf("Max call depth exceeded (%d)", params.CallCreateDepth)
41-
}
42-
43-
func IsDepthErr(err error) bool {
44-
_, ok := err.(DepthError)
45-
return ok
46-
}

‎core/vm/vm.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
116116

117117
context.UseGas(context.Gas)
118118

119-
return context.Return(nil), OutOfGasError{}
119+
return context.Return(nil), OutOfGasError
120120
}
121121
// Resize the memory calculated previously
122122
mem.Resize(newMemSize.Uint64())
@@ -789,7 +789,7 @@ func (self *Vm) RunPrecompiled(p *PrecompiledAccount, input []byte, context *Con
789789

790790
return context.Return(ret), nil
791791
} else {
792-
return nil, OutOfGasError{}
792+
return nil, OutOfGasError
793793
}
794794
}
795795

‎tests/init.go‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ var (
2020
BlockSkipTests = []string{
2121
"SimpleTx3",
2222

23-
// these panic in block_processor.go:84 , see https://github.com/ethereum/go-ethereum/issues/1384
24-
"TRANSCT_rvalue_TooShort",
25-
"TRANSCT_rvalue_TooLarge",
26-
"TRANSCT_svalue_TooLarge",
27-
2823
// TODO: check why these fail
2924
"BLOCK__RandomByteAtTheEnd",
3025
"TRANSCT__RandomByteAtTheEnd",

0 commit comments

Comments
 (0)