diff --git a/merkletree/collapsed_tree.go b/merkletree/collapsed_tree.go index c565a7f..8f4537b 100644 --- a/merkletree/collapsed_tree.go +++ b/merkletree/collapsed_tree.go @@ -44,7 +44,10 @@ func CloneCollapsedTree(source *CollapsedTree) *CollapsedTree { func (tree *CollapsedTree) Add(hash Hash) { tree.nodes = append(tree.nodes, hash) tree.size++ + tree.collapse() +} +func (tree *CollapsedTree) collapse() { numNodes := calculateNumNodes(tree.size) for len(tree.nodes) > numNodes { left, right := tree.nodes[len(tree.nodes)-2], tree.nodes[len(tree.nodes)-1]