OSDN Git Service

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