diff --git a/tasks/window/recover_task.go b/tasks/window/recover_task.go index 07997bf13..14c1a8469 100644 --- a/tasks/window/recover_task.go +++ b/tasks/window/recover_task.go @@ -266,45 +266,48 @@ func (w *WdPostRecoverDeclareTask) processHeadChange(ctx context.Context, revert return nil // not proving anything yet } - // declaring two deadlines ahead - declDeadline := (di.Index + 2) % di.WPoStPeriodDeadlines - - pps := di.PeriodStart - if declDeadline != di.Index+2 { - pps = di.NextPeriodStart() - } - - partitions, err := w.api.StateMinerPartitions(ctx, maddr, declDeadline, apply.Key()) - if err != nil { - return xerrors.Errorf("getting partitions: %w", err) - } - - for pidx, partition := range partitions { - unrecovered, err := bitfield.SubtractBitField(partition.FaultySectors, partition.RecoveringSectors) - if err != nil { - return xerrors.Errorf("subtracting recovered set from fault set: %w", err) + // repeat checks for [2, 4, 6, 8, 10, 12, 14, 16, ... 38], the closer deadline is prioritized + for i := 1; i < 20; i++ { + // declaring 2*i deadlines ahead + declDeadline := (di.Index + uint64(2*i)) % di.WPoStPeriodDeadlines + + pps := di.PeriodStart + if declDeadline != di.Index+uint64(2*i) { + pps = di.NextPeriodStart() } - uc, err := unrecovered.Count() + partitions, err := w.api.StateMinerPartitions(ctx, maddr, declDeadline, apply.Key()) if err != nil { - return xerrors.Errorf("counting unrecovered sectors: %w", err) + return xerrors.Errorf("getting partitions: %w", err) } - if uc == 0 { - log.Debugw("WdPostRecoverDeclareTask.processHeadChange() uc == 0, skipping", "maddr", maddr, "declDeadline", declDeadline, "pidx", pidx) - continue + for pidx, partition := range partitions { + unrecovered, err := bitfield.SubtractBitField(partition.FaultySectors, partition.RecoveringSectors) + if err != nil { + return xerrors.Errorf("subtracting recovered set from fault set: %w", err) + } + + uc, err := unrecovered.Count() + if err != nil { + return xerrors.Errorf("counting unrecovered sectors: %w", err) + } + + if uc == 0 { + log.Debugw("WdPostRecoverDeclareTask.processHeadChange() uc == 0, skipping", "maddr", maddr, "declDeadline", declDeadline, "pidx", pidx) + continue + } + + tid := wdTaskIdentity{ + SpID: aid, + ProvingPeriodStart: pps, + DeadlineIndex: declDeadline, + PartitionIndex: uint64(pidx), + } + + tf(func(id harmonytask.TaskID, tx *harmonydb.Tx) (bool, error) { + return w.addTaskToDB(id, tid, tx) + }) } - - tid := wdTaskIdentity{ - SpID: aid, - ProvingPeriodStart: pps, - DeadlineIndex: declDeadline, - PartitionIndex: uint64(pidx), - } - - tf(func(id harmonytask.TaskID, tx *harmonydb.Tx) (bool, error) { - return w.addTaskToDB(id, tid, tx) - }) } }