From 1413b877f3447b6066649c654ce658419ff17115 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 16 Feb 2023 20:36:37 -0500 Subject: [PATCH] merkletree: factor out collapsing logic --- merkletree/collapsed_tree.go | 3 +++ 1 file changed, 3 insertions(+) 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]