From 1bde49894c21d39aadf57ec30da07aa617ae9948 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 16 Feb 2023 20:36:13 -0500 Subject: [PATCH] merkletree: make some code a bit more obvious and general --- merkletree/collapsed_tree.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/merkletree/collapsed_tree.go b/merkletree/collapsed_tree.go index d0525bd..c565a7f 100644 --- a/merkletree/collapsed_tree.go +++ b/merkletree/collapsed_tree.go @@ -44,12 +44,12 @@ func CloneCollapsedTree(source *CollapsedTree) *CollapsedTree { func (tree *CollapsedTree) Add(hash Hash) { tree.nodes = append(tree.nodes, hash) tree.size++ - size := tree.size - for size%2 == 0 { + + numNodes := calculateNumNodes(tree.size) + for len(tree.nodes) > numNodes { left, right := tree.nodes[len(tree.nodes)-2], tree.nodes[len(tree.nodes)-1] tree.nodes = tree.nodes[:len(tree.nodes)-2] tree.nodes = append(tree.nodes, HashChildren(left, right)) - size /= 2 } }