trie: make db insert use size instead of full data

This commit is contained in:
Martin Holst Swende 2019-12-26 11:08:36 +01:00
parent a903912b96
commit 1ed51e97a3
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 6 additions and 6 deletions

View file

@ -310,24 +310,24 @@ func (db *Database) InsertBlob(hash common.Hash, blob []byte) {
db.lock.Lock() db.lock.Lock()
defer db.lock.Unlock() defer db.lock.Unlock()
db.insert(hash, blob, rawNode(blob)) db.insert(hash, len(blob), rawNode(blob))
} }
// insert inserts a collapsed trie node into the memory database. This method is // insert inserts a collapsed trie node into the memory database. This method is
// a more generic version of InsertBlob, supporting both raw blob insertions as // a more generic version of InsertBlob, supporting both raw blob insertions as
// well ex trie node insertions. The blob must always be specified to allow proper // well ex trie node insertions. The blob size must be specified to allow proper
// size tracking. // size tracking.
func (db *Database) insert(hash common.Hash, blob []byte, node node) { func (db *Database) insert(hash common.Hash, size int, node node) {
// If the node's already cached, skip // If the node's already cached, skip
if _, ok := db.dirties[hash]; ok { if _, ok := db.dirties[hash]; ok {
return return
} }
memcacheDirtyWriteMeter.Mark(int64(len(blob))) memcacheDirtyWriteMeter.Mark(int64(size))
// Create the cached entry for this node // Create the cached entry for this node
entry := &cachedNode{ entry := &cachedNode{
node: simplifyNode(node), node: simplifyNode(node),
size: uint16(len(blob)), size: uint16(size),
flushPrev: db.newest, flushPrev: db.newest,
} }
entry.forChilds(func(child common.Hash) { entry.forChilds(func(child common.Hash) {

View file

@ -184,7 +184,7 @@ func (h *hasher) store(n node, db *Database, force bool) (node, error) {
hash := common.BytesToHash(hash) hash := common.BytesToHash(hash)
db.lock.Lock() db.lock.Lock()
db.insert(hash, h.tmp, n) db.insert(hash, len(h.tmp), n)
db.lock.Unlock() db.lock.Unlock()
// Track external references from account->storage trie // Track external references from account->storage trie