From 0a579e7f78b5d34039b2f56ec7f25972944475f8 Mon Sep 17 00:00:00 2001 From: Svarog Date: Thu, 11 Feb 2021 16:59:31 +0200 Subject: [PATCH] DownloadHeaders: Instead of using doneChan - close blockHeadersMessageChan. (#1523) --- app/protocol/flows/blockrelay/ibd.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/protocol/flows/blockrelay/ibd.go b/app/protocol/flows/blockrelay/ibd.go index f8a4fda65..e4851aed2 100644 --- a/app/protocol/flows/blockrelay/ibd.go +++ b/app/protocol/flows/blockrelay/ibd.go @@ -221,7 +221,6 @@ func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externa // headers blockHeadersMessageChan := make(chan *appmessage.BlockHeadersMessage, 2) errChan := make(chan error) - doneChan := make(chan interface{}) spawn("handleRelayInvsFlow-downloadHeaders", func() { for { blockHeadersMessage, doneIBD, err := flow.receiveHeaders() @@ -230,7 +229,7 @@ func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externa return } if doneIBD { - doneChan <- struct{}{} + close(blockHeadersMessageChan) return } @@ -246,7 +245,10 @@ func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externa for { select { - case blockHeadersMessage := <-blockHeadersMessageChan: + case blockHeadersMessage, ok := <-blockHeadersMessageChan: + if !ok { + return nil + } for _, header := range blockHeadersMessage.BlockHeaders { err = flow.processHeader(header) if err != nil { @@ -255,8 +257,6 @@ func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externa } case err := <-errChan: return err - case <-doneChan: - return nil } } }