From b8ba5274e27f227ade054d60df56ecb3b6ca6192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 16 Mar 2022 20:17:20 +0100 Subject: [PATCH] sealing: Enforce minimum expiration in tryGetUpgradeSector --- extern/storage-sealing/input.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/extern/storage-sealing/input.go b/extern/storage-sealing/input.go index 64efb4944..4c9c21273 100644 --- a/extern/storage-sealing/input.go +++ b/extern/storage-sealing/input.go @@ -516,7 +516,7 @@ func (m *Sealing) updateInput(ctx context.Context, sp abi.RegisteredSealProof) e return nil } -func (m *Sealing) calcTargetExpiration(ctx context.Context, ssize abi.SectorSize) (target abi.ChainEpoch) { +func (m *Sealing) calcTargetExpiration(ctx context.Context, ssize abi.SectorSize) (minTarget, target abi.ChainEpoch, err error) { var candidates []*pendingPiece for _, piece := range m.pendingPieces { @@ -536,19 +536,18 @@ func (m *Sealing) calcTargetExpiration(ctx context.Context, ssize abi.SectorSize totalBytes += uint64(candidate.size) if totalBytes >= uint64(abi.PaddedPieceSize(ssize).Unpadded()) { - return candidate.deal.DealProposal.EndEpoch + return candidates[0].deal.DealProposal.EndEpoch, candidate.deal.DealProposal.EndEpoch, nil } } _, curEpoch, err := m.Api.ChainHead(ctx) if err != nil { - log.Errorf("getting current epoch: %s", err) - return 0 + return 0, 0, xerrors.Errorf("getting current epoch: %w", err) } - _, maxDur := policy.DealDurationBounds(0) + minDur, maxDur := policy.DealDurationBounds(0) - return curEpoch + maxDur + return curEpoch + minDur, curEpoch + maxDur, nil } func (m *Sealing) tryGetUpgradeSector(ctx context.Context, sp abi.RegisteredSealProof, ef expFn) (bool, error) { @@ -560,7 +559,10 @@ func (m *Sealing) tryGetUpgradeSector(ctx context.Context, sp abi.RegisteredSeal if err != nil { return false, xerrors.Errorf("getting sector size: %w", err) } - targetExpiration := m.calcTargetExpiration(ctx, ssize) + minExpiration, targetExpiration, err := m.calcTargetExpiration(ctx, ssize) + if err != nil { + return false, xerrors.Errorf("calculating min target expiration: %w", err) + } var candidate abi.SectorID var bestExpiration abi.ChainEpoch @@ -605,7 +607,8 @@ func (m *Sealing) tryGetUpgradeSector(ctx context.Context, sp abi.RegisteredSeal } } - if bestExpiration == 0 { + if bestExpiration < minExpiration { + log.Infow("Not upgrading any sectors", "available", len(m.available), "bestExp", bestExpiration, "target", targetExpiration, "min", minExpiration, "candidate", candidate) // didn't find a good sector / no sectors were available return false, nil }