Skip to content

Commit b530d8e

Browse files
authored
trie, triedb: remove unnecessary child resolver interface (#30167)
1 parent 0d38b0c commit b530d8e

File tree

3 files changed

+14
-34
lines changed

3 files changed

+14
-34
lines changed

trie/committer.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,8 @@ func (c *committer) store(path []byte, n node) node {
154154
return hash
155155
}
156156

157-
// MerkleResolver the children resolver in merkle-patricia-tree.
158-
type MerkleResolver struct{}
159-
160-
// ForEach implements childResolver, decodes the provided node and
161-
// traverses the children inside.
162-
func (resolver MerkleResolver) ForEach(node []byte, onChild func(common.Hash)) {
157+
// ForGatherChildren decodes the provided node and traverses the children inside.
158+
func ForGatherChildren(node []byte, onChild func(common.Hash)) {
163159
forGatherChildren(mustDecodeNodeUnsafe(nil, node), onChild)
164160
}
165161

triedb/database.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/ethereum/go-ethereum/core/rawdb"
2424
"github.com/ethereum/go-ethereum/ethdb"
2525
"github.com/ethereum/go-ethereum/log"
26-
"github.com/ethereum/go-ethereum/trie"
2726
"github.com/ethereum/go-ethereum/trie/trienode"
2827
"github.com/ethereum/go-ethereum/trie/triestate"
2928
"github.com/ethereum/go-ethereum/triedb/database"
@@ -112,14 +111,7 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
112111
if config.PathDB != nil {
113112
db.backend = pathdb.New(diskdb, config.PathDB, config.IsVerkle)
114113
} else {
115-
var resolver hashdb.ChildResolver
116-
if config.IsVerkle {
117-
// TODO define verkle resolver
118-
log.Crit("verkle does not use a hash db")
119-
} else {
120-
resolver = trie.MerkleResolver{}
121-
}
122-
db.backend = hashdb.New(diskdb, config.HashDB, resolver)
114+
db.backend = hashdb.New(diskdb, config.HashDB)
123115
}
124116
return db
125117
}

triedb/hashdb/database.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/log"
3232
"github.com/ethereum/go-ethereum/metrics"
3333
"github.com/ethereum/go-ethereum/rlp"
34+
"github.com/ethereum/go-ethereum/trie"
3435
"github.com/ethereum/go-ethereum/trie/trienode"
3536
"github.com/ethereum/go-ethereum/trie/triestate"
3637
"github.com/ethereum/go-ethereum/triedb/database"
@@ -60,12 +61,6 @@ var (
6061
memcacheCommitBytesMeter = metrics.NewRegisteredMeter("hashdb/memcache/commit/bytes", nil)
6162
)
6263

63-
// ChildResolver defines the required method to decode the provided
64-
// trie node and iterate the children on top.
65-
type ChildResolver interface {
66-
ForEach(node []byte, onChild func(common.Hash))
67-
}
68-
6964
// Config contains the settings for database.
7065
type Config struct {
7166
CleanCacheSize int // Maximum memory allowance (in bytes) for caching clean nodes
@@ -84,9 +79,7 @@ var Defaults = &Config{
8479
// the disk database. The aim is to accumulate trie writes in-memory and only
8580
// periodically flush a couple tries to disk, garbage collecting the remainder.
8681
type Database struct {
87-
diskdb ethdb.Database // Persistent storage for matured trie nodes
88-
resolver ChildResolver // The handler to resolve children of nodes
89-
82+
diskdb ethdb.Database // Persistent storage for matured trie nodes
9083
cleans *fastcache.Cache // GC friendly memory cache of clean node RLPs
9184
dirties map[common.Hash]*cachedNode // Data and references relationships of dirty trie nodes
9285
oldest common.Hash // Oldest tracked node, flush-list head
@@ -124,15 +117,15 @@ var cachedNodeSize = int(reflect.TypeOf(cachedNode{}).Size())
124117
// forChildren invokes the callback for all the tracked children of this node,
125118
// both the implicit ones from inside the node as well as the explicit ones
126119
// from outside the node.
127-
func (n *cachedNode) forChildren(resolver ChildResolver, onChild func(hash common.Hash)) {
120+
func (n *cachedNode) forChildren(onChild func(hash common.Hash)) {
128121
for child := range n.external {
129122
onChild(child)
130123
}
131-
resolver.ForEach(n.node, onChild)
124+
trie.ForGatherChildren(n.node, onChild)
132125
}
133126

134127
// New initializes the hash-based node database.
135-
func New(diskdb ethdb.Database, config *Config, resolver ChildResolver) *Database {
128+
func New(diskdb ethdb.Database, config *Config) *Database {
136129
if config == nil {
137130
config = Defaults
138131
}
@@ -141,10 +134,9 @@ func New(diskdb ethdb.Database, config *Config, resolver ChildResolver) *Databas
141134
cleans = fastcache.New(config.CleanCacheSize)
142135
}
143136
return &Database{
144-
diskdb: diskdb,
145-
resolver: resolver,
146-
cleans: cleans,
147-
dirties: make(map[common.Hash]*cachedNode),
137+
diskdb: diskdb,
138+
cleans: cleans,
139+
dirties: make(map[common.Hash]*cachedNode),
148140
}
149141
}
150142

@@ -163,7 +155,7 @@ func (db *Database) insert(hash common.Hash, node []byte) {
163155
node: node,
164156
flushPrev: db.newest,
165157
}
166-
entry.forChildren(db.resolver, func(child common.Hash) {
158+
entry.forChildren(func(child common.Hash) {
167159
if c := db.dirties[child]; c != nil {
168160
c.parents++
169161
}
@@ -316,7 +308,7 @@ func (db *Database) dereference(hash common.Hash) {
316308
db.dirties[node.flushNext].flushPrev = node.flushPrev
317309
}
318310
// Dereference all children and delete the node
319-
node.forChildren(db.resolver, func(child common.Hash) {
311+
node.forChildren(func(child common.Hash) {
320312
db.dereference(child)
321313
})
322314
delete(db.dirties, hash)
@@ -465,7 +457,7 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch, uncacher *cleane
465457
var err error
466458

467459
// Dereference all children and delete the node
468-
node.forChildren(db.resolver, func(child common.Hash) {
460+
node.forChildren(func(child common.Hash) {
469461
if err == nil {
470462
err = db.commit(child, batch, uncacher)
471463
}

0 commit comments

Comments
 (0)