diff options
author | obscuren <geffobscura@gmail.com> | 2014-07-02 23:47:18 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-07-02 23:47:18 +0800 |
commit | 8de099ae753b2ea427a0f43abbd04019c5f76ddf (patch) | |
tree | 1cddec5f066df3317216ca0502b731cbb9a29c52 | |
parent | 40e3d2ab55f32c2458981533f5511e2f24a65c11 (diff) | |
download | dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.tar dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.tar.gz dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.tar.bz2 dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.tar.lz dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.tar.xz dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.tar.zst dexon-8de099ae753b2ea427a0f43abbd04019c5f76ddf.zip |
Added paranoia check
-rw-r--r-- | ethtrie/trie.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ethtrie/trie.go b/ethtrie/trie.go index 194c98006..38c78e7f4 100644 --- a/ethtrie/trie.go +++ b/ethtrie/trie.go @@ -1,6 +1,7 @@ package ethtrie import ( + "bytes" "fmt" "github.com/ethereum/eth-go/ethcrypto" "github.com/ethereum/eth-go/ethutil" @@ -8,6 +9,19 @@ import ( "sync" ) +func ParanoiaCheck(t1 *Trie) (bool, *Trie) { + t2 := NewTrie(ethutil.Config.Db, "") + + t1.NewIterator().Each(func(key string, v *ethutil.Value) { + t2.Update(key, v.Str()) + }) + + a := ethutil.NewValue(t2.Root).Bytes() + b := ethutil.NewValue(t1.Root).Bytes() + + return bytes.Compare(a, b) == 0, t2 +} + func (s *Cache) Len() int { return len(s.nodes) } |