Skip to content

Commit

Permalink
chore: refine some code
Browse files Browse the repository at this point in the history
  • Loading branch information
will@2012 committed Jun 12, 2024
1 parent 00e8f9d commit 8e6e681
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions triedb/pathdb/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ type diffLayer struct {
nodes map[common.Hash]map[string]*trienode.Node // Cached trie nodes indexed by owner and path
states *triestate.Set // Associated state change set for building history
memory uint64 // Approximate guess as to how much memory we use
cache *HashNodeCache // trienode cache by hash key. cache is immutable, but cache's item can be add/del.

// mutables
cache *HashNodeCache // trienode cache by hash key.
origin *diskLayer // The current difflayer corresponds to the underlying disklayer and is updated during cap.

origin *diskLayer // The current difflayer corresponds to the underlying disklayer and is updated during cap.
parent layer // Parent layer modified by this one, never nil, **can be changed**
lock sync.RWMutex // Lock used to protect parent
}
Expand All @@ -166,19 +165,16 @@ func newDiffLayer(parent layer, root common.Hash, id uint64, block uint64, nodes
switch l := parent.(type) {
case *diskLayer:
dl.origin = l
dl.cache = &HashNodeCache{
cache: make(map[common.Hash]*RefTrieNode),
}
case *diffLayer:
dl.origin = l.origin
dl.origin = l.originDiskLayer()
dl.cache = l.cache
default:
panic("unknown parent type")
}

if dl.cache == nil {
dl.cache = &HashNodeCache{
cache: make(map[common.Hash]*RefTrieNode),
}
}

for _, subset := range nodes {
for path, n := range subset {
dl.memory += uint64(n.Size() + len(path))
Expand Down

0 comments on commit 8e6e681

Please sign in to comment.