Spec changes.
* All errors during state transition result in an invalid tx
This commit is contained in:
parent
ca1093f848
commit
88ff13c241
@ -146,3 +146,19 @@ func IsKnownBlockErr(e error) bool {
|
|||||||
_, ok := e.(*KnownBlockError)
|
_, ok := e.(*KnownBlockError)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ValueTransferError struct {
|
||||||
|
message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ValueTransferErr(str string, v ...interface{}) *ValueTransferError {
|
||||||
|
return &ValueTransferError{fmt.Sprintf(str, v...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *ValueTransferError) Error() string {
|
||||||
|
return self.message
|
||||||
|
}
|
||||||
|
func IsValueTransferErr(e error) bool {
|
||||||
|
_, ok := e.(*ValueTransferError)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -26,7 +25,10 @@ func (self *Execution) Addr() []byte {
|
|||||||
|
|
||||||
func (self *Execution) Call(codeAddr []byte, caller vm.ContextRef) ([]byte, error) {
|
func (self *Execution) Call(codeAddr []byte, caller vm.ContextRef) ([]byte, error) {
|
||||||
// Retrieve the executing code
|
// Retrieve the executing code
|
||||||
code := self.env.State().GetCode(codeAddr)
|
var code []byte
|
||||||
|
if self.env.State().GetStateObject(codeAddr) != nil {
|
||||||
|
code = self.env.State().GetCode(codeAddr)
|
||||||
|
}
|
||||||
|
|
||||||
return self.exec(code, codeAddr, caller)
|
return self.exec(code, codeAddr, caller)
|
||||||
}
|
}
|
||||||
@ -55,7 +57,7 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret
|
|||||||
|
|
||||||
caller.ReturnGas(self.Gas, self.price)
|
caller.ReturnGas(self.Gas, self.price)
|
||||||
|
|
||||||
return nil, fmt.Errorf("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
|
return nil, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot := env.State().Copy()
|
snapshot := env.State().Copy()
|
||||||
|
@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
@ -185,7 +186,7 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = self.UseGas(big.NewInt(dgas)); err != nil {
|
if err = self.UseGas(big.NewInt(dgas)); err != nil {
|
||||||
return
|
return nil, InvalidTxError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//stateCopy := self.env.State().Copy()
|
//stateCopy := self.env.State().Copy()
|
||||||
@ -231,10 +232,16 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && IsValueTransferErr(err) {
|
||||||
self.UseGas(self.gas)
|
return nil, InvalidTxError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if err != nil {
|
||||||
|
self.UseGas(self.gas)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
vm/vm.go
7
vm/vm.go
@ -408,7 +408,12 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
|
|||||||
case BALANCE:
|
case BALANCE:
|
||||||
|
|
||||||
addr := stack.Pop().Bytes()
|
addr := stack.Pop().Bytes()
|
||||||
balance := statedb.GetBalance(addr)
|
var balance *big.Int
|
||||||
|
if statedb.GetStateObject(addr) != nil {
|
||||||
|
balance = statedb.GetBalance(addr)
|
||||||
|
} else {
|
||||||
|
balance = base
|
||||||
|
}
|
||||||
|
|
||||||
stack.Push(balance)
|
stack.Push(balance)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user