From 3c35ba7c31423da644c5fb73030af4673cff90ec Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 01:12:28 +0200 Subject: Fixed state overwriting issue --- ethutil/trie.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ethutil') 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)) -- cgit