Skip to content

Commit 50ba20c

Browse files
authored
fix: implement InsertValuesAtStem for HashedNode in Binary Trie (#554)
This fixes the "insertValuesAtStem not implemented for hashed node" error that was blocking contract creation tests in Binary Trie mode. The implementation follows the pattern established in InternalNode.GetValuesAtStem: 1. Generate the path for the node's position in the tree 2. Resolve the hashed node to get actual node data from the database 3. Deserialize the resolved data into a concrete node type 4. Call InsertValuesAtStem on the resolved node This allows the Binary Trie to handle cases where parts of the tree are not in memory but need to be modified during state transitions, maintaining the lazy-loading design.
1 parent d25699a commit 50ba20c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

trie/bintrie/hashed_node.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,27 @@ func (h HashedNode) GetValuesAtStem(_ []byte, _ NodeResolverFn) ([][]byte, error
4646
return nil, errors.New("attempted to get values from an unresolved node")
4747
}
4848

49-
func (h HashedNode) InsertValuesAtStem(key []byte, values [][]byte, resolver NodeResolverFn, depth int) (BinaryNode, error) {
50-
return nil, errors.New("insertValuesAtStem not implemented for hashed node")
49+
func (h HashedNode) InsertValuesAtStem(stem []byte, values [][]byte, resolver NodeResolverFn, depth int) (BinaryNode, error) {
50+
// Step 1: Generate the path for this node's position in the tree
51+
path, err := keyToPath(depth, stem)
52+
if err != nil {
53+
return nil, fmt.Errorf("InsertValuesAtStem path generation error: %w", err)
54+
}
55+
56+
// Step 2: Resolve the hashed node to get the actual node data
57+
data, err := resolver(path, common.Hash(h))
58+
if err != nil {
59+
return nil, fmt.Errorf("InsertValuesAtStem resolve error: %w", err)
60+
}
61+
62+
// Step 3: Deserialize the resolved data into a concrete node
63+
node, err := DeserializeNode(data, depth)
64+
if err != nil {
65+
return nil, fmt.Errorf("InsertValuesAtStem node deserialization error: %w", err)
66+
}
67+
68+
// Step 4: Call InsertValuesAtStem on the resolved concrete node
69+
return node.InsertValuesAtStem(stem, values, resolver, depth)
5170
}
5271

5372
func (h HashedNode) toDot(parent string, path string) string {

0 commit comments

Comments
 (0)