trie: disable fnv64a hashing of hashes for bigcache (#19314)

* trie: disable fnv64a hashing of hashes for bigcache

* trie/database: add very important period
This commit is contained in:
Martin Holst Swende 2019-03-22 16:13:28 +01:00 committed by Péter Szilágyi
parent 8d04154691
commit 876f357364
1 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package trie package trie
import ( import (
"encoding/binary"
"fmt" "fmt"
"io" "io"
"sync" "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 // 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 // its written out to disk or garbage collected. No read cache is created, so all
// data retrievals will hit the underlying disk database. // data retrievals will hit the underlying disk database.
@ -276,6 +290,7 @@ func NewDatabaseWithCache(diskdb ethdb.KeyValueStore, cache int) *Database {
MaxEntriesInWindow: cache * 1024, MaxEntriesInWindow: cache * 1024,
MaxEntrySize: 512, MaxEntrySize: 512,
HardMaxCacheSize: cache, HardMaxCacheSize: cache,
Hasher: trienodeHasher{},
}) })
} }
return &Database{ return &Database{