From 184e9ae9a81df2db6381e18d3daa035d913ae341 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sun, 2 Aug 2015 02:20:41 +0200 Subject: core, tests: reduced state copy by N calls Reduced the amount of state copied that are required by N calls by doing a balance check prior to any state modifications. --- core/vm/environment.go | 1 + core/vm/instructions.go | 1 + core/vm/jit.go | 3 ++- core/vm/jit_test.go | 3 +++ core/vm/settings.go | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) (limited to 'core/vm') diff --git a/core/vm/environment.go b/core/vm/environment.go index 723924b6f..5a1bf3201 100644 --- a/core/vm/environment.go +++ b/core/vm/environment.go @@ -36,6 +36,7 @@ type Environment interface { Time() uint64 Difficulty() *big.Int GasLimit() *big.Int + CanTransfer(from Account, balance *big.Int) bool Transfer(from, to Account, amount *big.Int) error AddLog(*state.Log) AddStructLog(StructLog) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 7793ff169..d7605e5a2 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . + package vm import ( diff --git a/core/vm/jit.go b/core/vm/jit.go index a77309223..c66630ae8 100644 --- a/core/vm/jit.go +++ b/core/vm/jit.go @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . + package vm import ( @@ -48,7 +49,7 @@ func SetJITCacheSize(size int) { programs, _ = lru.New(size) } -// GetProgram returns the program by id or nil when non-existant +// GetProgram returns the program by id or nil when non-existent func GetProgram(id common.Hash) *Program { if p, ok := programs.Get(id); ok { return p.(*Program) diff --git a/core/vm/jit_test.go b/core/vm/jit_test.go index 70432d47b..5b3feea99 100644 --- a/core/vm/jit_test.go +++ b/core/vm/jit_test.go @@ -105,6 +105,9 @@ func (self *Env) AddLog(log *state.Log) { } func (self *Env) Depth() int { return self.depth } func (self *Env) SetDepth(i int) { self.depth = i } +func (self *Env) CanTransfer(from Account, balance *big.Int) bool { + return from.Balance().Cmp(balance) >= 0 +} func (self *Env) Transfer(from, to Account, amount *big.Int) error { return nil } diff --git a/core/vm/settings.go b/core/vm/settings.go index 9e30d3add..b94efd9ab 100644 --- a/core/vm/settings.go +++ b/core/vm/settings.go @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . + package vm var ( -- cgit v1.2.3