Skip to content

Commit

Permalink
trie, triedb: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 committed Oct 16, 2024
1 parent d6b2ebb commit ef42ebb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 73 deletions.
2 changes: 1 addition & 1 deletion trie/trienode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (set *NodeSet) Size() (int, int) {

// HashSet returns a set of trie nodes keyed by node hash.
func (set *NodeSet) HashSet() map[common.Hash][]byte {
ret := make(map[common.Hash][]byte)
ret := make(map[common.Hash][]byte, len(set.Nodes))
for _, n := range set.Nodes {
ret[n.Hash] = n.Blob
}
Expand Down
53 changes: 0 additions & 53 deletions trie/triestate/state.go

This file was deleted.

8 changes: 2 additions & 6 deletions triedb/pathdb/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ func (b *buffer) node(owner common.Hash, path []byte) (*trienode.Node, bool) {
}

// commit merges the provided states and trie nodes into the buffer.
//
// This operation does not take ownership of the passed maps, which belong to
// the bottom-most diff layer. Instead, it holds references to the given maps,
// which are safe to copy.
func (b *buffer) commit(nodes *nodeSet) *buffer {
b.layers++
b.nodes.merge(nodes)
Expand Down Expand Up @@ -133,7 +129,7 @@ func (b *buffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWriter, node
return err
}
}
nodes := b.nodes.write(batch, b.nodes.nodes, nodesCache)
nodes := b.nodes.write(batch, nodesCache)
rawdb.WritePersistentStateID(batch, id)

// Flush all mutations in a single batch
Expand All @@ -145,6 +141,6 @@ func (b *buffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWriter, node
commitNodesMeter.Mark(int64(nodes))
commitTimeTimer.UpdateSince(start)
b.reset()
log.Info("Persisted buffer content", "nodes", nodes, "bytes", common.StorageSize(size), "elapsed", common.PrettyDuration(time.Since(start)))
log.Debug("Persisted buffer content", "nodes", nodes, "bytes", common.StorageSize(size), "elapsed", common.PrettyDuration(time.Since(start)))
return nil
}
26 changes: 13 additions & 13 deletions triedb/pathdb/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ func (s *nodeSet) computeSize() {
s.size = size
}

// updateSize updates the total cache size by the given delta.
func (s *nodeSet) updateSize(delta int64) {
size := int64(s.size) + delta
if size >= 0 {
s.size = uint64(size)
return
}
log.Error("Nodeset size underflow", "prev", common.StorageSize(s.size), "delta", common.StorageSize(delta))
s.size = 0
}

// node retrieves the trie node with node path and its trie identifier.
func (s *nodeSet) node(owner common.Hash, path []byte) (*trienode.Node, bool) {
subset, ok := s.nodes[owner]
Expand Down Expand Up @@ -211,8 +222,8 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
}

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

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

// updateSize updates the total cache size by the given delta.
func (s *nodeSet) updateSize(delta int64) {
size := int64(s.size) + delta
if size >= 0 {
s.size = uint64(size)
return
}
log.Error("Nodeset size underflow", "prev", common.StorageSize(s.size), "delta", common.StorageSize(delta))
s.size = 0
}

// dbsize returns the approximate size of db write.
func (s *nodeSet) dbsize() int {
var m int
Expand Down

0 comments on commit ef42ebb

Please sign in to comment.