Fix the stopOldTemplateSolving channel in the miner getting closed twice (#1286)

* Fix the stopOldTemplateSolving channel in the miner getting closed twice.

* Remove a unused variable.
This commit is contained in:
stasatdaglabs 2020-12-24 17:58:28 +02:00 committed by GitHub
parent 830ddf4735
commit 0dea766373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,7 +89,7 @@ func mineNextBlock(client *minerClient, miningAddr util.Address, foundBlock chan
templatesLoop(client, miningAddr, newTemplateChan, errChan, templateStopChan)
})
spawn("solveLoop", func() {
solveLoop(newTemplateChan, foundBlock, mineWhenNotSynced, errChan)
solveLoop(newTemplateChan, foundBlock, mineWhenNotSynced)
})
}
@ -151,18 +151,19 @@ func templatesLoop(client *minerClient, miningAddr util.Address,
}
func solveLoop(newTemplateChan chan *appmessage.GetBlockTemplateResponseMessage, foundBlock chan *externalapi.DomainBlock,
mineWhenNotSynced bool, errChan chan error) {
mineWhenNotSynced bool) {
var stopOldTemplateSolving chan struct{}
for template := range newTemplateChan {
if stopOldTemplateSolving != nil {
close(stopOldTemplateSolving)
}
if !template.IsSynced && !mineWhenNotSynced {
log.Warnf("Kaspad is not synced. Skipping current block template")
continue
}
if stopOldTemplateSolving != nil {
close(stopOldTemplateSolving)
}
stopOldTemplateSolving = make(chan struct{})
block := appmessage.MsgBlockToDomainBlock(template.MsgBlock)