mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-17 12:21:38 +00:00
trie/bintrie: remove hasParent dead code in getValuesAtStem
Gballet (comment 3101708418): the hasParent check in the kindHashed branch never fires — NewBinaryTrie resolves the root eagerly at open time, so any HashedNode we encounter during a getValuesAtStem walk is necessarily a child of a previously-visited internal (parentIdx / parentIsLeft set on the prior kindInternal iteration). Drop the hasParent flag and its setter; replace the check with a short comment stating the invariant.
This commit is contained in:
parent
33227e7e6d
commit
aa21cd1b80
1 changed files with 3 additions and 5 deletions
|
|
@ -46,7 +46,6 @@ func (s *NodeStore) getValuesAtStem(ref nodeRef, stem []byte, resolver NodeResol
|
||||||
cur := ref
|
cur := ref
|
||||||
var parentIdx uint32
|
var parentIdx uint32
|
||||||
var parentIsLeft bool
|
var parentIsLeft bool
|
||||||
hasParent := false
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
switch cur.Kind() {
|
switch cur.Kind() {
|
||||||
|
|
@ -57,7 +56,6 @@ func (s *NodeStore) getValuesAtStem(ref nodeRef, stem []byte, resolver NodeResol
|
||||||
}
|
}
|
||||||
bit := stem[node.depth/8] >> (7 - (node.depth % 8)) & 1
|
bit := stem[node.depth/8] >> (7 - (node.depth % 8)) & 1
|
||||||
parentIdx = cur.Index()
|
parentIdx = cur.Index()
|
||||||
hasParent = true
|
|
||||||
if bit == 0 {
|
if bit == 0 {
|
||||||
parentIsLeft = true
|
parentIsLeft = true
|
||||||
cur = node.left
|
cur = node.left
|
||||||
|
|
@ -74,9 +72,9 @@ func (s *NodeStore) getValuesAtStem(ref nodeRef, stem []byte, resolver NodeResol
|
||||||
return sn.allValues(), nil
|
return sn.allValues(), nil
|
||||||
|
|
||||||
case kindHashed:
|
case kindHashed:
|
||||||
if !hasParent {
|
// HashedNode at root is impossible: NewBinaryTrie resolves the
|
||||||
return nil, errors.New("getValuesAtStem: hashed node at root")
|
// root eagerly before any query. Any HashedNode we encounter here
|
||||||
}
|
// is necessarily a child of a previously-visited internal node.
|
||||||
if resolver == nil {
|
if resolver == nil {
|
||||||
return nil, errors.New("getValuesAtStem: cannot resolve hashed node without resolver")
|
return nil, errors.New("getValuesAtStem: cannot resolve hashed node without resolver")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue