mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 09:51:36 +00:00
review feedback
This commit is contained in:
parent
169c545693
commit
5bca28faef
4 changed files with 15 additions and 11 deletions
|
|
@ -48,7 +48,8 @@ func (e Empty) Hash() common.Hash {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Empty) GetValuesAtStem(_ []byte, _ NodeResolverFn) ([][]byte, error) {
|
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) {
|
func (e Empty) InsertValuesAtStem(key []byte, values [][]byte, _ NodeResolverFn, depth int) (BinaryNode, error) {
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,7 @@ func TestEmptyHash(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestEmptyGetValuesAtStem tests that GetValuesAtStem returns nil for an empty node,
|
// TestEmptyGetValuesAtStem tests the GetValuesAtStem method
|
||||||
// signaling that no values exist at the queried stem.
|
|
||||||
func TestEmptyGetValuesAtStem(t *testing.T) {
|
func TestEmptyGetValuesAtStem(t *testing.T) {
|
||||||
node := Empty{}
|
node := Empty{}
|
||||||
|
|
||||||
|
|
@ -115,8 +114,16 @@ func TestEmptyGetValuesAtStem(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,7 @@ type StemNode struct {
|
||||||
hash common.Hash // cached hash when mustRecompute == false
|
hash common.Hash // cached hash when mustRecompute == false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get retrieves the value for the given key. Returns (nil, nil) if the
|
// Get retrieves the value for the given key.
|
||||||
// key's stem does not match this node's stem (non-membership).
|
|
||||||
func (bt *StemNode) Get(key []byte, _ NodeResolverFn) ([]byte, error) {
|
func (bt *StemNode) Get(key []byte, _ NodeResolverFn) ([]byte, error) {
|
||||||
if !bytes.Equal(bt.Stem, key[:StemSize]) {
|
if !bytes.Equal(bt.Stem, key[:StemSize]) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
||||||
|
|
@ -202,9 +202,6 @@ func (t *BinaryTrie) GetAccount(addr common.Address) (*types.StateAccount, error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("GetAccount (%x) error: %v", addr, err)
|
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.
|
// The following code is required for the MPT->Binary conversion.
|
||||||
// An account can be partially migrated, where storage slots were moved to the binary
|
// 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).
|
// 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.
|
// TODO: we can simplify this logic depending if the conversion is in progress or finished.
|
||||||
emptyAccount := true
|
emptyAccount := true
|
||||||
for i := 0; i <= CodeHashLeafKey && emptyAccount; i++ {
|
for i := 0; values != nil && i <= CodeHashLeafKey && emptyAccount; i++ {
|
||||||
emptyAccount = emptyAccount && values[i] == nil
|
emptyAccount = emptyAccount && values[i] == nil
|
||||||
}
|
}
|
||||||
if emptyAccount {
|
if emptyAccount {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue