Bladeren bron

core, core/vm, cmd/evm: remove redundant balance check

Gustav Simonsson 10 jaren geleden
bovenliggende
commit
e1616f77c7
6 gewijzigde bestanden met toevoegingen van 10 en 19 verwijderingen
  1. 2 2
      cmd/evm/main.go
  2. 1 8
      core/execution.go
  3. 1 1
      core/vm/environment.go
  4. 1 3
      core/vm/jit_test.go
  5. 2 2
      core/vm_env.go
  6. 3 3
      tests/util.go

+ 2 - 2
cmd/evm/main.go

@@ -217,8 +217,8 @@ func (self *VMEnv) AddLog(log *vm.Log) {
 func (self *VMEnv) CanTransfer(from common.Address, balance *big.Int) bool {
 	return self.state.GetBalance(from).Cmp(balance) >= 0
 }
-func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
-	return core.Transfer(from, to, amount)
+func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) {
+	core.Transfer(from, to, amount)
 }
 
 func (self *VMEnv) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {

+ 1 - 8
core/execution.go

@@ -17,7 +17,6 @@
 package core
 
 import (
-	"errors"
 	"math/big"
 
 	"github.com/ethereum/go-ethereum/common"
@@ -108,13 +107,7 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
 }
 
 // generic transfer method
-func Transfer(from, to vm.Account, amount *big.Int) error {
-	if from.Balance().Cmp(amount) < 0 {
-		return errors.New("Insufficient balance in account")
-	}
-
+func Transfer(from, to vm.Account, amount *big.Int) {
 	from.SubBalance(amount)
 	to.AddBalance(amount)
-
-	return nil
 }

+ 1 - 1
core/vm/environment.go

@@ -51,7 +51,7 @@ type Environment interface {
 	// Determines whether it's possible to transact
 	CanTransfer(from common.Address, balance *big.Int) bool
 	// Transfers amount from one account to the other
-	Transfer(from, to Account, amount *big.Int) error
+	Transfer(from, to Account, amount *big.Int)
 	// Adds a LOG to the state
 	AddLog(*Log)
 	// Adds a structured log to the env

+ 1 - 3
core/vm/jit_test.go

@@ -152,9 +152,7 @@ func (self *Env) SetDepth(i int) { self.depth = i }
 func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool {
 	return true
 }
-func (self *Env) Transfer(from, to Account, amount *big.Int) error {
-	return nil
-}
+func (self *Env) Transfer(from, to Account, amount *big.Int) {}
 func (self *Env) Call(caller ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
 	return nil, nil
 }

+ 2 - 2
core/vm_env.go

@@ -81,8 +81,8 @@ func (self *VMEnv) SetSnapshot(copy vm.Database) {
 	self.state.Set(copy.(*state.StateDB))
 }
 
-func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
-	return Transfer(from, to, amount)
+func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) {
+	Transfer(from, to, amount)
 }
 
 func (self *VMEnv) Call(me vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {

+ 3 - 3
tests/util.go

@@ -209,11 +209,11 @@ func (self *Env) SetSnapshot(copy vm.Database) {
 	self.state.Set(copy.(*state.StateDB))
 }
 
-func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
+func (self *Env) Transfer(from, to vm.Account, amount *big.Int) {
 	if self.skipTransfer {
-		return nil
+		return
 	}
-	return core.Transfer(from, to, amount)
+	core.Transfer(from, to, amount)
 }
 
 func (self *Env) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {