trie: remove unused code (#20366)

This commit is contained in:
Felix Lange 2019-11-22 16:24:48 +01:00 committed by Péter Szilágyi
parent 58f2ce8671
commit 0abcf03fde
2 changed files with 7 additions and 63 deletions

View File

@ -97,7 +97,6 @@ type Database struct {
// in the same cache fields).
type rawNode []byte
func (n rawNode) canUnload(uint16, uint16) bool { panic("this should never end up in a live trie") }
func (n rawNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
func (n rawNode) fstring(ind string) string { panic("this should never end up in a live trie") }
@ -106,7 +105,6 @@ func (n rawNode) fstring(ind string) string { panic("this should never end u
// the same RLP encoding as the original parent.
type rawFullNode [17]node
func (n rawFullNode) canUnload(uint16, uint16) bool { panic("this should never end up in a live trie") }
func (n rawFullNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
func (n rawFullNode) fstring(ind string) string { panic("this should never end up in a live trie") }
@ -131,7 +129,6 @@ type rawShortNode struct {
Val node
}
func (n rawShortNode) canUnload(uint16, uint16) bool { panic("this should never end up in a live trie") }
func (n rawShortNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
func (n rawShortNode) fstring(ind string) string { panic("this should never end up in a live trie") }
@ -841,7 +838,7 @@ func (c *cleaner) Put(key []byte, rlp []byte) error {
}
func (c *cleaner) Delete(key []byte) error {
panic("Not implemented")
panic("not implemented")
}
// Size returns the current storage size of the memory cache in front of the
@ -857,45 +854,3 @@ func (db *Database) Size() (common.StorageSize, common.StorageSize) {
var metarootRefs = common.StorageSize(len(db.dirties[common.Hash{}].children) * (common.HashLength + 2))
return db.dirtiesSize + db.childrenSize + metadataSize - metarootRefs, db.preimagesSize
}
// verifyIntegrity is a debug method to iterate over the entire trie stored in
// memory and check whether every node is reachable from the meta root. The goal
// is to find any errors that might cause memory leaks and or trie nodes to go
// missing.
//
// This method is extremely CPU and memory intensive, only use when must.
func (db *Database) verifyIntegrity() {
// Iterate over all the cached nodes and accumulate them into a set
reachable := map[common.Hash]struct{}{{}: {}}
for child := range db.dirties[common.Hash{}].children {
db.accumulate(child, reachable)
}
// Find any unreachable but cached nodes
var unreachable []string
for hash, node := range db.dirties {
if _, ok := reachable[hash]; !ok {
unreachable = append(unreachable, fmt.Sprintf("%x: {Node: %v, Parents: %d, Prev: %x, Next: %x}",
hash, node.node, node.parents, node.flushPrev, node.flushNext))
}
}
if len(unreachable) != 0 {
panic(fmt.Sprintf("trie cache memory leak: %v", unreachable))
}
}
// accumulate iterates over the trie defined by hash and accumulates all the
// cached children found in memory.
func (db *Database) accumulate(hash common.Hash, reachable map[common.Hash]struct{}) {
// Mark the node reachable if present in the memory cache
node, ok := db.dirties[hash]
if !ok {
return
}
reachable[hash] = struct{}{}
// Iterate over all the children and accumulate them too
for _, child := range node.childs() {
db.accumulate(child, reachable)
}
}

View File

@ -31,7 +31,6 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/rlp"
@ -317,16 +316,6 @@ func TestLargeValue(t *testing.T) {
trie.Hash()
}
type countingDB struct {
ethdb.KeyValueStore
gets map[string]int
}
func (db *countingDB) Get(key []byte) ([]byte, error) {
db.gets[string(key)]++
return db.KeyValueStore.Get(key)
}
// randTest performs random trie operations.
// Instances of this test are created by Generate.
type randTest []randTestStep