chore: Move cfg getter into PCPolicy; Clamp values on get
This commit is contained in:
parent
9e34cce1f2
commit
adb62a3fff
@ -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
|
||||
}
|
||||
|
48
extern/storage-sealing/precommit_policy.go
vendored
48
extern/storage-sealing/precommit_policy.go
vendored
@ -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 {
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +81,13 @@ 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
|
||||
}
|
||||
|
||||
@ -87,3 +95,23 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi
|
||||
|
||||
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
extern/storage-sealing/sealiface/config.go
vendored
2
extern/storage-sealing/sealiface/config.go
vendored
@ -20,7 +20,7 @@ type Config struct {
|
||||
|
||||
WaitDealsDelay time.Duration
|
||||
|
||||
CommittedCapacityDefaultLifetime time.Duration
|
||||
CommittedCapacitySectorLifetime time.Duration
|
||||
|
||||
AlwaysKeepUnsealedCopy bool
|
||||
|
||||
|
@ -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"
|
||||
)
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"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"
|
||||
"github.com/filecoin-project/lotus/chain/events"
|
||||
"github.com/filecoin-project/lotus/chain/gen"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@ -178,15 +177,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) {
|
||||
@ -203,16 +199,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{
|
||||
|
Loading…
Reference in New Issue
Block a user