diff --git a/tree.go b/tree.go index 76d4e4d5..65075ac6 100644 --- a/tree.go +++ b/tree.go @@ -772,6 +772,33 @@ func groupKeys(keys keylist, depth byte) []keylist { return groups } +func (n *InternalNode) LoadKeyForProof(key []byte, resolver NodeResolverFn) error { + // Each internal node that is part of the proof needs to load all it's + // children since it's needed for proof openings. + childrenKey := make([]byte, n.depth+1) + copy(childrenKey, key[:n.depth]) + for i := range n.children { + if _, ok := n.children[i].(HashedNode); ok { + childrenKey[n.depth] = byte(i) + serialized, err := resolver(childrenKey) + if err != nil { + return err + } + c, err := ParseNode(serialized, n.depth+1) + if err != nil { + return err + } + n.children[i] = c + } + if child, ok := n.children[i].(*InternalNode); ok { + if err := child.LoadKeyForProof(childrenKey, resolver); err != nil { + return err + } + } + } + return nil +} + func (n *InternalNode) GetProofItems(keys keylist) (*ProofElements, []byte, [][]byte, error) { var ( groups = groupKeys(keys, n.depth) @@ -1339,8 +1366,8 @@ func (n *LeafNode) GetProofItems(keys keylist) (*ProofElements, []byte, [][]byte if len(esses) == 0 { esses = append(esses, extStatusAbsentOther|(n.depth<<3)) poass = append(poass, n.stem) - pe.Vals = append(pe.Vals, nil) } + pe.Vals = append(pe.Vals, nil) // TODO(PR-temp): workaround proving bug. continue }