Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This fixes timely automatic recovery tasks #209

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions tasks/window/recover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

Expand Down