aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-10-04 18:36:02 +0800
committerFelix Lange <fjl@twurst.com>2016-10-06 21:32:16 +0800
commit1f1ea18b5414bea22332bb4fce53cc95b5c6a07d (patch)
treed1aa3051f9c4d9f33a24519c18b70f0dd2f00644 /core/vm
parentab7adb0027dbcf09cf75a533be356c1e24c46c90 (diff)
downloadgo-tangerine-1f1ea18b5414bea22332bb4fce53cc95b5c6a07d.tar.gz
go-tangerine-1f1ea18b5414bea22332bb4fce53cc95b5c6a07d.tar.zst
go-tangerine-1f1ea18b5414bea22332bb4fce53cc95b5c6a07d.zip
core/state: implement reverts by journaling all changes
This commit replaces the deep-copy based state revert mechanism with a linear complexity journal. This commit also hides several internal StateDB methods to limit the number of ways in which calling code can use the journal incorrectly. As usual consultation and bug fixes to the initial implementation were provided by @karalabe, @obscuren and @Arachnid. Thank you!
Diffstat (limited to 'core/vm')
-rw-r--r--core/vm/environment.go4
-rw-r--r--core/vm/jit_test.go4
-rw-r--r--core/vm/runtime/env.go8
3 files changed, 8 insertions, 8 deletions
diff --git a/core/vm/environment.go b/core/vm/environment.go
index daf6fb90d..1038e69d5 100644
--- a/core/vm/environment.go
+++ b/core/vm/environment.go
@@ -36,9 +36,9 @@ type Environment interface {
// The state database
Db() Database
// Creates a restorable snapshot
- MakeSnapshot() Database
+ SnapshotDatabase() int
// Set database to previous snapshot
- SetSnapshot(Database)
+ RevertToSnapshot(int)
// Address of the original invoker (first occurrence of the VM invoker)
Origin() common.Address
// The block number this VM is invoked on
diff --git a/core/vm/jit_test.go b/core/vm/jit_test.go
index e6922aeb7..a6de710e1 100644
--- a/core/vm/jit_test.go
+++ b/core/vm/jit_test.go
@@ -179,8 +179,8 @@ func (self *Env) BlockNumber() *big.Int { return big.NewInt(0) }
//func (self *Env) PrevHash() []byte { return self.parent }
func (self *Env) Coinbase() common.Address { return common.Address{} }
-func (self *Env) MakeSnapshot() Database { return nil }
-func (self *Env) SetSnapshot(Database) {}
+func (self *Env) SnapshotDatabase() int { return 0 }
+func (self *Env) RevertToSnapshot(int) {}
func (self *Env) Time() *big.Int { return big.NewInt(time.Now().Unix()) }
func (self *Env) Difficulty() *big.Int { return big.NewInt(0) }
func (self *Env) Db() Database { return nil }
diff --git a/core/vm/runtime/env.go b/core/vm/runtime/env.go
index a4793c98f..59fbaa792 100644
--- a/core/vm/runtime/env.go
+++ b/core/vm/runtime/env.go
@@ -86,11 +86,11 @@ func (self *Env) SetDepth(i int) { self.depth = i }
func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool {
return self.state.GetBalance(from).Cmp(balance) >= 0
}
-func (self *Env) MakeSnapshot() vm.Database {
- return self.state.Copy()
+func (self *Env) SnapshotDatabase() int {
+ return self.state.Snapshot()
}
-func (self *Env) SetSnapshot(copy vm.Database) {
- self.state.Set(copy.(*state.StateDB))
+func (self *Env) RevertToSnapshot(snapshot int) {
+ self.state.RevertToSnapshot(snapshot)
}
func (self *Env) Transfer(from, to vm.Account, amount *big.Int) {