review feedback

This commit is contained in:
Guillaume Ballet 2026-04-10 19:01:22 +02:00
parent 169c545693
commit 5bca28faef
No known key found for this signature in database
4 changed files with 15 additions and 11 deletions

View file

@ -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) {

View file

@ -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)
}
}
}

View file

@ -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

View file

@ -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 {