OSDN Git Service

Revert "Fix BlockWaiter dead lock (#311)" (#314)
authoryahtoo <yahtoo.ma@gmail.com>
Thu, 18 Jul 2019 07:44:09 +0000 (15:44 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 18 Jul 2019 07:44:09 +0000 (15:44 +0800)
This reverts commit 101539186ad6a4422b703abf5f8739f26c7a21f3.

protocol/protocol.go

index 314b568..d7ea944 100644 (file)
@@ -201,7 +201,9 @@ func (c *Chain) setState(blockHeader, irrBlockHeader *types.BlockHeader, mainBlo
 func (c *Chain) BlockWaiter(height uint64) <-chan struct{} {
        ch := make(chan struct{}, 1)
        go func() {
-               for bestHeight := c.BestBlockHeight(); bestHeight < height; bestHeight = c.BestBlockHeight() {
+               c.cond.L.Lock()
+               defer c.cond.L.Unlock()
+               for c.bestBlockHeader.Height < height {
                        c.cond.Wait()
                }
                ch <- struct{}{}