From 5bca28faef9641cebf58bf9c6eb14c60aa8d8baa Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Fri, 10 Apr 2026 19:01:22 +0200 Subject: [PATCH] review feedback --- trie/bintrie/empty.go | 3 ++- trie/bintrie/empty_test.go | 15 +++++++++++---- trie/bintrie/stem_node.go | 3 +-- trie/bintrie/trie.go | 5 +---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/trie/bintrie/empty.go b/trie/bintrie/empty.go index 63863e1c4c..252146a4a7 100644 --- a/trie/bintrie/empty.go +++ b/trie/bintrie/empty.go @@ -48,7 +48,8 @@ func (e Empty) Hash() common.Hash { } func (e Empty) GetValuesAtStem(_ []byte, _ NodeResolverFn) ([][]byte, error) { - return nil, nil + var values [256][]byte + return values[:], nil } func (e Empty) InsertValuesAtStem(key []byte, values [][]byte, _ NodeResolverFn, depth int) (BinaryNode, error) { diff --git a/trie/bintrie/empty_test.go b/trie/bintrie/empty_test.go index 526ac8f93c..574ae1830b 100644 --- a/trie/bintrie/empty_test.go +++ b/trie/bintrie/empty_test.go @@ -105,8 +105,7 @@ func TestEmptyHash(t *testing.T) { } } -// TestEmptyGetValuesAtStem tests that GetValuesAtStem returns nil for an empty node, -// signaling that no values exist at the queried stem. +// TestEmptyGetValuesAtStem tests the GetValuesAtStem method func TestEmptyGetValuesAtStem(t *testing.T) { node := Empty{} @@ -115,8 +114,16 @@ func TestEmptyGetValuesAtStem(t *testing.T) { if err != nil { t.Fatalf("Unexpected error: %v", err) } - if values != nil { - t.Errorf("Expected nil values from Empty.GetValuesAtStem, got %d entries", len(values)) + + // Should return an array of 256 nil values + if len(values) != 256 { + t.Errorf("Expected 256 values, got %d", len(values)) + } + + for i, v := range values { + if v != nil { + t.Errorf("Expected nil value at index %d, got %x", i, v) + } } } diff --git a/trie/bintrie/stem_node.go b/trie/bintrie/stem_node.go index 65e7ae3720..e5729e6182 100644 --- a/trie/bintrie/stem_node.go +++ b/trie/bintrie/stem_node.go @@ -35,8 +35,7 @@ type StemNode struct { hash common.Hash // cached hash when mustRecompute == false } -// Get retrieves the value for the given key. Returns (nil, nil) if the -// key's stem does not match this node's stem (non-membership). +// Get retrieves the value for the given key. func (bt *StemNode) Get(key []byte, _ NodeResolverFn) ([]byte, error) { if !bytes.Equal(bt.Stem, key[:StemSize]) { return nil, nil diff --git a/trie/bintrie/trie.go b/trie/bintrie/trie.go index 407014d55c..156e0887ff 100644 --- a/trie/bintrie/trie.go +++ b/trie/bintrie/trie.go @@ -202,9 +202,6 @@ func (t *BinaryTrie) GetAccount(addr common.Address) (*types.StateAccount, error if err != nil { return nil, fmt.Errorf("GetAccount (%x) error: %v", addr, err) } - if values == nil { - return nil, nil - } // The following code is required for the MPT->Binary conversion. // An account can be partially migrated, where storage slots were moved to the binary @@ -212,7 +209,7 @@ func (t *BinaryTrie) GetAccount(addr common.Address) (*types.StateAccount, error // are in the binary trie but basic account information must be read in the base tree (MPT). // TODO: we can simplify this logic depending if the conversion is in progress or finished. emptyAccount := true - for i := 0; i <= CodeHashLeafKey && emptyAccount; i++ { + for i := 0; values != nil && i <= CodeHashLeafKey && emptyAccount; i++ { emptyAccount = emptyAccount && values[i] == nil } if emptyAccount {