From 42a79d52a2889d77e0ee1f8cef3daf8926cd47d3 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 12 Apr 2022 23:41:52 -0400 Subject: [PATCH] Fail to add expired precommits to a batch --- extern/storage-sealing/precommit_batch.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/extern/storage-sealing/precommit_batch.go b/extern/storage-sealing/precommit_batch.go index 07d2e796e..2a8168a4a 100644 --- a/extern/storage-sealing/precommit_batch.go +++ b/extern/storage-sealing/precommit_batch.go @@ -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, @@ -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 { @@ -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 }