@@ -31,6 +31,7 @@ import (
31
31
"github.com/ethereum/go-ethereum/log"
32
32
"github.com/ethereum/go-ethereum/metrics"
33
33
"github.com/ethereum/go-ethereum/rlp"
34
+ "github.com/ethereum/go-ethereum/trie"
34
35
"github.com/ethereum/go-ethereum/trie/trienode"
35
36
"github.com/ethereum/go-ethereum/trie/triestate"
36
37
"github.com/ethereum/go-ethereum/triedb/database"
60
61
memcacheCommitBytesMeter = metrics .NewRegisteredMeter ("hashdb/memcache/commit/bytes" , nil )
61
62
)
62
63
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
-
69
64
// Config contains the settings for database.
70
65
type Config struct {
71
66
CleanCacheSize int // Maximum memory allowance (in bytes) for caching clean nodes
@@ -84,9 +79,7 @@ var Defaults = &Config{
84
79
// the disk database. The aim is to accumulate trie writes in-memory and only
85
80
// periodically flush a couple tries to disk, garbage collecting the remainder.
86
81
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
90
83
cleans * fastcache.Cache // GC friendly memory cache of clean node RLPs
91
84
dirties map [common.Hash ]* cachedNode // Data and references relationships of dirty trie nodes
92
85
oldest common.Hash // Oldest tracked node, flush-list head
@@ -124,15 +117,15 @@ var cachedNodeSize = int(reflect.TypeOf(cachedNode{}).Size())
124
117
// forChildren invokes the callback for all the tracked children of this node,
125
118
// both the implicit ones from inside the node as well as the explicit ones
126
119
// 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 )) {
128
121
for child := range n .external {
129
122
onChild (child )
130
123
}
131
- resolver . ForEach (n .node , onChild )
124
+ trie . ForGatherChildren (n .node , onChild )
132
125
}
133
126
134
127
// 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 {
136
129
if config == nil {
137
130
config = Defaults
138
131
}
@@ -141,10 +134,9 @@ func New(diskdb ethdb.Database, config *Config, resolver ChildResolver) *Databas
141
134
cleans = fastcache .New (config .CleanCacheSize )
142
135
}
143
136
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 ),
148
140
}
149
141
}
150
142
@@ -163,7 +155,7 @@ func (db *Database) insert(hash common.Hash, node []byte) {
163
155
node : node ,
164
156
flushPrev : db .newest ,
165
157
}
166
- entry .forChildren (db . resolver , func (child common.Hash ) {
158
+ entry .forChildren (func (child common.Hash ) {
167
159
if c := db .dirties [child ]; c != nil {
168
160
c .parents ++
169
161
}
@@ -316,7 +308,7 @@ func (db *Database) dereference(hash common.Hash) {
316
308
db .dirties [node .flushNext ].flushPrev = node .flushPrev
317
309
}
318
310
// Dereference all children and delete the node
319
- node .forChildren (db . resolver , func (child common.Hash ) {
311
+ node .forChildren (func (child common.Hash ) {
320
312
db .dereference (child )
321
313
})
322
314
delete (db .dirties , hash )
@@ -465,7 +457,7 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch, uncacher *cleane
465
457
var err error
466
458
467
459
// Dereference all children and delete the node
468
- node .forChildren (db . resolver , func (child common.Hash ) {
460
+ node .forChildren (func (child common.Hash ) {
469
461
if err == nil {
470
462
err = db .commit (child , batch , uncacher )
471
463
}
0 commit comments