Skip to content

Commit

Permalink
fix: WinPoSt: Prioritize recent tasks, don't care about old mining bases
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Aug 6, 2024
1 parent 0c4e1ff commit 9fcdcba
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tasks/winning/winning_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/rand"
"encoding/binary"
"encoding/json"
"github.com/filecoin-project/lotus/chain/actors/policy"
"time"

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -185,6 +186,20 @@ func (t *WinPostTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (don

mbi, err := t.api.MinerGetBaseInfo(ctx, maddr, round, base.TipSet.Key())
if err != nil {
// possible that the tipset was really obsolete
log.Errorw("WinPoSt failed to get mining base info", "error", err, "tipset", types.LogCids(base.TipSet.Cids()))

curHead, err := t.api.ChainHead(ctx)
if err != nil {
return false, xerrors.Errorf("failed to get chain head with miner base info check error: %w", err)
}

maxAge := policy.ChainFinality
if curHead.Height() > base.TipSet.Height()+maxAge {
log.Warnw("Mining base too old, dropping", "tipset", types.LogCids(base.TipSet.Cids()), "miner", maddr, "curHead", curHead.Height(), "baseHead", base.TipSet.Height(), "diffEpochs", curHead.Height()-base.TipSet.Height())
return persistNoWin()
}

return false, xerrors.Errorf("failed to get mining base info: %w", err)
}
if mbi == nil {
Expand Down Expand Up @@ -488,24 +503,15 @@ func (t *WinPostTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.Ta
return nil, nil
}

// select lowest epoch
var lowestEpoch abi.ChainEpoch
var lowestEpochID = ids[0]
// select task id, hoping to get the highest epoch
var highestTaskID harmonytask.TaskID
for _, id := range ids {
var epoch uint64
err := t.db.QueryRow(context.Background(), `SELECT epoch FROM mining_tasks WHERE task_id = $1`, id).Scan(&epoch)
if err != nil {
log.Errorw("failed to get epoch for task", "task", id, "error", err)
continue
}

if lowestEpoch == 0 || abi.ChainEpoch(epoch) < lowestEpoch {
lowestEpoch = abi.ChainEpoch(epoch)
lowestEpochID = id
if id > highestTaskID {
highestTaskID = id
}
}

return &lowestEpochID, nil
return &highestTaskID, nil
}

func (t *WinPostTask) TypeDetails() harmonytask.TaskTypeDetails {
Expand Down

0 comments on commit 9fcdcba

Please sign in to comment.