diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-12 08:36:36 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-12 08:36:36 +0800 |
commit | 60cdb1148c404218846fd39331690658168f4e04 (patch) | |
tree | 229e68d7dfdaccb12e0b6b9ff19c5c14b9f9c603 /trie/trie.go | |
parent | 9bb1ac7564ff0588f33a1eb43e76f40664d9e527 (diff) | |
download | dexon-60cdb1148c404218846fd39331690658168f4e04.tar dexon-60cdb1148c404218846fd39331690658168f4e04.tar.gz dexon-60cdb1148c404218846fd39331690658168f4e04.tar.bz2 dexon-60cdb1148c404218846fd39331690658168f4e04.tar.lz dexon-60cdb1148c404218846fd39331690658168f4e04.tar.xz dexon-60cdb1148c404218846fd39331690658168f4e04.tar.zst dexon-60cdb1148c404218846fd39331690658168f4e04.zip |
Transaction execution fixes
Diffstat (limited to 'trie/trie.go')
-rw-r--r-- | trie/trie.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/trie/trie.go b/trie/trie.go index d5ab2035a..139e3d286 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -16,10 +16,7 @@ func ParanoiaCheck(t1 *Trie) (bool, *Trie) { t2.Update(key, v.Str()) }) - a := ethutil.NewValue(t2.Root).Bytes() - b := ethutil.NewValue(t1.Root).Bytes() - - return bytes.Compare(a, b) == 0, t2 + return bytes.Compare(t2.GetRoot(), t1.GetRoot()) == 0, t2 } func (s *Cache) Len() int { @@ -97,7 +94,7 @@ func (cache *Cache) Get(key []byte) *ethutil.Value { } }() // Create caching node - cache.nodes[string(key)] = NewNode(key, value, false) + cache.nodes[string(key)] = NewNode(key, value, true) return value } @@ -177,10 +174,12 @@ func New(db ethutil.Database, Root interface{}) *Trie { func (self *Trie) setRoot(root interface{}) { switch t := root.(type) { case string: - if t == "" { - root = crypto.Sha3(ethutil.Encode("")) - } - self.Root = root + /* + if t == "" { + root = crypto.Sha3(ethutil.Encode("")) + } + */ + self.Root = []byte(t) case []byte: self.Root = root default: @@ -223,13 +222,20 @@ func (t *Trie) Delete(key string) { } func (self *Trie) GetRoot() []byte { - switch self.Root.(type) { + switch t := self.Root.(type) { case string: - return []byte(self.Root.(string)) + if t == "" { + return crypto.Sha3(ethutil.Encode("")) + } + return []byte(t) case []byte: - return self.Root.([]byte) + if len(t) == 0 { + return crypto.Sha3(ethutil.Encode("")) + } + + return t default: - panic(fmt.Sprintf("invalid root type %T", self.Root)) + panic(fmt.Sprintf("invalid root type %T (%v)", self.Root, self.Root)) } } |