@@ -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"
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.
7065type 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.
8681type 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