aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-21 07:12:28 +0800
committerobscuren <geffobscura@gmail.com>2014-05-21 07:12:28 +0800
commit3c35ba7c31423da644c5fb73030af4673cff90ec (patch)
treec8e19b5a16b70780d6d837c3a60a260b13c6fd62 /ethutil
parent6ef2832083ad9d1e3cb1895f1aa836517dbf042d (diff)
downloaddexon-3c35ba7c31423da644c5fb73030af4673cff90ec.tar
dexon-3c35ba7c31423da644c5fb73030af4673cff90ec.tar.gz
dexon-3c35ba7c31423da644c5fb73030af4673cff90ec.tar.bz2
dexon-3c35ba7c31423da644c5fb73030af4673cff90ec.tar.lz
dexon-3c35ba7c31423da644c5fb73030af4673cff90ec.tar.xz
dexon-3c35ba7c31423da644c5fb73030af4673cff90ec.tar.zst
dexon-3c35ba7c31423da644c5fb73030af4673cff90ec.zip
Fixed state overwriting issue
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/trie.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/ethutil/trie.go b/ethutil/trie.go
index 4d088ccff..c993e4d8f 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -3,8 +3,13 @@ package ethutil
import (
"fmt"
"reflect"
+ "sync"
)
+func (s *Cache) Len() int {
+ return len(s.nodes)
+}
+
// TODO
// A StateObject is an object that has a state root
// This is goig to be the object for the second level caching (the caching of object which have a state such as contracts)
@@ -113,6 +118,7 @@ func (cache *Cache) Undo() {
// Please note that the data isn't persisted unless `Sync` is
// explicitly called.
type Trie struct {
+ mut sync.RWMutex
prevRoot interface{}
Root interface{}
//db Database
@@ -157,12 +163,18 @@ func (t *Trie) Cache() *Cache {
* Public (query) interface functions
*/
func (t *Trie) Update(key string, value string) {
+ t.mut.Lock()
+ defer t.mut.Unlock()
+
k := CompactHexDecode(key)
t.Root = t.UpdateState(t.Root, k, value)
}
func (t *Trie) Get(key string) string {
+ t.mut.RLock()
+ defer t.mut.RUnlock()
+
k := CompactHexDecode(key)
c := NewValue(t.GetState(t.Root, k))