merkletree.Append: fix appending to empty trees
This commit is contained in:
parent
cc98a06bcb
commit
759631f7e6
|
@ -54,10 +54,12 @@ func (tree *CollapsedTree) Add(hash Hash) {
|
|||
}
|
||||
|
||||
func (tree *CollapsedTree) Append(other *CollapsedTree) error {
|
||||
if tree.size > 0 {
|
||||
maxSize := uint64(1) << bits.TrailingZeros64(tree.size)
|
||||
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.size += other.size
|
||||
|
|
Loading…
Reference in New Issue