Skip to content

Commit

Permalink
close verifyTask when length of verifyPeers is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dean65 committed Apr 29, 2022
1 parent 8929510 commit e9be0d4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/remote_state_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (vm *remoteVerifyManager) mainLoop() {
verifyTaskCounter.Dec(1)
verifyTaskSucceedMeter.Mark(1)
verifyTaskExecutionTimer.Update(time.Since(task.startAt))
close(task.terminalCh)
task.Close()
}
vm.taskLock.Unlock()
case <-pruneTicker.C:
Expand All @@ -126,7 +126,7 @@ func (vm *remoteVerifyManager) mainLoop() {
delete(vm.tasks, hash)
verifyTaskCounter.Dec(1)
verifyTaskFailedMeter.Mark(1)
close(task.terminalCh)
task.Close()
}
}
vm.taskLock.Unlock()
Expand All @@ -140,7 +140,7 @@ func (vm *remoteVerifyManager) mainLoop() {
case <-vm.bc.quit:
vm.taskLock.RLock()
for _, task := range vm.tasks {
close(task.terminalCh)
task.Close()
}
vm.taskLock.RUnlock()
return
Expand Down Expand Up @@ -276,6 +276,15 @@ func NewVerifyTask(diffhash common.Hash, header *types.Header, peers verifyPeers
return vt
}

func (vt *verifyTask) Close() {
// It is safe to call close multiple
select {
case <-vt.terminalCh:
default:
close(vt.terminalCh)
}
}

func (vt *verifyTask) Start(verifyCh chan common.Hash) {
vt.startAt = time.Now()

Expand Down Expand Up @@ -326,7 +335,7 @@ func (vt *verifyTask) sendVerifyRequest(n int) {
// if has not valid peer, log warning.
if len(validPeers) == 0 {
log.Warn("there is no valid peer for block", "number", vt.blockHeader.Number)
return
vt.Close()
}

if n < len(validPeers) && n > 0 {
Expand Down

0 comments on commit e9be0d4

Please sign in to comment.