Skip to content

Commit

Permalink
remove owned references
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Oct 11, 2024
1 parent bd25322 commit 30419cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions pkg/trie/triedb/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,21 @@ func newNodeFromEncoded[H hash.Hash](nodeHash H, data []byte, storage *nodeStora
}

func newNodeFromCachedNode[H hash.Hash](
nodeOwned CachedNode[H], storage *nodeStorage[H],
node CachedNode[H], storage *nodeStorage[H],
) Node {
switch nodeOwned := nodeOwned.(type) {
switch node := node.(type) {
case EmptyCachedNode[H]:
return Empty{}
case LeafCachedNode[H]:
leaf := nodeOwned
leaf := node
return Leaf[H]{
partialKey: leaf.PartialKey.NodeKey(),
value: newValueFromCachedNodeValue[H](leaf.Value),
}
case BranchCachedNode[H]:
k := nodeOwned.PartialKey
encodedChildren := nodeOwned.Children
val := nodeOwned.Value
k := node.PartialKey
encodedChildren := node.Children
val := node.Value

child := func(i uint) NodeHandle {
if encodedChildren[i] != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/trie/triedb/node_owned.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func newCachedNodeHandleFromMerkleValue[H hash.Hash, Hasher hash.Hasher[H]](
if err != nil {
return nil, err
}
nodeOwned, err := newCachedNodeFromNode[H, Hasher](node)
cachedNode, err := newCachedNodeFromNode[H, Hasher](node)
if err != nil {
return nil, err
}
return InlineCachedNodeHandle[H]{nodeOwned}, nil
return InlineCachedNodeHandle[H]{cachedNode}, nil
default:
panic("unreachable")
}
Expand Down Expand Up @@ -247,20 +247,20 @@ func newCachedNodeFromNode[H hash.Hash, Hasher hash.Hasher[H]](n codec.EncodedNo
Value: newCachedNodeValueFromEncodedValue[H, Hasher](n.Value),
}, nil
case codec.Branch:
var childrenOwned [codec.ChildrenCapacity]CachedNodeHandle
var children [codec.ChildrenCapacity]CachedNodeHandle
for i, child := range n.Children {
if child == nil {
continue
}
var err error
childrenOwned[i], err = newCachedNodeHandleFromMerkleValue[H, Hasher](child)
children[i], err = newCachedNodeHandleFromMerkleValue[H, Hasher](child)
if err != nil {
return nil, err
}
}
return BranchCachedNode[H]{
PartialKey: nibbles.NewNibbleSliceFromNibbles(n.PartialKey),
Children: childrenOwned,
Children: children,
Value: newCachedNodeValueFromEncodedValue[H, Hasher](n.Value),
}, nil
default:
Expand Down
8 changes: 4 additions & 4 deletions pkg/trie/triedb/triedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,16 +838,16 @@ func (t *TrieDB[H, Hasher]) lookupNode(hash H, key nibbles.Prefix) (storageHandl
// to have it being cached.
var node Node
if t.cache != nil {
nodeOwned := t.cache.GetNode(hash)
if nodeOwned == nil {
cachedNode := t.cache.GetNode(hash)
if cachedNode == nil {
var err error
node, err = newNode()
if err != nil {
return -1, err
}
} else {
t.recordAccess(CachedNodeAccess[H]{Hash: hash, Node: nodeOwned})
node = newNodeFromCachedNode(nodeOwned, &t.storage)
t.recordAccess(CachedNodeAccess[H]{Hash: hash, Node: cachedNode})
node = newNodeFromCachedNode(cachedNode, &t.storage)
}
} else {
var err error
Expand Down

0 comments on commit 30419cd

Please sign in to comment.