diff options
author | Martin Holst Swende <martin@swende.se> | 2019-03-22 23:13:28 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-03-22 23:13:28 +0800 |
commit | 876f3573647f9a62d94073b342bc678f380f0304 (patch) | |
tree | 150e9890f7174e1a4fd38c7fcf5a3e3109e05d62 | |
parent | 8d04154691ef497f18816ac720f58b650d25e1e2 (diff) | |
download | go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.tar go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.tar.gz go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.tar.bz2 go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.tar.lz go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.tar.xz go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.tar.zst go-tangerine-876f3573647f9a62d94073b342bc678f380f0304.zip |
trie: disable fnv64a hashing of hashes for bigcache (#19314)
* trie: disable fnv64a hashing of hashes for bigcache
* trie/database: add very important period
-rw-r--r-- | trie/database.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/trie/database.go b/trie/database.go index c853dfe51..6df1a7f79 100644 --- a/trie/database.go +++ b/trie/database.go @@ -17,6 +17,7 @@ package trie import ( + "encoding/binary" "fmt" "io" "sync" @@ -257,6 +258,19 @@ func expandNode(hash hashNode, n node) node { } } +// trienodeHasher is a struct to be used with BigCache, which uses a Hasher to +// determine which shard to place an entry into. It's not a cryptographic hash, +// just to provide a bit of anti-collision (default is FNV64a). +// +// Since trie keys are already hashes, we can just use the key directly to +// map shard id. +type trienodeHasher struct{} + +// Sum64 implements the bigcache.Hasher interface. +func (t trienodeHasher) Sum64(key string) uint64 { + return binary.BigEndian.Uint64([]byte(key)) +} + // NewDatabase creates a new trie database to store ephemeral trie content before // its written out to disk or garbage collected. No read cache is created, so all // data retrievals will hit the underlying disk database. @@ -276,6 +290,7 @@ func NewDatabaseWithCache(diskdb ethdb.KeyValueStore, cache int) *Database { MaxEntriesInWindow: cache * 1024, MaxEntrySize: 512, HardMaxCacheSize: cache, + Hasher: trienodeHasher{}, }) } return &Database{ |