diff --git a/bzz/chunker.go b/bzz/chunker.go index 2f4b554c76..d01994c6d8 100644 --- a/bzz/chunker.go +++ b/bzz/chunker.go @@ -206,8 +206,7 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data SectionR var hash Key dpaLogger.Debugf("depth: %v, max subtree size: %v, data size: %v", depth, treeSize, size) - switch { - case depth == 0: + if depth == 0 { // leaf nodes -> content chunks hash = self.Hash(size, data) dpaLogger.Debugf("content chunk: max subtree size: %v, data size: %v", treeSize, size) @@ -216,13 +215,11 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data SectionR Data: data, Size: size, } - case size < treeSize: - parentWg.Add(1) - // last item on this level (== size % self.Branches ^ (depth + 1) ) - self.split(depth-1, treeSize/self.Branches, key, data, chunkC, errc, parentWg) - return - - default: + } else { + for size < treeSize { + treeSize /= self.Branches + depth-- + } // intermediate chunk containing child nodes hashes branches := int64((size-1)/treeSize) + 1 dpaLogger.Debugf("intermediate node: setting branches: %v, depth: %v, max subtree size: %v, data size: %v", branches, depth, treeSize, size)