Skip to content

Commit 325cab5

Browse files
committed
fix: WinPoSt: Prioritize recent tasks, don't care about old mining bases
1 parent 0c4e1ff commit 325cab5

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

tasks/winning/winning_task.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/filecoin-project/curio/lib/promise"
3131

3232
"github.com/filecoin-project/lotus/api"
33+
"github.com/filecoin-project/lotus/chain/actors/policy"
3334
"github.com/filecoin-project/lotus/chain/gen"
3435
lrand "github.com/filecoin-project/lotus/chain/rand"
3536
"github.com/filecoin-project/lotus/chain/types"
@@ -185,6 +186,20 @@ func (t *WinPostTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (don
185186

186187
mbi, err := t.api.MinerGetBaseInfo(ctx, maddr, round, base.TipSet.Key())
187188
if err != nil {
189+
// possible that the tipset was really obsolete
190+
log.Errorw("WinPoSt failed to get mining base info", "error", err, "tipset", types.LogCids(base.TipSet.Cids()))
191+
192+
curHead, err := t.api.ChainHead(ctx)
193+
if err != nil {
194+
return false, xerrors.Errorf("failed to get chain head with miner base info check error: %w", err)
195+
}
196+
197+
maxAge := policy.ChainFinality
198+
if curHead.Height() > base.TipSet.Height()+maxAge {
199+
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())
200+
return persistNoWin()
201+
}
202+
188203
return false, xerrors.Errorf("failed to get mining base info: %w", err)
189204
}
190205
if mbi == nil {
@@ -488,24 +503,15 @@ func (t *WinPostTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.Ta
488503
return nil, nil
489504
}
490505

491-
// select lowest epoch
492-
var lowestEpoch abi.ChainEpoch
493-
var lowestEpochID = ids[0]
506+
// select task id, hoping to get the highest epoch
507+
var highestTaskID harmonytask.TaskID
494508
for _, id := range ids {
495-
var epoch uint64
496-
err := t.db.QueryRow(context.Background(), `SELECT epoch FROM mining_tasks WHERE task_id = $1`, id).Scan(&epoch)
497-
if err != nil {
498-
log.Errorw("failed to get epoch for task", "task", id, "error", err)
499-
continue
500-
}
501-
502-
if lowestEpoch == 0 || abi.ChainEpoch(epoch) < lowestEpoch {
503-
lowestEpoch = abi.ChainEpoch(epoch)
504-
lowestEpochID = id
509+
if id > highestTaskID {
510+
highestTaskID = id
505511
}
506512
}
507513

508-
return &lowestEpochID, nil
514+
return &highestTaskID, nil
509515
}
510516

511517
func (t *WinPostTask) TypeDetails() harmonytask.TaskTypeDetails {

0 commit comments

Comments
 (0)