Skip to content

Commit

Permalink
break out of mining loop when stop is called during niceSleep
Browse files Browse the repository at this point in the history
  • Loading branch information
travisperson committed Sep 16, 2020
1 parent 0c1c19c commit 808051d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (m *Miner) niceSleep(d time.Duration) bool {
case <-build.Clock.After(d):
return true
case <-m.stop:
log.Infow("recieved interrupt while trying to sleep in mining cycle")
return false
}
}
Expand Down Expand Up @@ -169,7 +170,9 @@ func (m *Miner) mine(ctx context.Context) {
prebase, err := m.GetBestMiningCandidate(ctx)
if err != nil {
log.Errorf("failed to get best mining candidate: %s", err)
m.niceSleep(time.Second * 5)
if !m.niceSleep(time.Second * 5) {
break
}
continue
}

Expand Down Expand Up @@ -199,7 +202,9 @@ func (m *Miner) mine(ctx context.Context) {
_, err = m.api.BeaconGetEntry(ctx, prebase.TipSet.Height()+prebase.NullRounds+1)
if err != nil {
log.Errorf("failed getting beacon entry: %s", err)
m.niceSleep(time.Second)
if !m.niceSleep(time.Second) {
break
}
continue
}

Expand All @@ -208,7 +213,9 @@ func (m *Miner) mine(ctx context.Context) {

if base.TipSet.Equals(lastBase.TipSet) && lastBase.NullRounds == base.NullRounds {
log.Warnf("BestMiningCandidate from the previous round: %s (nulls:%d)", lastBase.TipSet.Cids(), lastBase.NullRounds)
m.niceSleep(time.Duration(build.BlockDelaySecs) * time.Second)
if !m.niceSleep(time.Duration(build.BlockDelaySecs) * time.Second) {
break
}
continue
}

Expand All @@ -217,7 +224,9 @@ func (m *Miner) mine(ctx context.Context) {
b, err := m.mineOne(ctx, base)
if err != nil {
log.Errorf("mining block failed: %+v", err)
m.niceSleep(time.Second)
if !m.niceSleep(time.Second) {
break
}
onDone(false, 0, err)
continue
}
Expand Down

1 comment on commit 808051d

@zgfzgf
Copy link
Contributor

@zgfzgf zgfzgf commented on 808051d Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break error
may use goto
#3953

Please sign in to comment.