Skip to content

Commit a58d668

Browse files
fjlenriquefynn
authored andcommitted
trie: remove unused code (ethereum#20366)
1 parent 53e67f1 commit a58d668

File tree

2 files changed

+7
-63
lines changed

2 files changed

+7
-63
lines changed

trie/database.go

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,16 @@ type Database struct {
9797
// in the same cache fields).
9898
type rawNode []byte
9999

100-
func (n rawNode) canUnload(uint16, uint16) bool { panic("this should never end up in a live trie") }
101-
func (n rawNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
102-
func (n rawNode) fstring(ind string) string { panic("this should never end up in a live trie") }
100+
func (n rawNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
101+
func (n rawNode) fstring(ind string) string { panic("this should never end up in a live trie") }
103102

104103
// rawFullNode represents only the useful data content of a full node, with the
105104
// caches and flags stripped out to minimize its data storage. This type honors
106105
// the same RLP encoding as the original parent.
107106
type rawFullNode [17]node
108107

109-
func (n rawFullNode) canUnload(uint16, uint16) bool { panic("this should never end up in a live trie") }
110-
func (n rawFullNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
111-
func (n rawFullNode) fstring(ind string) string { panic("this should never end up in a live trie") }
108+
func (n rawFullNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
109+
func (n rawFullNode) fstring(ind string) string { panic("this should never end up in a live trie") }
112110

113111
func (n rawFullNode) EncodeRLP(w io.Writer) error {
114112
var nodes [17]node
@@ -131,9 +129,8 @@ type rawShortNode struct {
131129
Val node
132130
}
133131

134-
func (n rawShortNode) canUnload(uint16, uint16) bool { panic("this should never end up in a live trie") }
135-
func (n rawShortNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
136-
func (n rawShortNode) fstring(ind string) string { panic("this should never end up in a live trie") }
132+
func (n rawShortNode) cache() (hashNode, bool) { panic("this should never end up in a live trie") }
133+
func (n rawShortNode) fstring(ind string) string { panic("this should never end up in a live trie") }
137134

138135
// cachedNode is all the information we know about a single cached node in the
139136
// memory database write layer.
@@ -841,7 +838,7 @@ func (c *cleaner) Put(key []byte, rlp []byte) error {
841838
}
842839

843840
func (c *cleaner) Delete(key []byte) error {
844-
panic("Not implemented")
841+
panic("not implemented")
845842
}
846843

847844
// 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) {
857854
var metarootRefs = common.StorageSize(len(db.dirties[common.Hash{}].children) * (common.HashLength + 2))
858855
return db.dirtiesSize + db.childrenSize + metadataSize - metarootRefs, db.preimagesSize
859856
}
860-
861-
// verifyIntegrity is a debug method to iterate over the entire trie stored in
862-
// memory and check whether every node is reachable from the meta root. The goal
863-
// is to find any errors that might cause memory leaks and or trie nodes to go
864-
// missing.
865-
//
866-
// This method is extremely CPU and memory intensive, only use when must.
867-
func (db *Database) verifyIntegrity() {
868-
// Iterate over all the cached nodes and accumulate them into a set
869-
reachable := map[common.Hash]struct{}{{}: {}}
870-
871-
for child := range db.dirties[common.Hash{}].children {
872-
db.accumulate(child, reachable)
873-
}
874-
// Find any unreachable but cached nodes
875-
var unreachable []string
876-
for hash, node := range db.dirties {
877-
if _, ok := reachable[hash]; !ok {
878-
unreachable = append(unreachable, fmt.Sprintf("%x: {Node: %v, Parents: %d, Prev: %x, Next: %x}",
879-
hash, node.node, node.parents, node.flushPrev, node.flushNext))
880-
}
881-
}
882-
if len(unreachable) != 0 {
883-
panic(fmt.Sprintf("trie cache memory leak: %v", unreachable))
884-
}
885-
}
886-
887-
// accumulate iterates over the trie defined by hash and accumulates all the
888-
// cached children found in memory.
889-
func (db *Database) accumulate(hash common.Hash, reachable map[common.Hash]struct{}) {
890-
// Mark the node reachable if present in the memory cache
891-
node, ok := db.dirties[hash]
892-
if !ok {
893-
return
894-
}
895-
reachable[hash] = struct{}{}
896-
897-
// Iterate over all the children and accumulate them too
898-
for _, child := range node.childs() {
899-
db.accumulate(child, reachable)
900-
}
901-
}

trie/trie_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/davecgh/go-spew/spew"
3232
"github.com/ethereum/go-ethereum/common"
3333
"github.com/ethereum/go-ethereum/crypto"
34-
"github.com/ethereum/go-ethereum/ethdb"
3534
"github.com/ethereum/go-ethereum/ethdb/leveldb"
3635
"github.com/ethereum/go-ethereum/ethdb/memorydb"
3736
"github.com/ethereum/go-ethereum/rlp"
@@ -317,16 +316,6 @@ func TestLargeValue(t *testing.T) {
317316
trie.Hash()
318317
}
319318

320-
type countingDB struct {
321-
ethdb.KeyValueStore
322-
gets map[string]int
323-
}
324-
325-
func (db *countingDB) Get(key []byte) ([]byte, error) {
326-
db.gets[string(key)]++
327-
return db.KeyValueStore.Get(key)
328-
}
329-
330319
// randTest performs random trie operations.
331320
// Instances of this test are created by Generate.
332321
type randTest []randTestStep

0 commit comments

Comments
 (0)