merkletree.Append: fix appending to empty trees

This commit is contained in:
Andrew Ayer 2024-06-09 11:13:16 -04:00
parent cc98a06bcb
commit 759631f7e6
1 changed files with 5 additions and 3 deletions

View File

@ -54,9 +54,11 @@ func (tree *CollapsedTree) Add(hash Hash) {
} }
func (tree *CollapsedTree) Append(other *CollapsedTree) error { func (tree *CollapsedTree) Append(other *CollapsedTree) error {
maxSize := uint64(1) << bits.TrailingZeros64(tree.size) if tree.size > 0 {
if other.size > maxSize { maxSize := uint64(1) << bits.TrailingZeros64(tree.size)
return fmt.Errorf("tree of size %d is too large to append to a tree of size %d (maximum size is %d)", other.size, tree.size, maxSize) if other.size > maxSize {
return fmt.Errorf("tree of size %d is too large to append to a tree of size %d (maximum size is %d)", other.size, tree.size, maxSize)
}
} }
tree.nodes = append(tree.nodes, other.nodes...) tree.nodes = append(tree.nodes, other.nodes...)