Skip to content

Commit ef42ebb

Browse files
committed
trie, triedb: address comments
1 parent d6b2ebb commit ef42ebb

File tree

4 files changed

+16
-73
lines changed

4 files changed

+16
-73
lines changed

trie/trienode/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (set *NodeSet) Size() (int, int) {
155155

156156
// HashSet returns a set of trie nodes keyed by node hash.
157157
func (set *NodeSet) HashSet() map[common.Hash][]byte {
158-
ret := make(map[common.Hash][]byte)
158+
ret := make(map[common.Hash][]byte, len(set.Nodes))
159159
for _, n := range set.Nodes {
160160
ret[n.Hash] = n.Blob
161161
}

trie/triestate/state.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

triedb/pathdb/buffer.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ func (b *buffer) node(owner common.Hash, path []byte) (*trienode.Node, bool) {
5757
}
5858

5959
// commit merges the provided states and trie nodes into the buffer.
60-
//
61-
// This operation does not take ownership of the passed maps, which belong to
62-
// the bottom-most diff layer. Instead, it holds references to the given maps,
63-
// which are safe to copy.
6460
func (b *buffer) commit(nodes *nodeSet) *buffer {
6561
b.layers++
6662
b.nodes.merge(nodes)
@@ -133,7 +129,7 @@ func (b *buffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWriter, node
133129
return err
134130
}
135131
}
136-
nodes := b.nodes.write(batch, b.nodes.nodes, nodesCache)
132+
nodes := b.nodes.write(batch, nodesCache)
137133
rawdb.WritePersistentStateID(batch, id)
138134

139135
// Flush all mutations in a single batch
@@ -145,6 +141,6 @@ func (b *buffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWriter, node
145141
commitNodesMeter.Mark(int64(nodes))
146142
commitTimeTimer.UpdateSince(start)
147143
b.reset()
148-
log.Info("Persisted buffer content", "nodes", nodes, "bytes", common.StorageSize(size), "elapsed", common.PrettyDuration(time.Since(start)))
144+
log.Debug("Persisted buffer content", "nodes", nodes, "bytes", common.StorageSize(size), "elapsed", common.PrettyDuration(time.Since(start)))
149145
return nil
150146
}

triedb/pathdb/nodes.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ func (s *nodeSet) computeSize() {
6666
s.size = size
6767
}
6868

69+
// updateSize updates the total cache size by the given delta.
70+
func (s *nodeSet) updateSize(delta int64) {
71+
size := int64(s.size) + delta
72+
if size >= 0 {
73+
s.size = uint64(size)
74+
return
75+
}
76+
log.Error("Nodeset size underflow", "prev", common.StorageSize(s.size), "delta", common.StorageSize(delta))
77+
s.size = 0
78+
}
79+
6980
// node retrieves the trie node with node path and its trie identifier.
7081
func (s *nodeSet) node(owner common.Hash, path []byte) (*trienode.Node, bool) {
7182
subset, ok := s.nodes[owner]
@@ -211,8 +222,8 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
211222
}
212223

213224
// write flushes nodes into the provided database batch as a whole.
214-
func (s *nodeSet) write(batch ethdb.Batch, nodes map[common.Hash]map[string]*trienode.Node, clean *fastcache.Cache) int {
215-
return writeNodes(batch, nodes, clean)
225+
func (s *nodeSet) write(batch ethdb.Batch, clean *fastcache.Cache) int {
226+
return writeNodes(batch, s.nodes, clean)
216227
}
217228

218229
// reset clears all cached trie node data.
@@ -221,17 +232,6 @@ func (s *nodeSet) reset() {
221232
s.size = 0
222233
}
223234

224-
// updateSize updates the total cache size by the given delta.
225-
func (s *nodeSet) updateSize(delta int64) {
226-
size := int64(s.size) + delta
227-
if size >= 0 {
228-
s.size = uint64(size)
229-
return
230-
}
231-
log.Error("Nodeset size underflow", "prev", common.StorageSize(s.size), "delta", common.StorageSize(delta))
232-
s.size = 0
233-
}
234-
235235
// dbsize returns the approximate size of db write.
236236
func (s *nodeSet) dbsize() int {
237237
var m int

0 commit comments

Comments
 (0)