Skip to content

Commit

Permalink
DownloadHeaders: Instead of using doneChan - close blockHeadersMessag…
Browse files Browse the repository at this point in the history
…eChan. (#1523)
  • Loading branch information
svarogg authored Feb 11, 2021
1 parent 05d1671 commit 6db296b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/protocol/flows/blockrelay/ibd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -230,7 +229,7 @@ func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externa
return
}
if doneIBD {
doneChan <- struct{}{}
close(blockHeadersMessageChan)
return
}

Expand All @@ -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 {
Expand All @@ -255,8 +257,6 @@ func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externa
}
case err := <-errChan:
return err
case <-doneChan:
return nil
}
}
}
Expand Down

0 comments on commit 6db296b

Please sign in to comment.