Skip to content

Commit 6a38871

Browse files
committed
fold use SubtreeConsistency for Consistency
1 parent 1dc9004 commit 6a38871

1 file changed

Lines changed: 5 additions & 18 deletions

File tree

proof/proof.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,7 @@ func Consistency(size1, size2 uint64) (Nodes, error) {
9090
if size1 == 0 {
9191
return Nodes{}, fmt.Errorf("consistency proof from empty tree is meaningless")
9292
}
93-
if size1 == size2 {
94-
return Nodes{IDs: []compact.NodeID{}}, nil
95-
}
96-
97-
// Find the root of the biggest perfect subtree that ends at size1.
98-
level := uint(bits.TrailingZeros64(size1))
99-
index := (size1 - 1) >> level
100-
// The consistency proof consists of this node (except if size1 is a power of
101-
// two, in which case adding this node would be redundant because the client
102-
// is assumed to know it from a checkpoint), and nodes of the inclusion proof
103-
// of this node in the tree of size2.
104-
p := nodes(index, level, size2)
105-
106-
// Handle the case when size1 is a power of 2.
107-
if index == 0 {
108-
return p.skipFirst(), nil
109-
}
110-
return p, nil
93+
return subtreeConsistency(0, size1, size2)
11194
}
11295

11396
// SubtreeConsistency returns the information on how to fetch and construct a
@@ -123,6 +106,10 @@ func SubtreeConsistency(start, end, size uint64) (Nodes, error) {
123106
if end > size {
124107
return Nodes{}, fmt.Errorf("subtree end %d strictly greater than tree size %d", end, size)
125108
}
109+
return subtreeConsistency(start, end, size)
110+
}
111+
112+
func subtreeConsistency(start, end, size uint64) (Nodes, error) {
126113
if start == 0 && end == size {
127114
return Nodes{IDs: []compact.NodeID{}}, nil
128115
}

0 commit comments

Comments
 (0)