Skip to content

Commit

Permalink
Update bmt.go
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbarry authored May 7, 2018
1 parent c223d2b commit 1fe86ed
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions bmt/bmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,27 +438,27 @@ func (h *Hasher) releaseTree() {
}

func (h *Hasher) writeSegment(i int, s []byte, d int) {
h := h.pool.hasher()
hash := h.pool.hasher()
n := h.bmt.leaves[i]

if len(s) > h.size && n.parent != nil {
go func() {
h.Reset()
h.Write(s)
s = h.Sum(nil)
hash.Reset()
hash.Write(s)
s = hash.Sum(nil)

if n.root {
h.result <- s
return
}
h.run(n.parent, h, d, n.index, s)
h.run(n.parent, hash, d, n.index, s)
}()
return
}
go h.run(n, h, d, i*2, s)
go h.run(n, hash, d, i*2, s)
}

func (h *Hasher) run(n *Node, h hash.Hash, d int, i int, s []byte) {
func (h *Hasher) run(n *Node, hash hash.Hash, d int, i int, s []byte) {
isLeft := i%2 == 0
for {
if isLeft {
Expand All @@ -470,10 +470,10 @@ func (h *Hasher) run(n *Node, h hash.Hash, d int, i int, s []byte) {
return
}
if !n.unbalanced || !isLeft || i == 0 && d == 0 {
h.Reset()
h.Write(n.left)
h.Write(n.right)
s = h.Sum(nil)
hash.Reset()
hash.Write(n.left)
hash.Write(n.right)
s = hash.Sum(nil)

} else {
s = append(n.left, n.right...)
Expand Down

0 comments on commit 1fe86ed

Please sign in to comment.