From aa21cd1b80a4c36363d65c7ecdef72fac4b88121 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Sat, 18 Apr 2026 18:57:56 +0200 Subject: [PATCH] trie/bintrie: remove hasParent dead code in getValuesAtStem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- trie/bintrie/store_ops.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/trie/bintrie/store_ops.go b/trie/bintrie/store_ops.go index 1a1083ab8d..79f94010a2 100644 --- a/trie/bintrie/store_ops.go +++ b/trie/bintrie/store_ops.go @@ -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") }