@@ -30,6 +30,7 @@ import (
30
30
"github.com/filecoin-project/curio/lib/promise"
31
31
32
32
"github.com/filecoin-project/lotus/api"
33
+ "github.com/filecoin-project/lotus/chain/actors/policy"
33
34
"github.com/filecoin-project/lotus/chain/gen"
34
35
lrand "github.com/filecoin-project/lotus/chain/rand"
35
36
"github.com/filecoin-project/lotus/chain/types"
@@ -185,6 +186,20 @@ func (t *WinPostTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (don
185
186
186
187
mbi , err := t .api .MinerGetBaseInfo (ctx , maddr , round , base .TipSet .Key ())
187
188
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
+
188
203
return false , xerrors .Errorf ("failed to get mining base info: %w" , err )
189
204
}
190
205
if mbi == nil {
@@ -488,24 +503,15 @@ func (t *WinPostTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.Ta
488
503
return nil , nil
489
504
}
490
505
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
494
508
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
505
511
}
506
512
}
507
513
508
- return & lowestEpochID , nil
514
+ return & highestTaskID , nil
509
515
}
510
516
511
517
func (t * WinPostTask ) TypeDetails () harmonytask.TaskTypeDetails {
0 commit comments