mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +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
|
||||
var parentIdx uint32
|
||||
var parentIsLeft bool
|
||||
hasParent := false
|
||||
|
||||
for {
|
||||
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
|
||||
parentIdx = cur.Index()
|
||||
hasParent = true
|
||||
if bit == 0 {
|
||||
parentIsLeft = true
|
||||
cur = node.left
|
||||
|
|
@ -74,9 +72,9 @@ func (s *NodeStore) getValuesAtStem(ref nodeRef, stem []byte, resolver NodeResol
|
|||
return sn.allValues(), nil
|
||||
|
||||
case kindHashed:
|
||||
if !hasParent {
|
||||
return nil, errors.New("getValuesAtStem: hashed node at root")
|
||||
}
|
||||
// HashedNode at root is impossible: NewBinaryTrie resolves the
|
||||
// root eagerly before any query. Any HashedNode we encounter here
|
||||
// is necessarily a child of a previously-visited internal node.
|
||||
if resolver == nil {
|
||||
return nil, errors.New("getValuesAtStem: cannot resolve hashed node without resolver")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue