Skip to content

Commit

Permalink
chore: Move cfg getter into PCPolicy; Clamp values on get
Browse files Browse the repository at this point in the history
  • Loading branch information
placer14 committed Jul 22, 2021
1 parent ad03e0b commit 0085fc0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
4 changes: 4 additions & 0 deletions chain/actors/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
return ChainFinality
}

func GetMinSectorExpiration() abi.ChainEpoch {
return miner5.MinSectorExpiration
}

func GetMaxSectorExpirationExtension() abi.ChainEpoch {
return miner5.MaxSectorExpirationExtension
}
Expand Down
48 changes: 38 additions & 10 deletions extern/storage-sealing/precommit_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package sealing
import (
"context"

"github.com/filecoin-project/lotus/chain/actors/builtin/miner"

"github.com/filecoin-project/go-state-types/network"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/policy"
)

type PreCommitPolicy interface {
Expand All @@ -34,21 +36,21 @@ type Chain interface {
// If we're in Mode 2: The pre-commit expiration epoch will be set to the
// current epoch + the provided default duration.
type BasicPreCommitPolicy struct {
api Chain
api Chain
getSealingConfig GetSealingConfigFunc

provingBoundary abi.ChainEpoch
duration abi.ChainEpoch
}

// NewBasicPreCommitPolicy produces a BasicPreCommitPolicy.
//
// The provided duration is used as the default sector expiry when the sector
// contains no deals. The proving boundary is used to adjust/align the sector's expiration.
func NewBasicPreCommitPolicy(api Chain, duration abi.ChainEpoch, provingBoundary abi.ChainEpoch) BasicPreCommitPolicy {
func NewBasicPreCommitPolicy(api Chain, cfgGetter GetSealingConfigFunc, provingBoundary abi.ChainEpoch) BasicPreCommitPolicy {
return BasicPreCommitPolicy{
api: api,
provingBoundary: provingBoundary,
duration: duration,
api: api,
getSealingConfig: cfgGetter,
provingBoundary: provingBoundary,
}
}

Expand Down Expand Up @@ -79,11 +81,37 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi
}

if end == nil {
tmp := epoch + p.duration
// no deal pieces, get expiration for committed capacity sector
expirationDuration, err := p.getCCSectorLifetime()
if err != nil {
return 0, err
}

tmp := epoch + expirationDuration
end = &tmp
}

*end += miner.WPoStProvingPeriod - (*end % miner.WPoStProvingPeriod) + p.provingBoundary - 1

return *end, nil
}

func (p *BasicPreCommitPolicy) getCCSectorLifetime() (abi.ChainEpoch, error) {
c, err := p.getSealingConfig()
if err != nil {
return 0, xerrors.Errorf("sealing config load error: %w", err)
}

sectorExpiration := abi.ChainEpoch(c.CommittedCapacitySectorLifetime.Truncate(builtin.EpochDurationSeconds) / builtin.EpochDurationSeconds)

if minExpiration := policy.GetMinSectorExpiration(); sectorExpiration < minExpiration {
log.Warnf("value for CommittedCapacitySectorLiftime is too short, using default minimum (%d epochs)", minExpiration)
return minExpiration, nil
}
if maxExpiration := policy.GetMaxSectorExpirationExtension(); sectorExpiration > maxExpiration {
log.Warnf("value for CommittedCapacitySectorLiftime is too long, using default maximum (%d epochs)", maxExpiration)
return maxExpiration, nil
}

return sectorExpiration, nil
}
2 changes: 1 addition & 1 deletion extern/storage-sealing/sealiface/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct {

WaitDealsDelay time.Duration

CommittedCapacityDefaultLifetime time.Duration
CommittedCapacitySectorLifetime time.Duration

AlwaysKeepUnsealedCopy bool

Expand Down
13 changes: 8 additions & 5 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/filecoin-project/go-state-types/big"
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"

"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/policy"
"github.com/filecoin-project/lotus/chain/types"
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
)
Expand Down Expand Up @@ -131,11 +133,10 @@ type SealingConfig struct {

WaitDealsDelay Duration

// CommittedCapacityDefaultLifetime is the default duration a Committed Capacity (CC)
// sector will live before it must be extended or converted into sector containing deals
// before it is terminated.
// Value must be between 180-540 days inclusive.
CommittedCapacityDefaultLifetime Duration
// CommittedCapacitySectorLifetime is the duration a Committed Capacity (CC) sector will
// live before it must be extended or converted into sector containing deals before it is
// terminated. Value must be between 180-540 days inclusive.
CommittedCapacitySectorLifetime Duration

AlwaysKeepUnsealedCopy bool

Expand Down Expand Up @@ -358,6 +359,8 @@ func DefaultStorageMiner() *StorageMiner {
PreCommitBatchWait: Duration(24 * time.Hour), // this should be less than 31.5 hours, which is the expiration of a precommit ticket
PreCommitBatchSlack: Duration(3 * time.Hour), // time buffer for forceful batch submission before sectors/deals in batch would start expiring, higher value will lower the chances for message fail due to expiration

CommittedCapacitySectorLifetime: Duration(builtin.EpochDurationSeconds * policy.GetMaxSectorExpirationExtension()),

AggregateCommits: true,
MinCommitBatch: miner5.MinAggregatedSectors, // per FIP13, we must have at least four proofs to aggregate, where 4 is the cross over point where aggregation wins out on single provecommit gas costs
MaxCommitBatch: miner5.MaxAggregatedSectors, // maximum 819 sectors, this is the maximum aggregation per FIP13
Expand Down
17 changes: 2 additions & 15 deletions storage/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,12 @@ func (m *Miner) Run(ctx context.Context) error {
// provides extra methods.
adaptedAPI = NewSealingAPIAdapter(m.api)

// sealing configuration.
cfg = sealing.GetSealingConfigFunc(m.getSealConfig)

// Instantiate a precommit policy.
defaultDuration = getDefaultSectorExpirationExtension(cfg) - (md.WPoStProvingPeriod * 2)
cfg = sealing.GetSealingConfigFunc(m.getSealConfig)
provingBoundary = md.PeriodStart % md.WPoStProvingPeriod

// TODO: Maybe we update this policy after actor upgrades?
pcp = sealing.NewBasicPreCommitPolicy(adaptedAPI, defaultDuration, provingBoundary)
pcp = sealing.NewBasicPreCommitPolicy(adaptedAPI, cfg, provingBoundary)

// address selector.
as = func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) {
Expand All @@ -203,16 +200,6 @@ func (m *Miner) Run(ctx context.Context) error {
return nil
}

func getDefaultSectorExpirationExtension(cfg sealing.GetSealingConfigFunc) abi.ChainEpoch {
c, err := cfg()
if err != nil {
log.Warnf("failed to load sealing config, using default sector extension expiration")
log.Errorf("sealing config load error: %s", err.Error())
return policy.GetMaxSectorExpirationExtension()
}
return abi.ChainEpoch(c.CommittedCapacityDefaultLifetime.Truncate(builtin.EpochDurationSeconds))
}

func (m *Miner) handleSealingNotifications(before, after sealing.SectorInfo) {
m.journal.RecordEvent(m.sealingEvtType, func() interface{} {
return SealingStateEvt{
Expand Down

0 comments on commit 0085fc0

Please sign in to comment.