Skip to content

Commit

Permalink
Merge pull request #8479 from filecoin-project/asr/expired-cutoff
Browse files Browse the repository at this point in the history
Fail to add expired precommits to a batch
  • Loading branch information
magik6k authored Apr 13, 2022
2 parents 02a6176 + 42a79d5 commit 88142d2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions extern/storage-sealing/precommit_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,15 @@ func (b *PreCommitBatcher) AddPreCommit(ctx context.Context, s SectorInfo, depos
return sealiface.PreCommitBatchRes{}, err
}

cutoff, err := getPreCommitCutoff(curEpoch, s)
if err != nil {
return sealiface.PreCommitBatchRes{}, xerrors.Errorf("failed to calculate cutoff: %w", err)
}

sn := s.SectorNumber

b.lk.Lock()
b.cutoffs[sn] = getPreCommitCutoff(curEpoch, s)
b.cutoffs[sn] = cutoff
b.todo[sn] = &preCommitEntry{
deposit: deposit,
pci: in,
Expand Down Expand Up @@ -467,7 +472,7 @@ func (b *PreCommitBatcher) Stop(ctx context.Context) error {
}

// TODO: If this returned epochs, it would make testing much easier
func getPreCommitCutoff(curEpoch abi.ChainEpoch, si SectorInfo) time.Time {
func getPreCommitCutoff(curEpoch abi.ChainEpoch, si SectorInfo) (time.Time, error) {
cutoffEpoch := si.TicketEpoch + policy.MaxPreCommitRandomnessLookback
for _, p := range si.Pieces {
if p.DealInfo == nil {
Expand All @@ -481,8 +486,8 @@ func getPreCommitCutoff(curEpoch abi.ChainEpoch, si SectorInfo) time.Time {
}

if cutoffEpoch <= curEpoch {
return time.Now()
return time.Now(), xerrors.Errorf("cutoff has already passed (cutoff %d <= curEpoch %d)", cutoffEpoch, curEpoch)
}

return time.Now().Add(time.Duration(cutoffEpoch-curEpoch) * time.Duration(build.BlockDelaySecs) * time.Second)
return time.Now().Add(time.Duration(cutoffEpoch-curEpoch) * time.Duration(build.BlockDelaySecs) * time.Second), nil
}

0 comments on commit 88142d2

Please sign in to comment.