aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/trie.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-29 18:36:27 +0800
committerobscuren <geffobscura@gmail.com>2014-04-29 18:36:27 +0800
commit38d6b67b5cfbfb63620a244ea01b5b534917128f (patch)
tree42b4f55e4cd5c2f2a2c28f8551d8b92686abf567 /ethutil/trie.go
parent5516efdfa0494e028fc3649e4a38da81c56ed598 (diff)
downloadgo-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.tar
go-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.tar.gz
go-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.tar.bz2
go-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.tar.lz
go-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.tar.xz
go-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.tar.zst
go-tangerine-38d6b67b5cfbfb63620a244ea01b5b534917128f.zip
Fixed state problem
Diffstat (limited to 'ethutil/trie.go')
-rw-r--r--ethutil/trie.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/ethutil/trie.go b/ethutil/trie.go
index c67f750bc..4d088ccff 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -119,14 +119,29 @@ type Trie struct {
cache *Cache
}
+func copyRoot(root interface{}) interface{} {
+ var prevRootCopy interface{}
+ if b, ok := root.([]byte); ok {
+ prevRootCopy = CopyBytes(b)
+ } else {
+ prevRootCopy = root
+ }
+
+ return prevRootCopy
+}
+
func NewTrie(db Database, Root interface{}) *Trie {
- return &Trie{cache: NewCache(db), Root: Root, prevRoot: Root}
+ // Make absolute sure the root is copied
+ r := copyRoot(Root)
+ p := copyRoot(Root)
+
+ return &Trie{cache: NewCache(db), Root: r, prevRoot: p}
}
// Save the cached value to the database.
func (t *Trie) Sync() {
t.cache.Commit()
- t.prevRoot = t.Root
+ t.prevRoot = copyRoot(t.Root)
}
func (t *Trie) Undo() {