Skip to content

Commit

Permalink
fix(miner): continue mining if we fail to submit a block
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Nov 1, 2024
1 parent e1a0572 commit c80f32d
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ minerLoop:
onDone(b != nil, h, nil)

// Process the mined block.
if b != nil {
switch {
case b != nil:
// Record the event of mining a block.
m.journal.RecordEvent(m.evtTypes[evtTypeBlockMined], func() interface{} {
return map[string]interface{}{
Expand Down Expand Up @@ -348,19 +349,19 @@ minerLoop:
if err != nil {
log.Errorf("<!!> SLASH FILTER ERRORED: %s", err)
// Continue here, because it's _probably_ wiser to not submit this block
continue
break
}

if fault {
log.Errorf("<!!> SLASH FILTER DETECTED FAULT due to blocks %s and %s", b.Header.Cid(), witness)
continue
break
}
}

// Check for blocks created at the same height.
if _, ok := m.minedBlockHeights.Get(b.Header.Height); ok {
log.Warnw("Created a block at the same height as another block we've created", "height", b.Header.Height, "miner", b.Header.Miner, "parents", b.Header.Parents)
continue
break
}

// Add the block height to the mined block heights.
Expand All @@ -369,24 +370,26 @@ minerLoop:
// Submit the newly mined block.
if err := m.api.SyncSubmitBlock(ctx, b); err != nil {
log.Errorf("failed to submit newly mined block: %+v", err)
break
}
} else {
// If no block was mined, increase the null rounds and wait for the next epoch.
base.NullRounds++

// Calculate the time for the next round.
nextRound := time.Unix(int64(base.TipSet.MinTimestamp()+buildconstants.BlockDelaySecs*uint64(base.NullRounds))+int64(buildconstants.PropagationDelaySecs), 0)

// Wait for the next round or stop signal.
select {
case <-build.Clock.After(build.Clock.Until(nextRound)):
case <-m.stop:
stopping := m.stopping
m.stop = nil
m.stopping = nil
close(stopping)
return
}
continue // TODO: we should probably remove this continue and wait in this case as well... but that's a bigger change.
}

// If no block was mined or if we fail to submit the block, increase the null rounds and wait for the next epoch.
base.NullRounds++

// Calculate the time for the next round.
nextRound := time.Unix(int64(base.TipSet.MinTimestamp()+buildconstants.BlockDelaySecs*uint64(base.NullRounds))+int64(buildconstants.PropagationDelaySecs), 0)

// Wait for the next round or stop signal.
select {
case <-build.Clock.After(build.Clock.Until(nextRound)):
case <-m.stop:
stopping := m.stopping
m.stop = nil
m.stopping = nil
close(stopping)
return
}
}
}
Expand Down

0 comments on commit c80f32d

Please sign in to comment.